2009-09-22 15:53:47 +00:00
|
|
|
# 2009 September 22
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
|
|
|
|
|
|
|
ifcapable !foreignkey||!trigger {
|
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
|
|
|
source $testdir/malloc_common.tcl
|
|
|
|
|
|
|
|
do_malloc_test fkey_malloc-1 -sqlprep {
|
|
|
|
PRAGMA foreign_keys = 1;
|
|
|
|
CREATE TABLE t1(a PRIMARY KEY, b);
|
|
|
|
CREATE TABLE t2(x REFERENCES t1 ON UPDATE CASCADE ON DELETE CASCADE);
|
|
|
|
} -sqlbody {
|
|
|
|
INSERT INTO t1 VALUES('aaa', 1);
|
|
|
|
INSERT INTO t2 VALUES('aaa');
|
|
|
|
UPDATE t1 SET a = 'bbb';
|
|
|
|
DELETE FROM t1;
|
|
|
|
}
|
|
|
|
|
2009-09-22 16:55:38 +00:00
|
|
|
do_malloc_test fkey_malloc-2 -sqlprep {
|
|
|
|
PRAGMA foreign_keys = 1;
|
|
|
|
CREATE TABLE t1(a, b, UNIQUE(a, b));
|
|
|
|
} -sqlbody {
|
|
|
|
CREATE TABLE t2(x, y,
|
|
|
|
FOREIGN KEY(x, y) REFERENCES t1(a, b) DEFERRABLE INITIALLY DEFERRED
|
|
|
|
);
|
|
|
|
BEGIN;
|
|
|
|
INSERT INTO t2 VALUES('a', 'b');
|
|
|
|
INSERT INTO t1 VALUES('a', 'b');
|
|
|
|
UPDATE t1 SET a = 'c';
|
|
|
|
DELETE FROM t2;
|
|
|
|
INSERT INTO t2 VALUES('d', 'b');
|
|
|
|
UPDATE t2 SET x = 'c';
|
|
|
|
COMMIT;
|
|
|
|
}
|
|
|
|
|
2009-09-22 15:53:47 +00:00
|
|
|
finish_test
|
|
|
|
|
|
|
|
|