aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/sqlite/unix/sqlite-3.5.1/test/tkt2409.test
diff options
context:
space:
mode:
authordan miller2007-10-20 02:49:29 +0000
committerdan miller2007-10-20 02:49:29 +0000
commite36d23a85ebff914d74bb541558c2b6082b78edb (patch)
tree54b58fdf162e78af64055282a6035c8d2443389d /libraries/sqlite/unix/sqlite-3.5.1/test/tkt2409.test
parent* Fixed an issue whereby avatar chat distances were being calculated against ... (diff)
downloadopensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.zip
opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.gz
opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.bz2
opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.xz
sqlite source (unix build) added to libraries
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/test/tkt2409.test')
-rw-r--r--libraries/sqlite/unix/sqlite-3.5.1/test/tkt2409.test218
1 files changed, 218 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/test/tkt2409.test b/libraries/sqlite/unix/sqlite-3.5.1/test/tkt2409.test
new file mode 100644
index 0000000..54e8265
--- /dev/null
+++ b/libraries/sqlite/unix/sqlite-3.5.1/test/tkt2409.test
@@ -0,0 +1,218 @@
1# 2007 June 13
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
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.
9#
10#***********************************************************************
11# This file implements regression tests for SQLite library.
12#
13# This file implements tests to verify that ticket #2409 has been
14# fixed. More specifically, they verify that if SQLite cannot
15# obtain an EXCLUSIVE lock while trying to spill the cache during
16# any statement other than a COMMIT, an I/O error is returned instead
17# of SQLITE_BUSY.
18#
19# $Id: tkt2409.test,v 1.3 2007/09/12 17:01:45 danielk1977 Exp $
20
21# Test Outline:
22#
23# tkt-2409-1.*: Cause a cache-spill during an INSERT that is within
24# a db transaction but does not start a statement transaction.
25# Verify that the transaction is automatically rolled back
26# and SQLITE_IOERR_BLOCKED is returned
27#
28# tkt-2409-2.*: Cause a cache-spill while updating the change-counter
29# during a database COMMIT. Verify that the transaction is not
30# rolled back and SQLITE_BUSY is returned.
31#
32# tkt-2409-3.*: Similar to 2409-1.*, but using many INSERT statements
33# within a transaction instead of just one.
34#
35# tkt-2409-4.*: Similar to 2409-1.*, but rig it so that the
36# INSERT statement starts a statement transaction. Verify that
37# SQLOTE_BUSY is returned and the transaction is not rolled back.
38#
39
40set testdir [file dirname $argv0]
41source $testdir/tester.tcl
42
43ifcapable !pager_pragmas {
44 finish_test
45 return
46}
47
48sqlite3_extended_result_codes $::DB 1
49
50# Aquire a read-lock on the database using handle [db2].
51#
52proc read_lock_db {} {
53 if {$::STMT eq ""} {
54 set ::STMT [sqlite3_prepare db2 {SELECT rowid FROM sqlite_master} -1 TAIL]
55 set rc [sqlite3_step $::STMT]
56 if {$rc eq "SQLITE_ERROR"} {
57 unread_lock_db
58 read_lock_db
59 }
60 }
61}
62
63# Release any read-lock obtained using [read_lock_db]
64#
65proc unread_lock_db {} {
66 if {$::STMT ne ""} {
67 sqlite3_finalize $::STMT
68 set ::STMT ""
69 }
70}
71
72# Open the db handle used by [read_lock_db].
73#
74sqlite3 db2 test.db
75set ::STMT ""
76
77do_test tkt2409-1.1 {
78 execsql {
79 PRAGMA cache_size=10;
80 CREATE TABLE t1(x TEXT UNIQUE NOT NULL, y BLOB);
81 }
82 read_lock_db
83 set ::zShort [string repeat 0123456789 1]
84 set ::zLong [string repeat 0123456789 1500]
85 catchsql {
86 BEGIN;
87 INSERT INTO t1 VALUES($::zShort, $::zLong);
88 }
89} {1 {disk I/O error}}
90
91do_test tkt2409-1.2 {
92 sqlite3_errcode $::DB
93} {SQLITE_IOERR+11}
94
95# Check the integrity of the cache.
96#
97integrity_check tkt2409-1.3
98
99# Check that the transaction was rolled back. Because the INSERT
100# statement in which the "I/O error" occured did not open a statement
101# transaction, SQLite had no choice but to roll back the transaction.
102#
103do_test tkt2409-1.4 {
104 unread_lock_db
105 catchsql { ROLLBACK }
106} {1 {cannot rollback - no transaction is active}}
107
108
109set ::zShort [string repeat 0123456789 1]
110set ::zLong [string repeat 0123456789 1500]
111set ::rc 1
112for {set iCache 10} {$::rc} {incr iCache} {
113 execsql "PRAGMA cache_size = $iCache"
114 do_test tkt2409-2.1.$iCache {
115 read_lock_db
116 set ::rc [catch {
117 execsql {
118 BEGIN;
119 INSERT INTO t1 VALUES($::zShort, $::zLong);
120 }
121 } msg]
122 expr {($::rc == 1 && $msg eq "disk I/O error") || $::rc == 0}
123 } {1}
124}
125
126do_test tkt2409-2.2 {
127 catchsql {
128 ROLLBACK;
129 BEGIN;
130 INSERT INTO t1 VALUES($::zShort, $::zLong);
131 COMMIT;
132 }
133} {1 {database is locked}}
134
135do_test tkt2409-2.3 {
136 unread_lock_db
137 catchsql {
138 COMMIT;
139 }
140} {0 {}}
141
142do_test tkt2409-3.1 {
143 db close
144 set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db]
145 sqlite3_extended_result_codes $::DB 1
146 execsql {
147 PRAGMA cache_size=10;
148 DELETE FROM t1;
149 }
150 read_lock_db
151 set ::zShort [string repeat 0123456789 1]
152 set ::zLong [string repeat 0123456789 1500]
153 catchsql {
154 BEGIN;
155 INSERT INTO t1 SELECT $::zShort, $::zLong;
156 }
157} {1 {database is locked}}
158
159do_test tkt2409-3.2 {
160 sqlite3_errcode $::DB
161} {SQLITE_BUSY}
162
163# Check the integrity of the cache.
164#
165integrity_check tkt2409-3.3
166
167# Check that the transaction was rolled back. Because the INSERT
168# statement in which the "I/O error" occured did not open a statement
169# transaction, SQLite had no choice but to roll back the transaction.
170#
171do_test tkt2409-3.4 {
172 unread_lock_db
173 catchsql { ROLLBACK }
174} {0 {}}
175
176
177do_test tkt2409-4.1 {
178 execsql {
179 PRAGMA cache_size=20;
180 DROP TABLE t1;
181 CREATE TABLE t1 (x TEXT UNIQUE NOT NULL);
182 }
183
184 unset -nocomplain t1
185 array unset t1
186 set t1(0) 1
187 set sql ""
188 for {set i 0} {$i<5000} {incr i} {
189 set r 0
190 while {[info exists t1($r)]} {
191 set r [expr {int(rand()*1000000000)}]
192 }
193 set t1($r) 1
194 append sql "INSERT INTO t1 VALUES('some-text-$r');"
195 }
196
197 read_lock_db
198 execsql BEGIN
199 catchsql $sql
200} {1 {disk I/O error}}
201
202do_test tkt2409-4.2 {
203 sqlite3_errcode $::DB
204} {SQLITE_IOERR+11}
205
206# Check the integrity of the cache.
207#
208integrity_check tkt2409-4.3
209
210do_test tkt2409-4.4 {
211 catchsql { ROLLBACK }
212} {1 {cannot rollback - no transaction is active}}
213
214
215unread_lock_db
216db2 close
217unset -nocomplain t1
218finish_test