1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Ensure foreign key related processing takes place when rows are deleted from the database by REPLACE conflict handling.

FossilOrigin-Name: 3f40c142c8526c1572020bd4d945c03a72019135
This commit is contained in:
dan
2009-09-24 11:31:21 +00:00
parent 4bb3b679b0
commit 1bea559a94
4 changed files with 66 additions and 12 deletions

View File

@ -55,6 +55,9 @@ ifcapable {!foreignkey||!trigger} {
#
# fkey2-12.*: Test RESTRICT actions.
#
# fkey2-13.*: Test that FK processing is performed when a row is REPLACED by
# an UPDATE or INSERT statement.
#
# fkey2-genfkey.*: Tests that were used with the shell tool .genfkey
# command. Recycled to test the built-in implementation.
#
@ -636,7 +639,58 @@ do_test fkey2-12.1.7 {
}
} {}
#-------------------------------------------------------------------------
# The following tests, fkey2-13.*, test that FK processing is performed
# when rows are REPLACEd.
#
drop_all_tables
do_test fkey2-13.1.1 {
execsql {
CREATE TABLE pp(a UNIQUE, b, c, PRIMARY KEY(b, c));
CREATE TABLE cc(d, e, f UNIQUE, FOREIGN KEY(d, e) REFERENCES pp);
INSERT INTO pp VALUES(1, 2, 3);
INSERT INTO cc VALUES(2, 3, 1);
}
} {}
foreach {tn stmt} {
1 "REPLACE INTO pp VALUES(1, 4, 5)"
2 "REPLACE INTO pp(rowid, a, b, c) VALUES(1, 2, 3, 4)"
} {
do_test fkey2-13.1.$tn.1 {
catchsql $stmt
} {1 {foreign key constraint failed}}
do_test fkey2-13.1.$tn.2 {
execsql {
SELECT * FROM pp;
SELECT * FROM cc;
}
} {1 2 3 2 3 1}
do_test fkey2-13.1.$tn.3 {
execsql BEGIN;
catchsql $stmt
} {1 {foreign key constraint failed}}
do_test fkey2-13.1.$tn.4 {
execsql {
COMMIT;
SELECT * FROM pp;
SELECT * FROM cc;
}
} {1 2 3 2 3 1}
}
do_test fkey2-13.1.3 {
execsql {
REPLACE INTO pp(rowid, a, b, c) VALUES(1, 2, 2, 3);
SELECT rowid, * FROM pp;
SELECT * FROM cc;
}
} {1 2 2 3 2 3 1}
do_test fkey2-13.1.4 {
execsql {
REPLACE INTO pp(rowid, a, b, c) VALUES(2, 2, 2, 3);
SELECT rowid, * FROM pp;
SELECT * FROM cc;
}
} {2 2 2 3 2 3 1}
#-------------------------------------------------------------------------
# The following block of tests, those prefixed with "fkey2-genfkey.", are