sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
sqlite / ext / fts5 / test / fts5conflict.test
| 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 | |
| 15 | source [file join [file dirname [info script]] fts5_common.tcl] |
| 16 | set testprefix fts5conflict |
| 17 | |
| 18 | # If SQLITE_ENABLE_FTS5 is not defined, omit this file. |
| 19 | ifcapable !fts5 { |
| 20 | finish_test |
| 21 | return |
| 22 | } |
| 23 | |
| 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); |
| 27 | } |
| 28 | |
| 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'); |
| 32 | } |
| 33 | |
| 34 | do_execsql_test 1.2 { |
| 35 | INSERT INTO ft(ft) VALUES('integrity-check'); |
| 36 | } |
| 37 | |
| 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; |
| 53 | } |
| 54 | |
| 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'); |
| 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 | |
| 68 | #------------------------------------------------------------------------- |
| 69 | # Tests for OR IGNORE conflict handling. |
| 70 | # |
| 71 | reset_db |
| 72 | foreach_detail_mode $::testprefix { |
| 73 | |
| 74 | do_execsql_test 3.0 { |
| 75 | CREATE VIRTUAL TABLE t1 USING fts5(xyz, detail=%DETAIL%); |
| 76 | |
| 77 | BEGIN; |
| 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'); |
| 81 | COMMIT; |
| 82 | } |
| 83 | |
| 84 | set db_cksum [cksum] |
| 85 | foreach {tn sql} { |
| 86 | 1 { |
| 87 | INSERT OR IGNORE INTO t1(rowid, xyz) VALUES(14, 'new text'); |
| 88 | } |
| 89 | 2 { |
| 90 | UPDATE OR IGNORE t1 SET rowid=13 WHERE rowid=15; |
| 91 | } |
| 92 | 3 { |
| 93 | INSERT OR IGNORE INTO t1(rowid, xyz) |
| 94 | SELECT 13, 'some text' |
| 95 | UNION ALL |
| 96 | SELECT 14, 'some text' |
| 97 | UNION ALL |
| 98 | SELECT 15, 'some text' |
| 99 | } |
| 100 | } { |
| 101 | do_execsql_test 3.1.$tn.1 $sql |
| 102 | do_test 3.1.$tn.2 { cksum } $db_cksum |
| 103 | } |
| 104 | |
| 105 | } |
| 106 | |
| 107 | |
| 108 | finish_test |