1*4e1f0efbSdan# 2017 January 4 2*4e1f0efbSdan# 3*4e1f0efbSdan# The author disclaims copyright to this source code. In place of 4*4e1f0efbSdan# a legal notice', here is a blessing: 5*4e1f0efbSdan# 6*4e1f0efbSdan# May you do good and not evil. 7*4e1f0efbSdan# May you find forgiveness for yourself and forgive others. 8*4e1f0efbSdan# May you share freely, never taking more than you give. 9*4e1f0efbSdan# 10*4e1f0efbSdan#*********************************************************************** 11*4e1f0efbSdan# 12*4e1f0efbSdan 13*4e1f0efbSdanset testdir [file dirname $argv0] 14*4e1f0efbSdansource $testdir/tester.tcl 15*4e1f0efbSdanset testprefix triggerF 16*4e1f0efbSdanifcapable {!trigger} { 17*4e1f0efbSdan finish_test 18*4e1f0efbSdan return 19*4e1f0efbSdan} 20*4e1f0efbSdan 21*4e1f0efbSdan 22*4e1f0efbSdanforeach {tn sql log} { 23*4e1f0efbSdan 1 {} {} 24*4e1f0efbSdan 25*4e1f0efbSdan 2 { 26*4e1f0efbSdan CREATE TRIGGER trd AFTER DELETE ON t1 BEGIN 27*4e1f0efbSdan INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1)); 28*4e1f0efbSdan END; 29*4e1f0efbSdan } {1one2 2two1 3three1} 30*4e1f0efbSdan 31*4e1f0efbSdan 3 { 32*4e1f0efbSdan CREATE TRIGGER trd BEFORE DELETE ON t1 BEGIN 33*4e1f0efbSdan INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1)); 34*4e1f0efbSdan END; 35*4e1f0efbSdan } {1one3 2two2 3three2} 36*4e1f0efbSdan 37*4e1f0efbSdan 4 { 38*4e1f0efbSdan CREATE TRIGGER tr1 AFTER DELETE ON t1 BEGIN 39*4e1f0efbSdan INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1)); 40*4e1f0efbSdan END; 41*4e1f0efbSdan CREATE TRIGGER tr2 BEFORE DELETE ON t1 BEGIN 42*4e1f0efbSdan INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1)); 43*4e1f0efbSdan END; 44*4e1f0efbSdan } {1one3 1one2 2two2 2two1 3three2 3three1} 45*4e1f0efbSdan 46*4e1f0efbSdan} { 47*4e1f0efbSdan reset_db 48*4e1f0efbSdan do_execsql_test 1.$tn.0 { 49*4e1f0efbSdan PRAGMA recursive_triggers = on; 50*4e1f0efbSdan CREATE TABLE t1(a INT PRIMARY KEY, b) WITHOUT ROWID; 51*4e1f0efbSdan CREATE TABLE log(t); 52*4e1f0efbSdan } 53*4e1f0efbSdan 54*4e1f0efbSdan execsql $sql 55*4e1f0efbSdan 56*4e1f0efbSdan do_execsql_test 1.$tn.1 { 57*4e1f0efbSdan INSERT INTO t1 VALUES(1, 'one'); 58*4e1f0efbSdan INSERT INTO t1 VALUES(2, 'two'); 59*4e1f0efbSdan INSERT INTO t1 VALUES(3, 'three'); 60*4e1f0efbSdan 61*4e1f0efbSdan DELETE FROM t1 WHERE a=1; 62*4e1f0efbSdan INSERT OR REPLACE INTO t1 VALUES(2, 'three'); 63*4e1f0efbSdan UPDATE OR REPLACE t1 SET a=3 WHERE a=2; 64*4e1f0efbSdan } 65*4e1f0efbSdan 66*4e1f0efbSdan do_execsql_test 1.$tn.2 { 67*4e1f0efbSdan SELECT * FROM log ORDER BY rowid; 68*4e1f0efbSdan } $log 69*4e1f0efbSdan} 70*4e1f0efbSdan 71*4e1f0efbSdanfinish_test 72