aboutsummaryrefslogtreecommitdiff
path: root/testdata/tcl/triggerF.test
diff options
context:
space:
mode:
authorJan Mercl <0xjnml@gmail.com>2020-07-26 22:36:18 +0200
committerJan Mercl <0xjnml@gmail.com>2020-07-26 22:36:18 +0200
commitb406626c64313ae348996c243a0a05d3f6ed2c3c (patch)
tree0eaae4fa6348b150568725e6f2ec0b4c4203b5f8 /testdata/tcl/triggerF.test
parentd8d9f40ce80062793349c0ea47520b6878312f4a (diff)
release v1.4.0-beta1v1.4.0-beta1
Diffstat (limited to 'testdata/tcl/triggerF.test')
-rw-r--r--testdata/tcl/triggerF.test71
1 files changed, 71 insertions, 0 deletions
diff --git a/testdata/tcl/triggerF.test b/testdata/tcl/triggerF.test
new file mode 100644
index 0000000..2e3e35e
--- /dev/null
+++ b/testdata/tcl/triggerF.test
@@ -0,0 +1,71 @@
+# 2017 January 4
+#
+# 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.
+#
+#***********************************************************************
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix triggerF
+ifcapable {!trigger} {
+ finish_test
+ return
+}
+
+
+foreach {tn sql log} {
+ 1 {} {}
+
+ 2 {
+ CREATE TRIGGER trd AFTER DELETE ON t1 BEGIN
+ INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1));
+ END;
+ } {1one2 2two1 3three1}
+
+ 3 {
+ CREATE TRIGGER trd BEFORE DELETE ON t1 BEGIN
+ INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1));
+ END;
+ } {1one3 2two2 3three2}
+
+ 4 {
+ CREATE TRIGGER tr1 AFTER DELETE ON t1 BEGIN
+ INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1));
+ END;
+ CREATE TRIGGER tr2 BEFORE DELETE ON t1 BEGIN
+ INSERT INTO log VALUES(old.a || old.b || (SELECT count(*) FROM t1));
+ END;
+ } {1one3 1one2 2two2 2two1 3three2 3three1}
+
+} {
+ reset_db
+ do_execsql_test 1.$tn.0 {
+ PRAGMA recursive_triggers = on;
+ CREATE TABLE t1(a INT PRIMARY KEY, b) WITHOUT ROWID;
+ CREATE TABLE log(t);
+ }
+
+ execsql $sql
+
+ do_execsql_test 1.$tn.1 {
+ INSERT INTO t1 VALUES(1, 'one');
+ INSERT INTO t1 VALUES(2, 'two');
+ INSERT INTO t1 VALUES(3, 'three');
+
+ DELETE FROM t1 WHERE a=1;
+ INSERT OR REPLACE INTO t1 VALUES(2, 'three');
+ UPDATE OR REPLACE t1 SET a=3 WHERE a=2;
+ }
+
+ do_execsql_test 1.$tn.2 {
+ SELECT * FROM log ORDER BY rowid;
+ } $log
+}
+
+finish_test