xref: /sqlite-3.40.0/test/fkey1.test (revision 4dcbdbff)
1# 2001 September 15
2#
3# The author disclaims copyright to this source code.  In place of
4# a legal notice, here is a blessing:
5#
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.
9#
10#***********************************************************************
11# This file implements regression tests for SQLite library.
12#
13# This file implements tests for foreign keys.
14#
15
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18
19ifcapable {!foreignkey} {
20  finish_test
21  return
22}
23
24# Create a table and some data to work with.
25#
26do_test fkey1-1.0 {
27  execsql {
28    CREATE TABLE t1(
29      a INTEGER PRIMARY KEY,
30      b INTEGER
31           REFERENCES t1 ON DELETE CASCADE
32           REFERENCES t2,
33      c TEXT,
34      FOREIGN KEY (b,c) REFERENCES t2(x,y) ON UPDATE CASCADE
35    );
36  }
37} {}
38do_test fkey1-1.1 {
39  execsql {
40    CREATE TABLE t2(
41      x INTEGER PRIMARY KEY,
42      y TEXT
43    );
44  }
45} {}
46do_test fkey1-1.2 {
47  execsql {
48    CREATE TABLE t3(
49      a INTEGER REFERENCES t2,
50      b INTEGER REFERENCES t1,
51      FOREIGN KEY (a,b) REFERENCES t2(x,y)
52    );
53  }
54} {}
55
56
57
58finish_test
59