diff options
author | dan <dan@noemail.net> | 2016-02-19 18:54:29 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2016-02-19 18:54:29 +0000 |
commit | 3200132add116844c8855bb479c698f7a3a98d34 (patch) | |
tree | d032cef55180479167b9226706d8750369aa0711 /test/regexp2.test | |
parent | b719e3a747f94b1be16f7daa36d99f8f7ac49a9c (diff) | |
download | sqlite-3200132add116844c8855bb479c698f7a3a98d34.tar.gz sqlite-3200132add116844c8855bb479c698f7a3a98d34.zip |
Use a separate list of aux-data structures for each trigger program at the VDBE level. Fix for [dc9b1c91].
FossilOrigin-Name: c4295725015d394f01b8563f47236e0890f1cc0d
Diffstat (limited to 'test/regexp2.test')
-rw-r--r-- | test/regexp2.test | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/test/regexp2.test b/test/regexp2.test new file mode 100644 index 000000000..07955e15e --- /dev/null +++ b/test/regexp2.test @@ -0,0 +1,105 @@ +# 2016 February 19 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests for the REGEXP operator in ext/misc/regexp.c. +# It focuses on the use of the sqlite3_set_auxdata()/get_auxdata() APIs. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix regexp2 + +load_static_extension db regexp + +#------------------------------------------------------------------------- +# Test that triggers do not become confused and use aux-data created by +# a different trigger for a different REGEXP invocation. +# +do_execsql_test 1.0 { + CREATE TABLE t1(a, b, c); + CREATE TABLE x1(x, y, z); + CREATE TABLE x2(x, y, z); + + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + INSERT INTO x1 VALUES( + new.a REGEXP 'abc', + new.b REGEXP 'abc', + new.c REGEXP 'abc' + ); + END; + + CREATE TRIGGER tr2 AFTER INSERT ON t1 BEGIN + INSERT INTO x2 VALUES( + new.a REGEXP 'def', + new.b REGEXP 'def', + new.c REGEXP 'def' + ); + END; + + INSERT INTO t1 VALUES('abc', 'def', 'abc'); + SELECT * FROM t1; +} {abc def abc} + +do_execsql_test 1.1 { SELECT * FROM x1 } {1 0 1} +do_execsql_test 1.2 { SELECT * FROM x2 } {0 1 0} + +#------------------------------------------------------------------------- +# Test that if an exception is thrown several triggers deep, all aux-data +# objects are cleaned up correctly. +# +proc sql_error {} { + error "SQL error!" +} +db func error sql_error +do_execsql_test 2.0 { + CREATE TABLE t2(a, b); + CREATE TABLE t3(c, d); + CREATE TABLE t4(e, f); + + CREATE TRIGGER t2_tr1 AFTER UPDATE ON t2 BEGIN + UPDATE t3 SET d = new.b WHERE c = old.a; + END; + + CREATE TRIGGER t3_tr1 AFTER UPDATE ON t3 BEGIN + UPDATE t4 SET f = new.d WHERE e = old.c AND new.d REGEXP 'a.*'; + END; + + CREATE TRIGGER t4_tr1 AFTER UPDATE ON t4 BEGIN + SELECT CASE WHEN new.f REGEXP '.*y.*' THEN error() ELSE 1 END; + END; + + INSERT INTO t2 VALUES(1, 'a_x_1'); + INSERT INTO t2 VALUES(2, 'a_y_1'); + + INSERT INTO t3 VALUES(1, 'b1'); + INSERT INTO t3 VALUES(2, 'b2'); + + INSERT INTO t4 VALUES(1, 'b1'); + INSERT INTO t4 VALUES(2, 'b2'); +} {} + +do_catchsql_test 2.1 { + UPDATE t2 SET a=a+1 WHERE b REGEXP 'a.*' AND b REGEXP '.*1'; +} {1 {SQL error!}} + +# Test that the triggers used in the test above work as expected. +# +do_execsql_test 2.2 { + UPDATE t2 SET b = 'a_abc_1'; +} {} +do_execsql_test 2.3 { + SELECT * FROM t2; + SELECT * FROM t3; + SELECT * FROM t4; +} {1 a_abc_1 2 a_abc_1 1 a_abc_1 2 a_abc_1 1 a_abc_1 2 a_abc_1} + +finish_test + |