sl@0
|
1 |
# 2001 September 15
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
# This file implements regression tests for SQLite library.
|
sl@0
|
12 |
#
|
sl@0
|
13 |
# This file implements tests for foreign keys.
|
sl@0
|
14 |
#
|
sl@0
|
15 |
|
sl@0
|
16 |
set testdir [file dirname $argv0]
|
sl@0
|
17 |
source $testdir/tester.tcl
|
sl@0
|
18 |
|
sl@0
|
19 |
ifcapable {!foreignkey} {
|
sl@0
|
20 |
finish_test
|
sl@0
|
21 |
return
|
sl@0
|
22 |
}
|
sl@0
|
23 |
|
sl@0
|
24 |
# Create a table and some data to work with.
|
sl@0
|
25 |
#
|
sl@0
|
26 |
do_test fkey1-1.0 {
|
sl@0
|
27 |
execsql {
|
sl@0
|
28 |
CREATE TABLE t1(
|
sl@0
|
29 |
a INTEGER PRIMARY KEY,
|
sl@0
|
30 |
b INTEGER
|
sl@0
|
31 |
REFERENCES t1 ON DELETE CASCADE
|
sl@0
|
32 |
REFERENCES t2,
|
sl@0
|
33 |
c TEXT,
|
sl@0
|
34 |
FOREIGN KEY (b,c) REFERENCES t2(x,y) ON UPDATE CASCADE
|
sl@0
|
35 |
);
|
sl@0
|
36 |
}
|
sl@0
|
37 |
} {}
|
sl@0
|
38 |
do_test fkey1-1.1 {
|
sl@0
|
39 |
execsql {
|
sl@0
|
40 |
CREATE TABLE t2(
|
sl@0
|
41 |
x INTEGER PRIMARY KEY,
|
sl@0
|
42 |
y TEXT
|
sl@0
|
43 |
);
|
sl@0
|
44 |
}
|
sl@0
|
45 |
} {}
|
sl@0
|
46 |
do_test fkey1-1.2 {
|
sl@0
|
47 |
execsql {
|
sl@0
|
48 |
CREATE TABLE t3(
|
sl@0
|
49 |
a INTEGER REFERENCES t2 ON INSERT RESTRICT,
|
sl@0
|
50 |
b INTEGER REFERENCES t1,
|
sl@0
|
51 |
FOREIGN KEY (a,b) REFERENCES t2(x,y)
|
sl@0
|
52 |
);
|
sl@0
|
53 |
}
|
sl@0
|
54 |
} {}
|
sl@0
|
55 |
|
sl@0
|
56 |
do_test fkey1-2.1 {
|
sl@0
|
57 |
execsql {
|
sl@0
|
58 |
CREATE TABLE t4(a integer primary key);
|
sl@0
|
59 |
CREATE TABLE t5(x references t4);
|
sl@0
|
60 |
CREATE TABLE t6(x references t4);
|
sl@0
|
61 |
CREATE TABLE t7(x references t4);
|
sl@0
|
62 |
CREATE TABLE t8(x references t4);
|
sl@0
|
63 |
CREATE TABLE t9(x references t4);
|
sl@0
|
64 |
CREATE TABLE t10(x references t4);
|
sl@0
|
65 |
DROP TABLE t7;
|
sl@0
|
66 |
DROP TABLE t9;
|
sl@0
|
67 |
DROP TABLE t5;
|
sl@0
|
68 |
DROP TABLE t8;
|
sl@0
|
69 |
DROP TABLE t6;
|
sl@0
|
70 |
DROP TABLE t10;
|
sl@0
|
71 |
}
|
sl@0
|
72 |
} {}
|
sl@0
|
73 |
|
sl@0
|
74 |
|
sl@0
|
75 |
|
sl@0
|
76 |
|
sl@0
|
77 |
finish_test
|