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 #***********************************************************************
12 # This file contains tests for the RBU module. More specifically, it
13 # contains tests to ensure that RBU works with FTS tables.
16 source [file join [file dirname [info script]] rbu_common.tcl]
17 if_no_rbu_support { finish_test ; return }
18 set ::testprefix rbufts
25 proc step_rbu {target rbu} {
27 sqlite3rbu rbu $target $rbu
30 if {$rc != "SQLITE_OK"} break
35 proc apply_rbu_update {target sql} {
41 step_rbu $target rbu.db
44 do_execsql_test 1.1.0 {
45 CREATE TABLE t1(i INTEGER PRIMARY KEY, a, b);
46 CREATE VIRTUAL TABLE xx USING fts4(content=t1, a, b);
47 INSERT INTO t1(rowid, a, b) VALUES(10, 'a b c', 'c b a');
48 INSERT INTO t1(rowid, a, b) VALUES(20, 'a b c', 'd e f');
49 INSERT INTO t1(rowid, a, b) VALUES(30, 'd e f', 'a b c');
50 INSERT INTO t1(rowid, a, b) VALUES(40, 'd e f', 'd e f');
53 do_execsql_test 1.1.1 {
54 INSERT INTO xx(xx) VALUES('rebuild');
55 INSERT INTO xx(xx) VALUES('integrity-check');
59 apply_rbu_update test.db {
60 CREATE TABLE data_t1(i, a, b, rbu_control);
61 INSERT INTO data_t1 VALUES(20, NULL, NULL, 1); -- delete
62 INSERT INTO data_t1 VALUES(30, 'x y z', NULL, '.x.'); -- update
63 INSERT INTO data_t1 VALUES(50, '1 2 3', 'x y z', 0); -- insert
65 CREATE VIEW data0_xx AS
66 SELECT i AS rbu_rowid, a, b,
67 CASE WHEN rbu_control IN (0, 1)
68 THEN rbu_control ELSE substr(rbu_control, 2) END AS rbu_control
73 do_execsql_test 1.1.3 {
74 INSERT INTO xx(xx) VALUES('integrity-check');
78 do_execsql_test 1.2.1 {
79 CREATE TABLE ccc(addr, text);
80 CREATE VIRTUAL TABLE ccc_fts USING fts4(addr, text, content=ccc);
81 INSERT INTO ccc VALUES('a b c', 'd e f');
82 INSERT INTO ccc VALUES('a b c', 'd e f');
83 INSERT INTO ccc_fts(ccc_fts) VALUES('rebuild');
84 INSERT INTO ccc_fts(ccc_fts) VALUES('integrity-check');
88 apply_rbu_update test.db {
89 CREATE TABLE data_ccc(addr, text, rbu_rowid, rbu_control);
90 CREATE VIEW data0_ccc_fts AS SELECT * FROM data_ccc;
91 INSERT INTO data_ccc VALUES(NULL, NULL, 1, 1);
92 INSERT INTO data_ccc VALUES('x y z', NULL, 2, 'x.');
93 INSERT INTO data_ccc VALUES('y y y', '1 1 1', 3, 0);
97 do_execsql_test 1.2.3 {
98 INSERT INTO ccc_fts(ccc_fts) VALUES('integrity-check');
100 do_execsql_test 1.2.4 {
101 SELECT rowid, * FROM ccc_fts;
102 } {2 {x y z} {d e f} 3 {y y y} {1 1 1}}
104 #-------------------------------------------------------------------------
105 # Test the outcome of attempting to delete or update a row within a
106 # contentless FTS table using RBU. An error.
109 do_execsql_test 3.1 {
110 CREATE VIRTUAL TABLE ft USING fts4(x, content=);
111 INSERT INTO ft(rowid, x) VALUES(1, '1 2 3');
112 INSERT INTO ft(rowid, x) VALUES(2, '4 5 6');
116 list [catch { apply_rbu_update test.db {
117 CREATE TABLE data_ft(x, rbu_rowid, rbu_control);
118 INSERT INTO data_ft VALUES(NULL, 2, 1);
120 } {1 {SQLITE_ERROR - SQL logic error]}}
123 list [catch { apply_rbu_update test.db {
124 CREATE TABLE data_ft(x, rbu_rowid, rbu_control);
125 INSERT INTO data_ft VALUES('7 8 9', 1, 'x');
127 } {1 {SQLITE_ERROR - SQL logic error]}}