Added experimental APIs: sqlite_begin_hook() and sqlite_commit_hook(). (CVS 896)
FossilOrigin-Name: 5efbf62313519d0a6e8b8f5dbb29d3ef428d73e8
This commit is contained in:
+148
@@ -0,0 +1,148 @@
|
||||
# 2003 April 3
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for TCL interface to the
|
||||
# SQLite library.
|
||||
#
|
||||
# The focus of the tests in this file is the following interface:
|
||||
#
|
||||
# sqlite_begin_hook
|
||||
# sqlite_commit_hook
|
||||
#
|
||||
# $Id: hook.test,v 1.1 2003/04/03 15:46:05 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
do_test hook-1.1 {
|
||||
db begin_hook
|
||||
} {}
|
||||
do_test hook-1.2 {
|
||||
db commit_hook
|
||||
} {}
|
||||
|
||||
do_test hook-2.1 {
|
||||
set begin_cnt 0
|
||||
proc begin_hook {} {
|
||||
incr ::begin_cnt
|
||||
return 0
|
||||
}
|
||||
db begin_hook begin_hook
|
||||
db begin_hook
|
||||
} {begin_hook}
|
||||
do_test hook-2.2 {
|
||||
set begin_cnt
|
||||
} {0}
|
||||
do_test hook-2.3 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a,b);
|
||||
}
|
||||
set begin_cnt
|
||||
} {1}
|
||||
do_test hook-2.4 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(1,2);
|
||||
INSERT INTO t1 SELECT a+1, b+1 FROM t1;
|
||||
INSERT INTO t1 SELECT a+2, b+2 FROM t1;
|
||||
}
|
||||
set begin_cnt
|
||||
} {4}
|
||||
do_test hook-2.5 {
|
||||
execsql {
|
||||
SELECT * FROM t1
|
||||
}
|
||||
} {1 2 2 3 3 4 4 5}
|
||||
do_test hook-2.6 {
|
||||
set begin_cnt
|
||||
} {4}
|
||||
do_test hook-2.7 {
|
||||
proc begin_hook {} {
|
||||
incr ::begin_cnt
|
||||
return 1
|
||||
}
|
||||
catchsql {
|
||||
INSERT INTO t1 VALUES(9,10);
|
||||
}
|
||||
} {1 {constraint failed}}
|
||||
do_test hook-2.8 {
|
||||
set begin_cnt
|
||||
} {5}
|
||||
do_test hook-2.9 {
|
||||
execsql {
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} {1 2 2 3 3 4 4 5}
|
||||
do_test hook-2.10 {
|
||||
db begin_hook {}
|
||||
db begin_hook
|
||||
} {}
|
||||
do_test hook-2.11 {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES(9,10);
|
||||
SELECT * FROM t1
|
||||
}
|
||||
} {1 2 2 3 3 4 4 5 9 10}
|
||||
|
||||
do_test hook-3.1 {
|
||||
set commit_cnt 0
|
||||
proc commit_hook {} {
|
||||
incr ::commit_cnt
|
||||
return 0
|
||||
}
|
||||
db commit_hook ::commit_hook
|
||||
db commit_hook
|
||||
} {::commit_hook}
|
||||
do_test hook-3.2 {
|
||||
set commit_cnt
|
||||
} {0}
|
||||
do_test hook-3.3 {
|
||||
execsql {
|
||||
CREATE TABLE t2(a,b);
|
||||
}
|
||||
set commit_cnt
|
||||
} {1}
|
||||
do_test hook-3.4 {
|
||||
execsql {
|
||||
INSERT INTO t2 VALUES(1,2);
|
||||
INSERT INTO t2 SELECT a+1, b+1 FROM t2;
|
||||
INSERT INTO t2 SELECT a+2, b+2 FROM t2;
|
||||
}
|
||||
set commit_cnt
|
||||
} {4}
|
||||
do_test hook-3.5 {
|
||||
set commit_cnt {}
|
||||
proc commit_hook {} {
|
||||
set ::commit_cnt [execsql {SELECT * FROM t2}]
|
||||
return 0
|
||||
}
|
||||
execsql {
|
||||
INSERT INTO t2 VALUES(5,6);
|
||||
}
|
||||
set commit_cnt
|
||||
} {1 2 2 3 3 4 4 5 5 6}
|
||||
do_test hook-3.6 {
|
||||
set commit_cnt {}
|
||||
proc commit_hook {} {
|
||||
set ::commit_cnt [execsql {SELECT * FROM t2}]
|
||||
return 1
|
||||
}
|
||||
catchsql {
|
||||
INSERT INTO t2 VALUES(6,7);
|
||||
}
|
||||
} {1 {constraint failed}}
|
||||
do_test hook-3.7 {
|
||||
set commit_cnt
|
||||
} {1 2 2 3 3 4 4 5 5 6 6 7}
|
||||
do_test hook-3.8 {
|
||||
execsql {SELECT * FROM t2}
|
||||
} {1 2 2 3 3 4 4 5 5 6}
|
||||
|
||||
|
||||
finish_test
|
||||
+2
-2
@@ -15,7 +15,7 @@
|
||||
# interface is pretty well tested. This file contains some addition
|
||||
# tests for fringe issues that the main test suite does not cover.
|
||||
#
|
||||
# $Id: tclsqlite.test,v 1.10 2003/03/30 19:17:03 drh Exp $
|
||||
# $Id: tclsqlite.test,v 1.11 2003/04/03 15:46:05 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -29,7 +29,7 @@ do_test tcl-1.1 {
|
||||
do_test tcl-1.2 {
|
||||
set v [catch {db bogus} msg]
|
||||
lappend v $msg
|
||||
} {1 {bad option "bogus": must be busy, changes, close, complete, errorcode, eval, function, last_insert_rowid, or timeout}}
|
||||
} {1 {bad option "bogus": must be begin_hook, busy, changes, close, commit_hook, complete, errorcode, eval, function, last_insert_rowid, or timeout}}
|
||||
do_test tcl-1.3 {
|
||||
execsql {CREATE TABLE t1(a int, b int)}
|
||||
execsql {INSERT INTO t1 VALUES(10,20)}
|
||||
|
||||
Reference in New Issue
Block a user