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
15source [file join [file dirname [info script]] fts5_common.tcl]
16set testprefix fts5conflict
17
18# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
19ifcapable !fts5 {
20  finish_test
21  return
22}
23
24do_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);
27}
28
29do_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');
32}
33
34do_execsql_test 1.2 {
35  INSERT INTO ft(ft) VALUES('integrity-check');
36}
37
38do_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;
53}
54
55do_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');
60
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;
64
65  INSERT INTO fts_idx(fts_idx) VALUES('integrity-check');
66}
67
68finish_test
69