Snapshot of upstream SQLite 3.40.1
[sqlcipher.git] / ext / fts5 / test / fts5conflict.test
blob644db53a1e464acfad4604e2bf42a74dfbcf435b
1 # 2015 October 27
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.
19 ifcapable !fts5 {
20   finish_test
21   return
24 do_execsql_test 1.0 {
25   CREATE TABLE t1(x INTEGER PRIMARY KEY, a, b);
26   CREATE VIRTUAL TABLE ft USING fts5(a, b, content=t1, content_rowid=x);
29 do_execsql_test 1.1 {
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');
34 do_execsql_test 1.2 {
35   INSERT INTO ft(ft) VALUES('integrity-check');
38 do_execsql_test 2.0 {
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);
43   END;
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);
47   END;
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);
52   END;
55 do_execsql_test 2.1 {
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 finish_test