3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #*************************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this script is testing the FTS5 module.
15 source [file join [file dirname [info script]] fts5_common.tcl]
16 set testprefix fts5conflict
18 # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
25 CREATE TABLE t1(x INTEGER PRIMARY KEY, a, b);
26 CREATE VIRTUAL TABLE ft USING fts5(a, b, content=t1, content_rowid=x);
30 REPLACE INTO ft(rowid, a, b) VALUES(1, 'a b c', 'a b c');
31 REPLACE INTO t1 VALUES(1, 'a b c', 'a b c');
35 INSERT INTO ft(ft) VALUES('integrity-check');
39 CREATE TABLE tbl(a INTEGER PRIMARY KEY, b, c);
40 CREATE VIRTUAL TABLE fts_idx USING fts5(b, c, content=tbl, content_rowid=a);
41 CREATE TRIGGER tbl_ai AFTER INSERT ON tbl BEGIN
42 INSERT INTO fts_idx(rowid, b, c) VALUES (new.a, new.b, new.c);
44 CREATE TRIGGER tbl_ad AFTER DELETE ON tbl BEGIN
45 INSERT INTO fts_idx(fts_idx, rowid, b, c)
46 VALUES('delete', old.a, old.b, old.c);
48 CREATE TRIGGER tbl_au AFTER UPDATE ON tbl BEGIN
49 INSERT INTO fts_idx(fts_idx, rowid, b, c)
50 VALUES('delete', old.a, old.b, old.c);
51 INSERT INTO fts_idx(rowid, b, c) VALUES (new.a, new.b, new.c);
56 PRAGMA recursive_triggers = 1;
57 INSERT INTO tbl VALUES(1, 'x y z', '1 2 3');
58 INSERT INTO tbl VALUES(10, 'x y z', '1 2 3');
59 INSERT INTO tbl VALUES(100, 'x 1 z', '1 y 3');
61 UPDATE tbl SET b = '1 2 x' WHERE rowid=10;
62 REPLACE INTO tbl VALUES(1, '4 5 6', '3 2 1');
63 DELETE FROM tbl WHERE a=100;
65 INSERT INTO fts_idx(fts_idx) VALUES('integrity-check');
68 #-------------------------------------------------------------------------
69 # Tests for OR IGNORE conflict handling.
72 foreach_detail_mode $::testprefix {
75 CREATE VIRTUAL TABLE t1 USING fts5(xyz, detail=%DETAIL%);
78 INSERT INTO t1(rowid, xyz) VALUES(13, 'thirteen documents');
79 INSERT INTO t1(rowid, xyz) VALUES(14, 'fourteen documents');
80 INSERT INTO t1(rowid, xyz) VALUES(15, 'fifteen documents');
87 INSERT OR IGNORE INTO t1(rowid, xyz) VALUES(14, 'new text');
90 UPDATE OR IGNORE t1 SET rowid=13 WHERE rowid=15;
93 INSERT OR IGNORE INTO t1(rowid, xyz)
94 SELECT 13, 'some text'
96 SELECT 14, 'some text'
98 SELECT 15, 'some text'
101 do_execsql_test 3.1.$tn.1 $sql
102 do_test 3.1.$tn.2 { cksum } $db_cksum