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/recoverfault2.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 / recoverfault2.test` 102 lines ยท 2329 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 recoverfault2 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); 39 INSERT INTO t1 VALUES(2, '\012hello\015world\012today\n'); 40 " 41 faultsim_save_and_close 42 43 proc my_sql_hook {sql} { 44 lappend ::lSql $sql 45 return 0 46 } 47 48 do_faultsim_test 1 -faults oom* -prep { 49 catch { db2 close } 50 faultsim_restore_and_reopen 51 set ::lSql [list] 52 } -body { 53 set R [sqlite3_recover_init_sql db main my_sql_hook] 54 $R run 55 $R finish 56 } -test { 57 faultsim_test_result {0 {}} {1 {}} 58 if {$testrc==0} { 59 sqlite3 db2 "" 60 db2 eval [join $::lSql ";"] 61 compare_dbs db db2 62 db2 close 63 } 64 } 65 66 ifcapable utf16 { 67 reset_db 68 do_execsql_test 2.0 " 69 PRAGMA encoding='utf-16'; 70 CREATE TABLE t1(a INTEGER PRIMARY KEY, b); 71 INSERT INTO t1 VALUES(2, '\012hello\015world\012today\n'); 72 " 73 faultsim_save_and_close 74 75 proc my_sql_hook {sql} { 76 lappend ::lSql $sql 77 return 0 78 } 79 80 do_faultsim_test 2 -faults oom-t* -prep { 81 catch { db2 close } 82 faultsim_restore_and_reopen 83 set ::lSql [list] 84 } -body { 85 set R [sqlite3_recover_init_sql db main my_sql_hook] 86 $R run 87 $R finish 88 } -test { 89 faultsim_test_result {0 {}} {1 {}} 90 if {$testrc==0} { 91 sqlite3 db2 "" 92 db2 eval [join $::lSql ";"] 93 compare_dbs db db2 94 db2 close 95 } 96 } 97 } 98 99 100 101 finish_test 102