SQLite

Check-in [d1a6a2edd7]
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
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d1a6a2edd799d65ff88510df951e909919e35b6b
User & Date: danielk1977 2009-01-01 04:19:51.000
Context
2009-01-01
07:08
Add pseudo-random tests of the fts3 expression parser. Revise the fix in (6091). (CVS 6092) (check-in: 11c2d46861 user: danielk1977 tags: trunk)
04:19
Fix a bug parsing "<expr> AND (abc NEAR def)" in fts3_expr.c. (CVS 6091) (check-in: d1a6a2edd7 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: 73958060aa user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to ext/fts3/fts3_expr.c.
525
526
527
528
529
530
531

532
533
534
535
536
537
538
539
540
        pNot->pRight = p;
        if( pNotBranch ){
          pNotBranch->pLeft = p;
          pNot->pRight = pNotBranch;
        }
        pNotBranch = pNot;
      }else{

        assert( p->eType!=FTSQUERY_PHRASE || !p->pPhrase->isNot );
        isPhrase = (p->eType==FTSQUERY_PHRASE || p->pLeft);
        if( !isPhrase && isRequirePhrase ){
          sqlite3Fts3ExprFree(p);
          rc = SQLITE_ERROR;
          goto exprparse_out;
        }
  
        if( isPhrase && !isRequirePhrase ){







>
|
|







525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
        pNot->pRight = p;
        if( pNotBranch ){
          pNotBranch->pLeft = p;
          pNot->pRight = pNotBranch;
        }
        pNotBranch = pNot;
      }else{
        int eType = p->eType;
        assert( eType!=FTSQUERY_PHRASE || !p->pPhrase->isNot );
        isPhrase = (eType==FTSQUERY_PHRASE || p->pLeft);
        if( !isPhrase && isRequirePhrase ){
          sqlite3Fts3ExprFree(p);
          rc = SQLITE_ERROR;
          goto exprparse_out;
        }
  
        if( isPhrase && !isRequirePhrase ){
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
          memset(pAnd, 0, sizeof(Fts3Expr));
          pAnd->eType = FTSQUERY_AND;
          insertBinaryOperator(&pRet, pPrev, pAnd);
          pPrev = pAnd;
        }

        if( pPrev && (
            (pPrev->eType==FTSQUERY_NEAR && p->eType!=FTSQUERY_PHRASE)
         || (p->eType==FTSQUERY_NEAR && pPrev->eType!=FTSQUERY_PHRASE) 
        )){
          /* This is an attempt to do "phrase NEAR (bracketed expression)"
          ** or "(bracketed expression) NEAR phrase", both of which are
          ** illegal. Return an error.
          */
          sqlite3Fts3ExprFree(p);
          rc = SQLITE_ERROR;







|
|







551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
          memset(pAnd, 0, sizeof(Fts3Expr));
          pAnd->eType = FTSQUERY_AND;
          insertBinaryOperator(&pRet, pPrev, pAnd);
          pPrev = pAnd;
        }

        if( pPrev && (
            (pPrev->eType==FTSQUERY_NEAR && eType!=FTSQUERY_PHRASE)
         || (eType==FTSQUERY_NEAR && pPrev->eType!=FTSQUERY_PHRASE && !isPhrase)
        )){
          /* This is an attempt to do "phrase NEAR (bracketed expression)"
          ** or "(bracketed expression) NEAR phrase", both of which are
          ** illegal. Return an error.
          */
          sqlite3Fts3ExprFree(p);
          rc = SQLITE_ERROR;
Changes to test/fts3expr.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2006 September 9
#
# 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.
#
#*************************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is testing the FTS3 module.
#
# $Id: fts3expr.test,v 1.1 2008/12/17 15:18:18 danielk1977 Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# If SQLITE_ENABLE_FTS3 is defined, omit this file.
ifcapable !fts3 {













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2006 September 9
#
# 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.
#
#*************************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is testing the FTS3 module.
#
# $Id: fts3expr.test,v 1.2 2009/01/01 04:19:51 danielk1977 Exp $
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# If SQLITE_ENABLE_FTS3 is defined, omit this file.
ifcapable !fts3 {
115
116
117
118
119
120
121




122
123
124
125
126
127
128
do_test fts3expr-3.3 {
  test_fts3expr2 "(ab OR cd)"
} {OR ab cd}
do_test fts3expr-3.4 {
  test_fts3expr2 "(((ab OR cd)))"
} {OR ab cd}





#------------------------------------------------------------------------
# The following tests, fts3expr-4.*, test the parsers response to syntax
# errors in query expressions. This is done using a real fts3 table and
# MATCH clauses, not the parser test interface.
# 
do_test fts3expr-4.1 {
  execsql { CREATE VIRTUAL TABLE t1 USING fts3(a, b, c) }







>
>
>
>







115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
do_test fts3expr-3.3 {
  test_fts3expr2 "(ab OR cd)"
} {OR ab cd}
do_test fts3expr-3.4 {
  test_fts3expr2 "(((ab OR cd)))"
} {OR ab cd}

do_test fts3expr-3.5 {
  test_fts3expr2 "one AND (two NEAR three)"
} {AND one {NEAR/10 two three}}

#------------------------------------------------------------------------
# The following tests, fts3expr-4.*, test the parsers response to syntax
# errors in query expressions. This is done using a real fts3 table and
# MATCH clauses, not the parser test interface.
# 
do_test fts3expr-4.1 {
  execsql { CREATE VIRTUAL TABLE t1 USING fts3(a, b, c) }