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 #***********************************************************************
13 source [file join [file dirname [info script]] recover_common.tcl]
14 set testprefix recovercorrupt
16 database_may_be_corrupt
19 PRAGMA page_size = 512;
20 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
21 INSERT INTO t1 VALUES(1, 2, 3);
22 INSERT INTO t1 VALUES(2, hex(randomblob(100)), randomblob(200));
23 CREATE INDEX i1 ON t1(b, c);
24 CREATE TABLE t2(a PRIMARY KEY, b, c) WITHOUT ROWID;
25 INSERT INTO t2 VALUES(1, 2, 3);
26 INSERT INTO t2 VALUES(2, hex(randomblob(100)), randomblob(200));
28 PRAGMA writable_schema = 1;
29 DELETE FROM sqlite_schema WHERE name='t2';
33 expr [file size test.db]>3072
36 proc toggle_bit {blob bit} {
37 set byte [expr {$bit / 8}]
38 set bit [expr {$bit & 0x0F}]
39 binary scan $blob a${byte}ca* A x B
40 set x [expr {$x ^ (1 << $bit)}]
41 binary format a*ca* $A $x $B
46 for {set ii 0} {$ii < 10000} {incr ii} {
48 db func toggle_bit toggle_bit
49 set bitsperpage [expr 512*8]
51 set pg [expr {($ii / $bitsperpage)+1}]
52 set byte [expr {$ii % $bitsperpage}]
54 UPDATE sqlite_dbpage SET data = toggle_bit(data, $byte) WHERE pgno=$pg
57 set R [sqlite3_recover_init db main test.db2]
58 $R config lostandfound lost_and_found