mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Detect misuse of aggregate functions in the ORDER BY clause of a query
even if the query also contains window functions. FossilOrigin-Name: 0d11d777c8d368f0b6e9faf3afccf7da1b041d303a68782e43aebd713aaecf51
This commit is contained in:
12
src/window.c
12
src/window.c
@@ -941,6 +941,14 @@ static int sqlite3WindowExtraAggFuncDepth(Walker *pWalker, Expr *pExpr){
|
||||
return WRC_Continue;
|
||||
}
|
||||
|
||||
static int disallowAggregatesInOrderByCb(Walker *pWalker, Expr *pExpr){
|
||||
if( pExpr->op==TK_AGG_FUNCTION && pExpr->pAggInfo==0 ){
|
||||
sqlite3ErrorMsg(pWalker->pParse,
|
||||
"misuse of aggregate: %s()", pExpr->u.zToken);
|
||||
}
|
||||
return WRC_Continue;
|
||||
}
|
||||
|
||||
/*
|
||||
** If the SELECT statement passed as the second argument does not invoke
|
||||
** any SQL window functions, this function is a no-op. Otherwise, it
|
||||
@@ -974,6 +982,10 @@ int sqlite3WindowRewrite(Parse *pParse, Select *p){
|
||||
}
|
||||
sqlite3AggInfoPersistWalkerInit(&w, pParse);
|
||||
sqlite3WalkSelect(&w, p);
|
||||
if( (p->selFlags & SF_Aggregate)==0 ){
|
||||
w.xExprCallback = disallowAggregatesInOrderByCb;
|
||||
sqlite3WalkExprList(&w, p->pOrderBy);
|
||||
}
|
||||
|
||||
p->pSrc = 0;
|
||||
p->pWhere = 0;
|
||||
|
Reference in New Issue
Block a user