/ Check-in [d1a6a2ed]
Login

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

Overview
Comment:Fix a bug parsing "<expr> AND (abc NEAR def)" in fts3_expr.c. (CVS 6091)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d1a6a2edd799d65ff88510df951e909919e35b6b
User & Date: danielk1977 2009-01-01 04:19:51
Context
2009-01-01
07:08
Add pseudo-random tests of the fts3 expression parser. Revise the fix in (6091). (CVS 6092) check-in: 11c2d468 user: danielk1977 tags: trunk
04:19
Fix a bug parsing "<expr> AND (abc NEAR def)" in fts3_expr.c. (CVS 6091) check-in: d1a6a2ed user: danielk1977 tags: trunk
2008-12-31
21:52
Avoid surplus bytes at the end of the keyword string table. Add testcase() macros to make sure all keywords are used during testing. (CVS 6090) check-in: 73958060 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to ext/fts3/fts3_expr.c.

   525    525           pNot->pRight = p;
   526    526           if( pNotBranch ){
   527    527             pNotBranch->pLeft = p;
   528    528             pNot->pRight = pNotBranch;
   529    529           }
   530    530           pNotBranch = pNot;
   531    531         }else{
   532         -        assert( p->eType!=FTSQUERY_PHRASE || !p->pPhrase->isNot );
   533         -        isPhrase = (p->eType==FTSQUERY_PHRASE || p->pLeft);
          532  +        int eType = p->eType;
          533  +        assert( eType!=FTSQUERY_PHRASE || !p->pPhrase->isNot );
          534  +        isPhrase = (eType==FTSQUERY_PHRASE || p->pLeft);
   534    535           if( !isPhrase && isRequirePhrase ){
   535    536             sqlite3Fts3ExprFree(p);
   536    537             rc = SQLITE_ERROR;
   537    538             goto exprparse_out;
   538    539           }
   539    540     
   540    541           if( isPhrase && !isRequirePhrase ){
................................................................................
   550    551             memset(pAnd, 0, sizeof(Fts3Expr));
   551    552             pAnd->eType = FTSQUERY_AND;
   552    553             insertBinaryOperator(&pRet, pPrev, pAnd);
   553    554             pPrev = pAnd;
   554    555           }
   555    556   
   556    557           if( pPrev && (
   557         -            (pPrev->eType==FTSQUERY_NEAR && p->eType!=FTSQUERY_PHRASE)
   558         -         || (p->eType==FTSQUERY_NEAR && pPrev->eType!=FTSQUERY_PHRASE) 
          558  +            (pPrev->eType==FTSQUERY_NEAR && eType!=FTSQUERY_PHRASE)
          559  +         || (eType==FTSQUERY_NEAR && pPrev->eType!=FTSQUERY_PHRASE && !isPhrase)
   559    560           )){
   560    561             /* This is an attempt to do "phrase NEAR (bracketed expression)"
   561    562             ** or "(bracketed expression) NEAR phrase", both of which are
   562    563             ** illegal. Return an error.
   563    564             */
   564    565             sqlite3Fts3ExprFree(p);
   565    566             rc = SQLITE_ERROR;

Changes to test/fts3expr.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #*************************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is testing the FTS3 module.
    13     13   #
    14         -# $Id: fts3expr.test,v 1.1 2008/12/17 15:18:18 danielk1977 Exp $
           14  +# $Id: fts3expr.test,v 1.2 2009/01/01 04:19:51 danielk1977 Exp $
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # If SQLITE_ENABLE_FTS3 is defined, omit this file.
    21     21   ifcapable !fts3 {
................................................................................
   115    115   do_test fts3expr-3.3 {
   116    116     test_fts3expr2 "(ab OR cd)"
   117    117   } {OR ab cd}
   118    118   do_test fts3expr-3.4 {
   119    119     test_fts3expr2 "(((ab OR cd)))"
   120    120   } {OR ab cd}
   121    121   
          122  +do_test fts3expr-3.5 {
          123  +  test_fts3expr2 "one AND (two NEAR three)"
          124  +} {AND one {NEAR/10 two three}}
          125  +
   122    126   #------------------------------------------------------------------------
   123    127   # The following tests, fts3expr-4.*, test the parsers response to syntax
   124    128   # errors in query expressions. This is done using a real fts3 table and
   125    129   # MATCH clauses, not the parser test interface.
   126    130   # 
   127    131   do_test fts3expr-4.1 {
   128    132     execsql { CREATE VIRTUAL TABLE t1 USING fts3(a, b, c) }