OLD | NEW |
(Empty) | |
| 1 # 2011 January 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 FTS3 module. |
| 13 # |
| 14 |
| 15 set testdir [file dirname $argv0] |
| 16 source $testdir/tester.tcl |
| 17 ifcapable !fts3 { finish_test ; return } |
| 18 set ::testprefix fts3comp1 |
| 19 |
| 20 # Create a pretend compression system. |
| 21 # |
| 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. |
| 26 # |
| 27 set next_x 0 |
| 28 proc zip {x} { |
| 29 incr ::next_x |
| 30 set ::strings($::next_x) $x |
| 31 return $::next_x |
| 32 } |
| 33 proc unzip {x} { |
| 34 return $::strings($x) |
| 35 } |
| 36 |
| 37 foreach {tn zip unzip} { |
| 38 1 zip unzip |
| 39 2 {z.i.p!!} {un "zip"} |
| 40 } { |
| 41 |
| 42 set next_x 0 |
| 43 catch {db close} |
| 44 forcedelete test.db |
| 45 sqlite3 db test.db |
| 46 db func $zip zip |
| 47 db func $unzip unzip |
| 48 |
| 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. |
| 52 # |
| 53 do_execsql_test 1.$tn.0 " |
| 54 CREATE VIRTUAL TABLE t1 USING fts4( |
| 55 a, b, |
| 56 compress='$zip', uncompress='$unzip' |
| 57 ); |
| 58 " |
| 59 do_execsql_test 1.$tn.1 { |
| 60 INSERT INTO t1 VALUES('one two three', 'two four six'); |
| 61 SELECT a, b FROM t1; |
| 62 } {{one two three} {two four six}} |
| 63 do_execsql_test 1.$tn.2 { |
| 64 SELECT c0a, c1b FROM t1_content; |
| 65 } {1 2} |
| 66 |
| 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. |
| 70 # |
| 71 do_execsql_test 1.$tn.3 { |
| 72 INSERT INTO t1 VALUES('three six nine', 'four eight twelve'); |
| 73 SELECT a, b FROM t1; |
| 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; |
| 77 } {1 2 3 4} |
| 78 |
| 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}} |
| 85 |
| 86 # Delete a row and check that the full-text index is correctly updated. |
| 87 # Inspect the full-text index using an fts4aux table. |
| 88 # |
| 89 do_execsql_test 1.$tn.7 { |
| 90 CREATE VIRTUAL TABLE terms USING fts4aux(t1); |
| 91 SELECT term, documents, occurrences FROM terms WHERE col = '*'; |
| 92 } { |
| 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 |
| 95 } |
| 96 do_execsql_test 1.$tn.8 { |
| 97 DELETE FROM t1 WHERE docid = 1; |
| 98 SELECT term, documents, occurrences FROM terms WHERE col = '*'; |
| 99 } { |
| 100 eight 1 1 four 1 1 nine 1 1 |
| 101 six 1 1 three 1 1 twelve 1 1 |
| 102 } |
| 103 do_execsql_test 1.$tn.9 { SELECT c0a, c1b FROM t1_content } {3 4} |
| 104 } |
| 105 |
| 106 # Test that is an error to specify just one of compress and uncompress. |
| 107 # |
| 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}} |
| 114 |
| 115 finish_test |
OLD | NEW |