xref: /sqlite-3.40.0/test/pager4.test (revision 3fee8a63)
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_IOERR_NODB error condition: the database file file
13# is unlinked or renamed out from under SQLite.
14#
15
16if {$tcl_platform(platform)!="unix"} return
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20
21# Create a database file for testing
22#
23do_execsql_test pager4-1.1 {
24  CREATE TABLE t1(a,b,c);
25  INSERT INTO t1 VALUES(673,'stone','philips');
26  SELECT * FROM t1;
27} {673 stone philips}
28
29# After renaming the database file while it is open, one can still
30# read from the database, but writing returns a READONLY error.
31#
32file delete -force test-xyz.db
33file rename test.db test-xyz.db
34do_catchsql_test pager4-1.2 {
35  SELECT * FROM t1;
36} {0 {673 stone philips}}
37do_catchsql_test pager4-1.3 {
38  UPDATE t1 SET a=537;
39} {1 {attempt to write a readonly database}}
40
41# Changing the name back clears the READONLY error
42#
43file rename test-xyz.db test.db
44do_catchsql_test pager4-1.4 {
45  SELECT * FROM t1;
46} {0 {673 stone philips}}
47do_catchsql_test pager4-1.5 {
48  UPDATE t1 SET a=537;
49  SELECT * FROM t1;
50} {0 {537 stone philips}}
51
52# We can write to a renamed database if journal_mode=OFF or
53# journal_mode=MEMORY.
54#
55file rename test.db test-xyz.db
56do_catchsql_test pager4-1.6 {
57  PRAGMA journal_mode=OFF;
58  UPDATE t1 SET a=107;
59  SELECT * FROM t1;
60} {0 {off 107 stone philips}}
61do_catchsql_test pager4-1.7 {
62  PRAGMA journal_mode=MEMORY;
63  UPDATE t1 SET b='magpie';
64  SELECT * FROM t1;
65} {0 {memory 107 magpie philips}}
66
67# Any other journal mode gives a READONLY error
68#
69do_catchsql_test pager4-1.8 {
70  PRAGMA journal_mode=DELETE;
71  UPDATE t1 SET c='jaguar';
72} {1 {attempt to write a readonly database}}
73do_catchsql_test pager4-1.9 {
74  PRAGMA journal_mode=TRUNCATE;
75  UPDATE t1 SET c='jaguar';
76} {1 {attempt to write a readonly database}}
77do_catchsql_test pager4-1.10 {
78  PRAGMA journal_mode=PERSIST;
79  UPDATE t1 SET c='jaguar';
80} {1 {attempt to write a readonly database}}
81
82
83finish_test
84