1# 2017-03-24 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 triggerG 16ifcapable {!trigger} { 17 finish_test 18 return 19} 20 21# Test cases for ticket 22# https://www.sqlite.org/src/tktview/06796225f59c057cd120f 23# 24# The OP_Once opcode was not working correctly for recursive triggers. 25# 26do_execsql_test 100 { 27 PRAGMA recursive_triggers = 1; 28 29 CREATE TABLE t1(a); 30 CREATE INDEX i1 ON t1(a); 31 INSERT INTO t1(a) VALUES(0),(2),(3),(8),(9); 32 CREATE TABLE t2(b); 33 CREATE TABLE t3(c); 34 35 CREATE TRIGGER tr AFTER INSERT ON t3 BEGIN 36 INSERT INTO t3 SELECT new.c+1 WHERE new.c<5; 37 INSERT INTO t2 SELECT new.c*100+a FROM t1 WHERE a IN (1, 2, 3, 4); 38 END; 39 40 INSERT INTO t3 VALUES(2); 41 SELECT c FROM t3 ORDER BY c;; 42} {2 3 4 5} 43do_execsql_test 110 { 44 SELECT b FROM t2 ORDER BY b; 45} {202 203 302 303 402 403 502 503} 46 47do_execsql_test 200 { 48 DELETE FROM t1; 49 INSERT INTO t1(a) VALUES(0),(2),(3),(8),(9); 50 DELETE FROM t2; 51 DELETE FROM t3; 52 DROP TRIGGER tr; 53 CREATE TRIGGER tr AFTER INSERT ON t3 BEGIN 54 INSERT INTO t3 SELECT new.c+1 WHERE new.c<5; 55 INSERT INTO t2 SELECT new.c*10000+xx.a*100+yy.a 56 FROM t1 AS xx, t1 AS yy 57 WHERE xx.a IN (1,2,3,4) 58 AND yy.a IN (2,3,4,5); 59 END; 60 61 INSERT INTO t3 VALUES(2); 62 SELECT b FROM t2 ORDER BY b; 63} {20202 20203 20302 20303 30202 30203 30302 30303 40202 40203 40302 40303 50202 50203 50302 50303} 64 65finish_test 66