mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Raise an error right away if the number of aggregate terms in a query
exceeds the maximum number of columns. FossilOrigin-Name: 5508b56fd24016c13981ec280ecdd833007c9d8dd595edb295b984c2b487b5c8
This commit is contained in:
16
src/expr.c
16
src/expr.c
@@ -7015,7 +7015,9 @@ static void findOrCreateAggInfoColumn(
|
||||
){
|
||||
struct AggInfo_col *pCol;
|
||||
int k;
|
||||
int mxTerm = pParse->db->aLimit[SQLITE_LIMIT_COLUMN];
|
||||
|
||||
assert( mxTerm <= SMXV(i16) );
|
||||
assert( pAggInfo->iFirstReg==0 );
|
||||
pCol = pAggInfo->aCol;
|
||||
for(k=0; k<pAggInfo->nColumn; k++, pCol++){
|
||||
@@ -7033,6 +7035,10 @@ static void findOrCreateAggInfoColumn(
|
||||
assert( pParse->db->mallocFailed );
|
||||
return;
|
||||
}
|
||||
if( k>mxTerm ){
|
||||
sqlite3ErrorMsg(pParse, "more than %d aggregate terms", mxTerm);
|
||||
k = mxTerm;
|
||||
}
|
||||
pCol = &pAggInfo->aCol[k];
|
||||
assert( ExprUseYTab(pExpr) );
|
||||
pCol->pTab = pExpr->y.pTab;
|
||||
@@ -7066,6 +7072,7 @@ fix_up_expr:
|
||||
if( pExpr->op==TK_COLUMN ){
|
||||
pExpr->op = TK_AGG_COLUMN;
|
||||
}
|
||||
assert( k <= SMXV(pExpr->iAgg) );
|
||||
pExpr->iAgg = (i16)k;
|
||||
}
|
||||
|
||||
@@ -7150,13 +7157,19 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
|
||||
** function that is already in the pAggInfo structure
|
||||
*/
|
||||
struct AggInfo_func *pItem = pAggInfo->aFunc;
|
||||
int mxTerm = pParse->db->aLimit[SQLITE_LIMIT_COLUMN];
|
||||
assert( mxTerm <= SMXV(i16) );
|
||||
for(i=0; i<pAggInfo->nFunc; i++, pItem++){
|
||||
if( NEVER(pItem->pFExpr==pExpr) ) break;
|
||||
if( sqlite3ExprCompare(0, pItem->pFExpr, pExpr, -1)==0 ){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( i>=pAggInfo->nFunc ){
|
||||
if( i>mxTerm ){
|
||||
sqlite3ErrorMsg(pParse, "more than %d aggregate terms", mxTerm);
|
||||
i = mxTerm;
|
||||
assert( i<pAggInfo->nFunc );
|
||||
}else if( i>=pAggInfo->nFunc ){
|
||||
/* pExpr is original. Make a new entry in pAggInfo->aFunc[]
|
||||
*/
|
||||
u8 enc = ENC(pParse->db);
|
||||
@@ -7210,6 +7223,7 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
|
||||
*/
|
||||
assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
|
||||
ExprSetVVAProperty(pExpr, EP_NoReduce);
|
||||
assert( i <= SMXV(pExpr->iAgg) );
|
||||
pExpr->iAgg = (i16)i;
|
||||
pExpr->pAggInfo = pAggInfo;
|
||||
return WRC_Prune;
|
||||
|
Reference in New Issue
Block a user