diff options
author | unknown <georg@lmy002.wdf.sap.corp> | 2005-09-16 17:13:21 +0200 |
---|---|---|
committer | unknown <georg@lmy002.wdf.sap.corp> | 2005-09-16 17:13:21 +0200 |
commit | bf58b698e22efe0849fc8ee18fc30e3914d73409 (patch) | |
tree | 42699dfbd0ad93df462e371d7a4a287bd38af876 /sql/sql_rename.cc | |
parent | b34d5bd24733e2e50d4d32c37fa9ebc722177bf2 (diff) | |
download | mariadb-git-bf58b698e22efe0849fc8ee18fc30e3914d73409.tar.gz |
Fix for bug#5508 after Sanja's review
mysql-test/r/view.result:
test results for rename table view1 to view2
mysql-test/t/view.test:
tests for rename table view1 to view2
sql/share/errmsg.txt:
added new errormessage (schema change not allowed in rename table view)
sql/sql_rename.cc:
added support for renaming views
sql/sql_view.cc:
added new function mysql_rename_view
sql/sql_view.h:
added prototype mysql_rename_view
Diffstat (limited to 'sql/sql_rename.cc')
-rw-r--r-- | sql/sql_rename.cc | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc index 3880aa428b9..b848809ccc9 100644 --- a/sql/sql_rename.cc +++ b/sql/sql_rename.cc @@ -133,6 +133,7 @@ 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) @@ -164,18 +165,35 @@ 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) + if ((frm_type= mysql_frm_type(name)) == FRMTYPE_TABLE && + (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); + DBUG_RETURN(ren_table); } - else if (mysql_rename_table(table_type, - ren_table->db, old_alias, - new_table->db, new_alias)) - { - if (!skip_error) - DBUG_RETURN(ren_table); + else { + int rc= 1; + switch (frm_type) + { + case FRMTYPE_TABLE: + 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; + case FRMTYPE_ERROR: + default: + my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno); + } + if (rc && !skip_error) + DBUG_RETURN(ren_table); } } DBUG_RETURN(0); |