Fix for ticket #84: If the WHERE clause is too complex, issue an error message

and refuse to do the SELECT.  The cutoff is a WHERE clause with 100 terms. (CVS 650)

FossilOrigin-Name: c07e493b62125e85eaea36b6945f1e146e2792b8
This commit is contained in:
drh
2002-06-28 01:02:38 +00:00
parent ac83f718fc
commit 83dcb1ad37
5 changed files with 74 additions and 23 deletions
+3 -1
View File
@@ -30,7 +30,7 @@
** But other routines are also provided to help in building up
** a program instruction by instruction.
**
** $Id: vdbe.c,v 1.161 2002/06/26 02:45:04 drh Exp $
** $Id: vdbe.c,v 1.162 2002/06/28 01:02:38 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -2845,6 +2845,8 @@ case OP_Commit: {
if( rc==SQLITE_OK ){
sqliteCommitInternalChanges(db);
}else{
if( db->pBeTemp ) sqliteBtreeRollback(db->pBeTemp);
sqliteBtreeRollback(pBt);
sqliteRollbackInternalChanges(db);
}
break;
+18 -12
View File
@@ -13,7 +13,7 @@
** the WHERE clause of SQL statements. Also found here are subroutines
** to generate VDBE code to evaluate expressions.
**
** $Id: where.c,v 1.56 2002/06/25 01:09:12 drh Exp $
** $Id: where.c,v 1.57 2002/06/28 01:02:38 drh Exp $
*/
#include "sqliteInt.h"
@@ -304,12 +304,28 @@ WhereInfo *sqliteWhereBegin(
int iDirectEq[32]; /* Term of the form ROWID==X for the N-th table */
int iDirectLt[32]; /* Term of the form ROWID<X or ROWID<=X */
int iDirectGt[32]; /* Term of the form ROWID>X or ROWID>=X */
ExprInfo aExpr[50]; /* The WHERE clause is divided into these expressions */
ExprInfo aExpr[101]; /* The WHERE clause is divided into these expressions */
/* pushKey is only allowed if there is a single table (as in an INSERT or
** UPDATE statement)
*/
assert( pushKey==0 || pTabList->nSrc==1 );
/* Split the WHERE clause into separate subexpressions where each
** subexpression is separated by an AND operator. If the aExpr[]
** array fills up, the last entry might point to an expression which
** contains additional unfactored AND operators.
*/
memset(aExpr, 0, sizeof(aExpr));
nExpr = exprSplit(ARRAYSIZE(aExpr), aExpr, pWhere);
if( nExpr==ARRAYSIZE(aExpr) ){
char zBuf[50];
sprintf(zBuf, "%d", ARRAYSIZE(aExpr)-1);
sqliteSetString(&pParse->zErrMsg, "WHERE clause too complex - no more "
"than ", zBuf, " terms allowed", 0);
pParse->nErr++;
return 0;
}
/* Allocate space for aOrder[] */
aOrder = sqliteMalloc( sizeof(int) * pTabList->nSrc );
@@ -337,16 +353,6 @@ WhereInfo *sqliteWhereBegin(
pWhere = 0;
}
/* Split the WHERE clause into as many as 32 separate subexpressions
** where each subexpression is separated by an AND operator. Any additional
** subexpressions are attached in the aExpr[32] and will not enter
** into the query optimizer computations. 32 is chosen as the cutoff
** since that is the number of bits in an integer that we use for an
** expression-used mask.
*/
memset(aExpr, 0, sizeof(aExpr));
nExpr = exprSplit(ARRAYSIZE(aExpr), aExpr, pWhere);
/* Analyze all of the subexpressions.
*/
for(i=0; i<nExpr; i++){