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