sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
sqlite / ext / recover / recoverpgsz.test
| 1 | # 2022 October 14 |
| 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 | |
| 15 | db close |
| 16 | sqlite3_test_control_pending_byte 0x1000000 |
| 17 | |
| 18 | set testprefix recoverpgsz |
| 19 | |
| 20 | foreach {pgsz bOverflow} { |
| 21 | 512 0 1024 0 2048 0 4096 0 8192 0 16384 0 32768 0 65536 0 |
| 22 | 512 1 1024 1 2048 1 4096 1 8192 1 16384 1 32768 1 65536 1 |
| 23 | } { |
| 24 | reset_db |
| 25 | execsql "PRAGMA page_size = $pgsz" |
| 26 | execsql "PRAGMA auto_vacuum = 0" |
| 27 | do_execsql_test 1.$pgsz.$bOverflow.1 { |
| 28 | CREATE TABLE t1(a, b, c); |
| 29 | CREATE INDEX i1 ON t1(b, a, c); |
| 30 | INSERT INTO t1(a, b) VALUES(1, 2), (3, 4), (5, 6); |
| 31 | DELETE FROM t1 WHERE a=3; |
| 32 | } |
| 33 | if {$bOverflow} { |
| 34 | do_execsql_test 1.$pgsz.$bOverflow.1a { |
| 35 | UPDATE t1 SET c = randomblob(100000); |
| 36 | } |
| 37 | } |
| 38 | db close |
| 39 | |
| 40 | |
| 41 | set fd [open test.db] |
| 42 | fconfigure $fd -translation binary |
| 43 | seek $fd $pgsz |
| 44 | set pg1 [read $fd $pgsz] |
| 45 | set pg2 [read $fd $pgsz] |
| 46 | close $fd |
| 47 | |
| 48 | set fd2 [open test.db2 w] |
| 49 | fconfigure $fd2 -translation binary |
| 50 | seek $fd2 $pgsz |
| 51 | puts -nonewline $fd2 $pg1 |
| 52 | close $fd2 |
| 53 | |
| 54 | sqlite3 db2 test.db2 |
| 55 | do_test 1.$pgsz.$bOverflow.2 { |
| 56 | set R [sqlite3_recover_init db2 main test.db3] |
| 57 | $R run |
| 58 | $R finish |
| 59 | } {} |
| 60 | |
| 61 | sqlite3 db3 test.db3 |
| 62 | do_test 1.$pgsz.$bOverflow.3 { |
| 63 | db3 eval { SELECT * FROM sqlite_schema } |
| 64 | db3 eval { PRAGMA page_size } |
| 65 | } $pgsz |
| 66 | |
| 67 | db2 close |
| 68 | db3 close |
| 69 | |
| 70 | forcedelete test.db3 |
| 71 | forcedelete test.db2 |
| 72 | |
| 73 | set fd2 [open test.db2 w] |
| 74 | fconfigure $fd2 -translation binary |
| 75 | seek $fd2 $pgsz |
| 76 | puts -nonewline $fd2 $pg2 |
| 77 | close $fd2 |
| 78 | |
| 79 | sqlite3 db2 test.db2 |
| 80 | do_test 1.$pgsz.$bOverflow.4 { |
| 81 | set R [sqlite3_recover_init db2 main test.db3] |
| 82 | $R run |
| 83 | $R finish |
| 84 | } {} |
| 85 | |
| 86 | sqlite3 db3 test.db3 |
| 87 | do_test 1.$pgsz.$bOverflow.5 { |
| 88 | db3 eval { SELECT * FROM sqlite_schema } |
| 89 | db3 eval { PRAGMA page_size } |
| 90 | } $pgsz |
| 91 | |
| 92 | db2 close |
| 93 | db3 close |
| 94 | } |
| 95 | |
| 96 | |
| 97 | finish_test |