xref: /sqlite-3.40.0/ext/fts5/test/fts5delete.test (revision 1418b9da)
1# 2017 May 12
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 fts5delete
17
18# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
19ifcapable !fts5 {
20  finish_test
21  return
22}
23fts5_aux_test_functions db
24
25do_execsql_test 1.0 {
26  CREATE VIRTUAL TABLE t1 USING fts5(x);
27  WITH s(i) AS (
28    SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<5000
29  )
30  INSERT INTO t1(rowid, x) SELECT i, (i/2)*2 FROM s;
31}
32
33do_test 1.1 {
34  execsql BEGIN
35  for {set i 1} {$i<=5000} {incr i} {
36    if {$i % 2} {
37      execsql { INSERT INTO t1 VALUES($i) }
38    } else {
39      execsql { DELETE FROM t1 WHERE rowid = $i }
40    }
41  }
42  execsql COMMIT
43} {}
44
45do_test 1.2 {
46  execsql { INSERT INTO t1(t1, rank) VALUES('usermerge', 2); }
47  for {set i 0} {$i < 5} {incr i} {
48    execsql { INSERT INTO t1(t1, rank) VALUES('merge', 1) }
49    execsql { INSERT INTO t1(t1) VALUES('integrity-check') }
50  }
51} {}
52
53#-------------------------------------------------------------------------
54reset_db
55do_execsql_test 2.0 {
56  CREATE TABLE test (
57      id INTEGER PRIMARY KEY,
58      name TEXT,
59      value TEXT
60  );
61  CREATE VIRTUAL TABLE test_idx USING fts5(
62      name, content=test, content_rowid=id
63  );
64}
65
66do_catchsql_test 2.1 {
67  INSERT INTO test_idx (test_idx, rowid, name) VALUES('delete', 1, 'quick');
68} {1 {database disk image is malformed}}
69
70do_catchsql_test 2.2 {
71  INSERT INTO test_idx(rowid, name) VALUES(123, 'one one one');
72  INSERT INTO test_idx (test_idx, rowid, name) VALUES('delete', 123, 'one');
73  INSERT INTO test_idx (test_idx, rowid, name) VALUES('delete', 123, 'one');
74} {1 {database disk image is malformed}}
75
76do_execsql_test 2.3 {
77  DROP TABLE test_idx;
78  CREATE VIRTUAL TABLE test_idx USING fts5(
79      name, content=test, content_rowid=id
80  );
81
82  INSERT INTO test_idx(rowid, name) VALUES(123, 'one one one');
83  INSERT INTO test_idx(rowid, name) VALUES(124, 'two two two');
84  INSERT INTO test_idx(rowid, name) VALUES(125, 'two two two');
85  INSERT INTO test_idx (test_idx, rowid, name) VALUES('delete', 123, 'one');
86  INSERT INTO test_idx (test_idx, rowid, name) VALUES('delete', 123, 'one');
87  INSERT INTO test_idx (test_idx, rowid, name) VALUES('delete', 123, 'one');
88}
89
90do_catchsql_test 2.4 {
91  SELECT rowid FROM test_idx WHERE test_idx MATCH 'two' ORDER BY rank;
92} {1 {database disk image is malformed}}
93
94#-------------------------------------------------------------------------
95reset_db
96do_execsql_test 3.0 {
97  CREATE VIRTUAL TABLE tx USING fts5(a, b, c, d, content=);
98  INSERT INTO tx(rowid, a, c) VALUES(1, 'abc def', 'a b c');
99  INSERT INTO tx(rowid, a, c) VALUES(5, 'a b c', 'a b d def');
100}
101do_execsql_test 3.1 {
102  INSERT INTO tx(tx, rowid, a, b, c, d)
103    VALUES('delete', 5, 'a b c', NULL, 'a b d def', NULL);
104}
105do_execsql_test 3.2 {
106  INSERT INTO tx(tx) VALUES('integrity-check');
107}
108do_execsql_test 3.3 {
109  INSERT INTO tx(tx, rowid, a, b, c, d)
110    VALUES('delete', 1, 'abc def', NULL, 'a b c', NULL);
111}
112do_execsql_test 3.4 {
113  INSERT INTO tx(tx) VALUES('integrity-check');
114}
115
116finish_test
117
118