fts1o.test 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # 2007 July 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 focus
  12. # of this script is testing the FTS1 module rename functionality. Mostly
  13. # copied from fts2o.test.
  14. #
  15. # $Id: fts1o.test,v 1.2 2007/08/30 20:01:33 shess Exp $
  16. #
  17. set testdir [file dirname $argv0]
  18. source $testdir/tester.tcl
  19. # If SQLITE_ENABLE_FTS1 is not defined, omit this file.
  20. ifcapable !fts1 {
  21. finish_test
  22. return
  23. }
  24. db eval {
  25. CREATE VIRTUAL TABLE t1 USING fts1(a, b, c);
  26. INSERT INTO t1(a, b, c) VALUES('one three four', 'one four', 'one four two');
  27. }
  28. #---------------------------------------------------------------------
  29. # Test that it is possible to rename an fts1 table.
  30. #
  31. do_test fts1o-1.1 {
  32. execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
  33. } {t1 t1_content t1_term}
  34. do_test fts1o-1.2 {
  35. execsql { ALTER TABLE t1 RENAME to fts_t1; }
  36. } {}
  37. do_test fts1o-1.3 {
  38. execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; }
  39. } {1 {one three <b>four</b>}}
  40. do_test fts1o-1.4 {
  41. execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
  42. } {fts_t1 fts_t1_content fts_t1_term}
  43. # See what happens when renaming the fts1 table fails.
  44. #
  45. do_test fts1o-2.1 {
  46. catchsql {
  47. CREATE TABLE t1_term(a, b, c);
  48. ALTER TABLE fts_t1 RENAME to t1;
  49. }
  50. } {1 {SQL logic error or missing database}}
  51. do_test fts1o-2.2 {
  52. execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; }
  53. } {1 {one three <b>four</b>}}
  54. do_test fts1o-2.3 {
  55. execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
  56. } {fts_t1 fts_t1_content fts_t1_term t1_term}
  57. # See what happens when renaming the fts1 table fails inside a transaction.
  58. #
  59. do_test fts1o-3.1 {
  60. execsql {
  61. BEGIN;
  62. INSERT INTO fts_t1(a, b, c) VALUES('one two three', 'one four', 'one two');
  63. }
  64. } {}
  65. do_test fts1o-3.2 {
  66. catchsql {
  67. ALTER TABLE fts_t1 RENAME to t1;
  68. }
  69. } {1 {SQL logic error or missing database}}
  70. # NOTE(shess) rowid AS rowid to defeat caching. Otherwise, this
  71. # seg-faults, I suspect that there's something up with a stale
  72. # virtual-table reference, but I'm not quite sure how it happens here
  73. # but not for fts2o.test.
  74. do_test fts1o-3.3 {
  75. execsql { SELECT rowid AS rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; }
  76. } {1 {one three <b>four</b>}}
  77. do_test fts1o-3.4 {
  78. execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
  79. } {fts_t1 fts_t1_content fts_t1_term t1_term}
  80. do_test fts1o-3.5 {
  81. execsql COMMIT
  82. execsql {SELECT a FROM fts_t1}
  83. } {{one three four} {one two three}}
  84. do_test fts1o-3.6 {
  85. execsql { SELECT a, b, c FROM fts_t1 WHERE c MATCH 'four'; }
  86. } {{one three four} {one four} {one four two}}
  87. #---------------------------------------------------------------------
  88. # Test that it is possible to rename an fts1 table in an attached
  89. # database.
  90. #
  91. forcedelete test2.db test2.db-journal
  92. do_test fts1o-4.1 {
  93. execsql {
  94. DROP TABLE t1_term;
  95. ALTER TABLE fts_t1 RENAME to t1;
  96. SELECT a, b, c FROM t1 WHERE c MATCH 'two';
  97. }
  98. } {{one three four} {one four} {one four two} {one two three} {one four} {one two}}
  99. do_test fts1o-4.2 {
  100. execsql {
  101. ATTACH 'test2.db' AS aux;
  102. CREATE VIRTUAL TABLE aux.t1 USING fts1(a, b, c);
  103. INSERT INTO aux.t1(a, b, c) VALUES(
  104. 'neung song sahm', 'neung see', 'neung see song'
  105. );
  106. }
  107. } {}
  108. do_test fts1o-4.3 {
  109. execsql { SELECT a, b, c FROM aux.t1 WHERE a MATCH 'song'; }
  110. } {{neung song sahm} {neung see} {neung see song}}
  111. do_test fts1o-4.4 {
  112. execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; }
  113. } {{one three four} {one four} {one four two} {one two three} {one four} {one two}}
  114. do_test fts1o-4.5 {
  115. execsql { ALTER TABLE aux.t1 RENAME TO t2 }
  116. } {}
  117. do_test fts1o-4.6 {
  118. execsql { SELECT a, b, c FROM t2 WHERE a MATCH 'song'; }
  119. } {{neung song sahm} {neung see} {neung see song}}
  120. do_test fts1o-4.7 {
  121. execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; }
  122. } {{one three four} {one four} {one four two} {one two three} {one four} {one two}}
  123. finish_test