blob: c037c04dc278f8c1f1af7bc957510f0bd3fe63f9 [file] [log] [blame]
drhaa940ea2004-01-15 02:44:03 +00001# 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#
danielk19771d850a72004-05-31 08:26:49 +000018# $Id: hook.test,v 1.4 2004/05/31 08:26:49 danielk1977 Exp $
drhaa940ea2004-01-15 02:44:03 +000019
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 {} {
danielk19771d850a72004-05-31 08:26:49 +000068 set ::commit_cnt [execsql {SELECT * FROM t2}]
drhaa940ea2004-01-15 02:44:03 +000069 return 1
70 }
71 catchsql {
72 INSERT INTO t2 VALUES(6,7);
73 }
74} {1 {constraint failed}}
75do_test hook-3.7 {
danielk19771d850a72004-05-31 08:26:49 +000076 set ::commit_cnt
drhaa940ea2004-01-15 02:44:03 +000077} {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
83finish_test