1 # 2010 July 1 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 # Verify that an empty database and a non-empty WAL file do not 12 # result in database corruption 13 # 14 15 set testdir [file dirname $argv0] 16 source $testdir/tester.tcl 17 source $testdir/malloc_common.tcl 18 ifcapable !wal {finish_test ; return } 19 20 do_test wal4-1.1 { 21 execsql { 22 PRAGMA journal_mode=WAL; 23 CREATE TABLE t1(x); 24 INSERT INTO t1 VALUES(1); 25 INSERT INTO t1 VALUES(2); 26 SELECT x FROM t1 ORDER BY x; 27 } 28 } {wal 1 2} 29 30 do_test wal4-1.2 { 31 # Save a copy of the file-system containing the wal and wal-index files 32 # only (no database file). 33 faultsim_save_and_close 34 file delete -force sv_test.db 35 } {} 36 37 do_test wal4-1.3 { 38 faultsim_restore_and_reopen 39 catchsql { SELECT * FROM t1 } 40 } {1 {no such table: t1}} 41 42 do_faultsim_test wal4-2 -prep { 43 faultsim_restore_and_reopen 44 } -body { 45 execsql { SELECT name FROM sqlite_master } 46 } -test { 47 # Result should be zero rows (empty db file). 48 # 49 faultsim_test_result {0 {}} 50 51 # If the SELECT finished successfully, the WAL file should have been 52 # deleted. In no case should the database file have been written, so 53 # it should still be zero bytes in size regardless of whether or not 54 # a fault was injected. Test these assertions: 55 # 56 if { $testrc==0 && [file exists test.db-wal] } { 57 error "Wal file was not deleted" 58 } 59 if { [file size test.db]!=0 } { 60 error "Db file grew to [file size test.db] bytes" 61 } 62 } 63 64 finish_test 65