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