1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/rdonly.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,78 @@
1.4 +# 2007 April 24
1.5 +#
1.6 +# The author disclaims copyright to this source code. In place of
1.7 +# a legal notice, here is a blessing:
1.8 +#
1.9 +# May you do good and not evil.
1.10 +# May you find forgiveness for yourself and forgive others.
1.11 +# May you share freely, never taking more than you give.
1.12 +#
1.13 +#***********************************************************************
1.14 +# This file implements regression tests for SQLite library.
1.15 +#
1.16 +# This file implements tests to make sure SQLite treats a database
1.17 +# as readonly if its write version is set to high.
1.18 +#
1.19 +# $Id: rdonly.test,v 1.2 2008/07/08 10:19:58 danielk1977 Exp $
1.20 +
1.21 +set testdir [file dirname $argv0]
1.22 +source $testdir/tester.tcl
1.23 +
1.24 +
1.25 +# Create a database.
1.26 +#
1.27 +do_test rdonly-1.1 {
1.28 + execsql {
1.29 + CREATE TABLE t1(x);
1.30 + INSERT INTO t1 VALUES(1);
1.31 + SELECT * FROM t1;
1.32 + }
1.33 +} {1}
1.34 +
1.35 +# Changes the write version from 1 to 2. Verify that the database
1.36 +# can be read but not written.
1.37 +#
1.38 +do_test rdonly-1.2 {
1.39 + db close
1.40 + hexio_get_int [hexio_read test.db 18 1]
1.41 +} 1
1.42 +do_test rdonly-1.3 {
1.43 + hexio_write test.db 18 02
1.44 + sqlite3 db test.db
1.45 + execsql {
1.46 + SELECT * FROM t1;
1.47 + }
1.48 +} {1}
1.49 +do_test rdonly-1.4 {
1.50 + catchsql {
1.51 + INSERT INTO t1 VALUES(2)
1.52 + }
1.53 +} {1 {attempt to write a readonly database}}
1.54 +
1.55 +# Change the write version back to 1. Verify that the database
1.56 +# is read-write again.
1.57 +#
1.58 +do_test rdonly-1.5 {
1.59 + db close
1.60 + hexio_write test.db 18 01
1.61 + sqlite3 db test.db
1.62 + catchsql {
1.63 + INSERT INTO t1 VALUES(2);
1.64 + SELECT * FROM t1;
1.65 + }
1.66 +} {0 {1 2}}
1.67 +
1.68 +# Now, after connection [db] has loaded the database schema, modify the
1.69 +# write-version of the file (and the change-counter, so that the
1.70 +# write-version is reloaded). This way, SQLite does not discover that
1.71 +# the database is read-only until after it is locked.
1.72 +#
1.73 +do_test rdonly-1.6 {
1.74 + hexio_write test.db 18 02 ; # write-version
1.75 + hexio_write test.db 24 11223344 ; # change-counter
1.76 + catchsql {
1.77 + INSERT INTO t1 VALUES(2);
1.78 + }
1.79 +} {1 {attempt to write a readonly database}}
1.80 +
1.81 +finish_test