Loading mysql-test/r/view.result +9 −0 Original line number Diff line number Diff line Loading @@ -845,6 +845,15 @@ select * from v1; cast(1 as char(3)) 1 drop view v1; create table t1 (a int); create view v1 as select a from t1; create database seconddb; rename table v1 to seconddb.v1; ERROR HY000: Changing schema from 'test' to 'seconddb' is not allowed. rename table v1 to v2; drop table t1; drop view v2; drop database seconddb; create view v1 as select 'a',1; create view v2 as select * from v1 union all select * from v1; create view v3 as select * from v2 where 1 = (select `1` from v2); Loading mysql-test/t/view.test +13 −0 Original line number Diff line number Diff line Loading @@ -785,6 +785,19 @@ show create view v1; select * from v1; drop view v1; # # renaming views # create table t1 (a int); create view v1 as select a from t1; create database seconddb; -- error 1450 rename table v1 to seconddb.v1; rename table v1 to v2; drop table t1; drop view v2; drop database seconddb; # # bug handling from VIEWs # Loading sql/parse_file.cc +53 −0 Original line number Diff line number Diff line Loading @@ -333,6 +333,59 @@ sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name, DBUG_RETURN(TRUE); } /* Renames a frm file (including backups) in same schema SYNOPSIS rename_in_schema_file schema name of given schema old_name original file name new_name new file name revision revision number num_view_backups number of backups RETURN 0 - OK 1 - Error (only if renaming of frm failed) */ my_bool rename_in_schema_file(const char *schema, const char *old_name, const char *new_name, ulonglong revision, uint num_view_backups) { char old_path[FN_REFLEN], new_path[FN_REFLEN], arc_path[FN_REFLEN]; strxnmov(old_path, FN_REFLEN, mysql_data_home, "/", schema, "/", old_name, reg_ext, NullS); (void) unpack_filename(old_path, old_path); strxnmov(new_path, FN_REFLEN, mysql_data_home, "/", schema, "/", new_name, reg_ext, NullS); (void) unpack_filename(new_path, new_path); if (my_rename(old_path, new_path, MYF(MY_WME))) return 1; /* check if arc_dir exists */ strxnmov(arc_path, FN_REFLEN, mysql_data_home, "/", schema, "/arc", NullS); (void) unpack_filename(arc_path, arc_path); if (revision > 0 && !access(arc_path, F_OK)) { ulonglong limit= (revision > num_view_backups) ? revision - num_view_backups : 0; while (revision > limit) { my_snprintf(old_path, FN_REFLEN, "%s/%s%s-%04lu", arc_path, old_name, reg_ext, (ulong)revision); (void) unpack_filename(old_path, old_path); my_snprintf(new_path, FN_REFLEN, "%s/%s%s-%04lu", arc_path, new_name, reg_ext, (ulong)revision); (void) unpack_filename(new_path, new_path); my_rename(old_path, new_path, MYF(0)); revision--; } } return 0; } /* Prepare frm to parse (read to memory) Loading sql/parse_file.h +3 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,9 @@ my_bool sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name, const LEX_STRING *type, gptr base, File_option *parameters, uint versions); my_bool rename_in_schema_file(const char *schema, const char *old_name, const char *new_name, ulonglong revision, uint num_view_backups); class File_parser: public Sql_alloc { Loading sql/share/errmsg.txt +2 −0 Original line number Diff line number Diff line Loading @@ -5413,3 +5413,5 @@ ER_VIEW_OTHER_USER eng "You need the SUPER privilege for creation view with %-.64s@%-.64s definer" ER_NO_SUCH_USER eng "There is not %-.64s@%-.64s registered" ER_FORBID_SCHEMA_CHANGE eng "Changing schema from '%-.64s' to '%-.64s' is not allowed." Loading
mysql-test/r/view.result +9 −0 Original line number Diff line number Diff line Loading @@ -845,6 +845,15 @@ select * from v1; cast(1 as char(3)) 1 drop view v1; create table t1 (a int); create view v1 as select a from t1; create database seconddb; rename table v1 to seconddb.v1; ERROR HY000: Changing schema from 'test' to 'seconddb' is not allowed. rename table v1 to v2; drop table t1; drop view v2; drop database seconddb; create view v1 as select 'a',1; create view v2 as select * from v1 union all select * from v1; create view v3 as select * from v2 where 1 = (select `1` from v2); Loading
mysql-test/t/view.test +13 −0 Original line number Diff line number Diff line Loading @@ -785,6 +785,19 @@ show create view v1; select * from v1; drop view v1; # # renaming views # create table t1 (a int); create view v1 as select a from t1; create database seconddb; -- error 1450 rename table v1 to seconddb.v1; rename table v1 to v2; drop table t1; drop view v2; drop database seconddb; # # bug handling from VIEWs # Loading
sql/parse_file.cc +53 −0 Original line number Diff line number Diff line Loading @@ -333,6 +333,59 @@ sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name, DBUG_RETURN(TRUE); } /* Renames a frm file (including backups) in same schema SYNOPSIS rename_in_schema_file schema name of given schema old_name original file name new_name new file name revision revision number num_view_backups number of backups RETURN 0 - OK 1 - Error (only if renaming of frm failed) */ my_bool rename_in_schema_file(const char *schema, const char *old_name, const char *new_name, ulonglong revision, uint num_view_backups) { char old_path[FN_REFLEN], new_path[FN_REFLEN], arc_path[FN_REFLEN]; strxnmov(old_path, FN_REFLEN, mysql_data_home, "/", schema, "/", old_name, reg_ext, NullS); (void) unpack_filename(old_path, old_path); strxnmov(new_path, FN_REFLEN, mysql_data_home, "/", schema, "/", new_name, reg_ext, NullS); (void) unpack_filename(new_path, new_path); if (my_rename(old_path, new_path, MYF(MY_WME))) return 1; /* check if arc_dir exists */ strxnmov(arc_path, FN_REFLEN, mysql_data_home, "/", schema, "/arc", NullS); (void) unpack_filename(arc_path, arc_path); if (revision > 0 && !access(arc_path, F_OK)) { ulonglong limit= (revision > num_view_backups) ? revision - num_view_backups : 0; while (revision > limit) { my_snprintf(old_path, FN_REFLEN, "%s/%s%s-%04lu", arc_path, old_name, reg_ext, (ulong)revision); (void) unpack_filename(old_path, old_path); my_snprintf(new_path, FN_REFLEN, "%s/%s%s-%04lu", arc_path, new_name, reg_ext, (ulong)revision); (void) unpack_filename(new_path, new_path); my_rename(old_path, new_path, MYF(0)); revision--; } } return 0; } /* Prepare frm to parse (read to memory) Loading
sql/parse_file.h +3 −0 Original line number Diff line number Diff line Loading @@ -48,6 +48,9 @@ my_bool sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name, const LEX_STRING *type, gptr base, File_option *parameters, uint versions); my_bool rename_in_schema_file(const char *schema, const char *old_name, const char *new_name, ulonglong revision, uint num_view_backups); class File_parser: public Sql_alloc { Loading
sql/share/errmsg.txt +2 −0 Original line number Diff line number Diff line Loading @@ -5413,3 +5413,5 @@ ER_VIEW_OTHER_USER eng "You need the SUPER privilege for creation view with %-.64s@%-.64s definer" ER_NO_SUCH_USER eng "There is not %-.64s@%-.64s registered" ER_FORBID_SCHEMA_CHANGE eng "Changing schema from '%-.64s' to '%-.64s' is not allowed."