sl@0: # 2001 September 15 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. sl@0: # sl@0: # This file implements tests for foreign keys. sl@0: # sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: ifcapable {!foreignkey} { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: # Create a table and some data to work with. sl@0: # sl@0: do_test fkey1-1.0 { sl@0: execsql { sl@0: CREATE TABLE t1( sl@0: a INTEGER PRIMARY KEY, sl@0: b INTEGER sl@0: REFERENCES t1 ON DELETE CASCADE sl@0: REFERENCES t2, sl@0: c TEXT, sl@0: FOREIGN KEY (b,c) REFERENCES t2(x,y) ON UPDATE CASCADE sl@0: ); sl@0: } sl@0: } {} sl@0: do_test fkey1-1.1 { sl@0: execsql { sl@0: CREATE TABLE t2( sl@0: x INTEGER PRIMARY KEY, sl@0: y TEXT sl@0: ); sl@0: } sl@0: } {} sl@0: do_test fkey1-1.2 { sl@0: execsql { sl@0: CREATE TABLE t3( sl@0: a INTEGER REFERENCES t2 ON INSERT RESTRICT, sl@0: b INTEGER REFERENCES t1, sl@0: FOREIGN KEY (a,b) REFERENCES t2(x,y) sl@0: ); sl@0: } sl@0: } {} sl@0: sl@0: do_test fkey1-2.1 { sl@0: execsql { sl@0: CREATE TABLE t4(a integer primary key); sl@0: CREATE TABLE t5(x references t4); sl@0: CREATE TABLE t6(x references t4); sl@0: CREATE TABLE t7(x references t4); sl@0: CREATE TABLE t8(x references t4); sl@0: CREATE TABLE t9(x references t4); sl@0: CREATE TABLE t10(x references t4); sl@0: DROP TABLE t7; sl@0: DROP TABLE t9; sl@0: DROP TABLE t5; sl@0: DROP TABLE t8; sl@0: DROP TABLE t6; sl@0: DROP TABLE t10; sl@0: } sl@0: } {} sl@0: sl@0: sl@0: sl@0: sl@0: finish_test