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 / fts5 / test / fts5corrupt4.test
| 1 | # 2019 May 16 |
| 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 | |
| 14 | source [file join [file dirname [info script]] fts5_common.tcl] |
| 15 | set testprefix fts5corrupt4 |
| 16 | |
| 17 | # If SQLITE_ENABLE_FTS5 is not defined, omit this file. |
| 18 | ifcapable !fts5 { |
| 19 | finish_test |
| 20 | return |
| 21 | } |
| 22 | sqlite3_fts5_may_be_corrupt 1 |
| 23 | |
| 24 | do_execsql_test 1.0 { |
| 25 | CREATE VIRTUAL TABLE ttt USING fts5(a, b); |
| 26 | INSERT INTO ttt |
| 27 | VALUES('e ee eee e ee eee e ee eee', 'eee ee e e e ee eee ee ee'); |
| 28 | INSERT INTO ttt SELECT a||a, b||b FROM ttt; |
| 29 | INSERT INTO ttt SELECT a||a, b||b FROM ttt; |
| 30 | } |
| 31 | |
| 32 | expr srand(1) |
| 33 | |
| 34 | proc mutate {blob i} { |
| 35 | set o [expr {$i % [string length $blob]}] |
| 36 | set a [string range $blob 0 $o-1] |
| 37 | set b [string range $blob $o+1 end] |
| 38 | set v [expr int(rand()*255) - 127] |
| 39 | return "$a[binary format c $v]$b" |
| 40 | } |
| 41 | db func mutate mutate |
| 42 | |
| 43 | for {set j 1000} {$j <= 5000} {incr j 1000} { |
| 44 | do_test 1.$j { |
| 45 | for {set i 0} {$i < 1000} {incr i} { |
| 46 | execsql { |
| 47 | BEGIN; |
| 48 | UPDATE ttt_data SET block = mutate(block, $i) WHERE id>10; |
| 49 | } |
| 50 | foreach sql { |
| 51 | {SELECT snippet(ttt, -1, '.', '..', '[', ']'), * FROM ttt('e*')} |
| 52 | {SELECT snippet(ttt, -1, '.', '..', '[', ']'), * FROM ttt('e* NOT ee*')} |
| 53 | } { |
| 54 | catch { execsql $sql } |
| 55 | } |
| 56 | execsql ROLLBACK |
| 57 | } |
| 58 | } {} |
| 59 | } |
| 60 | |
| 61 | sqlite3_fts5_may_be_corrupt 0 |
| 62 | finish_test |
| 63 |