3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # This file implements tests for the REGEXP operator in ext/misc/regexp.c.
13 # It focuses on the use of the sqlite3_set_auxdata()/get_auxdata() APIs.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 set testprefix regexp2
20 load_static_extension db regexp
22 #-------------------------------------------------------------------------
23 # Test that triggers do not become confused and use aux-data created by
24 # a different trigger for a different REGEXP invocation.
27 CREATE TABLE t1(a, b, c);
28 CREATE TABLE x1(x, y, z);
29 CREATE TABLE x2(x, y, z);
31 CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
32 INSERT INTO x1 VALUES(
39 CREATE TRIGGER tr2 AFTER INSERT ON t1 BEGIN
40 INSERT INTO x2 VALUES(
47 INSERT INTO t1 VALUES('abc', 'def', 'abc');
51 do_execsql_test 1.1 { SELECT * FROM x1 } {1 0 1}
52 do_execsql_test 1.2 { SELECT * FROM x2 } {0 1 0}
54 #-------------------------------------------------------------------------
55 # Test that if an exception is thrown several triggers deep, all aux-data
56 # objects are cleaned up correctly.
61 db func error sql_error
63 CREATE TABLE t2(a, b);
64 CREATE TABLE t3(c, d);
65 CREATE TABLE t4(e, f);
67 CREATE TRIGGER t2_tr1 AFTER UPDATE ON t2 BEGIN
68 UPDATE t3 SET d = new.b WHERE c = old.a;
71 CREATE TRIGGER t3_tr1 AFTER UPDATE ON t3 BEGIN
72 UPDATE t4 SET f = new.d WHERE e = old.c AND new.d REGEXP 'a.*';
75 CREATE TRIGGER t4_tr1 AFTER UPDATE ON t4 BEGIN
76 SELECT CASE WHEN new.f REGEXP '.*y.*' THEN error() ELSE 1 END;
79 INSERT INTO t2 VALUES(1, 'a_x_1');
80 INSERT INTO t2 VALUES(2, 'a_y_1');
82 INSERT INTO t3 VALUES(1, 'b1');
83 INSERT INTO t3 VALUES(2, 'b2');
85 INSERT INTO t4 VALUES(1, 'b1');
86 INSERT INTO t4 VALUES(2, 'b2');
89 do_catchsql_test 2.1 {
90 UPDATE t2 SET a=a+1 WHERE b REGEXP 'a.*' AND b REGEXP '.*1';
93 # Test that the triggers used in the test above work as expected.
96 UPDATE t2 SET b = 'a_abc_1';
102 } {1 a_abc_1 2 a_abc_1 1 a_abc_1 2 a_abc_1 1 a_abc_1 2 a_abc_1}
104 #-------------------------------------------------------------------------
105 # Test that trigger parameters (i.e. new.* and old.*) refs are not
106 # considered to be constant across separate invocations of the trigger.
108 do_execsql_test 3.0 {
112 CREATE TRIGGER t5tr AFTER DELETE ON t5 BEGIN
113 DELETE FROM t6 WHERE t6.x REGEXP old.a;
116 INSERT INTO t5 VALUES ('^a.*'), ('^b.*'), ('^c.*');
117 INSERT INTO t6 VALUES ('eab'), ('abc'), ('bcd'), ('cde'), ('dea');