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 / session / sessioncorrupt.test
| 1 | # 2026 August 17 |
| 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 | if {![info exists testdir]} { |
| 14 | set testdir [file join [file dirname [info script]] .. .. test] |
| 15 | } |
| 16 | source [file join [file dirname [info script]] session_common.tcl] |
| 17 | source $testdir/tester.tcl |
| 18 | ifcapable !session {finish_test; return} |
| 19 | |
| 20 | set testprefix sessioncorrupt |
| 21 | |
| 22 | |
| 23 | set C [db one {SELECT unhex(' |
| 24 | 5402 0100 7400 1700 0100 0000 0000 0000 |
| 25 | 0103 036f 6c64 0003 036e 6577 5440 0100 |
| 26 | 0000 0000 0000 0000 0000 0000 0000 0000 |
| 27 | 0000 0000 0000 0000 0000 0000 0000 0000 |
| 28 | 0000 0000 0000 0000 0000 0000 0000 0000 |
| 29 | 0000 0000 0000 0000 0000 0000 0000 7400 |
| 30 | 1700 0100 0000 0000 0000 0100 0000 0000 |
| 31 | 0000 0000 0000 0000 0000 0000 0000 0000 |
| 32 | 0000 0000 0000 0000 0000 0000 0000 0000 |
| 33 | 0000 0000 0000 0000 0000 0000 0000 0000 |
| 34 | 0000 0000 0000 0000 0000 0000 0000 0000 |
| 35 | 0000 0000 0000 0000 0000 0000 0000 0000 |
| 36 | 0000 0000 0000 0000 0000 0000 0000 0000 |
| 37 | 0000 0000 0000 0000 0000 0000 0000 0000 |
| 38 | 0000 0000 0000 0000 0001 0000 0000 0000 |
| 39 | 0002 |
| 40 | ', char(0x20,0x0a,0x0d))}] |
| 41 | |
| 42 | do_test 1.0 { string length $C } 242 |
| 43 | |
| 44 | do_execsql_test 1.1 { |
| 45 | CREATE TABLE t(id INTEGER PRIMARY KEY, v TEXT); |
| 46 | INSERT INTO t VALUES(1, 'old'); |
| 47 | } |
| 48 | |
| 49 | proc xConflict {args} { return "OMIT" } |
| 50 | |
| 51 | do_test 1.2 { |
| 52 | sqlite3changeset_apply db $C xConflict |
| 53 | } {} |
| 54 | |
| 55 | #------------------------------------------------------------------------- |
| 56 | # An UPDATE change with an undefined old.* PK value is corrupt. Even if |
| 57 | # it follows an UPDATE that uses the same cached UPDATE statement. |
| 58 | # |
| 59 | reset_db |
| 60 | do_execsql_test 2.0 { |
| 61 | CREATE TABLE x(a INTEGER PRIMARY KEY, b TEXT, c TEXT); |
| 62 | INSERT INTO x VALUES(1, 'same', 'one'), (2, 'same', 'two'); |
| 63 | } |
| 64 | |
| 65 | set C [db one {SELECT unhex( |
| 66 | '5403010000' || hex('x') || '00' || |
| 67 | '1700' || '010000000000000002' || '0304' || hex('same') || '00' || |
| 68 | '00' || '0304' || hex('same') || '00' || |
| 69 | '1700' || '00' || '0304' || hex('same') || '00' || |
| 70 | '00' || '0309' || hex('second-ok') || '00' |
| 71 | )}] |
| 72 | |
| 73 | do_test 2.1 { |
| 74 | list [catch { sqlite3changeset_apply db $C xConflict } msg] $msg |
| 75 | } {1 SQLITE_CORRUPT} |
| 76 | |
| 77 | do_execsql_test 2.2 { |
| 78 | SELECT * FROM x |
| 79 | } {1 same one 2 same two} |
| 80 | |
| 81 | finish_test |