3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file implements tests for foreign keys.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
19 ifcapable {!foreignkey||!trigger} {
24 # Create a table and some data to work with.
28 PRAGMA foreign_keys=ON;
29 CREATE TABLE t1(x INTEGER PRIMARY KEY);
30 INSERT INTO t1 VALUES(100);
31 INSERT INTO t1 VALUES(101);
32 CREATE TABLE t2(y INTEGER REFERENCES t1 (x));
33 INSERT INTO t2 VALUES(100);
34 INSERT INTO t2 VALUES(101);
38 } {1 100 1 101 2 100 2 101}
42 DELETE FROM t1 WHERE x=100;
44 } {1 {foreign key constraint failed}}
50 } {1 {foreign key constraint failed}}
66 PRAGMA foreign_keys=ON;
67 CREATE TABLE t1(x INTEGER PRIMARY KEY);
68 INSERT INTO t1 VALUES(100);
69 INSERT INTO t1 VALUES(101);
70 CREATE TABLE t2(y INTEGER PRIMARY KEY REFERENCES t1 (x) ON UPDATE SET NULL);
73 INSERT INTO t2 VALUES(100);
74 INSERT INTO t2 VALUES(101);
78 } {1 100 1 101 2 100 2 101}