~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-12 06:56:00 UTC
  • mto: This revision was merged to the branch mainline in revision 2161.
  • Revision ID: brian@tangent.org-20110212065600-m6c68fybw51rflhj
Further strip out includes.

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