blob: c2682edbe5fbf3a286693b380046f6592f77e472 [file] [log] [blame]
dan8ff2d952013-09-05 18:40:29 +00001# 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
18set testprefix fkey7
19
20ifcapable {!foreignkey} {
21 finish_test
22 return
23}
24
25do_execsql_test 1.1 {
26 PRAGMA foreign_keys = 1;
27
28 CREATE TABLE s1(a PRIMARY KEY, b);
29 CREATE TABLE par(a, b REFERENCES s1, c UNIQUE, PRIMARY KEY(a));
30
31 CREATE TABLE c1(a, b REFERENCES par);
32 CREATE TABLE c2(a, b REFERENCES par);
33 CREATE TABLE c3(a, b REFERENCES par(c));
34}
35
36proc auth {op tbl args} {
37 if {$op == "SQLITE_READ"} { set ::tbls($tbl) 1 }
38 return "SQLITE_OK"
39}
40db auth auth
41db cache size 0
42proc do_tblsread_test {tn sql tbllist} {
43 array unset ::tbls
44 uplevel [list execsql $sql]
45 uplevel [list do_test $tn {lsort [array names ::tbls]} $tbllist]
46}
47
48do_tblsread_test 1.2 { UPDATE par SET b=? WHERE a=? } {par s1}
49do_tblsread_test 1.3 { UPDATE par SET a=? WHERE b=? } {c1 c2 par}
50do_tblsread_test 1.4 { UPDATE par SET c=? WHERE b=? } {c3 par}
51do_tblsread_test 1.5 { UPDATE par SET a=?,b=?,c=? WHERE b=? } {c1 c2 c3 par s1}
52
53
54finish_test