fts5conflict.test 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # 2015 October 27
  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. # This file implements regression tests for SQLite library. The
  12. # focus of this script is testing the FTS5 module.
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. set testprefix fts5conflict
  16. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  17. ifcapable !fts5 {
  18. finish_test
  19. return
  20. }
  21. do_execsql_test 1.0 {
  22. CREATE TABLE t1(x INTEGER PRIMARY KEY, a, b);
  23. CREATE VIRTUAL TABLE ft USING fts5(a, b, content=t1, content_rowid=x);
  24. }
  25. do_execsql_test 1.1 {
  26. REPLACE INTO ft(rowid, a, b) VALUES(1, 'a b c', 'a b c');
  27. REPLACE INTO t1 VALUES(1, 'a b c', 'a b c');
  28. }
  29. do_execsql_test 1.2 {
  30. INSERT INTO ft(ft) VALUES('integrity-check');
  31. }
  32. do_execsql_test 2.0 {
  33. CREATE TABLE tbl(a INTEGER PRIMARY KEY, b, c);
  34. CREATE VIRTUAL TABLE fts_idx USING fts5(b, c, content=tbl, content_rowid=a);
  35. CREATE TRIGGER tbl_ai AFTER INSERT ON tbl BEGIN
  36. INSERT INTO fts_idx(rowid, b, c) VALUES (new.a, new.b, new.c);
  37. END;
  38. CREATE TRIGGER tbl_ad AFTER DELETE ON tbl BEGIN
  39. INSERT INTO fts_idx(fts_idx, rowid, b, c)
  40. VALUES('delete', old.a, old.b, old.c);
  41. END;
  42. CREATE TRIGGER tbl_au AFTER UPDATE ON tbl BEGIN
  43. INSERT INTO fts_idx(fts_idx, rowid, b, c)
  44. VALUES('delete', old.a, old.b, old.c);
  45. INSERT INTO fts_idx(rowid, b, c) VALUES (new.a, new.b, new.c);
  46. END;
  47. }
  48. do_execsql_test 2.1 {
  49. PRAGMA recursive_triggers = 1;
  50. INSERT INTO tbl VALUES(1, 'x y z', '1 2 3');
  51. INSERT INTO tbl VALUES(10, 'x y z', '1 2 3');
  52. INSERT INTO tbl VALUES(100, 'x 1 z', '1 y 3');
  53. UPDATE tbl SET b = '1 2 x' WHERE rowid=10;
  54. REPLACE INTO tbl VALUES(1, '4 5 6', '3 2 1');
  55. DELETE FROM tbl WHERE a=100;
  56. INSERT INTO fts_idx(fts_idx) VALUES('integrity-check');
  57. }
  58. #-------------------------------------------------------------------------
  59. # Tests for OR IGNORE conflict handling.
  60. #
  61. reset_db
  62. foreach_detail_mode $::testprefix {
  63. do_execsql_test 3.0 {
  64. CREATE VIRTUAL TABLE t1 USING fts5(xyz, detail=%DETAIL%);
  65. BEGIN;
  66. INSERT INTO t1(rowid, xyz) VALUES(13, 'thirteen documents');
  67. INSERT INTO t1(rowid, xyz) VALUES(14, 'fourteen documents');
  68. INSERT INTO t1(rowid, xyz) VALUES(15, 'fifteen documents');
  69. COMMIT;
  70. }
  71. set db_cksum [cksum]
  72. foreach {tn sql} {
  73. 1 {
  74. INSERT OR IGNORE INTO t1(rowid, xyz) VALUES(14, 'new text');
  75. }
  76. 2 {
  77. UPDATE OR IGNORE t1 SET rowid=13 WHERE rowid=15;
  78. }
  79. 3 {
  80. INSERT OR IGNORE INTO t1(rowid, xyz)
  81. SELECT 13, 'some text'
  82. UNION ALL
  83. SELECT 14, 'some text'
  84. UNION ALL
  85. SELECT 15, 'some text'
  86. }
  87. } {
  88. do_execsql_test 3.1.$tn.1 $sql
  89. do_test 3.1.$tn.2 { cksum } $db_cksum
  90. }
  91. }
  92. finish_test