~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_table.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
 
21
#include <config.h>
 
22
 
22
23
#include <drizzled/show.h>
23
24
#include <drizzled/lock.h>
24
25
#include <drizzled/session.h>
26
27
#include <drizzled/message.h>
27
28
#include <drizzled/identifier.h>
28
29
#include <drizzled/plugin/storage_engine.h>
 
30
#include <drizzled/select_create.h>
29
31
 
30
32
#include <iostream>
31
33
 
79
81
 
80
82
bool statement::CreateTable::execute()
81
83
{
82
 
  TableList *first_table= (TableList *) getSession()->lex->select_lex.table_list.first;
83
 
  TableList *all_tables= getSession()->lex->query_tables;
 
84
  TableList *first_table= (TableList *) getSession()->getLex()->select_lex.table_list.first;
 
85
  TableList *all_tables= getSession()->getLex()->query_tables;
84
86
  assert(first_table == all_tables && first_table != 0);
85
87
  bool need_start_waiting= false;
86
88
  lex_identified_temp_table= createTableMessage().type() == message::Table::TEMPORARY;
119
121
    }
120
122
  }
121
123
  /* Skip first table, which is the table we are creating */
122
 
  create_table_list= getSession()->lex->unlink_first_table(&link_to_local);
 
124
  create_table_list= getSession()->getLex()->unlink_first_table(&link_to_local);
123
125
 
124
126
  drizzled::message::table::init(createTableMessage(), createTableMessage().name(), create_table_list->getSchemaName(), create_info().db_type->getName());
125
127
 
130
132
  if (not check(new_table_identifier))
131
133
  {
132
134
    /* put tables back for PS rexecuting */
133
 
    getSession()->lex->link_first_table_back(create_table_list, link_to_local);
 
135
    getSession()->getLex()->link_first_table_back(create_table_list, link_to_local);
134
136
    return true;
135
137
  }
136
138
 
153
155
  if (! (need_start_waiting= not getSession()->wait_if_global_read_lock(0, 1)))
154
156
  {
155
157
    /* put tables back for PS rexecuting */
156
 
    getSession()->lex->link_first_table_back(create_table_list, link_to_local);
 
158
    getSession()->getLex()->link_first_table_back(create_table_list, link_to_local);
157
159
    return true;
158
160
  }
159
161
 
171
173
bool statement::CreateTable::executeInner(identifier::Table::const_reference new_table_identifier)
172
174
{
173
175
  bool res= false;
174
 
  Select_Lex *select_lex= &getSession()->lex->select_lex;
175
 
  TableList *select_tables= getSession()->lex->query_tables;
 
176
  Select_Lex *select_lex= &getSession()->getLex()->select_lex;
 
177
  TableList *select_tables= getSession()->getLex()->query_tables;
176
178
 
177
179
  do 
178
180
  {
179
181
    if (select_lex->item_list.elements)         // With select
180
182
    {
181
 
      Select_Lex_Unit *unit= &getSession()->lex->unit;
 
183
      Select_Lex_Unit *unit= &getSession()->getLex()->unit;
182
184
      select_result *result;
183
185
 
184
186
      select_lex->options|= SELECT_NO_UNLOCK;
186
188
 
187
189
      if (not lex_identified_temp_table)
188
190
      {
189
 
        getSession()->lex->link_first_table_back(create_table_list, link_to_local);
 
191
        getSession()->getLex()->link_first_table_back(create_table_list, link_to_local);
190
192
        create_table_list->setCreate(true);
191
193
      }
192
194
 
193
 
      if (not (res= getSession()->openTablesLock(getSession()->lex->query_tables)))
 
195
      if (not (res= getSession()->openTablesLock(getSession()->getLex()->query_tables)))
194
196
      {
195
197
        /*
196
198
          Is table which we are changing used somewhere in other parts
199
201
        if (not lex_identified_temp_table)
200
202
        {
201
203
          TableList *duplicate= NULL;
202
 
          create_table_list= getSession()->lex->unlink_first_table(&link_to_local);
 
204
          create_table_list= getSession()->getLex()->unlink_first_table(&link_to_local);
203
205
 
204
206
          if ((duplicate= unique_table(create_table_list, select_tables)))
205
207
          {
206
208
            my_error(ER_UPDATE_TABLE_USED, MYF(0), create_table_list->alias);
207
209
            /* put tables back for PS rexecuting */
208
 
            getSession()->lex->link_first_table_back(create_table_list, link_to_local);
 
210
            getSession()->getLex()->link_first_table_back(create_table_list, link_to_local);
209
211
 
210
212
            res= true;
211
213
            break;
222
224
                                       createTableMessage(),
223
225
                                       &alter_info,
224
226
                                       select_lex->item_list,
225
 
                                       getSession()->lex->duplicates,
226
 
                                       getSession()->lex->ignore,
 
227
                                       getSession()->getLex()->duplicates,
 
228
                                       getSession()->getLex()->ignore,
227
229
                                       select_tables,
228
230
                                       new_table_identifier)))
229
231
        {
231
233
            CREATE from SELECT give its Select_Lex for SELECT,
232
234
            and item_list belong to SELECT
233
235
          */
234
 
          res= handle_select(getSession(), getSession()->lex, result, 0);
 
236
          res= handle_select(getSession(), getSession()->getLex(), result, 0);
235
237
          delete result;
236
238
        }
237
239
      }
238
240
      else if (not lex_identified_temp_table)
239
241
      {
240
 
        create_table_list= getSession()->lex->unlink_first_table(&link_to_local);
 
242
        create_table_list= getSession()->getLex()->unlink_first_table(&link_to_local);
241
243
      }
242
244
    }
243
245
    else
292
294
  // See if any storage engine objects to the name of the file
293
295
  if (not plugin::StorageEngine::canCreateTable(identifier))
294
296
  {
295
 
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", identifier.getSchemaName().c_str());
 
297
    identifier::Schema schema_identifier= identifier;
 
298
    error::access(*getSession()->user(), schema_identifier);
296
299
 
297
300
    return false;
298
301
  }
301
304
  // create for the table.
302
305
  if (not plugin::StorageEngine::doesSchemaExist(identifier))
303
306
  {
304
 
    my_error(ER_BAD_DB_ERROR, MYF(0), identifier.getSchemaName().c_str());
 
307
    identifier::Schema schema_identifier= identifier;
 
308
    my_error(ER_BAD_DB_ERROR, schema_identifier);
305
309
 
306
310
    return false;
307
311
  }