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 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file implements tests to make sure SQLite treats a database
14 # as readonly if its write version is set to high.
16 # $Id: rdonly.test,v 1.2 2008/07/08 10:19:58 danielk1977 Exp $
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
21 # Do not use a codec for tests in this file, as the database file is
22 # manipulated directly using tcl scripts (using the [hexio_write] command).
31 INSERT INTO t1 VALUES(1);
36 # EVIDENCE-OF: R-29639-16887 The sqlite3_db_readonly(D,N) interface
37 # returns 1 if the database N of connection D is read-only, 0 if it is
38 # read/write, or -1 if N is not the name of a database on connection D.
40 do_test rdonly-1.1.1 {
41 sqlite3_db_readonly db main
44 # Changes the write version from 1 to 3. Verify that the database
45 # can be read but not written.
49 hexio_get_int [hexio_read test.db 18 1]
52 hexio_write test.db 18 03
58 do_test rdonly-1.3.1 {
59 sqlite3_db_readonly db main
63 INSERT INTO t1 VALUES(2)
65 } {1 {attempt to write a readonly database}}
67 # Change the write version back to 1. Verify that the database
68 # is read-write again.
72 hexio_write test.db 18 01
75 INSERT INTO t1 VALUES(2);
80 # Now, after connection [db] has loaded the database schema, modify the
81 # write-version of the file (and the change-counter, so that the
82 # write-version is reloaded). This way, SQLite does not discover that
83 # the database is read-only until after it is locked.
86 ifcapable wal { set ro_version 03 }
88 hexio_write test.db 18 $ro_version ; # write-version
89 hexio_write test.db 24 11223344 ; # change-counter
91 INSERT INTO t1 VALUES(2);
93 } {1 {attempt to write a readonly database}}