]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add coverage tests (and associated fixes) for new matchinfo() code.
authordan <dan@noemail.net>
Thu, 25 Nov 2010 17:49:28 +0000 (17:49 +0000)
committerdan <dan@noemail.net>
Thu, 25 Nov 2010 17:49:28 +0000 (17:49 +0000)
FossilOrigin-Name: 70495ceccc793d608930f59e330777f287ba1ede

ext/fts3/fts3_snippet.c
manifest
manifest.uuid
test/fts3fault.test
test/fts3matchinfo.test

index 3796d78f27bfe396ada3f94946007e072d4cf7dd..061e1a8da01e58f5ce971719954befa68e87a111 100644 (file)
@@ -289,6 +289,16 @@ static int fts3ExprLoadDoclists(
   return rc;
 }
 
+static int fts3ExprPhraseCountCb(Fts3Expr *pExpr, int iPhrase, void *ctx){
+  (*(int *)ctx)++;
+  return SQLITE_OK;
+}
+static int fts3ExprPhraseCount(Fts3Expr *pExpr){
+  int nPhrase = 0;
+  (void)fts3ExprIterate(pExpr, fts3ExprPhraseCountCb, (void *)&nPhrase);
+  return nPhrase;
+}
+
 /*
 ** Advance the position list iterator specified by the first two 
 ** arguments so that it points to the first element with a value greater
@@ -939,7 +949,8 @@ static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
       nVal = pInfo->nCol;
       break;
 
-    case FTS3_MATCHINFO_HITS:
+    default:
+      assert( cArg==FTS3_MATCHINFO_HITS );
       nVal = pInfo->nCol * pInfo->nPhrase * 3;
       break;
   }
@@ -1055,12 +1066,9 @@ static int fts3MatchinfoLcs(Fts3Cursor *pCsr, MatchInfo *pInfo){
     while( nLive>0 ){
       LcsIterator *pAdv = 0;
       int nThisLcs = 0;
-      char *aRead;
-      sqlite3_int64 iRead;
 
       for(i=0; i<pInfo->nPhrase; i++){
         LcsIterator *pIter = &aIter[i];
-        int nToken = pIter->pExpr->pPhrase->nToken;
 
         if( iCol!=pIter->iCol ){  
           nThisLcs = 0;
@@ -1086,6 +1094,7 @@ static int fts3MatchinfoLcs(Fts3Cursor *pCsr, MatchInfo *pInfo){
   }
 
   sqlite3_free(aIter);
+  return SQLITE_OK;
 }
 
 static int fts3MatchinfoValues(
@@ -1100,7 +1109,7 @@ static int fts3MatchinfoValues(
 
   sqlite3_stmt *pSelect = 0;
 
-  for(i=0; zArg[i]; i++){
+  for(i=0; rc==SQLITE_OK && zArg[i]; i++){
 
     switch( zArg[i] ){
       case FTS3_MATCHINFO_NPHRASE: 
@@ -1152,30 +1161,29 @@ static int fts3MatchinfoValues(
         break;
       }
 
-      case FTS3_MATCHINFO_HITS: {
-        Fts3Expr *pExpr = pCsr->pExpr;
+      case FTS3_MATCHINFO_LCS:
         rc = fts3ExprLoadDoclists(pCsr, 0, 0);
         if( rc==SQLITE_OK ){
-          if( bGlobal ){
-            if( pCsr->pDeferred ){
-              rc = fts3MatchinfoSelectDoctotal(pTab, &pSelect, &pInfo->nDoc, 0);
-            }
-            (void)fts3ExprIterate(pExpr, fts3ExprGlobalHitsCb,(void*)pInfo);
-          }
-          (void)fts3ExprIterate(pExpr, fts3ExprLocalHitsCb,(void*)pInfo);
+          rc = fts3MatchinfoLcs(pCsr, pInfo);
         }
         break;
-      }
 
-      case FTS3_MATCHINFO_LCS:
+      default: {
+        assert( zArg[i]==FTS3_MATCHINFO_HITS );
+        Fts3Expr *pExpr = pCsr->pExpr;
         rc = fts3ExprLoadDoclists(pCsr, 0, 0);
-        if( rc==SQLITE_OK ){
-          fts3MatchinfoLcs(pCsr, pInfo);
+        if( rc!=SQLITE_OK ) break;
+        if( bGlobal ){
+          if( pCsr->pDeferred ){
+            rc = fts3MatchinfoSelectDoctotal(pTab, &pSelect, &pInfo->nDoc, 0);
+            if( rc!=SQLITE_OK ) break;
+          }
+          rc = fts3ExprIterate(pExpr, fts3ExprGlobalHitsCb,(void*)pInfo);
+          if( rc!=SQLITE_OK ) break;
         }
+        (void)fts3ExprIterate(pExpr, fts3ExprLocalHitsCb,(void*)pInfo);
         break;
-
-      default:
-        assert( !"this cannot happen" );
+      }
     }
 
     pInfo->aMatchinfo += fts3MatchinfoSize(pInfo, zArg[i]);
@@ -1224,8 +1232,7 @@ static int fts3GetMatchinfo(
     int i;                        /* Used to iterate through zArg */
 
     /* Load doclists for each phrase in the query. */
-    rc = fts3ExprLoadDoclists(pCsr, &pCsr->nPhrase, 0);
-    if( rc!=SQLITE_OK ) return rc;
+    pCsr->nPhrase = fts3ExprPhraseCount(pCsr->pExpr);
     sInfo.nPhrase = pCsr->nPhrase;
 
     for(i=0; zArg[i]; i++){
@@ -1247,7 +1254,7 @@ static int fts3GetMatchinfo(
 
   sInfo.aMatchinfo = pCsr->aMatchinfo;
   sInfo.nPhrase = pCsr->nPhrase;
-  if( rc==SQLITE_OK && pCsr->isMatchinfoNeeded ){
+  if( pCsr->isMatchinfoNeeded ){
     rc = fts3MatchinfoValues(pCsr, bGlobal, &sInfo, zArg);
     pCsr->isMatchinfoNeeded = 0;
   }
index 3d94ca291d5a7a75e454ef5d9628819a7709ee52..f5a68af891e361712019681d6a74f11e6fffe61c 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sbugs\sin\sfts3\sfunction\smatchinfo()\swhen\sused\swith\sdeferred\stokens.
-D 2010-11-25T10:33:54
+C Add\scoverage\stests\s(and\sassociated\sfixes)\sfor\snew\smatchinfo()\scode.
+D 2010-11-25T17:49:28
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in e7a59672eaeb04408d1fa8501618d7501a3c5e39
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -69,7 +69,7 @@ F ext/fts3/fts3_hash.c 3c8f6387a4a7f5305588b203fa7c887d753e1f1c
 F ext/fts3/fts3_hash.h 8331fb2206c609f9fc4c4735b9ab5ad6137c88ec
 F ext/fts3/fts3_icu.c ac494aed69835008185299315403044664bda295
 F ext/fts3/fts3_porter.c 8df6f6efcc4e9e31f8bf73a4007c2e9abca1dfba
-F ext/fts3/fts3_snippet.c d765bda619c66e8f3b77f323c3c53cfc8dec84aa
+F ext/fts3/fts3_snippet.c 8dc1fe915ce572a2104c6399622d5d25d1acc4a4
 F ext/fts3/fts3_tokenizer.c 1301b0ee3ef414caae3257a702215925cc48cd9c
 F ext/fts3/fts3_tokenizer.h 13ffd9fcb397fec32a05ef5cd9e0fa659bf3dbd3
 F ext/fts3/fts3_tokenizer1.c 6e5cbaa588924ac578263a598e4fb9f5c9bb179d
@@ -444,9 +444,9 @@ F test/fts3defer2.test da840efaedebfdd54293d04b36098e2d9872caa6
 F test/fts3e.test 1f6c6ac9cc8b772ca256e6b22aaeed50c9350851
 F test/fts3expr.test 5e745b2b6348499d9ef8d59015de3182072c564c
 F test/fts3expr2.test 18da930352e5693eaa163a3eacf96233b7290d1a
-F test/fts3fault.test 81fd40ceb12f33f9d16c5637d0f8d95d4556c456
+F test/fts3fault.test f83e556465bb69dc8bc676339eca408dce4ca246
 F test/fts3malloc.test 9c8cc3f885bb4dfc66d0460c52f68f45e4710d1b
-F test/fts3matchinfo.test 5f7c7a16f5911e05210f2eeda9df2f4567964f79
+F test/fts3matchinfo.test ae33ea9149b9867b0353b30647fb59d705dea339
 F test/fts3near.test 2e318ee434d32babd27c167142e2b94ddbab4844
 F test/fts3query.test ef79d31fdb355d094baec1c1b24b60439a1fb8a2
 F test/fts3rnd.test 707533ce943f490443ce5e696236bb1675a37635
@@ -889,7 +889,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 71011a4f9baf09ec6935ad591145252bf3c286ed
-R 08fa9c5772f6e2165a7fbe403b4e4263
+P ddc2b7ec2618b010c981ecfa05b3e53a9fac686f
+R e123b51122e9ccc0e657b3357d0441ec
 U dan
-Z afc34a2b2b43c5dc214681d1fbfcf7d4
+Z 265f951641d795636aa4f45fe10ea271
index f43ad87f81ee25e13191d0b98e1942b0493a7a97..57cb9a10b370afe1db0685ec2397e96496ac3d89 100644 (file)
@@ -1 +1 @@
-ddc2b7ec2618b010c981ecfa05b3e53a9fac686f
\ No newline at end of file
+70495ceccc793d608930f59e330777f287ba1ede
\ No newline at end of file
index c5578310125ca1a743dab7a635c8007b1f830095..2dd7bbbc43cb0fd2639371b3df59c9c42c81073b 100644 (file)
@@ -18,6 +18,8 @@ set ::testprefix fts3fault
 # If SQLITE_ENABLE_FTS3 is not defined, omit this file.
 ifcapable !fts3 { finish_test ; return }
 
+if 1 {
+
 # Test error handling in the sqlite3Fts3Init() function. This is the 
 # function that registers the FTS3 module and various support functions
 # with SQLite.
@@ -155,4 +157,77 @@ do_faultsim_test 7.3 -prep {
                        {1 {vtable constructor failed: t1}}
 }
 
+}
+
+proc mit {blob} {
+  set scan(littleEndian) i*
+  set scan(bigEndian) I*
+  binary scan $blob $scan($::tcl_platform(byteOrder)) r
+  return $r
+}
+
+do_test 8.0 {
+  faultsim_delete_and_reopen
+  execsql { CREATE VIRTUAL TABLE t8 USING fts4 }
+  execsql "INSERT INTO t8 VALUES('a b c')"
+  execsql "INSERT INTO t8 VALUES('b b b')"
+  execsql "INSERT INTO t8 VALUES('[string repeat {c } 50000]')"
+  execsql "INSERT INTO t8 VALUES('d d d')"
+  execsql "INSERT INTO t8 VALUES('e e e')"
+  execsql "INSERT INTO t8(t8) VALUES('optimize')"
+  faultsim_save_and_close
+} {}
+
+do_faultsim_test 8.1 -prep { 
+  faultsim_restore_and_reopen
+  db func mit mit
+} -body {
+  execsql { SELECT mit(matchinfo(t8, 'x')) FROM t8 WHERE t8 MATCH 'a b c' }
+} -test {
+  faultsim_test_result {0 {{1 1 1 1 4 2 1 5 5}}}
+}
+do_faultsim_test 8.2 -faults oom-t* -prep { 
+  faultsim_restore_and_reopen
+  db func mit mit
+} -body {
+  execsql { SELECT mit(matchinfo(t8, 's')) FROM t8 WHERE t8 MATCH 'a b c' }
+} -test {
+  faultsim_test_result {0 3}
+}
+do_faultsim_test 8.3 -prep { 
+  faultsim_restore_and_reopen
+  db func mit mit
+} -body {
+  execsql { SELECT mit(matchinfo(t8, 'a')) FROM t8 WHERE t8 MATCH 'a b c' }
+} -test {
+  faultsim_test_result {0 10002}
+}
+do_faultsim_test 8.4 -prep { 
+  faultsim_restore_and_reopen
+  db func mit mit
+} -body {
+  execsql { SELECT mit(matchinfo(t8, 'l')) FROM t8 WHERE t8 MATCH 'a b c' }
+} -test {
+  faultsim_test_result {0 3}
+}
+
+do_test 9.0 {
+  faultsim_delete_and_reopen
+  execsql {
+    CREATE VIRTUAL TABLE t9 USING fts4(tokenize=porter);
+    INSERT INTO t9 VALUES(
+      'this record is used toooooooooooooooooooooooooooooooooooooo try to'
+    );
+    SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*';
+  }
+  faultsim_save_and_close
+} {}
+do_faultsim_test 9.1 -prep {
+  faultsim_restore_and_reopen
+} -body {
+  execsql { SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*' }
+} -test {
+  faultsim_test_result {0 {{0 0 20 39 0 0 64 2}}}
+}
+
 finish_test
index 2100287e012e4fc5f365b5c330766ccd1ed07afd..a7b49cf5ec48b90d57c1cd84d8dfdbe6c6531ad0 100644 (file)
@@ -265,6 +265,57 @@ do_matchinfo_test 4.4.3 t5 {t5 MATCH 'a b a'}       { s {3} }
 do_matchinfo_test 4.4.4 t5 {t5 MATCH 'a a a'}       { s {3 1} }
 do_matchinfo_test 4.4.5 t5 {t5 MATCH '"a b" "a b"'} { s {2} }
 
+do_execsql_test 4.5.0 {
+  CREATE VIRTUAL TABLE t6 USING fts4(a, b, c);
+  INSERT INTO t6 VALUES('a', 'b', 'c');
+}
+do_matchinfo_test 4.5.1 t6 {t6 MATCH 'a b c'}       { s {{1 1 1}} }
+
+
+#-------------------------------------------------------------------------
+# Check the following restrictions:
+#
+#   + Matchinfo flags 'a', 'l' and 'n' can only be used with fts4, not fts3.
+#   + Matchinfo flag 'l' cannot be used with matchinfo=fts3.
+#
+do_execsql_test 5.1 {
+  CREATE VIRTUAL TABLE t7 USING fts3(a, b);
+  INSERT INTO t7 VALUES('u v w', 'x y z');
+
+  CREATE VIRTUAL TABLE t8 USING fts4(a, b, matchinfo=fts3);
+  INSERT INTO t8 VALUES('u v w', 'x y z');
+}
+
+do_catchsql_test 5.2.1 { 
+  SELECT matchinfo(t7, 'a') FROM t7 WHERE t7 MATCH 'x y'
+} {1 {unrecognized matchinfo request: a}}
+do_catchsql_test 5.2.2 { 
+  SELECT matchinfo(t7, 'l') FROM t7 WHERE t7 MATCH 'x y'
+} {1 {unrecognized matchinfo request: l}}
+do_catchsql_test 5.2.3 { 
+  SELECT matchinfo(t7, 'n') FROM t7 WHERE t7 MATCH 'x y'
+} {1 {unrecognized matchinfo request: n}}
+
+do_catchsql_test 5.3.1 { 
+  SELECT matchinfo(t8, 'l') FROM t8 WHERE t8 MATCH 'x y'
+} {1 {unrecognized matchinfo request: l}}
+
+#-------------------------------------------------------------------------
+# Test that the offsets() function handles corruption in the %_content
+# table correctly.
+#
+do_execsql_test 6.1 {
+  CREATE VIRTUAL TABLE t9 USING fts4;
+  INSERT INTO t9 VALUES(
+    'this record is used to try to dectect corruption'
+  );
+  SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to';
+} {{0 0 20 2 0 0 27 2}}
+
+do_catchsql_test 6.2 {
+  UPDATE t9_content SET c0content = 'this record is used to'; 
+  SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to';
+} {1 {database disk image is malformed}}
 
 finish_test