fts5ak.test 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. # 2014 November 24
  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. # Specifically, the auxiliary function "highlight".
  15. #
  16. source [file join [file dirname [info script]] fts5_common.tcl]
  17. set testprefix fts5ak
  18. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  19. ifcapable !fts5 {
  20. finish_test
  21. return
  22. }
  23. foreach_detail_mode $testprefix {
  24. do_execsql_test 1.1 {
  25. CREATE VIRTUAL TABLE ft1 USING fts5(x, detail=%DETAIL%);
  26. INSERT INTO ft1 VALUES('i d d a g i b g d d');
  27. INSERT INTO ft1 VALUES('h d b j c c g a c a');
  28. INSERT INTO ft1 VALUES('e j a e f h b f h h');
  29. INSERT INTO ft1 VALUES('j f h d g h i b d f');
  30. INSERT INTO ft1 VALUES('d c j d c j b c g e');
  31. INSERT INTO ft1 VALUES('i a d e g j g d a a');
  32. INSERT INTO ft1 VALUES('j f c e d a h j d b');
  33. INSERT INTO ft1 VALUES('i c c f a d g h j e');
  34. INSERT INTO ft1 VALUES('i d i g c d c h b f');
  35. INSERT INTO ft1 VALUES('g d a e h a b c f j');
  36. CREATE VIRTUAL TABLE ft2 USING fts5(x, detail=%DETAIL%);
  37. INSERT INTO ft2 VALUES('a b c d e f g h i j');
  38. }
  39. do_execsql_test 1.2 {
  40. SELECT highlight(ft1, 0, '[', ']') FROM ft1 WHERE ft1 MATCH 'e';
  41. } {
  42. {[e] j a [e] f h b f h h}
  43. {d c j d c j b c g [e]}
  44. {i a d [e] g j g d a a}
  45. {j f c [e] d a h j d b}
  46. {i c c f a d g h j [e]}
  47. {g d a [e] h a b c f j}
  48. }
  49. do_execsql_test 1.3 {
  50. SELECT highlight(ft1, 0, '[', ']') FROM ft1 WHERE ft1 MATCH 'e e e'
  51. } {
  52. {[e] j a [e] f h b f h h}
  53. {d c j d c j b c g [e]}
  54. {i a d [e] g j g d a a}
  55. {j f c [e] d a h j d b}
  56. {i c c f a d g h j [e]}
  57. {g d a [e] h a b c f j}
  58. }
  59. do_execsql_test 1.4 {
  60. SELECT highlight(ft2, 0, '[', ']') FROM ft2 WHERE ft2 MATCH 'f d'
  61. } {
  62. {a b c [d] e [f] g h i j}
  63. }
  64. do_execsql_test 1.5 {
  65. SELECT highlight(ft2, 0, '[', ']') FROM ft2 WHERE ft2 MATCH 'd f'
  66. } {
  67. {a b c [d] e [f] g h i j}
  68. }
  69. #-------------------------------------------------------------------------
  70. # Tests below this point require detail=full.
  71. #-------------------------------------------------------------------------
  72. if {[detail_is_full]==0} continue
  73. do_execsql_test 2.1 {
  74. SELECT highlight(ft1, 0, '[', ']') FROM ft1 WHERE ft1 MATCH 'h + d';
  75. } {
  76. {[h d] b j c c g a c a}
  77. {j f [h d] g h i b d f}
  78. }
  79. do_execsql_test 2.2 {
  80. SELECT highlight(ft1, 0, '[', ']') FROM ft1 WHERE ft1 MATCH 'd + d';
  81. } {
  82. {i [d d] a g i b g [d d]}
  83. }
  84. do_execsql_test 2.3 {
  85. SELECT highlight(ft1, 0, '[', ']') FROM ft1 WHERE ft1 MATCH 'd + d d + d';
  86. } {
  87. {i [d d] a g i b g [d d]}
  88. }
  89. do_execsql_test 2.4 {
  90. SELECT highlight(ft2, 0, '[', ']') FROM ft2 WHERE ft2 MATCH 'b+c+d c+d+e'
  91. } {{a [b c d e] f g h i j}}
  92. do_execsql_test 2.5 {
  93. SELECT highlight(ft2, 0, '[', ']') FROM ft2 WHERE ft2 MATCH 'b+c+d e+f+g'
  94. } {
  95. {a [b c d] [e f g] h i j}
  96. }
  97. do_execsql_test 2.6 {
  98. SELECT highlight(ft2, 0, '[', ']') FROM ft2 WHERE ft2 MATCH 'b+c+d c'
  99. } {
  100. {a [b c d] e f g h i j}
  101. }
  102. do_execsql_test 2.7 {
  103. SELECT highlight(ft2, 0, '[', ']') FROM ft2 WHERE ft2 MATCH 'b+c c+d+e'
  104. } {
  105. {a [b c d e] f g h i j}
  106. }
  107. #-------------------------------------------------------------------------
  108. # The example from the docs.
  109. #
  110. do_execsql_test 3.1 {
  111. -- Assuming this:
  112. CREATE VIRTUAL TABLE ft USING fts5(a, detail=%DETAIL%);
  113. INSERT INTO ft VALUES('a b c x c d e');
  114. INSERT INTO ft VALUES('a b c c d e');
  115. INSERT INTO ft VALUES('a b c d e');
  116. -- The following SELECT statement returns these three rows:
  117. -- '[a b c] x [c d e]'
  118. -- '[a b c] [c d e]'
  119. -- '[a b c d e]'
  120. SELECT highlight(ft, 0, '[', ']') FROM ft WHERE ft MATCH 'a+b+c AND c+d+e';
  121. } {
  122. {[a b c] x [c d e]}
  123. {[a b c] [c d e]}
  124. {[a b c d e]}
  125. }
  126. do_execsql_test 3.2 {
  127. SELECT highlight(ft, 0, NULL, NULL) FROM ft WHERE ft MATCH 'a+b+c AND c+d+e';
  128. } {
  129. {a b c x c d e}
  130. {a b c c d e}
  131. {a b c d e}
  132. }
  133. }
  134. # 2023-04-06 https://sqlite.org/forum/forumpost/cae4367d9b
  135. #
  136. # This is not a test of FTS5, but rather a test of the of what happens to
  137. # prepared statements that encounter SQLITE_SCHEMA while other prepared
  138. # statements are running. The original problem POC used FTS5, and so
  139. # is seems reasonable to put the test here.
  140. #
  141. # The vdbeaux24.test module in TH3 also tests this same behavior but
  142. # without requiring FTS5 or an other extension.
  143. #
  144. reset_db
  145. db null NULL
  146. do_execsql_test 4.0 {
  147. CREATE TABLE t5(a PRIMARY KEY);
  148. INSERT INTO t5 VALUES(0);
  149. CREATE VIRTUAL TABLE t6 USING fts5(0);
  150. DELETE FROM t6;
  151. CREATE TABLE t7(x);
  152. WITH cte(a) AS (
  153. SELECT a FROM t5
  154. WHERE ((0,0) IN (SELECT 0, LAG(0) OVER (PARTITION BY 0) FROM t6), 0)
  155. < (a,0)
  156. )
  157. SELECT max(a) FROM cte;
  158. } NULL
  159. finish_test