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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
# 2017 August 10
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# 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.
#
#***********************************************************************
#
# The tests in this file focus on testing the fts5vocab module.
#
source [file join [file dirname [info script]] fts5_common.tcl]
set testprefix fts5vocab2
# If SQLITE_ENABLE_FTS5 is defined, omit this file.
ifcapable !fts5 {
finish_test
return
}
do_execsql_test 1.0 {
CREATE VIRTUAL TABLE t1 USING fts5(a, b);
CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
INSERT INTO t1 VALUES('one two', 'two three');
INSERT INTO t1 VALUES('three four', 'four five five five');
}
do_execsql_test 1.1 {
SELECT * FROM v1;
} {
five 2 b 1
five 2 b 2
five 2 b 3
four 2 a 1
four 2 b 0
one 1 a 0
three 1 b 1
three 2 a 0
two 1 a 1
two 1 b 0
}
do_execsql_test 1.2 {
SELECT * FROM v1 WHERE term='three';
} {
three 1 b 1
three 2 a 0
}
do_execsql_test 1.3 {
BEGIN;
DELETE FROM t1 WHERE rowid=2;
SELECT * FROM v1;
ROLLBACK;
} {
one 1 a 0
three 1 b 1
two 1 a 1
two 1 b 0
}
do_execsql_test 1.4 {
BEGIN;
DELETE FROM t1 WHERE rowid=1;
SELECT * FROM v1;
ROLLBACK;
} {
five 2 b 1
five 2 b 2
five 2 b 3
four 2 a 1
four 2 b 0
three 2 a 0
}
do_execsql_test 1.5 {
DELETE FROM t1;
SELECT * FROM v1;
} {}
#-------------------------------------------------------------------------
#
do_execsql_test 2.0 {
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS v1;
CREATE VIRTUAL TABLE t1 USING fts5(a, b, detail=column);
CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
INSERT INTO t1 VALUES('one two', 'two three');
INSERT INTO t1 VALUES('three four', 'four five five five');
}
do_execsql_test 2.1 {
SELECT * FROM v1;
} {
five 2 b {}
four 2 a {}
four 2 b {}
one 1 a {}
three 1 b {}
three 2 a {}
two 1 a {}
two 1 b {}
}
do_execsql_test 2.2 {
SELECT * FROM v1 WHERE term='three';
} {
three 1 b {}
three 2 a {}
}
do_execsql_test 2.3 {
BEGIN;
DELETE FROM t1 WHERE rowid=2;
SELECT * FROM v1;
ROLLBACK;
} {
one 1 a {}
three 1 b {}
two 1 a {}
two 1 b {}
}
do_execsql_test 2.4 {
BEGIN;
DELETE FROM t1 WHERE rowid=1;
SELECT * FROM v1;
ROLLBACK;
} {
five 2 b {}
four 2 a {}
four 2 b {}
three 2 a {}
}
do_execsql_test 2.5 {
DELETE FROM t1;
SELECT * FROM v1;
} {}
#-------------------------------------------------------------------------
#
do_execsql_test 3.0 {
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS v1;
CREATE VIRTUAL TABLE t1 USING fts5(a, b, detail=none);
CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
INSERT INTO t1 VALUES('one two', 'two three');
INSERT INTO t1 VALUES('three four', 'four five five five');
}
do_execsql_test 3.1 {
SELECT * FROM v1;
} {
five 2 {} {}
four 2 {} {}
one 1 {} {}
three 1 {} {}
three 2 {} {}
two 1 {} {}
}
do_execsql_test 3.2 {
SELECT * FROM v1 WHERE term='three';
} {
three 1 {} {}
three 2 {} {}
}
do_execsql_test 3.3 {
BEGIN;
DELETE FROM t1 WHERE rowid=2;
SELECT * FROM v1;
ROLLBACK;
} {
one 1 {} {}
three 1 {} {}
two 1 {} {}
}
do_execsql_test 3.4 {
BEGIN;
DELETE FROM t1 WHERE rowid=1;
SELECT * FROM v1;
ROLLBACK;
} {
five 2 {} {}
four 2 {} {}
three 2 {} {}
}
do_execsql_test 3.5 {
DELETE FROM t1;
SELECT * FROM v1;
} {}
#-------------------------------------------------------------------------
#
reset_db
do_execsql_test 4.0 {
CREATE VIRTUAL TABLE v1 USING fts5vocab(nosuchtable, col);
}
do_catchsql_test 4.1 {
SELECT * FROM v1 WHERE term=='nosuchterm';
} {1 {no such fts5 table: main.nosuchtable}}
do_execsql_test 4.2.1 {
CREATE TABLE nosuchtable(nosuchtable, y, z);
}
do_catchsql_test 4.2.2 {
SELECT * FROM v1 WHERE term=='nosuchterm';
} {1 {no such fts5 table: main.nosuchtable}}
ifcapable fts3 {
do_execsql_test 4.3.1 {
DROP TABLE nosuchtable;
CREATE VIRTUAL TABLE nosuchtable USING fts3(a, b);
} {}
do_catchsql_test 4.3.2 {
SELECT * FROM v1 WHERE term=='nosuchterm';
} {1 {no such fts5 table: main.nosuchtable}}
do_catchsql_test 4.3.3 {
INSERT INTO nosuchtable VALUES('id', '*id');
SELECT * FROM v1 WHERE term=='nosuchterm';
} {1 {no such fts5 table: main.nosuchtable}}
}
#-------------------------------------------------------------------------
# Check that the fts5 table cannot be written while there are vocab
# cursors open.
reset_db
do_execsql_test 5.0 {
CREATE VIRTUAL TABLE t1 USING fts5(a);
CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
INSERT INTO t1 VALUES('one'), ('two'), ('three'), ('four');
}
do_test 5.1 {
list [catch {
db eval { SELECT * FROM v1 } {
db eval {INSERT INTO t1 VALUES('five')}
}
} msg] $msg
} {1 {query aborted}}
do_execsql_test 5.2 {
SELECT * FROM t1
} {one two three four five}
#-------------------------------------------------------------------------
# Check that the fts5 table cannot be written while there are vocab
# cursors open.
reset_db
do_execsql_test 5.0 {
CREATE VIRTUAL TABLE t1 USING fts5(a);
CREATE VIRTUAL TABLE v1 USING fts5vocab(t1, instance);
WITH s(i) AS (
VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<10000
)
INSERT INTO t1 SELECT
'State Emergency Service (SES), Rural Fire Service (RFS) and Volunteers'
FROM s;
}
do_catchsql_test 5.1 {
INSERT INTO t1 SELECT rowid FROM v1
} {1 {query aborted}}
do_catchsql_test 5.2 {
DELETE FROM t1 WHERE rowid>100;
INSERT INTO t1 SELECT randomblob(3000) FROM v1
} {1 {query aborted}}
finish_test
|