1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/trigger6.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,82 @@
1.4 +# 2004 December 07
1.5 +#
1.6 +# The author disclaims copyright to this source code. In place of
1.7 +# a legal notice, here is a blessing:
1.8 +#
1.9 +# May you do good and not evil.
1.10 +# May you find forgiveness for yourself and forgive others.
1.11 +# May you share freely, never taking more than you give.
1.12 +#
1.13 +#***********************************************************************
1.14 +# This file implements regression tests for SQLite library.
1.15 +#
1.16 +# This file implements tests to make sure expression of an INSERT
1.17 +# and UPDATE statement are only evaluated once. See ticket #980.
1.18 +# If an expression uses a function that has side-effects or which
1.19 +# is not deterministic (ex: random()) then we want to make sure
1.20 +# that the same evaluation occurs for the actual INSERT/UPDATE and
1.21 +# for the NEW.* fields of any triggers that fire.
1.22 +#
1.23 +# $Id: trigger6.test,v 1.2 2005/05/05 11:04:50 drh Exp $
1.24 +
1.25 +set testdir [file dirname $argv0]
1.26 +source $testdir/tester.tcl
1.27 +ifcapable {!trigger} {
1.28 + finish_test
1.29 + return
1.30 +}
1.31 +
1.32 +do_test trigger6-1.1 {
1.33 + execsql {
1.34 + CREATE TABLE t1(x, y);
1.35 + CREATE TABLE log(a, b, c);
1.36 + CREATE TRIGGER r1 BEFORE INSERT ON t1 BEGIN
1.37 + INSERT INTO log VALUES(1, new.x, new.y);
1.38 + END;
1.39 + CREATE TRIGGER r2 BEFORE UPDATE ON t1 BEGIN
1.40 + INSERT INTO log VALUES(2, new.x, new.y);
1.41 + END;
1.42 + }
1.43 + set ::trigger6_cnt 0
1.44 + proc trigger6_counter {args} {
1.45 + incr ::trigger6_cnt
1.46 + return $::trigger6_cnt
1.47 + }
1.48 + db function counter trigger6_counter
1.49 + execsql {
1.50 + INSERT INTO t1 VALUES(1,counter());
1.51 + SELECT * FROM t1;
1.52 + }
1.53 +} {1 1}
1.54 +do_test trigger6-1.2 {
1.55 + execsql {
1.56 + SELECT * FROM log;
1.57 + }
1.58 +} {1 1 1}
1.59 +do_test trigger6-1.3 {
1.60 + execsql {
1.61 + DELETE FROM t1;
1.62 + DELETE FROM log;
1.63 + INSERT INTO t1 VALUES(2,counter(2,3)+4);
1.64 + SELECT * FROM t1;
1.65 + }
1.66 +} {2 6}
1.67 +do_test trigger6-1.4 {
1.68 + execsql {
1.69 + SELECT * FROM log;
1.70 + }
1.71 +} {1 2 6}
1.72 +do_test trigger6-1.5 {
1.73 + execsql {
1.74 + DELETE FROM log;
1.75 + UPDATE t1 SET y=counter(5);
1.76 + SELECT * FROM t1;
1.77 + }
1.78 +} {2 3}
1.79 +do_test trigger6-1.6 {
1.80 + execsql {
1.81 + SELECT * FROM log;
1.82 + }
1.83 +} {2 2 3}
1.84 +
1.85 +finish_test