Below is the list of changes that have just been committed into a local
5.2 repository of msvensson. When msvensson 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.2099 06/02/10 09:18:27 msvensson@neptunus.(none) +5 -0
Merge bk-internal.mysql.com:/home/bk/mysql-5.2
into neptunus.(none):/home/msvensson/mysql/mysql-5.2
sql/share/errmsg.txt
1.81 06/02/10 09:18:17 msvensson@neptunus.(none) +0 -0
Auto merged
sql/handler.cc
1.215 06/02/10 09:18:16 msvensson@neptunus.(none) +0 -0
Auto merged
sql/ha_innodb.cc
1.256 06/02/10 09:18:16 msvensson@neptunus.(none) +0 -0
Auto merged
mysql-test/t/innodb.test
1.129 06/02/10 09:18:16 msvensson@neptunus.(none) +0 -0
Auto merged
mysql-test/r/innodb.result
1.160 06/02/10 09:18:15 msvensson@neptunus.(none) +0 -0
Auto merged
# 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: msvensson
# Host: neptunus.(none)
# Root: /home/msvensson/mysql/mysql-5.2/RESYNC
--- 1.214/sql/handler.cc 2006-02-06 11:47:05 +01:00
+++ 1.215/sql/handler.cc 2006-02-10 09:18:16 +01:00
@@ -358,6 +358,7 @@
SETMSG(HA_ERR_TABLE_EXIST, ER(ER_TABLE_EXISTS_ERROR));
SETMSG(HA_ERR_NO_CONNECTION, "Could not connect to storage engine");
SETMSG(HA_ERR_TABLE_DEF_CHANGED, ER(ER_TABLE_DEF_CHANGED));
+ SETMSG(HA_ERR_FOREIGN_DUPLICATE_KEY, "FK constraint would lead to duplicate key");
/* Register the error messages for use with my_error(). */
return my_error_register(errmsgs, HA_ERR_FIRST, HA_ERR_LAST);
@@ -1868,6 +1869,29 @@
textno=ER_DUP_KEY;
break;
}
+ case HA_ERR_FOREIGN_DUPLICATE_KEY:
+ {
+ uint key_nr= get_dup_key(error);
+ if ((int) key_nr >= 0)
+ {
+ /* Write the 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_FOREIGN_DUPLICATE_KEY));
+ if (str.length() >= max_length)
+ {
+ str.length(max_length-4);
+ str.append(STRING_WITH_LEN("..."));
+ }
+ my_error(ER_FOREIGN_DUPLICATE_KEY, MYF(0), table_share->table_name.str,
+ str.c_ptr(), key_nr+1);
+ DBUG_VOID_RETURN;
+ }
+ textno= ER_DUP_KEY;
+ break;
+ }
case HA_ERR_NULL_IN_SPATIAL:
textno= ER_UNKNOWN_ERROR;
break;
@@ -2003,8 +2027,9 @@
{
DBUG_ENTER("handler::get_dup_key");
table->file->errkey = (uint) -1;
- if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOUND_DUPP_UNIQUE ||
- error == HA_ERR_NULL_IN_SPATIAL || error == HA_ERR_DROP_INDEX_FK)
+ if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
+ error == HA_ERR_FOUND_DUPP_UNIQUE || error == HA_ERR_NULL_IN_SPATIAL ||
+ error == HA_ERR_DROP_INDEX_FK)
info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK);
DBUG_RETURN(table->file->errkey);
}
--- 1.80/sql/share/errmsg.txt 2006-02-06 21:30:33 +01:00
+++ 1.81/sql/share/errmsg.txt 2006-02-10 09:18:17 +01:00
@@ -5800,3 +5800,5 @@
eng "You can't use usual read lock with log tables. Try READ LOCAL instead."
ER_SP_WRONG_NAME 42000
eng "Incorrect routine name '%-.64s'"
+ER_FOREIGN_DUPLICATE_KEY 23000 S1009
+ eng "Upholding foreign key constraints for table '%.64s', entry '%-.64s', key %d would lead to a duplicate entry"
--- 1.159/mysql-test/r/innodb.result 2006-02-08 11:58:49 +01:00
+++ 1.160/mysql-test/r/innodb.result 2006-02-10 09:18:15 +01:00
@@ -2758,3 +2758,21 @@
key (a,b,c,d,e)) engine=innodb;
ERROR 42000: Specified key was too long; max key length is 3072 bytes
End of 5.0 tests
+CREATE TABLE t1 (
+field1 varchar(8) NOT NULL DEFAULT '',
+field2 varchar(8) NOT NULL DEFAULT '',
+PRIMARY KEY (field1, field2)
+) ENGINE=InnoDB;
+CREATE TABLE t2 (
+field1 varchar(8) NOT NULL DEFAULT '' PRIMARY KEY,
+FOREIGN KEY (field1) REFERENCES t1 (field1)
+ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB;
+INSERT INTO t1 VALUES ('old', 'somevalu');
+INSERT INTO t1 VALUES ('other', 'anyvalue');
+INSERT INTO t2 VALUES ('old');
+INSERT INTO t2 VALUES ('other');
+UPDATE t1 SET field1 = 'other' WHERE field2 = 'somevalu';
+ERROR 23000: Upholding foreign key constraints for table 't1', entry 'other-somevalu', key 1 would lead to a duplicate entry
+DROP TABLE t2;
+DROP TABLE t1;
--- 1.128/mysql-test/t/innodb.test 2006-02-08 11:58:49 +01:00
+++ 1.129/mysql-test/t/innodb.test 2006-02-10 09:18:16 +01:00
@@ -1715,3 +1715,32 @@
key (a,b,c,d,e)) engine=innodb;
--echo End of 5.0 tests
+
+#
+# Test that cascading updates leading to duplicate keys give the correct
+# error message (bug #9680)
+#
+
+CREATE TABLE t1 (
+ field1 varchar(8) NOT NULL DEFAULT '',
+ field2 varchar(8) NOT NULL DEFAULT '',
+ PRIMARY KEY (field1, field2)
+) ENGINE=InnoDB;
+
+CREATE TABLE t2 (
+ field1 varchar(8) NOT NULL DEFAULT '' PRIMARY KEY,
+ FOREIGN KEY (field1) REFERENCES t1 (field1)
+ ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
+INSERT INTO t1 VALUES ('old', 'somevalu');
+INSERT INTO t1 VALUES ('other', 'anyvalue');
+
+INSERT INTO t2 VALUES ('old');
+INSERT INTO t2 VALUES ('other');
+
+--error ER_FOREIGN_DUPLICATE_KEY
+UPDATE t1 SET field1 = 'other' WHERE field2 = 'somevalu';
+
+DROP TABLE t2;
+DROP TABLE t1;
--- 1.255/sql/ha_innodb.cc 2006-02-08 11:58:49 +01:00
+++ 1.256/sql/ha_innodb.cc 2006-02-10 09:18:16 +01:00
@@ -465,6 +465,10 @@
return(HA_ERR_FOUND_DUPP_KEY);
+ } else if (error == (int) DB_FOREIGN_DUPLICATE_KEY) {
+
+ return(HA_ERR_FOREIGN_DUPLICATE_KEY);
+
} else if (error == (int) DB_RECORD_NOT_FOUND) {
return(HA_ERR_NO_ACTIVE_RECORD);
| Thread |
|---|
| • bk commit into 5.2 tree (msvensson:1.2099) | msvensson | 10 Feb |