fts5alter.test 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # 2015 Jun 10
  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 renaming FTS5 tables using the
  13. # "ALTER TABLE ... RENAME TO ..." command
  14. #
  15. source [file join [file dirname [info script]] fts5_common.tcl]
  16. set testprefix fts5alter
  17. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  18. ifcapable !fts5 {
  19. finish_test
  20. return
  21. }
  22. #-------------------------------------------------------------------------
  23. # Test renaming regular, contentless and columnsize=0 FTS5 tables.
  24. #
  25. do_execsql_test 1.1.0 {
  26. CREATE VIRTUAL TABLE "a x" USING fts5(a, x);
  27. INSERT INTO "a x" VALUES('a a a', 'x x x');
  28. ALTER TABLE "a x" RENAME TO "x y";
  29. }
  30. do_execsql_test 1.1.1 {
  31. SELECT * FROM "x y";
  32. SELECT rowid FROM "x y" WHERE "x y" MATCH 'a'
  33. } {{a a a} {x x x} 1}
  34. do_execsql_test 1.2.0 {
  35. CREATE VIRTUAL TABLE "one/two" USING fts5(one, columnsize=0);
  36. INSERT INTO "one/two"(rowid, one) VALUES(456, 'd d d');
  37. ALTER TABLE "one/two" RENAME TO "three/four";
  38. }
  39. do_execsql_test 1.2.1 {
  40. SELECT * FROM "three/four";
  41. SELECT rowid FROM "three/four" WHERE "three/four" MATCH 'd'
  42. } {{d d d} 456}
  43. do_execsql_test 1.3.0 {
  44. CREATE VIRTUAL TABLE t1 USING fts5(val, content='');
  45. INSERT INTO t1(rowid, val) VALUES(-1, 'drop table');
  46. INSERT INTO t1(rowid, val) VALUES(-2, 'drop view');
  47. ALTER TABLE t1 RENAME TO t2;
  48. }
  49. do_execsql_test 1.3.1 {
  50. SELECT rowid, * FROM t2;
  51. SELECT rowid FROM t2 WHERE t2 MATCH 'table'
  52. } {-2 {} -1 {} -1}
  53. #-------------------------------------------------------------------------
  54. # Test renaming an FTS5 table within a transaction.
  55. #
  56. do_execsql_test 2.1 {
  57. CREATE VIRTUAL TABLE zz USING fts5(a);
  58. INSERT INTO zz(rowid, a) VALUES(-56, 'a b c');
  59. BEGIN;
  60. INSERT INTO zz(rowid, a) VALUES(-22, 'a b c');
  61. ALTER TABLE zz RENAME TO yy;
  62. SELECT rowid FROM yy WHERE yy MATCH 'a + b + c';
  63. COMMIT;
  64. } {-56 -22}
  65. do_execsql_test 2.2 {
  66. BEGIN;
  67. ALTER TABLE yy RENAME TO ww;
  68. INSERT INTO ww(rowid, a) VALUES(-11, 'a b c');
  69. SELECT rowid FROM ww WHERE ww MATCH 'a + b + c';
  70. } {-56 -22 -11}
  71. do_execsql_test 2.3 {
  72. ROLLBACK;
  73. SELECT rowid FROM yy WHERE yy MATCH 'a + b + c';
  74. } {-56 -22}
  75. #-------------------------------------------------------------------------
  76. do_execsql_test 3.1 {
  77. CREATE VIRTUAL TABLE abc USING fts5(a);
  78. INSERT INTO abc(rowid, a) VALUES(1, 'a');
  79. BEGIN;
  80. INSERT INTO abc(rowid, a) VALUES(2, 'a');
  81. }
  82. do_execsql_test 3.2 {
  83. SELECT rowid FROM abc WHERE abc MATCH 'a';
  84. } {1 2}
  85. do_execsql_test 3.3 {
  86. COMMIT;
  87. SELECT rowid FROM abc WHERE abc MATCH 'a';
  88. } {1 2}
  89. finish_test