diff options
author | Jan Mercl <0xjnml@gmail.com> | 2020-07-26 22:36:18 +0200 |
---|---|---|
committer | Jan Mercl <0xjnml@gmail.com> | 2020-07-26 22:36:18 +0200 |
commit | b406626c64313ae348996c243a0a05d3f6ed2c3c (patch) | |
tree | 0eaae4fa6348b150568725e6f2ec0b4c4203b5f8 /testdata/tcl/trigger6.test | |
parent | d8d9f40ce80062793349c0ea47520b6878312f4a (diff) |
release v1.4.0-beta1v1.4.0-beta1
Diffstat (limited to 'testdata/tcl/trigger6.test')
-rw-r--r-- | testdata/tcl/trigger6.test | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/testdata/tcl/trigger6.test b/testdata/tcl/trigger6.test new file mode 100644 index 0000000..bb343fa --- /dev/null +++ b/testdata/tcl/trigger6.test @@ -0,0 +1,82 @@ +# 2004 December 07 +# +# 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 regression tests for SQLite library. +# +# This file implements tests to make sure expression of an INSERT +# and UPDATE statement are only evaluated once. See ticket #980. +# If an expression uses a function that has side-effects or which +# is not deterministic (ex: random()) then we want to make sure +# that the same evaluation occurs for the actual INSERT/UPDATE and +# for the NEW.* fields of any triggers that fire. +# +# $Id: trigger6.test,v 1.2 2005/05/05 11:04:50 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +ifcapable {!trigger} { + finish_test + return +} + +do_test trigger6-1.1 { + execsql { + CREATE TABLE t1(x, y); + CREATE TABLE log(a, b, c); + CREATE TRIGGER r1 BEFORE INSERT ON t1 BEGIN + INSERT INTO log VALUES(1, new.x, new.y); + END; + CREATE TRIGGER r2 BEFORE UPDATE ON t1 BEGIN + INSERT INTO log VALUES(2, new.x, new.y); + END; + } + set ::trigger6_cnt 0 + proc trigger6_counter {args} { + incr ::trigger6_cnt + return $::trigger6_cnt + } + db function counter trigger6_counter + execsql { + INSERT INTO t1 VALUES(1,counter()); + SELECT * FROM t1; + } +} {1 1} +do_test trigger6-1.2 { + execsql { + SELECT * FROM log; + } +} {1 1 1} +do_test trigger6-1.3 { + execsql { + DELETE FROM t1; + DELETE FROM log; + INSERT INTO t1 VALUES(2,counter(2,3)+4); + SELECT * FROM t1; + } +} {2 6} +do_test trigger6-1.4 { + execsql { + SELECT * FROM log; + } +} {1 2 6} +do_test trigger6-1.5 { + execsql { + DELETE FROM log; + UPDATE t1 SET y=counter(5); + SELECT * FROM t1; + } +} {2 3} +do_test trigger6-1.6 { + execsql { + SELECT * FROM log; + } +} {2 2 3} + +finish_test |