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 / ext / fts5 / test / fts5config.test

265 lines · 7589 bytes Raw Blame History
1# 2015 Jan 13
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# This file focuses on the code in fts5_config.c, which is largely concerned
13# with parsing the various configuration and CREATE TABLE options.
14#
15
16source [file join [file dirname [info script]] fts5_common.tcl]
17set testprefix fts5config
18
19# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
20ifcapable !fts5 {
21 finish_test
22 return
23}
24
25#-------------------------------------------------------------------------
26# Try different types of quote characters.
27#
28do_execsql_test 1.0 {
29 CREATE VIRTUAL TABLE t1 USING fts5('a', "b", [c], `d`);
30 PRAGMA table_info = t1;
31} {
32 0 a {} 0 {} 0
33 1 b {} 0 {} 0
34 2 c {} 0 {} 0
35 3 d {} 0 {} 0
36}
37
38#-------------------------------------------------------------------------
39# Syntax errors in the prefix= option.
40#
41foreach {tn opt} {
42 1 {prefix=x}
43 2 {prefix='x'}
44 3 {prefix='$'}
45 4 {prefix='1,2,'}
46 5 {prefix=',1'}
47 6 {prefix='1,2,3...'}
48 7 {prefix='1,2,3xyz'}
49} {
50 set res [list 1 {malformed prefix=... directive}]
51 do_catchsql_test 2.$tn "CREATE VIRTUAL TABLE f1 USING fts5(x, $opt)" $res
52}
53
54#-------------------------------------------------------------------------
55# Syntax errors in the 'rank' option.
56#
57foreach {tn val} {
58 1 "f1(xyz)"
59 2 "f1(zyx)"
60 3 "f1(nzz)"
61 4 "f1(x'!!')"
62 5 "f1(x':;')"
63 6 "f1(x'[]')"
64 7 "f1(x'{}')"
65 8 "f1('abc)"
66} {
67 do_catchsql_test 3.$tn {
68 INSERT INTO t1(t1, rank) VALUES('rank', $val);
69 } {1 {SQL logic error}}
70}
71
72#-------------------------------------------------------------------------
73# The parsing of SQL literals specified as part of 'rank' options.
74#
75do_execsql_test 4.0 {
76 CREATE VIRTUAL TABLE zzz USING fts5(one);
77 INSERT INTO zzz VALUES('a b c');
78}
79proc first {cmd A} { return $A }
80sqlite3_fts5_create_function db first first
81
82foreach {tn arg} {
83 1 "123"
84 2 "'01234567890ABCDEF'"
85 3 "x'0123'"
86 4 "x'ABCD'"
87 5 "x'0123456789ABCDEF'"
88 6 "x'0123456789abcdef'"
89 7 "22.5"
90 8 "-91.5"
91 9 "-.5"
92 10 "''''"
93 11 "+.5"
94} {
95 set func [string map {' ''} "first($arg)"]
96 do_execsql_test 4.1.$tn "
97 INSERT INTO zzz(zzz, rank) VALUES('rank', '$func');
98 SELECT rank IS $arg FROM zzz WHERE zzz MATCH 'a + b + c'
99 " 1
100}
101
102do_execsql_test 4.2 {
103 INSERT INTO zzz(zzz, rank) VALUES('rank', 'f1()');
104} {}
105
106#-------------------------------------------------------------------------
107# Misquoting in tokenize= and other options.
108#
109do_catchsql_test 5.1 {
110 CREATE VIRTUAL TABLE xx USING fts5(x, tokenize="porter 'ascii");
111} {1 {parse error in tokenize directive}}
112
113do_catchsql_test 5.2 {
114 CREATE VIRTUAL TABLE xx USING fts5(x, [y[]);
115} {0 {}}
116
117do_catchsql_test 5.3 {
118 CREATE VIRTUAL TABLE yy USING fts5(x, [y]]);
119} {1 {unrecognized token: "]"}}
120
121#-------------------------------------------------------------------------
122# Errors in prefix= directives.
123#
124do_catchsql_test 6.2 {
125 CREATE VIRTUAL TABLE abc USING fts5(a, prefix='1, 2, 1001');
126} {1 {prefix length out of range (max 999)}}
127do_catchsql_test 6.3 {
128 CREATE VIRTUAL TAbLE abc USING fts5(a, prefix='1, 2, 0000');
129} {1 {prefix length out of range (max 999)}}
130do_catchsql_test 6.4 {
131 CREATE VIRTUAL TABLE abc USING fts5(a, prefix='1 , 1000000');
132} {1 {prefix length out of range (max 999)}}
133
134#-------------------------------------------------------------------------
135# Duplicate tokenize= and other options.
136#
137do_catchsql_test 7.1 {
138 CREATE VIRTUAL TABLE abc USING fts5(a, tokenize=porter, tokenize=ascii);
139} {1 {multiple tokenize=... directives}}
140do_catchsql_test 7.2 {
141 CREATE VIRTUAL TABLE abc USING fts5(a, content=porter, content=ascii);
142} {1 {multiple content=... directives}}
143do_catchsql_test 7.3 {
144 CREATE VIRTUAL TABLE abc USING fts5(a, content_rowid=porter, content_rowid=a);
145} {1 {multiple content_rowid=... directives}}
146
147#-------------------------------------------------------------------------
148# Unrecognized option.
149#
150do_catchsql_test 8.0 {
151 CREATE VIRTUAL TABLE abc USING fts5(a, nosuchoption=123);
152} {1 {unrecognized option: "nosuchoption"}}
153do_catchsql_test 8.1 {
154 CREATE VIRTUAL TABLE abc USING fts5(a, "nosuchoption"=123);
155} {1 {parse error in ""nosuchoption"=123"}}
156
157#-------------------------------------------------------------------------
158# Errors in:
159#
160# 9.1.* 'pgsz' options.
161# 9.2.* 'automerge' options.
162# 9.3.* 'crisismerge' options.
163# 9.4.* a non-existant option.
164# 9.5.* 'hashsize' options.
165#
166do_execsql_test 9.0 {
167 CREATE VIRTUAL TABLE abc USING fts5(a, b);
168} {}
169do_catchsql_test 9.1.1 {
170 INSERT INTO abc(abc, rank) VALUES('pgsz', -5);
171} {1 {SQL logic error}}
172do_catchsql_test 9.1.2 {
173 INSERT INTO abc(abc, rank) VALUES('pgsz', 50000000);
174} {1 {SQL logic error}}
175do_catchsql_test 9.1.3 {
176 INSERT INTO abc(abc, rank) VALUES('pgsz', 66.67);
177} {1 {SQL logic error}}
178
179do_catchsql_test 9.2.1 {
180 INSERT INTO abc(abc, rank) VALUES('automerge', -5);
181} {1 {SQL logic error}}
182do_catchsql_test 9.2.2 {
183 INSERT INTO abc(abc, rank) VALUES('automerge', 50000000);
184} {1 {SQL logic error}}
185do_catchsql_test 9.2.3 {
186 INSERT INTO abc(abc, rank) VALUES('automerge', 66.67);
187} {1 {SQL logic error}}
188do_execsql_test 9.2.4 {
189 INSERT INTO abc(abc, rank) VALUES('automerge', 1);
190} {}
191
192do_catchsql_test 9.3.1 {
193 INSERT INTO abc(abc, rank) VALUES('crisismerge', -5);
194} {1 {SQL logic error}}
195do_catchsql_test 9.3.2 {
196 INSERT INTO abc(abc, rank) VALUES('crisismerge', 66.67);
197} {1 {SQL logic error}}
198do_execsql_test 9.3.3 {
199 INSERT INTO abc(abc, rank) VALUES('crisismerge', 1);
200} {}
201do_execsql_test 9.3.4 {
202 INSERT INTO abc(abc, rank) VALUES('crisismerge', 50000000);
203} {}
204
205do_catchsql_test 9.4.1 {
206 INSERT INTO abc(abc, rank) VALUES('nosuchoption', 1);
207} {1 {SQL logic error}}
208
209do_catchsql_test 9.5.1 {
210 INSERT INTO abc(abc, rank) VALUES('hashsize', 'not an integer');
211} {1 {SQL logic error}}
212do_catchsql_test 9.5.2 {
213 INSERT INTO abc(abc, rank) VALUES('hashsize', -500000);
214} {1 {SQL logic error}}
215do_catchsql_test 9.5.3 {
216 INSERT INTO abc(abc, rank) VALUES('hashsize', 500000);
217} {0 {}}
218
219#-------------------------------------------------------------------------
220# Too many prefix indexes. Maximum allowed is 31.
221#
222foreach {tn spec} {
223 1 {prefix="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"}
224 2 {prefix="1 2 3 4", prefix="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"}
225} {
226 set sql "CREATE VIRTUAL TABLE xyz USING fts5(x, $spec)"
227 do_catchsql_test 10.$tn $sql {1 {too many prefix indexes (max 31)}}
228}
229
230#-------------------------------------------------------------------------
231# errors in the detail= option.
232#
233foreach {tn opt} {
234 1 {detail=x}
235 2 {detail='x'}
236 3 {detail='$'}
237 4 {detail='1,2,'}
238 5 {detail=',1'}
239 6 {detail=''}
240} {
241 set res [list 1 {malformed detail=... directive}]
242 do_catchsql_test 11.$tn "CREATE VIRTUAL TABLE f1 USING fts5(x, $opt)" $res
243}
244
245do_catchsql_test 12.1 {
246 INSERT INTO t1(t1, rank) VALUES('rank', NULL);;
247} {1 {SQL logic error}}
248
249#-------------------------------------------------------------------------
250# errors in the 'usermerge' option
251#
252do_execsql_test 13.0 {
253 CREATE VIRTUAL TABLE tt USING fts5(ttt);
254}
255foreach {tn val} {
256 1 -1
257 2 4.2
258 3 17
259 4 1
260} {
261 set sql "INSERT INTO tt(tt, rank) VALUES('usermerge', $val)"
262 do_catchsql_test 13.$tn $sql {1 {SQL logic error}}
263}
264
265finish_test