fts5secure5.test 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # 2023 April 14
  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. #
  12. source [file join [file dirname [info script]] fts5_common.tcl]
  13. return_if_no_fts5
  14. set ::testprefix fts5secure5
  15. return_if_no_fts5
  16. proc dump {} {
  17. execsql_pp {
  18. SELECT id, quote(block), fts5_decode_none(id, block) FROM ft1_data
  19. }
  20. }
  21. do_execsql_test 1.0 {
  22. CREATE VIRTUAL TABLE ft1 USING fts5(a, detail=none);
  23. INSERT INTO ft1(ft1, rank) VALUES('secure-delete', 1);
  24. }
  25. do_execsql_test 1.1 {
  26. BEGIN;
  27. INSERT INTO ft1(rowid, a) VALUES(1, 'abcd');
  28. INSERT INTO ft1(rowid, a) VALUES(2, 'abcd');
  29. INSERT INTO ft1(rowid, a) VALUES(3, 'abcd');
  30. COMMIT;
  31. }
  32. do_execsql_test 1.2 {
  33. DELETE FROM ft1 WHERE rowid=1;
  34. }
  35. do_execsql_test 1.3 {
  36. INSERT INTO ft1(ft1) VALUES('integrity-check');
  37. }
  38. do_execsql_test 1.4 {
  39. DELETE FROM ft1 WHERE rowid=3;
  40. }
  41. do_execsql_test 1.5 {
  42. INSERT INTO ft1(ft1) VALUES('integrity-check');
  43. }
  44. do_execsql_test 1.6 {
  45. DELETE FROM ft1 WHERE rowid=3;
  46. }
  47. do_execsql_test 1.7 {
  48. INSERT INTO ft1(ft1) VALUES('integrity-check');
  49. }
  50. #-------------------------------------------------------------------------
  51. reset_db
  52. do_execsql_test 2.0 {
  53. CREATE VIRTUAL TABLE ft1 USING fts5(a, detail=none);
  54. INSERT INTO ft1(ft1, rank) VALUES('secure-delete', 1);
  55. }
  56. do_execsql_test 2.1 {
  57. BEGIN;
  58. INSERT INTO ft1(rowid, a) VALUES(1, 'abcd one');
  59. INSERT INTO ft1(rowid, a) VALUES(2, 'abcd two');
  60. INSERT INTO ft1(rowid, a) VALUES(3, 'abcd two');
  61. INSERT INTO ft1(rowid, a) VALUES(4, 'abcd two');
  62. INSERT INTO ft1(rowid, a) VALUES(5, 'abcd three');
  63. COMMIT;
  64. }
  65. do_execsql_test 2.2a {
  66. DELETE FROM ft1 WHERE rowid=3;
  67. }
  68. do_execsql_test 2.2b {
  69. INSERT INTO ft1(ft1) VALUES('integrity-check');
  70. }
  71. do_execsql_test 2.3a {
  72. DELETE FROM ft1 WHERE rowid=2;
  73. }
  74. do_execsql_test 2.3b {
  75. INSERT INTO ft1(ft1) VALUES('integrity-check');
  76. }
  77. do_execsql_test 2.4a {
  78. DELETE FROM ft1 WHERE rowid=4;
  79. }
  80. do_execsql_test 2.4b {
  81. INSERT INTO ft1(ft1) VALUES('integrity-check');
  82. }
  83. #-------------------------------------------------------------------------
  84. reset_db
  85. do_execsql_test 3.0 {
  86. CREATE VIRTUAL TABLE ft1 USING fts5(a, detail=none, prefix=1);
  87. INSERT INTO ft1(ft1, rank) VALUES('secure-delete', 1);
  88. INSERT INTO ft1(ft1, rank) VALUES('pgsz', 64);
  89. }
  90. do_execsql_test 3.1 {
  91. BEGIN;
  92. INSERT INTO ft1(a) VALUES('c');
  93. COMMIT;
  94. }
  95. do_execsql_test 3.2 {
  96. DELETE FROM ft1 WHERE rowid IN (1);
  97. INSERT INTO ft1(ft1) VALUES('integrity-check');
  98. }
  99. #-------------------------------------------------------------------------
  100. reset_db
  101. do_execsql_test 4.0 {
  102. CREATE VIRTUAL TABLE ft1 USING fts5(a, detail=none);
  103. INSERT INTO ft1(ft1, rank) VALUES('secure-delete', 1);
  104. INSERT INTO ft1(ft1, rank) VALUES('pgsz', 64);
  105. WITH s(i) AS (
  106. SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<500
  107. )
  108. INSERT INTO ft1 SELECT 'abcdefg' FROM s;
  109. }
  110. do_test 4.1 {
  111. for {set i 500} {$i > 0} {incr i -1} {
  112. execsql { DELETE FROM ft1 WHERE rowid=$i }
  113. execsql { INSERT INTO ft1(ft1) VALUES('integrity-check') }
  114. }
  115. } {}
  116. finish_test