AryaWu/sqlite
0
1# 2014-05-072#3# The author disclaims copyright to this source code. In place of4# 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#12# This file implements regression tests for SQLite library. The13# focus of this file is testing the nolock=1 and immutable=1 query14# parameters and the SQLITE_IOCAP_IMMUTABLE device characteristic.15#16 17set testdir [file dirname $argv0]18source $testdir/tester.tcl19 20unset -nocomplain tvfs_calls21proc tvfs_reset {} {22 global tvfs_calls23 array set tvfs_calls {xLock 0 xUnlock 0 xCheckReservedLock 0 xAccess 0}24}25proc tvfs_callback {op args} {26 global tvfs_calls27 incr tvfs_calls($op)28 return SQLITE_OK29}30tvfs_reset31 32testvfs tvfs33tvfs script tvfs_callback34tvfs filter {xLock xUnlock xCheckReservedLock xAccess}35 36############################################################################37# Verify that the nolock=1 query parameter for URI filenames disables all38# calls to xLock and xUnlock for rollback databases.39#40do_test nolock-1.0 {41 db close42 forcedelete test.db43 tvfs_reset44 sqlite db test.db -vfs tvfs45 db eval {CREATE TABLE t1(a,b,c); INSERT INTO t1 VALUES(1,2,3);}46 list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \47 xCheckReservedLock $::tvfs_calls(xCheckReservedLock)48} {xLock 7 xUnlock 5 xCheckReservedLock 0}49 50do_test nolock-1.1 {51 db close52 forcedelete test.db53 tvfs_reset54 sqlite db file:test.db?nolock=0 -vfs tvfs -uri 155 db eval {CREATE TABLE t1(a,b,c); INSERT INTO t1 VALUES(1,2,3);}56 list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \57 xCheckReservedLock $::tvfs_calls(xCheckReservedLock)58} {xLock 7 xUnlock 5 xCheckReservedLock 0}59 60do_test nolock-1.2 {61 db close62 forcedelete test.db63 tvfs_reset64 sqlite db file:test.db?nolock=1 -vfs tvfs -uri 165 db eval {CREATE TABLE t1(a,b,c); INSERT INTO t1 VALUES(1,2,3);}66 list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \67 xCheckReservedLock $::tvfs_calls(xCheckReservedLock)68} {xLock 0 xUnlock 0 xCheckReservedLock 0}69 70do_test nolock-1.3 {71 db close72 tvfs_reset73 sqlite db file:test.db?nolock=0 -vfs tvfs -uri 1 -readonly 174 db eval {SELECT * FROM t1}75 list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \76 xCheckReservedLock $::tvfs_calls(xCheckReservedLock)77} {xLock 2 xUnlock 2 xCheckReservedLock 0}78 79do_test nolock-1.4 {80 db close81 tvfs_reset82 sqlite db file:test.db?nolock=1 -vfs tvfs -uri 1 -readonly 183 db eval {SELECT * FROM t1}84 list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \85 xCheckReservedLock $::tvfs_calls(xCheckReservedLock)86} {xLock 0 xUnlock 0 xCheckReservedLock 0}87 88#############################################################################89# Verify that immutable=1 disables both locking and xAccess calls to the90# journal files.91#92do_test nolock-2.0 {93 db close94 forcedelete test.db95 # begin by creating a test database96 sqlite3 db test.db97 db eval {98 CREATE TABLE t1(a,b);99 INSERT INTO t1 VALUES('hello','world');100 CREATE TABLE t2(x,y);101 INSERT INTO t2 VALUES(12345,67890);102 SELECT * FROM t1, t2;103 }104} {hello world 12345 67890}105do_test nolock-2.1 {106 tvfs_reset107 sqlite3 db2 test.db -vfs tvfs108 db2 eval {SELECT * FROM t1, t2}109} {hello world 12345 67890}110do_test nolock-2.2 {111 list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \112 xCheckReservedLock $::tvfs_calls(xCheckReservedLock) \113 xAccess $::tvfs_calls(xAccess)114} {xLock 2 xUnlock 2 xCheckReservedLock 0 xAccess 4}115 116 117do_test nolock-2.11 {118 db2 close119 tvfs_reset120 sqlite3 db2 file:test.db?immutable=0 -vfs tvfs -uri 1121 db2 eval {SELECT * FROM t1, t2}122} {hello world 12345 67890}123do_test nolock-2.12 {124 list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \125 xCheckReservedLock $::tvfs_calls(xCheckReservedLock) \126 xAccess $::tvfs_calls(xAccess)127} {xLock 2 xUnlock 2 xCheckReservedLock 0 xAccess 4}128 129 130do_test nolock-2.21 {131 db2 close132 tvfs_reset133 sqlite3 db2 file:test.db?immutable=1 -vfs tvfs -uri 1134 db2 eval {SELECT * FROM t1, t2}135} {hello world 12345 67890}136do_test nolock-2.22 {137 list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \138 xCheckReservedLock $::tvfs_calls(xCheckReservedLock) \139 xAccess $::tvfs_calls(xAccess)140} {xLock 0 xUnlock 0 xCheckReservedLock 0 xAccess 0}141 142do_test nolock-2.31 {143 db2 close144 tvfs_reset145 sqlite3 db2 file:test.db?immutable=1 -vfs tvfs -uri 1 -readonly 1146 db2 eval {SELECT * FROM t1, t2}147} {hello world 12345 67890}148do_test nolock-2.32 {149 list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \150 xCheckReservedLock $::tvfs_calls(xCheckReservedLock) \151 xAccess $::tvfs_calls(xAccess)152} {xLock 0 xUnlock 0 xCheckReservedLock 0 xAccess 0}153 154############################################################################155# Verify that the SQLITE_IOCAP_IMMUTABLE flag works156#157do_test nolock-3.1 {158 db2 close159 tvfs devchar immutable160 tvfs_reset161 sqlite3 db2 test.db -vfs tvfs162 db2 eval {SELECT * FROM t1, t2}163} {hello world 12345 67890}164do_test nolock-3.2 {165 list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \166 xCheckReservedLock $::tvfs_calls(xCheckReservedLock) \167 xAccess $::tvfs_calls(xAccess)168} {xLock 0 xUnlock 0 xCheckReservedLock 0 xAccess 0}169 170do_test nolock-3.11 {171 db2 close172 tvfs_reset173 sqlite3 db2 test.db -vfs tvfs -readonly 1174 db2 eval {SELECT * FROM t1, t2}175} {hello world 12345 67890}176do_test nolock-3.12 {177 list xLock $::tvfs_calls(xLock) xUnlock $::tvfs_calls(xUnlock) \178 xCheckReservedLock $::tvfs_calls(xCheckReservedLock) \179 xAccess $::tvfs_calls(xAccess)180} {xLock 0 xUnlock 0 xCheckReservedLock 0 xAccess 0}181 182db2 close183db close184tvfs delete185 186if {[permutation]!="inmemory_journal"} {187 # 2016-03-11: Make sure all works when transitioning to WAL mode188 # under nolock.189 #190 do_test nolock-4.1 {191 forcedelete test.db192 sqlite3 db file:test.db?nolock=1 -uri 1193 db eval {194 PRAGMA journal_mode=WAL;195 CREATE TABLE t1(x);196 INSERT INTO t1 VALUES('youngling');197 SELECT * FROM t1;198 }199 } {delete youngling}200 db close201 202 do_test nolock-4.2 {203 forcedelete test.db204 sqlite3 db test.db205 db eval {206 PRAGMA journal_mode=WAL;207 CREATE TABLE t1(x);208 INSERT INTO t1 VALUES('catbird');209 SELECT * FROM t1;210 }211 } {wal catbird}212 do_test nolock-4.3 {213 db close214 sqlite3 db file:test.db?nolock=1 -uri 1215 set rc [catch {db eval {SELECT * FROM t1}} msg]216 lappend rc $msg217 } {1 {unable to open database file}}218}219 220finish_test221 