blob: c7a4381341741db00f2f2a026a4230f48b543b79 [file] [log] [blame]
drh32f29642010-07-01 19:45:34 +00001# 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
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17source $testdir/malloc_common.tcl
18ifcapable !wal {finish_test ; return }
19
20do_test wal4-1.1 {
dan250ea1a2010-07-16 11:10:25 +000021 execsql {
drh32f29642010-07-01 19:45:34 +000022 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}
dan250ea1a2010-07-16 11:10:25 +000029
drh32f29642010-07-01 19:45:34 +000030do_test wal4-1.2 {
dan250ea1a2010-07-16 11:10:25 +000031 # Save a copy of the file-system containing the wal and wal-index files
32 # only (no database file).
33 faultsim_save_and_close
mistachkinfda06be2011-08-02 00:57:34 +000034 forcedelete sv_test.db
dan250ea1a2010-07-16 11:10:25 +000035} {}
36
37do_test wal4-1.3 {
38 faultsim_restore_and_reopen
39 catchsql { SELECT * FROM t1 }
drh32f29642010-07-01 19:45:34 +000040} {1 {no such table: t1}}
41
dan250ea1a2010-07-16 11:10:25 +000042do_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 {}}
drh32f29642010-07-01 19:45:34 +000050
dan250ea1a2010-07-16 11:10:25 +000051 # 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}
drh32f29642010-07-01 19:45:34 +000063
64finish_test