diff options
author | drh <drh@noemail.net> | 2015-02-09 16:09:34 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2015-02-09 16:09:34 +0000 |
commit | 2308ed385462208621ce052e5736b317fa81068f (patch) | |
tree | f8de76952454441f86a8fdf61fc70503c5453ceb /src/expr.c | |
parent | 885a5b030ee3717b78bfb82d61e6ee38ef0892ea (diff) | |
download | sqlite-2308ed385462208621ce052e5736b317fa81068f.tar.gz sqlite-2308ed385462208621ce052e5736b317fa81068f.zip |
Propagate the COLLATE operator upward through function calls.
Initial fix for ticket [ca0d20b6cdddec5e8].
FossilOrigin-Name: c053448a55f9d030e8ffe88cf4fc14ada7f6ec19
Diffstat (limited to 'src/expr.c')
-rw-r--r-- | src/expr.c | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/src/expr.c b/src/expr.c index 2def950f2..496c7a317 100644 --- a/src/expr.c +++ b/src/expr.c @@ -146,10 +146,20 @@ CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr){ break; } if( p->flags & EP_Collate ){ - if( ALWAYS(p->pLeft) && (p->pLeft->flags & EP_Collate)!=0 ){ + if( p->pLeft && (p->pLeft->flags & EP_Collate)!=0 ){ p = p->pLeft; }else{ - p = p->pRight; + Expr *pNext = p->pRight; + if( p->x.pList!=0 && !ExprHasProperty(p, EP_xIsSelect) ){ + int i; + for(i=0; i<p->x.pList->nExpr; i++){ + if( ExprHasProperty(p->x.pList->a[i].pExpr, EP_Collate) ){ + pNext = p->x.pList->a[i].pExpr; + break; + } + } + } + p = pNext; } }else{ break; @@ -355,6 +365,9 @@ static void heightOfSelect(Select *p, int *pnHeight){ ** Expr.pSelect member has a height of 1. Any other expression ** has a height equal to the maximum height of any other ** referenced Expr plus one. +** +** Also propagate EP_Propagate flags up from Expr.x.pList to Expr.flags, +** if appropriate. */ static void exprSetHeight(Expr *p){ int nHeight = 0; @@ -362,8 +375,9 @@ static void exprSetHeight(Expr *p){ heightOfExpr(p->pRight, &nHeight); if( ExprHasProperty(p, EP_xIsSelect) ){ heightOfSelect(p->x.pSelect, &nHeight); - }else{ + }else if( p->x.pList ){ heightOfExprList(p->x.pList, &nHeight); + p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList); } p->nHeight = nHeight + 1; } @@ -372,8 +386,11 @@ static void exprSetHeight(Expr *p){ ** Set the Expr.nHeight variable using the exprSetHeight() function. If ** the height is greater than the maximum allowed expression depth, ** leave an error in pParse. +** +** Also propagate all EP_Propagate flags from the Expr.x.pList into +** Expr.flags. */ -void sqlite3ExprSetHeight(Parse *pParse, Expr *p){ +void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){ exprSetHeight(p); sqlite3ExprCheckHeight(pParse, p->nHeight); } @@ -387,8 +404,17 @@ int sqlite3SelectExprHeight(Select *p){ heightOfSelect(p, &nHeight); return nHeight; } -#else - #define exprSetHeight(y) +#else /* ABOVE: Height enforcement enabled. BELOW: Height enforcement off */ +/* +** Propagate all EP_Propagate flags from the Expr.x.pList into +** Expr.flags. +*/ +void sqlite3ExprSetHeightAndFlags(Parse *pParse, Expr *p){ + if( p && p->x.pList && !ExprHasProperty(p, EP_xIsSelect) ){ + p->flags |= EP_Propagate & sqlite3ExprListFlags(p->x.pList); + } +} +#define exprSetHeight(y) #endif /* SQLITE_MAX_EXPR_DEPTH>0 */ /* @@ -594,7 +620,7 @@ Expr *sqlite3ExprFunction(Parse *pParse, ExprList *pList, Token *pToken){ } pNew->x.pList = pList; assert( !ExprHasProperty(pNew, EP_xIsSelect) ); - sqlite3ExprSetHeight(pParse, pNew); + sqlite3ExprSetHeightAndFlags(pParse, pNew); return pNew; } @@ -1210,16 +1236,18 @@ void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){ } /* -** Return TRUE if any expression in ExprList has any of the EP_* -** properties given by "m" +** Return the bitwise-OR of all Expr.flags fields in the given +** ExprList. */ -int sqlite3AnyExprListHasProperty(const ExprList *pList, u32 m){ +u32 sqlite3ExprListFlags(const ExprList *pList){ int i; - if( pList==0 ) return 0; - for(i=0; i<pList->nExpr; i++){ - if( ExprHasProperty(pList->a[i].pExpr, m) ) return 1; + u32 m = 0; + if( pList ){ + for(i=0; i<pList->nExpr; i++){ + m |= pList->a[i].pExpr->flags; + } } - return 0; + return m; } /* |