3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
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.
16 source [file join [file dirname [info script]] fts5_common.tcl]
17 set testprefix fts5config
19 # If SQLITE_ENABLE_FTS5 is defined, omit this file.
25 #-------------------------------------------------------------------------
26 # Try different types of quote characters.
29 CREATE VIRTUAL TABLE t1 USING fts5('a', "b", [c], `d`);
30 PRAGMA table_info = t1;
38 #-------------------------------------------------------------------------
39 # Syntax errors in the prefix= option.
50 set res [list 1 {malformed prefix=... directive}]
51 do_catchsql_test 2.$tn "CREATE VIRTUAL TABLE f1 USING fts5(x, $opt)" $res
54 #-------------------------------------------------------------------------
55 # Syntax errors in the 'rank' option.
67 do_catchsql_test 3.$tn {
68 INSERT INTO t1(t1, rank) VALUES('rank', $val);
69 } {1 {SQL logic error}}
72 #-------------------------------------------------------------------------
73 # The parsing of SQL literals specified as part of 'rank' options.
76 CREATE VIRTUAL TABLE zzz USING fts5(one);
77 INSERT INTO zzz VALUES('a b c');
79 proc first {cmd A} { return $A }
80 sqlite3_fts5_create_function db first first
84 2 "'01234567890ABCDEF'"
87 5 "x'0123456789ABCDEF'"
88 6 "x'0123456789abcdef'"
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'
102 do_execsql_test 4.2 {
103 INSERT INTO zzz(zzz, rank) VALUES('rank', 'f1()');
106 #-------------------------------------------------------------------------
107 # Misquoting in tokenize= and other options.
109 do_catchsql_test 5.1 {
110 CREATE VIRTUAL TABLE xx USING fts5(x, tokenize="porter 'ascii");
111 } {1 {parse error in tokenize directive}}
113 do_catchsql_test 5.2 {
114 CREATE VIRTUAL TABLE xx USING fts5(x, [y[]);
117 do_catchsql_test 5.3 {
118 CREATE VIRTUAL TABLE yy USING fts5(x, [y]]);
119 } {1 {unrecognized token: "]"}}
121 #-------------------------------------------------------------------------
122 # Errors in prefix= directives.
124 do_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)}}
127 do_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)}}
130 do_catchsql_test 6.4 {
131 CREATE VIRTUAL TABLE abc USING fts5(a, prefix='1 , 1000000');
132 } {1 {prefix length out of range (max 999)}}
134 #-------------------------------------------------------------------------
135 # Duplicate tokenize= and other options.
137 do_catchsql_test 7.1 {
138 CREATE VIRTUAL TABLE abc USING fts5(a, tokenize=porter, tokenize=ascii);
139 } {1 {multiple tokenize=... directives}}
140 do_catchsql_test 7.2 {
141 CREATE VIRTUAL TABLE abc USING fts5(a, content=porter, content=ascii);
142 } {1 {multiple content=... directives}}
143 do_catchsql_test 7.3 {
144 CREATE VIRTUAL TABLE abc USING fts5(a, content_rowid=porter, content_rowid=a);
145 } {1 {multiple content_rowid=... directives}}
147 #-------------------------------------------------------------------------
148 # Unrecognized option.
150 do_catchsql_test 8.0 {
151 CREATE VIRTUAL TABLE abc USING fts5(a, nosuchoption=123);
152 } {1 {unrecognized option: "nosuchoption"}}
153 do_catchsql_test 8.1 {
154 CREATE VIRTUAL TABLE abc USING fts5(a, "nosuchoption"=123);
155 } {1 {parse error in ""nosuchoption"=123"}}
157 #-------------------------------------------------------------------------
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.
166 do_execsql_test 9.0 {
167 CREATE VIRTUAL TABLE abc USING fts5(a, b);
169 do_catchsql_test 9.1.1 {
170 INSERT INTO abc(abc, rank) VALUES('pgsz', -5);
171 } {1 {SQL logic error}}
172 do_catchsql_test 9.1.2 {
173 INSERT INTO abc(abc, rank) VALUES('pgsz', 50000000);
174 } {1 {SQL logic error}}
175 do_catchsql_test 9.1.3 {
176 INSERT INTO abc(abc, rank) VALUES('pgsz', 66.67);
177 } {1 {SQL logic error}}
179 do_catchsql_test 9.2.1 {
180 INSERT INTO abc(abc, rank) VALUES('automerge', -5);
181 } {1 {SQL logic error}}
182 do_catchsql_test 9.2.2 {
183 INSERT INTO abc(abc, rank) VALUES('automerge', 50000000);
184 } {1 {SQL logic error}}
185 do_catchsql_test 9.2.3 {
186 INSERT INTO abc(abc, rank) VALUES('automerge', 66.67);
187 } {1 {SQL logic error}}
188 do_execsql_test 9.2.4 {
189 INSERT INTO abc(abc, rank) VALUES('automerge', 1);
192 do_catchsql_test 9.3.1 {
193 INSERT INTO abc(abc, rank) VALUES('crisismerge', -5);
194 } {1 {SQL logic error}}
195 do_catchsql_test 9.3.2 {
196 INSERT INTO abc(abc, rank) VALUES('crisismerge', 66.67);
197 } {1 {SQL logic error}}
198 do_execsql_test 9.3.3 {
199 INSERT INTO abc(abc, rank) VALUES('crisismerge', 1);
201 do_execsql_test 9.3.4 {
202 INSERT INTO abc(abc, rank) VALUES('crisismerge', 50000000);
205 do_catchsql_test 9.4.1 {
206 INSERT INTO abc(abc, rank) VALUES('nosuchoption', 1);
207 } {1 {SQL logic error}}
209 do_catchsql_test 9.5.1 {
210 INSERT INTO abc(abc, rank) VALUES('hashsize', 'not an integer');
211 } {1 {SQL logic error}}
212 do_catchsql_test 9.5.2 {
213 INSERT INTO abc(abc, rank) VALUES('hashsize', -500000);
214 } {1 {SQL logic error}}
215 do_catchsql_test 9.5.3 {
216 INSERT INTO abc(abc, rank) VALUES('hashsize', 500000);
219 #-------------------------------------------------------------------------
220 # Too many prefix indexes. Maximum allowed is 31.
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"}
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)}}
230 #-------------------------------------------------------------------------
231 # errors in the detail= option.
241 set res [list 1 {malformed detail=... directive}]
242 do_catchsql_test 11.$tn "CREATE VIRTUAL TABLE f1 USING fts5(x, $opt)" $res
245 do_catchsql_test 12.1 {
246 INSERT INTO t1(t1, rank) VALUES('rank', NULL);;
247 } {1 {SQL logic error}}
249 #-------------------------------------------------------------------------
250 # errors in the 'usermerge' option
252 do_execsql_test 13.0 {
253 CREATE VIRTUAL TABLE tt USING fts5(ttt);
261 set sql "INSERT INTO tt(tt, rank) VALUES('usermerge', $val)"
262 do_catchsql_test 13.$tn $sql {1 {SQL logic error}}