summaryrefslogtreecommitdiff
path: root/sql/sql_rename.cc
diff options
context:
space:
mode:
authorunknown <gkodinov@dl145s.mysql.com>2006-10-19 16:43:46 +0200
committerunknown <gkodinov@dl145s.mysql.com>2006-10-19 16:43:46 +0200
commitfcbf1509e22e9c27910d5beacb6d105e81d2a6b3 (patch)
tree1d4b8a5dec4c6f52e2b5a119df93d2225083cb70 /sql/sql_rename.cc
parentf4f15b54351dcb02bbe99251e2fbab5317c95ee6 (diff)
parent5e1fe0f80043993c1db64169e4d87eb787762763 (diff)
downloadmariadb-git-fcbf1509e22e9c27910d5beacb6d105e81d2a6b3.tar.gz
Merge dl145s.mysql.com:/data/bk/team_tree_merge/MERGE/mysql-5.0-opt
into dl145s.mysql.com:/data/bk/team_tree_merge/MERGE/mysql-5.1-opt BitKeeper/deleted/.del-bdb.result: Auto merged mysql-test/r/func_gconcat.result: Auto merged mysql-test/r/group_min_max.result: Auto merged mysql-test/r/innodb.result: Auto merged mysql-test/r/merge.result: Auto merged mysql-test/r/myisam.result: Auto merged mysql-test/r/olap.result: Auto merged mysql-test/r/select.result: Auto merged mysql-test/r/type_decimal.result: Auto merged mysql-test/r/view.result: Auto merged mysql-test/t/func_gconcat.test: Auto merged mysql-test/t/group_min_max.test: Auto merged mysql-test/t/select.test: Auto merged sql/item_cmpfunc.cc: Auto merged sql/item_cmpfunc.h: Auto merged sql/opt_range.cc: Auto merged sql/opt_range.h: Auto merged sql/sql_base.cc: Auto merged sql/sql_delete.cc: Auto merged sql/sql_lex.cc: Auto merged sql/sql_lex.h: Auto merged sql/sql_select.h: Auto merged sql/sql_update.cc: Auto merged sql/table.cc: Auto merged include/my_base.h: SCCS merged mysql-test/include/mix1.inc: SCCS merged mysql-test/r/group_by.result: SCCS merged mysql-test/r/innodb_mysql.result: SCCS merged mysql-test/t/group_by.test: SCCS merged sql/sql_select.cc: SCCS merged
Diffstat (limited to 'sql/sql_rename.cc')
-rw-r--r--sql/sql_rename.cc192
1 files changed, 119 insertions, 73 deletions
diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc
index 73473ddd24b..8b04345640b 100644
--- a/sql/sql_rename.cc
+++ b/sql/sql_rename.cc
@@ -126,95 +126,141 @@ static TABLE_LIST *reverse_table_list(TABLE_LIST *table_list)
/*
- Rename all tables in list; Return pointer to wrong entry if something goes
- wrong. Note that the table_list may be empty!
+ Rename a single table or a view
+
+ SYNPOSIS
+ do_rename()
+ thd Thread handle
+ ren_table A table/view to be renamed
+ new_db The database to which the table to be moved to
+ new_table_name The new table/view name
+ new_table_alias The new table/view alias
+ skip_error Whether to skip error
+
+ DESCRIPTION
+ Rename a single table or a view.
+
+ RETURN
+ false Ok
+ true rename failed
*/
-static TABLE_LIST *
-rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error)
+bool
+do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name,
+ char *new_table_alias, bool skip_error)
{
- TABLE_LIST *ren_table,*new_table;
+ int rc= 1;
+ char name[FN_REFLEN];
+ const char *new_alias, *old_alias;
frm_type_enum frm_type;
enum legacy_db_type table_type;
- DBUG_ENTER("rename_tables");
+ DBUG_ENTER("do_rename");
- for (ren_table= table_list; ren_table; ren_table= new_table->next_local)
+ if (lower_case_table_names == 2)
{
- int rc= 1;
- char name[FN_REFLEN];
- const char *new_alias, *old_alias;
-
- new_table= ren_table->next_local;
- if (lower_case_table_names == 2)
- {
- old_alias= ren_table->alias;
- new_alias= new_table->alias;
- }
- else
- {
- old_alias= ren_table->table_name;
- new_alias= new_table->table_name;
- }
- build_table_filename(name, sizeof(name),
- new_table->db, new_alias, reg_ext, 0);
- if (!access(name,F_OK))
- {
- my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
- DBUG_RETURN(ren_table); // This can't be skipped
- }
- build_table_filename(name, sizeof(name),
- ren_table->db, old_alias, reg_ext, 0);
+ old_alias= ren_table->alias;
+ new_alias= new_table_alias;
+ }
+ else
+ {
+ old_alias= ren_table->table_name;
+ new_alias= new_table_table_name;
+ }
+ build_table_filename(name, sizeof(name),
+ new_db, new_alias, reg_ext, 0);
+ if (!access(name,F_OK))
+ {
+ my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
+ DBUG_RETURN(1); // This can't be skipped
+ }
+ build_table_filename(name, sizeof(name),
+ ren_table->db, old_alias, reg_ext, 0);
- frm_type= mysql_frm_type(thd, name, &table_type);
- switch (frm_type)
- {
- case FRMTYPE_TABLE:
+ frm_type= mysql_frm_type(thd, name, &table_type);
+ switch (frm_type)
+ {
+ case FRMTYPE_TABLE:
{
- if (table_type == DB_TYPE_UNKNOWN)
- my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno);
- else
+ if (!(rc= mysql_rename_table(table_type, ren_table->db, old_alias,
+ new_db, new_alias)))
{
- if (!(rc= mysql_rename_table(ha_resolve_by_legacy_type(thd,
- table_type),
- ren_table->db, old_alias,
- new_table->db, new_alias, 0)))
+ if ((rc= Table_triggers_list::change_table_name(thd, ren_table->db,
+ old_alias,
+ new_db,
+ new_alias)))
{
- if ((rc= Table_triggers_list::change_table_name(thd, ren_table->db,
- old_alias,
- new_table->db,
- new_alias)))
- {
- /*
- We've succeeded in renaming table's .frm and in updating
- corresponding handler data, but have failed to update table's
- triggers appropriately. So let us revert operations on .frm
- and handler's data and report about failure to rename table.
- */
- (void) mysql_rename_table(ha_resolve_by_legacy_type(thd,
- table_type),
- new_table->db, new_alias,
- ren_table->db, old_alias, 0);
- }
+ /*
+ We've succeeded in renaming table's .frm and in updating
+ corresponding handler data, but have failed to update table's
+ triggers appropriately. So let us revert operations on .frm
+ and handler's data and report about failure to rename table.
+ */
+ (void) mysql_rename_table(ha_resolve_by_legacy_type(thd,
+ table_type),
+ new_db, new_alias,
+ ren_table->db, old_alias, 0);
}
}
- break;
}
- case FRMTYPE_VIEW:
- /* change of schema is not allowed */
- if (strcmp(ren_table->db, new_table->db))
- my_error(ER_FORBID_SCHEMA_CHANGE, MYF(0), ren_table->db,
- new_table->db);
- else
- rc= mysql_rename_view(thd, new_alias, ren_table);
- break;
- default:
- DBUG_ASSERT(0); // should never happen
- case FRMTYPE_ERROR:
- my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno);
- break;
+ break;
}
- if (rc && !skip_error)
+ case FRMTYPE_VIEW:
+ /* change of schema is not allowed */
+ if (strcmp(ren_table->db, new_db))
+ my_error(ER_FORBID_SCHEMA_CHANGE, MYF(0), ren_table->db,
+ new_db);
+ else
+ rc= mysql_rename_view(thd, new_alias, ren_table);
+ break;
+ default:
+ DBUG_ASSERT(0); // should never happen
+ case FRMTYPE_ERROR:
+ my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno);
+ break;
+ }
+ if (rc && !skip_error)
+ DBUG_RETURN(1);
+
+ DBUG_RETURN(0);
+
+}
+/*
+ Rename all tables in list; Return pointer to wrong entry if something goes
+ wrong. Note that the table_list may be empty!
+*/
+
+/*
+ Rename tables/views in the list
+
+ SYNPOSIS
+ rename_tables()
+ thd Thread handle
+ table_list List of tables to rename
+ skip_error Whether to skip errors
+
+ DESCRIPTION
+ Take a table/view name from and odd list element and rename it to a
+ the name taken from list element+1. Note that the table_list may be
+ empty.
+
+ RETURN
+ false Ok
+ true rename failed
+*/
+
+static TABLE_LIST *
+rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error)
+{
+ TABLE_LIST *ren_table,*new_table, *tmp_table;
+
+ DBUG_ENTER("rename_tables");
+
+ for (ren_table= table_list; ren_table; ren_table= new_table->next_local)
+ {
+ new_table= ren_table->next_local;
+ if (do_rename(thd, ren_table, new_table->db, new_table->table_name,
+ new_table->alias, skip_error))
DBUG_RETURN(ren_table);
}
DBUG_RETURN(0);