summaryrefslogtreecommitdiff
path: root/sql/sql_rename.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_rename.cc')
-rw-r--r--sql/sql_rename.cc19
1 files changed, 13 insertions, 6 deletions
diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc
index fc87356e452..0e0b8eb60b9 100644
--- a/sql/sql_rename.cc
+++ b/sql/sql_rename.cc
@@ -244,7 +244,7 @@ do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name,
char *new_table_alias, bool skip_error)
{
int rc= 1;
- char name[FN_REFLEN];
+ char name[FN_REFLEN + 1];
const char *new_alias, *old_alias;
frm_type_enum frm_type;
enum legacy_db_type table_type;
@@ -261,14 +261,16 @@ do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name,
old_alias= ren_table->table_name;
new_alias= new_table_name;
}
- build_table_filename(name, sizeof(name),
+ DBUG_ASSERT(new_alias);
+
+ build_table_filename(name, sizeof(name) - 1,
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),
+ build_table_filename(name, sizeof(name) - 1,
ren_table->db, old_alias, reg_ext, 0);
frm_type= mysql_frm_type(thd, name, &table_type);
@@ -301,12 +303,17 @@ do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name,
}
break;
case FRMTYPE_VIEW:
- /* change of schema is not allowed */
- if (strcmp(ren_table->db, new_db))
+ /*
+ change of schema is not allowed
+ except of ALTER ...UPGRADE DATA DIRECTORY NAME command
+ because a view has valid internal db&table names in this case.
+ */
+ if (thd->lex->sql_command != SQLCOM_ALTER_DB_UPGRADE &&
+ 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);
+ rc= mysql_rename_view(thd, new_db, new_alias, ren_table);
break;
default:
DBUG_ASSERT(0); // should never happen