fts5corrupt6.test 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # 2015 Apr 24
  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. # This file tests that FTS5 handles corrupt databases (i.e. internal
  13. # inconsistencies in the backing tables) correctly. In this case
  14. # "correctly" means without crashing.
  15. #
  16. source [file join [file dirname [info script]] fts5_common.tcl]
  17. set testprefix fts5corrupt6
  18. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  19. ifcapable !fts5 {
  20. finish_test
  21. return
  22. }
  23. sqlite3_fts5_may_be_corrupt 1
  24. database_may_be_corrupt
  25. proc editblock {block} {
  26. binary format Sa* 20000 [string range $block 2 end]
  27. }
  28. db func editblock editblock
  29. do_execsql_test 1.0 {
  30. CREATE VIRTUAL TABLE ft USING fts5(abc, def);
  31. WITH a(i) AS (
  32. SELECT 1 UNION ALL SELECT i+1 FROM a WHERE i<1000
  33. )
  34. INSERT INTO ft SELECT
  35. 'abc abc abc abc abc abc abc abc abc abc',
  36. 'def def def def def def def def def def'
  37. FROM a;
  38. UPDATE ft_data SET block = editblock(block) WHERE id=(
  39. SELECT id FROM ft_data ORDER BY id LIMIT 1 OFFSET 5
  40. );
  41. }
  42. do_catchsql_test 1.1 {
  43. SELECT rowid FROM ft('def') ORDER BY rowid DESC LIMIT 1 OFFSET 9999;
  44. } {1 {database disk image is malformed}}
  45. sqlite3_fts5_may_be_corrupt 0
  46. finish_test