1b4a1fed2Sdrh# 2010 February 02 2b4a1fed2Sdrh# 3b4a1fed2Sdrh# The author disclaims copyright to this source code. In place of 4b4a1fed2Sdrh# a legal notice, here is a blessing: 5b4a1fed2Sdrh# 6b4a1fed2Sdrh# May you do good and not evil. 7b4a1fed2Sdrh# May you find forgiveness for yourself and forgive others. 8b4a1fed2Sdrh# May you share freely, never taking more than you give. 9b4a1fed2Sdrh# 10b4a1fed2Sdrh#************************************************************************* 11b4a1fed2Sdrh# This file implements regression tests for SQLite library. The 12b4a1fed2Sdrh# focus of this script is testing the FTS4 module. 13b4a1fed2Sdrh# 14b4a1fed2Sdrh# 15b4a1fed2Sdrh 16b4a1fed2Sdrhset testdir [file dirname $argv0] 17b4a1fed2Sdrhsource $testdir/tester.tcl 18b4a1fed2Sdrh 19b4a1fed2Sdrh# If SQLITE_ENABLE_FTS3 is defined, omit this file. 20b4a1fed2Sdrhifcapable !fts3 { 21b4a1fed2Sdrh finish_test 22b4a1fed2Sdrh return 23b4a1fed2Sdrh} 24b4a1fed2Sdrh 2592054fefSdrh# Create the fts_kjv_genesis procedure which fills and FTS3/4 table with 2692054fefSdrh# the complete text of the Book of Genesis. 2745de8d5fSdrh# 2892054fefSdrhsource $testdir/genesis.tcl 2945de8d5fSdrh 3045de8d5fSdrh# The following is a list of queries to perform against the above 3145de8d5fSdrh# FTS3/FTS4 database. We will be trying these queries in various 3245de8d5fSdrh# configurations to ensure that they always return the same answers. 3345de8d5fSdrh# 3445de8d5fSdrhset fts4aa_queries { 3545de8d5fSdrh {abraham} 3645de8d5fSdrh {the king} 3745de8d5fSdrh {"the king"} 3845de8d5fSdrh {abraham OR joseph} 3945de8d5fSdrh {ab* OR jos*} 4045de8d5fSdrh {lived t*} 4145de8d5fSdrh {spake hebrew} 4245de8d5fSdrh {melchizedek} 4345de8d5fSdrh {t* melchizedek} 4445de8d5fSdrh {melchizedek t*} 4545de8d5fSdrh} 4645de8d5fSdrhunset -nocomplain fts4aa_res 4745de8d5fSdrh 4845de8d5fSdrh# Set up the baseline results 4945de8d5fSdrh# 5045de8d5fSdrhdo_test fts4aa-1.0 { 5145de8d5fSdrh db eval { 5245de8d5fSdrh CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter); 5345de8d5fSdrh } 5492054fefSdrh fts_kjv_genesis 5545de8d5fSdrh foreach q $::fts4aa_queries { 5645de8d5fSdrh set r [db eval {SELECT docid FROM t1 WHERE words MATCH $q ORDER BY docid}] 5745de8d5fSdrh set ::fts4aa_res($q) $r 5845de8d5fSdrh } 59b4a1fed2Sdrh} {} 60b4a1fed2Sdrh 6145de8d5fSdrh# Legacy test cases 6245de8d5fSdrh# 63b4a1fed2Sdrhdo_test fts4aa-1.1 { 64b4a1fed2Sdrh db eval { 65b4a1fed2Sdrh SELECT docid FROM t1 EXCEPT SELECT docid FROM t1_docsize 66b4a1fed2Sdrh } 67b4a1fed2Sdrh} {} 68b4a1fed2Sdrhdo_test fts4aa-1.2 { 69b4a1fed2Sdrh db eval { 70b4a1fed2Sdrh SELECT docid FROM t1_docsize EXCEPT SELECT docid FROM t1 71b4a1fed2Sdrh } 72b4a1fed2Sdrh} {} 73b4a1fed2Sdrh 74b4a1fed2Sdrhproc mit {blob} { 75b4a1fed2Sdrh set scan(littleEndian) i* 76b4a1fed2Sdrh set scan(bigEndian) I* 77b4a1fed2Sdrh binary scan $blob $scan($::tcl_platform(byteOrder)) r 78b4a1fed2Sdrh return $r 79b4a1fed2Sdrh} 80b4a1fed2Sdrhdb func mit mit 81b4a1fed2Sdrh 8245de8d5fSdrhdo_test fts4aa-1.3 { 83b4a1fed2Sdrh db eval { 841fce2b14Sdan SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1 WHERE t1 MATCH 'melchizedek'; 85b4a1fed2Sdrh } 86b4a1fed2Sdrh} {1014018 {1 1 1 1 1 1533 25 20}} 8745de8d5fSdrhdo_test fts4aa-1.4 { 88b4a1fed2Sdrh db eval { 891fce2b14Sdan SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1 90b4a1fed2Sdrh WHERE t1 MATCH 'spake hebrew' 91b4a1fed2Sdrh ORDER BY docid; 92b4a1fed2Sdrh } 93b4a1fed2Sdrh} {1039014 {2 1 1 40 40 1 6 6 1533 25 42} 1039017 {2 1 1 40 40 1 6 6 1533 25 26}} 9445de8d5fSdrhdo_test fts4aa-1.5 { 95b4a1fed2Sdrh db eval { 961fce2b14Sdan SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1 97b4a1fed2Sdrh WHERE t1 MATCH 'laban overtook jacob' 98b4a1fed2Sdrh ORDER BY docid; 99b4a1fed2Sdrh } 100b4a1fed2Sdrh} {1031025 {3 1 2 54 46 1 3 3 2 181 160 1533 25 24}} 101b4a1fed2Sdrh 10245de8d5fSdrhdo_test fts4aa-1.6 { 103b4a1fed2Sdrh db eval { 104b4a1fed2Sdrh DELETE FROM t1 WHERE docid!=1050026; 105b4a1fed2Sdrh SELECT hex(size) FROM t1_docsize; 106b4a1fed2Sdrh SELECT hex(value) FROM t1_stat; 107b4a1fed2Sdrh } 1081fce2b14Sdan} {17 01176F} 109b4a1fed2Sdrh 11045de8d5fSdrhdo_test fts4aa-1.7 { 111b4a1fed2Sdrh db eval { 112b4a1fed2Sdrh SELECT docid FROM t1 EXCEPT SELECT docid FROM t1_docsize 113b4a1fed2Sdrh } 114b4a1fed2Sdrh} {} 11545de8d5fSdrhdo_test fts4aa-1.8 { 116b4a1fed2Sdrh db eval { 117b4a1fed2Sdrh SELECT docid FROM t1_docsize EXCEPT SELECT docid FROM t1 118b4a1fed2Sdrh } 119b4a1fed2Sdrh} {} 1204dc3d73dSdanifcapable fts4_deferred { 12145de8d5fSdrh do_test fts4aa-1.9 { 1221fce2b14Sdan # Note: Token 'in' is being deferred in the following query. 123b4a1fed2Sdrh db eval { 1241fce2b14Sdan SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1 125b4a1fed2Sdrh WHERE t1 MATCH 'joseph died in egypt' 126b4a1fed2Sdrh ORDER BY docid; 127b4a1fed2Sdrh } 1281fce2b14Sdan } {1050026 {4 1 1 1 1 1 1 1 2 1 1 1 1 1 1 23 23}} 1294dc3d73dSdan} 130b4a1fed2Sdrh 13145de8d5fSdrh# Should get the same search results from FTS3 13245de8d5fSdrh# 13345de8d5fSdrhdo_test fts4aa-2.0 { 13445de8d5fSdrh db eval { 13545de8d5fSdrh DROP TABLE t1; 13645de8d5fSdrh CREATE VIRTUAL TABLE t1 USING fts3(words, tokenize porter); 13745de8d5fSdrh } 13892054fefSdrh fts_kjv_genesis 13945de8d5fSdrh} {} 14045de8d5fSdrhunset -nocomplain ii 14145de8d5fSdrhset ii 0 14245de8d5fSdrhforeach {q r} [array get fts4aa_res] { 14345de8d5fSdrh incr ii 14445de8d5fSdrh do_test fts4aa-2.$ii { 14545de8d5fSdrh db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid} 14645de8d5fSdrh } $r 14745de8d5fSdrh} 14845de8d5fSdrh 14945de8d5fSdrh# Should get the same search results when the page size is very large 15045de8d5fSdrh# 15145de8d5fSdrhdo_test fts4aa-3.0 { 15245de8d5fSdrh db close 153fda06befSmistachkin forcedelete test.db 15445de8d5fSdrh sqlite3 db test.db 15545de8d5fSdrh db eval { 15645de8d5fSdrh PRAGMA page_size=65536; 15745de8d5fSdrh CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter); 15845de8d5fSdrh } 15992054fefSdrh fts_kjv_genesis 16045de8d5fSdrh} {} 16145de8d5fSdrhunset -nocomplain ii 16245de8d5fSdrhset ii 0 16345de8d5fSdrhforeach {q r} [array get fts4aa_res] { 16445de8d5fSdrh incr ii 16545de8d5fSdrh do_test fts4aa-3.$ii { 16645de8d5fSdrh db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid} 16745de8d5fSdrh } $r 16845de8d5fSdrh} 16945de8d5fSdrh 17045de8d5fSdrh# Should get the same search results when an authorizer prevents 17145de8d5fSdrh# all PRAGMA statements. 17245de8d5fSdrh# 17332c6a48bSdrhproc no_pragma_auth {code arg1 arg2 arg3 arg4 args} { 17445de8d5fSdrh if {$code=="SQLITE_PRAGMA"} {return SQLITE_DENY} 17545de8d5fSdrh return SQLITE_OK; 17645de8d5fSdrh} 17745de8d5fSdrhdo_test fts4aa-4.0 { 17845de8d5fSdrh db auth ::no_pragma_auth 17945de8d5fSdrh db eval { 18045de8d5fSdrh DROP TABLE t1; 18145de8d5fSdrh CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter); 18245de8d5fSdrh } 18392054fefSdrh fts_kjv_genesis 18445de8d5fSdrh} {} 18545de8d5fSdrhunset -nocomplain ii 18645de8d5fSdrhset ii 0 18745de8d5fSdrhforeach {q r} [array get fts4aa_res] { 18845de8d5fSdrh incr ii 18945de8d5fSdrh do_test fts4aa-4.$ii { 19045de8d5fSdrh db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid} 19145de8d5fSdrh } $r 19245de8d5fSdrh} 19345de8d5fSdrh 194*feb5dcf1Sdrh# 2019-11-16 https://bugs.chromium.org/p/chromium/issues/detail?id=1025472 195*feb5dcf1Sdrh# 196*feb5dcf1Sdrhdb close 197*feb5dcf1Sdrhsqlite3 db :memory: 198*feb5dcf1Sdrhdo_execsql_test fts4aa-5.10 { 199*feb5dcf1Sdrh CREATE VIRTUAL TABLE t1 USING fts4(a, b, c, d, e,f,g,h,i,j,k,l,m,n,o,p,q,r); 200*feb5dcf1Sdrh INSERT INTO t1 VALUES('X Y', '2', '3', '4', '5', '6', '7', '8', '9', '0', 201*feb5dcf1Sdrh 'a','b','c','d','e','f','g','h'); 202*feb5dcf1Sdrh UPDATE t1_docsize SET size=x'88' WHERE docid=1; 203*feb5dcf1Sdrh} {} 204*feb5dcf1Sdrhdo_catchsql_test fts4aa-5.20 { 205*feb5dcf1Sdrh SELECT quote(matchinfo(t1, 'l')) FROM t1 WHERE t1 MATCH 'X Y'; 206*feb5dcf1Sdrh} {1 {database disk image is malformed}} 207*feb5dcf1Sdrhdo_execsql_test fts4aa-5.30 { 208*feb5dcf1Sdrh DROP TABLE t1; 209*feb5dcf1Sdrh CREATE VIRTUAL TABLE t1 USING fts4(a,b,c,d); 210*feb5dcf1Sdrh INSERT INTO t1 VALUES('one two','three four','five six','seven eight'); 211*feb5dcf1Sdrh} {} 212*feb5dcf1Sdrhdo_catchsql_test fts4aa-5.40 { 213*feb5dcf1Sdrh UPDATE t1_stat SET value=x'01010101' WHERE id=0; 214*feb5dcf1Sdrh SELECT quote(matchinfo(t1,'a')) FROM t1 WHERE t1 MATCH 'one two'; 215*feb5dcf1Sdrh} {1 {database disk image is malformed}} 216*feb5dcf1Sdrhdo_catchsql_test fts4aa-5.50 { 217*feb5dcf1Sdrh UPDATE t1_stat SET value=x'010101' WHERE id=0; 218*feb5dcf1Sdrh SELECT quote(matchinfo(t1,'a')) FROM t1 WHERE t1 MATCH 'one two'; 219*feb5dcf1Sdrh} {1 {database disk image is malformed}} 220*feb5dcf1Sdrhdo_catchsql_test fts4aa-5.60 { 221*feb5dcf1Sdrh UPDATE t1_stat SET value=x'01' WHERE id=0; 222*feb5dcf1Sdrh SELECT quote(matchinfo(t1,'a')) FROM t1 WHERE t1 MATCH 'one two'; 223*feb5dcf1Sdrh} {1 {database disk image is malformed}} 224*feb5dcf1Sdrhdo_catchsql_test fts4aa-5.70 { 225*feb5dcf1Sdrh UPDATE t1_stat SET value=x'' WHERE id=0; 226*feb5dcf1Sdrh SELECT quote(matchinfo(t1,'a')) FROM t1 WHERE t1 MATCH 'one two'; 227*feb5dcf1Sdrh} {1 {database disk image is malformed}} 228*feb5dcf1Sdrh 229*feb5dcf1Sdrh 230*feb5dcf1Sdrh 231*feb5dcf1Sdrh 232b4a1fed2Sdrhfinish_test 233