~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_rename.cc

  • Committer: Brian Aker
  • Date: 2008-07-20 07:36:57 UTC
  • Revision ID: brian@tangent.org-20080720073657-qrzqnfu31mut8vjd
my_bool...

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
{
34
34
  bool error= 1;
35
35
  TABLE_LIST *ren_table= 0;
36
 
  DBUG_ENTER("mysql_rename_tables");
37
36
 
38
37
  /*
39
38
    Avoid problems with a rename on a table that we have locked or
40
39
    if the user is trying to to do this in a transcation context
41
40
  */
42
 
 
43
41
  if (thd->locked_tables || thd->active_transaction())
44
42
  {
45
43
    my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
46
44
               ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
47
 
    DBUG_RETURN(1);
 
45
    return(1);
48
46
  }
49
47
 
50
 
  mysql_ha_rm_tables(thd, table_list, FALSE);
 
48
  mysql_ha_rm_tables(thd, table_list, false);
51
49
 
52
50
  if (wait_if_global_read_lock(thd,0,1))
53
 
    DBUG_RETURN(1);
 
51
    return(1);
54
52
 
55
53
  pthread_mutex_lock(&LOCK_open);
56
54
  if (lock_table_names_exclusively(thd, table_list))
93
91
  /* Lets hope this doesn't fail as the result will be messy */ 
94
92
  if (!silent && !error)
95
93
  {
96
 
    write_bin_log(thd, TRUE, thd->query, thd->query_length);
 
94
    write_bin_log(thd, true, thd->query, thd->query_length);
97
95
    my_ok(thd);
98
96
  }
99
97
 
103
101
 
104
102
err:
105
103
  start_waiting_global_read_lock(thd);
106
 
  DBUG_RETURN(error);
 
104
  return(error);
107
105
}
108
106
 
109
107
 
159
157
  int rc= 1;
160
158
  char name[FN_REFLEN];
161
159
  const char *new_alias, *old_alias;
162
 
  enum legacy_db_type table_type;
163
 
 
164
 
  DBUG_ENTER("do_rename");
 
160
  /* TODO: What should this really be set to - it doesn't
 
161
     get set anywhere before it's used? */
 
162
  enum legacy_db_type table_type=DB_TYPE_UNKNOWN;
165
163
 
166
164
  if (lower_case_table_names == 2)
167
165
  {
178
176
  if (!access(name,F_OK))
179
177
  {
180
178
    my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
181
 
    DBUG_RETURN(1);                     // This can't be skipped
 
179
    return(1);                  // This can't be skipped
182
180
  }
183
181
  build_table_filename(name, sizeof(name),
184
182
                       ren_table->db, old_alias, reg_ext, 0);
185
183
 
186
 
  rc= mysql_rename_table(ha_resolve_by_legacy_type(thd, table_type), 
 
184
  rc= mysql_rename_table(ha_resolve_by_legacy_type(thd, table_type),
187
185
                               ren_table->db, old_alias,
188
186
                               new_db, new_alias, 0);
189
187
  if (rc && !skip_error)
190
 
    DBUG_RETURN(1);
 
188
    return(1);
191
189
 
192
 
  DBUG_RETURN(0);
 
190
  return(0);
193
191
 
194
192
}
195
193
/*
221
219
{
222
220
  TABLE_LIST *ren_table, *new_table;
223
221
 
224
 
  DBUG_ENTER("rename_tables");
225
 
 
226
222
  for (ren_table= table_list; ren_table; ren_table= new_table->next_local)
227
223
  {
228
224
    new_table= ren_table->next_local;
229
225
    if (do_rename(thd, ren_table, new_table->db, new_table->table_name,
230
226
                  new_table->alias, skip_error))
231
 
      DBUG_RETURN(ren_table);
 
227
      return(ren_table);
232
228
  }
233
 
  DBUG_RETURN(0);
 
229
  return(0);
234
230
}