Debian Codegraph @

ext/recover/recovercorrupt4.test

raw
1 # 2024 May 15
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 #
12
13 source [file join [file dirname [info script]] recover_common.tcl]
14 set testprefix recovercorrupt4
15
16 database_may_be_corrupt
17
18 if {[permutation]!="inmemory_journal"} {
19 # This test cannot be run with the inmemory_journal permutation, as it
20 # must open a truncated, corrupt, database file. With the inmemory_journal
21 # permutation, this fails (SQLITE_CORRUPT error) when the [sqlite3] wrapper
22 # executes "PRAGMA journal_mode = memory".
23 do_execsql_test 1.0 {
24 CREATE TABLE rows(indexed INTEGER NOT NULL, unindexed INTEGER NOT NULL, filler BLOB NOT NULL DEFAULT 13);
25 -- CREATE UNIQUE INDEX rows_index ON rows(indexed);
26 INSERT INTO rows(indexed, unindexed, filler) VALUES(1, 1, x'31');
27 INSERT INTO rows(indexed, unindexed, filler) VALUES(2, 2, x'32');
28 INSERT INTO rows(indexed, unindexed, filler) VALUES(4, 4, x'34');
29 INSERT INTO rows(indexed, unindexed, filler) VALUES(8, 8, randomblob(2048));
30 }
31
32 db close
33
34 do_test 1.1 {
35 set sz [expr [file size test.db] - 1024]
36 set fd [open test.db]
37 fconfigure $fd -translation binary
38
39 set data [read $fd $sz]
40 set fd2 [open test.db2 w]
41 fconfigure $fd2 -translation binary
42 puts -nonewline $fd2 $data
43 close $fd2
44 set {} {}
45 } {}
46
47 do_test 1.2 {
48 forcedelete test.db3
49 sqlite3 db test.db2
50 set R [sqlite3_recover_init db main test.db3]
51 $R run
52 $R finish
53 } {}
54
55 do_test 1.3 {
56 sqlite3 db test.db3
57 execsql {
58 SELECT indexed, unindexed FROM rows
59 }
60 } {1 1 2 2 4 4 8 8}
61 }
62
63 finish_test