1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-08 03:22:21 +03:00

Detect nested aggregate functions even if the inner aggregate function is

aliased using an AS clause.  Ticket #2526. (CVS 4179)

FossilOrigin-Name: de000280c6d0b13440d2450eb6ba42073ad46c56
This commit is contained in:
drh
2007-07-23 22:51:15 +00:00
parent 2e06c67c08
commit 36379e973b
4 changed files with 43 additions and 12 deletions

View File

@@ -12,7 +12,7 @@
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.300 2007/06/25 16:29:34 danielk1977 Exp $
** $Id: expr.c,v 1.301 2007/07/23 22:51:15 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -1140,11 +1140,17 @@ static int lookupName(
for(j=0; j<pEList->nExpr; j++){
char *zAs = pEList->a[j].zName;
if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){
Expr *pDup;
Expr *pDup, *pOrig;
assert( pExpr->pLeft==0 && pExpr->pRight==0 );
assert( pExpr->pList==0 );
assert( pExpr->pSelect==0 );
pDup = sqlite3ExprDup(pEList->a[j].pExpr);
pOrig = pEList->a[j].pExpr;
if( !pNC->allowAgg && ExprHasProperty(pOrig, EP_Agg) ){
sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
sqliteFree(zCol);
return 2;
}
pDup = sqlite3ExprDup(pOrig);
if( pExpr->flags & EP_ExpCollate ){
pDup->pColl = pExpr->pColl;
pDup->flags |= EP_ExpCollate;