mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
Add extra tests for foreign key support.
FossilOrigin-Name: 7d086afe69da4d03bd1de5408626858273f91e8f
This commit is contained in:
@ -22,7 +22,7 @@ source $testdir/malloc_common.tcl
|
||||
|
||||
do_malloc_test fkey_malloc-1 -sqlprep {
|
||||
PRAGMA foreign_keys = 1;
|
||||
CREATE TABLE t1(a PRIMARY KEY, b);
|
||||
CREATE TABLE t1(a PRIMARY KEY, b UNIQUE);
|
||||
CREATE TABLE t2(x REFERENCES t1 ON UPDATE CASCADE ON DELETE CASCADE);
|
||||
} -sqlbody {
|
||||
INSERT INTO t1 VALUES('aaa', 1);
|
||||
@ -48,6 +48,61 @@ do_malloc_test fkey_malloc-2 -sqlprep {
|
||||
COMMIT;
|
||||
}
|
||||
|
||||
do_malloc_test fkey_malloc-3 -sqlprep {
|
||||
PRAGMA foreign_keys = 1;
|
||||
CREATE TABLE t1(x INTEGER PRIMARY KEY);
|
||||
CREATE TABLE t2(y REFERENCES t1(rowid) ON UPDATE CASCADE);
|
||||
CREATE TABLE t3(y DEFAULT 14 REFERENCES t1(x) ON UPDATE SET DEFAULT);
|
||||
CREATE TABLE t4(y REFERENCES t1 ON UPDATE SET NULL);
|
||||
INSERT INTO t1 VALUES(13);
|
||||
INSERT INTO t2 VALUES(13);
|
||||
INSERT INTO t3 VALUES(13);
|
||||
INSERT INTO t4 VALUES(13);
|
||||
} -sqlbody {
|
||||
UPDATE t1 SET x = 14;
|
||||
}
|
||||
|
||||
proc catch_fk_error {zSql} {
|
||||
set rc [catch {db eval $zSql} msg]
|
||||
if {$rc==0} {
|
||||
return $msg
|
||||
}
|
||||
if {[string match {*foreign key*} $msg]} {
|
||||
return ""
|
||||
}
|
||||
if {$msg eq "out of memory"} {
|
||||
error 1
|
||||
}
|
||||
error $msg
|
||||
}
|
||||
|
||||
do_malloc_test fkey_malloc-4 -sqlprep {
|
||||
PRAGMA foreign_keys = 1;
|
||||
CREATE TABLE t1(x INTEGER PRIMARY KEY, y UNIQUE);
|
||||
CREATE TABLE t2(z REFERENCES t1(x), a REFERENCES t1(y));
|
||||
CREATE TABLE t3(x);
|
||||
CREATE TABLE t4(z REFERENCES t3);
|
||||
CREATE TABLE t5(x, y);
|
||||
CREATE TABLE t6(z REFERENCES t5(x));
|
||||
CREATE INDEX i51 ON t5(x);
|
||||
CREATE INDEX i52 ON t5(y, x);
|
||||
INSERT INTO t1 VALUES(1, 2);
|
||||
} -tclbody {
|
||||
catch_fk_error {INSERT INTO t2 VALUES(1, 3)}
|
||||
catch_fk_error {INSERT INTO t4 VALUES(2)}
|
||||
catch_fk_error {INSERT INTO t6 VALUES(2)}
|
||||
}
|
||||
|
||||
do_malloc_test fkey_malloc-5 -sqlprep {
|
||||
PRAGMA foreign_keys = 1;
|
||||
CREATE TABLE t1(x, y, PRIMARY KEY(x, y));
|
||||
CREATE TABLE t2(a, b, FOREIGN KEY(a, b) REFERENCES t1 ON UPDATE CASCADE);
|
||||
INSERT INTO t1 VALUES(1, 2);
|
||||
INSERT INTO t2 VALUES(1, 2);
|
||||
} -sqlbody {
|
||||
UPDATE t1 SET x = 5;
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user