mirror of
https://github.com/MariaDB/server.git
synced 2025-01-25 00:04:33 +01:00
Apply InnoDB-specific parts of the fix for bug #9680, wrong error from
cascading update.
This commit is contained in:
parent
67be8fe939
commit
48eb9e46a1
6 changed files with 73 additions and 2 deletions
|
@ -457,6 +457,10 @@ convert_error_code_to_mysql(
|
|||
|
||||
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);
|
||||
|
|
|
@ -57,6 +57,10 @@ Created 5/24/1996 Heikki Tuuri
|
|||
buffer pool (for big transactions,
|
||||
InnoDB stores the lock structs in the
|
||||
buffer pool) */
|
||||
#define DB_FOREIGN_DUPLICATE_KEY 46 /* foreign key constraints
|
||||
activated by the operation would
|
||||
lead to a duplicate key in some
|
||||
table */
|
||||
|
||||
/* The following are partial failure codes */
|
||||
#define DB_FAIL 1000
|
||||
|
|
|
@ -3213,3 +3213,21 @@ drop trigger t2t;
|
|||
drop trigger t3t;
|
||||
drop trigger t4t;
|
||||
drop table t1, t2, t3, t4, t5;
|
||||
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;
|
||||
|
|
|
@ -2106,3 +2106,32 @@ drop trigger t4t;
|
|||
drop table t1, t2, t3, t4, t5;
|
||||
disconnect a;
|
||||
disconnect b;
|
||||
|
||||
#
|
||||
# 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;
|
||||
|
|
|
@ -1386,6 +1386,21 @@ run_again:
|
|||
thr, foreign, &pcur, entry,
|
||||
&mtr);
|
||||
if (err != DB_SUCCESS) {
|
||||
/* Since reporting a plain
|
||||
"duplicate key" error
|
||||
message to the user in
|
||||
cases where a long CASCADE
|
||||
operation would lead to a
|
||||
duplicate key in some
|
||||
other table is very
|
||||
confusing, map duplicate
|
||||
key errors resulting from
|
||||
FK constraints to a
|
||||
separate error code. */
|
||||
|
||||
if (err == DB_DUPLICATE_KEY) {
|
||||
err = DB_FOREIGN_DUPLICATE_KEY;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -474,7 +474,8 @@ handle_new_error:
|
|||
|
||||
trx->error_state = DB_SUCCESS;
|
||||
|
||||
if (err == DB_DUPLICATE_KEY) {
|
||||
if ((err == DB_DUPLICATE_KEY)
|
||||
|| (err == DB_FOREIGN_DUPLICATE_KEY)) {
|
||||
if (savept) {
|
||||
/* Roll back the latest, possibly incomplete
|
||||
insertion or update */
|
||||
|
|
Loading…
Add table
Reference in a new issue