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 #***********************************************************************
12 # This file implements regression tests for SQLite library. The
13 # focus of this file is testing WITHOUT ROWID tables, and especially
14 # FOREIGN KEY constraints.
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 ifcapable {!foreignkey} {
25 # Create a table and some data to work with.
27 do_test without_rowid2-1.0 {
32 REFERENCES t1 ON DELETE CASCADE
35 FOREIGN KEY (b,c) REFERENCES t2(x,y) ON UPDATE CASCADE
39 do_test without_rowid2-1.1 {
47 do_test without_rowid2-1.2 {
52 FOREIGN KEY (a,b) REFERENCES t2(x,y)
57 do_test without_rowid2-2.1 {
59 CREATE TABLE t4(a int primary key) WITHOUT rowid;
60 CREATE TABLE t5(x references t4);
61 CREATE TABLE t6(x references t4);
62 CREATE TABLE t7(x references t4);
63 CREATE TABLE t8(x references t4);
64 CREATE TABLE t9(x references t4);
65 CREATE TABLE t10(x references t4);
75 do_test without_rowid2-3.1 {
77 CREATE TABLE t5(a PRIMARY KEY, b, c) WITHOUT rowid;
82 PRAGMA foreign_key_list(t6);
85 {0 0 t5 e c {NO ACTION} {NO ACTION} NONE} \
86 {1 0 t5 d {} {NO ACTION} {NO ACTION} NONE} \
88 do_test without_rowid2-3.2 {
90 CREATE TABLE t7(d, e, f,
91 FOREIGN KEY (d, e) REFERENCES t5(a, b)
93 PRAGMA foreign_key_list(t7);
96 {0 0 t5 d a {NO ACTION} {NO ACTION} NONE} \
97 {0 1 t5 e b {NO ACTION} {NO ACTION} NONE} \
99 do_test without_rowid2-3.3 {
101 CREATE TABLE t8(d, e, f,
102 FOREIGN KEY (d, e) REFERENCES t5 ON DELETE CASCADE ON UPDATE SET NULL
104 PRAGMA foreign_key_list(t8);
107 {0 0 t5 d {} {SET NULL} CASCADE NONE} \
108 {0 1 t5 e {} {SET NULL} CASCADE NONE} \
110 do_test without_rowid2-3.4 {
112 CREATE TABLE t9(d, e, f,
113 FOREIGN KEY (d, e) REFERENCES t5 ON DELETE CASCADE ON UPDATE SET DEFAULT
115 PRAGMA foreign_key_list(t9);
118 {0 0 t5 d {} {SET DEFAULT} CASCADE NONE} \
119 {0 1 t5 e {} {SET DEFAULT} CASCADE NONE} \
121 do_test without_rowid2-3.5 {
122 sqlite3_db_status db DBSTATUS_DEFERRED_FKS 0