interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / fts4intck1.test

75 lines · 1842 bytes Raw Blame History
1# 2023-10-23
2#
3# May you do good and not evil.
4# May you find forgiveness for yourself and forgive others.
5# May you share freely, never taking more than you give.
6#
7#***********************************************************************
8#
9# Test PRAGMA integrity_check against and FTS3/FTS4 table.
10#
11
12
13set testdir [file dirname $argv0]
14source $testdir/tester.tcl
15
16ifcapable !fts3 { finish_test ; return }
17
18set ::testprefix fts4intck1
19
20proc slang {in} {
21 return [string map {th d e eh} $in]
22}
23
24db function slang -deterministic -innocuous slang
25do_execsql_test 1.0 {
26 CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c TEXT AS (slang(b)));
27 INSERT INTO t1(b) VALUES('the quick fox jumps over the lazy brown dog');
28 SELECT c FROM t1;
29} {{deh quick fox jumps ovehr deh lazy brown dog}}
30
31do_execsql_test 1.1 {
32 CREATE VIRTUAL TABLE t2 USING fts4(content="t1", c);
33 INSERT INTO t2(t2) VALUES('rebuild');
34 SELECT docid FROM t2 WHERE t2 MATCH 'deh';
35} {1}
36
37do_execsql_test 1.2 {
38 PRAGMA integrity_check(t2);
39} {ok}
40
41db close
42sqlite3 db test.db
43do_execsql_test 2.1 {
44 PRAGMA integrity_check(t2);
45} {{unable to validate the inverted index for FTS4 table main.t2: SQL logic error}}
46
47db function slang -deterministic -innocuous slang
48do_execsql_test 2.2 {
49 PRAGMA integrity_check(t2);
50} {ok}
51
52proc slang {in} {return $in}
53do_execsql_test 2.3 {
54 PRAGMA integrity_check(t2);
55} {{malformed inverted index for FTS4 table main.t2}}
56
57#-------------------------------------------------------------------------
58# Test that integrity-check works on a read-only database.
59#
60reset_db
61do_execsql_test 3.0 {
62 CREATE VIRTUAL TABLE x1 USING fts4(a, b);
63 INSERT INTO x1 VALUES('one', 'two');
64 INSERT INTO x1 VALUES('three', 'four');
65}
66db close
67sqlite3 db test.db -readonly 1
68
69do_execsql_test 3.1 {
70 PRAGMA integrity_check;
71} {ok}
72
73
74
75finish_test