PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/src/sqlite/test/fts3ao.test

#
Unknown | 220 lines | 199 code | 21 blank | 0 comment | 0 complexity | ededc0bc9b684c4978b540f493d8b18f MD5 | raw file
Possible License(s): BSD-3-Clause
  1. # 2007 June 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. # This file implements regression tests for SQLite library. The
  12. # focus of this script is testing the FTS3 module.
  13. #
  14. # $Id: fts3ao.test,v 1.1 2007/08/20 17:38:42 shess Exp $
  15. #
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. # If SQLITE_ENABLE_FTS3 is not defined, omit this file.
  19. ifcapable !fts3 {
  20. finish_test
  21. return
  22. }
  23. set ::testprefix fts3ao
  24. #---------------------------------------------------------------------
  25. # These tests, fts3ao-1.*, test that ticket #2429 is fixed.
  26. #
  27. db eval {
  28. CREATE VIRTUAL TABLE t1 USING fts3(a, b, c);
  29. INSERT INTO t1(a, b, c) VALUES('one three four', 'one four', 'one four two');
  30. }
  31. do_test fts3ao-1.1 {
  32. execsql {
  33. SELECT rowid, snippet(t1) FROM t1 WHERE c MATCH 'four';
  34. }
  35. } {1 {one <b>four</b> two}}
  36. do_test fts3ao-1.2 {
  37. execsql {
  38. SELECT rowid, snippet(t1) FROM t1 WHERE b MATCH 'four';
  39. }
  40. } {1 {one <b>four</b>}}
  41. do_test fts3ao-1.3 {
  42. execsql {
  43. SELECT rowid, snippet(t1) FROM t1 WHERE a MATCH 'four';
  44. }
  45. } {1 {one three <b>four</b>}}
  46. #---------------------------------------------------------------------
  47. # Test that it is possible to rename an fts3 table.
  48. #
  49. do_test fts3ao-2.1 {
  50. execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
  51. } {t1 t1_content t1_segments t1_segdir}
  52. do_test fts3ao-2.2 {
  53. execsql { ALTER TABLE t1 RENAME to fts_t1; }
  54. } {}
  55. do_test fts3ao-2.3 {
  56. execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; }
  57. } {1 {one three <b>four</b>}}
  58. do_test fts3ao-2.4 {
  59. execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
  60. } {fts_t1 fts_t1_content fts_t1_segments fts_t1_segdir}
  61. # See what happens when renaming the fts3 table fails.
  62. #
  63. do_test fts3ao-2.5 {
  64. catchsql {
  65. CREATE TABLE t1_segdir(a, b, c);
  66. ALTER TABLE fts_t1 RENAME to t1;
  67. }
  68. } {1 {SQL logic error or missing database}}
  69. do_test fts3ao-2.6 {
  70. execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; }
  71. } {1 {one three <b>four</b>}}
  72. do_test fts3ao-2.7 {
  73. execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
  74. } {fts_t1 fts_t1_content fts_t1_segments fts_t1_segdir t1_segdir}
  75. # See what happens when renaming the fts3 table fails inside a transaction.
  76. #
  77. do_test fts3ao-2.8 {
  78. execsql {
  79. BEGIN;
  80. INSERT INTO fts_t1(a, b, c) VALUES('one two three', 'one four', 'one two');
  81. }
  82. } {}
  83. do_test fts3ao-2.9 {
  84. catchsql {
  85. ALTER TABLE fts_t1 RENAME to t1;
  86. }
  87. } {1 {SQL logic error or missing database}}
  88. do_test fts3ao-2.10 {
  89. execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; }
  90. } {1 {one three <b>four</b>}}
  91. do_test fts3ao-2.11 {
  92. execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
  93. } {fts_t1 fts_t1_content fts_t1_segments fts_t1_segdir t1_segdir}
  94. do_test fts3ao-2.12 {
  95. execsql COMMIT
  96. execsql {SELECT a FROM fts_t1}
  97. } {{one three four} {one two three}}
  98. do_test fts3ao-2.12 {
  99. execsql { SELECT a, b, c FROM fts_t1 WHERE c MATCH 'four'; }
  100. } {{one three four} {one four} {one four two}}
  101. #-------------------------------------------------------------------
  102. # Close, delete and reopen the database. The following test should
  103. # be run on an initially empty db.
  104. #
  105. db close
  106. file delete -force test.db test.db-journal
  107. sqlite3 db test.db
  108. do_test fts3ao-3.1 {
  109. execsql {
  110. CREATE VIRTUAL TABLE t1 USING fts3(a, b, c);
  111. INSERT INTO t1(a, b, c) VALUES('one three four', 'one four', 'one two');
  112. SELECT a, b, c FROM t1 WHERE c MATCH 'two';
  113. }
  114. } {{one three four} {one four} {one two}}
  115. # This test was crashing at one point.
  116. #
  117. do_test fts3ao-3.2 {
  118. execsql {
  119. SELECT a, b, c FROM t1 WHERE c MATCH 'two';
  120. CREATE TABLE t3(a, b, c);
  121. SELECT a, b, c FROM t1 WHERE c MATCH 'two';
  122. }
  123. } {{one three four} {one four} {one two} {one three four} {one four} {one two}}
  124. #---------------------------------------------------------------------
  125. # Test that it is possible to rename an fts3 table in an attached
  126. # database.
  127. #
  128. file delete -force test2.db test2.db-journal
  129. do_test fts3ao-3.1 {
  130. execsql {
  131. ATTACH 'test2.db' AS aux;
  132. CREATE VIRTUAL TABLE aux.t1 USING fts3(a, b, c);
  133. INSERT INTO aux.t1(a, b, c) VALUES(
  134. 'neung song sahm', 'neung see', 'neung see song'
  135. );
  136. }
  137. } {}
  138. do_test fts3ao-3.2 {
  139. execsql { SELECT a, b, c FROM aux.t1 WHERE a MATCH 'song'; }
  140. } {{neung song sahm} {neung see} {neung see song}}
  141. do_test fts3ao-3.3 {
  142. execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; }
  143. } {{one three four} {one four} {one two}}
  144. do_test fts3ao-3.4 {
  145. execsql { ALTER TABLE aux.t1 RENAME TO t2 }
  146. } {}
  147. do_test fts3ao-3.2 {
  148. execsql { SELECT a, b, c FROM t2 WHERE a MATCH 'song'; }
  149. } {{neung song sahm} {neung see} {neung see song}}
  150. do_test fts3ao-3.3 {
  151. execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; }
  152. } {{one three four} {one four} {one two}}
  153. #---------------------------------------------------------------------
  154. # Test that it is possible to rename an fts3 table within a
  155. # transaction.
  156. #
  157. do_test fts3ao-4.1 {
  158. execsql {
  159. CREATE VIRTUAL TABLE t4 USING fts3;
  160. INSERT INTO t4 VALUES('the quick brown fox');
  161. }
  162. } {}
  163. do_test fts3ao-4.2 {
  164. execsql {
  165. BEGIN;
  166. INSERT INTO t4 VALUES('jumped over the');
  167. }
  168. } {}
  169. do_test fts3ao-4.3 { execsql { ALTER TABLE t4 RENAME TO t5; } } {}
  170. do_test fts3ao-4.4 { execsql { INSERT INTO t5 VALUES('lazy dog'); } } {}
  171. do_test fts3ao-4.5 { execsql COMMIT } {}
  172. do_test fts3ao-4.6 {
  173. execsql { SELECT * FROM t5 }
  174. } {{the quick brown fox} {jumped over the} {lazy dog}}
  175. do_test fts3ao-4.7 {
  176. execsql {
  177. BEGIN;
  178. INSERT INTO t5 VALUES('Down came a jumbuck to drink at that billabong');
  179. ALTER TABLE t5 RENAME TO t6;
  180. INSERT INTO t6 VALUES('Down came the troopers, one, two, three');
  181. ROLLBACK;
  182. SELECT * FROM t5;
  183. }
  184. } {{the quick brown fox} {jumped over the} {lazy dog}}
  185. # Test that it is possible to rename an FTS4 table. Renaming an FTS4 table
  186. # involves renaming the extra %_docsize and %_stat tables.
  187. #
  188. do_execsql_test 5.1 {
  189. CREATE VIRTUAL TABLE t7 USING FTS4;
  190. INSERT INTO t7 VALUES('coined by a German clinician');
  191. SELECT count(*) FROM sqlite_master WHERE name LIKE 't7%';
  192. SELECT count(*) FROM sqlite_master WHERE name LIKE 't8%';
  193. } {6 0}
  194. do_execsql_test 5.2 {
  195. ALTER TABLE t7 RENAME TO t8;
  196. SELECT count(*) FROM sqlite_master WHERE name LIKE 't7%';
  197. SELECT count(*) FROM sqlite_master WHERE name LIKE 't8%';
  198. } {0 6}
  199. finish_test