fts5simple2.test 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. # 2015 September 05
  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. source [file join [file dirname [info script]] fts5_common.tcl]
  13. set testprefix fts5simple2
  14. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  15. ifcapable !fts5 {
  16. finish_test
  17. return
  18. }
  19. do_execsql_test 1.0 {
  20. CREATE VIRTUAL TABLE t1 USING fts5(a, detail=none);
  21. INSERT INTO t1 VALUES('a b c');
  22. }
  23. do_execsql_test 1.1 {
  24. SELECT rowid FROM t1('c a b')
  25. } {1}
  26. #-------------------------------------------------------------------------
  27. #
  28. reset_db
  29. do_execsql_test 2.0 {
  30. CREATE VIRTUAL TABLE t1 USING fts5(a, detail=none);
  31. BEGIN;
  32. INSERT INTO t1 VALUES('b c d');
  33. INSERT INTO t1 VALUES('b c d');
  34. COMMIT;
  35. }
  36. do_execsql_test 2.1 {
  37. SELECT rowid FROM t1('b c d')
  38. } {1 2}
  39. #-------------------------------------------------------------------------
  40. #
  41. reset_db
  42. do_execsql_test 3.0 {
  43. CREATE VIRTUAL TABLE t1 USING fts5(a, detail=none);
  44. BEGIN;
  45. INSERT INTO t1 VALUES('b c d');
  46. INSERT INTO t1 VALUES('b c d');
  47. }
  48. do_execsql_test 3.1 {
  49. SELECT rowid FROM t1('b c d'); COMMIT;
  50. } {1 2}
  51. #-------------------------------------------------------------------------
  52. #
  53. reset_db
  54. do_execsql_test 4.0 {
  55. CREATE VIRTUAL TABLE t1 USING fts5(a, detail=none);
  56. BEGIN;
  57. INSERT INTO t1 VALUES('a1 b1 c1');
  58. INSERT INTO t1 VALUES('a2 b2 c2');
  59. INSERT INTO t1 VALUES('a3 b3 c3');
  60. COMMIT;
  61. }
  62. do_execsql_test 4.1 {
  63. SELECT rowid FROM t1('b*');
  64. } {1 2 3}
  65. #-------------------------------------------------------------------------
  66. #
  67. reset_db
  68. do_execsql_test 5.0 {
  69. CREATE VIRTUAL TABLE t1 USING fts5(a, detail=none);
  70. BEGIN;
  71. INSERT INTO t1 VALUES('a1 b1 c1');
  72. INSERT INTO t1 VALUES('a2 b2 c2');
  73. INSERT INTO t1 VALUES('a1 b1 c1');
  74. COMMIT;
  75. }
  76. do_execsql_test 5.1 { SELECT rowid FROM t1('b*') } {1 2 3}
  77. #-------------------------------------------------------------------------
  78. #
  79. reset_db
  80. do_execsql_test 6.0 {
  81. CREATE VIRTUAL TABLE t1 USING fts5(a, detail=full);
  82. BEGIN;
  83. INSERT INTO t1 VALUES('a1 b1 c1');
  84. INSERT INTO t1 VALUES('a1 b1 c1');
  85. INSERT INTO t1 VALUES('a1 b1 c1');
  86. COMMIT;
  87. }
  88. do_execsql_test 6.1 { SELECT rowid FROM t1('a1') ORDER BY rowid DESC } {3 2 1}
  89. do_execsql_test 6.2 { SELECT rowid FROM t1('b1') ORDER BY rowid DESC } {3 2 1}
  90. do_execsql_test 6.3 { SELECT rowid FROM t1('c1') ORDER BY rowid DESC } {3 2 1}
  91. #-------------------------------------------------------------------------
  92. #
  93. reset_db
  94. do_execsql_test 7.0 {
  95. CREATE VIRTUAL TABLE t1 USING fts5(a, detail=none);
  96. BEGIN;
  97. INSERT INTO t1 VALUES('a1 b1');
  98. INSERT INTO t1 VALUES('a1 b2');
  99. COMMIT;
  100. }
  101. do_execsql_test 7.1 { SELECT rowid FROM t1('b*') ORDER BY rowid DESC } {2 1}
  102. do_execsql_test 7.2 { SELECT rowid FROM t1('a1') ORDER BY rowid DESC } {2 1}
  103. #-------------------------------------------------------------------------
  104. #
  105. reset_db
  106. do_execsql_test 8.0 {
  107. CREATE VIRTUAL TABLE t1 USING fts5(a, detail=none);
  108. INSERT INTO t1 VALUES('a1 b1 c1');
  109. INSERT INTO t1 VALUES('a2 b2 c2');
  110. INSERT INTO t1 VALUES('a1 b1 c1');
  111. }
  112. do_execsql_test 8.0.1 { SELECT rowid FROM t1('b*') } {1 2 3}
  113. do_execsql_test 8.0.2 { SELECT rowid FROM t1('a1') } {1 3}
  114. do_execsql_test 8.0.3 { SELECT rowid FROM t1('c2') } {2}
  115. do_execsql_test 8.0.4 { SELECT rowid FROM t1('b*') ORDER BY rowid DESC } {3 2 1}
  116. do_execsql_test 8.0.5 { SELECT rowid FROM t1('a1') ORDER BY rowid DESC } {3 1}
  117. do_execsql_test 8.0.8 { SELECT rowid FROM t1('c2') ORDER BY rowid DESC } {2}
  118. do_execsql_test 8.1.0 { INSERT INTO t1(t1) VALUES('optimize') }
  119. do_execsql_test 8.1.1 { SELECT rowid FROM t1('b*') } {1 2 3}
  120. do_execsql_test 8.1.2 { SELECT rowid FROM t1('a1') } {1 3}
  121. do_execsql_test 8.1.3 { SELECT rowid FROM t1('c2') } {2}
  122. do_execsql_test 8.2.1 { SELECT rowid FROM t1('b*') ORDER BY rowid DESC} {3 2 1}
  123. do_execsql_test 8.2.2 { SELECT rowid FROM t1('a1') ORDER BY rowid DESC} {3 1}
  124. do_execsql_test 8.2.3 { SELECT rowid FROM t1('c2') ORDER BY rowid DESC} {2}
  125. #--------------------------------------------------------------------------
  126. #
  127. reset_db
  128. do_execsql_test 9.0.0 {
  129. CREATE VIRTUAL TABLE t1 USING fts5(a, detail=none);
  130. INSERT INTO t1 VALUES('a1 b1 c1');
  131. INSERT INTO t1 VALUES('a2 b2 c2');
  132. INSERT INTO t1 VALUES('a1 b1 c1');
  133. }
  134. do_execsql_test 9.0.1 {
  135. INSERT INTO t1(t1) VALUES('integrity-check');
  136. } {}
  137. reset_db
  138. do_execsql_test 9.1.0 {
  139. CREATE VIRTUAL TABLE t1 USING fts5(a, b, detail=none);
  140. INSERT INTO t1 VALUES('a1 b1 c1', 'x y z');
  141. INSERT INTO t1 VALUES('a2 b2 c2', '1 2 3');
  142. INSERT INTO t1 VALUES('a1 b1 c1', 'x 2 z');
  143. }
  144. do_execsql_test 9.2.1 {
  145. INSERT INTO t1(t1) VALUES('integrity-check');
  146. } {}
  147. #--------------------------------------------------------------------------
  148. #
  149. reset_db
  150. do_execsql_test 10.0 {
  151. CREATE VIRTUAL TABLE t1 USING fts5(a, detail=none);
  152. INSERT INTO t1 VALUES('b1');
  153. INSERT INTO t1 VALUES('b1');
  154. DELETE FROM t1 WHERE rowid=1;
  155. }
  156. do_execsql_test 10.1 {
  157. SELECT rowid FROM t1('b1');
  158. } {2}
  159. do_execsql_test 10.2 {
  160. SELECT rowid FROM t1('b1') ORDER BY rowid DESC;
  161. } {2}
  162. do_execsql_test 10.3 {
  163. INSERT INTO t1(t1) VALUES('integrity-check');
  164. } {}
  165. #--------------------------------------------------------------------------
  166. #
  167. reset_db
  168. do_execsql_test 11.1 {
  169. CREATE VIRTUAL TABLE t1 USING fts5(x, y, detail=none);
  170. INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
  171. WITH d(x,y) AS (
  172. SELECT NULL, 'xyz' UNION ALL SELECT NULL, 'xyz' FROM d
  173. )
  174. INSERT INTO t1 SELECT * FROM d LIMIT 23;
  175. }
  176. #db eval { SELECT rowid AS r, quote(block) AS b FROM t1_data } { puts "$r: $b" }
  177. do_execsql_test 11.2 {
  178. SELECT rowid FROM t1;
  179. } {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23}
  180. do_execsql_test 11.3 {
  181. SELECT rowid FROM t1('xyz');
  182. } {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23}
  183. do_execsql_test 11.4 {
  184. INSERT INTO t1(t1) VALUES('integrity-check');
  185. }
  186. #-------------------------------------------------------------------------
  187. #
  188. reset_db
  189. do_execsql_test 12.0 {
  190. CREATE VIRTUAL TABLE yy USING fts5(x, detail=none);
  191. INSERT INTO yy VALUES('in if');
  192. INSERT INTO yy VALUES('if');
  193. } {}
  194. do_execsql_test 12.1 {
  195. SELECT rowid FROM yy('i*');
  196. } {1 2}
  197. #-------------------------------------------------------------------------
  198. #
  199. reset_db
  200. do_execsql_test 13.0 {
  201. CREATE VIRTUAL TABLE t1 USING fts5(a, prefix=1, detail=none);
  202. } {}
  203. foreach {rowid a} {
  204. 0 {f}
  205. 1 {u}
  206. 2 {k}
  207. 3 {a}
  208. 4 {a}
  209. 5 {u}
  210. 6 {u}
  211. 7 {u}
  212. 8 {f}
  213. 9 {f}
  214. 10 {a}
  215. 11 {p}
  216. 12 {f}
  217. 13 {u}
  218. 14 {a}
  219. 15 {a}
  220. } {
  221. do_execsql_test 13.1.$rowid {
  222. INSERT INTO t1(rowid, a) VALUES($rowid, $a);
  223. }
  224. }
  225. #-------------------------------------------------------------------------
  226. #
  227. reset_db
  228. fts5_aux_test_functions db
  229. do_execsql_test 14.0 {
  230. CREATE VIRTUAL TABLE t1 USING fts5(a, detail=none);
  231. INSERT INTO t1 VALUES('a b c d');
  232. } {}
  233. do_execsql_test 14.1 {
  234. SELECT fts5_test_poslist(t1) FROM t1('b') ORDER BY rank;
  235. } {0.0.1}
  236. #-------------------------------------------------------------------------
  237. #
  238. reset_db
  239. do_execsql_test 15.1 {
  240. CREATE VIRTUAL TABLE t1 USING fts5(x, detail=none);
  241. BEGIN;
  242. INSERT INTO t1(rowid, x) VALUES(1, 'sqlite');
  243. INSERT INTO t1(rowid, x) VALUES(2, 'sqlite');
  244. COMMIT;
  245. } {}
  246. do_test 15.1 {
  247. execsql { INSERT INTO t1(t1) VALUES('integrity-check') }
  248. } {}
  249. do_test 15.2 {
  250. execsql { DELETE FROM t1 }
  251. } {}
  252. do_execsql_test 15.3.1 {
  253. SELECT rowid FROM t1('sqlite');
  254. } {}
  255. do_execsql_test 15.3.2 {
  256. SELECT rowid FROM t1('sqlite') ORDER BY rowid DESC;
  257. } {}
  258. do_test 15.4 {
  259. execsql { INSERT INTO t1(t1) VALUES('integrity-check') }
  260. } {}
  261. #-------------------------------------------------------------------------
  262. #
  263. reset_db
  264. do_execsql_test 16.0 {
  265. CREATE VIRTUAL TABLE t2 USING fts5(x, detail=none);
  266. BEGIN;
  267. INSERT INTO t2(rowid, x) VALUES(1, 'a b c');
  268. INSERT INTO t2(rowid, x) VALUES(456, 'a b c');
  269. INSERT INTO t2(rowid, x) VALUES(1000, 'a b c');
  270. COMMIT;
  271. UPDATE t2 SET x=x;
  272. }
  273. do_execsql_test 16.1 {
  274. INSERT INTO t2(t2) VALUES('integrity-check');
  275. } {}
  276. do_execsql_test 16.2 {
  277. SELECT rowid FROM t2('b') ORDER BY rowid DESC
  278. } {1000 456 1}
  279. #-------------------------------------------------------------------------
  280. #
  281. reset_db
  282. do_execsql_test 16.0 {
  283. CREATE VIRTUAL TABLE t2 USING fts5(x, detail=none);
  284. BEGIN;
  285. INSERT INTO t2(rowid, x) VALUES(1, 'a b c');
  286. INSERT INTO t2(rowid, x) VALUES(456, 'a b c');
  287. INSERT INTO t2(rowid, x) VALUES(1000, 'a b c');
  288. COMMIT;
  289. UPDATE t2 SET x=x;
  290. DELETE FROM t2;
  291. }
  292. #-------------------------------------------------------------------------
  293. #
  294. reset_db
  295. do_execsql_test 17.0 {
  296. CREATE VIRTUAL TABLE t2 USING fts5(x, y);
  297. BEGIN;
  298. INSERT INTO t2 VALUES('a aa aaa', 'b bb bbb');
  299. INSERT INTO t2 VALUES('a aa aaa', 'b bb bbb');
  300. INSERT INTO t2 VALUES('a aa aaa', 'b bb bbb');
  301. COMMIT;
  302. }
  303. do_execsql_test 17.1 {
  304. SELECT * FROM t2('y:a*') WHERE rowid BETWEEN 10 AND 20
  305. }
  306. do_execsql_test 17.2 {
  307. BEGIN;
  308. INSERT INTO t2 VALUES('a aa aaa', 'b bb bbb');
  309. SELECT * FROM t2('y:a*') WHERE rowid BETWEEN 10 AND 20 ;
  310. }
  311. do_execsql_test 17.3 {
  312. COMMIT
  313. }
  314. reset_db
  315. do_execsql_test 17.4 {
  316. CREATE VIRTUAL TABLE t2 USING fts5(x, y);
  317. BEGIN;
  318. INSERT INTO t2 VALUES('a aa aaa', 'b bb bbb');
  319. INSERT INTO t2 VALUES('a aa aaa', 'b bb bbb');
  320. SELECT * FROM t2('y:a*') WHERE rowid>66;
  321. }
  322. do_execsql_test 17.5 { SELECT * FROM t2('x:b* OR y:a*') }
  323. do_execsql_test 17.5 { COMMIT ; SELECT * FROM t2('x:b* OR y:a*') }
  324. do_execsql_test 17.6 {
  325. SELECT * FROM t2('x:b* OR y:a*') WHERE rowid>55
  326. }
  327. #db eval {SELECT rowid, fts5_decode_none(rowid, block) aS r FROM t2_data} {puts $r}
  328. finish_test