sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
sqlite / ext / fts5 / test / fts5aux.test
| 1 | # 2014 Dec 20 |
| 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 | # Tests focusing on the auxiliary function APIs. |
| 13 | # |
| 14 | |
| 15 | source [file join [file dirname [info script]] fts5_common.tcl] |
| 16 | set testprefix fts5aux |
| 17 | |
| 18 | # If SQLITE_ENABLE_FTS5 is not defined, omit this file. |
| 19 | ifcapable !fts5 { |
| 20 | finish_test |
| 21 | return |
| 22 | } |
| 23 | |
| 24 | proc inst {cmd i} { |
| 25 | $cmd xInst $i |
| 26 | } |
| 27 | sqlite3_fts5_create_function db inst inst |
| 28 | |
| 29 | proc colsize {cmd i} { |
| 30 | $cmd xColumnSize $i |
| 31 | } |
| 32 | sqlite3_fts5_create_function db colsize colsize |
| 33 | |
| 34 | proc totalsize {cmd i} { |
| 35 | $cmd xColumnTotalSize $i |
| 36 | } |
| 37 | sqlite3_fts5_create_function db totalsize totalsize |
| 38 | |
| 39 | do_execsql_test 1.0 { |
| 40 | CREATE VIRTUAL TABLE f1 USING fts5(a, b); |
| 41 | INSERT INTO f1 VALUES('one two', 'two one zero'); |
| 42 | INSERT INTO f1 VALUES('one one', 'one one one'); |
| 43 | } |
| 44 | |
| 45 | do_catchsql_test 1.1 { |
| 46 | SELECT inst(f1, -1) FROM f1 WHERE f1 MATCH 'two'; |
| 47 | } {1 SQLITE_RANGE} |
| 48 | do_catchsql_test 1.2 { |
| 49 | SELECT inst(f1, 0) FROM f1 WHERE f1 MATCH 'two'; |
| 50 | } {0 {{0 0 1}}} |
| 51 | do_catchsql_test 1.3 { |
| 52 | SELECT inst(f1, 1) FROM f1 WHERE f1 MATCH 'two'; |
| 53 | } {0 {{0 1 0}}} |
| 54 | do_catchsql_test 1.4 { |
| 55 | SELECT inst(f1, 2) FROM f1 WHERE f1 MATCH 'two'; |
| 56 | } {1 SQLITE_RANGE} |
| 57 | |
| 58 | do_catchsql_test 2.1 { |
| 59 | SELECT colsize(f1, 2) FROM f1 WHERE f1 MATCH 'two'; |
| 60 | } {1 SQLITE_RANGE} |
| 61 | do_execsql_test 2.2 { |
| 62 | SELECT colsize(f1, 0), colsize(f1, 1) FROM f1 WHERE f1 MATCH 'zero'; |
| 63 | } {2 3} |
| 64 | do_execsql_test 2.3 { |
| 65 | SELECT colsize(f1, -1) FROM f1 WHERE f1 MATCH 'zero'; |
| 66 | } {5} |
| 67 | |
| 68 | do_execsql_test 2.4.1 { |
| 69 | SELECT totalsize(f1, -1) FROM f1 WHERE f1 MATCH 'zero'; |
| 70 | } {10} |
| 71 | do_execsql_test 2.4.2 { |
| 72 | SELECT totalsize(f1, 0) FROM f1 WHERE f1 MATCH 'zero'; |
| 73 | } {4} |
| 74 | do_execsql_test 2.4.3 { |
| 75 | SELECT totalsize(f1, 1) FROM f1 WHERE f1 MATCH 'zero'; |
| 76 | } {6} |
| 77 | do_catchsql_test 2.4.4 { |
| 78 | SELECT totalsize(f1, 2) FROM f1 WHERE f1 MATCH 'zero'; |
| 79 | } {1 SQLITE_RANGE} |
| 80 | |
| 81 | #------------------------------------------------------------------------- |
| 82 | # Test the xSet and xGetAuxdata APIs with a NULL destructor. |
| 83 | # |
| 84 | proc prevrowid {add cmd} { |
| 85 | set res [$cmd xGetAuxdataInt 0] |
| 86 | set r [$cmd xRowid] |
| 87 | $cmd xSetAuxdataInt $r |
| 88 | return [expr $res + $add] |
| 89 | } |
| 90 | sqlite3_fts5_create_function db prevrowid [list prevrowid 0] |
| 91 | sqlite3_fts5_create_function db prevrowid1 [list prevrowid 1] |
| 92 | |
| 93 | do_execsql_test 3.0 { |
| 94 | CREATE VIRTUAL TABLE e5 USING fts5(x); |
| 95 | INSERT INTO e5 VALUES('a b c'); |
| 96 | INSERT INTO e5 VALUES('d e f'); |
| 97 | INSERT INTO e5 VALUES('a b c'); |
| 98 | INSERT INTO e5 VALUES('d e f'); |
| 99 | INSERT INTO e5 VALUES('a b c'); |
| 100 | } |
| 101 | |
| 102 | do_execsql_test 3.1 { |
| 103 | SELECT prevrowid(e5) || '+' || rowid FROM e5 WHERE e5 MATCH 'c' |
| 104 | } {0+1 1+3 3+5} |
| 105 | |
| 106 | do_execsql_test 3.2 { |
| 107 | SELECT prevrowid(e5) || '+' || prevrowid1(e5) || '+' || rowid |
| 108 | FROM e5 WHERE e5 MATCH 'e' |
| 109 | } {0+1+2 2+3+4} |
| 110 | |
| 111 | #------------------------------------------------------------------------- |
| 112 | # Test that if the xQueryPhrase callback returns other than SQLITE_OK, |
| 113 | # the query is abandoned. And that if it returns an error code other than |
| 114 | # SQLITE_DONE, the error is propagated back to the caller. |
| 115 | # |
| 116 | do_execsql_test 4.0 { |
| 117 | CREATE VIRTUAL TABLE e7 USING fts5(x); |
| 118 | INSERT INTO e7 VALUES('a x a'); |
| 119 | INSERT INTO e7 VALUES('b x b'); |
| 120 | INSERT INTO e7 VALUES('c x c'); |
| 121 | INSERT INTO e7 VALUES('d x d'); |
| 122 | INSERT INTO e7 VALUES('e x e'); |
| 123 | } |
| 124 | |
| 125 | proc xCallback {rowid code cmd} { |
| 126 | set r [$cmd xRowid] |
| 127 | lappend ::cb $r |
| 128 | if {$r==$rowid} { return $code } |
| 129 | return "" |
| 130 | } |
| 131 | |
| 132 | proc phrasequery {cmd code} { |
| 133 | set ::cb [list] |
| 134 | $cmd xQueryPhrase 1 [list xCallback [$cmd xRowid] $code] |
| 135 | set ::cb |
| 136 | } |
| 137 | |
| 138 | sqlite3_fts5_create_function db phrasequery phrasequery |
| 139 | |
| 140 | do_execsql_test 4.1 { |
| 141 | SELECT phrasequery(e7, 'SQLITE_OK') FROM e7 WHERE e7 MATCH 'c x' |
| 142 | } {{1 2 3 4 5}} |
| 143 | |
| 144 | do_execsql_test 4.2 { |
| 145 | SELECT phrasequery(e7, 'SQLITE_DONE') FROM e7 WHERE e7 MATCH 'c x' |
| 146 | } {{1 2 3}} |
| 147 | |
| 148 | do_catchsql_test 4.3 { |
| 149 | SELECT phrasequery(e7, 'SQLITE_ERROR') FROM e7 WHERE e7 MATCH 'c x' |
| 150 | } {1 SQLITE_ERROR} |
| 151 | |
| 152 | #------------------------------------------------------------------------- |
| 153 | # Auxiliary function calls with many cursors in the global cursor list. |
| 154 | # |
| 155 | do_execsql_test 5.0 { |
| 156 | CREATE VIRTUAL TABLE e9 USING fts5(y); |
| 157 | INSERT INTO e9(rowid, y) VALUES(1, 'i iii'); |
| 158 | INSERT INTO e9(rowid, y) VALUES(2, 'ii iv'); |
| 159 | INSERT INTO e9(rowid, y) VALUES(3, 'ii'); |
| 160 | INSERT INTO e9(rowid, y) VALUES(4, 'i iv'); |
| 161 | INSERT INTO e9(rowid, y) VALUES(5, 'iii'); |
| 162 | } |
| 163 | |
| 164 | proc my_rowid {cmd} { $cmd xRowid } |
| 165 | sqlite3_fts5_create_function db my_rowid my_rowid |
| 166 | |
| 167 | foreach {var q} { |
| 168 | s1 i |
| 169 | s2 ii |
| 170 | s3 iii |
| 171 | s4 iv |
| 172 | } { |
| 173 | set sql "SELECT my_rowid(e9) FROM e9 WHERE e9 MATCH '$q'" |
| 174 | set $var [sqlite3_prepare db $sql -1 dummy] |
| 175 | } |
| 176 | |
| 177 | do_test 5.1.1 { sqlite3_step $s1 ; sqlite3_column_int $s1 0 } 1 |
| 178 | do_test 5.1.2 { sqlite3_step $s2 ; sqlite3_column_int $s2 0 } 2 |
| 179 | do_test 5.1.3 { sqlite3_step $s3 ; sqlite3_column_int $s3 0 } 1 |
| 180 | do_test 5.1.4 { sqlite3_step $s4 ; sqlite3_column_int $s4 0 } 2 |
| 181 | |
| 182 | do_test 5.2.1 { sqlite3_step $s1 ; sqlite3_column_int $s1 0 } 4 |
| 183 | do_test 5.2.2 { sqlite3_step $s2 ; sqlite3_column_int $s2 0 } 3 |
| 184 | do_test 5.2.3 { sqlite3_step $s3 ; sqlite3_column_int $s3 0 } 5 |
| 185 | do_test 5.2.4 { sqlite3_step $s4 ; sqlite3_column_int $s4 0 } 4 |
| 186 | |
| 187 | sqlite3_finalize $s1 |
| 188 | sqlite3_finalize $s2 |
| 189 | sqlite3_finalize $s3 |
| 190 | sqlite3_finalize $s4 |
| 191 | |
| 192 | #------------------------------------------------------------------------- |
| 193 | # Passing an invalid first argument to an auxiliary function is detected. |
| 194 | # |
| 195 | do_execsql_test 6.0 { |
| 196 | CREATE VIRTUAL TABLE e11 USING fts5(y, z); |
| 197 | INSERT INTO e11(rowid, y, z) VALUES(1, 'a b', 45); |
| 198 | INSERT INTO e11(rowid, y, z) VALUES(2, 'b c', 46); |
| 199 | } |
| 200 | |
| 201 | do_catchsql_test 6.1 { |
| 202 | SELECT my_rowid(z) FROM e11 WHERE e11 MATCH 'b' |
| 203 | } {1 {no such cursor: 45}} |
| 204 | |
| 205 | do_catchsql_test 6.2 { |
| 206 | SELECT my_rowid(y) FROM e11 WHERE e11 MATCH 'b' |
| 207 | } {1 {no such cursor: 0}} |
| 208 | |
| 209 | #------------------------------------------------------------------------- |
| 210 | # Test passing an out-of-range phrase number to xPhraseSize (should |
| 211 | # return 0). |
| 212 | # |
| 213 | proc my_phrasesize {cmd iPhrase} { $cmd xPhraseSize $iPhrase } |
| 214 | sqlite3_fts5_create_function db my_phrasesize my_phrasesize |
| 215 | |
| 216 | do_execsql_test 7.1 { |
| 217 | CREATE VIRTUAL TABLE t1 USING fts5(a); |
| 218 | INSERT INTO t1 VALUES('a b c'); |
| 219 | } |
| 220 | do_execsql_test 7.2 { |
| 221 | SELECT |
| 222 | my_phrasesize(t1, -1), |
| 223 | my_phrasesize(t1, 0), |
| 224 | my_phrasesize(t1, 1), |
| 225 | my_phrasesize(t1, 2) |
| 226 | FROM t1 WHERE t1 MATCH 'a OR b+c' |
| 227 | } {0 1 2 0} |
| 228 | |
| 229 | #------------------------------------------------------------------------- |
| 230 | # |
| 231 | do_execsql_test 8.0 { |
| 232 | CREATE VIRTUAL TABLE x1 USING fts5(a); |
| 233 | } |
| 234 | |
| 235 | foreach {tn lRow res} { |
| 236 | 4 {"a a a" "b" "a d"} {"[a] [a] [a]" "[a] d"} |
| 237 | 1 {"b d" "a b"} {"[b] [d]" "[a] b"} |
| 238 | 2 {"d b" "a d"} {"[d] [b]" "[a] d"} |
| 239 | 3 {"a a d"} {"[a] [a] d"} |
| 240 | } { |
| 241 | execsql { DELETE FROM x1 } |
| 242 | foreach row $lRow { execsql { INSERT INTO x1 VALUES($row) } } |
| 243 | do_execsql_test 8.$tn { |
| 244 | SELECT highlight(x1, 0, '[', ']') FROM x1 WHERE x1 MATCH 'a OR (b AND d)'; |
| 245 | } $res |
| 246 | } |
| 247 | |
| 248 | #------------------------------------------------------------------------- |
| 249 | # Test the built-in bm25() demo. |
| 250 | # |
| 251 | reset_db |
| 252 | do_execsql_test 9.1 { |
| 253 | CREATE VIRTUAL TABLE t1 USING fts5(a, b); |
| 254 | INSERT INTO t1 VALUES('a', NULL); -- 1 |
| 255 | INSERT INTO t1 VALUES('a', NULL); -- 2 |
| 256 | INSERT INTO t1 VALUES('a', NULL); -- 3 |
| 257 | INSERT INTO t1 VALUES('a', NULL); -- 4 |
| 258 | INSERT INTO t1 VALUES('a', NULL); -- 5 |
| 259 | INSERT INTO t1 VALUES('a', NULL); -- 6 |
| 260 | INSERT INTO t1 VALUES('a', NULL); -- 7 |
| 261 | INSERT INTO t1 VALUES('a', NULL); -- 8 |
| 262 | INSERT INTO t1 VALUES(NULL, 'a a b'); -- 9 |
| 263 | INSERT INTO t1 VALUES(NULL, 'b b a'); -- 10 |
| 264 | } |
| 265 | |
| 266 | do_execsql_test 9.2 { |
| 267 | SELECT rowid FROM t1('a AND b') ORDER BY rank; |
| 268 | } { |
| 269 | 10 9 |
| 270 | } |
| 271 | |
| 272 | do_execsql_test 9.3 { |
| 273 | SELECT rowid FROM t1('b:a AND b:b') ORDER BY rank; |
| 274 | } { |
| 275 | 9 10 |
| 276 | } |
| 277 | |
| 278 | #------------------------------------------------------------------------- |
| 279 | # Test that aux. functions may not be used in aggregate queries. |
| 280 | # |
| 281 | reset_db |
| 282 | do_execsql_test 10.0 { |
| 283 | CREATE VIRTUAL TABLE t1 USING fts5(x, y, z); |
| 284 | INSERT INTO t1 VALUES('a', 'one two', 1); |
| 285 | INSERT INTO t1 VALUES('b', 'two three', 2); |
| 286 | INSERT INTO t1 VALUES('c', 'three four', 1); |
| 287 | INSERT INTO t1 VALUES('d', 'four five', 2); |
| 288 | INSERT INTO t1 VALUES('e', 'five six', 1); |
| 289 | INSERT INTO t1 VALUES('f', 'six seven', 2); |
| 290 | } |
| 291 | |
| 292 | proc firstcol {cmd} { $cmd xColumnText 0 } |
| 293 | sqlite3_fts5_create_function db firstcol firstcol |
| 294 | |
| 295 | do_execsql_test 10.1.1 { |
| 296 | SELECT firstcol(t1) FROM t1 |
| 297 | } {a b c d e f} |
| 298 | do_execsql_test 10.1.2 { |
| 299 | SELECT group_concat(x, '.') FROM t1 |
| 300 | } {a.b.c.d.e.f} |
| 301 | |
| 302 | do_catchsql_test 10.1.3 { |
| 303 | SELECT group_concat(firstcol(t1), '.') FROM t1 |
| 304 | } {1 {unable to use function firstcol in the requested context}} |
| 305 | |
| 306 | do_catchsql_test 10.1.4 { |
| 307 | SELECT group_concat(firstcol(t1), '.') FROM t1 GROUP BY rowid |
| 308 | } {1 {unable to use function firstcol in the requested context}} |
| 309 | |
| 310 | #------------------------------------------------------------------------- |
| 311 | # Test that xInstCount() works from within an xPhraseQuery() callback. |
| 312 | # |
| 313 | reset_db |
| 314 | |
| 315 | proc xCallback {cmd} { |
| 316 | incr ::hitcount [$cmd xInstCount] |
| 317 | return SQLITE_OK |
| 318 | } |
| 319 | proc fts5_hitcount {cmd} { |
| 320 | set ::hitcount 0 |
| 321 | $cmd xQueryPhrase 0 xCallback |
| 322 | return $::hitcount |
| 323 | } |
| 324 | sqlite3_fts5_create_function db fts5_hitcount fts5_hitcount |
| 325 | |
| 326 | do_execsql_test 11.1 { |
| 327 | CREATE VIRTUAL TABLE x1 USING fts5(z); |
| 328 | INSERT INTO x1 VALUES('one two three'); |
| 329 | INSERT INTO x1 VALUES('one two one three one'); |
| 330 | INSERT INTO x1 VALUES('one two three'); |
| 331 | } |
| 332 | |
| 333 | do_execsql_test 11.2 { |
| 334 | SELECT fts5_hitcount(x1) FROM x1('one') LIMIT 1; |
| 335 | } {5} |
| 336 | |
| 337 | #------------------------------------------------------------------------- |
| 338 | # Test that xColumnText returns SQLITE_RANGE when it should. |
| 339 | # |
| 340 | reset_db |
| 341 | fts5_aux_test_functions db |
| 342 | do_execsql_test 12.0 { |
| 343 | CREATE VIRTUAL TABLE t1 USING fts5(a, b, c); |
| 344 | INSERT INTO t1 VALUES('one', 'two', 'three'); |
| 345 | INSERT INTO t1 VALUES('one', 'one', 'one'); |
| 346 | INSERT INTO t1 VALUES('two', 'two', 'two'); |
| 347 | INSERT INTO t1 VALUES('three', 'three', 'three'); |
| 348 | } |
| 349 | |
| 350 | do_catchsql_test 12.1.1 { |
| 351 | SELECT fts5_columntext(t1, -1) FROM t1('two'); |
| 352 | } {1 SQLITE_RANGE} |
| 353 | do_catchsql_test 12.1.2 { |
| 354 | SELECT fts5_columntext(t1, 3) FROM t1('two'); |
| 355 | } {1 SQLITE_RANGE} |
| 356 | do_catchsql_test 12.1.2 { |
| 357 | SELECT fts5_columntext(t1, 1) FROM t1('one AND two'); |
| 358 | } {0 two} |
| 359 | |
| 360 | do_catchsql_test 12.2.1 { |
| 361 | SELECT fts5_queryphrase(t1, -1) FROM t1('one AND two'); |
| 362 | } {1 SQLITE_RANGE} |
| 363 | do_catchsql_test 12.2.2 { |
| 364 | SELECT fts5_queryphrase(t1, 2) FROM t1('one AND two'); |
| 365 | } {1 SQLITE_RANGE} |
| 366 | do_catchsql_test 12.2.3 { |
| 367 | SELECT fts5_queryphrase(t1, 1) FROM t1('one AND two'); |
| 368 | } {0 {{1 2 1}}} |
| 369 | |
| 370 | do_catchsql_test 12.3.1 { |
| 371 | SELECT fts5_collist(t1, -1) FROM t1('one AND two'); |
| 372 | } {1 SQLITE_RANGE} |
| 373 | do_catchsql_test 12.3.2 { |
| 374 | SELECT fts5_collist(t1, 2) FROM t1('one AND two'); |
| 375 | } {1 SQLITE_RANGE} |
| 376 | do_catchsql_test 12.3.3 { |
| 377 | SELECT fts5_collist(t1, 1) FROM t1('one AND two'); |
| 378 | } {0 1} |
| 379 | |
| 380 | do_catchsql_test 12.3.4 { |
| 381 | SELECT fts5_collist(t1, 15000) FROM t1('one AND two'); |
| 382 | } {1 SQLITE_RANGE} |
| 383 | |
| 384 | #------------------------------------------------------------------------- |
| 385 | reset_db |
| 386 | do_execsql_test 13.1 { |
| 387 | CREATE VIRTUAL TABLE t1 USING fts5(a, tokenize=ascii); |
| 388 | INSERT INTO t1 VALUES('a b c'), ('d e f'); |
| 389 | PRAGMA integrity_check; |
| 390 | } {ok} |
| 391 | |
| 392 | do_catchsql_test 13.2 { |
| 393 | SELECT highlight(t1, 0, '[', ']') FROM t1 |
| 394 | } {0 {{a b c} {d e f}}} |
| 395 | |
| 396 | do_execsql_test 13.3 { |
| 397 | PRAGMA writable_schema = 1; |
| 398 | UPDATE sqlite_schema SET sql = 'CREATE VIRTUAL TABLE t1 USING fts5(a, tokenize=blah)' |
| 399 | WHERE name = 't1'; |
| 400 | } |
| 401 | |
| 402 | db close |
| 403 | sqlite3 db test.db |
| 404 | do_catchsql_test 13.4 { |
| 405 | SELECT highlight(t1, 0, '[', ']') FROM t1 |
| 406 | } {1 {SQL logic error}} |
| 407 | |
| 408 | #------------------------------------------------------------------------- |
| 409 | |
| 410 | foreach_detail_mode $testprefix { |
| 411 | reset_db |
| 412 | fts5_aux_test_functions db |
| 413 | |
| 414 | do_execsql_test 14.0 { |
| 415 | CREATE VIRTUAL TABLE t1 USING fts5(x, detail=%DETAIL%); |
| 416 | INSERT INTO t1 VALUES('one two three'); |
| 417 | INSERT INTO t1 VALUES('three two one'); |
| 418 | } |
| 419 | |
| 420 | do_catchsql_test 14.1 { |
| 421 | SELECT fts5_collist(t1, 15000) FROM t1('one AND two'); |
| 422 | } {1 SQLITE_RANGE} |
| 423 | |
| 424 | do_catchsql_test 14.2 { |
| 425 | SELECT fts5_collist(t1, 0) FROM t1('one AND two'); |
| 426 | } {0 {0 0}} |
| 427 | |
| 428 | do_catchsql_test 14.3 { |
| 429 | SELECT fts5_collist(t1, 0) FROM t1('one AND two') ORDER BY rank; |
| 430 | } {0 {0 0}} |
| 431 | |
| 432 | do_catchsql_test 14.3 { |
| 433 | SELECT fts5_collist(t1, 15000) FROM t1('one AND two') ORDER BY rank; |
| 434 | } {1 SQLITE_RANGE} |
| 435 | } |
| 436 | |
| 437 | #------------------------------------------------------------------------- |
| 438 | # Test that highlight() and snippet() handle column-number arguments that |
| 439 | # are too large or too small to fit in a 32-bit signed integer in the |
| 440 | # same way as other out-of-range values of the same sign. |
| 441 | # |
| 442 | reset_db |
| 443 | do_execsql_test 15.0 { |
| 444 | CREATE VIRTUAL TABLE t1 USING fts5(a, b); |
| 445 | INSERT INTO t1 VALUES('one two three', 'four five six'); |
| 446 | } |
| 447 | |
| 448 | foreach {tn iCol} { |
| 449 | 1 2 |
| 450 | 2 -1 |
| 451 | 3 2147483648 |
| 452 | 4 -2147483649 |
| 453 | 5 4294967295 |
| 454 | 6 4294967296 |
| 455 | 7 4294967297 |
| 456 | 8 -4294967295 |
| 457 | 9 -4294967296 |
| 458 | 10 9223372036854775807 |
| 459 | 11 -9223372036854775808 |
| 460 | } { |
| 461 | do_execsql_test 15.1.$tn { |
| 462 | SELECT quote(highlight(t1, $iCol, '[', ']')) FROM t1('one OR five'); |
| 463 | } {''} |
| 464 | } |
| 465 | |
| 466 | foreach {tn iCol} { |
| 467 | 1 -1 |
| 468 | 2 -2147483649 |
| 469 | 3 -4294967295 |
| 470 | 4 -4294967296 |
| 471 | 5 -9223372036854775808 |
| 472 | } { |
| 473 | do_execsql_test 15.2.$tn { |
| 474 | SELECT snippet(t1, $iCol, '[', ']', '...', 5) FROM t1('five'); |
| 475 | } {{four [five] six}} |
| 476 | } |
| 477 | |
| 478 | foreach {tn iCol} { |
| 479 | 1 2 |
| 480 | 2 2147483648 |
| 481 | 3 4294967295 |
| 482 | 4 4294967296 |
| 483 | 5 4294967297 |
| 484 | 6 9223372036854775807 |
| 485 | } { |
| 486 | do_catchsql_test 15.3.$tn { |
| 487 | SELECT snippet(t1, $iCol, '[', ']', '...', 5) FROM t1('one OR five'); |
| 488 | } {1 {column index out of range}} |
| 489 | } |
| 490 | |
| 491 | #------------------------------------------------------------------------- |
| 492 | reset_db |
| 493 | |
| 494 | do_execsql_test 16.0 { |
| 495 | CREATE VIRTUAL TABLE t1 USING fts5(a, b UNINDEXED, detail=none); |
| 496 | INSERT INTO t1 VALUES ('one two zeta three four', 'x y zeta'); |
| 497 | } |
| 498 | |
| 499 | do_execsql_test 16.1 { |
| 500 | SELECT snippet(t1, -1, '[', ']', '..', 3) FROM t1('zeta'); |
| 501 | } {{one two [zeta]..}} |
| 502 | |
| 503 | do_execsql_test 16.2 { |
| 504 | SELECT highlight(t1, 1, '[', ']') FROM t1('zeta'); |
| 505 | } {{x y zeta}} |
| 506 | |
| 507 | do_execsql_test 16.3 { |
| 508 | SELECT highlight(t1, 0, '[', ']') FROM t1('zeta'); |
| 509 | } {{one two [zeta] three four}} |
| 510 | |
| 511 | do_execsql_test 16.4 { |
| 512 | SELECT highlight(t1, -1, '[', ']') FROM t1('zeta'); |
| 513 | } {{}} |
| 514 | |
| 515 | #------------------------------------------------------------------------- |
| 516 | # Test that phrase instances reported to auxiliary functions are correct |
| 517 | # for queries with AND and NOT nodes that are not the root of the |
| 518 | # expression. |
| 519 | # |
| 520 | # 17.1.*: When a non-root AND node visits a row that does not match, only |
| 521 | # the phrases of its sub-tree that point to that row are cleared. |
| 522 | # Phrases that have already advanced to a later row (e.g. "z" |
| 523 | # below) keep their instances for that row. |
| 524 | # |
| 525 | # 17.2.*: If the LHS of a NOT matches no rows at all, the instances of |
| 526 | # phrases on its RHS are not reported for rows matched by other |
| 527 | # parts of the expression. |
| 528 | # |
| 529 | # 17.3.*: Combination of the two above, with a NOT below an AND. |
| 530 | # |
| 531 | reset_db |
| 532 | do_execsql_test 17.0 { |
| 533 | CREATE VIRTUAL TABLE t1 USING fts5(a); |
| 534 | INSERT INTO t1(rowid, a) VALUES (1, 'x y'), (2, 'x z'); |
| 535 | CREATE VIRTUAL TABLE t3 USING fts5(a); |
| 536 | INSERT INTO t3(rowid, a) VALUES (1, 'g b'); |
| 537 | CREATE VIRTUAL TABLE t4 USING fts5(a); |
| 538 | INSERT INTO t4(rowid, a) VALUES (1, 'y x'), (2, 'g b'), (3, 'x y'); |
| 539 | } |
| 540 | |
| 541 | foreach {tn order res1 res3} { |
| 542 | 1 ASC {2 {[x] [z]}} {2 {[g] b} 3 {[x y]}} |
| 543 | 2 DESC {2 {[x] [z]}} {3 {[x y]} 2 {[g] b}} |
| 544 | } { |
| 545 | set M [list %ORDER% $order] |
| 546 | do_execsql_test 17.1.$tn.1 [string map $M { |
| 547 | SELECT rowid, highlight(t1, 0, '[', ']') FROM t1('x AND (z OR "y x")') |
| 548 | ORDER BY rowid %ORDER% |
| 549 | }] $res1 |
| 550 | do_execsql_test 17.1.$tn.2 [string map $M { |
| 551 | SELECT rowid, highlight(t1, 0, '[', ']') |
| 552 | FROM t1('(x AND (z OR "y x")) OR zz') ORDER BY rowid %ORDER% |
| 553 | }] $res1 |
| 554 | do_execsql_test 17.3.$tn [string map $M { |
| 555 | SELECT rowid, highlight(t4, 0, '[', ']') |
| 556 | FROM t4('g OR ("x y" AND (y OR (zz NOT b)))') ORDER BY rowid %ORDER% |
| 557 | }] $res3 |
| 558 | } |
| 559 | |
| 560 | do_execsql_test 17.2.1 { |
| 561 | SELECT rowid, highlight(t3, 0, '[', ']') FROM t3('g OR (zz NOT b)'); |
| 562 | } {1 {[g] b}} |
| 563 | do_execsql_test 17.2.2 { |
| 564 | INSERT INTO t3(rowid, a) VALUES (2, 'zz'); |
| 565 | SELECT rowid, highlight(t3, 0, '[', ']') FROM t3('g OR (zz NOT b)'); |
| 566 | } {1 {[g] b} 2 {[zz]}} |
| 567 | do_execsql_test 17.2.3 { |
| 568 | SELECT rowid, highlight(t3, 0, '[', ']') FROM t3('g OR (zz NOT b)') |
| 569 | ORDER BY rowid DESC; |
| 570 | } {2 {[zz]} 1 {[g] b}} |
| 571 | |
| 572 | finish_test |