fts5misc.test 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. # 2019 September 02
  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. # This file implements regression tests for SQLite library. The
  12. # focus of this script is testing the FTS5 module.
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. set testprefix fts5misc
  16. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  17. ifcapable !fts5 {
  18. finish_test
  19. return
  20. }
  21. do_execsql_test 1.0 {
  22. CREATE VIRTUAL TABLE t1 USING fts5(a);
  23. }
  24. do_catchsql_test 1.1.1 {
  25. SELECT highlight(t1, 4, '<b>', '</b>') FROM t1('*');
  26. } {1 {unknown special query: }}
  27. do_catchsql_test 1.1.2 {
  28. SELECT a FROM t1
  29. WHERE rank = (SELECT highlight(t1, 4, '<b>', '</b>') FROM t1('*'));
  30. } {1 {unknown special query: }}
  31. do_catchsql_test 1.2.1 {
  32. SELECT highlight(t1, 4, '<b>', '</b>') FROM t1('*id');
  33. } {1 {no such cursor: 4}}
  34. do_catchsql_test 1.2.2 {
  35. SELECT a FROM t1
  36. WHERE rank = (SELECT highlight(t1, 4, '<b>', '</b>') FROM t1('*id'));
  37. } {1 {no such cursor: 6}}
  38. do_catchsql_test 1.3.1 {
  39. SELECT highlight(t1, 4, '<b>', '</b>') FROM t1('*reads');
  40. } {1 {no such cursor: 0}}
  41. do_catchsql_test 1.3.2 {
  42. SELECT a FROM t1
  43. WHERE rank = (SELECT highlight(t1, 4, '<b>', '</b>') FROM t1('*reads'));
  44. } {1 {no such cursor: 0}}
  45. db close
  46. sqlite3 db test.db
  47. do_catchsql_test 1.3.3 {
  48. SELECT a FROM t1
  49. WHERE rank = (SELECT highlight(t1, 4, '<b>', '</b>') FROM t1('*reads'));
  50. } {1 {no such cursor: 0}}
  51. fts5_aux_test_functions db
  52. do_catchsql_test 1.3.4 {
  53. SELECT fts5_columntext(t1) FROM t1('*reads');
  54. } {1 {no such cursor: 0}}
  55. #-------------------------------------------------------------------------
  56. reset_db
  57. do_execsql_test 2.0 {
  58. CREATE TABLE t0(c0);
  59. CREATE VIRTUAL TABLE vt0 USING fts5(c0);
  60. }
  61. do_execsql_test 2.1.1 {
  62. BEGIN TRANSACTION;
  63. INSERT INTO vt0(c0) VALUES ('xyz');
  64. }
  65. do_execsql_test 2.1.2 {
  66. ALTER TABLE t0 ADD COLUMN c5;
  67. }
  68. do_execsql_test 2.1.3 {
  69. INSERT INTO vt0(vt0) VALUES('integrity-check');
  70. }
  71. do_execsql_test 2.1.4 {
  72. INSERT INTO vt0(c0) VALUES ('abc');
  73. COMMIT
  74. }
  75. do_execsql_test 2.1.5 {
  76. INSERT INTO vt0(vt0) VALUES('integrity-check');
  77. }
  78. reset_db
  79. do_execsql_test 2.2.1 {
  80. CREATE TABLE t0(c0);
  81. CREATE VIRTUAL TABLE vt0 USING fts5(c0);
  82. BEGIN TRANSACTION;
  83. INSERT INTO vt0(c0) VALUES ('xyz');
  84. }
  85. do_execsql_test 2.2.2 {
  86. ALTER TABLE t0 RENAME TO t1;
  87. }
  88. do_execsql_test 2.2.3 {
  89. INSERT INTO vt0(vt0) VALUES('integrity-check');
  90. }
  91. do_execsql_test 2.2.4 {
  92. INSERT INTO vt0(c0) VALUES ('abc');
  93. COMMIT;
  94. }
  95. do_execsql_test 2.2.5 {
  96. INSERT INTO vt0(vt0) VALUES('integrity-check');
  97. }
  98. #-------------------------------------------------------------------------
  99. reset_db
  100. do_execsql_test 3.0 {
  101. CREATE VIRTUAL TABLE vt0 USING fts5(a);
  102. PRAGMA reverse_unordered_selects = true;
  103. INSERT INTO vt0 VALUES('365062398'), (0), (0);
  104. INSERT INTO vt0(vt0, rank) VALUES('pgsz', '38');
  105. }
  106. do_execsql_test 3.1 {
  107. UPDATE vt0 SET a = 399905135; -- unexpected: database disk image is malformed
  108. }
  109. do_execsql_test 3.2 {
  110. INSERT INTO vt0(vt0) VALUES('integrity-check');
  111. }
  112. #-------------------------------------------------------------------------
  113. reset_db
  114. do_execsql_test 4.0 {
  115. CREATE VIRTUAL TABLE vt0 USING fts5(c0);
  116. INSERT INTO vt0(c0) VALUES ('xyz');
  117. }
  118. do_execsql_test 4.1 {
  119. BEGIN;
  120. INSERT INTO vt0(c0) VALUES ('abc');
  121. INSERT INTO vt0(vt0) VALUES('rebuild');
  122. COMMIT;
  123. }
  124. do_execsql_test 4.2 {
  125. INSERT INTO vt0(vt0) VALUES('integrity-check');
  126. }
  127. do_execsql_test 4.3 {
  128. BEGIN;
  129. INSERT INTO vt0(vt0) VALUES('rebuild');
  130. INSERT INTO vt0(vt0) VALUES('rebuild');
  131. COMMIT;
  132. }
  133. do_execsql_test 4.4 {
  134. INSERT INTO vt0(vt0) VALUES('integrity-check');
  135. }
  136. #-------------------------------------------------------------------------
  137. # Ticket [81a7f7b9].
  138. #
  139. reset_db
  140. do_execsql_test 5.0 {
  141. CREATE VIRTUAL TABLE vt0 USING fts5(c0, c1);
  142. INSERT INTO vt0(vt0, rank) VALUES('pgsz', '65536');
  143. WITH s(i) AS (
  144. SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1236
  145. )
  146. INSERT INTO vt0(c0) SELECT '0' FROM s;
  147. } {}
  148. do_execsql_test 5.1 {
  149. UPDATE vt0 SET c1 = 'T,D&p^y/7#3*v<b<4j7|f';
  150. }
  151. do_execsql_test 5.2 {
  152. INSERT INTO vt0(vt0) VALUES('integrity-check');
  153. }
  154. do_catchsql_test 5.3 {
  155. INSERT INTO vt0(vt0, rank) VALUES('pgsz', '65537');
  156. } {1 {SQL logic error}}
  157. #-------------------------------------------------------------------------
  158. # Ticket [d392017c].
  159. #
  160. reset_db
  161. do_execsql_test 6.0 {
  162. CREATE VIRTUAL TABLE vt0 USING fts5(c0);
  163. WITH s(i) AS (
  164. SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<10000
  165. )
  166. INSERT INTO vt0(c0) SELECT '0' FROM s;
  167. INSERT INTO vt0(vt0, rank) VALUES('crisismerge', 2000);
  168. INSERT INTO vt0(vt0, rank) VALUES('automerge', 0);
  169. } {}
  170. do_execsql_test 6.1 {
  171. INSERT INTO vt0(vt0) VALUES('rebuild');
  172. }
  173. #-------------------------------------------------------------------------
  174. #
  175. reset_db
  176. do_execsql_test 7.0 {
  177. CREATE VIRTUAL TABLE t1 USING fts5(x);
  178. INSERT INTO t1(rowid, x) VALUES(1, 'hello world');
  179. INSERT INTO t1(rowid, x) VALUES(2, 'well said');
  180. INSERT INTO t1(rowid, x) VALUES(3, 'hello said');
  181. INSERT INTO t1(rowid, x) VALUES(4, 'well world');
  182. CREATE TABLE t2 (a, b);
  183. INSERT INTO t2 VALUES(1, 'hello');
  184. INSERT INTO t2 VALUES(2, 'world');
  185. INSERT INTO t2 VALUES(3, 'said');
  186. INSERT INTO t2 VALUES(4, 'hello');
  187. }
  188. do_execsql_test 7.1 {
  189. SELECT rowid FROM t1 WHERE (rowid, x) IN (SELECT a, b FROM t2);
  190. }
  191. do_execsql_test 7.2 {
  192. SELECT rowid FROM t1 WHERE rowid=2 AND t1 = 'hello';
  193. }
  194. #-------------------------------------------------------------------------
  195. #
  196. reset_db
  197. do_execsql_test 8.0 {
  198. CREATE VIRTUAL TABLE vt0 USING fts5(c0, tokenize = "ascii", prefix = 1);
  199. INSERT INTO vt0(c0) VALUES (x'd1');
  200. }
  201. do_execsql_test 8.1 {
  202. INSERT INTO vt0(vt0) VALUES('integrity-check');
  203. }
  204. #-------------------------------------------------------------------------
  205. #
  206. reset_db
  207. do_execsql_test 9.0 {
  208. CREATE VIRTUAL TABLE t1 using FTS5(mailcontent);
  209. insert into t1(rowid, mailcontent) values
  210. (-4764623217061966105, 'we are going to upgrade'),
  211. (8324454597464624651, 'we are going to upgrade');
  212. }
  213. do_execsql_test 9.1 {
  214. INSERT INTO t1(t1) VALUES('integrity-check');
  215. }
  216. do_execsql_test 9.2 {
  217. SELECT rowid FROM t1('upgrade');
  218. } {
  219. -4764623217061966105 8324454597464624651
  220. }
  221. #-------------------------------------------------------------------------
  222. #
  223. reset_db
  224. do_execsql_test 10.0 {
  225. CREATE VIRTUAL TABLE vt1 USING fts5(c1, c2, prefix = 1, tokenize = "ascii");
  226. INSERT INTO vt1 VALUES (x'e4', '䔬');
  227. }
  228. do_execsql_test 10.1 {
  229. SELECT quote(CAST(c1 AS blob)), quote(CAST(c2 AS blob)) FROM vt1
  230. } {X'E4' X'E494AC'}
  231. do_execsql_test 10.2 {
  232. INSERT INTO vt1(vt1) VALUES('integrity-check');
  233. }
  234. #-------------------------------------------------------------------------
  235. #
  236. reset_db
  237. do_execsql_test 11.0 {
  238. CREATE VIRTUAL TABLE vt0 USING fts5(
  239. c0, prefix = 71, tokenize = "porter ascii", prefix = 9
  240. );
  241. } {}
  242. do_execsql_test 11.1 {
  243. BEGIN;
  244. INSERT INTO vt0(c0) VALUES (x'e8');
  245. }
  246. do_execsql_test 11.2 {
  247. INSERT INTO vt0(vt0) VALUES('integrity-check');
  248. }
  249. #-------------------------------------------------------------------------
  250. # Ticket [752fdbf6]
  251. #
  252. reset_db
  253. do_execsql_test 11.0 {
  254. PRAGMA encoding = 'UTF-16';
  255. CREATE VIRTUAL TABLE vt0 USING fts5(c0, c1);
  256. INSERT INTO vt0(vt0, rank) VALUES('pgsz', '37');
  257. INSERT INTO vt0(c0, c1) VALUES (0.66077, 1957391816);
  258. }
  259. do_execsql_test 11.1 {
  260. INSERT INTO vt0(vt0) VALUES('integrity-check');
  261. }
  262. #-------------------------------------------------------------------------
  263. # Ticket [7c0e06b16]
  264. #
  265. do_execsql_test 12.0 {
  266. CREATE TABLE t1(a, b, rank);
  267. INSERT INTO t1 VALUES('a', 'hello', '');
  268. INSERT INTO t1 VALUES('b', 'world', '');
  269. CREATE VIRTUAL TABLE ft USING fts5(a);
  270. INSERT INTO ft VALUES('b');
  271. INSERT INTO ft VALUES('y');
  272. CREATE TABLE t2(x, y, ft);
  273. INSERT INTO t2 VALUES(1, 2, 'x');
  274. INSERT INTO t2 VALUES(3, 4, 'b');
  275. }
  276. do_execsql_test 12.1 {
  277. SELECT * FROM t1 NATURAL JOIN ft WHERE ft MATCH('b')
  278. } {b world {}}
  279. do_execsql_test 12.2 {
  280. SELECT * FROM ft NATURAL JOIN t1 WHERE ft MATCH('b')
  281. } {b world {}}
  282. do_execsql_test 12.3 {
  283. SELECT * FROM t2 JOIN ft USING (ft)
  284. } {3 4 b b}
  285. #-------------------------------------------------------------------------
  286. # Forum post https://sqlite.org/forum/forumpost/21127c1160
  287. #
  288. reset_db
  289. sqlite3_db_config db DEFENSIVE 1
  290. do_execsql_test 13.1.0 {
  291. CREATE TABLE a (id INTEGER PRIMARY KEY, name TEXT);
  292. CREATE VIRTUAL TABLE b USING fts5(name);
  293. CREATE TRIGGER a_trigger AFTER INSERT ON a BEGIN
  294. INSERT INTO b (name) VALUES ('foo');
  295. END;
  296. }
  297. do_test 13.1.1 {
  298. set ::STMT [
  299. sqlite3_prepare db "INSERT INTO a VALUES (1, 'foo') RETURNING id;" -1 dummy
  300. ]
  301. sqlite3_step $::STMT
  302. } {SQLITE_ROW}
  303. do_test 13.1.2 {
  304. sqlite3_finalize $::STMT
  305. } {SQLITE_OK}
  306. do_test 13.1.3 {
  307. sqlite3_errmsg db
  308. } {not an error}
  309. reset_db
  310. sqlite3_db_config db DEFENSIVE 1
  311. do_execsql_test 13.2.0 {
  312. BEGIN;
  313. CREATE TABLE a (id INTEGER PRIMARY KEY, name TEXT);
  314. CREATE VIRTUAL TABLE b USING fts5(name);
  315. CREATE TRIGGER a_trigger AFTER INSERT ON a BEGIN
  316. INSERT INTO b (name) VALUES ('foo');
  317. END;
  318. }
  319. do_test 13.2.1 {
  320. set ::STMT [
  321. sqlite3_prepare db "INSERT INTO a VALUES (1, 'foo') RETURNING id;" -1 dummy
  322. ]
  323. sqlite3_step $::STMT
  324. } {SQLITE_ROW}
  325. do_test 13.2.2 {
  326. sqlite3_finalize $::STMT
  327. } {SQLITE_OK}
  328. do_test 13.2.3 {
  329. sqlite3_errmsg db
  330. } {not an error}
  331. #-------------------------------------------------------------------------
  332. reset_db
  333. db close
  334. sqlite3 db test.db -uri 1
  335. do_execsql_test 14.0 {
  336. PRAGMA locking_mode=EXCLUSIVE;
  337. BEGIN;
  338. ATTACH 'file:/one?vfs=memdb' AS aux1;
  339. ATTACH 'file:/one?vfs=memdb' AS aux2;
  340. CREATE VIRTUAL TABLE t1 USING fts5(x);
  341. } {exclusive}
  342. do_catchsql_test 14.1 {
  343. ANALYZE;
  344. } {1 {database is locked}}
  345. do_catchsql_test 14.2 {
  346. COMMIT;
  347. } {1 {database is locked}}
  348. do_catchsql_test 14.3 {
  349. COMMIT;
  350. } {1 {database is locked}}
  351. do_catchsql_test 14.4 {
  352. ROLLBACK;
  353. } {0 {}}
  354. #-------------------------------------------------------------------------
  355. reset_db
  356. sqlite3 db2 test.db
  357. do_execsql_test 15.0 {
  358. CREATE TABLE t1(a, b);
  359. BEGIN;
  360. SELECT * FROM t1;
  361. }
  362. do_execsql_test -db db2 15.1 {
  363. BEGIN;
  364. CREATE VIRTUAL TABLE x1 USING fts5(y);
  365. }
  366. do_test 15.2 {
  367. list [catch { db2 eval COMMIT } msg] $msg
  368. } {1 {database is locked}}
  369. do_execsql_test -db db2 15.3 {
  370. SAVEPOINT one;
  371. } {}
  372. do_execsql_test 15.4 END
  373. do_test 15.5 {
  374. list [catch { db2 eval COMMIT } msg] $msg
  375. } {0 {}}
  376. db2 close
  377. #-------------------------------------------------------------------------
  378. reset_db
  379. forcedelete test.db2
  380. sqlite3 db2 test.db
  381. do_execsql_test 16.0 {
  382. ATTACH 'test.db2' AS aux;
  383. CREATE TABLE aux.t2(x,y);
  384. INSERT INTO t2 VALUES(1, 2);
  385. CREATE VIRTUAL TABLE x1 USING fts5(a);
  386. BEGIN;
  387. INSERT INTO x1 VALUES('abc');
  388. INSERT INTO t2 VALUES(3, 4);
  389. }
  390. do_execsql_test -db db2 16.1 {
  391. ATTACH 'test.db2' AS aux;
  392. BEGIN;
  393. SELECT * FROM t2
  394. } {1 2}
  395. do_catchsql_test 16.2 {
  396. COMMIT;
  397. } {1 {database is locked}}
  398. do_execsql_test 16.3 {
  399. INSERT INTO x1 VALUES('def');
  400. }
  401. do_execsql_test -db db2 16.4 {
  402. END
  403. }
  404. do_execsql_test 16.5 {
  405. COMMIT
  406. }
  407. do_execsql_test -db db2 16.6 {
  408. SELECT * FROM x1
  409. } {abc def}
  410. db2 close
  411. #-------------------------------------------------------------------------
  412. reset_db
  413. do_execsql_test 17.1 {
  414. CREATE VIRTUAL TABLE ft USING fts5(x, tokenize="unicode61 separators 'X'");
  415. }
  416. do_execsql_test 17.2 {
  417. SELECT 0 FROM ft WHERE ft MATCH 'X' AND ft MATCH 'X'
  418. }
  419. do_execsql_test 17.3 {
  420. SELECT 0 FROM ft('X')
  421. }
  422. do_execsql_test 17.4 {
  423. CREATE VIRTUAL TABLE t0 USING fts5(c0, t="trigram");
  424. INSERT INTO t0 VALUES('assertionfaultproblem');
  425. }
  426. do_execsql_test 17.5 {
  427. SELECT 0 FROM t0(0) WHERE c0 GLOB 0;
  428. } {}
  429. do_execsql_test 17.5 {
  430. SELECT c0 FROM t0 WHERE c0 GLOB '*f*';
  431. } {assertionfaultproblem}
  432. do_execsql_test 17.5 {
  433. SELECT c0 FROM t0 WHERE c0 GLOB '*faul*';
  434. } {assertionfaultproblem}
  435. #-------------------------------------------------------------------------
  436. reset_db
  437. do_execsql_test 18.0 {
  438. BEGIN;
  439. CREATE VIRTUAL TABLE t1 USING fts5(text);
  440. ALTER TABLE t1 RENAME TO t2;
  441. }
  442. do_execsql_test 18.1 {
  443. DROP TABLE t2;
  444. }
  445. do_execsql_test 18.2 {
  446. COMMIT;
  447. }
  448. #-------------------------------------------------------------------------
  449. reset_db
  450. do_execsql_test 19.0 {
  451. CREATE VIRTUAL TABLE t1 USING fts5(text);
  452. CREATE TABLE t2(text);
  453. BEGIN;
  454. INSERT INTO t1 VALUES('one');
  455. INSERT INTO t1 VALUES('two');
  456. INSERT INTO t1 VALUES('three');
  457. INSERT INTO t1 VALUES('one');
  458. INSERT INTO t1 VALUES('two');
  459. INSERT INTO t1 VALUES('three');
  460. SAVEPOINT one;
  461. INSERT INTO t2 VALUES('one');
  462. INSERT INTO t2 VALUES('two');
  463. INSERT INTO t2 VALUES('three');
  464. ROLLBACK TO one;
  465. COMMIT;
  466. }
  467. #-------------------------------------------------------------------------
  468. reset_db
  469. do_execsql_test 20.0 {
  470. CREATE VIRTUAL TABLE x1 USING fts5(a);
  471. INSERT INTO x1(rowid, a) VALUES
  472. (1, 'a b c d'),
  473. (2, 'x b c d'),
  474. (3, 'x y z d'),
  475. (4, 'a y c x');
  476. }
  477. do_execsql_test 20.1 {
  478. SELECT rowid FROM x1 WHERE x1 MATCH 'a' AND x1 MATCH 'b';
  479. } {1}
  480. do_execsql_test 20.2 {
  481. SELECT rowid FROM x1 WHERE x1 MATCH 'a' AND x1 MATCH 'y';
  482. } {4}
  483. do_execsql_test 20.3 {
  484. SELECT rowid FROM x1 WHERE x1 MATCH 'a' OR x1 MATCH 'y';
  485. } {1 4 3}
  486. do_execsql_test 20.4 {
  487. SELECT rowid FROM x1 WHERE x1 MATCH 'a' OR (x1 MATCH 'y' AND x1 MATCH 'd');
  488. } {1 4 3}
  489. do_execsql_test 20.5 {
  490. SELECT rowid FROM x1 WHERE x1 MATCH 'z' OR (x1 MATCH 'a' AND x1 MATCH 'd');
  491. } {3 1}
  492. #-------------------------------------------------------------------------
  493. reset_db
  494. do_execsql_test 21.0 {
  495. CREATE TABLE t1(ii INTEGER, x TEXT, y TEXT);
  496. CREATE VIRTUAL TABLE xyz USING fts5(content_rowid=ii, content=t1, x, y);
  497. INSERT INTO t1 VALUES(1, 'one', 'i');
  498. INSERT INTO t1 VALUES(2, 'two', 'ii');
  499. INSERT INTO t1 VALUES(3, 'tree', 'iii');
  500. INSERT INTO xyz(xyz) VALUES('rebuild');
  501. }
  502. do_execsql_test 21.1 {
  503. UPDATE xyz SET y='TWO' WHERE rowid=2;
  504. UPDATE t1 SET y='TWO' WHERE ii=2;
  505. }
  506. do_execsql_test 21.2 {
  507. PRAGMA integrity_check
  508. } {ok}
  509. breakpoint
  510. sqlite3_db_config db DEFENSIVE 1
  511. do_execsql_test 21.3 {
  512. CREATE TABLE xyz_notashadow(x, y);
  513. DROP TABLE xyz_notashadow;
  514. }
  515. sqlite3_db_config db DEFENSIVE 0
  516. #-------------------------------------------------------------------------
  517. reset_db
  518. do_execsql_test 22.0 {
  519. SELECT fts5(NULL);
  520. } {{}}
  521. do_execsql_test 22.1 {
  522. SELECT count(*) FROM (
  523. SELECT fts5_source_id()
  524. )
  525. } {1}
  526. execsql_pp {
  527. SELECT fts5_source_id()
  528. }
  529. #-------------------------------------------------------------------------
  530. reset_db
  531. do_execsql_test 23.0 {
  532. CREATE VIRTUAL TABLE x1 USING fts5(x);
  533. INSERT INTO x1 VALUES('one + two + three');
  534. INSERT INTO x1 VALUES('one + xyz + three');
  535. INSERT INTO x1 VALUES('xyz + two + xyz');
  536. }
  537. do_execsql_test 23.1 {
  538. SELECT rowid FROM x1('one + two + three');
  539. } {1}
  540. do_execsql_test 23.2 {
  541. SELECT rowid FROM x1('^".." AND one');
  542. } {}
  543. do_execsql_test 23.3 {
  544. SELECT rowid FROM x1('abc NEAR ".." NEAR def');
  545. } {}
  546. #-------------------------------------------------------------------------
  547. reset_db
  548. do_execsql_test 24.0 {
  549. CREATE VIRTUAL TABLE t1 USING fts5(a, detail='none');
  550. INSERT INTO t1(a) VALUES('a');
  551. }
  552. do_execsql_test 24.2 {
  553. SELECT rank FROM ( SELECT rank FROM t1('a NOT "" NOT def') ) ORDER BY 1;
  554. } {-1e-06}
  555. do_execsql_test 24.3 {
  556. SELECT rank FROM ( SELECT rank FROM t1('a NOT � NOT def') ) ORDER BY 1;
  557. } {-1e-06}
  558. do_execsql_test 24.4 {
  559. SELECT rank FROM ( SELECT rank FROM t1('a NOT "" NOT def') );
  560. } {-1e-06}
  561. #-------------------------------------------------------------------------
  562. reset_db
  563. fts5_aux_test_functions db
  564. do_execsql_test 25.0 {
  565. CREATE VIRTUAL TABLE t1 USING fts5(a, detail='none', content='');
  566. INSERT INTO t1(a) VALUES('a b c');
  567. }
  568. do_execsql_test 25.0 {
  569. SELECT fts5_test_poslist(t1) FROM t1('b') ORDER BY rank;
  570. } {{}}
  571. finish_test