Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/ext/rbu/rbufts.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / ext / rbu / rbufts.test` 131 lines ยท 3715 bytes Raw Blame History 1 # 2014 August 30 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 # 12 # This file contains tests for the RBU module. More specifically, it 13 # contains tests to ensure that RBU works with FTS tables. 14 # 15 16 source [file join [file dirname [info script]] rbu_common.tcl] 17 if_no_rbu_support { finish_test ; return } 18 set ::testprefix rbufts 19 20 ifcapable !fts3 { 21 finish_test 22 return 23 } 24 25 proc step_rbu {target rbu} { 26 while 1 { 27 sqlite3rbu rbu $target $rbu 28 set rc [rbu step] 29 rbu close 30 if {$rc != "SQLITE_OK"} break 31 } 32 set rc 33 } 34 35 proc apply_rbu_update {target sql} { 36 forcedelete rbu.db 37 sqlite3 dbrbu rbu.db 38 execsql $sql dbrbu 39 dbrbu close 40 41 step_rbu $target rbu.db 42 } 43 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'); 51 } 52 53 do_execsql_test 1.1.1 { 54 INSERT INTO xx(xx) VALUES('rebuild'); 55 INSERT INTO xx(xx) VALUES('integrity-check'); 56 } 57 58 do_test 1.1.2 { 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 64 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 69 FROM data_t1; 70 } 71 } {SQLITE_DONE} 72 73 do_execsql_test 1.1.3 { 74 INSERT INTO xx(xx) VALUES('integrity-check'); 75 } 76 77 reset_db 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'); 85 } 86 87 do_test 1.2.2 { 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); 94 } 95 } {SQLITE_DONE} 96 97 do_execsql_test 1.2.3 { 98 INSERT INTO ccc_fts(ccc_fts) VALUES('integrity-check'); 99 } 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}} 103 104 #------------------------------------------------------------------------- 105 # Test the outcome of attempting to delete or update a row within a 106 # contentless FTS table using RBU. An error. 107 # 108 reset_db 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'); 113 } 114 115 do_test 3.2 { 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); 119 } } msg] $msg] 120 } {1 {SQLITE_ERROR - SQL logic error]}} 121 122 do_test 3.3 { 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'); 126 } } msg] $msg] 127 } {1 {SQLITE_ERROR - SQL logic error]}} 128 129 130 131 finish_test