interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / ext / fts5 / test / fts5limits.test

133 lines · 3717 bytes Raw Blame History
1# 2023 May 16
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
13source [file join [file dirname [info script]] fts5_common.tcl]
14set testprefix fts5limits
15return_if_no_fts5
16
17
18do_execsql_test 1.0 {
19 CREATE VIRTUAL TABLE ft USING fts5(x);
20}
21
22# Default limit for expression depth is 256
23#
24foreach {tn nRepeat op bErr} {
25 1 200 AND 0
26 2 200 NOT 0
27 3 200 OR 0
28
29 4 260 AND 0
30 5 260 NOT 1
31 6 260 OR 0
32} {
33 set L [string repeat "abc " $nRepeat]
34 set Q [join $L " $op "]
35
36 set res {0 {}}
37 if {$bErr} {
38 set res "1 {fts5 expression tree is too large (maximum depth 256)}"
39 }
40
41 do_catchsql_test 1.$tn {
42 SELECT * FROM ft($Q)
43 } $res
44}
45
46#-------------------------------------------------------------------------
47# Test that if a record written to the %_data or %_docsize tables is larger
48# than SQLITE_LIMIT_LENGTH, the write fails with SQLITE_TOOBIG. It should not
49# succeed and store a NULL in place of the record, corrupting the index.
50#
51# Report: https://sqlite.org/bugs/forumpost/f712b4e116
52#
53set toobig {1 {string or blob too big}}
54
55# A %_data leaf record that is too large.
56#
57reset_db
58set nLimit [sqlite3_limit db SQLITE_LIMIT_LENGTH -1]
59do_execsql_test 2.1.0 {
60 CREATE VIRTUAL TABLE ft USING fts5(a);
61}
62sqlite3_limit db SQLITE_LIMIT_LENGTH 100
63do_catchsql_test 2.1.1 {
64 INSERT INTO ft VALUES('a b c d e f g h i j k l m n o p q r s t u v w x y z');
65} $toobig
66sqlite3_limit db SQLITE_LIMIT_LENGTH $nLimit
67do_execsql_test 2.1.2 {
68 SELECT count(*) FROM ft_data WHERE block IS NULL;
69} {0}
70do_execsql_test 2.1.3 {
71 INSERT INTO ft(ft) VALUES('integrity-check');
72 SELECT rowid FROM ft('a');
73} {}
74
75# The tables used by the following tests have 31 columns, so that both the
76# averages record and the %_docsize record are larger than the minimum
77# possible value of SQLITE_LIMIT_LENGTH (30). They are contentless, as
78# otherwise writing to the %_content table fails. And all values inserted
79# are empty, so that no leaf records are written.
80#
81set cols [list]
82set vals [list]
83for {set i 0} {$i < 31} {incr i} {
84 lappend cols c$i
85 lappend vals "''"
86}
87set cols [join $cols ,]
88set vals [join $vals ,]
89
90# An averages record that is too large. The columnsize=0 option means that
91# there is no %_docsize record to write.
92#
93reset_db
94do_execsql_test 2.2.0 "
95 CREATE VIRTUAL TABLE ft USING fts5($cols, content='', columnsize=0);
96"
97sqlite3_limit db SQLITE_LIMIT_LENGTH 30
98do_catchsql_test 2.2.1 "
99 INSERT INTO ft(rowid, $cols) VALUES(1, $vals);
100" $toobig
101sqlite3_limit db SQLITE_LIMIT_LENGTH $nLimit
102do_execsql_test 2.2.2 {
103 SELECT count(*) FROM ft_data WHERE block IS NULL;
104} {0}
105do_execsql_test 2.2.3 {
106 INSERT INTO ft(ft) VALUES('integrity-check');
107}
108
109# A %_docsize record that is too large. The %_docsize record is written as
110# part of the INSERT statement, but the slightly larger averages record is
111# not written until the transaction is committed. So raising the limit before
112# the COMMIT means that this tests the %_docsize write only.
113#
114reset_db
115do_execsql_test 2.3.0 "
116 CREATE VIRTUAL TABLE ft USING fts5($cols, content='');
117 BEGIN;
118"
119sqlite3_limit db SQLITE_LIMIT_LENGTH 30
120do_catchsql_test 2.3.1 "
121 INSERT INTO ft(rowid, $cols) VALUES(1, $vals);
122" $toobig
123sqlite3_limit db SQLITE_LIMIT_LENGTH $nLimit
124do_execsql_test 2.3.2 {
125 COMMIT;
126 SELECT count(*) FROM ft_docsize WHERE sz IS NULL;
127} {0}
128do_execsql_test 2.3.3 {
129 INSERT INTO ft(ft) VALUES('integrity-check');
130}
131
132finish_test
133