From: dan Date: Thu, 3 Feb 2011 12:48:17 +0000 (+0000) Subject: Extra tests for fts4 compress/uncompress hooks. Fix some minor problems with the... X-Git-Tag: version-3.7.6~169 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=767f9a8f9eec3dd9a92448a3eca9c640c5afe7d8;p=thirdparty%2Fsqlite.git Extra tests for fts4 compress/uncompress hooks. Fix some minor problems with the same. FossilOrigin-Name: 80225abe79b0a7723b922ec129954438af95855a --- diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 4e8c396aa3..20da05164d 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -692,6 +692,35 @@ static void fts3Appendf( } } +/* +** Return a copy of input string zInput enclosed in double-quotes (") and +** with all double quote characters escaped. For example: +** +** fts3QuoteId("un \"zip\"") -> "un \"\"zip\"\"" +** +** The pointer returned points to memory obtained from sqlite3_malloc(). It +** is the callers responsibility to call sqlite3_free() to release this +** memory. +*/ +static char *fts3QuoteId(char const *zInput){ + int nRet; + char *zRet; + nRet = 2 + strlen(zInput)*2 + 1; + zRet = sqlite3_malloc(nRet); + if( zRet ){ + int i; + char *z = zRet; + *(z++) = '"'; + for(i=0; zInput[i]; i++){ + if( zInput[i]=='"' ) *(z++) = '"'; + *(z++) = zInput[i]; + } + *(z++) = '"'; + *(z++) = '\0'; + } + return zRet; +} + /* ** Return a list of comma separated SQL expressions that could be used ** in a SELECT statement such as the following: @@ -717,12 +746,20 @@ static void fts3Appendf( */ static char *fts3ReadExprList(Fts3Table *p, const char *zFunc, int *pRc){ char *zRet = 0; + char *zFree = 0; + char *zFunction; int i; - if( !zFunc ) zFunc = ""; + + if( !zFunc ){ + zFunction = ""; + }else{ + zFree = zFunction = fts3QuoteId(zFunc); + } fts3Appendf(pRc, &zRet, "docid"); for(i=0; inColumn; i++){ - fts3Appendf(pRc, &zRet, ",%s(x.'c%d%q')", zFunc, i, p->azColumn[i]); + fts3Appendf(pRc, &zRet, ",%s(x.'c%d%q')", zFunction, i, p->azColumn[i]); } + sqlite3_free(zFree); return zRet; } @@ -748,12 +785,20 @@ static char *fts3ReadExprList(Fts3Table *p, const char *zFunc, int *pRc){ */ static char *fts3WriteExprList(Fts3Table *p, const char *zFunc, int *pRc){ char *zRet = 0; + char *zFree = 0; + char *zFunction; int i; - if( !zFunc ) zFunc = ""; + + if( !zFunc ){ + zFunction = ""; + }else{ + zFree = zFunction = fts3QuoteId(zFunc); + } fts3Appendf(pRc, &zRet, "?"); for(i=0; inColumn; i++){ - fts3Appendf(pRc, &zRet, ",%s(?)", zFunc); + fts3Appendf(pRc, &zRet, ",%s(?)", zFunction); } + sqlite3_free(zFree); return zRet; } @@ -927,9 +972,9 @@ static int fts3InitVtab( } if( (zCompress==0)!=(zUncompress==0) ){ - char const *zMissing = (zCompress==0 ? "compress" : "uncompress"); + char const *zMiss = (zCompress==0 ? "compress" : "uncompress"); rc = SQLITE_ERROR; - *pzErr = sqlite3_mprintf("missing %s parameter", zMissing); + *pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss); } p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc); p->zWriteExprlist = fts3WriteExprList(p, zCompress, &rc); diff --git a/manifest b/manifest index a99513bc9c..c2ae1eaf4b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Extra\stests\sfor\sthe\sfts4aux\smodule. -D 2011-02-03T10:56:00.411 +C Extra\stests\sfor\sfts4\scompress/uncompress\shooks.\sFix\ssome\sminor\sproblems\swith\sthe\ssame. +D 2011-02-03T12:48:17.458 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in de6498556d536ae60bb8bb10e8c1ba011448658c F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -61,7 +61,7 @@ F ext/fts2/mkfts2amal.tcl 974d5d438cb3f7c4a652639262f82418c1e4cff0 F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a F ext/fts3/README.tokenizers 998756696647400de63d5ba60e9655036cb966e9 F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d -F ext/fts3/fts3.c f93f5d614e92b0221e954ea3bd800f11f6f00191 +F ext/fts3/fts3.c 5653c5654ac9b65bf3646af7e1d695c7e9b991a0 F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe F ext/fts3/fts3Int.h 945926ea4b6a686c3e9834640a252d9870b7191e F ext/fts3/fts3_aux.c 233a9f0bd8fa336d78f5905b2c94c8860d237dd9 @@ -441,7 +441,7 @@ F test/fts3atoken.test 25c2070e1e8755d414bf9c8200427b277a9f99fa F test/fts3aux1.test 6145608289e8a6337acb3432d592e57b8e46ad35 F test/fts3b.test e93bbb653e52afde110ad53bbd793f14fe7a8984 F test/fts3c.test fc723a9cf10b397fdfc2b32e73c53c8b1ec02958 -F test/fts3comp1.test ef36e5ddf9811c9801f52b2988bca1fce7dc8ce8 +F test/fts3comp1.test dab659038f2e0e2f5807d51da4dde38e213e28da F test/fts3corrupt.test 7890cc202406858386ddf390a879dcf80bc10abf F test/fts3corrupt2.test 6d96efae2f8a6af3eeaf283aba437e6d0e5447ba F test/fts3cov.test e0fb00d8b715ddae4a94c305992dfc3ef70353d7 @@ -904,7 +904,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 8bf2d51b6a50da84cf6b0d2bd78e633d6810160b -R ddc2098046dae72dcd5cb0c3ae07050f +P cfc475690d85ea7e3547424289d9837f46ab7ef4 +R 88eebeb229dec71bb74cda54c9987bad U dan -Z 24b73331b8700cbc651162882517a9c3 +Z cc8e3364f71d0c95c8a268f7f131b691 diff --git a/manifest.uuid b/manifest.uuid index ac29c97b66..9526938e63 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cfc475690d85ea7e3547424289d9837f46ab7ef4 \ No newline at end of file +80225abe79b0a7723b922ec129954438af95855a \ No newline at end of file diff --git a/test/fts3comp1.test b/test/fts3comp1.test index 69e484e6b7..7c506f4f02 100644 --- a/test/fts3comp1.test +++ b/test/fts3comp1.test @@ -17,6 +17,13 @@ source $testdir/tester.tcl ifcapable !fts3 { finish_test ; return } set ::testprefix fts3comp1 +# Create a pretend compression system. +# +# Each time the [zip] function is called, an entry is added to the ::strings +# array mapping from an integer key to the string argument to zip. The key +# is returned. Later on, when the key is passed to [unzip], the original +# string is retrieved from the ::strings array and returned. +# set next_x 0 proc zip {x} { incr ::next_x @@ -27,52 +34,82 @@ proc unzip {x} { return $::strings($x) } -db func zip zip -db func unzip unzip - -do_execsql_test 1.0 { - CREATE VIRTUAL TABLE t1 USING fts4( - a, b, - compress=zip, uncompress=unzip - ); - INSERT INTO t1 VALUES('one two three', 'two four six'); -} - -do_execsql_test 1.1 { - SELECT a, b FROM t1; -} {{one two three} {two four six}} - -do_execsql_test 1.2 { - SELECT c0a, c1b FROM t1_content; -} {1 2} - -do_execsql_test 1.3 { - INSERT INTO t1 VALUES('three six nine', 'four eight twelve'); - SELECT a, b FROM t1; -} {{one two three} {two four six} {three six nine} {four eight twelve}} - -do_execsql_test 1.4 { - SELECT c0a, c1b FROM t1_content; -} {1 2 3 4} - -do_execsql_test 1.5 { - CREATE VIRTUAL TABLE terms USING fts4aux(t1); - SELECT * FROM terms; +foreach {tn zip unzip} { + 1 zip unzip + 2 {z.i.p!!} {un "zip"} } { - eight 1 1 four 2 2 nine 1 1 one 1 1 - six 2 2 three 2 2 twelve 1 1 two 1 2 -} -do_execsql_test 1.6 { - DELETE FROM t1 WHERE docid = 1; - SELECT * FROM terms; -} { - eight 1 1 four 1 1 nine 1 1 - six 1 1 three 1 1 twelve 1 1 + set next_x 0 + catch {db close} + forcedelete test.db + sqlite3 db test.db + db func $zip zip + db func $unzip unzip + + # Create a table that uses zip/unzip. Check that content inserted into + # the table can be read back (using a full-scan query). Check that the + # underlying %_content table contains the compressed (integer) values. + # + do_execsql_test 1.$tn.0 " + CREATE VIRTUAL TABLE t1 USING fts4( + a, b, + compress='$zip', uncompress='$unzip' + ); + " + do_execsql_test 1.$tn.1 { + INSERT INTO t1 VALUES('one two three', 'two four six'); + SELECT a, b FROM t1; + } {{one two three} {two four six}} + do_execsql_test 1.$tn.2 { + SELECT c0a, c1b FROM t1_content; + } {1 2} + + # Insert another row and check that it can be read back. Also that the + # %_content table still contains all compressed content. This time, try + # full-text index and by-docid queries too. + # + do_execsql_test 1.$tn.3 { + INSERT INTO t1 VALUES('three six nine', 'four eight twelve'); + SELECT a, b FROM t1; + } {{one two three} {two four six} {three six nine} {four eight twelve}} + do_execsql_test 1.$tn.4 { + SELECT c0a, c1b FROM t1_content; + } {1 2 3 4} + + do_execsql_test 1.$tn.5 { + SELECT a, b FROM t1 WHERE docid = 2 + } {{three six nine} {four eight twelve}} + do_execsql_test 1.$tn.6 { + SELECT a, b FROM t1 WHERE t1 MATCH 'two' + } {{one two three} {two four six}} + + # Delete a row and check that the full-text index is correctly updated. + # Inspect the full-text index using an fts4aux table. + # + do_execsql_test 1.$tn.7 { + CREATE VIRTUAL TABLE terms USING fts4aux(t1); + SELECT * FROM terms; + } { + eight 1 1 four 2 2 nine 1 1 one 1 1 + six 2 2 three 2 2 twelve 1 1 two 1 2 + } + do_execsql_test 1.$tn.8 { + DELETE FROM t1 WHERE docid = 1; + SELECT * FROM terms; + } { + eight 1 1 four 1 1 nine 1 1 + six 1 1 three 1 1 twelve 1 1 + } + do_execsql_test 1.$tn.9 { SELECT c0a, c1b FROM t1_content } {3 4} } -do_execsql_test 1.7 { - SELECT c0a, c1b FROM t1_content; -} {3 4} +# Test that is an error to specify just one of compress and uncompress. +# +do_catchsql_test 2.1 { + CREATE VIRTUAL TABLE t2 USING fts4(x, compress=zip) +} {1 {missing uncompress parameter in fts4 constructor}} +do_catchsql_test 2.2 { + CREATE VIRTUAL TABLE t2 USING fts4(x, uncompress=unzip) +} {1 {missing compress parameter in fts4 constructor}} finish_test