/ Check-in [1a08a836]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improve coverage of code in fts3.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:1a08a836fa919524216a16faf5212eebc9ad788c9e15463b68b0576dfccd4387
User & Date: dan 2017-04-17 13:38:09
Context
2017-04-17
16:07
Further improvements to test coverage in fts3. check-in: 352413ee user: dan tags: trunk
13:38
Improve coverage of code in fts3. check-in: 1a08a836 user: dan tags: trunk
13:18
Fix the ".column" output mode in the command-line shell so that it correctly counts and formats multi-byte UTF characters. check-in: f508aff8 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts3/fts3.c.

  1215   1215         }else{
  1216   1216           for(iOpt=0; iOpt<SizeofArray(aFts4Opt); iOpt++){
  1217   1217             struct Fts4Option *pOp = &aFts4Opt[iOpt];
  1218   1218             if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){
  1219   1219               break;
  1220   1220             }
  1221   1221           }
  1222         -        if( iOpt==SizeofArray(aFts4Opt) ){
  1223         -          sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z);
  1224         -          rc = SQLITE_ERROR;
  1225         -        }else{
  1226         -          switch( iOpt ){
  1227         -            case 0:               /* MATCHINFO */
  1228         -              if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
  1229         -                sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal);
  1230         -                rc = SQLITE_ERROR;
  1231         -              }
  1232         -              bNoDocsize = 1;
  1233         -              break;
  1234         -
  1235         -            case 1:               /* PREFIX */
  1236         -              sqlite3_free(zPrefix);
  1237         -              zPrefix = zVal;
  1238         -              zVal = 0;
  1239         -              break;
  1240         -
  1241         -            case 2:               /* COMPRESS */
  1242         -              sqlite3_free(zCompress);
  1243         -              zCompress = zVal;
  1244         -              zVal = 0;
  1245         -              break;
  1246         -
  1247         -            case 3:               /* UNCOMPRESS */
  1248         -              sqlite3_free(zUncompress);
  1249         -              zUncompress = zVal;
  1250         -              zVal = 0;
  1251         -              break;
  1252         -
  1253         -            case 4:               /* ORDER */
  1254         -              if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3)) 
  1255         -               && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4)) 
  1256         -              ){
  1257         -                sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal);
  1258         -                rc = SQLITE_ERROR;
  1259         -              }
  1260         -              bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
  1261         -              break;
  1262         -
  1263         -            case 5:              /* CONTENT */
  1264         -              sqlite3_free(zContent);
  1265         -              zContent = zVal;
  1266         -              zVal = 0;
  1267         -              break;
  1268         -
  1269         -            case 6:              /* LANGUAGEID */
  1270         -              assert( iOpt==6 );
  1271         -              sqlite3_free(zLanguageid);
  1272         -              zLanguageid = zVal;
  1273         -              zVal = 0;
  1274         -              break;
  1275         -
  1276         -            case 7:              /* NOTINDEXED */
  1277         -              azNotindexed[nNotindexed++] = zVal;
  1278         -              zVal = 0;
  1279         -              break;
  1280         -          }
         1222  +        switch( iOpt ){
         1223  +          case 0:               /* MATCHINFO */
         1224  +            if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
         1225  +              sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal);
         1226  +              rc = SQLITE_ERROR;
         1227  +            }
         1228  +            bNoDocsize = 1;
         1229  +            break;
         1230  +
         1231  +          case 1:               /* PREFIX */
         1232  +            sqlite3_free(zPrefix);
         1233  +            zPrefix = zVal;
         1234  +            zVal = 0;
         1235  +            break;
         1236  +
         1237  +          case 2:               /* COMPRESS */
         1238  +            sqlite3_free(zCompress);
         1239  +            zCompress = zVal;
         1240  +            zVal = 0;
         1241  +            break;
         1242  +
         1243  +          case 3:               /* UNCOMPRESS */
         1244  +            sqlite3_free(zUncompress);
         1245  +            zUncompress = zVal;
         1246  +            zVal = 0;
         1247  +            break;
         1248  +
         1249  +          case 4:               /* ORDER */
         1250  +            if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3)) 
         1251  +             && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4)) 
         1252  +            ){
         1253  +              sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal);
         1254  +              rc = SQLITE_ERROR;
         1255  +            }
         1256  +            bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
         1257  +            break;
         1258  +
         1259  +          case 5:              /* CONTENT */
         1260  +            sqlite3_free(zContent);
         1261  +            zContent = zVal;
         1262  +            zVal = 0;
         1263  +            break;
         1264  +
         1265  +          case 6:              /* LANGUAGEID */
         1266  +            assert( iOpt==6 );
         1267  +            sqlite3_free(zLanguageid);
         1268  +            zLanguageid = zVal;
         1269  +            zVal = 0;
         1270  +            break;
         1271  +
         1272  +          case 7:              /* NOTINDEXED */
         1273  +            azNotindexed[nNotindexed++] = zVal;
         1274  +            zVal = 0;
         1275  +            break;
         1276  +
         1277  +          default:
         1278  +            assert( iOpt==SizeofArray(aFts4Opt) );
         1279  +            sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z);
         1280  +            rc = SQLITE_ERROR;
         1281  +            break;
  1281   1282           }
  1282   1283           sqlite3_free(zVal);
  1283   1284         }
  1284   1285       }
  1285   1286   
  1286   1287       /* Otherwise, the argument is a column name. */
  1287   1288       else {

Changes to test/fts3aa.test.

   239    239   do_execsql_test 8.4 {
   240    240     SELECT docid FROM t0 WHERE t0 MATCH 'abc';
   241    241   } {6 5}
   242    242   do_execsql_test 8.5 {
   243    243     SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"';
   244    244   } {}
   245    245   
          246  +
          247  +do_execsql_test 9.1 {
          248  +  CREATE VIRTUAL TABLE t9 USING fts4(a, "", '---');
          249  +}
          250  +do_execsql_test 9.2 {
          251  +  CREATE VIRTUAL TABLE t10 USING fts3(<, b, c);
          252  +}
   246    253   
   247    254   finish_test

Added test/fts3corrupt3.test.

            1  +# 2010 October 27
            2  +#
            3  +#    May you do good and not evil.
            4  +#    May you find forgiveness for yourself and forgive others.
            5  +#    May you share freely, never taking more than you give.
            6  +#
            7  +#***********************************************************************
            8  +# Test that the FTS3 extension does not crash when it encounters a
            9  +# corrupt data structure on disk.
           10  +#
           11  +
           12  +
           13  +set testdir [file dirname $argv0]
           14  +source $testdir/tester.tcl
           15  +
           16  +# If SQLITE_ENABLE_FTS3 is not defined, omit this file.
           17  +ifcapable !fts3 { finish_test ; return }
           18  +
           19  +set ::testprefix fts3corrupt3
           20  +
           21  +do_execsql_test 1.0 {
           22  +  CREATE VIRTUAL TABLE t1 USING fts3;
           23  +  BEGIN;
           24  +    INSERT INTO t1 VALUES('one');
           25  +    INSERT INTO t1 VALUES('one');
           26  +    INSERT INTO t1 VALUES('one');
           27  +  COMMIT;
           28  +}
           29  +do_execsql_test 1.1 {
           30  +  SELECT quote(root) from t1_segdir;
           31  +} {X'00036F6E6509010200010200010200'}
           32  +do_execsql_test 1.2 {
           33  +  UPDATE t1_segdir SET root = X'00036F6E650EFFFFFFFFFFFFFFFFFFFFFFFF0200';
           34  +}
           35  +do_catchsql_test 1.3 {
           36  +  SELECT rowid FROM t1 WHERE t1 MATCH 'one'
           37  +} {0 -1}
           38  +
           39  +
           40  +
           41  +
           42  +finish_test

Changes to test/fts3fault.test.

    14     14   source $testdir/tester.tcl
    15     15   
    16     16   set ::testprefix fts3fault
    17     17   
    18     18   # If SQLITE_ENABLE_FTS3 is not defined, omit this file.
    19     19   ifcapable !fts3 { finish_test ; return }
    20     20   
    21         -if 0 {
    22         -
    23     21   # Test error handling in the sqlite3Fts3Init() function. This is the 
    24     22   # function that registers the FTS3 module and various support functions
    25     23   # with SQLite.
    26     24   #
    27     25   do_faultsim_test 1 -body { 
    28     26     sqlite3 db test.db 
    29     27     expr 0
................................................................................
   156    154   } -test {
   157    155     faultsim_test_result {1 {unrecognized parameter: matchnfo=fts3}} \
   158    156                          {1 {vtable constructor failed: t1}} \
   159    157                          {1 {SQL logic error or missing database}}
   160    158   }
   161    159   
   162    160   
   163         -}
   164         -
   165    161   proc mit {blob} {
   166    162     set scan(littleEndian) i*
   167    163     set scan(bigEndian) I*
   168    164     binary scan $blob $scan($::tcl_platform(byteOrder)) r
   169    165     return $r
   170    166   }
   171    167   
................................................................................
   229    225   do_faultsim_test 9.1 -prep {
   230    226     faultsim_restore_and_reopen
   231    227   } -body {
   232    228     execsql { SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*' }
   233    229   } -test {
   234    230     faultsim_test_result {0 {{0 0 20 39 0 0 64 2}}}
   235    231   }
          232  +
          233  +do_faultsim_test 10.1 -prep {
          234  +  faultsim_delete_and_reopen
          235  +} -body {
          236  +  execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, languageid=d) }
          237  +} -test {
          238  +  faultsim_test_result {0 {}}
          239  +}
   236    240   
   237    241   finish_test

Changes to test/fts4langid.test.

    10     10   #*************************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is testing the languageid=xxx FTS4 option.
    13     13   #
    14     14   
    15     15   set testdir [file dirname $argv0]
    16     16   source $testdir/tester.tcl
    17         -set ::testprefix fts4content
    18     17   
    19     18   # If SQLITE_ENABLE_FTS3 is defined, omit this file.
    20     19   ifcapable !fts3 {
    21     20     finish_test
    22     21     return
    23     22   }
    24     23   
................................................................................
   336    335   do_test_query1 3.3.2 {"zero one two"} { rowid_list "zero one two" }
   337    336   do_test_query1 3.3.3 {zero one two} {
   338    337     and_merge_lists [rowid_list zero] [rowid_list one] [rowid_list two]
   339    338   }
   340    339   do_test_query1 3.3.4 {"zero one" OR "one two"} {
   341    340     or_merge_lists [rowid_list "zero one"] [rowid_list "one two"]
   342    341   }
          342  +
          343  +do_execsql_test 3.4 {
          344  +  CREATE TABLE t8c(a, b);
          345  +  CREATE VIRTUAL TABLE t8 USING fts4(content=t8c, languageid=langid);
          346  +  INSERT INTO t8(docid, a, b) VALUES(-1, 'one two three', 'x y z');
          347  +  SELECT docid FROM t8 WHERE t8 MATCH 'one x' AND langid=0
          348  +} {-1}
   343    349   
   344    350   #-------------------------------------------------------------------------
   345    351   # Test cases 4.*
   346    352   #
   347    353   proc build_multilingual_db_2 {db} {
   348    354     $db eval {
   349    355       CREATE VIRTUAL TABLE t4 USING fts4(

Changes to test/permutations.test.

   261    261     fts3offsets.test fts3prefix2.test fts3prefix.test fts3query.test
   262    262     fts3shared.test fts3snippet.test fts3sort.test fts3tok1.test
   263    263     fts3tok_err.test fts3varint.test fts4aa.test fts4check.test
   264    264     fts4content.test fts4docid.test fts4growth2.test fts4growth.test
   265    265     fts4incr.test fts4langid.test fts4lastrowid.test fts4merge2.test
   266    266     fts4merge4.test fts4merge.test fts4noti.test fts4onepass.test 
   267    267     fts4opt.test fts4unicode.test
          268  +  fts3corrupt3.test
   268    269   }
   269    270   
   270    271   test_suite "fts5" -prefix "" -description {
   271    272     All FTS5 tests.
   272    273   } -files [glob -nocomplain $::testdir/../ext/fts5/test/*.test]
   273    274   
   274    275   test_suite "fts5-light" -prefix "" -description {