sl@0: # 2007 April 24 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. sl@0: # sl@0: # This file implements tests to make sure SQLite treats a database sl@0: # as readonly if its write version is set to high. sl@0: # sl@0: # $Id: rdonly.test,v 1.2 2008/07/08 10:19:58 danielk1977 Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: sl@0: # Create a database. sl@0: # sl@0: do_test rdonly-1.1 { sl@0: execsql { sl@0: CREATE TABLE t1(x); sl@0: INSERT INTO t1 VALUES(1); sl@0: SELECT * FROM t1; sl@0: } sl@0: } {1} sl@0: sl@0: # Changes the write version from 1 to 2. Verify that the database sl@0: # can be read but not written. sl@0: # sl@0: do_test rdonly-1.2 { sl@0: db close sl@0: hexio_get_int [hexio_read test.db 18 1] sl@0: } 1 sl@0: do_test rdonly-1.3 { sl@0: hexio_write test.db 18 02 sl@0: sqlite3 db test.db sl@0: execsql { sl@0: SELECT * FROM t1; sl@0: } sl@0: } {1} sl@0: do_test rdonly-1.4 { sl@0: catchsql { sl@0: INSERT INTO t1 VALUES(2) sl@0: } sl@0: } {1 {attempt to write a readonly database}} sl@0: sl@0: # Change the write version back to 1. Verify that the database sl@0: # is read-write again. sl@0: # sl@0: do_test rdonly-1.5 { sl@0: db close sl@0: hexio_write test.db 18 01 sl@0: sqlite3 db test.db sl@0: catchsql { sl@0: INSERT INTO t1 VALUES(2); sl@0: SELECT * FROM t1; sl@0: } sl@0: } {0 {1 2}} sl@0: sl@0: # Now, after connection [db] has loaded the database schema, modify the sl@0: # write-version of the file (and the change-counter, so that the sl@0: # write-version is reloaded). This way, SQLite does not discover that sl@0: # the database is read-only until after it is locked. sl@0: # sl@0: do_test rdonly-1.6 { sl@0: hexio_write test.db 18 02 ; # write-version sl@0: hexio_write test.db 24 11223344 ; # change-counter sl@0: catchsql { sl@0: INSERT INTO t1 VALUES(2); sl@0: } sl@0: } {1 {attempt to write a readonly database}} sl@0: sl@0: finish_test