interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

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
13source [file join [file dirname [info script]] recover_common.tcl]
14set testprefix recovercorrupt
15
16database_may_be_corrupt
17
18do_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
32do_test 1.1 {
33 expr [file size test.db]>3072
34} {1}
35
36proc 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
45db_save_and_close
46for {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
66finish_test
67