diff options
author | unknown <konstantin@mysql.com> | 2004-02-06 14:28:57 +0300 |
---|---|---|
committer | unknown <konstantin@mysql.com> | 2004-02-06 14:28:57 +0300 |
commit | b5819094a70fa1c4f9c231424af6792da0b7b801 (patch) | |
tree | 02ab95be219033200e8a697bc32e7e67f7377ae3 | |
parent | cbda6835edefb245f883e015b4b3e6761db6171a (diff) | |
download | mariadb-git-b5819094a70fa1c4f9c231424af6792da0b7b801.tar.gz |
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.
-rw-r--r-- | BitKeeper/etc/logging_ok | 1 | ||||
-rw-r--r-- | mysql-test/r/alter_table.result | 8 | ||||
-rw-r--r-- | mysql-test/t/alter_table.test | 17 | ||||
-rw-r--r-- | sql/sql_table.cc | 18 |
4 files changed, 38 insertions, 6 deletions
diff --git a/BitKeeper/etc/logging_ok b/BitKeeper/etc/logging_ok index 777c590ce62..11a8f3b8fcd 100644 --- a/BitKeeper/etc/logging_ok +++ b/BitKeeper/etc/logging_ok @@ -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 diff --git a/mysql-test/r/alter_table.result b/mysql-test/r/alter_table.result index dbdbb7f57a9..8b104225b9c 100644 --- a/mysql-test/r/alter_table.result +++ b/mysql-test/r/alter_table.result @@ -32,3 +32,11 @@ i 2 3 4 +name +current +name +mysqltest +name +current +name +mysqltest diff --git a/mysql-test/t/alter_table.test b/mysql-test/t/alter_table.test index dbfbd4267d8..cfb4f958372 100644 --- a/mysql-test/t/alter_table.test +++ b/mysql-test/t/alter_table.test @@ -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; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index f273821c5e0..04dfd8a1fbd 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -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) |