~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/rename_table.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 00:53:34 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913005334-6wio2sbjugskfbm3
Added calls to the connection start/end dtrace probes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
 
21
#include <drizzled/server_includes.h>
22
22
#include <drizzled/show.h>
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
 
#include "drizzled/pthread_globals.h"
28
26
 
29
 
namespace drizzled
30
 
{
 
27
using namespace drizzled;
31
28
 
32
29
bool statement::RenameTable::execute()
33
30
{
110
107
  /* Lets hope this doesn't fail as the result will be messy */
111
108
  if (! error)
112
109
  {
113
 
    write_bin_log(session, session->query.c_str());
 
110
    write_bin_log(session, true, session->query, session->query_length);
114
111
    session->my_ok();
115
112
  }
116
113
 
151
148
    new_alias= new_table_name;
152
149
  }
153
150
 
154
 
  plugin::StorageEngine *engine= NULL;
 
151
  StorageEngine *engine= NULL;
155
152
  message::Table table_proto;
156
 
 
157
 
  TableIdentifier old_identifier(ren_table->db, old_alias, message::Table::STANDARD);
158
 
 
159
 
  if (plugin::StorageEngine::getTableDefinition(*session, old_identifier, table_proto) != EEXIST)
 
153
  char path[FN_REFLEN];
 
154
  size_t length;
 
155
 
 
156
  length= build_table_filename(path, sizeof(path),
 
157
                               ren_table->db, old_alias, false);
 
158
 
 
159
  if (StorageEngine::getTableProto(path, &table_proto)!= EEXIST)
160
160
  {
161
161
    my_error(ER_NO_SUCH_TABLE, MYF(0), ren_table->db, old_alias);
162
162
    return true;
163
163
  }
164
164
 
165
 
  engine= plugin::StorageEngine::findByName(*session, table_proto.engine().name());
166
 
 
167
 
  TableIdentifier new_identifier(new_db, new_alias, message::Table::STANDARD);
168
 
  if (plugin::StorageEngine::doesTableExist(*session, new_identifier))
 
165
  engine= ha_resolve_by_name(session, table_proto.engine().name());
 
166
 
 
167
  length= build_table_filename(path, sizeof(path),
 
168
                               new_db, new_alias, false);
 
169
 
 
170
  if (StorageEngine::getTableProto(path, NULL)!=ENOENT)
169
171
  {
170
172
    my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
171
173
    return 1; // This can't be skipped
172
174
  }
173
175
 
174
 
  rc= mysql_rename_table(engine, old_identifier, new_identifier, 0);
 
176
  rc= mysql_rename_table(engine,
 
177
                         ren_table->db, old_alias,
 
178
                         new_db, new_alias, 0);
175
179
  if (rc && ! skip_error)
176
180
    return true;
177
181
 
191
195
  }
192
196
  return 0;
193
197
}
194
 
 
195
 
} /* namespace drizzled */