Merge the fixes and tests for the ieee754 extension.

FossilOrigin-Name: 7a9988d38cd7ab3df79eed97631ff23d5928b4ad
This commit is contained in:
drh 2015-11-06 17:59:33 +00:00
commit 9ced20d892
11 changed files with 216 additions and 53 deletions

View File

@ -707,33 +707,37 @@ int sqlite3Fts5ConfigParseRank(
*pzRank = 0;
*pzRankArgs = 0;
p = fts5ConfigSkipWhitespace(p);
pRank = p;
p = fts5ConfigSkipBareword(p);
if( p ){
zRank = sqlite3Fts5MallocZero(&rc, 1 + p - pRank);
if( zRank ) memcpy(zRank, pRank, p-pRank);
}else{
if( p==0 ){
rc = SQLITE_ERROR;
}
}else{
p = fts5ConfigSkipWhitespace(p);
pRank = p;
p = fts5ConfigSkipBareword(p);
if( rc==SQLITE_OK ){
p = fts5ConfigSkipWhitespace(p);
if( *p!='(' ) rc = SQLITE_ERROR;
p++;
}
if( rc==SQLITE_OK ){
const char *pArgs;
p = fts5ConfigSkipWhitespace(p);
pArgs = p;
if( *p!=')' ){
p = fts5ConfigSkipArgs(p);
if( p==0 ){
rc = SQLITE_ERROR;
}else{
zRankArgs = sqlite3Fts5MallocZero(&rc, 1 + p - pArgs);
if( zRankArgs ) memcpy(zRankArgs, pArgs, p-pArgs);
if( p ){
zRank = sqlite3Fts5MallocZero(&rc, 1 + p - pRank);
if( zRank ) memcpy(zRank, pRank, p-pRank);
}else{
rc = SQLITE_ERROR;
}
if( rc==SQLITE_OK ){
p = fts5ConfigSkipWhitespace(p);
if( *p!='(' ) rc = SQLITE_ERROR;
p++;
}
if( rc==SQLITE_OK ){
const char *pArgs;
p = fts5ConfigSkipWhitespace(p);
pArgs = p;
if( *p!=')' ){
p = fts5ConfigSkipArgs(p);
if( p==0 ){
rc = SQLITE_ERROR;
}else{
zRankArgs = sqlite3Fts5MallocZero(&rc, 1 + p - pArgs);
if( zRankArgs ) memcpy(zRankArgs, pArgs, p-pArgs);
}
}
}
}

View File

@ -4447,9 +4447,6 @@ int sqlite3Fts5IndexBeginWrite(Fts5Index *p, int bDelete, i64 iRowid){
/* Allocate the hash table if it has not already been allocated */
if( p->pHash==0 ){
p->rc = sqlite3Fts5HashNew(&p->pHash, &p->nPendingData);
/* Force the configuration to be loaded */
fts5StructureRelease(fts5StructureRead(p));
}
/* Flush the hash table to disk if required */

View File

@ -395,6 +395,15 @@ static int fts5InitVtab(
rc = sqlite3Fts5ConfigDeclareVtab(pConfig);
}
/* Load the initial configuration */
if( rc==SQLITE_OK ){
assert( pConfig->pzErrmsg==0 );
pConfig->pzErrmsg = pzErr;
rc = sqlite3Fts5IndexLoadConfig(pTab->pIndex);
sqlite3Fts5IndexRollback(pTab->pIndex);
pConfig->pzErrmsg = 0;
}
if( rc!=SQLITE_OK ){
fts5FreeVtab(pTab);
pTab = 0;
@ -829,6 +838,36 @@ static int fts5NextMethod(sqlite3_vtab_cursor *pCursor){
return rc;
}
static sqlite3_stmt *fts5PrepareStatement(
int *pRc,
Fts5Config *pConfig,
const char *zFmt,
...
){
sqlite3_stmt *pRet = 0;
va_list ap;
va_start(ap, zFmt);
if( *pRc==SQLITE_OK ){
int rc;
char *zSql = sqlite3_vmprintf(zFmt, ap);
if( zSql==0 ){
rc = SQLITE_NOMEM;
}else{
rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pRet, 0);
if( rc!=SQLITE_OK ){
*pConfig->pzErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(pConfig->db));
}
sqlite3_free(zSql);
}
*pRc = rc;
}
va_end(ap);
return pRet;
}
static int fts5CursorFirstSorted(Fts5Table *pTab, Fts5Cursor *pCsr, int bDesc){
Fts5Config *pConfig = pTab->pConfig;
Fts5Sorter *pSorter;
@ -853,17 +892,13 @@ static int fts5CursorFirstSorted(Fts5Table *pTab, Fts5Cursor *pCsr, int bDesc){
** table, saving it creates a circular reference.
**
** If SQLite a built-in statement cache, this wouldn't be a problem. */
zSql = sqlite3Fts5Mprintf(&rc,
pSorter->pStmt = fts5PrepareStatement(&rc, pConfig,
"SELECT rowid, rank FROM %Q.%Q ORDER BY %s(%s%s%s) %s",
pConfig->zDb, pConfig->zName, zRank, pConfig->zName,
(zRankArgs ? ", " : ""),
(zRankArgs ? zRankArgs : ""),
bDesc ? "DESC" : "ASC"
);
if( zSql ){
rc = sqlite3_prepare_v2(pConfig->db, zSql, -1, &pSorter->pStmt, 0);
sqlite3_free(zSql);
}
pCsr->pSorter = pSorter;
if( rc==SQLITE_OK ){

View File

@ -52,7 +52,7 @@ do_faultsim_test 2 -prep {
INSERT INTO t1 VALUES('a b c', 'a bc def ghij klmno');
}
} -test {
faultsim_test_result {0 {}}
faultsim_test_result {0 {}} {1 {vtable constructor failed: t1}}
}
reset_db
@ -66,7 +66,7 @@ do_faultsim_test 3 -prep {
} -body {
execsql { DELETE FROM t1 }
} -test {
faultsim_test_result {0 {}}
faultsim_test_result {0 {}} {1 {vtable constructor failed: t1}}
}
reset_db
@ -101,7 +101,7 @@ foreach {tn expr res} {
} -body "
execsql { SELECT rowid FROM t2 WHERE t2 MATCH '$expr' }
" -test "
faultsim_test_result {[list 0 $res]}
faultsim_test_result {[list 0 $res]} {1 {vtable constructor failed: t2}}
"
}

View File

@ -107,7 +107,7 @@ set ::res [db eval {SELECT rowid, x1 FROM x1 WHERE x1 MATCH '*reads'}]
do_faultsim_test 4 -faults oom-* -body {
db eval {SELECT rowid, x, x1 FROM x1 WHERE x1 MATCH '*reads'}
} -test {
faultsim_test_result {0 {0 {} 3}}
faultsim_test_result {0 {0 {} 4}}
}
#-------------------------------------------------------------------------

View File

@ -41,5 +41,60 @@ do_execsql_test 1.3 {
WHERE xyz MATCH 'x AND y' ORDER BY rank
} [list [string map {x [x] y [y]} $doc]]
#-------------------------------------------------------------------------
# Check that the 'rank' option really is persistent.
#
do_execsql_test 2.0 {
CREATE VIRTUAL TABLE tt USING fts5(a);
INSERT INTO tt VALUES('a x x x x');
INSERT INTO tt VALUES('x x a a a');
INSERT INTO tt VALUES('x a a x x');
}
proc firstinst {cmd} {
foreach {p c o} [$cmd xInst 0] {}
return $o
}
sqlite3_fts5_create_function db firstinst firstinst
do_execsql_test 2.1 {
SELECT rowid FROM tt('a') ORDER BY rank;
} {2 3 1}
do_execsql_test 2.2 {
SELECT rowid FROM tt('a', 'firstinst()') ORDER BY rank;
} {1 3 2}
do_execsql_test 2.3 {
INSERT INTO tt(tt, rank) VALUES('rank', 'firstinst()');
SELECT rowid FROM tt('a') ORDER BY rank;
} {1 3 2}
do_test 2.4 {
sqlite3 db2 test.db
catchsql { SELECT rowid FROM tt('a') ORDER BY rank; } db2
} {1 {no such function: firstinst}}
do_test 2.5 {
db2 close
sqlite3 db2 test.db
sqlite3_fts5_create_function db2 firstinst firstinst
execsql { SELECT rowid FROM tt('a') ORDER BY rank; } db2
} {1 3 2}
do_test 2.6 {
execsql { SELECT rowid FROM tt('a') ORDER BY rank; } db2
} {1 3 2}
do_test 2.7 {
execsql { SELECT rowid FROM tt('a') ORDER BY rank; } db
} {1 3 2}
finish_test

View File

@ -336,5 +336,20 @@ do_test 14.2 {
fts5_level_segs ttt
} {1}
#-------------------------------------------------------------------------
db func rnddoc fts5_rnddoc
do_execsql_test 4.0 {
CREATE VIRTUAL TABLE x1 USING fts5(x);
INSERT INTO x1(x1, rank) VALUES('pgsz', 32);
WITH ii(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM ii WHERE i<10 )
INSERT INTO x1 SELECT rnddoc(5) FROM ii;
}
do_execsql_test 4.1 {
SELECT rowid, x, x1 FROM x1 WHERE x1 MATCH '*reads'
} {0 {} 4}
finish_test

View File

@ -94,13 +94,13 @@ static void ieee754func(
m >>= 1;
e++;
}
while( ((m>>32)&0xfff00000)==0 ){
while( m!=0 && ((m>>32)&0xfff00000)==0 ){
m <<= 1;
e--;
}
e += 1075;
if( e<0 ) e = m = 0;
if( e>0x7ff ) m = 0;
if( e>0x7ff ) e = 0x7ff;
a = m & ((((sqlite3_int64)1)<<52)-1);
a |= e<<52;
if( isNeg ) a |= ((sqlite3_int64)1)<<63;

View File

@ -1,5 +1,5 @@
C A\sdifferent\sapproach\sto\shandling\sinteger/float\scomparisons.\s\sThis\sseems\sto\nwork\sbetter\son\ssystems\swhere\s"long\sdouble"\sand\s"double"\sare\sthe\ssame\stype,\nbut\sstill\sneeds\srefinement\sand\stesting.
D 2015-11-06T14:59:07.361
C Merge\sthe\sfixes\sand\stests\sfor\sthe\sieee754\sextension.
D 2015-11-06T17:59:33.872
F Makefile.in 3a705bb4bd12e194212ddbdbf068310d17153cdb
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc 702d3e98f3afc6587a78481257f3c4c900efc3a4
@ -106,11 +106,11 @@ F ext/fts5/fts5.h 8b9a13b309b180e9fb88ea5666c0d8d73c6102d9
F ext/fts5/fts5Int.h acf968e43d57b6b1caf7554d34ec35d6ed3b4fe8
F ext/fts5/fts5_aux.c 1f384972d606375b8fa078319f25ab4b5feb1b35
F ext/fts5/fts5_buffer.c 1e49512a535045e621246dc7f4f65f3593fa0fc2
F ext/fts5/fts5_config.c 81ec07cb644e33df4cd58d46990016b2ce7c175c
F ext/fts5/fts5_config.c 6fc92c0b1bda5244c28a54c9ba740736bd5513d9
F ext/fts5/fts5_expr.c 28b15c9ae296204bc0a2e5cf7a667d840a9d2900
F ext/fts5/fts5_hash.c a9d4c1efebc2a91d26ad7ebdfcbf2678ceac405f
F ext/fts5/fts5_index.c 967d797282e4595f8671d152ed8ecf6cc7e640b5
F ext/fts5/fts5_main.c 39358d3d8f0d6ea3757c40e0ddcbb6bc435604c3
F ext/fts5/fts5_index.c b622a0a70f57a96469e6828da2dd70e0872aeb37
F ext/fts5/fts5_main.c 0569cd9fc18f3b56f6eeac601836df8ed5fb54cb
F ext/fts5/fts5_storage.c 9ea3d92178743758b6c54d9fe8836bbbdcc92e3b
F ext/fts5/fts5_tcl.c 3bf445e66de32137d4693694ff7b1fd6074e32bd
F ext/fts5/fts5_test_mi.c e96be827aa8f571031e65e481251dc1981d608bf
@ -149,10 +149,10 @@ F ext/fts5/test/fts5dlidx.test ecba5e62ea8b26c33829961602069c546228046d
F ext/fts5/test/fts5doclist.test 8edb5b57e5f144030ed74ec00ef6fa4294fed79b
F ext/fts5/test/fts5ea.test b01e3a18cdfabbff8104a96a5242a06a68a998a0
F ext/fts5/test/fts5eb.test 3e5869af2008cbc4ad03a175a0b6f6e58134cd43
F ext/fts5/test/fts5fault1.test 7a562367cb4a735b57b410dbdb62dcc8d971faec
F ext/fts5/test/fts5fault1.test 4b39c47ca3544615daa8a2f733b911fa08022c77
F ext/fts5/test/fts5fault2.test 28c36c843bb39ae855ba79827417ecc37f114341
F ext/fts5/test/fts5fault3.test d6e9577d4312e331a913c72931bf131704efc8f3
F ext/fts5/test/fts5fault4.test 762991d526ee67c2b374351a17248097ea38bee7
F ext/fts5/test/fts5fault4.test 4864f2b5c2c083440dbe85aff60897bc1aa04603
F ext/fts5/test/fts5fault5.test f2b8645053d48982e8979749e93994c43011c118
F ext/fts5/test/fts5fault6.test 9682664d679643ac6736e90c225526cc84073cda
F ext/fts5/test/fts5fault7.test 01be274bfc8d9bf22451a3bf5892e9399d044f1b
@ -170,11 +170,11 @@ F ext/fts5/test/fts5porter.test 7cdc07bef301d70eebbfa75dcaf45c3680e1d0e1
F ext/fts5/test/fts5porter2.test 2e65633d58a1c525d5af0f6c01e5a59155bb3487
F ext/fts5/test/fts5prefix.test 7ccbdf180ed561a912acef520519e85af8642239
F ext/fts5/test/fts5query.test f5ec25f5f2fbb70033424113cdffc101b1985a40
F ext/fts5/test/fts5rank.test 11dcebba31d822f7e99685b4ea2c2ae3ec0b16f1
F ext/fts5/test/fts5rank.test 7e9e64eac7245637f6f2033aec4b292aaf611aab
F ext/fts5/test/fts5rebuild.test 03935f617ace91ed23a6099c7c74d905227ff29b
F ext/fts5/test/fts5restart.test c17728fdea26e7d0f617d22ad5b4b2862b994c17
F ext/fts5/test/fts5rowid.test 400384798349d658eaf06aefa1e364957d5d4821
F ext/fts5/test/fts5simple.test ec1c6a6f51890ba864f866387794878ff2994de9
F ext/fts5/test/fts5simple.test 9bded45827b4ab8933c87b7b3bcc3cd47f7378a4
F ext/fts5/test/fts5synonym.test cf88c0a56d5ea9591e3939ef1f6e294f7f2d0671
F ext/fts5/test/fts5tokenizer.test ea4df698b35cc427ebf2ba22829d0e28386d8c89
F ext/fts5/test/fts5unicode.test fbef8d8a3b4b88470536cc57604a82ca52e51841
@ -196,7 +196,7 @@ F ext/misc/compress.c 122faa92d25033d6c3f07c39231de074ab3d2e83
F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2
F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f
F ext/misc/fuzzer.c 4c84635c71c26cfa7c2e5848cf49fe2d2cfcd767
F ext/misc/ieee754.c b0362167289170627659e84173f5d2e8fee8566e
F ext/misc/ieee754.c ca4a0a8fd2d4667a7ef10b761312c256bc734039
F ext/misc/json1.c 4f45afd9dbcd6feca8c528251efbb7fc09299a09
F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342
F ext/misc/percentile.c bcbee3c061b884eccb80e21651daaae8e1e43c63
@ -765,6 +765,7 @@ F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98
F test/hexlit.test 1d312fa816dfd3650a3bb488093bc09a0c927f67
F test/hook.test 162d7cef7a2d2b04839fe14402934e6a1b79442f
F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4
F test/ieee754.test 118b665a97a8df0e8f2fbdb07d113e596f4a6b53
F test/imposter1.test c3f1db2d3db2c24611a6596a3fc0ffc14f1466c8
F test/in.test 61a24ae38d4b64ec69f06ccdf022992f68a98176
F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75
@ -1399,7 +1400,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P c220741a62808c64d42c6161152ab06af74cb48c
R 657a004dd1109c7e46c85d0fcca1d027
P a3f7614b2095fbc1eca54801b2da88f85f294ec5 840cbda88675b6012dae2423252bf42d0d563874
R 281cdf2e28b38f35a9e781fe4ef44557
U drh
Z b71edcd294ef001f8419c54517ae11bb
Z 35915d26f010e261a34e33f9bc3e14c7

View File

@ -1 +1 @@
a3f7614b2095fbc1eca54801b2da88f85f294ec5
7a9988d38cd7ab3df79eed97631ff23d5928b4ad

56
test/ieee754.test Normal file
View File

@ -0,0 +1,56 @@
# 2015-11-06
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
# Tests of the iee754 extension
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
load_static_extension db ieee754
foreach {id float rep} {
1 1.0 1,0
2 2.0 2,0
3 0.5 1,-1
4 1.5 3,-1
5 0.0 0,-1075
6 4.9406564584124654e-324 4503599627370497,-1075
7 2.2250738585072009e-308 9007199254740991,-1075
8 2.2250738585072014e-308 1,-1022
} {
do_test ieee754-100-$id-1 {
db eval "SELECT ieee754($float);"
} "ieee754($rep)"
do_test ieee754-100-$id-2 {
db eval "SELECT ieee754($rep)==$float;"
} {1}
if {$float!=0.0} {
do_test ieee754-100-$id-3 {
db eval "SELECT ieee754(-$float);"
} "ieee754(-$rep)"
do_test ieee754-100-$id-4 {
db eval "SELECT ieee754(-$rep)==-$float;"
} {1}
}
}
do_execsql_test ieee754-110 {
SELECT ieee754(1,1024), ieee754(4503599627370495,972);
} {Inf 1.79769313486232e+308}
do_execsql_test ieee754-111 {
SELECT ieee754(-1,1024), ieee754(-4503599627370495,972);
} {-Inf -1.79769313486232e+308}
do_execsql_test ieee754-112 {
SELECT ieee754(4503599627370495,973) is null;
} {1}
finish_test