3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # Verify that an empty database and a non-empty WAL file do not
12 # result in database corruption
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 source $testdir/malloc_common.tcl
18 ifcapable !wal {finish_test ; return }
22 PRAGMA journal_mode=WAL;
24 INSERT INTO t1 VALUES(1);
25 INSERT INTO t1 VALUES(2);
26 SELECT x FROM t1 ORDER BY x;
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 forcedelete sv_test.db
38 faultsim_restore_and_reopen
39 catchsql { SELECT * FROM t1 }
40 } {1 {no such table: t1}}
42 do_faultsim_test wal4-2 -prep {
43 faultsim_restore_and_reopen
45 execsql { SELECT name FROM sqlite_master }
47 # Result should be zero rows (empty db file).
49 faultsim_test_result {0 {}}
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:
56 if { $testrc==0 && [file exists test.db-wal] } {
57 error "Wal file was not deleted"
59 if { [file size test.db]!=0 } {
60 error "Db file grew to [file size test.db] bytes"