From: Date: May 12 2006 3:02pm Subject: bk commit into 5.1 tree (holyfoot:1.2391) BUG#14573 List-Archive: http://lists.mysql.com/commits/6303 X-Bug: 14573 Message-Id: <20060512130255.F126370004C@deer.myoffice.izhnet.ru> Below is the list of changes that have just been committed into a local 5.1 repository of hf. When hf does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.2391 06/05/12 18:02:42 holyfoot@deer.(none) +6 -0 bug #14573 (Error on adding auto_increment on to a column with '0' values) sql/sql_table.cc 1.332 06/05/12 18:00:46 holyfoot@stripped +14 -0 now we return different error message for auto_increment case sql/share/errmsg.txt 1.99 06/05/12 18:00:46 holyfoot@stripped +3 -0 error message added sql/handler.h 1.209 06/05/12 18:00:46 holyfoot@stripped +1 -0 handler::print_keydupp_error declared sql/handler.cc 1.232 06/05/12 18:00:46 holyfoot@stripped +19 -12 print_keydupp_error implemented mysql-test/t/auto_increment.test 1.26 06/05/12 18:00:46 holyfoot@stripped +11 -0 test case mysql-test/r/auto_increment.result 1.40 06/05/12 18:00:46 holyfoot@stripped +6 -0 test result # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: holyfoot # Host: deer.(none) # Root: /home/hf/work/mysql-5.1.14573 --- 1.231/sql/handler.cc Fri May 5 22:08:36 2006 +++ 1.232/sql/handler.cc Fri May 12 18:00:46 2006 @@ -1818,6 +1818,24 @@ } +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 @@ 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; --- 1.208/sql/handler.h Thu May 4 17:58:26 2006 +++ 1.209/sql/handler.h Fri May 12 18:00:46 2006 @@ -864,6 +864,7 @@ 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); --- 1.331/sql/sql_table.cc Fri May 5 22:08:37 2006 +++ 1.332/sql/sql_table.cc Fri May 12 18:00:46 2006 @@ -6323,6 +6323,20 @@ (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; } --- 1.98/sql/share/errmsg.txt Thu May 4 21:39:43 2006 +++ 1.99/sql/share/errmsg.txt Fri May 12 18:00:46 2006 @@ -5842,3 +5842,6 @@ 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'" + --- 1.39/mysql-test/r/auto_increment.result Wed May 10 23:39:20 2006 +++ 1.40/mysql-test/r/auto_increment.result Fri May 12 18:00:46 2006 @@ -418,3 +418,9 @@ 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; --- 1.25/mysql-test/t/auto_increment.test Thu May 4 20:35:52 2006 +++ 1.26/mysql-test/t/auto_increment.test Fri May 12 18:00:46 2006 @@ -275,3 +275,14 @@ 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;