summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Glukhov <Sergey.Glukhov@sun.com>2009-04-13 18:09:10 +0500
committerSergey Glukhov <Sergey.Glukhov@sun.com>2009-04-13 18:09:10 +0500
commit7ff5b7a9369e97a66d5773df5092553f5e976888 (patch)
treeb4749b2e890efcbe49fdddc527836b6733e5ae5a
parent6c08e3c2fb75eebb814f77057fea5827d0468f7c (diff)
downloadmariadb-git-7ff5b7a9369e97a66d5773df5092553f5e976888.tar.gz
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).
-rw-r--r--mysql-test/t/upgrade.test2
-rw-r--r--sql/parse_file.cc5
-rw-r--r--sql/parse_file.h2
-rw-r--r--sql/sql_rename.cc2
-rw-r--r--sql/sql_view.cc10
-rw-r--r--sql/sql_view.h3
6 files changed, 15 insertions, 9 deletions
diff --git a/mysql-test/t/upgrade.test b/mysql-test/t/upgrade.test
index 5c4abc7559d..e096b6520a1 100644
--- a/mysql-test/t/upgrade.test
+++ b/mysql-test/t/upgrade.test
@@ -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;
diff --git a/sql/parse_file.cc b/sql/parse_file.cc
index 07ea434e8e0..f2dbeba1bbf 100644
--- a/sql/parse_file.cc
+++ b/sql/parse_file.cc
@@ -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;
diff --git a/sql/parse_file.h b/sql/parse_file.h
index cfac69cc471..84647e45927 100644
--- a/sql/parse_file.h
+++ b/sql/parse_file.h
@@ -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
{
diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc
index ced69388009..d4331b12cd4 100644
--- a/sql/sql_rename.cc
+++ b/sql/sql_rename.cc
@@ -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
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 4d523ddf9ac..4f207f78688 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -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
diff --git a/sql/sql_view.h b/sql/sql_view.h
index b8138663489..e08c2168e14 100644
--- a/sql/sql_view.h
+++ b/sql/sql_view.h
@@ -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)