~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_table.cc

  • Committer: Lee Bieber
  • Date: 2011-01-24 17:20:08 UTC
  • mfrom: (2107.2.1 trunk-bug-703913)
  • mto: This revision was merged to the branch mainline in revision 2109.
  • Revision ID: kalebral@gmail.com-20110124172008-y5maihyoyu7gn18p
Merge Andrew - fix bug 703913: some support-files should be dropped

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