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
#***********************************************************************
11
# This file implements regression tests for SQLite library.
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.
19
set testdir [file dirname $argv0]
20
source $testdir/tester.tcl
22
ifcapable {!foreignkey||!trigger} {
27
# Create a table and some data to work with.
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);
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]
46
set ::STMT2 [sqlite3_prepare_v2 $::DB $::SQL -1 TAIL]
50
db eval {SELECT * FROM t2}
52
sqlite3_finalize $::STMT1
53
sqlite3_finalize $::STMT2