~drizzle-developers/drizzle/elliott-release

« back to all changes in this revision

Viewing changes to drizzled/statement/rename_table.cc

  • Committer: Patrick Crews
  • Date: 2011-02-01 20:33:06 UTC
  • mfrom: (1845.2.288 drizzle)
  • Revision ID: gleebix@gmail.com-20110201203306-mwq2rk0it81tlwxh
Merged Trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
bool statement::RenameTable::execute()
33
33
{
34
 
  TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
35
 
  TableList *all_tables= session->lex->query_tables;
 
34
  TableList *first_table= (TableList *) getSession()->lex->select_lex.table_list.first;
 
35
  TableList *all_tables= getSession()->lex->query_tables;
36
36
  assert(first_table == all_tables && first_table != 0);
37
37
  TableList *table;
 
38
 
 
39
  if (getSession()->inTransaction())
 
40
  {
 
41
    my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
 
42
    return true;
 
43
  }
 
44
 
38
45
  for (table= first_table; table; table= table->next_local->next_local)
39
46
  {
40
47
    TableList old_list, new_list;
46
53
    new_list= table->next_local[0];
47
54
  }
48
55
 
49
 
  if (! session->endActiveTransaction() || renameTables(first_table))
 
56
  if (renameTables(first_table))
50
57
  {
51
58
    return true;
52
59
  }
 
60
 
53
61
  return false;
54
62
}
55
63
 
62
70
    Avoid problems with a rename on a table that we have locked or
63
71
    if the user is trying to to do this in a transcation context
64
72
  */
65
 
  if (session->inTransaction())
 
73
  if (getSession()->inTransaction())
66
74
  {
67
75
    my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
68
76
    return true;
69
77
  }
70
78
 
71
 
  if (session->wait_if_global_read_lock(false, true))
 
79
  if (getSession()->wait_if_global_read_lock(false, true))
72
80
    return true;
73
81
 
74
82
  {
75
83
    boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex()); /* Rename table lock for exclusive access */
76
84
 
77
 
    if (not session->lock_table_names_exclusively(table_list))
 
85
    if (not getSession()->lock_table_names_exclusively(table_list))
78
86
    {
79
87
      error= false;
80
88
      ren_table= renameTablesInList(table_list, false);
107
115
  /* Lets hope this doesn't fail as the result will be messy */
108
116
  if (not error)
109
117
  {
110
 
    write_bin_log(session, *session->getQueryString());
111
 
    session->my_ok();
 
118
    write_bin_log(getSession(), *getSession()->getQueryString());
 
119
    getSession()->my_ok();
112
120
  }
113
121
 
114
 
  session->startWaitingGlobalReadLock();
 
122
  getSession()->startWaitingGlobalReadLock();
115
123
 
116
124
  return error;
117
125
}
148
156
 
149
157
  identifier::Table old_identifier(ren_table->getSchemaName(), old_alias, message::Table::STANDARD);
150
158
 
151
 
  if (plugin::StorageEngine::getTableDefinition(*session, old_identifier, table_proto) != EEXIST)
 
159
  if (plugin::StorageEngine::getTableDefinition(*getSession(), old_identifier, table_proto) != EEXIST)
152
160
  {
153
161
    my_error(ER_NO_SUCH_TABLE, MYF(0), ren_table->getSchemaName(), old_alias);
154
162
    return true;
155
163
  }
156
164
 
157
 
  engine= plugin::StorageEngine::findByName(*session, table_proto->engine().name());
 
165
  engine= plugin::StorageEngine::findByName(*getSession(), table_proto->engine().name());
158
166
 
159
167
  identifier::Table new_identifier(new_db, new_alias, message::Table::STANDARD);
160
 
  if (plugin::StorageEngine::doesTableExist(*session, new_identifier))
 
168
  if (plugin::StorageEngine::doesTableExist(*getSession(), new_identifier))
161
169
  {
162
170
    my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
163
171
    return 1; // This can't be skipped
164
172
  }
165
173
 
166
 
  rc= rename_table(*session, engine, old_identifier, new_identifier);
 
174
  rc= rename_table(*getSession(), engine, old_identifier, new_identifier);
167
175
  if (rc && ! skip_error)
168
176
    return true;
169
177