~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/rename_table.cc

Namespace the parser just a bit, and update our call for the type of parser
we want.

Show diffs side-by-side

added added

removed removed

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