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 is database locks.
14 # $Id: lock5.test,v 1.6 2008/12/04 12:34:16 drh Exp $
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
19 # This file is only run if using the unix backend compiled with the
20 # SQLITE_ENABLE_LOCKING_STYLE macro.
22 if {[catch {sqlite3 db test.db -vfs unix-none} msg]} {
27 forcedelete test.db.lock
29 ifcapable lock_proxy_pragmas {
31 foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
32 set ::using_proxy $value
34 # Disable the proxy locking for these tests
35 set env(SQLITE_FORCE_PROXY_LOCKING) "0"
39 do_test lock5-dotfile.1 {
40 sqlite3 db test.db -vfs unix-dotfile
43 CREATE TABLE t1(a, b);
47 do_test lock5-dotfile.2 {
48 file exists test.db.lock
51 do_test lock5-dotfile.3 {
53 file exists test.db.lock
56 do_test lock5-dotfile.4 {
57 sqlite3 db2 test.db -vfs unix-dotfile
59 INSERT INTO t1 VALUES('a', 'b');
64 do_test lock5-dotfile.5 {
71 do_test lock5-dotfile.6 {
72 file exists test.db.lock
75 do_test lock5-dotfile.7 {
76 catchsql { SELECT * FROM t1; }
77 } {1 {database is locked}}
79 do_test lock5-dotfile.8 {
86 do_test lock5-dotfile.9 {
87 catchsql { SELECT * FROM t1; }
90 do_test lock5-dotfile.10 {
91 file exists test.db.lock
94 do_test lock5-dotfile.X {
96 execsql {BEGIN EXCLUSIVE}
98 file exists test.db.lock
101 #####################################################################
104 if {[catch {sqlite3 db test.db -vfs unix-flock} msg]} {
109 do_test lock5-flock.1 {
110 sqlite3 db test.db -vfs unix-flock
112 CREATE TABLE t1(a, b);
114 INSERT INTO t1 VALUES(1, 2);
118 # Make sure we are not accidentally using the dotfile locking scheme.
119 do_test lock5-flock.2 {
120 file exists test.db.lock
123 do_test lock5-flock.3 {
124 catch { sqlite3 db2 test.db -vfs unix-flock }
125 catchsql { SELECT * FROM t1 } db2
126 } {1 {database is locked}}
128 do_test lock5-flock.4 {
130 catchsql { SELECT * FROM t1 } db2
133 do_test lock5-flock.5 {
135 catchsql { SELECT * FROM t1 } db2
138 do_test lock5-flock.6 {
139 execsql {SELECT * FROM t1}
140 catchsql { SELECT * FROM t1 } db2
141 } {1 {database is locked}}
143 do_test lock5-flock.7 {
145 catchsql { SELECT * FROM t1 } db2
148 do_test lock5-flock.8 {
152 #####################################################################
154 do_test lock5-none.1 {
155 sqlite3 db test.db -vfs unix-none
156 sqlite3 db2 test.db -vfs unix-none
157 execsql { PRAGMA mmap_size = 0 } db2
160 INSERT INTO t1 VALUES(3, 4);
163 do_test lock5-none.2 {
164 execsql { SELECT * FROM t1 }
166 do_test lock5-none.3 {
167 execsql { SELECT * FROM t1; } db2
169 do_test lock5-none.4 {
175 do_test lock5-none.5 {
177 execsql {SELECT * FROM t1} db2
180 ifcapable memorymanage {
181 do_test lock5-none.6 {
182 sqlite3_release_memory 1000000
183 execsql {SELECT * FROM t1} db2
187 do_test lock5-none.X {
192 ifcapable lock_proxy_pragmas {
193 set env(SQLITE_FORCE_PROXY_LOCKING) $::using_proxy