summaryrefslogtreecommitdiff
path: root/sql/sql_rename.cc
diff options
context:
space:
mode:
authorpem@mysql.com <>2004-04-07 19:07:44 +0200
committerpem@mysql.com <>2004-04-07 19:07:44 +0200
commitdfd59e296e2c267a21f1ea8b3b937e07730dad0d (patch)
treee5ac1517ff3dccc42352b7bac39ecd1c093d0ae6 /sql/sql_rename.cc
parent1541f2e7949416d6e172ef6406ecf140d3b26659 (diff)
parent61fd95d168b51092b7ce3ff56b2c8c8ed1a49c0f (diff)
downloadmariadb-git-dfd59e296e2c267a21f1ea8b3b937e07730dad0d.tar.gz
Merge 4.1 -> 5.0.
Diffstat (limited to 'sql/sql_rename.cc')
-rw-r--r--sql/sql_rename.cc73
1 files changed, 56 insertions, 17 deletions
diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc
index 29b4f2f4a01..a1676aed78d 100644
--- a/sql/sql_rename.cc
+++ b/sql/sql_rename.cc
@@ -24,6 +24,8 @@
static TABLE_LIST *rename_tables(THD *thd, TABLE_LIST *table_list,
bool skip_error);
+static TABLE_LIST *reverse_table_list(TABLE_LIST *table_list);
+
/*
Every second entry in the table_list is the original name and every
second entry is the new name.
@@ -46,6 +48,8 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list)
DBUG_RETURN(1);
}
+ if (wait_if_global_read_lock(thd,0))
+ DBUG_RETURN(1);
VOID(pthread_mutex_lock(&LOCK_open));
if (lock_table_names(thd, table_list))
goto err;
@@ -54,17 +58,10 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list)
if ((ren_table=rename_tables(thd,table_list,0)))
{
/* Rename didn't succeed; rename back the tables in reverse order */
- TABLE_LIST *prev=0,*table;
- /* Reverse the table list */
+ TABLE_LIST *table;
- while (table_list)
- {
- TABLE_LIST *next=table_list->next;
- table_list->next=prev;
- prev=table_list;
- table_list=next;
- }
- table_list=prev;
+ /* Reverse the table list */
+ table_list= reverse_table_list(table_list);
/* Find the last renamed table */
for (table=table_list ;
@@ -73,6 +70,10 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list)
table=table->next->next; // Skip error table
/* Revert to old names */
rename_tables(thd, table, 1);
+
+ /* Revert the table list (for prepared statements) */
+ table_list= reverse_table_list(table_list);
+
error= 1;
}
@@ -92,11 +93,37 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list)
err:
pthread_mutex_unlock(&LOCK_open);
+ start_waiting_global_read_lock(thd);
DBUG_RETURN(error);
}
/*
+ reverse table list
+
+ SYNOPSIS
+ reverse_table_list()
+ table_list pointer to table _list
+
+ RETURN
+ pointer to new (reversed) list
+*/
+static TABLE_LIST *reverse_table_list(TABLE_LIST *table_list)
+{
+ TABLE_LIST *prev= 0;
+
+ while (table_list)
+ {
+ TABLE_LIST *next= table_list->next;
+ table_list->next= prev;
+ prev= table_list;
+ table_list= next;
+ }
+ return (prev);
+}
+
+
+/*
Rename all tables in list; Return pointer to wrong entry if something goes
wrong. Note that the table_list may be empty!
*/
@@ -111,19 +138,31 @@ rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error)
{
db_type table_type;
char name[FN_REFLEN];
- new_table=ren_table->next;
+ const char *new_alias, *old_alias;
+ new_table=ren_table->next;
+ if (lower_case_table_names == 2)
+ {
+ old_alias= ren_table->alias;
+ new_alias= new_table->alias;
+ }
+ else
+ {
+ old_alias= ren_table->real_name;
+ new_alias= new_table->real_name;
+ }
sprintf(name,"%s/%s/%s%s",mysql_data_home,
- new_table->db,new_table->real_name,
- reg_ext);
+ new_table->db, new_alias, reg_ext);
+ unpack_filename(name, name);
if (!access(name,F_OK))
{
- my_error(ER_TABLE_EXISTS_ERROR,MYF(0),name);
+ my_error(ER_TABLE_EXISTS_ERROR,MYF(0),new_alias);
DBUG_RETURN(ren_table); // This can't be skipped
}
sprintf(name,"%s/%s/%s%s",mysql_data_home,
- ren_table->db,ren_table->real_name,
+ ren_table->db, old_alias,
reg_ext);
+ unpack_filename(name, name);
if ((table_type=get_table_type(name)) == DB_TYPE_UNKNOWN)
{
my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno);
@@ -131,8 +170,8 @@ rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error)
DBUG_RETURN(ren_table);
}
else if (mysql_rename_table(table_type,
- ren_table->db, ren_table->real_name,
- new_table->db, new_table->real_name))
+ ren_table->db, old_alias,
+ new_table->db, new_alias))
{
if (!skip_error)
DBUG_RETURN(ren_table);