fts2r.test 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # 2008 July 29
  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. # These tests exercise the various types of fts2 cursors.
  12. #
  13. # $Id: fts2r.test,v 1.1 2008/07/29 20:38:18 shess Exp $
  14. #
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. # If SQLITE_ENABLE_FTS2 is not defined, omit this file.
  18. ifcapable !fts2 {
  19. finish_test
  20. return
  21. }
  22. #*************************************************************************
  23. # Test table scan (QUERY_GENERIC). This kind of query happens for
  24. # queries with no WHERE clause, or for WHERE clauses which cannot be
  25. # satisfied by an index.
  26. db eval {
  27. DROP TABLE IF EXISTS t1;
  28. CREATE VIRTUAL TABLE t1 USING fts2(c);
  29. INSERT INTO t1 (rowid, c) VALUES (1, 'This is a test');
  30. INSERT INTO t1 (rowid, c) VALUES (2, 'That was a test');
  31. INSERT INTO t1 (rowid, c) VALUES (3, 'This is a test');
  32. }
  33. do_test fts2e-1.1 {
  34. execsql {
  35. SELECT rowid FROM t1 ORDER BY rowid;
  36. }
  37. } {1 2 3}
  38. do_test fts2e-1.2 {
  39. execsql {
  40. SELECT rowid FROM t1 WHERE c LIKE '%test' ORDER BY rowid;
  41. }
  42. } {1 2 3}
  43. do_test fts2e-1.3 {
  44. execsql {
  45. SELECT rowid FROM t1 WHERE c LIKE 'That%' ORDER BY rowid;
  46. }
  47. } {2}
  48. #*************************************************************************
  49. # Test lookup by rowid (QUERY_ROWID). This kind of query happens for
  50. # queries which select by the rowid implicit index.
  51. db eval {
  52. DROP TABLE IF EXISTS t1;
  53. DROP TABLE IF EXISTS t2;
  54. CREATE VIRTUAL TABLE t1 USING fts2(c);
  55. CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, weight INTEGER UNIQUE);
  56. INSERT INTO t2 VALUES (null, 10);
  57. INSERT INTO t1 (rowid, c) VALUES (last_insert_rowid(), 'This is a test');
  58. INSERT INTO t2 VALUES (null, 5);
  59. INSERT INTO t1 (rowid, c) VALUES (last_insert_rowid(), 'That was a test');
  60. INSERT INTO t2 VALUES (null, 20);
  61. INSERT INTO t1 (rowid, c) VALUES (last_insert_rowid(), 'This is a test');
  62. }
  63. # TODO(shess): This actually is doing QUERY_GENERIC? I'd have
  64. # expected QUERY_ROWID in this case, as for a very large table the
  65. # full scan is less efficient.
  66. do_test fts2e-2.1 {
  67. execsql {
  68. SELECT rowid FROM t1 WHERE rowid in (1, 2, 10);
  69. }
  70. } {1 2}
  71. do_test fts2e-2.2 {
  72. execsql {
  73. SELECT t1.rowid, weight FROM t1, t2 WHERE t2.id = t1.rowid ORDER BY weight;
  74. }
  75. } {2 5 1 10 3 20}
  76. do_test fts2e-2.3 {
  77. execsql {
  78. SELECT t1.rowid, weight FROM t1, t2
  79. WHERE t2.weight>5 AND t2.id = t1.rowid ORDER BY weight;
  80. }
  81. } {1 10 3 20}
  82. #*************************************************************************
  83. # Test lookup by MATCH (QUERY_FULLTEXT). This is the fulltext index.
  84. db eval {
  85. DROP TABLE IF EXISTS t1;
  86. DROP TABLE IF EXISTS t2;
  87. CREATE VIRTUAL TABLE t1 USING fts2(c);
  88. CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, weight INTEGER UNIQUE);
  89. INSERT INTO t2 VALUES (null, 10);
  90. INSERT INTO t1 (rowid, c) VALUES (last_insert_rowid(), 'This is a test');
  91. INSERT INTO t2 VALUES (null, 5);
  92. INSERT INTO t1 (rowid, c) VALUES (last_insert_rowid(), 'That was a test');
  93. INSERT INTO t2 VALUES (null, 20);
  94. INSERT INTO t1 (rowid, c) VALUES (last_insert_rowid(), 'This is a test');
  95. }
  96. do_test fts2e-3.1 {
  97. execsql {
  98. SELECT rowid FROM t1 WHERE t1 MATCH 'this' ORDER BY rowid;
  99. }
  100. } {1 3}
  101. do_test fts2e-3.2 {
  102. execsql {
  103. SELECT t1.rowid, weight FROM t1, t2
  104. WHERE t1 MATCH 'this' AND t1.rowid = t2.id ORDER BY weight;
  105. }
  106. } {1 10 3 20}
  107. finish_test