3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # Tests for the SQLITE_READONLY_DBMOVED error condition: the database file
13 # is unlinked or renamed out from under SQLite.
16 if {$tcl_platform(platform)!="unix"} return
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
21 if {[permutation]=="inmemory_journal"} {
26 # Create a database file for testing
28 do_execsql_test pager4-1.1 {
29 CREATE TABLE t1(a,b,c);
30 INSERT INTO t1 VALUES(673,'stone','philips');
34 # After renaming the database file while it is open, one can still
35 # read from the database, but writing returns a READONLY error.
37 file delete -force test-xyz.db
38 file rename test.db test-xyz.db
39 do_catchsql_test pager4-1.2 {
41 } {0 {673 stone philips}}
42 do_catchsql_test pager4-1.3 {
44 } {1 {attempt to write a readonly database}}
46 # Creating a different database file with the same name of the original
47 # is detected and still leaves the database read-only.
50 db2 eval {CREATE TABLE t2(x,y,z)}
51 do_catchsql_test pager4-1.4 {
53 } {1 {attempt to write a readonly database}}
55 # Changing the name back clears the READONLY error
58 file delete -force test.db
59 file rename test-xyz.db test.db
60 do_catchsql_test pager4-1.5 {
62 } {0 {673 stone philips}}
63 do_catchsql_test pager4-1.6 {
66 } {0 {537 stone philips}}
68 # We can write to a renamed database if journal_mode=OFF or
69 # journal_mode=MEMORY.
71 file rename test.db test-xyz.db
72 do_catchsql_test pager4-1.7 {
73 PRAGMA journal_mode=OFF;
76 } {0 {off 107 stone philips}}
77 do_catchsql_test pager4-1.8 {
78 PRAGMA journal_mode=MEMORY;
79 UPDATE t1 SET b='magpie';
81 } {0 {memory 107 magpie philips}}
83 # Any other journal mode gives a READONLY error
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}}