Commit 0f7161b0 authored by unknown's avatar unknown

Bug#11493 - Alter table rename to default database does not work without db name qualifying

Supplied the default database name for ALTER TABLE ... RENAME 
for the new table instead of the old tables db like we do for 
other ALTERs.


mysql-test/r/alter_table.result:
  Bug#11493 - Alter table rename to default database does not work without db name qualifying
  The test result.
mysql-test/t/alter_table.test:
  Bug#11493 - Alter table rename to default database does not work without db name qualifying
  The test case.
parent f876fae9
...@@ -528,3 +528,18 @@ create table t1 ( a timestamp ); ...@@ -528,3 +528,18 @@ create table t1 ( a timestamp );
alter table t1 add unique ( a(1) ); alter table t1 add unique ( a(1) );
ERROR HY000: Incorrect sub part key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique sub keys ERROR HY000: Incorrect sub part key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique sub keys
drop table t1; drop table t1;
create database mysqltest1;
create table t1 (c1 int);
alter table t1 rename mysqltest1.t1;
drop table t1;
ERROR 42S02: Unknown table 't1'
alter table mysqltest1.t1 rename t1;
drop table t1;
create table t1 (c1 int);
use mysqltest1;
drop database mysqltest1;
alter table test.t1 rename t1;
ERROR 3D000: No database selected
alter table test.t1 rename test.t1;
use test;
drop table t1;
...@@ -361,4 +361,35 @@ create table t1 ( a timestamp ); ...@@ -361,4 +361,35 @@ create table t1 ( a timestamp );
alter table t1 add unique ( a(1) ); alter table t1 add unique ( a(1) );
drop table t1; drop table t1;
#
# Bug#11493 - Alter table rename to default database does not work without
# db name qualifying
#
create database mysqltest1;
create table t1 (c1 int);
# Move table to other database.
alter table t1 rename mysqltest1.t1;
# Assure that it has moved.
--error 1051
drop table t1;
# Move table back.
alter table mysqltest1.t1 rename t1;
# Assure that it is back.
drop table t1;
# Now test for correct message if no database is selected.
# Create t1 in 'test'.
create table t1 (c1 int);
# Change to other db.
use mysqltest1;
# Drop the current db. This de-selects any db.
drop database mysqltest1;
# Now test for correct message.
--error 1046
alter table test.t1 rename t1;
# Check that explicit qualifying works even with no selected db.
alter table test.t1 rename test.t1;
# Go back to standard 'test' db.
use test;
drop table t1;
# End of 4.1 tests # End of 4.1 tests
...@@ -2599,7 +2599,24 @@ unsent_create_error: ...@@ -2599,7 +2599,24 @@ unsent_create_error:
break; break;
} }
if (!select_lex->db) if (!select_lex->db)
{
/*
In the case of ALTER TABLE ... RENAME we should supply the
default database if the new name is not explicitly qualified
by a database. (Bug #11493)
*/
if (lex->alter_info.flags & ALTER_RENAME)
{
if (! thd->db)
{
send_error(thd,ER_NO_DB_ERROR);
goto error;
}
select_lex->db= thd->db;
}
else
select_lex->db=tables->db; select_lex->db=tables->db;
}
if (check_access(thd,ALTER_ACL,tables->db,&tables->grant.privilege,0,0) || if (check_access(thd,ALTER_ACL,tables->db,&tables->grant.privilege,0,0) ||
check_access(thd,INSERT_ACL | CREATE_ACL,select_lex->db,&priv,0,0)|| check_access(thd,INSERT_ACL | CREATE_ACL,select_lex->db,&priv,0,0)||
check_merge_table_access(thd, tables->db, check_merge_table_access(thd, tables->db,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment