mirror of https://github.com/sqlite/sqlite
Add tests to test/e_fkey.test.
FossilOrigin-Name: 533703d78ab4330b2dc8e08aaba89b4667e46331
This commit is contained in:
parent
07fcc26824
commit
ce3745329c
12
manifest
12
manifest
|
@ -1,5 +1,5 @@
|
|||
C Update\striggerC.test\sto\smatch\sthe\schange\sto\sthe\sway\sthe\strigger-recursion\slimit\sis\shandled.
|
||||
D 2009-10-08T06:24:41
|
||||
C Add\stests\sto\stest/e_fkey.test.
|
||||
D 2009-10-08T11:57:25
|
||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||
F Makefile.in 4ca3f1dd6efa2075bcb27f4dc43eef749877740d
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
|
@ -319,7 +319,7 @@ F test/descidx2.test 1310ed1326cdfed4ea2c55169631579f082d174f
|
|||
F test/descidx3.test 3394ad4d089335cac743c36a14129d6d931c316f
|
||||
F test/diskfull.test 0cede7ef9d8f415d9d3944005c76be7589bb5ebb
|
||||
F test/distinctagg.test 1a6ef9c87a58669438fc771450d7a72577417376
|
||||
F test/e_fkey.test 0f520315537039d6e2c72285dca2a63ab26b5c48
|
||||
F test/e_fkey.test 1fc787e91aeb3adf09f186473d9091f66035fd22
|
||||
F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea
|
||||
F test/enc2.test 6d91a5286f59add0cfcbb2d0da913b76f2242398
|
||||
F test/enc3.test 5c550d59ff31dccdba5d1a02ae11c7047d77c041
|
||||
|
@ -756,7 +756,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
|||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||
P 33973814c67bc9bac575bf2249df6530dd2184d3
|
||||
R dd04ee19d49e7a136c94ca39ddd17c66
|
||||
P 5806925283b889867567c4ad92518bad000e9d9d
|
||||
R 97b0c9624c1352ee1bd2b4c1a280677a
|
||||
U dan
|
||||
Z a4b0521924041d87ab332fd1d83d83e4
|
||||
Z b579362d2c03d6f47ae2f91d34cdcb70
|
||||
|
|
|
@ -1 +1 @@
|
|||
5806925283b889867567c4ad92518bad000e9d9d
|
||||
533703d78ab4330b2dc8e08aaba89b4667e46331
|
109
test/e_fkey.test
109
test/e_fkey.test
|
@ -19,6 +19,115 @@ ifcapable {!foreignkey} { finish_test ; return }
|
|||
|
||||
execsql "PRAGMA foreign_keys = ON"
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# /* EV: R-36018-21755 */
|
||||
# /* EV: R-25384-39337 */
|
||||
#
|
||||
# Test that parent keys are not checked when tables are created.
|
||||
#
|
||||
# Child keys are checked to ensure all component columns exist. If parent
|
||||
# key columns are explicitly specified, SQLite checks to make sure there
|
||||
# are the same number of columns in the child and parent keys. (TODO: This
|
||||
# is tested but does not correspond to any testable statement.)
|
||||
#
|
||||
# /* EV: R-50163-54229 */
|
||||
#
|
||||
# Also test that the above statements are true regardless of whether or not
|
||||
# foreign keys are enabled.
|
||||
#
|
||||
foreach {tn zCreateTbl lRes} {
|
||||
1 "CREATE TABLE t1(a, b REFERENCES t1)" {0 {}}
|
||||
2 "CREATE TABLE t1(a, b REFERENCES t2)" {0 {}}
|
||||
3 "CREATE TABLE t1(a, b, FOREIGN KEY(a,b) REFERENCES t1)" {0 {}}
|
||||
4 "CREATE TABLE t1(a, b, FOREIGN KEY(a,b) REFERENCES t2)" {0 {}}
|
||||
5 "CREATE TABLE t1(a, b, FOREIGN KEY(a,b) REFERENCES t2)" {0 {}}
|
||||
6 "CREATE TABLE t1(a, b, FOREIGN KEY(a,b) REFERENCES t2(n,d))" {0 {}}
|
||||
7 "CREATE TABLE t1(a, b, FOREIGN KEY(a,b) REFERENCES t1(a,b))" {0 {}}
|
||||
|
||||
A "CREATE TABLE t1(a, b, FOREIGN KEY(c,b) REFERENCES t2)"
|
||||
{1 {unknown column "c" in foreign key definition}}
|
||||
B "CREATE TABLE t1(a, b, FOREIGN KEY(c,b) REFERENCES t2(d))"
|
||||
{1 {number of columns in foreign key does not match the number of columns in the referenced table}}
|
||||
} {
|
||||
do_test e_fkey-5.$tn.off {
|
||||
drop_all_tables
|
||||
execsql {PRAGMA foreign_keys = OFF}
|
||||
catchsql $zCreateTbl
|
||||
} $lRes
|
||||
do_test e_fkey-5.$tn.on {
|
||||
drop_all_tables
|
||||
execsql {PRAGMA foreign_keys = ON}
|
||||
catchsql $zCreateTbl
|
||||
} $lRes
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# /* EV: R-47952-62498 */
|
||||
#
|
||||
proc test_efkey_6 {tn zAlter isError} {
|
||||
drop_all_tables
|
||||
|
||||
do_test e_fkey-6.$tn.1 "
|
||||
execsql { CREATE TABLE tbl(a, b) }
|
||||
[list catchsql $zAlter]
|
||||
" [lindex {{0 {}} {1 {Cannot add a REFERENCES column with non-NULL default value}}} $isError]
|
||||
|
||||
}
|
||||
|
||||
test_efkey_6 1 "ALTER TABLE tbl ADD COLUMN c REFERENCES xx" 0
|
||||
test_efkey_6 2 "ALTER TABLE tbl ADD COLUMN c DEFAULT NULL REFERENCES xx" 0
|
||||
test_efkey_6 3 "ALTER TABLE tbl ADD COLUMN c DEFAULT 0 REFERENCES xx" 1
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# /* EV: R-47080-02069 */
|
||||
#
|
||||
# Test that ALTER TABLE adjusts REFERENCES clauses when the parent table
|
||||
# is RENAMED.
|
||||
#
|
||||
# /* EV: R-63827-54774 */
|
||||
#
|
||||
# Test that these adjustments are visible in the sqlite_master table.
|
||||
#
|
||||
do_test e_fkey-7.1 {
|
||||
drop_all_tables
|
||||
execsql {
|
||||
CREATE TABLE 'p 1 "parent one"'(a REFERENCES 'p 1 "parent one"', b, PRIMARY KEY(b));
|
||||
|
||||
CREATE TABLE c1(c, d REFERENCES 'p 1 "parent one"' ON UPDATE CASCADE);
|
||||
CREATE TABLE c2(e, f, FOREIGN KEY(f) REFERENCES 'p 1 "parent one"' ON UPDATE CASCADE);
|
||||
CREATE TABLE c3(e, 'f col 2', FOREIGN KEY('f col 2') REFERENCES 'p 1 "parent one"' ON UPDATE CASCADE);
|
||||
|
||||
INSERT INTO 'p 1 "parent one"' VALUES(1, 1);
|
||||
INSERT INTO c1 VALUES(1, 1);
|
||||
INSERT INTO c2 VALUES(1, 1);
|
||||
INSERT INTO c3 VALUES(1, 1);
|
||||
|
||||
-- CREATE TABLE q(a, b, PRIMARY KEY(b));
|
||||
}
|
||||
} {}
|
||||
do_test e_fkey-7.2 {
|
||||
execsql { ALTER TABLE 'p 1 "parent one"' RENAME TO p }
|
||||
} {}
|
||||
do_test e_fkey-7.3 {
|
||||
execsql {
|
||||
UPDATE p SET a = 'xxx', b = 'xxx';
|
||||
SELECT * FROM p;
|
||||
SELECT * FROM c1;
|
||||
SELECT * FROM c2;
|
||||
SELECT * FROM c3;
|
||||
}
|
||||
} {xxx xxx 1 xxx 1 xxx 1 xxx}
|
||||
do_test e_fkey-7.4 {
|
||||
execsql { SELECT sql FROM sqlite_master WHERE type = 'table'}
|
||||
} [list \
|
||||
{CREATE TABLE "p"(a REFERENCES "p", b, PRIMARY KEY(b))} \
|
||||
{CREATE TABLE c1(c, d REFERENCES "p" ON UPDATE CASCADE)} \
|
||||
{CREATE TABLE c2(e, f, FOREIGN KEY(f) REFERENCES "p" ON UPDATE CASCADE)} \
|
||||
{CREATE TABLE c3(e, 'f col 2', FOREIGN KEY('f col 2') REFERENCES "p" ON UPDATE CASCADE)} \
|
||||
]
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# /* EV: R-24728-13230 */
|
||||
# /* EV: R-24450-46174 */
|
||||
|
|
Loading…
Reference in New Issue