sl@0: # 2004 December 07 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. sl@0: # sl@0: # This file implements tests to make sure expression of an INSERT sl@0: # and UPDATE statement are only evaluated once. See ticket #980. sl@0: # If an expression uses a function that has side-effects or which sl@0: # is not deterministic (ex: random()) then we want to make sure sl@0: # that the same evaluation occurs for the actual INSERT/UPDATE and sl@0: # for the NEW.* fields of any triggers that fire. sl@0: # sl@0: # $Id: trigger6.test,v 1.2 2005/05/05 11:04:50 drh Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: ifcapable {!trigger} { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: do_test trigger6-1.1 { sl@0: execsql { sl@0: CREATE TABLE t1(x, y); sl@0: CREATE TABLE log(a, b, c); sl@0: CREATE TRIGGER r1 BEFORE INSERT ON t1 BEGIN sl@0: INSERT INTO log VALUES(1, new.x, new.y); sl@0: END; sl@0: CREATE TRIGGER r2 BEFORE UPDATE ON t1 BEGIN sl@0: INSERT INTO log VALUES(2, new.x, new.y); sl@0: END; sl@0: } sl@0: set ::trigger6_cnt 0 sl@0: proc trigger6_counter {args} { sl@0: incr ::trigger6_cnt sl@0: return $::trigger6_cnt sl@0: } sl@0: db function counter trigger6_counter sl@0: execsql { sl@0: INSERT INTO t1 VALUES(1,counter()); sl@0: SELECT * FROM t1; sl@0: } sl@0: } {1 1} sl@0: do_test trigger6-1.2 { sl@0: execsql { sl@0: SELECT * FROM log; sl@0: } sl@0: } {1 1 1} sl@0: do_test trigger6-1.3 { sl@0: execsql { sl@0: DELETE FROM t1; sl@0: DELETE FROM log; sl@0: INSERT INTO t1 VALUES(2,counter(2,3)+4); sl@0: SELECT * FROM t1; sl@0: } sl@0: } {2 6} sl@0: do_test trigger6-1.4 { sl@0: execsql { sl@0: SELECT * FROM log; sl@0: } sl@0: } {1 2 6} sl@0: do_test trigger6-1.5 { sl@0: execsql { sl@0: DELETE FROM log; sl@0: UPDATE t1 SET y=counter(5); sl@0: SELECT * FROM t1; sl@0: } sl@0: } {2 3} sl@0: do_test trigger6-1.6 { sl@0: execsql { sl@0: SELECT * FROM log; sl@0: } sl@0: } {2 2 3} sl@0: sl@0: finish_test