Commit 2093624a authored by konstantin@mysql.com's avatar konstantin@mysql.com

Fix for bug #2628 "ALTER TABLE destroys table and reports success"

parent 62f193bf
...@@ -12,6 +12,7 @@ heikki@donna.mysql.fi ...@@ -12,6 +12,7 @@ heikki@donna.mysql.fi
heikki@hundin.mysql.fi heikki@hundin.mysql.fi
jani@hynda.mysql.fi jani@hynda.mysql.fi
jorge@linux.jorge.mysql.com jorge@linux.jorge.mysql.com
konstantin@mysql.com
lenz@mysql.com lenz@mysql.com
miguel@hegel.(none) miguel@hegel.(none)
miguel@hegel.br miguel@hegel.br
......
...@@ -32,3 +32,11 @@ i ...@@ -32,3 +32,11 @@ i
2 2
3 3
4 4
name
current
name
mysqltest
name
current
name
mysqltest
...@@ -82,3 +82,20 @@ alter table t1 drop i,add i int unsigned not null auto_increment, drop primary k ...@@ -82,3 +82,20 @@ alter table t1 drop i,add i int unsigned not null auto_increment, drop primary k
select * from t1; select * from t1;
drop table t1; drop table t1;
#
# Bug #2628: 'alter table t1 rename mysqltest.t1' silently drops mysqltest.t1
# if it exists
#
create table t1 (name char(15));
insert into t1 (name) values ("current");
create database mysqltest;
create table mysqltest.t1 (name char(15));
insert into mysqltest.t1 (name) values ("mysqltest");
select * from t1;
select * from mysqltest.t1;
--error 1050
alter table t1 rename mysqltest.t1;
select * from t1;
select * from mysqltest.t1;
drop table t1;
drop database mysqltest;
...@@ -1151,7 +1151,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -1151,7 +1151,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
thd->proc_info="init"; thd->proc_info="init";
table_name=table_list->real_name; table_name=table_list->real_name;
db=table_list->db; db=table_list->db;
if (!new_db) if (!new_db || !strcmp(new_db, db))
new_db=db; new_db=db;
if (!(table=open_ltable(thd,table_list,TL_WRITE_ALLOW_READ))) if (!(table=open_ltable(thd,table_list,TL_WRITE_ALLOW_READ)))
...@@ -1161,14 +1161,20 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -1161,14 +1161,20 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
if (new_name) if (new_name)
{ {
strmov(new_name_buff,new_name); strmov(new_name_buff,new_name);
fn_same(new_name_buff,table_name,3);
if (lower_case_table_names) if (lower_case_table_names)
casedn_str(new_name); casedn_str(new_name);
if ((lower_case_table_names && if (new_db == db &&
!my_strcasecmp(new_name_buff,table_name)) || (lower_case_table_names &&
(!lower_case_table_names && !my_strcasecmp(new_name_buff,table_name) ||
!lower_case_table_names &&
!strcmp(new_name_buff,table_name))) !strcmp(new_name_buff,table_name)))
new_name=table_name; // No. Make later check easier {
/*
Source and destination table names are equal: make later check
easier.
*/
new_name= table_name;
}
else else
{ {
if (table->tmp_table) if (table->tmp_table)
......
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