Fix a problem with NULL handling in aggregate min/max when returning

values from the row containing the min or max.

FossilOrigin-Name: f27c7b4fb193126548e6a620ac89664d1efa3856
This commit is contained in:
drh
2012-02-02 18:42:09 +00:00
parent 7a95789c0c
commit 94a6d998f6
5 changed files with 159 additions and 15 deletions
+4 -3
View File
@@ -1342,11 +1342,12 @@ static void minmaxStep(
Mem *pBest;
UNUSED_PARAMETER(NotUsed);
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
pBest = (Mem *)sqlite3_aggregate_context(context, sizeof(*pBest));
if( !pBest ) return;
if( pBest->flags ){
if( sqlite3_value_type(argv[0])==SQLITE_NULL ){
if( pBest->flags ) sqlite3SkipAccumulatorLoad(context);
}else if( pBest->flags ){
int max;
int cmp;
CollSeq *pColl = sqlite3GetFuncCollSeq(context);
@@ -1373,7 +1374,7 @@ static void minMaxFinalize(sqlite3_context *context){
sqlite3_value *pRes;
pRes = (sqlite3_value *)sqlite3_aggregate_context(context, 0);
if( pRes ){
if( ALWAYS(pRes->flags) ){
if( pRes->flags ){
sqlite3_result_value(context, pRes);
}
sqlite3VdbeMemRelease(pRes);