2013-12-06 19:37:35 +04:00
|
|
|
# 2013-12-06
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
#
|
2014-01-27 20:35:15 +04:00
|
|
|
# Tests for the SQLITE_READONLY_DBMOVED error condition: the database file
|
2013-12-06 19:37:35 +04:00
|
|
|
# is unlinked or renamed out from under SQLite.
|
|
|
|
#
|
|
|
|
|
|
|
|
if {$tcl_platform(platform)!="unix"} return
|
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
|
|
|
|
2014-01-27 20:35:15 +04:00
|
|
|
if {[permutation]=="inmemory_journal"} {
|
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2013-12-06 21:23:38 +04:00
|
|
|
# Create a database file for testing
|
|
|
|
#
|
2013-12-06 19:37:35 +04:00
|
|
|
do_execsql_test pager4-1.1 {
|
|
|
|
CREATE TABLE t1(a,b,c);
|
|
|
|
INSERT INTO t1 VALUES(673,'stone','philips');
|
|
|
|
SELECT * FROM t1;
|
|
|
|
} {673 stone philips}
|
2013-12-06 21:23:38 +04:00
|
|
|
|
|
|
|
# After renaming the database file while it is open, one can still
|
|
|
|
# read from the database, but writing returns a READONLY error.
|
|
|
|
#
|
2013-12-06 19:37:35 +04:00
|
|
|
file delete -force test-xyz.db
|
|
|
|
file rename test.db test-xyz.db
|
|
|
|
do_catchsql_test pager4-1.2 {
|
|
|
|
SELECT * FROM t1;
|
2013-12-06 21:23:38 +04:00
|
|
|
} {0 {673 stone philips}}
|
|
|
|
do_catchsql_test pager4-1.3 {
|
|
|
|
UPDATE t1 SET a=537;
|
|
|
|
} {1 {attempt to write a readonly database}}
|
|
|
|
|
2013-12-07 16:29:22 +04:00
|
|
|
# Creating a different database file with the same name of the original
|
|
|
|
# is detected and still leaves the database read-only.
|
|
|
|
#
|
|
|
|
sqlite3 db2 test.db
|
|
|
|
db2 eval {CREATE TABLE t2(x,y,z)}
|
|
|
|
do_catchsql_test pager4-1.4 {
|
|
|
|
UPDATE t1 SET a=948;
|
|
|
|
} {1 {attempt to write a readonly database}}
|
|
|
|
|
2013-12-06 21:23:38 +04:00
|
|
|
# Changing the name back clears the READONLY error
|
|
|
|
#
|
2013-12-07 16:29:22 +04:00
|
|
|
db2 close
|
|
|
|
file delete -force test.db
|
2013-12-06 21:23:38 +04:00
|
|
|
file rename test-xyz.db test.db
|
2013-12-07 16:29:22 +04:00
|
|
|
do_catchsql_test pager4-1.5 {
|
2013-12-06 21:23:38 +04:00
|
|
|
SELECT * FROM t1;
|
|
|
|
} {0 {673 stone philips}}
|
2013-12-07 16:29:22 +04:00
|
|
|
do_catchsql_test pager4-1.6 {
|
2013-12-06 21:23:38 +04:00
|
|
|
UPDATE t1 SET a=537;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
} {0 {537 stone philips}}
|
|
|
|
|
|
|
|
# We can write to a renamed database if journal_mode=OFF or
|
|
|
|
# journal_mode=MEMORY.
|
|
|
|
#
|
|
|
|
file rename test.db test-xyz.db
|
2013-12-07 16:29:22 +04:00
|
|
|
do_catchsql_test pager4-1.7 {
|
2013-12-06 21:23:38 +04:00
|
|
|
PRAGMA journal_mode=OFF;
|
|
|
|
UPDATE t1 SET a=107;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
} {0 {off 107 stone philips}}
|
2013-12-07 16:29:22 +04:00
|
|
|
do_catchsql_test pager4-1.8 {
|
2013-12-06 21:23:38 +04:00
|
|
|
PRAGMA journal_mode=MEMORY;
|
|
|
|
UPDATE t1 SET b='magpie';
|
|
|
|
SELECT * FROM t1;
|
|
|
|
} {0 {memory 107 magpie philips}}
|
|
|
|
|
|
|
|
# Any other journal mode gives a READONLY error
|
|
|
|
#
|
2013-12-07 16:29:22 +04:00
|
|
|
do_catchsql_test pager4-1.9 {
|
2013-12-06 21:23:38 +04:00
|
|
|
PRAGMA journal_mode=DELETE;
|
|
|
|
UPDATE t1 SET c='jaguar';
|
|
|
|
} {1 {attempt to write a readonly database}}
|
2013-12-07 16:29:22 +04:00
|
|
|
do_catchsql_test pager4-1.10 {
|
2013-12-06 21:23:38 +04:00
|
|
|
PRAGMA journal_mode=TRUNCATE;
|
|
|
|
UPDATE t1 SET c='jaguar';
|
|
|
|
} {1 {attempt to write a readonly database}}
|
2013-12-07 16:29:22 +04:00
|
|
|
do_catchsql_test pager4-1.11 {
|
2013-12-06 21:23:38 +04:00
|
|
|
PRAGMA journal_mode=PERSIST;
|
|
|
|
UPDATE t1 SET c='jaguar';
|
|
|
|
} {1 {attempt to write a readonly database}}
|
2013-12-06 19:37:35 +04:00
|
|
|
|
|
|
|
|
|
|
|
finish_test
|