fts1f.test 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # 2006 October 19
  2. #
  3. # The author disclaims copyright to this source code.
  4. #
  5. #*************************************************************************
  6. # This file implements regression tests for SQLite library. The
  7. # focus of this script is testing updates in the FTS1 module.
  8. #
  9. # $Id: fts1f.test,v 1.2 2007/02/23 00:14:06 shess Exp $
  10. #
  11. set testdir [file dirname $argv0]
  12. source $testdir/tester.tcl
  13. # If SQLITE_ENABLE_FTS1 is defined, omit this file.
  14. ifcapable !fts1 {
  15. finish_test
  16. return
  17. }
  18. # Construct a full-text search table containing keywords which are the
  19. # ordinal numbers of the bit positions set for a sequence of integers,
  20. # which are used for the rowid. There are a total of 31 INSERT,
  21. # UPDATE, and DELETE statements, so that we'll test both the
  22. # segmentMerge() merge (over the first 16) and the termSelect() merge
  23. # (over the level-1 segment and 15 level-0 segments).
  24. db eval {
  25. CREATE VIRTUAL TABLE t1 USING fts1(content);
  26. INSERT INTO t1 (rowid, content) VALUES(1, 'one');
  27. INSERT INTO t1 (rowid, content) VALUES(2, 'two');
  28. INSERT INTO t1 (rowid, content) VALUES(3, 'one two');
  29. INSERT INTO t1 (rowid, content) VALUES(4, 'three');
  30. INSERT INTO t1 (rowid, content) VALUES(5, 'one three');
  31. INSERT INTO t1 (rowid, content) VALUES(6, 'two three');
  32. INSERT INTO t1 (rowid, content) VALUES(7, 'one two three');
  33. DELETE FROM t1 WHERE rowid = 4;
  34. INSERT INTO t1 (rowid, content) VALUES(8, 'four');
  35. UPDATE t1 SET content = 'update one three' WHERE rowid = 1;
  36. INSERT INTO t1 (rowid, content) VALUES(9, 'one four');
  37. INSERT INTO t1 (rowid, content) VALUES(10, 'two four');
  38. DELETE FROM t1 WHERE rowid = 7;
  39. INSERT INTO t1 (rowid, content) VALUES(11, 'one two four');
  40. INSERT INTO t1 (rowid, content) VALUES(12, 'three four');
  41. INSERT INTO t1 (rowid, content) VALUES(13, 'one three four');
  42. DELETE FROM t1 WHERE rowid = 10;
  43. INSERT INTO t1 (rowid, content) VALUES(14, 'two three four');
  44. INSERT INTO t1 (rowid, content) VALUES(15, 'one two three four');
  45. UPDATE t1 SET content = 'update two five' WHERE rowid = 8;
  46. INSERT INTO t1 (rowid, content) VALUES(16, 'five');
  47. DELETE FROM t1 WHERE rowid = 13;
  48. INSERT INTO t1 (rowid, content) VALUES(17, 'one five');
  49. INSERT INTO t1 (rowid, content) VALUES(18, 'two five');
  50. INSERT INTO t1 (rowid, content) VALUES(19, 'one two five');
  51. DELETE FROM t1 WHERE rowid = 16;
  52. INSERT INTO t1 (rowid, content) VALUES(20, 'three five');
  53. INSERT INTO t1 (rowid, content) VALUES(21, 'one three five');
  54. INSERT INTO t1 (rowid, content) VALUES(22, 'two three five');
  55. DELETE FROM t1 WHERE rowid = 19;
  56. UPDATE t1 SET content = 'update' WHERE rowid = 15;
  57. }
  58. do_test fts1f-1.1 {
  59. execsql {SELECT COUNT(*) FROM t1}
  60. } {16}
  61. do_test fts1f-2.0 {
  62. execsql {SELECT rowid FROM t1 WHERE content MATCH 'update'}
  63. } {1 8 15}
  64. do_test fts1f-2.1 {
  65. execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'}
  66. } {1 3 5 9 11 17 21}
  67. do_test fts1f-2.2 {
  68. execsql {SELECT rowid FROM t1 WHERE content MATCH 'two'}
  69. } {2 3 6 8 11 14 18 22}
  70. do_test fts1f-2.3 {
  71. execsql {SELECT rowid FROM t1 WHERE content MATCH 'three'}
  72. } {1 5 6 12 14 20 21 22}
  73. do_test fts1f-2.4 {
  74. execsql {SELECT rowid FROM t1 WHERE content MATCH 'four'}
  75. } {9 11 12 14}
  76. do_test fts1f-2.5 {
  77. execsql {SELECT rowid FROM t1 WHERE content MATCH 'five'}
  78. } {8 17 18 20 21 22}
  79. finish_test