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
14source [file join [file dirname [info script]] fts5_common.tcl]
15set testprefix fts5corrupt4
16
17# If SQLITE_ENABLE_FTS5 is defined, omit this file.
18ifcapable !fts5 {
19  finish_test
20  return
21}
22sqlite3_fts5_may_be_corrupt 1
23
24do_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
32expr srand(1)
33
34proc 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}
41db func mutate mutate
42
43for {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
61sqlite3_fts5_may_be_corrupt 0
62finish_test
63
64