~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_table.cc

  • Committer: Monty Taylor
  • Date: 2011-03-09 20:59:40 UTC
  • mfrom: (2226.1.14 build)
  • Revision ID: mordred@inaugust.com-20110309205940-7f5mk6zba2u7bawa
Merged Dave - Filtered Replication docs
Merged Olaf - Refactoring work
Removed archive, blackhole, filesystem_engine, blitzdb, csv and pbxt from
the tree pre-GA as we have no interest in supporting them moving forward.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
  link_to_local(false),
48
48
  create_table_list(NULL)
49
49
{
50
 
  getSession()->getLex()->sql_command= SQLCOM_CREATE_TABLE;
 
50
  set_command(SQLCOM_CREATE_TABLE);
51
51
  createTableMessage().set_name(ident->table.str, ident->table.length);
52
52
#if 0
53
53
  createTableMessage().set_schema(ident->db.str, ident->db.length);
74
74
  link_to_local(false),
75
75
  create_table_list(NULL)
76
76
{
77
 
  getSession()->getLex()->sql_command= SQLCOM_CREATE_TABLE;
 
77
  set_command(SQLCOM_CREATE_TABLE);
78
78
}
79
79
 
80
80
} // namespace statement
81
81
 
82
82
bool statement::CreateTable::execute()
83
83
{
84
 
  TableList *first_table= (TableList *) getSession()->getLex()->select_lex.table_list.first;
85
 
  TableList *all_tables= getSession()->getLex()->query_tables;
 
84
  TableList *first_table= (TableList *) lex().select_lex.table_list.first;
 
85
  TableList *all_tables= lex().query_tables;
86
86
  assert(first_table == all_tables && first_table != 0);
87
87
  bool need_start_waiting= false;
88
88
  lex_identified_temp_table= createTableMessage().type() == message::Table::TEMPORARY;
121
121
    }
122
122
  }
123
123
  /* Skip first table, which is the table we are creating */
124
 
  create_table_list= getSession()->getLex()->unlink_first_table(&link_to_local);
 
124
  create_table_list= lex().unlink_first_table(&link_to_local);
125
125
 
126
126
  drizzled::message::table::init(createTableMessage(), createTableMessage().name(), create_table_list->getSchemaName(), create_info().db_type->getName());
127
127
 
132
132
  if (not check(new_table_identifier))
133
133
  {
134
134
    /* put tables back for PS rexecuting */
135
 
    getSession()->getLex()->link_first_table_back(create_table_list, link_to_local);
 
135
    lex().link_first_table_back(create_table_list, link_to_local);
136
136
    return true;
137
137
  }
138
138
 
155
155
  if (! (need_start_waiting= not getSession()->wait_if_global_read_lock(0, 1)))
156
156
  {
157
157
    /* put tables back for PS rexecuting */
158
 
    getSession()->getLex()->link_first_table_back(create_table_list, link_to_local);
 
158
    lex().link_first_table_back(create_table_list, link_to_local);
159
159
    return true;
160
160
  }
161
161
 
173
173
bool statement::CreateTable::executeInner(identifier::Table::const_reference new_table_identifier)
174
174
{
175
175
  bool res= false;
176
 
  Select_Lex *select_lex= &getSession()->getLex()->select_lex;
177
 
  TableList *select_tables= getSession()->getLex()->query_tables;
 
176
  Select_Lex *select_lex= &lex().select_lex;
 
177
  TableList *select_tables= lex().query_tables;
178
178
 
179
179
  do 
180
180
  {
181
181
    if (select_lex->item_list.size())           // With select
182
182
    {
183
 
      Select_Lex_Unit *unit= &getSession()->getLex()->unit;
 
183
      Select_Lex_Unit *unit= &lex().unit;
184
184
      select_result *result;
185
185
 
186
186
      select_lex->options|= SELECT_NO_UNLOCK;
188
188
 
189
189
      if (not lex_identified_temp_table)
190
190
      {
191
 
        getSession()->getLex()->link_first_table_back(create_table_list, link_to_local);
 
191
        lex().link_first_table_back(create_table_list, link_to_local);
192
192
        create_table_list->setCreate(true);
193
193
      }
194
194
 
195
 
      if (not (res= getSession()->openTablesLock(getSession()->getLex()->query_tables)))
 
195
      if (not (res= getSession()->openTablesLock(lex().query_tables)))
196
196
      {
197
197
        /*
198
198
          Is table which we are changing used somewhere in other parts
201
201
        if (not lex_identified_temp_table)
202
202
        {
203
203
          TableList *duplicate= NULL;
204
 
          create_table_list= getSession()->getLex()->unlink_first_table(&link_to_local);
 
204
          create_table_list= lex().unlink_first_table(&link_to_local);
205
205
 
206
206
          if ((duplicate= unique_table(create_table_list, select_tables)))
207
207
          {
208
208
            my_error(ER_UPDATE_TABLE_USED, MYF(0), create_table_list->alias);
209
209
            /* put tables back for PS rexecuting */
210
 
            getSession()->getLex()->link_first_table_back(create_table_list, link_to_local);
 
210
            lex().link_first_table_back(create_table_list, link_to_local);
211
211
 
212
212
            res= true;
213
213
            break;
219
219
          needs to be created for every execution of a PS/SP.
220
220
        */
221
221
        if ((result= new select_create(create_table_list,
222
 
                                       getSession()->getLex()->exists(),
 
222
                                       lex().exists(),
223
223
                                       &create_info(),
224
224
                                       createTableMessage(),
225
225
                                       &alter_info,
226
226
                                       select_lex->item_list,
227
 
                                       getSession()->getLex()->duplicates,
228
 
                                       getSession()->getLex()->ignore,
 
227
                                       lex().duplicates,
 
228
                                       lex().ignore,
229
229
                                       select_tables,
230
230
                                       new_table_identifier)))
231
231
        {
233
233
            CREATE from SELECT give its Select_Lex for SELECT,
234
234
            and item_list belong to SELECT
235
235
          */
236
 
          res= handle_select(getSession(), getSession()->getLex(), result, 0);
 
236
          res= handle_select(getSession(), &lex(), result, 0);
237
237
          delete result;
238
238
        }
239
239
      }
240
240
      else if (not lex_identified_temp_table)
241
241
      {
242
 
        create_table_list= getSession()->getLex()->unlink_first_table(&link_to_local);
 
242
        create_table_list= lex().unlink_first_table(&link_to_local);
243
243
      }
244
244
    }
245
245
    else
252
252
                               identifier::Table(select_tables->getSchemaName(),
253
253
                                                 select_tables->getTableName()),
254
254
                               createTableMessage(),
255
 
                               getSession()->getLex()->exists(),
 
255
                               lex().exists(),
256
256
                               is_engine_set);
257
257
      }
258
258
      else
272
272
                          &alter_info, 
273
273
                          false, 
274
274
                          0,
275
 
                          getSession()->getLex()->exists());
 
275
                          lex().exists());
276
276
      }
277
277
 
278
278
      if (not res)