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 # Test that "PRAGMA incremental_vacuum" detects and reports database
12 # corruption properly. And that "PRAGMA auto_vacuum = INCREMENTAL"
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 set testprefix incrcorrupt
20 # If this build of the library does not support auto-vacuum, omit this
22 ifcapable {!autovacuum} {
28 PRAGMA auto_vacuum = 2;
29 CREATE TABLE t1(a PRIMARY KEY, b);
32 SELECT 1 UNION ALL SELECT i+1 FROM data
34 INSERT INTO t1 SELECT i, randomblob(600) FROM data LIMIT 20;
39 PRAGMA incremental_vacuum;
44 hexio_write test.db 36 00000019
45 catchsql { PRAGMA incremental_vacuum; }
46 } {1 {database disk image is malformed}}
49 set stmt [sqlite3_prepare_v2 db "PRAGMA incremental_vacuum" -1 dummy]
52 do_test 1.4 { sqlite3_errcode db } {SQLITE_CORRUPT}
53 do_test 1.5 { sqlite3_errmsg db } {database disk image is malformed}
54 do_test 1.6 { sqlite3_finalize $stmt } {SQLITE_CORRUPT}
55 do_test 1.7 { sqlite3_errcode db } {SQLITE_CORRUPT}
56 do_test 1.8 { sqlite3_errmsg db } {database disk image is malformed}
59 set stmt [sqlite3_prepare_v2 db "PRAGMA incremental_vacuum" -1 dummy]
62 do_test 1.10 { sqlite3_errcode db } {SQLITE_CORRUPT}
63 do_test 1.11 { sqlite3_errmsg db } {database disk image is malformed}
66 set stmt2 [sqlite3_prepare_v2 db "SELECT 1" -1 dummy]
67 sqlite3_finalize $stmt2
69 do_test 1.13 { sqlite3_errcode db } {SQLITE_OK}
70 do_test 1.14 { sqlite3_errmsg db } {not an error}
72 do_test 1.15 { sqlite3_finalize $stmt } {SQLITE_CORRUPT}
73 do_test 1.16 { sqlite3_errcode db } {SQLITE_CORRUPT}
74 do_test 1.17 { sqlite3_errmsg db } {database disk image is malformed}
76 #-------------------------------------------------------------------------
81 PRAGMA auto_vacuum = 1;
82 CREATE TABLE t1(a PRIMARY KEY, b);
84 SELECT 1 UNION ALL SELECT i+1 FROM data
86 INSERT INTO t1 SELECT i, randomblob(600) FROM data LIMIT 20;
92 set fd [open test.db r+]
93 chan truncate $fd [expr 22*1024]
95 catchsql { PRAGMA incremental_vacuum; }
96 } {1 {database disk image is malformed}}
99 set stmt [sqlite3_prepare_v2 db "PRAGMA auto_vacuum = INCREMENTAL" -1 dummy]
102 do_test 2.4 { sqlite3_errcode db } {SQLITE_CORRUPT}
103 do_test 2.5 { sqlite3_errmsg db } {database disk image is malformed}
104 do_test 2.6 { sqlite3_finalize $stmt } {SQLITE_CORRUPT}
105 do_test 2.7 { sqlite3_errcode db } {SQLITE_CORRUPT}
106 do_test 2.8 { sqlite3_errmsg db } {database disk image is malformed}
109 set stmt [sqlite3_prepare_v2 db "PRAGMA auto_vacuum = INCREMENTAL" -1 dummy]
112 do_test 2.10 { sqlite3_errcode db } {SQLITE_CORRUPT}
113 do_test 2.11 { sqlite3_errmsg db } {database disk image is malformed}
116 set stmt2 [sqlite3_prepare_v2 db "SELECT 1" -1 dummy]
117 sqlite3_finalize $stmt2
119 do_test 2.13 { sqlite3_errcode db } {SQLITE_OK}
120 do_test 2.14 { sqlite3_errmsg db } {not an error}
122 do_test 2.15 { sqlite3_finalize $stmt } {SQLITE_CORRUPT}
123 do_test 2.16 { sqlite3_errcode db } {SQLITE_CORRUPT}
124 do_test 2.17 { sqlite3_errmsg db } {database disk image is malformed}