fts1j.test 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # 2007 February 6
  2. #
  3. # The author disclaims copyright to this source code.
  4. #
  5. #*************************************************************************
  6. # This file implements regression tests for SQLite library. This
  7. # tests creating fts1 tables in an attached database.
  8. #
  9. # $Id: fts1j.test,v 1.1 2007/02/07 01:01:18 shess Exp $
  10. #
  11. set testdir [file dirname $argv0]
  12. source $testdir/tester.tcl
  13. # If SQLITE_ENABLE_FTS1 is defined, omit this file.
  14. ifcapable !fts1 {
  15. finish_test
  16. return
  17. }
  18. # Clean up anything left over from a previous pass.
  19. forcedelete test2.db
  20. forcedelete test2.db-journal
  21. sqlite3 db2 test2.db
  22. db eval {
  23. CREATE VIRTUAL TABLE t3 USING fts1(content);
  24. INSERT INTO t3 (rowid, content) VALUES(1, "hello world");
  25. }
  26. db2 eval {
  27. CREATE VIRTUAL TABLE t1 USING fts1(content);
  28. INSERT INTO t1 (rowid, content) VALUES(1, "hello world");
  29. INSERT INTO t1 (rowid, content) VALUES(2, "hello there");
  30. INSERT INTO t1 (rowid, content) VALUES(3, "cruel world");
  31. }
  32. # This has always worked because the t1_* tables used by fts1 will be
  33. # the defaults.
  34. do_test fts1j-1.1 {
  35. execsql {
  36. ATTACH DATABASE 'test2.db' AS two;
  37. SELECT rowid FROM t1 WHERE t1 MATCH 'hello';
  38. DETACH DATABASE two;
  39. }
  40. } {1 2}
  41. # Make certain we're detached if there was an error.
  42. catch {db eval {DETACH DATABASE two}}
  43. # In older code, this appears to work fine, but the t2_* tables used
  44. # by fts1 will be created in database 'main' instead of database
  45. # 'two'. It appears to work fine because the tables end up being the
  46. # defaults, but obviously is badly broken if you hope to use things
  47. # other than in the exact same ATTACH setup.
  48. do_test fts1j-1.2 {
  49. execsql {
  50. ATTACH DATABASE 'test2.db' AS two;
  51. CREATE VIRTUAL TABLE two.t2 USING fts1(content);
  52. INSERT INTO t2 (rowid, content) VALUES(1, "hello world");
  53. INSERT INTO t2 (rowid, content) VALUES(2, "hello there");
  54. INSERT INTO t2 (rowid, content) VALUES(3, "cruel world");
  55. SELECT rowid FROM t2 WHERE t2 MATCH 'hello';
  56. DETACH DATABASE two;
  57. }
  58. } {1 2}
  59. catch {db eval {DETACH DATABASE two}}
  60. # In older code, this broke because the fts1 code attempted to create
  61. # t3_* tables in database 'main', but they already existed. Normally
  62. # this wouldn't happen without t3 itself existing, in which case the
  63. # fts1 code would never be called in the first place.
  64. do_test fts1j-1.3 {
  65. execsql {
  66. ATTACH DATABASE 'test2.db' AS two;
  67. CREATE VIRTUAL TABLE two.t3 USING fts1(content);
  68. INSERT INTO two.t3 (rowid, content) VALUES(2, "hello there");
  69. INSERT INTO two.t3 (rowid, content) VALUES(3, "cruel world");
  70. SELECT rowid FROM two.t3 WHERE t3 MATCH 'hello';
  71. DETACH DATABASE two;
  72. } db2
  73. } {2}
  74. catch {db eval {DETACH DATABASE two}}
  75. catch {db2 close}
  76. forcedelete test2.db
  77. finish_test