1275fe3adSdrh 2275fe3adSdrh# 2015-05-28 3275fe3adSdrh# 4275fe3adSdrh# The author disclaims copyright to this source code. In place of 5275fe3adSdrh# a legal notice, here is a blessing: 6275fe3adSdrh# 7275fe3adSdrh# May you do good and not evil. 8275fe3adSdrh# May you find forgiveness for yourself and forgive others. 9275fe3adSdrh# May you share freely, never taking more than you give. 10275fe3adSdrh# 11275fe3adSdrh#*********************************************************************** 12275fe3adSdrh# This file implements regression tests for SQLite library. The 13275fe3adSdrh# focus of this file is testing locks on read-only WAL-mode databases. 14275fe3adSdrh 15275fe3adSdrhset testdir [file dirname $argv0] 16275fe3adSdrhsource $testdir/tester.tcl 17275fe3adSdrhsource $testdir/lock_common.tcl 18275fe3adSdrhset testprefix rowallock 19275fe3adSdrh 20*d1f9ffebSdanset mmap_res 1000000 21*d1f9ffebSdanifcapable !mmap { 22*d1f9ffebSdan set mmap_res 0 23*d1f9ffebSdan} 24*d1f9ffebSdan 25275fe3adSdrhdo_multiclient_test tn { 26275fe3adSdrh code2 { db2 close } 27275fe3adSdrh code3 { db3 close } 28275fe3adSdrh 29275fe3adSdrh do_execsql_test 1.$tn.1 { 30275fe3adSdrh PRAGMA page_size = 4096; 31275fe3adSdrh CREATE TABLE t1(a, b); 32275fe3adSdrh CREATE TABLE t2(a, b); 33275fe3adSdrh INSERT INTO t1 VALUES(1, 2), (3, 4); 34275fe3adSdrh PRAGMA journal_mode = wal; 35275fe3adSdrh } {wal} 36275fe3adSdrh 37275fe3adSdrh code1 { 38275fe3adSdrh db close 39275fe3adSdrh sqlite3 db test.db -readonly 1 40275fe3adSdrh } 41275fe3adSdrh 42275fe3adSdrh do_execsql_test 1.$tn.2 { 43275fe3adSdrh PRAGMA mmap_size = 1000000; 44*d1f9ffebSdan } $mmap_res 45275fe3adSdrh do_execsql_test 1.$tn.2.1 { 46275fe3adSdrh SELECT * FROM t1; 47275fe3adSdrh } {1 2 3 4} 48275fe3adSdrh 49275fe3adSdrh do_catchsql_test 1.$tn.3 { 50275fe3adSdrh INSERT INTO t1 VALUES(5, 6); 51275fe3adSdrh } {1 {attempt to write a readonly database}} 52275fe3adSdrh 53275fe3adSdrh do_test 1.$tn.4 { 54275fe3adSdrh code2 { sqlite3 db2 test.db } 55275fe3adSdrh sql2 { INSERT INTO t1 VALUES(5, 6); } 56275fe3adSdrh code2 { db2 close } 57275fe3adSdrh file exists test.db-wal 58275fe3adSdrh } {1} 59275fe3adSdrh 60275fe3adSdrh do_test 1.$tn.5 { 61275fe3adSdrh sql1 { SELECT * FROM t2 } 62275fe3adSdrh code1 { db close } 63275fe3adSdrh file exists test.db-wal 64275fe3adSdrh } {1} 65275fe3adSdrh} 66275fe3adSdrh 67275fe3adSdrhfinish_test 68