OLD | NEW |
1 # 2009 September 22 | 1 # 2009 September 22 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 do_malloc_test fkey_malloc-1 -sqlprep { | 23 do_malloc_test fkey_malloc-1 -sqlprep { |
24 PRAGMA foreign_keys = 1; | 24 PRAGMA foreign_keys = 1; |
25 CREATE TABLE t1(a PRIMARY KEY, b UNIQUE); | 25 CREATE TABLE t1(a PRIMARY KEY, b UNIQUE); |
26 CREATE TABLE t2(x REFERENCES t1 ON UPDATE CASCADE ON DELETE CASCADE); | 26 CREATE TABLE t2(x REFERENCES t1 ON UPDATE CASCADE ON DELETE CASCADE); |
27 } -sqlbody { | 27 } -sqlbody { |
28 INSERT INTO t1 VALUES('aaa', 1); | 28 INSERT INTO t1 VALUES('aaa', 1); |
29 INSERT INTO t2 VALUES('aaa'); | 29 INSERT INTO t2 VALUES('aaa'); |
30 UPDATE t1 SET a = 'bbb'; | 30 UPDATE t1 SET a = 'bbb'; |
31 DELETE FROM t1; | 31 DELETE FROM t1; |
| 32 PRAGMA foreign_key_check; |
32 } | 33 } |
33 | 34 |
34 do_malloc_test fkey_malloc-2 -sqlprep { | 35 do_malloc_test fkey_malloc-2 -sqlprep { |
35 PRAGMA foreign_keys = 1; | 36 PRAGMA foreign_keys = 1; |
36 CREATE TABLE t1(a, b, UNIQUE(a, b)); | 37 CREATE TABLE t1(a, b, UNIQUE(a, b)); |
37 } -sqlbody { | 38 } -sqlbody { |
38 CREATE TABLE t2(x, y, | 39 CREATE TABLE t2(x, y, |
39 FOREIGN KEY(x, y) REFERENCES t1(a, b) DEFERRABLE INITIALLY DEFERRED | 40 FOREIGN KEY(x, y) REFERENCES t1(a, b) DEFERRABLE INITIALLY DEFERRED |
40 ); | 41 ); |
41 BEGIN; | 42 BEGIN; |
(...skipping 19 matching lines...) Expand all Loading... |
61 } | 62 } |
62 | 63 |
63 proc catch_fk_error {zSql} { | 64 proc catch_fk_error {zSql} { |
64 set rc [catch {db eval $zSql} msg] | 65 set rc [catch {db eval $zSql} msg] |
65 if {$rc==0} { | 66 if {$rc==0} { |
66 return $msg | 67 return $msg |
67 } | 68 } |
68 if {[string match {*foreign key*} $msg]} { | 69 if {[string match {*foreign key*} $msg]} { |
69 return "" | 70 return "" |
70 } | 71 } |
71 if {$msg eq "out of memory"} { | 72 if {$msg eq "out of memory" |
| 73 || $msg eq "FOREIGN KEY constraint failed" |
| 74 || $msg eq "constraint failed" |
| 75 } { |
72 error 1 | 76 error 1 |
73 } | 77 } |
74 error $msg | 78 error $msg |
75 } | 79 } |
76 | 80 |
77 do_malloc_test fkey_malloc-4 -sqlprep { | 81 do_malloc_test fkey_malloc-4 -sqlprep { |
78 PRAGMA foreign_keys = 1; | 82 PRAGMA foreign_keys = 1; |
79 CREATE TABLE t1(x INTEGER PRIMARY KEY, y UNIQUE); | 83 CREATE TABLE t1(x INTEGER PRIMARY KEY, y UNIQUE); |
80 CREATE TABLE t2(z REFERENCES t1(x), a REFERENCES t1(y)); | 84 CREATE TABLE t2(z REFERENCES t1(x), a REFERENCES t1(y)); |
81 CREATE TABLE t3(x); | 85 CREATE TABLE t3(x); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 CREATE TABLE y(c, d, | 125 CREATE TABLE y(c, d, |
122 FOREIGN KEY(d, c) REFERENCES x DEFERRABLE INITIALLY DEFERRED | 126 FOREIGN KEY(d, c) REFERENCES x DEFERRABLE INITIALLY DEFERRED |
123 ); | 127 ); |
124 CREATE TABLE z(e, f, FOREIGN KEY(e, f) REFERENCES x); | 128 CREATE TABLE z(e, f, FOREIGN KEY(e, f) REFERENCES x); |
125 } -sqlbody { | 129 } -sqlbody { |
126 DROP TABLE y; | 130 DROP TABLE y; |
127 DROP TABLE x; | 131 DROP TABLE x; |
128 } | 132 } |
129 | 133 |
130 finish_test | 134 finish_test |
131 | |
132 | |
OLD | NEW |