xref: /sqlite-3.40.0/test/triggerG.test (revision ab087d4e)
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
47finish_test
48