OLD | NEW |
| (Empty) |
1 # 2013-12-06 | |
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 # Tests for the SQLITE_READONLY_DBMOVED error condition: the database file | |
13 # is unlinked or renamed out from under SQLite. | |
14 # | |
15 | |
16 if {$tcl_platform(platform)!="unix"} return | |
17 | |
18 set testdir [file dirname $argv0] | |
19 source $testdir/tester.tcl | |
20 | |
21 if {[permutation]=="inmemory_journal"} { | |
22 finish_test | |
23 return | |
24 } | |
25 | |
26 # Create a database file for testing | |
27 # | |
28 do_execsql_test pager4-1.1 { | |
29 CREATE TABLE t1(a,b,c); | |
30 INSERT INTO t1 VALUES(673,'stone','philips'); | |
31 SELECT * FROM t1; | |
32 } {673 stone philips} | |
33 | |
34 # After renaming the database file while it is open, one can still | |
35 # read from the database, but writing returns a READONLY error. | |
36 # | |
37 file delete -force test-xyz.db | |
38 file rename test.db test-xyz.db | |
39 do_catchsql_test pager4-1.2 { | |
40 SELECT * FROM t1; | |
41 } {0 {673 stone philips}} | |
42 do_catchsql_test pager4-1.3 { | |
43 UPDATE t1 SET a=537; | |
44 } {1 {attempt to write a readonly database}} | |
45 | |
46 # Creating a different database file with the same name of the original | |
47 # is detected and still leaves the database read-only. | |
48 # | |
49 sqlite3 db2 test.db | |
50 db2 eval {CREATE TABLE t2(x,y,z)} | |
51 do_catchsql_test pager4-1.4 { | |
52 UPDATE t1 SET a=948; | |
53 } {1 {attempt to write a readonly database}} | |
54 | |
55 # Changing the name back clears the READONLY error | |
56 # | |
57 db2 close | |
58 file delete -force test.db | |
59 file rename test-xyz.db test.db | |
60 do_catchsql_test pager4-1.5 { | |
61 SELECT * FROM t1; | |
62 } {0 {673 stone philips}} | |
63 do_catchsql_test pager4-1.6 { | |
64 UPDATE t1 SET a=537; | |
65 SELECT * FROM t1; | |
66 } {0 {537 stone philips}} | |
67 | |
68 # We can write to a renamed database if journal_mode=OFF or | |
69 # journal_mode=MEMORY. | |
70 # | |
71 file rename test.db test-xyz.db | |
72 do_catchsql_test pager4-1.7 { | |
73 PRAGMA journal_mode=OFF; | |
74 UPDATE t1 SET a=107; | |
75 SELECT * FROM t1; | |
76 } {0 {off 107 stone philips}} | |
77 do_catchsql_test pager4-1.8 { | |
78 PRAGMA journal_mode=MEMORY; | |
79 UPDATE t1 SET b='magpie'; | |
80 SELECT * FROM t1; | |
81 } {0 {memory 107 magpie philips}} | |
82 | |
83 # Any other journal mode gives a READONLY error | |
84 # | |
85 do_catchsql_test pager4-1.9 { | |
86 PRAGMA journal_mode=DELETE; | |
87 UPDATE t1 SET c='jaguar'; | |
88 } {1 {attempt to write a readonly database}} | |
89 do_catchsql_test pager4-1.10 { | |
90 PRAGMA journal_mode=TRUNCATE; | |
91 UPDATE t1 SET c='jaguar'; | |
92 } {1 {attempt to write a readonly database}} | |
93 do_catchsql_test pager4-1.11 { | |
94 PRAGMA journal_mode=PERSIST; | |
95 UPDATE t1 SET c='jaguar'; | |
96 } {1 {attempt to write a readonly database}} | |
97 | |
98 | |
99 finish_test | |
OLD | NEW |