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
This commit is contained in:
parent
77dedc31e9
commit
273e1e01fe
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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'"
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user