fts3ak.test 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # 2007 March 9
  2. #
  3. # The author disclaims copyright to this source code.
  4. #
  5. #*************************************************************************
  6. # This file implements regression tests for SQLite library. These
  7. # make sure that fts3 insertion buffering is fully transparent when
  8. # using transactions.
  9. #
  10. # $Id: fts3ak.test,v 1.1 2007/08/20 17:38:42 shess Exp $
  11. #
  12. set testdir [file dirname $argv0]
  13. source $testdir/tester.tcl
  14. # If SQLITE_ENABLE_FTS3 is defined, omit this file.
  15. ifcapable !fts3 {
  16. finish_test
  17. return
  18. }
  19. db eval {
  20. CREATE VIRTUAL TABLE t1 USING fts3(content);
  21. INSERT INTO t1 (rowid, content) VALUES(1, "hello world");
  22. INSERT INTO t1 (rowid, content) VALUES(2, "hello there");
  23. INSERT INTO t1 (rowid, content) VALUES(3, "cruel world");
  24. }
  25. # Test that possibly-buffered inserts went through after commit.
  26. do_test fts3ak-1.1 {
  27. execsql {
  28. BEGIN TRANSACTION;
  29. INSERT INTO t1 (rowid, content) VALUES(4, "false world");
  30. INSERT INTO t1 (rowid, content) VALUES(5, "false door");
  31. COMMIT TRANSACTION;
  32. SELECT rowid FROM t1 WHERE t1 MATCH 'world';
  33. }
  34. } {1 3 4}
  35. # Test that buffered inserts are seen by selects in the same
  36. # transaction.
  37. do_test fts3ak-1.2 {
  38. execsql {
  39. BEGIN TRANSACTION;
  40. INSERT INTO t1 (rowid, content) VALUES(6, "another world");
  41. INSERT INTO t1 (rowid, content) VALUES(7, "another test");
  42. SELECT rowid FROM t1 WHERE t1 MATCH 'world';
  43. COMMIT TRANSACTION;
  44. }
  45. } {1 3 4 6}
  46. # Test that buffered inserts are seen within a transaction. This is
  47. # really the same test as 1.2.
  48. do_test fts3ak-1.3 {
  49. execsql {
  50. BEGIN TRANSACTION;
  51. INSERT INTO t1 (rowid, content) VALUES(8, "second world");
  52. INSERT INTO t1 (rowid, content) VALUES(9, "second sight");
  53. SELECT rowid FROM t1 WHERE t1 MATCH 'world';
  54. ROLLBACK TRANSACTION;
  55. }
  56. } {1 3 4 6 8}
  57. # Double-check that the previous result doesn't persist past the
  58. # rollback!
  59. do_test fts3ak-1.4 {
  60. execsql {
  61. SELECT rowid FROM t1 WHERE t1 MATCH 'world';
  62. }
  63. } {1 3 4 6}
  64. # Test it all together.
  65. do_test fts3ak-1.5 {
  66. execsql {
  67. BEGIN TRANSACTION;
  68. INSERT INTO t1 (rowid, content) VALUES(10, "second world");
  69. INSERT INTO t1 (rowid, content) VALUES(11, "second sight");
  70. ROLLBACK TRANSACTION;
  71. SELECT rowid FROM t1 WHERE t1 MATCH 'world';
  72. }
  73. } {1 3 4 6}
  74. # Test that the obvious case works.
  75. do_test fts3ak-1.6 {
  76. execsql {
  77. BEGIN;
  78. INSERT INTO t1 (rowid, content) VALUES(12, "third world");
  79. COMMIT;
  80. SELECT rowid FROM t1 WHERE t1 MATCH 'third';
  81. }
  82. } {12}
  83. # This is exactly the same as the previous test, except that older
  84. # code loses the INSERT due to an SQLITE_SCHEMA error.
  85. do_test fts3ak-1.7 {
  86. execsql {
  87. BEGIN;
  88. INSERT INTO t1 (rowid, content) VALUES(13, "third dimension");
  89. CREATE TABLE x (c);
  90. COMMIT;
  91. SELECT rowid FROM t1 WHERE t1 MATCH 'dimension';
  92. }
  93. } {13}
  94. finish_test