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