1# 2011 Feb 04 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 test deferred foreign key constraint processing to make 14# sure that when a statement not within BEGIN...END fails a constraint, 15# that statement doesn't hold the transaction open thus allowing 16# a subsequent statement to fail a deferred constraint with impunity. 17# 18 19set testdir [file dirname $argv0] 20source $testdir/tester.tcl 21 22ifcapable {!foreignkey||!trigger} { 23 finish_test 24 return 25} 26 27# Create a table and some data to work with. 28# 29do_test fkey4-1.1 { 30 execsql { 31 PRAGMA foreign_keys = ON; 32 CREATE TABLE t1(a PRIMARY KEY, b); 33 CREATE TABLE t2(c REFERENCES t1 DEFERRABLE INITIALLY DEFERRED, d); 34 INSERT INTO t1 VALUES(1,2); 35 INSERT INTO t2 VALUES(1,3); 36 } 37} {} 38 39do_test fkey4-1.2 { 40 set ::DB [sqlite3_connection_pointer db] 41 set ::SQL {INSERT INTO t2 VALUES(2,4)} 42 set ::STMT1 [sqlite3_prepare_v2 $::DB $::SQL -1 TAIL] 43 sqlite3_step $::STMT1 44} {SQLITE_CONSTRAINT} 45do_test fkey4-1.3 { 46 set ::STMT2 [sqlite3_prepare_v2 $::DB $::SQL -1 TAIL] 47 sqlite3_step $::STMT2 48} {SQLITE_CONSTRAINT} 49do_test fkey4-1.4 { 50 db eval {SELECT * FROM t2} 51} {1 3} 52sqlite3_finalize $::STMT1 53sqlite3_finalize $::STMT2 54 55finish_test 56