diff options
Diffstat (limited to 'sql/sql_rename.cc')
-rw-r--r-- | sql/sql_rename.cc | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc index 3880aa428b9..154e828b47e 100644 --- a/sql/sql_rename.cc +++ b/sql/sql_rename.cc @@ -133,11 +133,12 @@ static TABLE_LIST * rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error) { TABLE_LIST *ren_table,*new_table; + frm_type_enum frm_type; DBUG_ENTER("rename_tables"); for (ren_table= table_list; ren_table; ren_table= new_table->next_local) { - db_type table_type; + int rc= 1; char name[FN_REFLEN]; const char *new_alias, *old_alias; @@ -164,19 +165,36 @@ rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error) ren_table->db, old_alias, reg_ext); unpack_filename(name, name); - if ((table_type=get_table_type(thd, name)) == DB_TYPE_UNKNOWN) - { - my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno); - if (!skip_error) - DBUG_RETURN(ren_table); - } - else if (mysql_rename_table(table_type, - ren_table->db, old_alias, - new_table->db, new_alias)) + + frm_type= mysql_frm_type(name); + switch (frm_type) { - if (!skip_error) - DBUG_RETURN(ren_table); + case FRMTYPE_TABLE: + { + db_type table_type; + if ((table_type= get_table_type(thd, name)) == DB_TYPE_UNKNOWN) + my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno); + else + rc= mysql_rename_table(table_type, ren_table->db, old_alias, + new_table->db, new_alias); + 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; } + if (rc && !skip_error) + DBUG_RETURN(ren_table); } DBUG_RETURN(0); } |