mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 03:52:35 +01:00
Bug#43385 Cannot ALTER DATABASE ... UPGRADE DATA DIRECTORY NAME when Views exist(addon)
mysql_rename_view can not rename view if database is not the same. The fix is to add new argument 'new_db' to mysql_rename_view() and allow rename with different databases (only for ALTER DATABASE ... UPGRADE DATA DIRECTORY NAME). mysql-test/t/upgrade.test: test fix sql/parse_file.cc: mysql_rename_view can not rename view if database is not the same. The fix is to add new argument 'new_db' to mysql_rename_view() and allow rename with different databases (only for ALTER DATABASE ... UPGRADE DATA DIRECTORY NAME). sql/parse_file.h: mysql_rename_view can not rename view if database is not the same. The fix is to add new argument 'new_db' to mysql_rename_view() and allow rename with different databases (only for ALTER DATABASE ... UPGRADE DATA DIRECTORY NAME). sql/sql_rename.cc: mysql_rename_view can not rename view if database is not the same. The fix is to add new argument 'new_db' to mysql_rename_view() and allow rename with different databases (only for ALTER DATABASE ... UPGRADE DATA DIRECTORY NAME). sql/sql_view.cc: mysql_rename_view can not rename view if database is not the same. The fix is to add new argument 'new_db' to mysql_rename_view() and allow rename with different databases (only for ALTER DATABASE ... UPGRADE DATA DIRECTORY NAME). sql/sql_view.h: mysql_rename_view can not rename view if database is not the same. The fix is to add new argument 'new_db' to mysql_rename_view() and allow rename with different databases (only for ALTER DATABASE ... UPGRADE DATA DIRECTORY NAME).
This commit is contained in:
parent
2187c60bf4
commit
19854c6d8c
6 changed files with 15 additions and 9 deletions
|
@ -116,6 +116,8 @@ show databases like '%a-b-c%';
|
|||
ALTER DATABASE `#mysql50#a-b-c` UPGRADE DATA DIRECTORY NAME;
|
||||
show databases like '%a-b-c%';
|
||||
show create view `a-b-c`.v1;
|
||||
--disable_ps_protocol
|
||||
select * from `a-b-c`.v1;
|
||||
--enable_ps_protocol
|
||||
drop database `a-b-c`;
|
||||
use test;
|
||||
|
|
|
@ -302,6 +302,7 @@ err_w_file:
|
|||
@thd thread handler
|
||||
@param schema name of given schema
|
||||
@param old_name original file name
|
||||
@param new_db new schema
|
||||
@param new_name new file name
|
||||
|
||||
@retval
|
||||
|
@ -311,14 +312,14 @@ err_w_file:
|
|||
*/
|
||||
my_bool rename_in_schema_file(THD *thd,
|
||||
const char *schema, const char *old_name,
|
||||
const char *new_name)
|
||||
const char *new_db, const char *new_name)
|
||||
{
|
||||
char old_path[FN_REFLEN], new_path[FN_REFLEN], arc_path[FN_REFLEN];
|
||||
|
||||
build_table_filename(old_path, sizeof(old_path) - 1,
|
||||
schema, old_name, reg_ext, 0);
|
||||
build_table_filename(new_path, sizeof(new_path) - 1,
|
||||
schema, new_name, reg_ext, 0);
|
||||
new_db, new_name, reg_ext, 0);
|
||||
|
||||
if (my_rename(old_path, new_path, MYF(MY_WME)))
|
||||
return 1;
|
||||
|
|
|
@ -83,7 +83,7 @@ sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name,
|
|||
uchar* base, File_option *parameters);
|
||||
my_bool rename_in_schema_file(THD *thd,
|
||||
const char *schema, const char *old_name,
|
||||
const char *new_name);
|
||||
const char *new_db, const char *new_name);
|
||||
|
||||
class File_parser: public Sql_alloc
|
||||
{
|
||||
|
|
|
@ -311,7 +311,7 @@ do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name,
|
|||
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
|
||||
|
|
|
@ -1912,6 +1912,7 @@ int view_checksum(THD *thd, TABLE_LIST *view)
|
|||
|
||||
Parameters:
|
||||
thd thread handler
|
||||
new_db new name of database
|
||||
new_name new name of view
|
||||
view view
|
||||
|
||||
|
@ -1921,6 +1922,7 @@ int view_checksum(THD *thd, TABLE_LIST *view)
|
|||
*/
|
||||
bool
|
||||
mysql_rename_view(THD *thd,
|
||||
const char *new_db,
|
||||
const char *new_name,
|
||||
TABLE_LIST *view)
|
||||
{
|
||||
|
@ -1959,16 +1961,16 @@ mysql_rename_view(THD *thd,
|
|||
goto err;
|
||||
|
||||
/* rename view and it's backups */
|
||||
if (rename_in_schema_file(thd, view->db, view->table_name, new_name))
|
||||
if (rename_in_schema_file(thd, view->db, view->table_name, new_db, new_name))
|
||||
goto err;
|
||||
|
||||
dir.str= dir_buff;
|
||||
dir.length= build_table_filename(dir_buff, sizeof(dir_buff) - 1,
|
||||
view->db, "", "", 0);
|
||||
new_db, "", "", 0);
|
||||
|
||||
pathstr.str= path_buff;
|
||||
pathstr.length= build_table_filename(path_buff, sizeof(path_buff) - 1,
|
||||
view->db, new_name, reg_ext, 0);
|
||||
new_db, new_name, reg_ext, 0);
|
||||
|
||||
file.str= pathstr.str + dir.length;
|
||||
file.length= pathstr.length - dir.length;
|
||||
|
@ -1977,7 +1979,7 @@ mysql_rename_view(THD *thd,
|
|||
(uchar*)&view_def, view_parameters))
|
||||
{
|
||||
/* restore renamed view in case of error */
|
||||
rename_in_schema_file(thd, view->db, new_name, view->table_name);
|
||||
rename_in_schema_file(thd, new_db, new_name, view->db, view->table_name);
|
||||
goto err;
|
||||
}
|
||||
} else
|
||||
|
|
|
@ -37,7 +37,8 @@ int view_checksum(THD *thd, TABLE_LIST *view);
|
|||
extern TYPELIB updatable_views_with_limit_typelib;
|
||||
|
||||
bool check_duplicate_names(List<Item>& item_list, bool gen_unique_view_names);
|
||||
bool mysql_rename_view(THD *thd, const char *new_name, TABLE_LIST *view);
|
||||
bool mysql_rename_view(THD *thd, const char *new_db, const char *new_name,
|
||||
TABLE_LIST *view);
|
||||
|
||||
#define VIEW_ANY_ACL (SELECT_ACL | UPDATE_ACL | INSERT_ACL | DELETE_ACL)
|
||||
|
||||
|
|
Loading…
Reference in a new issue