| OLD | NEW | 
 | (Empty) | 
|   1 # 2007 April 24 |  | 
|   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 # This file implements regression tests for SQLite library. |  | 
|  12 # |  | 
|  13 # This file implements tests to make sure SQLite treats a database |  | 
|  14 # as readonly if its write version is set to  high. |  | 
|  15 # |  | 
|  16 # $Id: rdonly.test,v 1.2 2008/07/08 10:19:58 danielk1977 Exp $ |  | 
|  17  |  | 
|  18 set testdir [file dirname $argv0] |  | 
|  19 source $testdir/tester.tcl |  | 
|  20  |  | 
|  21  |  | 
|  22 # Create a database. |  | 
|  23 # |  | 
|  24 do_test rdonly-1.1 { |  | 
|  25   execsql { |  | 
|  26     CREATE TABLE t1(x); |  | 
|  27     INSERT INTO t1 VALUES(1); |  | 
|  28     SELECT * FROM t1; |  | 
|  29   } |  | 
|  30 } {1} |  | 
|  31  |  | 
|  32 # Changes the write version from 1 to 2.  Verify that the database |  | 
|  33 # can be read but not written. |  | 
|  34 # |  | 
|  35 do_test rdonly-1.2 { |  | 
|  36   db close |  | 
|  37   hexio_get_int [hexio_read test.db 18 1] |  | 
|  38 } 1 |  | 
|  39 do_test rdonly-1.3 { |  | 
|  40   hexio_write test.db 18 02 |  | 
|  41   sqlite3 db test.db |  | 
|  42   execsql { |  | 
|  43     SELECT * FROM t1; |  | 
|  44   } |  | 
|  45 } {1} |  | 
|  46 do_test rdonly-1.4 { |  | 
|  47   catchsql { |  | 
|  48     INSERT INTO t1 VALUES(2) |  | 
|  49   } |  | 
|  50 } {1 {attempt to write a readonly database}} |  | 
|  51  |  | 
|  52 # Change the write version back to 1.  Verify that the database |  | 
|  53 # is read-write again. |  | 
|  54 # |  | 
|  55 do_test rdonly-1.5 { |  | 
|  56   db close |  | 
|  57   hexio_write test.db 18 01 |  | 
|  58   sqlite3 db test.db |  | 
|  59   catchsql { |  | 
|  60     INSERT INTO t1 VALUES(2); |  | 
|  61     SELECT * FROM t1; |  | 
|  62   } |  | 
|  63 } {0 {1 2}} |  | 
|  64  |  | 
|  65 # Now, after connection [db] has loaded the database schema, modify the |  | 
|  66 # write-version of the file (and the change-counter, so that the  |  | 
|  67 # write-version is reloaded). This way, SQLite does not discover that |  | 
|  68 # the database is read-only until after it is locked. |  | 
|  69 # |  | 
|  70 do_test rdonly-1.6 { |  | 
|  71   hexio_write test.db 18 02              ; # write-version |  | 
|  72   hexio_write test.db 24 11223344        ; # change-counter |  | 
|  73   catchsql { |  | 
|  74     INSERT INTO t1 VALUES(2); |  | 
|  75   } |  | 
|  76 } {1 {attempt to write a readonly database}} |  | 
|  77  |  | 
|  78 finish_test |  | 
| OLD | NEW |