~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/create_table.cc

  • Committer: Brian Aker
  • Date: 2011-01-22 07:05:32 UTC
  • mto: This revision was merged to the branch mainline in revision 2104.
  • Revision ID: brian@tangent.org-20110122070532-r9vtkolkl7e522tm
Make session encapsulated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
bool statement::CreateTable::execute()
35
35
{
36
 
  TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
37
 
  TableList *all_tables= session->lex->query_tables;
 
36
  TableList *first_table= (TableList *) getSession()->lex->select_lex.table_list.first;
 
37
  TableList *all_tables= getSession()->lex->query_tables;
38
38
  assert(first_table == all_tables && first_table != 0);
39
39
  bool need_start_waiting= false;
40
40
  lex_identified_temp_table= createTableMessage().type() == message::Table::TEMPORARY;
44
44
  if (is_engine_set)
45
45
  {
46
46
    create_info().db_type= 
47
 
      plugin::StorageEngine::findByName(*session, createTableMessage().engine().name());
 
47
      plugin::StorageEngine::findByName(*getSession(), createTableMessage().engine().name());
48
48
 
49
49
    if (create_info().db_type == NULL)
50
50
    {
56
56
  }
57
57
  else /* We now get the default, place it in create_info, and put the engine name in table proto */
58
58
  {
59
 
    create_info().db_type= session->getDefaultStorageEngine();
 
59
    create_info().db_type= getSession()->getDefaultStorageEngine();
60
60
  }
61
61
 
62
62
  if (not validateCreateTableOption())
68
68
  /* If CREATE TABLE of non-temporary table, do implicit commit */
69
69
  if (not lex_identified_temp_table)
70
70
  {
71
 
    if (not session->endActiveTransaction())
 
71
    if (not getSession()->endActiveTransaction())
72
72
    {
73
73
      return true;
74
74
    }
75
75
  }
76
76
  /* Skip first table, which is the table we are creating */
77
 
  create_table_list= session->lex->unlink_first_table(&link_to_local);
 
77
  create_table_list= getSession()->lex->unlink_first_table(&link_to_local);
78
78
 
79
79
  drizzled::message::table::init(createTableMessage(), createTableMessage().name(), create_table_list->getSchemaName(), create_info().db_type->getName());
80
80
 
85
85
  if (not check(new_table_identifier))
86
86
  {
87
87
    /* put tables back for PS rexecuting */
88
 
    session->lex->link_first_table_back(create_table_list, link_to_local);
 
88
    getSession()->lex->link_first_table_back(create_table_list, link_to_local);
89
89
    return true;
90
90
  }
91
91
 
105
105
     TABLE in the same way. That way we avoid that a new table is
106
106
     created during a gobal read lock.
107
107
   */
108
 
  if (! (need_start_waiting= not session->wait_if_global_read_lock(0, 1)))
 
108
  if (! (need_start_waiting= not getSession()->wait_if_global_read_lock(0, 1)))
109
109
  {
110
110
    /* put tables back for PS rexecuting */
111
 
    session->lex->link_first_table_back(create_table_list, link_to_local);
 
111
    getSession()->lex->link_first_table_back(create_table_list, link_to_local);
112
112
    return true;
113
113
  }
114
114
 
118
118
    Release the protection against the global read lock and wake
119
119
    everyone, who might want to set a global read lock.
120
120
  */
121
 
  session->startWaitingGlobalReadLock();
 
121
  getSession()->startWaitingGlobalReadLock();
122
122
 
123
123
  return res;
124
124
}
126
126
bool statement::CreateTable::executeInner(identifier::Table::const_reference new_table_identifier)
127
127
{
128
128
  bool res= false;
129
 
  Select_Lex *select_lex= &session->lex->select_lex;
130
 
  TableList *select_tables= session->lex->query_tables;
 
129
  Select_Lex *select_lex= &getSession()->lex->select_lex;
 
130
  TableList *select_tables= getSession()->lex->query_tables;
131
131
 
132
132
  do 
133
133
  {
134
134
    if (select_lex->item_list.elements)         // With select
135
135
    {
136
 
      Select_Lex_Unit *unit= &session->lex->unit;
 
136
      Select_Lex_Unit *unit= &getSession()->lex->unit;
137
137
      select_result *result;
138
138
 
139
139
      select_lex->options|= SELECT_NO_UNLOCK;
141
141
 
142
142
      if (not lex_identified_temp_table)
143
143
      {
144
 
        session->lex->link_first_table_back(create_table_list, link_to_local);
 
144
        getSession()->lex->link_first_table_back(create_table_list, link_to_local);
145
145
        create_table_list->setCreate(true);
146
146
      }
147
147
 
148
 
      if (not (res= session->openTablesLock(session->lex->query_tables)))
 
148
      if (not (res= getSession()->openTablesLock(getSession()->lex->query_tables)))
149
149
      {
150
150
        /*
151
151
          Is table which we are changing used somewhere in other parts
154
154
        if (not lex_identified_temp_table)
155
155
        {
156
156
          TableList *duplicate= NULL;
157
 
          create_table_list= session->lex->unlink_first_table(&link_to_local);
 
157
          create_table_list= getSession()->lex->unlink_first_table(&link_to_local);
158
158
 
159
159
          if ((duplicate= unique_table(create_table_list, select_tables)))
160
160
          {
161
161
            my_error(ER_UPDATE_TABLE_USED, MYF(0), create_table_list->alias);
162
162
            /* put tables back for PS rexecuting */
163
 
            session->lex->link_first_table_back(create_table_list, link_to_local);
 
163
            getSession()->lex->link_first_table_back(create_table_list, link_to_local);
164
164
 
165
165
            res= true;
166
166
            break;
172
172
          needs to be created for every execution of a PS/SP.
173
173
        */
174
174
        if ((result= new select_create(create_table_list,
175
 
                                       session->getLex()->exists(),
 
175
                                       getSession()->getLex()->exists(),
176
176
                                       &create_info(),
177
177
                                       createTableMessage(),
178
178
                                       &alter_info,
179
179
                                       select_lex->item_list,
180
 
                                       session->lex->duplicates,
181
 
                                       session->lex->ignore,
 
180
                                       getSession()->lex->duplicates,
 
181
                                       getSession()->lex->ignore,
182
182
                                       select_tables,
183
183
                                       new_table_identifier)))
184
184
        {
186
186
            CREATE from SELECT give its Select_Lex for SELECT,
187
187
            and item_list belong to SELECT
188
188
          */
189
 
          res= handle_select(session, session->lex, result, 0);
 
189
          res= handle_select(getSession(), getSession()->lex, result, 0);
190
190
          delete result;
191
191
        }
192
192
      }
193
193
      else if (not lex_identified_temp_table)
194
194
      {
195
 
        create_table_list= session->lex->unlink_first_table(&link_to_local);
 
195
        create_table_list= getSession()->lex->unlink_first_table(&link_to_local);
196
196
      }
197
197
    }
198
198
    else
200
200
      /* regular create */
201
201
      if (is_create_table_like)
202
202
      {
203
 
        res= create_like_table(session, 
 
203
        res= create_like_table(getSession(), 
204
204
                               new_table_identifier,
205
205
                               identifier::Table(select_tables->getSchemaName(),
206
206
                                                 select_tables->getTableName()),
207
207
                               createTableMessage(),
208
 
                               session->getLex()->exists(),
 
208
                               getSession()->getLex()->exists(),
209
209
                               is_engine_set);
210
210
      }
211
211
      else
218
218
          *field= alter_info.alter_proto.added_field(x);
219
219
        }
220
220
 
221
 
        res= create_table(session, 
 
221
        res= create_table(getSession(), 
222
222
                          new_table_identifier,
223
223
                          &create_info(),
224
224
                          createTableMessage(),
225
225
                          &alter_info, 
226
226
                          false, 
227
227
                          0,
228
 
                          session->getLex()->exists());
 
228
                          getSession()->getLex()->exists());
229
229
      }
230
230
 
231
231
      if (not res)
232
232
      {
233
 
        session->my_ok();
 
233
        getSession()->my_ok();
234
234
      }
235
235
    }
236
236
  } while (0);