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 #*************************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this script is testing the FTS3 module.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 ifcapable !fts3 { finish_test ; return }
18 set ::testprefix fts3comp1
20 # Create a pretend compression system.
22 # Each time the [zip] function is called, an entry is added to the ::strings
23 # array mapping from an integer key to the string argument to zip. The key
24 # is returned. Later on, when the key is passed to [unzip], the original
25 # string is retrieved from the ::strings array and returned.
30 set ::strings($::next_x) $x
37 foreach {tn zip unzip} {
39 2 {z.i.p!!} {un "zip"}
49 # Create a table that uses zip/unzip. Check that content inserted into
50 # the table can be read back (using a full-scan query). Check that the
51 # underlying %_content table contains the compressed (integer) values.
53 do_execsql_test 1.$tn.0 "
54 CREATE VIRTUAL TABLE t1 USING fts4(
56 compress='$zip', uncompress='$unzip'
59 do_execsql_test 1.$tn.1 {
60 INSERT INTO t1 VALUES('one two three', 'two four six');
62 } {{one two three} {two four six}}
63 do_execsql_test 1.$tn.2 {
64 SELECT c0a, c1b FROM t1_content;
67 # Insert another row and check that it can be read back. Also that the
68 # %_content table still contains all compressed content. This time, try
69 # full-text index and by-docid queries too.
71 do_execsql_test 1.$tn.3 {
72 INSERT INTO t1 VALUES('three six nine', 'four eight twelve');
74 } {{one two three} {two four six} {three six nine} {four eight twelve}}
75 do_execsql_test 1.$tn.4 {
76 SELECT c0a, c1b FROM t1_content;
79 do_execsql_test 1.$tn.5 {
80 SELECT a, b FROM t1 WHERE docid = 2
81 } {{three six nine} {four eight twelve}}
82 do_execsql_test 1.$tn.6 {
83 SELECT a, b FROM t1 WHERE t1 MATCH 'two'
84 } {{one two three} {two four six}}
86 # Delete a row and check that the full-text index is correctly updated.
87 # Inspect the full-text index using an fts4aux table.
89 do_execsql_test 1.$tn.7 {
90 CREATE VIRTUAL TABLE terms USING fts4aux(t1);
91 SELECT term, documents, occurrences FROM terms WHERE col = '*';
93 eight 1 1 four 2 2 nine 1 1 one 1 1
94 six 2 2 three 2 2 twelve 1 1 two 1 2
96 do_execsql_test 1.$tn.8 {
97 DELETE FROM t1 WHERE docid = 1;
98 SELECT term, documents, occurrences FROM terms WHERE col = '*';
100 eight 1 1 four 1 1 nine 1 1
101 six 1 1 three 1 1 twelve 1 1
103 do_execsql_test 1.$tn.9 { SELECT c0a, c1b FROM t1_content } {3 4}
106 # Test that is an error to specify just one of compress and uncompress.
108 do_catchsql_test 2.1 {
109 CREATE VIRTUAL TABLE t2 USING fts4(x, compress=zip)
110 } {1 {missing uncompress parameter in fts4 constructor}}
111 do_catchsql_test 2.2 {
112 CREATE VIRTUAL TABLE t2 USING fts4(x, uncompress=unzip)
113 } {1 {missing compress parameter in fts4 constructor}}