Index: src/func.c ================================================================== --- src/func.c +++ src/func.c @@ -14,11 +14,11 @@ ** ** There is only one exported symbol in this file - the function ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: func.c,v 1.43 2004/02/25 22:51:06 rdc Exp $ +** $Id: func.c,v 1.43.2.1 2004/06/23 21:16:52 drh Exp $ */ #include #include #include #include @@ -521,36 +521,45 @@ xCompare = sqliteCompare; }else{ xCompare = strcmp; } mask = (int)sqlite_user_data(context); + assert( mask==0 || mask==-1 ); p = sqlite_aggregate_context(context, sizeof(*p)); - if( p==0 || argc<1 || argv[0]==0 ) return; + if( p==0 || argc<1 ) return; + if( mask==0 && p->zBuf[0]>=2 ) return; + if( argv[0]==0 ){ + if( mask==0 ){ + p->zBuf[0] |= 2; + } + return; + } + assert( p->zBuf[0]<2 ); if( p->z==0 || (xCompare(argv[0],p->z)^mask)<0 ){ int len; - if( !p->zBuf[0] ){ + if( p->zBuf[0]!=0 ){ sqliteFree(p->z); } len = strlen(argv[0]); if( len < sizeof(p->zBuf)-1 ){ p->z = &p->zBuf[1]; - p->zBuf[0] = 1; + p->zBuf[0] = 0; }else{ p->z = sqliteMalloc( len+1 ); - p->zBuf[0] = 0; + p->zBuf[0] = 1; if( p->z==0 ) return; } strcpy(p->z, argv[0]); } } static void minMaxFinalize(sqlite_func *context){ MinMaxCtx *p; p = sqlite_aggregate_context(context, sizeof(*p)); - if( p && p->z ){ + if( p && p->z && p->zBuf[0]<2 ){ sqlite_set_result_string(context, p->z, strlen(p->z)); } - if( p && !p->zBuf[0] ){ + if( p && (p->zBuf[0]&1)!=0 ){ sqliteFree(p->z); } } /* @@ -619,19 +628,29 @@ }; static const char *azTypeFuncs[] = { "min", "max", "typeof" }; int i; for(i=0; i