wasCSharpSQLite – Blame information for rev 7
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | # 2011 May 09 |
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 | # |
||
12 | # This file contains tests for using WAL databases in read-only mode. |
||
13 | # |
||
14 | |||
15 | set testdir [file dirname $argv0] |
||
16 | source $testdir/tester.tcl |
||
17 | source $testdir/lock_common.tcl |
||
18 | set ::testprefix walro |
||
19 | |||
20 | # These tests are only going to work on unix. |
||
21 | # |
||
22 | if {$::tcl_platform(platform) != "unix"} { |
||
23 | finish_test |
||
24 | return |
||
25 | } |
||
26 | |||
27 | do_multiclient_test tn { |
||
28 | # Do not run tests with the connections in the same process. |
||
29 | # |
||
30 | if {$tn==2} continue |
||
31 | |||
32 | # Close all connections and delete the database. |
||
33 | # |
||
34 | code1 { db close } |
||
35 | code2 { db2 close } |
||
36 | code3 { db3 close } |
||
37 | forcedelete test.db |
||
38 | forcedelete walro |
||
39 | |||
40 | foreach c {code1 code2 code3} { |
||
41 | $c { |
||
42 | sqlite3_shutdown |
||
43 | sqlite3_config_uri 1 |
||
44 | } |
||
45 | } |
||
46 | |||
47 | file mkdir walro |
||
48 | |||
49 | do_test 1.1.1 { |
||
50 | code2 { sqlite3 db2 test.db } |
||
51 | sql2 { |
||
52 | PRAGMA journal_mode = WAL; |
||
53 | CREATE TABLE t1(x, y); |
||
54 | INSERT INTO t1 VALUES('a', 'b'); |
||
55 | } |
||
56 | file exists test.db-shm |
||
57 | } {1} |
||
58 | |||
59 | do_test 1.1.2 { |
||
60 | file attributes test.db-shm -permissions r--r--r-- |
||
61 | code1 { sqlite3 db file:test.db?readonly_shm=1 } |
||
62 | } {} |
||
63 | |||
64 | do_test 1.1.3 { sql1 "SELECT * FROM t1" } {a b} |
||
65 | do_test 1.1.4 { sql2 "INSERT INTO t1 VALUES('c', 'd')" } {} |
||
66 | do_test 1.1.5 { sql1 "SELECT * FROM t1" } {a b c d} |
||
67 | |||
68 | # Check that the read-only connection cannot write or checkpoint the db. |
||
69 | # |
||
70 | do_test 1.1.6 { |
||
71 | csql1 "INSERT INTO t1 VALUES('e', 'f')" |
||
72 | } {1 {attempt to write a readonly database}} |
||
73 | do_test 1.1.7 { |
||
74 | csql1 "PRAGMA wal_checkpoint" |
||
75 | } {1 {attempt to write a readonly database}} |
||
76 | |||
77 | do_test 1.1.9 { sql2 "INSERT INTO t1 VALUES('e', 'f')" } {} |
||
78 | do_test 1.1.10 { sql1 "SELECT * FROM t1" } {a b c d e f} |
||
79 | |||
80 | do_test 1.1.11 { |
||
81 | sql2 { |
||
82 | INSERT INTO t1 VALUES('g', 'h'); |
||
83 | PRAGMA wal_checkpoint; |
||
84 | } |
||
85 | set {} {} |
||
86 | } {} |
||
87 | do_test 1.1.12 { sql1 "SELECT * FROM t1" } {a b c d e f g h} |
||
88 | do_test 1.1.13 { sql2 "INSERT INTO t1 VALUES('i', 'j')" } {} |
||
89 | |||
90 | do_test 1.2.1 { |
||
91 | code2 { db2 close } |
||
92 | code1 { db close } |
||
93 | list [file exists test.db-wal] [file exists test.db-shm] |
||
94 | } {1 1} |
||
95 | do_test 1.2.2 { |
||
96 | code1 { sqlite3 db file:test.db?readonly_shm=1 } |
||
97 | sql1 { SELECT * FROM t1 } |
||
98 | } {a b c d e f g h i j} |
||
99 | |||
100 | do_test 1.2.3 { |
||
101 | code1 { db close } |
||
102 | file attributes test.db-shm -permissions rw-r--r-- |
||
103 | hexio_write test.db-shm 0 01020304 |
||
104 | file attributes test.db-shm -permissions r--r--r-- |
||
105 | code1 { sqlite3 db file:test.db?readonly_shm=1 } |
||
106 | csql1 { SELECT * FROM t1 } |
||
107 | } {1 {attempt to write a readonly database}} |
||
108 | do_test 1.2.4 { |
||
109 | code1 { sqlite3_extended_errcode db } |
||
110 | } {SQLITE_READONLY_RECOVERY} |
||
111 | |||
112 | do_test 1.2.5 { |
||
113 | file attributes test.db-shm -permissions rw-r--r-- |
||
114 | code2 { sqlite3 db2 test.db } |
||
115 | sql2 "SELECT * FROM t1" |
||
116 | } {a b c d e f g h i j} |
||
117 | file attributes test.db-shm -permissions r--r--r-- |
||
118 | do_test 1.2.6 { sql1 "SELECT * FROM t1" } {a b c d e f g h i j} |
||
119 | |||
120 | do_test 1.2.7 { |
||
121 | sql2 { |
||
122 | PRAGMA wal_checkpoint; |
||
123 | INSERT INTO t1 VALUES('k', 'l'); |
||
124 | } |
||
125 | set {} {} |
||
126 | } {} |
||
127 | do_test 1.2.8 { sql1 "SELECT * FROM t1" } {a b c d e f g h i j k l} |
||
128 | |||
129 | # Now check that if the readonly_shm option is not supplied, or if it |
||
130 | # is set to zero, it is not possible to connect to the database without |
||
131 | # read-write access to the shm. |
||
132 | do_test 1.3.1 { |
||
133 | code1 { db close } |
||
134 | code1 { sqlite3 db test.db } |
||
135 | csql1 { SELECT * FROM t1 } |
||
136 | } {1 {unable to open database file}} |
||
137 | |||
138 | # Also test that if the -shm file can be opened for read/write access, |
||
139 | # it is, even if readonly_shm=1 is present in the URI. |
||
140 | do_test 1.3.2.1 { |
||
141 | code1 { db close } |
||
142 | code2 { db2 close } |
||
143 | file exists test.db-shm |
||
144 | } {0} |
||
145 | do_test 1.3.2.2 { |
||
146 | code1 { sqlite3 db file:test.db?readonly_shm=1 } |
||
147 | sql1 { SELECT * FROM t1 } |
||
148 | } {a b c d e f g h i j k l} |
||
149 | do_test 1.3.2.3 { |
||
150 | code1 { db close } |
||
151 | close [open test.db-shm w] |
||
152 | file attributes test.db-shm -permissions r--r--r-- |
||
153 | code1 { sqlite3 db file:test.db?readonly_shm=1 } |
||
154 | csql1 { SELECT * FROM t1 } |
||
155 | } {1 {attempt to write a readonly database}} |
||
156 | do_test 1.3.2.4 { |
||
157 | code1 { sqlite3_extended_errcode db } |
||
158 | } {SQLITE_READONLY_RECOVERY} |
||
159 | } |
||
160 | |||
161 | finish_test |