Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/ext/recover/recovercorrupt.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / ext / recover / recovercorrupt.test` 67 lines ยท 1686 bytes Raw Blame History 1 # 2022 August 28 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 recovercorrupt 15 16 database_may_be_corrupt 17 18 do_execsql_test 1.0 { 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)); 27 ANALYZE; 28 PRAGMA writable_schema = 1; 29 DELETE FROM sqlite_schema WHERE name='t2'; 30 } 31 32 do_test 1.1 { 33 expr [file size test.db]>3072 34 } {1} 35 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 42 } 43 44 45 db_save_and_close 46 for {set ii 0} {$ii < 10000} {incr ii} { 47 db_restore_and_reopen 48 db func toggle_bit toggle_bit 49 set bitsperpage [expr 512*8] 50 51 set pg [expr {($ii / $bitsperpage)+1}] 52 set byte [expr {$ii % $bitsperpage}] 53 db eval { 54 UPDATE sqlite_dbpage SET data = toggle_bit(data, $byte) WHERE pgno=$pg 55 } 56 57 set R [sqlite3_recover_init db main test.db2] 58 $R config lostandfound lost_and_found 59 $R run 60 do_test 1.2.$ii { 61 $R finish 62 } {} 63 } 64 65 66 finish_test 67