]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Test the libaries response to read-only or unreadable database, WAL and wal-index...
authordan <dan@noemail.net>
Wed, 14 Jul 2010 16:37:17 +0000 (16:37 +0000)
committerdan <dan@noemail.net>
Wed, 14 Jul 2010 16:37:17 +0000 (16:37 +0000)
FossilOrigin-Name: 45bb84c6283d803fc29077fdc2d06fa50ec06a59

manifest
manifest.uuid
src/wal.c
test/malloc_common.tcl
test/wal2.test

index 40bcd2ed77c051e772f82c9b6912e21ccc6c9368..3addfb59d783b7f370af8069b09f30a845701631 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C On\sunix,\stry\sto\screate\sthe\s*-wal\sand\s*-shm\sfiles\swith\sthe\ssame\spermissions\sas\sthe\sassociated\sdatabase\sfile.
-D 2010-07-14T14:48:58
+C Test\sthe\slibaries\sresponse\sto\sread-only\sor\sunreadable\sdatabase,\sWAL\sand\swal-index\sfiles.\sIf\sa\sWAL\sfile\scannot\sbe\sopened\sin\sread/write\smode,\sreturn\sSQLITE_CANTOPEN\sto\sthe\scaller.
+D 2010-07-14T16:37:18
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in ec08dc838fd8110fe24c92e5130bcd91cbb1ff2e
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -227,7 +227,7 @@ F src/vdbeblob.c 258a6010ba7a82b72b327fb24c55790655689256
 F src/vdbemem.c 5e579abf6532001dfbee0e640dc34eae897a9807
 F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
 F src/vtab.c a0f8a40274e4261696ef57aa806de2776ab72cda
-F src/wal.c 60932f29302b978a5eb4c637dbbc2db1d70a536f
+F src/wal.c 656d50bb0b64f79353110a0b50790edfc0da08e9
 F src/wal.h 906c85760598b18584921fe08008435aa4eeeeb2
 F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
 F src/where.c 926c83c6394e132a1c62b6b12ceeba7d55a34c19
@@ -510,7 +510,7 @@ F test/mallocH.test 79b65aed612c9b3ed2dcdaa727c85895fd1bfbdb
 F test/mallocI.test a88c2b9627c8506bf4703d8397420043a786cdb6
 F test/mallocJ.test b5d1839da331d96223e5f458856f8ffe1366f62e
 F test/mallocK.test d79968641d1b70d88f6c01bdb9a7eb4a55582cc9
-F test/malloc_common.tcl 98542309c7c304a14c9b08560f654715d69d8090
+F test/malloc_common.tcl 55b88520b1b181a6e9bf2afcc75801256bbcecb7
 F test/manydb.test b3d3bc4c25657e7f68d157f031eb4db7b3df0d3c
 F test/memdb.test 0825155b2290e900264daaaf0334b6dfe69ea498
 F test/memleak.test 10b9c6c57e19fc68c32941495e9ba1c50123f6e2
@@ -776,7 +776,7 @@ F test/vtab_alter.test 9e374885248f69e251bdaacf480b04a197f125e5
 F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8
 F test/vtab_shared.test 0eff9ce4f19facbe0a3e693f6c14b80711a4222d
 F test/wal.test 1891e6f72dd437a1c2a48091aa9182ba17a8f780
-F test/wal2.test b26d04c36361a3dd99b9c5a43658f12e0d197c70
+F test/wal2.test 9a05210e52e92f375724809c6ee2878413323af1
 F test/wal3.test d2ae7e66f973bd6b58ce49e546b2c00f44fe0485
 F test/wal4.test 640be93f5422df37203aa5e7c06b24fb5e4a2439
 F test/wal_common.tcl 895d76138043b86bdccf36494054bdabcf65837b
@@ -834,7 +834,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P b092f2a74bdc77c1f90ad3b4448cb68a891ecf63
-R c3e2391a3a0460d3db8727396fae83c1
+P e5d180eed245437b61bfb257ee01e2571c93afe7
+R 37ecab746321ec5b139df993c3f23915
 U dan
-Z 33764ba68244566e69f565fd4aced7cc
+Z 80bc5a7b8b2ec2d9510d95559b42838d
index 909fbf88d6995e4f526958fb760abccd7436b768..c684d78197a220a5675ea9cdc370182010bcaeab 100644 (file)
@@ -1 +1 @@
-e5d180eed245437b61bfb257ee01e2571c93afe7
\ No newline at end of file
+45bb84c6283d803fc29077fdc2d06fa50ec06a59
\ No newline at end of file
index d9563e61937a65eaf973f881d83bbf5e9d88ec74..769db036dad50bb1d33ad54e37c11dcf421dc247 100644 (file)
--- a/src/wal.c
+++ b/src/wal.c
@@ -1226,6 +1226,9 @@ int sqlite3WalOpen(
   /* Open file handle on the write-ahead log file. */
   flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_WAL);
   rc = sqlite3OsOpen(pVfs, zWalName, pRet->pWalFd, flags, &flags);
+  if( rc==SQLITE_OK && flags&SQLITE_OPEN_READONLY ){
+    rc = SQLITE_CANTOPEN;
+  }
 
   if( rc!=SQLITE_OK ){
     walIndexClose(pRet, 0);
index e86c4f3661b42e993f02a149338ac117001e16a0..07e1b2b38cabd53f325f77fcef689a245703ed61 100644 (file)
@@ -137,6 +137,7 @@ proc do_faultsim_test {name args} {
 # Procedures to save and restore the current file-system state:
 #
 #   faultsim_save
+#   faultsim_restore
 #   faultsim_save_and_close
 #   faultsim_restore_and_reopen
 #   faultsim_delete_and_reopen
@@ -153,13 +154,16 @@ proc faultsim_save_and_close {} {
   catch { db close }
   return ""
 }
-proc faultsim_restore_and_reopen {{dbfile test.db}} {
-  catch { db close }
+proc faultsim_restore {} {
   foreach f [glob -nocomplain test.db*] { file delete -force $f }
   foreach f2 [glob -nocomplain sv_test.db*] {
     set f [string range $f2 3 end]
     file copy -force $f2 $f
   }
+}
+proc faultsim_restore_and_reopen {{dbfile test.db}} {
+  catch { db close }
+  faultsim_restore
   sqlite3 db $dbfile
   sqlite3_extended_result_codes db 1
   sqlite3_db_config_lookaside db 0 0 0
index 0638965374315c8d45d3ef1ae208ae8a66f2375a..951e8c39c2e548bebb439f6411957a3d3d24ee8e 100644 (file)
@@ -1005,8 +1005,8 @@ tvfs delete
 #
 if {$::tcl_platform(platform) == "unix"} {
   faultsim_delete_and_reopen
-
   set umask [exec /bin/sh -c umask]
+
   do_test wal2-12.1 {
     sqlite3 db test.db
     execsql { 
@@ -1046,5 +1046,96 @@ if {$::tcl_platform(platform) == "unix"} {
   }
 }
 
+#-------------------------------------------------------------------------
+# Test the libraries response to discovering that one or more of the
+# database, wal or shm files cannot be opened, or can only be opened
+# read-only.
+#
+if {$::tcl_platform(platform) == "unix"} {
+  proc perm {} {
+    set L [list]
+    foreach f {test.db test.db-wal test.db-shm} {
+      if {[file exists $f]} {
+        lappend L [file attr $f -perm]
+      } else {
+        lappend L {}
+      }
+    }
+    set L
+  }
+
+  faultsim_delete_and_reopen
+  execsql {
+    PRAGMA journal_mode = WAL;
+    CREATE TABLE t1(a, b);
+    PRAGMA wal_checkpoint;
+    INSERT INTO t1 VALUES('3.14', '2.72');
+  }
+  do_test wal2-13.1.1 {
+    list [file exists test.db-shm] [file exists test.db-wal]
+  } {1 1}
+  faultsim_save_and_close
+
+  foreach {tn db_perm wal_perm shm_perm can_open can_read can_write} {
+    2   00644   00644   00644   1   1   1
+    3   00644   00400   00644   1   0   0
+    4   00644   00644   00400   1   0   0
+    5   00400   00644   00644   1   1   0
+
+    7   00644   00000   00644   1   0   0
+    8   00644   00644   00000   1   0   0
+    9   00000   00644   00644   0   0   0
+  } {
+    faultsim_restore
+    do_test wal2-13.$tn.1 {
+      file attr test.db     -perm $db_perm
+      file attr test.db-wal -perm $wal_perm
+      file attr test.db-shm -perm $shm_perm
+
+      set     L [file attr test.db -perm]
+      lappend L [file attr test.db-wal -perm]
+      lappend L [file attr test.db-shm -perm]
+    } [list $db_perm $wal_perm $shm_perm]
+
+    # If $can_open is true, then it should be possible to open a database
+    # handle. Otherwise, if $can_open is 0, attempting to open the db
+    # handle throws an "unable to open database file" exception.
+    #
+    set r(1) {0 ok}
+    set r(0) {1 {unable to open database file}}
+    do_test wal2-13.$tn.2 {
+      list [catch {sqlite3 db test.db ; set {} ok} msg] $msg
+    } $r($can_open)
+
+    if {$can_open} {
+
+      # If $can_read is true, then the client should be able to read from
+      # the database file. If $can_read is false, attempting to read should
+      # throw the "unable to open database file" exception. 
+      #
+      set a(0) {1 {unable to open database file}}
+      set a(1) {0 {3.14 2.72}}
+      do_test wal2-13.$tn.3 {
+        catchsql { SELECT * FROM t1 }
+      } $a($can_read)
+  
+      # Now try to write to the db file. If the client can read but not
+      # write, then it should throw the familiar "unable to open db file"
+      # exception. If it can read but not write, the exception should
+      # be "attempt to write a read only database".
+      #
+      # If the client can read and write, the operation should succeed.
+      #
+      set b(0,0) {1 {unable to open database file}}
+      set b(1,0) {1 {attempt to write a readonly database}}
+      set b(1,1) {0 {}}
+      do_test wal2-13.$tn.4 {
+        catchsql { INSERT INTO t1 DEFAULT VALUES }
+      } $b($can_read,$can_write)
+    }
+    catch { db close }
+  }
+}
+
 finish_test