1*4520Snw141292 2*4520Snw141292#pragma ident "%Z%%M% %I% %E% SMI" 3*4520Snw141292 4*4520Snw141292# 2004 Jan 14 5*4520Snw141292# 6*4520Snw141292# The author disclaims copyright to this source code. In place of 7*4520Snw141292# a legal notice, here is a blessing: 8*4520Snw141292# 9*4520Snw141292# May you do good and not evil. 10*4520Snw141292# May you find forgiveness for yourself and forgive others. 11*4520Snw141292# May you share freely, never taking more than you give. 12*4520Snw141292# 13*4520Snw141292#*********************************************************************** 14*4520Snw141292# This file implements regression tests for TCL interface to the 15*4520Snw141292# SQLite library. 16*4520Snw141292# 17*4520Snw141292# The focus of the tests in this file is the following interface: 18*4520Snw141292# 19*4520Snw141292# sqlite_commit_hook 20*4520Snw141292# 21*4520Snw141292# $Id: hook.test,v 1.3 2004/01/15 02:44:03 drh Exp $ 22*4520Snw141292 23*4520Snw141292set testdir [file dirname $argv0] 24*4520Snw141292source $testdir/tester.tcl 25*4520Snw141292 26*4520Snw141292do_test hook-1.2 { 27*4520Snw141292 db commit_hook 28*4520Snw141292} {} 29*4520Snw141292 30*4520Snw141292 31*4520Snw141292do_test hook-3.1 { 32*4520Snw141292 set commit_cnt 0 33*4520Snw141292 proc commit_hook {} { 34*4520Snw141292 incr ::commit_cnt 35*4520Snw141292 return 0 36*4520Snw141292 } 37*4520Snw141292 db commit_hook ::commit_hook 38*4520Snw141292 db commit_hook 39*4520Snw141292} {::commit_hook} 40*4520Snw141292do_test hook-3.2 { 41*4520Snw141292 set commit_cnt 42*4520Snw141292} {0} 43*4520Snw141292do_test hook-3.3 { 44*4520Snw141292 execsql { 45*4520Snw141292 CREATE TABLE t2(a,b); 46*4520Snw141292 } 47*4520Snw141292 set commit_cnt 48*4520Snw141292} {1} 49*4520Snw141292do_test hook-3.4 { 50*4520Snw141292 execsql { 51*4520Snw141292 INSERT INTO t2 VALUES(1,2); 52*4520Snw141292 INSERT INTO t2 SELECT a+1, b+1 FROM t2; 53*4520Snw141292 INSERT INTO t2 SELECT a+2, b+2 FROM t2; 54*4520Snw141292 } 55*4520Snw141292 set commit_cnt 56*4520Snw141292} {4} 57*4520Snw141292do_test hook-3.5 { 58*4520Snw141292 set commit_cnt {} 59*4520Snw141292 proc commit_hook {} { 60*4520Snw141292 set ::commit_cnt [execsql {SELECT * FROM t2}] 61*4520Snw141292 return 0 62*4520Snw141292 } 63*4520Snw141292 execsql { 64*4520Snw141292 INSERT INTO t2 VALUES(5,6); 65*4520Snw141292 } 66*4520Snw141292 set commit_cnt 67*4520Snw141292} {1 2 2 3 3 4 4 5 5 6} 68*4520Snw141292do_test hook-3.6 { 69*4520Snw141292 set commit_cnt {} 70*4520Snw141292 proc commit_hook {} { 71*4520Snw141292 set ::commit_cnt [execsql {SELECT * FROM t2}] 72*4520Snw141292 return 1 73*4520Snw141292 } 74*4520Snw141292 catchsql { 75*4520Snw141292 INSERT INTO t2 VALUES(6,7); 76*4520Snw141292 } 77*4520Snw141292} {1 {constraint failed}} 78*4520Snw141292do_test hook-3.7 { 79*4520Snw141292 set commit_cnt 80*4520Snw141292} {1 2 2 3 3 4 4 5 5 6 6 7} 81*4520Snw141292do_test hook-3.8 { 82*4520Snw141292 execsql {SELECT * FROM t2} 83*4520Snw141292} {1 2 2 3 3 4 4 5 5 6} 84*4520Snw141292 85*4520Snw141292 86*4520Snw141292finish_test 87