author | sl@SLION-WIN7.fritz.box |
Fri, 15 Jun 2012 03:10:57 +0200 | |
changeset 0 | bde4ae8d615e |
permissions | -rw-r--r-- |
sl@0 | 1 |
# 2004 September 2 |
sl@0 | 2 |
# |
sl@0 | 3 |
# The author disclaims copyright to this source code. In place of |
sl@0 | 4 |
# a legal notice, here is a blessing: |
sl@0 | 5 |
# |
sl@0 | 6 |
# May you do good and not evil. |
sl@0 | 7 |
# May you find forgiveness for yourself and forgive others. |
sl@0 | 8 |
# May you share freely, never taking more than you give. |
sl@0 | 9 |
# |
sl@0 | 10 |
#*********************************************************************** |
sl@0 | 11 |
# This file implements regression tests for SQLite library. The |
sl@0 | 12 |
# focus of this script testing the callback-free C/C++ API and in |
sl@0 | 13 |
# particular the behavior of sqlite3_step() when trying to commit |
sl@0 | 14 |
# with lock contention. |
sl@0 | 15 |
# |
sl@0 | 16 |
# $Id: capi3b.test,v 1.4 2007/08/10 19:46:14 drh Exp $ |
sl@0 | 17 |
# |
sl@0 | 18 |
|
sl@0 | 19 |
set testdir [file dirname $argv0] |
sl@0 | 20 |
source $testdir/tester.tcl |
sl@0 | 21 |
|
sl@0 | 22 |
|
sl@0 | 23 |
# These tests depend on the pager holding changes in cache |
sl@0 | 24 |
# until it is time to commit. But that won't happen if the |
sl@0 | 25 |
# soft-heap-limit is set too low. So disable the soft heap limit |
sl@0 | 26 |
# for the duration of this test. |
sl@0 | 27 |
# |
sl@0 | 28 |
sqlite3_soft_heap_limit 0 |
sl@0 | 29 |
|
sl@0 | 30 |
|
sl@0 | 31 |
set DB [sqlite3_connection_pointer db] |
sl@0 | 32 |
sqlite3 db2 test.db |
sl@0 | 33 |
set DB2 [sqlite3_connection_pointer db2] |
sl@0 | 34 |
|
sl@0 | 35 |
# Create some data in the database |
sl@0 | 36 |
# |
sl@0 | 37 |
do_test capi3b-1.1 { |
sl@0 | 38 |
execsql { |
sl@0 | 39 |
CREATE TABLE t1(x); |
sl@0 | 40 |
INSERT INTO t1 VALUES(1); |
sl@0 | 41 |
INSERT INTO t1 VALUES(2); |
sl@0 | 42 |
SELECT * FROM t1 |
sl@0 | 43 |
} |
sl@0 | 44 |
} {1 2} |
sl@0 | 45 |
|
sl@0 | 46 |
# Make sure the second database connection can see the data |
sl@0 | 47 |
# |
sl@0 | 48 |
do_test capi3b-1.2 { |
sl@0 | 49 |
execsql { |
sl@0 | 50 |
SELECT * FROM t1 |
sl@0 | 51 |
} db2 |
sl@0 | 52 |
} {1 2} |
sl@0 | 53 |
|
sl@0 | 54 |
# First database connection acquires a shared lock |
sl@0 | 55 |
# |
sl@0 | 56 |
do_test capi3b-1.3 { |
sl@0 | 57 |
execsql { |
sl@0 | 58 |
BEGIN; |
sl@0 | 59 |
SELECT * FROM t1; |
sl@0 | 60 |
} |
sl@0 | 61 |
} {1 2} |
sl@0 | 62 |
|
sl@0 | 63 |
# Second database connection tries to write. The sqlite3_step() |
sl@0 | 64 |
# function returns SQLITE_BUSY because it cannot commit. |
sl@0 | 65 |
# |
sl@0 | 66 |
do_test capi3b-1.4 { |
sl@0 | 67 |
set VM [sqlite3_prepare $DB2 {INSERT INTO t1 VALUES(3)} -1 TAIL] |
sl@0 | 68 |
sqlite3_step $VM |
sl@0 | 69 |
} SQLITE_BUSY |
sl@0 | 70 |
|
sl@0 | 71 |
# The sqlite3_step call can be repeated multiple times. |
sl@0 | 72 |
# |
sl@0 | 73 |
do_test capi3b-1.5.1 { |
sl@0 | 74 |
sqlite3_step $VM |
sl@0 | 75 |
} SQLITE_BUSY |
sl@0 | 76 |
do_test capi3b-1.5.2 { |
sl@0 | 77 |
sqlite3_step $VM |
sl@0 | 78 |
} SQLITE_BUSY |
sl@0 | 79 |
|
sl@0 | 80 |
# The first connection closes its transaction. This allows the second |
sl@0 | 81 |
# connections sqlite3_step to succeed. |
sl@0 | 82 |
# |
sl@0 | 83 |
do_test capi3b-1.6 { |
sl@0 | 84 |
execsql COMMIT |
sl@0 | 85 |
sqlite3_step $VM |
sl@0 | 86 |
} SQLITE_DONE |
sl@0 | 87 |
do_test capi3b-1.7 { |
sl@0 | 88 |
sqlite3_finalize $VM |
sl@0 | 89 |
} SQLITE_OK |
sl@0 | 90 |
do_test capi3b-1.8 { |
sl@0 | 91 |
execsql {SELECT * FROM t1} db2 |
sl@0 | 92 |
} {1 2 3} |
sl@0 | 93 |
do_test capi3b-1.9 { |
sl@0 | 94 |
execsql {SELECT * FROM t1} |
sl@0 | 95 |
} {1 2 3} |
sl@0 | 96 |
|
sl@0 | 97 |
# Start doing a SELECT with one connection. This gets a SHARED lock. |
sl@0 | 98 |
# Then do an INSERT with the other connection. The INSERT should |
sl@0 | 99 |
# not be able to complete until the SELECT finishes. |
sl@0 | 100 |
# |
sl@0 | 101 |
do_test capi3b-2.1 { |
sl@0 | 102 |
set VM1 [sqlite3_prepare $DB {SELECT * FROM t1} -1 TAIL] |
sl@0 | 103 |
sqlite3_step $VM1 |
sl@0 | 104 |
} SQLITE_ROW |
sl@0 | 105 |
do_test capi3b-2.2 { |
sl@0 | 106 |
sqlite3_column_text $VM1 0 |
sl@0 | 107 |
} 1 |
sl@0 | 108 |
do_test capi3b-2.3 { |
sl@0 | 109 |
set VM2 [sqlite3_prepare $DB2 {INSERT INTO t1 VALUES(4)} -1 TAIL] |
sl@0 | 110 |
sqlite3_step $VM2 |
sl@0 | 111 |
} SQLITE_BUSY |
sl@0 | 112 |
do_test capi3b-2.4 { |
sl@0 | 113 |
sqlite3_step $VM1 |
sl@0 | 114 |
} SQLITE_ROW |
sl@0 | 115 |
do_test capi3b-2.5 { |
sl@0 | 116 |
sqlite3_column_text $VM1 0 |
sl@0 | 117 |
} 2 |
sl@0 | 118 |
do_test capi3b-2.6 { |
sl@0 | 119 |
sqlite3_step $VM2 |
sl@0 | 120 |
} SQLITE_BUSY |
sl@0 | 121 |
do_test capi3b-2.7 { |
sl@0 | 122 |
sqlite3_step $VM1 |
sl@0 | 123 |
} SQLITE_ROW |
sl@0 | 124 |
do_test capi3b-2.8 { |
sl@0 | 125 |
sqlite3_column_text $VM1 0 |
sl@0 | 126 |
} 3 |
sl@0 | 127 |
do_test capi3b-2.9 { |
sl@0 | 128 |
sqlite3_step $VM2 |
sl@0 | 129 |
} SQLITE_BUSY |
sl@0 | 130 |
do_test capi3b-2.10 { |
sl@0 | 131 |
sqlite3_step $VM1 |
sl@0 | 132 |
} SQLITE_DONE |
sl@0 | 133 |
do_test capi3b-2.11 { |
sl@0 | 134 |
sqlite3_step $VM2 |
sl@0 | 135 |
} SQLITE_DONE |
sl@0 | 136 |
do_test capi3b-2.12 { |
sl@0 | 137 |
sqlite3_finalize $VM1 |
sl@0 | 138 |
sqlite3_finalize $VM2 |
sl@0 | 139 |
execsql {SELECT * FROM t1} |
sl@0 | 140 |
} {1 2 3 4} |
sl@0 | 141 |
|
sl@0 | 142 |
catch {db2 close} |
sl@0 | 143 |
|
sl@0 | 144 |
sqlite3_soft_heap_limit $soft_limit |
sl@0 | 145 |
finish_test |