fts5delete.test 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. # 2017 May 12
  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 FTS5 module.
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. set testprefix fts5delete
  16. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  17. ifcapable !fts5 {
  18. finish_test
  19. return
  20. }
  21. fts5_aux_test_functions db
  22. do_execsql_test 1.0 {
  23. CREATE VIRTUAL TABLE t1 USING fts5(x);
  24. WITH s(i) AS (
  25. SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<5000
  26. )
  27. INSERT INTO t1(rowid, x) SELECT i, (i/2)*2 FROM s;
  28. }
  29. do_test 1.1 {
  30. execsql BEGIN
  31. for {set i 1} {$i<=5000} {incr i} {
  32. if {$i % 2} {
  33. execsql { INSERT INTO t1 VALUES($i) }
  34. } else {
  35. execsql { DELETE FROM t1 WHERE rowid = $i }
  36. }
  37. }
  38. execsql COMMIT
  39. } {}
  40. do_test 1.2 {
  41. execsql { INSERT INTO t1(t1, rank) VALUES('usermerge', 2); }
  42. for {set i 0} {$i < 5} {incr i} {
  43. execsql { INSERT INTO t1(t1, rank) VALUES('merge', 1) }
  44. execsql { INSERT INTO t1(t1) VALUES('integrity-check') }
  45. }
  46. } {}
  47. #-------------------------------------------------------------------------
  48. reset_db
  49. do_execsql_test 2.0 {
  50. CREATE TABLE test (
  51. id INTEGER PRIMARY KEY,
  52. name TEXT,
  53. value TEXT
  54. );
  55. CREATE VIRTUAL TABLE test_idx USING fts5(
  56. name, content=test, content_rowid=id
  57. );
  58. }
  59. do_catchsql_test 2.1 {
  60. INSERT INTO test_idx (test_idx, rowid, name) VALUES('delete', 1, 'quick');
  61. } {1 {database disk image is malformed}}
  62. do_catchsql_test 2.2 {
  63. INSERT INTO test_idx(rowid, name) VALUES(123, 'one one one');
  64. INSERT INTO test_idx (test_idx, rowid, name) VALUES('delete', 123, 'one');
  65. INSERT INTO test_idx (test_idx, rowid, name) VALUES('delete', 123, 'one');
  66. } {1 {database disk image is malformed}}
  67. do_execsql_test 2.3 {
  68. DROP TABLE test_idx;
  69. CREATE VIRTUAL TABLE test_idx USING fts5(
  70. name, content=test, content_rowid=id
  71. );
  72. INSERT INTO test_idx(rowid, name) VALUES(123, 'one one one');
  73. INSERT INTO test_idx(rowid, name) VALUES(124, 'two two two');
  74. INSERT INTO test_idx(rowid, name) VALUES(125, 'two two two');
  75. INSERT INTO test_idx (test_idx, rowid, name) VALUES('delete', 123, 'one');
  76. INSERT INTO test_idx (test_idx, rowid, name) VALUES('delete', 123, 'one');
  77. INSERT INTO test_idx (test_idx, rowid, name) VALUES('delete', 123, 'one');
  78. }
  79. do_catchsql_test 2.4 {
  80. SELECT rowid FROM test_idx WHERE test_idx MATCH 'two' ORDER BY rank;
  81. } {1 {database disk image is malformed}}
  82. #-------------------------------------------------------------------------
  83. reset_db
  84. do_execsql_test 3.0 {
  85. CREATE VIRTUAL TABLE tx USING fts5(a, b, c, d, content=);
  86. INSERT INTO tx(rowid, a, c) VALUES(1, 'abc def', 'a b c');
  87. INSERT INTO tx(rowid, a, c) VALUES(5, 'a b c', 'a b d def');
  88. }
  89. do_execsql_test 3.1 {
  90. INSERT INTO tx(tx, rowid, a, b, c, d)
  91. VALUES('delete', 5, 'a b c', NULL, 'a b d def', NULL);
  92. }
  93. do_execsql_test 3.2 {
  94. INSERT INTO tx(tx) VALUES('integrity-check');
  95. }
  96. do_execsql_test 3.3 {
  97. INSERT INTO tx(tx, rowid, a, b, c, d)
  98. VALUES('delete', 1, 'abc def', NULL, 'a b c', NULL);
  99. }
  100. do_execsql_test 3.4 {
  101. INSERT INTO tx(tx) VALUES('integrity-check');
  102. }
  103. #-------------------------------------------------------------------------
  104. reset_db
  105. do_execsql_test 4.0 {
  106. CREATE VIRTUAL TABLE ft1 USING fts5(a, b UNINDEXED,
  107. content='', contentless_unindexed=1
  108. );
  109. CREATE VIRTUAL TABLE ft2 USING fts5(a, b UNINDEXED,
  110. content='', contentless_unindexed=1, contentless_delete=1
  111. );
  112. INSERT INTO ft1(rowid, a, b) VALUES(1, 'one', 'i');
  113. INSERT INTO ft1(rowid, a, b) VALUES(2, 'two', 'ii');
  114. INSERT INTO ft1(rowid, a, b) VALUES(3, 'three', 'iii');
  115. INSERT INTO ft2(rowid, a, b) VALUES(1, 'one', 'i');
  116. INSERT INTO ft2(rowid, a, b) VALUES(2, 'two', 'ii');
  117. INSERT INTO ft2(rowid, a, b) VALUES(3, 'three', 'iii');
  118. }
  119. do_catchsql_test 4.1 {
  120. DELETE FROM ft1 WHERE rowid=2
  121. } {1 {cannot DELETE from contentless fts5 table: ft1}}
  122. do_catchsql_test 4.2 {
  123. DELETE FROM ft2 WHERE rowid=2
  124. } {0 {}}
  125. do_catchsql_test 4.3 {
  126. INSERT INTO ft1(ft1, rowid, a) VALUES('delete', 2, 'two');
  127. } {0 {}}
  128. do_catchsql_test 4.2 {
  129. INSERT INTO ft2(ft2, rowid, a) VALUES('delete', 2, 'two');
  130. } {1 {'delete' may not be used with a contentless_delete=1 table}}
  131. do_execsql_test 4.3 {
  132. SELECT rowid, * FROM ft1;
  133. } {
  134. 1 {} i
  135. 3 {} iii
  136. }
  137. do_execsql_test 4.4 {
  138. SELECT rowid, * FROM ft2;
  139. } {
  140. 1 {} i
  141. 3 {} iii
  142. }
  143. do_execsql_test 4.5 {
  144. SELECT * FROM ft1_content
  145. } {1 i 3 iii}
  146. do_execsql_test 4.6 {
  147. SELECT * FROM ft2_content
  148. } {1 i 3 iii}
  149. finish_test