~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_rename.cc

  • Committer: Brian Aker
  • Date: 2008-10-20 04:28:21 UTC
  • mto: (492.3.21 drizzle-clean-code)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: brian@tangent.org-20081020042821-rqqdrccuu8195k3y
Second pass of thd cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include <drizzled/server_includes.h>
20
20
#include <drizzled/drizzled_error_messages.h>
21
21
 
22
 
static TableList *rename_tables(Session *thd, TableList *table_list,
 
22
static TableList *rename_tables(Session *session, TableList *table_list,
23
23
                                 bool skip_error);
24
24
 
25
25
static TableList *reverse_table_list(TableList *table_list);
29
29
  second entry is the new name.
30
30
*/
31
31
 
32
 
bool mysql_rename_tables(Session *thd, TableList *table_list, bool silent)
 
32
bool mysql_rename_tables(Session *session, TableList *table_list, bool silent)
33
33
{
34
34
  bool error= 1;
35
35
  TableList *ren_table= 0;
38
38
    Avoid problems with a rename on a table that we have locked or
39
39
    if the user is trying to to do this in a transcation context
40
40
  */
41
 
  if (thd->locked_tables || thd->active_transaction())
 
41
  if (session->locked_tables || session->active_transaction())
42
42
  {
43
43
    my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
44
44
               ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
45
45
    return(1);
46
46
  }
47
47
 
48
 
  mysql_ha_rm_tables(thd, table_list, false);
 
48
  mysql_ha_rm_tables(session, table_list, false);
49
49
 
50
 
  if (wait_if_global_read_lock(thd,0,1))
 
50
  if (wait_if_global_read_lock(session,0,1))
51
51
    return(1);
52
52
 
53
53
  pthread_mutex_lock(&LOCK_open);
54
 
  if (lock_table_names_exclusively(thd, table_list))
 
54
  if (lock_table_names_exclusively(session, table_list))
55
55
  {
56
56
    pthread_mutex_unlock(&LOCK_open);
57
57
    goto err;
58
58
  }
59
59
 
60
60
  error=0;
61
 
  if ((ren_table=rename_tables(thd,table_list,0)))
 
61
  if ((ren_table=rename_tables(session,table_list,0)))
62
62
  {
63
63
    /* Rename didn't succeed;  rename back the tables in reverse order */
64
64
    TableList *table;
72
72
         table= table->next_local->next_local) ;
73
73
    table= table->next_local->next_local;               // Skip error table
74
74
    /* Revert to old names */
75
 
    rename_tables(thd, table, 1);
 
75
    rename_tables(session, table, 1);
76
76
 
77
77
    /* Revert the table list (for prepared statements) */
78
78
    table_list= reverse_table_list(table_list);
91
91
  /* Lets hope this doesn't fail as the result will be messy */ 
92
92
  if (!silent && !error)
93
93
  {
94
 
    write_bin_log(thd, true, thd->query, thd->query_length);
95
 
    my_ok(thd);
 
94
    write_bin_log(session, true, session->query, session->query_length);
 
95
    my_ok(session);
96
96
  }
97
97
 
98
98
  pthread_mutex_lock(&LOCK_open);
99
 
  unlock_table_names(thd, table_list, (TableList*) 0);
 
99
  unlock_table_names(session, table_list, (TableList*) 0);
100
100
  pthread_mutex_unlock(&LOCK_open);
101
101
 
102
102
err:
103
 
  start_waiting_global_read_lock(thd);
 
103
  start_waiting_global_read_lock(session);
104
104
  return(error);
105
105
}
106
106
 
135
135
 
136
136
  SYNPOSIS
137
137
    do_rename()
138
 
      thd               Thread handle
 
138
      session               Thread handle
139
139
      ren_table         A table/view to be renamed
140
140
      new_db            The database to which the table to be moved to
141
141
      new_table_name    The new table/view name
151
151
*/
152
152
 
153
153
bool
154
 
do_rename(Session *thd, TableList *ren_table, char *new_db, char *new_table_name,
 
154
do_rename(Session *session, TableList *ren_table, char *new_db, char *new_table_name,
155
155
          char *new_table_alias, bool skip_error)
156
156
{
157
157
  int rc= 1;
181
181
  build_table_filename(name, sizeof(name),
182
182
                       ren_table->db, old_alias, reg_ext, 0);
183
183
 
184
 
  rc= mysql_rename_table(ha_resolve_by_legacy_type(thd, table_type),
 
184
  rc= mysql_rename_table(ha_resolve_by_legacy_type(session, table_type),
185
185
                               ren_table->db, old_alias,
186
186
                               new_db, new_alias, 0);
187
187
  if (rc && !skip_error)
200
200
 
201
201
  SYNPOSIS
202
202
    rename_tables()
203
 
      thd               Thread handle
 
203
      session               Thread handle
204
204
      table_list        List of tables to rename
205
205
      skip_error        Whether to skip errors
206
206
 
215
215
*/
216
216
 
217
217
static TableList *
218
 
rename_tables(Session *thd, TableList *table_list, bool skip_error)
 
218
rename_tables(Session *session, TableList *table_list, bool skip_error)
219
219
{
220
220
  TableList *ren_table, *new_table;
221
221
 
222
222
  for (ren_table= table_list; ren_table; ren_table= new_table->next_local)
223
223
  {
224
224
    new_table= ren_table->next_local;
225
 
    if (do_rename(thd, ren_table, new_table->db, new_table->table_name,
 
225
    if (do_rename(session, ren_table, new_table->db, new_table->table_name,
226
226
                  new_table->alias, skip_error))
227
227
      return(ren_table);
228
228
  }