~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-04 09:29:39 UTC
  • mfrom: (2139.3.6 catalogs)
  • mto: This revision was merged to the branch mainline in revision 2144.
  • Revision ID: brian@tangent.org-20110204092939-nlwrimamw0fxxhgl
Main bit of this patch is that Inno now just uses the identifier so we only
have one spot to make changes for paths.

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