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