diff options
author | unknown <holyfoot@deer.(none)> | 2006-05-12 18:02:42 +0500 |
---|---|---|
committer | unknown <holyfoot@deer.(none)> | 2006-05-12 18:02:42 +0500 |
commit | 273e1e01fede7508c3b4905e90a25d573c4dd610 (patch) | |
tree | 8a98bab5c8013718b49b0907550f96d5008152ca | |
parent | 77dedc31e922d3bfdc4379f4be5b7a9ec02a309d (diff) | |
download | mariadb-git-273e1e01fede7508c3b4905e90a25d573c4dd610.tar.gz |
bug #14573 (Error on adding auto_increment on to a column with '0' values)
mysql-test/r/auto_increment.result:
test result
mysql-test/t/auto_increment.test:
test case
sql/handler.cc:
print_keydupp_error implemented
sql/handler.h:
handler::print_keydupp_error declared
sql/share/errmsg.txt:
error message added
sql/sql_table.cc:
now we return different error message for auto_increment case
-rw-r--r-- | mysql-test/r/auto_increment.result | 6 | ||||
-rw-r--r-- | mysql-test/t/auto_increment.test | 11 | ||||
-rw-r--r-- | sql/handler.cc | 31 | ||||
-rw-r--r-- | sql/handler.h | 1 | ||||
-rw-r--r-- | sql/share/errmsg.txt | 3 | ||||
-rw-r--r-- | sql/sql_table.cc | 14 |
6 files changed, 54 insertions, 12 deletions
diff --git a/mysql-test/r/auto_increment.result b/mysql-test/r/auto_increment.result index 525f64ea902..20936bcc10c 100644 --- a/mysql-test/r/auto_increment.result +++ b/mysql-test/r/auto_increment.result @@ -418,3 +418,9 @@ a val 2 1 3 1 drop table t1; +CREATE TABLE t1 (t1 INT(10) PRIMARY KEY, t2 INT(10)); +INSERT INTO t1 VALUES(0, 0); +INSERT INTO t1 VALUES(1, 1); +ALTER TABLE t1 CHANGE t1 t1 INT(10) auto_increment; +ERROR 23000: ALTER TABLE causes auto_increment resequencing, causing Duplicate entry '1' for key 'PRIMARY' +DROP TABLE t1; diff --git a/mysql-test/t/auto_increment.test b/mysql-test/t/auto_increment.test index 26b103b0107..e0b024d021b 100644 --- a/mysql-test/t/auto_increment.test +++ b/mysql-test/t/auto_increment.test @@ -275,3 +275,14 @@ update t1 set a=2 where a=1; insert into t1 (val) values (1); select * from t1; drop table t1; + +# +# Test key duplications with auto-increment in ALTER TABLE +# bug #14573 +# +CREATE TABLE t1 (t1 INT(10) PRIMARY KEY, t2 INT(10)); +INSERT INTO t1 VALUES(0, 0); +INSERT INTO t1 VALUES(1, 1); +--error ER_DUP_ENTRY +ALTER TABLE t1 CHANGE t1 t1 INT(10) auto_increment; +DROP TABLE t1; diff --git a/sql/handler.cc b/sql/handler.cc index b9ef05a33c2..f51e91f1882 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1818,6 +1818,24 @@ ulonglong handler::get_auto_increment() } +void handler::print_keydupp_error(uint key_nr, const char *msg) +{ + /* Write the duplicated key in the error message */ + char key[MAX_KEY_LENGTH]; + String str(key,sizeof(key),system_charset_info); + /* Table is opened and defined at this point */ + key_unpack(&str,table,(uint) key_nr); + uint max_length=MYSQL_ERRMSG_SIZE-(uint) strlen(msg); + if (str.length() >= max_length) + { + str.length(max_length-4); + str.append(STRING_WITH_LEN("...")); + } + my_printf_error(ER_DUP_ENTRY, msg, + MYF(0), str.c_ptr(), table->key_info[key_nr].name); +} + + /* Print error that we got from handler function @@ -1857,18 +1875,7 @@ void handler::print_error(int error, myf errflag) uint key_nr=get_dup_key(error); if ((int) key_nr >= 0) { - /* Write the duplicated key in the error message */ - char key[MAX_KEY_LENGTH]; - String str(key,sizeof(key),system_charset_info); - /* Table is opened and defined at this point */ - key_unpack(&str,table,(uint) key_nr); - uint max_length=MYSQL_ERRMSG_SIZE-(uint) strlen(ER(ER_DUP_ENTRY)); - if (str.length() >= max_length) - { - str.length(max_length-4); - str.append(STRING_WITH_LEN("...")); - } - my_error(ER_DUP_ENTRY, MYF(0), str.c_ptr(), table->key_info[key_nr].name); + print_keydupp_error(key_nr, ER(ER_DUP_ENTRY)); DBUG_VOID_RETURN; } textno=ER_DUP_KEY; diff --git a/sql/handler.h b/sql/handler.h index d988e46b236..221fdf38f2b 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -864,6 +864,7 @@ public: virtual int ha_initialise(); int ha_open(TABLE *table, const char *name, int mode, int test_if_locked); bool update_auto_increment(); + void print_keydupp_error(uint key_nr, const char *msg); virtual void print_error(int error, myf errflag); virtual bool get_error_message(int error, String *buf); uint get_dup_key(int error); diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index a2bc77714bb..b3bd93f9dad 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -5842,3 +5842,6 @@ ER_WRONG_PARTITION_NAME swe "Felaktigt partitionsnamn" ER_CANT_CHANGE_TX_ISOLATION 25001 eng "Transaction isolation level can't be changed while a transaction is in progress" +ER_DUP_ENTRY_AUTOINCREMENT_CASE + eng "ALTER TABLE causes auto_increment resequencing, causing Duplicate entry '%-.64s' for key '%-.64s'" + diff --git a/sql/sql_table.cc b/sql/sql_table.cc index f890f504952..e7391b3d913 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -6323,6 +6323,20 @@ copy_data_between_tables(TABLE *from,TABLE *to, (error != HA_ERR_FOUND_DUPP_KEY && error != HA_ERR_FOUND_DUPP_UNIQUE)) { + if (error == HA_ERR_FOUND_DUPP_KEY) + { + uint key_nr= to->file->get_dup_key(error); + if ((int) key_nr >= 0) + { + const char *err_msg= ER(ER_DUP_ENTRY); + if (key_nr == 0 && + (to->key_info[0].key_part[0].field->flags & AUTO_INCREMENT_FLAG)) + err_msg= ER(ER_DUP_ENTRY_AUTOINCREMENT_CASE); + to->file->print_keydupp_error(key_nr, err_msg); + break; + } + } + to->file->print_error(error,MYF(0)); break; } |