diff options
author | drh <drh@noemail.net> | 2013-04-13 19:59:58 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2013-04-13 19:59:58 +0000 |
commit | a3a5bd9b62324bcfafaf2e6d4d98fbc57e1a1d94 (patch) | |
tree | 341479db97b10f811ac1fbe3dbd533b449b99540 /src/resolve.c | |
parent | 4b2ac35e5bf760bad76366e44c3ed6eb4448ed41 (diff) | |
download | sqlite-a3a5bd9b62324bcfafaf2e6d4d98fbc57e1a1d94.tar.gz sqlite-a3a5bd9b62324bcfafaf2e6d4d98fbc57e1a1d94.zip |
Only consider AS names from the result set as candidates for resolving
identifiers in the WHERE clause if there are no other matches. In the
ORDER BY clause, AS names take priority over any column names.
Candidate fix for ticket [2500cdb9be].
FossilOrigin-Name: ad53924dcadffb95c6497c46c228c67e8f5370e4
Diffstat (limited to 'src/resolve.c')
-rw-r--r-- | src/resolve.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/resolve.c b/src/resolve.c index 038013867..9b350caf8 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -388,7 +388,10 @@ static int lookupName( ** Note that the expression in the result set should have already been ** resolved by the time the WHERE clause is resolved. */ - if( cnt==0 && (pEList = pNC->pEList)!=0 && zTab==0 ){ + if( (pEList = pNC->pEList)!=0 + && zTab==0 + && ((pNC->ncFlags & NC_AsMaybe)==0 || cnt==0) + ){ for(j=0; j<pEList->nExpr; j++){ char *zAs = pEList->a[j].zName; if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){ @@ -479,7 +482,9 @@ static int lookupName( lookupname_end: if( cnt==1 ){ assert( pNC!=0 ); - sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList); + if( pExpr->op!=TK_AS ){ + sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList); + } /* Increment the nRef value on all name contexts from TopNC up to ** the point where the name matched. */ for(;;){ @@ -1154,11 +1159,10 @@ static int resolveSelectStep(Walker *pWalker, Select *p){ ** re-evaluated for each reference to it. */ sNC.pEList = p->pEList; - if( sqlite3ResolveExprNames(&sNC, p->pWhere) || - sqlite3ResolveExprNames(&sNC, p->pHaving) - ){ - return WRC_Abort; - } + if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort; + sNC.ncFlags |= NC_AsMaybe; + if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort; + sNC.ncFlags &= ~NC_AsMaybe; /* The ORDER BY and GROUP BY clauses may not refer to terms in ** outer queries |