Loading mysql-test/r/auto_increment.result +6 −0 Original line number Diff line number Diff line Loading @@ -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; mysql-test/t/auto_increment.test +11 −0 Original line number Diff line number Diff line Loading @@ -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; sql/handler.cc +19 −12 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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; Loading sql/handler.h +1 −0 Original line number Diff line number Diff line Loading @@ -865,6 +865,7 @@ class handler :public Sql_alloc 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); Loading sql/share/errmsg.txt +3 −0 Original line number Diff line number Diff line Loading @@ -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, resulting in duplicate entry '%-.64s' for key '%-.64s'" Loading
mysql-test/r/auto_increment.result +6 −0 Original line number Diff line number Diff line Loading @@ -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;
mysql-test/t/auto_increment.test +11 −0 Original line number Diff line number Diff line Loading @@ -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;
sql/handler.cc +19 −12 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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; Loading
sql/handler.h +1 −0 Original line number Diff line number Diff line Loading @@ -865,6 +865,7 @@ class handler :public Sql_alloc 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); Loading
sql/share/errmsg.txt +3 −0 Original line number Diff line number Diff line Loading @@ -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, resulting in duplicate entry '%-.64s' for key '%-.64s'"