fts5secure3.test 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. # 2023 Feb 17
  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. # TESTRUNNER: slow
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. ifcapable !fts5 { finish_test ; return }
  16. set ::testprefix fts5secure3
  17. do_execsql_test 1.0 {
  18. CREATE VIRTUAL TABLE ft USING fts5(col);
  19. INSERT INTO ft VALUES('data for the table');
  20. INSERT INTO ft VALUES('more of the same');
  21. INSERT INTO ft VALUES('and extra data');
  22. INSERT INTO ft(ft, rank) VALUES('secure-delete', 1);
  23. }
  24. do_execsql_test 1.1 {
  25. BEGIN;
  26. INSERT INTO ft(rowid, col) VALUES(0, 'the next data');
  27. DELETE FROM ft WHERE rowid=1;
  28. DELETE FROM ft WHERE rowid=2;
  29. INSERT INTO ft(rowid, col) VALUES(6, 'with some more of the same data');
  30. COMMIT;
  31. }
  32. do_execsql_test 1.2 {
  33. INSERT INTO ft(ft) VALUES('integrity-check');
  34. }
  35. #-------------------------------------------------------------------------
  36. reset_db
  37. do_execsql_test 2.0 {
  38. CREATE VIRTUAL TABLE t1 USING fts5(x);
  39. INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
  40. INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
  41. BEGIN;
  42. INSERT INTO t1 VALUES('the start');
  43. }
  44. do_test 2.1 {
  45. for {set i 0} {$i < 1000} {incr i} {
  46. execsql { INSERT INTO t1 VALUES('the ' || hex(randomblob(3))) }
  47. }
  48. execsql {
  49. INSERT INTO t1 VALUES('the end');
  50. COMMIT;
  51. }
  52. } {}
  53. do_execsql_test 2.2 {
  54. DELETE FROM t1 WHERE rowid BETWEEN 2 AND 1000;
  55. }
  56. do_execsql_test 2.3 {
  57. INSERT INTO t1(t1) VALUES('integrity-check');
  58. }
  59. do_execsql_test 2.6 {
  60. INSERT INTO t1(rowid, x) VALUES(500, 'middle');
  61. INSERT INTO t1(rowid, x) VALUES(501, 'value');
  62. SELECT * FROM t1('the middle');
  63. }
  64. do_execsql_test 2.7 {
  65. INSERT INTO t1(t1) VALUES('optimize');
  66. }
  67. do_execsql_test 2.8 {
  68. SELECT count(*) FROM t1_data
  69. } 4
  70. #execsql_pp { SELECT id, quote(block), fts5_decode(id, block) FROM t1_data; }
  71. #-------------------------------------------------------------------------
  72. # Tests with large/small rowid values.
  73. #
  74. foreach {tn cfg} {
  75. 1 ""
  76. 2 "INSERT INTO fff(fff, rank) VALUES('secure-delete', 1)"
  77. } {
  78. reset_db
  79. expr srand(0)
  80. set vocab {
  81. Popper Poppins Popsicle Porfirio Porrima Porsche
  82. Porter Portia Portland Portsmouth Portugal Portuguese
  83. Poseidon Post PostgreSQL Potemkin Potomac Potsdam
  84. Pottawatomie Potter Potts Pound Poussin Powell
  85. PowerPC PowerPoint Powers Powhatan Poznan Prada
  86. Prado Praetorian Prague Praia Prakrit Pratchett
  87. Pratt Pravda Praxiteles Preakness Precambrian Preminger
  88. Premyslid Prensa Prentice Pres Presbyterian Presbyterianism
  89. }
  90. proc newdoc {} {
  91. for {set i 0} {$i<8} {incr i} {
  92. lappend ret [lindex $::vocab [expr int(abs(rand()) * [llength $::vocab])]]
  93. }
  94. set ret
  95. }
  96. db func newdoc newdoc
  97. do_execsql_test 3.$tn.0 {
  98. CREATE VIRTUAL TABLE fff USING fts5(y);
  99. INSERT INTO fff(fff, rank) VALUES('pgsz', 64);
  100. WITH s(x) AS ( VALUES(1) UNION ALL SELECT x+1 FROM s WHERE x<1000 )
  101. INSERT INTO fff(rowid, y) SELECT random() , newdoc() FROM s;
  102. WITH s(x) AS ( VALUES(1) UNION ALL SELECT x+1 FROM s WHERE x<1000 )
  103. INSERT INTO fff(rowid, y) SELECT random() , newdoc() FROM s;
  104. WITH s(x) AS ( VALUES(1) UNION ALL SELECT x+1 FROM s WHERE x<1000 )
  105. INSERT INTO fff(rowid, y) SELECT random() , newdoc() FROM s;
  106. }
  107. execsql $cfg
  108. proc lshuffle {in} {
  109. set out [list]
  110. while {[llength $in]>0} {
  111. set idx [expr int(abs(rand()) * [llength $in])]
  112. lappend out [lindex $in $idx]
  113. set in [lreplace $in $idx $idx]
  114. }
  115. set out
  116. }
  117. #dump fff
  118. set iTest 1
  119. foreach ii [lshuffle [db eval {SELECT rowid FROM fff}]] {
  120. #if {$iTest==1} { dump fff }
  121. #if {$iTest==1} { breakpoint }
  122. do_execsql_test 3.$tn.1.$iTest.$ii {
  123. DELETE FROM fff WHERE rowid=$ii;
  124. }
  125. #if {$iTest==1} { dump fff }
  126. if {($iTest % 20)==0} {
  127. do_execsql_test 3.$tn.1.$iTest.$ii.ic {
  128. INSERT INTO fff(fff) VALUES('integrity-check');
  129. }
  130. }
  131. #if {$iTest==1} { break }
  132. incr iTest
  133. }
  134. }
  135. #execsql_pp { SELECT rowid FROM fff('post') ORDER BY rowid ASC }
  136. #breakpoint
  137. #execsql_pp {
  138. # SELECT rowid FROM fff('post') ORDER BY rowid DESC
  139. #}
  140. #
  141. #dump fff
  142. finish_test