3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this script testing the callback-free C/C++ API and in
13 # particular the behavior of sqlite3_step() when trying to commit
14 # with lock contention.
16 # $Id: capi3b.test,v 1.4 2007/08/10 19:46:14 drh Exp $
19 set testdir [file dirname $argv0]
20 source $testdir/tester.tcl
23 # These tests depend on the pager holding changes in cache
24 # until it is time to commit. But that won't happen if the
25 # soft-heap-limit is set too low. So disable the soft heap limit
26 # for the duration of this test.
28 sqlite3_soft_heap_limit 0
31 set DB [sqlite3_connection_pointer db]
33 set DB2 [sqlite3_connection_pointer db2]
35 # Create some data in the database
40 INSERT INTO t1 VALUES(1);
41 INSERT INTO t1 VALUES(2);
46 # Make sure the second database connection can see the data
54 # First database connection acquires a shared lock
63 # Second database connection tries to write. The sqlite3_step()
64 # function returns SQLITE_BUSY because it cannot commit.
67 set VM [sqlite3_prepare $DB2 {INSERT INTO t1 VALUES(3)} -1 TAIL]
71 # The sqlite3_step call can be repeated multiple times.
73 do_test capi3b-1.5.1 {
76 do_test capi3b-1.5.2 {
80 # The first connection closes its transaction. This allows the second
81 # connections sqlite3_step to succeed.
91 execsql {SELECT * FROM t1} db2
94 execsql {SELECT * FROM t1}
97 # Start doing a SELECT with one connection. This gets a SHARED lock.
98 # Then do an INSERT with the other connection. The INSERT should
99 # not be able to complete until the SELECT finishes.
102 set VM1 [sqlite3_prepare $DB {SELECT * FROM t1} -1 TAIL]
106 sqlite3_column_text $VM1 0
109 set VM2 [sqlite3_prepare $DB2 {INSERT INTO t1 VALUES(4)} -1 TAIL]
116 sqlite3_column_text $VM1 0
125 sqlite3_column_text $VM1 0
130 do_test capi3b-2.10 {
133 do_test capi3b-2.11 {
136 do_test capi3b-2.12 {
137 sqlite3_finalize $VM1
138 sqlite3_finalize $VM2
139 execsql {SELECT * FROM t1}
144 sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit)