~clint-fewbar/ubuntu/natty/drizzle/beta1-fixes

« back to all changes in this revision

Viewing changes to drizzled/statement/rename_table.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2011-03-15 10:41:18 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20110315104118-eaf0hvlytjdl4zrf
Tags: 2011.03.13-0ubuntu1
* New upstream release.
* Added slave plugin.
* Removed archive, blackhole and blitzdb plugins.
* Moved location of libdrizzle headers.
* Removed drizzleadmin manpage patch.
* Add drizzle_safe_write_string to symbols.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <drizzled/lock.h>
24
24
#include <drizzled/session.h>
25
25
#include <drizzled/statement/rename_table.h>
26
 
#include <drizzled/sql_table.h>
27
26
#include <drizzled/pthread_globals.h>
28
27
#include <drizzled/plugin/storage_engine.h>
 
28
#include <drizzled/transaction_services.h>
29
29
 
30
30
namespace drizzled
31
31
{
32
32
 
33
33
bool statement::RenameTable::execute()
34
34
{
35
 
  TableList *first_table= (TableList *) getSession()->getLex()->select_lex.table_list.first;
36
 
  TableList *all_tables= getSession()->getLex()->query_tables;
 
35
  TableList *first_table= (TableList *) lex().select_lex.table_list.first;
 
36
  TableList *all_tables= lex().query_tables;
37
37
  assert(first_table == all_tables && first_table != 0);
38
38
  TableList *table;
39
39
 
40
 
  if (getSession()->inTransaction())
 
40
  if (session().inTransaction())
41
41
  {
42
42
    my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
43
43
    return true;
71
71
    Avoid problems with a rename on a table that we have locked or
72
72
    if the user is trying to to do this in a transcation context
73
73
  */
74
 
  if (getSession()->inTransaction())
 
74
  if (session().inTransaction())
75
75
  {
76
76
    my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
77
77
    return true;
78
78
  }
79
79
 
80
 
  if (getSession()->wait_if_global_read_lock(false, true))
 
80
  if (session().wait_if_global_read_lock(false, true))
81
81
    return true;
82
82
 
83
83
  {
84
84
    boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex()); /* Rename table lock for exclusive access */
85
85
 
86
 
    if (not getSession()->lock_table_names_exclusively(table_list))
 
86
    if (not session().lock_table_names_exclusively(table_list))
87
87
    {
88
88
      error= false;
89
89
      ren_table= renameTablesInList(table_list, false);
116
116
  /* Lets hope this doesn't fail as the result will be messy */
117
117
  if (not error)
118
118
  {
119
 
    write_bin_log(getSession(), *getSession()->getQueryString());
120
 
    getSession()->my_ok();
 
119
    TransactionServices &transaction_services= TransactionServices::singleton();
 
120
    transaction_services.rawStatement(session(),
 
121
                                      *session().getQueryString(),
 
122
                                      *session().schema());        
 
123
    session().my_ok();
121
124
  }
122
125
 
123
 
  getSession()->startWaitingGlobalReadLock();
 
126
  session().startWaitingGlobalReadLock();
124
127
 
125
128
  return error;
126
129
}
157
160
 
158
161
  identifier::Table old_identifier(ren_table->getSchemaName(), old_alias, message::Table::STANDARD);
159
162
 
160
 
  if (not (table_message= plugin::StorageEngine::getTableMessage(*getSession(), old_identifier)))
 
163
  if (not (table_message= plugin::StorageEngine::getTableMessage(session(), old_identifier)))
161
164
  {
162
165
    my_error(ER_TABLE_UNKNOWN, old_identifier);
163
166
    return true;
164
167
  }
165
168
 
166
 
  engine= plugin::StorageEngine::findByName(*getSession(), table_message->engine().name());
 
169
  engine= plugin::StorageEngine::findByName(session(), table_message->engine().name());
167
170
 
168
171
  identifier::Table new_identifier(new_db, new_alias, message::Table::STANDARD);
169
 
  if (plugin::StorageEngine::doesTableExist(*getSession(), new_identifier))
 
172
  if (plugin::StorageEngine::doesTableExist(session(), new_identifier))
170
173
  {
171
174
    my_error(ER_TABLE_EXISTS_ERROR, new_identifier);
172
175
    return 1; // This can't be skipped
173
176
  }
174
177
 
175
 
  rc= rename_table(*getSession(), engine, old_identifier, new_identifier);
 
178
  rc= rename_table(session(), engine, old_identifier, new_identifier);
176
179
  if (rc && ! skip_error)
177
180
    return true;
178
181