1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/capi3b.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,145 @@
1.4 +# 2004 September 2
1.5 +#
1.6 +# The author disclaims copyright to this source code. In place of
1.7 +# a legal notice, here is a blessing:
1.8 +#
1.9 +# May you do good and not evil.
1.10 +# May you find forgiveness for yourself and forgive others.
1.11 +# May you share freely, never taking more than you give.
1.12 +#
1.13 +#***********************************************************************
1.14 +# This file implements regression tests for SQLite library. The
1.15 +# focus of this script testing the callback-free C/C++ API and in
1.16 +# particular the behavior of sqlite3_step() when trying to commit
1.17 +# with lock contention.
1.18 +#
1.19 +# $Id: capi3b.test,v 1.4 2007/08/10 19:46:14 drh Exp $
1.20 +#
1.21 +
1.22 +set testdir [file dirname $argv0]
1.23 +source $testdir/tester.tcl
1.24 +
1.25 +
1.26 +# These tests depend on the pager holding changes in cache
1.27 +# until it is time to commit. But that won't happen if the
1.28 +# soft-heap-limit is set too low. So disable the soft heap limit
1.29 +# for the duration of this test.
1.30 +#
1.31 +sqlite3_soft_heap_limit 0
1.32 +
1.33 +
1.34 +set DB [sqlite3_connection_pointer db]
1.35 +sqlite3 db2 test.db
1.36 +set DB2 [sqlite3_connection_pointer db2]
1.37 +
1.38 +# Create some data in the database
1.39 +#
1.40 +do_test capi3b-1.1 {
1.41 + execsql {
1.42 + CREATE TABLE t1(x);
1.43 + INSERT INTO t1 VALUES(1);
1.44 + INSERT INTO t1 VALUES(2);
1.45 + SELECT * FROM t1
1.46 + }
1.47 +} {1 2}
1.48 +
1.49 +# Make sure the second database connection can see the data
1.50 +#
1.51 +do_test capi3b-1.2 {
1.52 + execsql {
1.53 + SELECT * FROM t1
1.54 + } db2
1.55 +} {1 2}
1.56 +
1.57 +# First database connection acquires a shared lock
1.58 +#
1.59 +do_test capi3b-1.3 {
1.60 + execsql {
1.61 + BEGIN;
1.62 + SELECT * FROM t1;
1.63 + }
1.64 +} {1 2}
1.65 +
1.66 +# Second database connection tries to write. The sqlite3_step()
1.67 +# function returns SQLITE_BUSY because it cannot commit.
1.68 +#
1.69 +do_test capi3b-1.4 {
1.70 + set VM [sqlite3_prepare $DB2 {INSERT INTO t1 VALUES(3)} -1 TAIL]
1.71 + sqlite3_step $VM
1.72 +} SQLITE_BUSY
1.73 +
1.74 +# The sqlite3_step call can be repeated multiple times.
1.75 +#
1.76 +do_test capi3b-1.5.1 {
1.77 + sqlite3_step $VM
1.78 +} SQLITE_BUSY
1.79 +do_test capi3b-1.5.2 {
1.80 + sqlite3_step $VM
1.81 +} SQLITE_BUSY
1.82 +
1.83 +# The first connection closes its transaction. This allows the second
1.84 +# connections sqlite3_step to succeed.
1.85 +#
1.86 +do_test capi3b-1.6 {
1.87 + execsql COMMIT
1.88 + sqlite3_step $VM
1.89 +} SQLITE_DONE
1.90 +do_test capi3b-1.7 {
1.91 + sqlite3_finalize $VM
1.92 +} SQLITE_OK
1.93 +do_test capi3b-1.8 {
1.94 + execsql {SELECT * FROM t1} db2
1.95 +} {1 2 3}
1.96 +do_test capi3b-1.9 {
1.97 + execsql {SELECT * FROM t1}
1.98 +} {1 2 3}
1.99 +
1.100 +# Start doing a SELECT with one connection. This gets a SHARED lock.
1.101 +# Then do an INSERT with the other connection. The INSERT should
1.102 +# not be able to complete until the SELECT finishes.
1.103 +#
1.104 +do_test capi3b-2.1 {
1.105 + set VM1 [sqlite3_prepare $DB {SELECT * FROM t1} -1 TAIL]
1.106 + sqlite3_step $VM1
1.107 +} SQLITE_ROW
1.108 +do_test capi3b-2.2 {
1.109 + sqlite3_column_text $VM1 0
1.110 +} 1
1.111 +do_test capi3b-2.3 {
1.112 + set VM2 [sqlite3_prepare $DB2 {INSERT INTO t1 VALUES(4)} -1 TAIL]
1.113 + sqlite3_step $VM2
1.114 +} SQLITE_BUSY
1.115 +do_test capi3b-2.4 {
1.116 + sqlite3_step $VM1
1.117 +} SQLITE_ROW
1.118 +do_test capi3b-2.5 {
1.119 + sqlite3_column_text $VM1 0
1.120 +} 2
1.121 +do_test capi3b-2.6 {
1.122 + sqlite3_step $VM2
1.123 +} SQLITE_BUSY
1.124 +do_test capi3b-2.7 {
1.125 + sqlite3_step $VM1
1.126 +} SQLITE_ROW
1.127 +do_test capi3b-2.8 {
1.128 + sqlite3_column_text $VM1 0
1.129 +} 3
1.130 +do_test capi3b-2.9 {
1.131 + sqlite3_step $VM2
1.132 +} SQLITE_BUSY
1.133 +do_test capi3b-2.10 {
1.134 + sqlite3_step $VM1
1.135 +} SQLITE_DONE
1.136 +do_test capi3b-2.11 {
1.137 + sqlite3_step $VM2
1.138 +} SQLITE_DONE
1.139 +do_test capi3b-2.12 {
1.140 + sqlite3_finalize $VM1
1.141 + sqlite3_finalize $VM2
1.142 + execsql {SELECT * FROM t1}
1.143 +} {1 2 3 4}
1.144 +
1.145 +catch {db2 close}
1.146 +
1.147 +sqlite3_soft_heap_limit $soft_limit
1.148 +finish_test