1# 2017 January 4 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# 12 13set testdir [file dirname $argv0] 14source $testdir/tester.tcl 15set testprefix triggerF 16ifcapable {!trigger} { 17 finish_test 18 return 19} 20 21 22foreach {tn sql log} { 23 1 {} {} 24 25 2 { 26 CREATE TRIGGER trd AFTER DELETE ON t1 BEGIN 27 INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1)); 28 END; 29 } {1one2 2two1 3three1} 30 31 3 { 32 CREATE TRIGGER trd BEFORE DELETE ON t1 BEGIN 33 INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1)); 34 END; 35 } {1one3 2two2 3three2} 36 37 4 { 38 CREATE TRIGGER tr1 AFTER DELETE ON t1 BEGIN 39 INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1)); 40 END; 41 CREATE TRIGGER tr2 BEFORE DELETE ON t1 BEGIN 42 INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1)); 43 END; 44 } {1one3 1one2 2two2 2two1 3three2 3three1} 45 46} { 47 reset_db 48 do_execsql_test 1.$tn.0 { 49 PRAGMA recursive_triggers = on; 50 CREATE TABLE t1(a INT PRIMARY KEY, b) WITHOUT ROWID; 51 CREATE TABLE log(t); 52 } 53 54 execsql $sql 55 56 do_execsql_test 1.$tn.1 { 57 INSERT INTO t1 VALUES(1, 'one'); 58 INSERT INTO t1 VALUES(2, 'two'); 59 INSERT INTO t1 VALUES(3, 'three'); 60 61 DELETE FROM t1 WHERE a=1; 62 INSERT OR REPLACE INTO t1 VALUES(2, 'three'); 63 UPDATE OR REPLACE t1 SET a=3 WHERE a=2; 64 } 65 66 do_execsql_test 1.$tn.2 { 67 SELECT * FROM log ORDER BY rowid; 68 } $log 69} 70 71finish_test 72