fts5version.test 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. # The tests in this file focus on testing that unrecognized file-format
  13. # versions are detected and reported.
  14. #
  15. source [file join [file dirname [info script]] fts5_common.tcl]
  16. set testprefix fts5version
  17. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  18. ifcapable !fts5 {
  19. finish_test
  20. return
  21. }
  22. do_execsql_test 1.1 {
  23. CREATE VIRTUAL TABLE t1 USING fts5(one);
  24. INSERT INTO t1 VALUES('a b c d');
  25. } {}
  26. do_execsql_test 1.2 {
  27. SELECT * FROM t1_config WHERE k='version'
  28. } {version 4}
  29. do_execsql_test 1.3 {
  30. SELECT rowid FROM t1 WHERE t1 MATCH 'a';
  31. } {1}
  32. sqlite3_db_config db DEFENSIVE 0
  33. do_execsql_test 1.4 {
  34. UPDATE t1_config set v=6 WHERE k='version';
  35. }
  36. do_test 1.5 {
  37. db close
  38. sqlite3 db test.db
  39. catchsql { SELECT * FROM t1 WHERE t1 MATCH 'a' }
  40. } {1 {invalid fts5 file format (found 6, expected 4 or 5) - run 'rebuild'}}
  41. do_test 1.6 {
  42. db close
  43. sqlite3 db test.db
  44. catchsql { INSERT INTO t1 VALUES('x y z') }
  45. } {1 {invalid fts5 file format (found 6, expected 4 or 5) - run 'rebuild'}}
  46. do_test 1.7 {
  47. sqlite3_db_config db DEFENSIVE 0
  48. execsql { DELETE FROM t1_config WHERE k='version' }
  49. db close
  50. sqlite3 db test.db
  51. catchsql { SELECT * FROM t1 WHERE t1 MATCH 'a' }
  52. } {1 {invalid fts5 file format (found 0, expected 4 or 5) - run 'rebuild'}}
  53. do_test 1.8 {
  54. sqlite3_db_config db DEFENSIVE 0
  55. execsql { INSERT INTO t1_config VALUES('version', 4) }
  56. execsql { INSERT INTO t1(t1, rank) VALUES('secure-delete', 1) }
  57. } {}
  58. do_execsql_test 1.10 {
  59. SELECT * FROM t1_config
  60. } {secure-delete 1 version 4}
  61. do_execsql_test 1.11 {
  62. INSERT INTO t1(rowid, one) VALUES(123, 'one two three');
  63. DELETE FROM t1 WHERE rowid=123;
  64. SELECT * FROM t1_config
  65. } {secure-delete 1 version 5}
  66. do_execsql_test 1.11 {
  67. INSERT INTO t1(t1) VALUES('rebuild');
  68. SELECT * FROM t1_config
  69. } {secure-delete 1 version 4}
  70. do_execsql_test 1.12 {
  71. SELECT * FROM t1_config
  72. } {secure-delete 1 version 4}
  73. #-------------------------------------------------------------------------
  74. reset_db
  75. do_execsql_test 2.0 {
  76. CREATE VIRTUAL TABLE xyz USING fts5(x);
  77. INSERT INTO xyz(rowid, x) VALUES
  78. (1, 'one document'),
  79. (2, 'two document'),
  80. (3, 'three document'),
  81. (4, 'four document'),
  82. (5, 'five document'),
  83. (6, 'six document');
  84. INSERT INTO xyz(xyz, rank) VALUES('secure-delete', 1);
  85. SELECT v FROM xyz_config WHERE k='version';
  86. } {4}
  87. do_execsql_test 2.1 {
  88. BEGIN;
  89. INSERT INTO xyz(rowid, x) VALUES(7, 'seven document');
  90. SAVEPOINT one;
  91. DELETE FROM xyz WHERE rowid = 4;
  92. }
  93. do_execsql_test 2.2 {
  94. SELECT v FROM xyz_config WHERE k='version';
  95. } {5}
  96. do_execsql_test 2.3 {
  97. ROLLBACK TO one;
  98. SELECT v FROM xyz_config WHERE k='version';
  99. } {4}
  100. do_execsql_test 2.4 {
  101. DELETE FROM xyz WHERE rowid = 3;
  102. COMMIT;
  103. SELECT v FROM xyz_config WHERE k='version';
  104. } {5}
  105. finish_test