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/recoverfault.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 / recoverfault.test` 84 lines ยท 2152 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 recoverfault 15 16 17 #-------------------------------------------------------------------------- 18 proc compare_result {db1 db2 sql} { 19 set r1 [$db1 eval $sql] 20 set r2 [$db2 eval $sql] 21 if {$r1 != $r2} { 22 puts "r1: $r1" 23 puts "r2: $r2" 24 error "mismatch for $sql" 25 } 26 return "" 27 } 28 29 proc compare_dbs {db1 db2} { 30 compare_result $db1 $db2 "SELECT sql FROM sqlite_master ORDER BY 1" 31 foreach tbl [$db1 eval {SELECT name FROM sqlite_master WHERE type='table'}] { 32 compare_result $db1 $db2 "SELECT * FROM $tbl" 33 } 34 } 35 #-------------------------------------------------------------------------- 36 37 do_execsql_test 1.0 { 38 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); 39 INSERT INTO t1 VALUES(1, 2, 3); 40 INSERT INTO t1 VALUES(2, hex(randomblob(1000)), randomblob(2000)); 41 CREATE INDEX i1 ON t1(b, c); 42 ANALYZE; 43 } 44 faultsim_save_and_close 45 46 do_faultsim_test 1 -faults oom* -prep { 47 catch { db2 close } 48 faultsim_restore_and_reopen 49 } -body { 50 set R [sqlite3_recover_init db main test.db2] 51 $R run 52 $R finish 53 } -test { 54 faultsim_test_result {0 {}} {1 {}} 55 if {$testrc==0} { 56 sqlite3 db2 test.db2 57 compare_dbs db db2 58 db2 close 59 } 60 } 61 62 faultsim_restore_and_reopen 63 do_execsql_test 2.0 { 64 CREATE TABLE t2(a INTEGER PRIMARY KEY, b, c); 65 INSERT INTO t2 VALUES(1, 2, 3); 66 INSERT INTO t2 VALUES(2, hex(randomblob(1000)), hex(randomblob(2000))); 67 PRAGMA writable_schema = 1; 68 DELETE FROM sqlite_schema WHERE name='t2'; 69 } 70 faultsim_save_and_close 71 72 do_faultsim_test 2 -faults oom* -prep { 73 faultsim_restore_and_reopen 74 } -body { 75 set R [sqlite3_recover_init db main test.db2] 76 $R config lostandfound lost_and_found 77 $R run 78 $R finish 79 } -test { 80 faultsim_test_result {0 {}} {1 {}} 81 } 82 83 finish_test 84