summaryrefslogtreecommitdiffstats
path: root/test/fts4intck1.test
blob: 6596b2f99726fcf5aa887447d4dc81080221e2aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# 2023-10-23
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# 
# Test PRAGMA integrity_check against and FTS3/FTS4 table.
#


set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !fts3 { finish_test ; return }

set ::testprefix fts4intck1

proc slang {in} {
  return [string map {th d e eh} $in]
}

db function slang -deterministic -innocuous slang
do_execsql_test 1.0 {
  CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c TEXT AS (slang(b)));
  INSERT INTO t1(b) VALUES('the quick fox jumps over the lazy brown dog');
  SELECT c FROM t1;
} {{deh quick fox jumps ovehr deh lazy brown dog}}

do_execsql_test 1.1 {
  CREATE VIRTUAL TABLE t2 USING fts4(content="t1", c);
  INSERT INTO t2(t2) VALUES('rebuild');
  SELECT docid FROM t2 WHERE t2 MATCH 'deh';
} {1}

do_execsql_test 1.2 {
  PRAGMA integrity_check(t2);
} {ok}

db close
sqlite3 db test.db
do_execsql_test 2.1 {
  PRAGMA integrity_check(t2);
} {{unable to validate the inverted index for FTS4 table main.t2: SQL logic error}}

db function slang -deterministic -innocuous slang
do_execsql_test 2.2 {
  PRAGMA integrity_check(t2);
} {ok}

proc slang {in} {return $in}
do_execsql_test 2.3 {
  PRAGMA integrity_check(t2);
} {{malformed inverted index for FTS4 table main.t2}}

#-------------------------------------------------------------------------
# Test that integrity-check works on a read-only database.
#
reset_db
do_execsql_test 3.0 {
  CREATE VIRTUAL TABLE x1 USING fts4(a, b);
  INSERT INTO x1 VALUES('one', 'two');
  INSERT INTO x1 VALUES('three', 'four');
}
db close
sqlite3 db test.db -readonly 1

do_execsql_test 3.1 {
  PRAGMA integrity_check;
} {ok}



finish_test