Commit b5819094 authored by unknown's avatar unknown

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


BitKeeper/etc/logging_ok:
  Logging to logging@openlogging.org accepted
mysql-test/r/alter_table.result:
  Fix for bug #2628: test result fixed
mysql-test/t/alter_table.test:
  Fix for bug #2628: test case added
sql/sql_table.cc:
  Fix for bug #2628:
  We need to take into account database name when checking if source and 
  destination table names are equal.
  Note, that after merge to 4.0 we also need to check for 
  lower_case_table_names.
parent cbda6835
......@@ -12,6 +12,7 @@ heikki@donna.mysql.fi
heikki@hundin.mysql.fi
jani@hynda.mysql.fi
jorge@linux.jorge.mysql.com
konstantin@mysql.com
lenz@mysql.com
miguel@hegel.(none)
miguel@hegel.br
......
......@@ -32,3 +32,11 @@ i
2
3
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
select * from 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,
thd->proc_info="init";
table_name=table_list->real_name;
db=table_list->db;
if (!new_db)
if (!new_db || !strcmp(new_db, db))
new_db=db;
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,
if (new_name)
{
strmov(new_name_buff,new_name);
fn_same(new_name_buff,table_name,3);
if (lower_case_table_names)
casedn_str(new_name);
if ((lower_case_table_names &&
!my_strcasecmp(new_name_buff,table_name)) ||
(!lower_case_table_names &&
if (new_db == db &&
(lower_case_table_names &&
!my_strcasecmp(new_name_buff,table_name) ||
!lower_case_table_names &&
!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
{
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