fts5corrupt4.test 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # 2019 May 16
  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. #
  13. source [file join [file dirname [info script]] fts5_common.tcl]
  14. set testprefix fts5corrupt4
  15. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  16. ifcapable !fts5 {
  17. finish_test
  18. return
  19. }
  20. sqlite3_fts5_may_be_corrupt 1
  21. do_execsql_test 1.0 {
  22. CREATE VIRTUAL TABLE ttt USING fts5(a, b);
  23. INSERT INTO ttt
  24. VALUES('e ee eee e ee eee e ee eee', 'eee ee e e e ee eee ee ee');
  25. INSERT INTO ttt SELECT a||a, b||b FROM ttt;
  26. INSERT INTO ttt SELECT a||a, b||b FROM ttt;
  27. }
  28. expr srand(1)
  29. proc mutate {blob i} {
  30. set o [expr {$i % [string length $blob]}]
  31. set a [string range $blob 0 $o-1]
  32. set b [string range $blob $o+1 end]
  33. set v [expr int(rand()*255) - 127]
  34. return "$a[binary format c $v]$b"
  35. }
  36. db func mutate mutate
  37. for {set j 1000} {$j <= 5000} {incr j 1000} {
  38. do_test 1.$j {
  39. for {set i 0} {$i < 1000} {incr i} {
  40. execsql {
  41. BEGIN;
  42. UPDATE ttt_data SET block = mutate(block, $i) WHERE id>10;
  43. }
  44. foreach sql {
  45. {SELECT snippet(ttt, -1, '.', '..', '[', ']'), * FROM ttt('e*')}
  46. {SELECT snippet(ttt, -1, '.', '..', '[', ']'), * FROM ttt('e* NOT ee*')}
  47. } {
  48. catch { execsql $sql }
  49. }
  50. execsql ROLLBACK
  51. }
  52. } {}
  53. }
  54. sqlite3_fts5_may_be_corrupt 0
  55. finish_test