-C Add\sfurther\stest\scases\sto\se_fkey.test.
-D 2009-10-12T08:41:50
+C Extra\stest\scases\smapped\sto\sstatements\sin\sforeignkeys.html.
+D 2009-10-12T11:27:01
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 4ca3f1dd6efa2075bcb27f4dc43eef749877740d
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
F test/descidx3.test 3394ad4d089335cac743c36a14129d6d931c316f
F test/diskfull.test 0cede7ef9d8f415d9d3944005c76be7589bb5ebb
F test/distinctagg.test 1a6ef9c87a58669438fc771450d7a72577417376
-F test/e_fkey.test f9fcab098eefc9eefe8624b730a48611dfeeface
+F test/e_fkey.test b9bf4788af033c5d56e58df1e989434d942196b3
F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea
F test/enc2.test 6d91a5286f59add0cfcbb2d0da913b76f2242398
F test/enc3.test 5c550d59ff31dccdba5d1a02ae11c7047d77c041
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 5ec07feea47e727824b8b48236b5cce80539a455
-R ec48fda10fcfca9f54309367518982c3
+P d61cc0e1a1e8b4bf49016d3d14554f9c20f86f6b
+R 19129dc0d2d5338325ee10c52d15ba5f
U dan
-Z 4e3c8e06ad003cd47ba138558d63cec3
+Z f04f7530e0d7bdd848703c83bac7f590
# This file implements tests to verify the "testable statements" in the
# foreignkeys.in document.
#
+# The tests in this file are arranged to mirror the structure of
+# foreignkey.in, with one exception: The statements in section 2, which
+# deals with enabling/disabling foreign key support, is tested first,
+# before section 1. This is because some statements in section 2 deal
+# with builds that do not include complete foreign key support (because
+# either SQLITE_OMIT_TRIGGER or SQLITE_OMIT_FOREIGN_KEY was defined
+# at build time).
+#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
-ifcapable {!foreignkey} { finish_test ; return }
-execsql "PRAGMA foreign_keys = ON"
+###########################################################################
+### SECTION 2: Enabling Foreign Key Support
+###########################################################################
+
+#-------------------------------------------------------------------------
+# /* EV: R-33710-56344 */
+#
+# Test builds neither OMIT_FOREIGN_KEY or OMIT_TRIGGER defined have
+# foreign key functionality.
+#
+ifcapable trigger&&foreignkey {
+ do_test e_fkey-49 {
+ execsql {
+ PRAGMA foreign_keys = ON;
+ CREATE TABLE p(i PRIMARY KEY);
+ CREATE TABLE c(j REFERENCES p ON UPDATE CASCADE);
+ INSERT INTO p VALUES('hello');
+ INSERT INTO c VALUES('hello');
+ UPDATE p SET i = 'world';
+ SELECT * FROM c;
+ }
+ } {world}
+}
+
+#-------------------------------------------------------------------------
+# /* EV: R-44697-61543 */
+#
+# Test the effects of defining OMIT_TRIGGER but not OMIT_FOREIGN_KEY.
+#
+# /* EV: R-22567-44039 */
+# /* EV: R-60444-29168 */
+#
+# Specifically, test that "PRAGMA foreign_keys" is a no-op in this case.
+# When using the pragma to query the current setting, 0 rows are returned.
+#
+reset_db
+ifcapable !trigger&&foreignkey {
+ do_test e_fkey-51.1 {
+ execsql {
+ PRAGMA foreign_keys = ON;
+ CREATE TABLE p(i PRIMARY KEY);
+ CREATE TABLE c(j REFERENCES p ON UPDATE CASCADE);
+ INSERT INTO p VALUES('hello');
+ INSERT INTO c VALUES('hello');
+ UPDATE p SET i = 'world';
+ SELECT * FROM c;
+ }
+ } {hello}
+ do_test e_fkey-51.2 {
+ execsql { PRAGMA foreign_key_list(c) }
+ } {0 0 p j {} CASCADE {NO ACTION} NONE}
+ do_test e_fkey-51.3 {
+ execsql { PRAGMA foreign_keys }
+ } {}
+}
+
+
+#-------------------------------------------------------------------------
+# /* EV: R-58428-36660 */
+#
+# Test the effects of defining OMIT_FOREIGN_KEY.
+#
+# /* EV: R-58428-36660 */
+#
+# Specifically, test that foreign key constraints cannot even be parsed
+# in such a build.
+#
+reset_db
+ifcapable !foreignkey {
+ do_test e_fkey-52.1 {
+ execsql { CREATE TABLE p(i PRIMARY KEY) }
+ catchsql { CREATE TABLE c(j REFERENCES p ON UPDATE CASCADE) }
+ } {1 {near "ON": syntax error}}
+ do_test e_fkey-52.2 {
+ # This is allowed, as in this build, "REFERENCES" is not a keyword.
+ # The declared datatype of column j is "REFERENCES p".
+ execsql { CREATE TABLE c(j REFERENCES p) }
+ } {}
+ do_test e_fkey-52.3 {
+ execsql { PRAGMA table_info(c) }
+ } {0 j {REFERENCES p} 0 {} 0}
+ do_test e_fkey-52.4 {
+ execsql { PRAGMA foreign_key_list(c) }
+ } {}
+ do_test e_fkey-52.5 {
+ execsql { PRAGMA foreign_keys }
+ } {}
+}
+
+ifcapable !foreignkey||!trigger { finish_test ; return }
+reset_db
+
+
+#-------------------------------------------------------------------------
+# /* EV: R-07280-60510 */
+#
+# Test that even if foreign keys are supported by the build, they must
+# be enabled using "PRAGMA foreign_keys = ON" (or similar).
+#
+# /* EV: R-15831-45974 */
+#
+# This also tests that foreign key constraints are disabled by default.
+#
+drop_all_tables
+do_test e_fkey-53.1 {
+ execsql {
+ CREATE TABLE p(i PRIMARY KEY);
+ CREATE TABLE c(j REFERENCES p ON UPDATE CASCADE);
+ INSERT INTO p VALUES('hello');
+ INSERT INTO c VALUES('hello');
+ UPDATE p SET i = 'world';
+ SELECT * FROM c;
+ }
+} {hello}
+do_test e_fkey-53.2 {
+ execsql {
+ DELETE FROM c;
+ DELETE FROM p;
+ PRAGMA foreign_keys = ON;
+ INSERT INTO p VALUES('hello');
+ INSERT INTO c VALUES('hello');
+ UPDATE p SET i = 'world';
+ SELECT * FROM c;
+ }
+} {world}
+
+#-------------------------------------------------------------------------
+# /* EV: R-15278-54456 */
+# /* EV: R-11255-19907 */
+#
+# Test that the application can use "PRAGMA foreign_keys" to query for
+# whether or not foreign keys are currently enabled. This also tests
+# the example code in section 2 of foreignkeys.in.
+#
+reset_db
+do_test e_fkey-54.1 {
+ execsql { PRAGMA foreign_keys }
+} {0}
+do_test e_fkey-54.2 {
+ execsql {
+ PRAGMA foreign_keys = ON;
+ PRAGMA foreign_keys;
+ }
+} {1}
+do_test e_fkey-54.3 {
+ execsql {
+ PRAGMA foreign_keys = OFF;
+ PRAGMA foreign_keys;
+ }
+} {0}
+
+#-------------------------------------------------------------------------
+# /* EV: R-07050-54503 */
+#
+# Test that it is not possible to enable or disable foreign key support
+# while not in auto-commit mode.
+#
+reset_db
+do_test e_fkey-55.1 {
+ execsql {
+ PRAGMA foreign_keys = ON;
+ CREATE TABLE t1(a UNIQUE, b);
+ CREATE TABLE t2(c, d REFERENCES t1(a));
+ INSERT INTO t1 VALUES(1, 2);
+ INSERT INTO t2 VALUES(2, 1);
+ BEGIN;
+ PRAGMA foreign_keys = OFF;
+ }
+ catchsql {
+ DELETE FROM t1
+ }
+} {1 {foreign key constraint failed}}
+do_test e_fkey-55.2 {
+ execsql { PRAGMA foreign_keys }
+} {1}
+do_test e_fkey-55.3 {
+ execsql {
+ COMMIT;
+ PRAGMA foreign_keys = OFF;
+ BEGIN;
+ PRAGMA foreign_keys = ON;
+ DELETE FROM t1;
+ PRAGMA foreign_keys;
+ }
+} {0}
+do_test e_fkey-55.4 {
+ execsql COMMIT
+} {}
###########################################################################
### SECTION 1: Introduction to Foreign Key Constraints
###########################################################################
+execsql "PRAGMA foreign_keys = ON"
#-------------------------------------------------------------------------
# /* EV: R-04042-24825 */
catchsql { DELETE FROM t1 WHERE rowid = 2 }
} {1 {foreign key constraint failed}}
-###########################################################################
-### SECTION 2: Enabling Foreign Key Support
-###########################################################################
-
###########################################################################
### SECTION 3: Required and Suggested Database Indexes
###########################################################################