1# 2008 June 28 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. The 12# focus of this script is database locks. 13# 14# $Id: lock5.test,v 1.4 2008/11/21 00:10:35 aswift Exp $ 15 16set testdir [file dirname $argv0] 17source $testdir/tester.tcl 18 19# This file is only run if using the unix backend compiled with the 20# SQLITE_ENABLE_LOCKING_STYLE macro. 21db close 22if {[catch {sqlite3 db test.db -vfs unix-none} msg]} { 23 finish_test 24 return 25} 26db close 27 28ifcapable lock_proxy_pragmas { 29 set ::using_proxy 0 30 foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] { 31 set ::using_proxy $value 32 } 33 # Disable the proxy locking for these tests 34 set env(SQLITE_FORCE_PROXY_LOCKING) "0" 35} 36 37 38do_test lock5-dotfile.1 { 39 sqlite3 db test.db -vfs unix-dotfile 40 execsql { 41 BEGIN; 42 CREATE TABLE t1(a, b); 43 } 44} {} 45 46do_test lock5-dotfile.2 { 47 file exists test.db.lock 48} {1} 49 50do_test lock5-dotfile.3 { 51 execsql COMMIT 52 file exists test.db.lock 53} {0} 54 55do_test lock5-dotfile.4 { 56 sqlite3 db2 test.db -vfs unix-dotfile 57 execsql { 58 INSERT INTO t1 VALUES('a', 'b'); 59 SELECT * FROM t1; 60 } db2 61} {a b} 62 63do_test lock5-dotfile.5 { 64 execsql { 65 BEGIN; 66 SELECT * FROM t1; 67 } db2 68} {a b} 69 70do_test lock5-dotfile.6 { 71 file exists test.db.lock 72} {1} 73 74do_test lock5-dotfile.7 { 75 catchsql { SELECT * FROM t1; } 76} {1 {database is locked}} 77 78do_test lock5-dotfile.8 { 79 execsql { 80 SELECT * FROM t1; 81 ROLLBACK; 82 } db2 83} {a b} 84 85do_test lock5-dotfile.9 { 86 catchsql { SELECT * FROM t1; } 87} {0 {a b}} 88 89do_test lock5-dotfile.10 { 90 file exists test.db.lock 91} {0} 92 93do_test lock5-dotfile.X { 94 db2 close 95 execsql {BEGIN EXCLUSIVE} 96 db close 97 file exists test.db.lock 98} {0} 99 100##################################################################### 101 102file delete -force test.db 103 104do_test lock5-flock.1 { 105 sqlite3 db test.db -vfs unix-flock 106 execsql { 107 CREATE TABLE t1(a, b); 108 BEGIN; 109 INSERT INTO t1 VALUES(1, 2); 110 } 111} {} 112 113# Make sure we are not accidentally using the dotfile locking scheme. 114do_test lock5-flock.2 { 115 file exists test.db.lock 116} {0} 117 118do_test lock5-flock.3 { 119 sqlite3 db2 test.db -vfs unix-flock 120 catchsql { SELECT * FROM t1 } db2 121} {1 {database is locked}} 122 123do_test lock5-flock.4 { 124 execsql COMMIT 125 catchsql { SELECT * FROM t1 } db2 126} {0 {1 2}} 127 128do_test lock5-flock.5 { 129 execsql BEGIN 130 catchsql { SELECT * FROM t1 } db2 131} {0 {1 2}} 132 133do_test lock5-flock.6 { 134 execsql {SELECT * FROM t1} 135 catchsql { SELECT * FROM t1 } db2 136} {1 {database is locked}} 137 138do_test lock5-flock.7 { 139 db close 140 catchsql { SELECT * FROM t1 } db2 141} {0 {1 2}} 142 143do_test lock5-flock.8 { 144 db2 close 145} {} 146 147##################################################################### 148 149do_test lock5-none.1 { 150 sqlite3 db test.db -vfs unix-none 151 sqlite3 db2 test.db -vfs unix-none 152 execsql { 153 BEGIN; 154 INSERT INTO t1 VALUES(3, 4); 155 } 156} {} 157do_test lock5-none.2 { 158 execsql { SELECT * FROM t1 } 159} {1 2 3 4} 160do_test lock5-flock.3 { 161 execsql { SELECT * FROM t1 } db2 162} {1 2} 163do_test lock5-none.4 { 164 execsql { 165 BEGIN; 166 SELECT * FROM t1; 167 } db2 168} {1 2} 169do_test lock5-none.5 { 170 execsql COMMIT 171 execsql {SELECT * FROM t1} db2 172} {1 2} 173 174ifcapable memorymanage { 175 do_test lock5-none.6 { 176 sqlite3_release_memory 1000000 177 execsql {SELECT * FROM t1} db2 178 } {1 2 3 4} 179} 180 181do_test lock5-flock.X { 182 db close 183 db2 close 184} {} 185 186ifcapable lock_proxy_pragmas { 187 set env(SQLITE_FORCE_PROXY_LOCKING) $::using_proxy 188} 189 190finish_test 191