1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

Refactor for correct NULL handling in the IS TRUE, IS FALSE, IS NOT TRUE,

and IS NOT FALSE operators.

FossilOrigin-Name: cf2abd59be9971a55bd3d6c5df374c6aaa23bf81819482b42f01ee2484dcd739
This commit is contained in:
drh
2018-02-26 18:49:05 +00:00
parent bc8f68a3a0
commit 8abed7b907
8 changed files with 181 additions and 46 deletions

View File

@@ -437,13 +437,9 @@ static int lookupName(
pExpr->pTab = 0;
return WRC_Prune;
}
if( sqlite3StrICmp(zCol, "true")==0 ){
pExpr->op = TK_TRUE;
pExpr->pTab = 0;
return WRC_Prune;
}
if( sqlite3StrICmp(zCol, "false")==0 ){
pExpr->op = TK_FALSE;
if( sqlite3StrICmp(zCol, "true")==0 || sqlite3StrICmp(zCol, "false")==0 ){
pExpr->op = TK_TRUEFALSE;
pExpr->iTable = zCol[4]==0;
pExpr->pTab = 0;
return WRC_Prune;
}
@@ -796,28 +792,30 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
break;
}
case TK_IS:
/* Handle special cases of "x IS TRUE" and "x IS FALSE". The first
** is transformed into "+x" and the second into "NOT x". */
if( pExpr->pRight->op==TK_ID ){
int rc = resolveExprStep(pWalker, pExpr->pRight);
case TK_ISNOT: {
Expr *pRight;
assert( !ExprHasProperty(pExpr, EP_Reduced) );
/* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE",
** and "x IS NOT FALSE". */
if( (pRight = pExpr->pRight)->op==TK_ID ){
int rc = resolveExprStep(pWalker, pRight);
if( rc==WRC_Abort ) return WRC_Abort;
if( pExpr->pRight->op==TK_TRUE ){
pExpr->op = TK_ISTRUE;
return WRC_Continue;
}else if( pExpr->pRight->op==TK_FALSE ){
pExpr->op = TK_NOT;
if( pRight->op==TK_TRUEFALSE ){
assert( pRight->iTable==0 || pRight->iTable==1 );
pExpr->op2 = pExpr->op;
pExpr->op = TK_TRUTH;
return WRC_Continue;
}
}
/* Fall thru */
}
case TK_BETWEEN:
case TK_EQ:
case TK_NE:
case TK_LT:
case TK_LE:
case TK_GT:
case TK_GE:
case TK_ISNOT: {
case TK_GE: {
int nLeft, nRight;
if( pParse->db->mallocFailed ) break;
assert( pExpr->pLeft!=0 );