fts5corrupt8.test 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # 2024 Aug 28
  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. set testprefix fts5corrupt8
  14. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  15. ifcapable !fts5 {
  16. finish_test
  17. return
  18. }
  19. do_execsql_test 1.0 {
  20. CREATE VIRTUAL TABLE t1 USING fts5(x);
  21. }
  22. do_execsql_test 1.1 {
  23. UPDATE t1_data SET block='hello world' WHERE id=10
  24. }
  25. db close
  26. sqlite3 db test.db
  27. do_catchsql_test 1.2 {
  28. SELECT * FROM t1
  29. } {1 {database disk image is malformed}}
  30. do_catchsql_test 1.3 {
  31. DROP TABLE t1
  32. } {0 {}}
  33. do_execsql_test 1.4 {
  34. SELECT * FROM sqlite_schema
  35. }
  36. do_execsql_test 2.0 {
  37. CREATE VIRTUAL TABLE t1 USING fts5(x);
  38. }
  39. do_execsql_test 2.1 {
  40. UPDATE t1_config SET v=555 WHERE k='version'
  41. }
  42. db close
  43. sqlite3 db test.db
  44. do_catchsql_test 2.2 {
  45. SELECT * FROM t1
  46. } {1 {invalid fts5 file format (found 555, expected 4 or 5) - run 'rebuild'}}
  47. do_catchsql_test 2.3 {
  48. DROP TABLE t1
  49. } {1 {invalid fts5 file format (found 555, expected 4 or 5) - run 'rebuild'}}
  50. do_test 2.4 {
  51. sqlite3_fts5_drop_corrupt_table db main t1
  52. } {}
  53. do_execsql_test 2.5 {
  54. SELECT * FROM sqlite_schema
  55. }
  56. do_execsql_test 3.0 {
  57. CREATE VIRTUAL TABLE t1 USING fts5(x);
  58. }
  59. do_execsql_test 3.1 {
  60. DELETE FROM t1_config;
  61. }
  62. db close
  63. sqlite3 db test.db
  64. do_catchsql_test 3.2 {
  65. SELECT * FROM t1
  66. } {1 {invalid fts5 file format (found 0, expected 4 or 5) - run 'rebuild'}}
  67. do_catchsql_test 3.3 {
  68. DROP TABLE t1
  69. } {1 {invalid fts5 file format (found 0, expected 4 or 5) - run 'rebuild'}}
  70. do_test 3.4 {
  71. sqlite3_db_config db DEFENSIVE 1
  72. } {1}
  73. do_test 3.5 {
  74. sqlite3_fts5_drop_corrupt_table db main t1
  75. } {}
  76. do_test 3.6 {
  77. sqlite3_db_config db DEFENSIVE -1
  78. } {1}
  79. do_execsql_test 3.7 {
  80. SELECT * FROM sqlite_schema
  81. }
  82. finish_test