Add manifest type aware versions of the min() and max() aggregates. (CVS 1452)
FossilOrigin-Name: b77c268ebebd5401c3f519a72cfb81438207368c
This commit is contained in:
parent
6ddcca553d
commit
88208050b6
16
manifest
16
manifest
@ -1,5 +1,5 @@
|
||||
C Aggregate\sfunctions\salso\suse\ssqlite_value*\sinstead\sof\sconst\schar\s*\sfor\narguments.\s(CVS\s1451)
|
||||
D 2004-05-24T23:48:26
|
||||
C Add\smanifest\stype\saware\sversions\sof\sthe\smin()\sand\smax()\saggregates.\s(CVS\s1452)
|
||||
D 2004-05-25T01:13:21
|
||||
F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a
|
||||
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
|
||||
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
|
||||
@ -32,7 +32,7 @@ F src/date.c 64fd7169c7d599ec8eaa99121d59e27ddf3d783d
|
||||
F src/delete.c 2e1dda38345416a1ea1c0a6468589a7472334dac
|
||||
F src/encode.c a876af473d1d636faa3dca51c7571f2e007eea37
|
||||
F src/expr.c 5b283e68bd6df365b7c2ad10bd04cc54c2b4b07c
|
||||
F src/func.c 3b511af0823ea32714e1702005b61a6efa2c0d87
|
||||
F src/func.c 7eb4356a9e3155d6783d84fc5d6b324031877572
|
||||
F src/hash.c 440c2f8cb373ee1b4e13a0988489c7cd95d55b6f
|
||||
F src/hash.h 762d95f1e567664d1eafc1687de755626be962fb
|
||||
F src/insert.c e510d62d23b4de4d901e7ccbbe7833b7fb3b9570
|
||||
@ -71,8 +71,8 @@ F src/util.c 4c0adcbc9ce6678dd046931253e45d623c6d279f
|
||||
F src/vacuum.c 8734f89742f246abd91dbd3e087fc153bddbfbad
|
||||
F src/vdbe.c 11bb4758ae692888ee2a2566be9e0119b489dff3
|
||||
F src/vdbe.h 391d5642a83af686f35c228fcd36cb4456d68f44
|
||||
F src/vdbeInt.h 7084fc1b67dbf77a8dff1d923aba2df0313df993
|
||||
F src/vdbeaux.c a01d066ff44654e392a405cd010c4391da8bd4d9
|
||||
F src/vdbeInt.h 4dfeaaf7ca34859553d62f391bfb6b6fe4be425e
|
||||
F src/vdbeaux.c 588e7df730b5d3f6cbe1f44203c91b7be0042ce5
|
||||
F src/where.c efe5d25fe18cd7381722457898cd863e84097a0c
|
||||
F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
|
||||
F test/attach.test cb9b884344e6cfa5e165965d5b1adea679a24c83
|
||||
@ -202,7 +202,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
|
||||
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
|
||||
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
|
||||
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
|
||||
P 162cf42e33691f4c9ec3a25abcaa2bdcdca2b5e0
|
||||
R 348a5f0d606240ddcf7fbfd3a2c640f5
|
||||
P 5c28ed5e9b5a3ecb3081ce0c5c9450d6ae8dc77d
|
||||
R 8308cdc960f78d11f007d3b61876bd79
|
||||
U danielk1977
|
||||
Z a101344ca61df76dd692642ca94ebcaa
|
||||
Z 39c12ff09c771deaa84ed1f3b56e6995
|
||||
|
@ -1 +1 @@
|
||||
5c28ed5e9b5a3ecb3081ce0c5c9450d6ae8dc77d
|
||||
b77c268ebebd5401c3f519a72cfb81438207368c
|
71
src/func.c
71
src/func.c
@ -16,13 +16,14 @@
|
||||
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
|
||||
** All other code has file scope.
|
||||
**
|
||||
** $Id: func.c,v 1.52 2004/05/24 23:48:26 danielk1977 Exp $
|
||||
** $Id: func.c,v 1.53 2004/05/25 01:13:21 danielk1977 Exp $
|
||||
*/
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "sqliteInt.h"
|
||||
#include "vdbeInt.h"
|
||||
#include "os.h"
|
||||
|
||||
/*
|
||||
@ -543,46 +544,44 @@ struct MinMaxCtx {
|
||||
** Routines to implement min() and max() aggregate functions.
|
||||
*/
|
||||
static void minmaxStep(sqlite_func *context, int argc, sqlite3_value **argv){
|
||||
MinMaxCtx *p;
|
||||
int (*xCompare)(const char*, const char*);
|
||||
int mask; /* 0 for min() or 0xffffffff for max() */
|
||||
const char *zArg0 = sqlite3_value_data(argv[0]);
|
||||
const char *zArg1 = sqlite3_value_data(argv[1]);
|
||||
int max = 0;
|
||||
int cmp = 0;
|
||||
Mem *pArg = (Mem *)argv[0];
|
||||
Mem *pBest = (Mem *)sqlite3_aggregate_context(context, sizeof(*pBest));
|
||||
|
||||
assert( argc==2 );
|
||||
if( zArg1[0]=='n' ){
|
||||
xCompare = sqlite3Compare;
|
||||
if( SQLITE3_NULL==sqlite3_value_type(argv[0]) ) return;
|
||||
|
||||
if( pBest->flags ){
|
||||
max = ((sqlite3_user_data(context)==(void *)-1)?1:0);
|
||||
cmp = sqlite3MemCompare(pBest, pArg, 0);
|
||||
if( (max && cmp<0) || (!max && cmp>0) ){
|
||||
sqlite3MemCopy(pBest, pArg);
|
||||
}
|
||||
}else{
|
||||
xCompare = strcmp;
|
||||
}
|
||||
mask = (int)sqlite3_user_data(context);
|
||||
p = sqlite3_aggregate_context(context, sizeof(*p));
|
||||
if( p==0 || argc<1 || zArg0==0 ) return;
|
||||
if( p->z==0 || (xCompare(zArg0,p->z)^mask)<0 ){
|
||||
int len;
|
||||
if( !p->zBuf[0] ){
|
||||
sqliteFree(p->z);
|
||||
}
|
||||
len = strlen(zArg0);
|
||||
if( len < sizeof(p->zBuf)-1 ){
|
||||
p->z = &p->zBuf[1];
|
||||
p->zBuf[0] = 1;
|
||||
}else{
|
||||
p->z = sqliteMalloc( len+1 );
|
||||
p->zBuf[0] = 0;
|
||||
if( p->z==0 ) return;
|
||||
}
|
||||
strcpy(p->z, zArg0);
|
||||
sqlite3MemCopy(pBest, pArg);
|
||||
}
|
||||
}
|
||||
static void minMaxFinalize(sqlite_func *context){
|
||||
MinMaxCtx *p;
|
||||
p = sqlite3_aggregate_context(context, sizeof(*p));
|
||||
if( p && p->z ){
|
||||
sqlite3_set_result_string(context, p->z, strlen(p->z));
|
||||
}
|
||||
if( p && !p->zBuf[0] ){
|
||||
sqliteFree(p->z);
|
||||
sqlite3_value *pRes;
|
||||
pRes = (sqlite3_value *)sqlite3_aggregate_context(context, sizeof(Mem));
|
||||
|
||||
if( pRes->flags ){
|
||||
switch( sqlite3_value_type(pRes) ){
|
||||
case SQLITE3_INTEGER:
|
||||
sqlite3_set_result_int(context, sqlite3_value_int(pRes));
|
||||
break;
|
||||
case SQLITE3_FLOAT:
|
||||
sqlite3_set_result_double(context, sqlite3_value_float(pRes));
|
||||
case SQLITE3_TEXT:
|
||||
case SQLITE3_BLOB:
|
||||
sqlite3_set_result_string(context,
|
||||
sqlite3_value_data(pRes),
|
||||
sqlite3_value_bytes(pRes));
|
||||
break;
|
||||
case SQLITE3_NULL:
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -361,6 +361,7 @@ int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
|
||||
int sqlite3VdbeIdxKeyCompare(Cursor*, int , const unsigned char*, int*);
|
||||
int sqlite3VdbeIdxRowid(BtCursor *, i64 *);
|
||||
int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
|
||||
int sqlite3MemCopy(Mem*, const Mem*);
|
||||
int sqlite3VdbeKeyCompare(void*,int,const void*,int, const void*);
|
||||
int sqlite3VdbeRowCompare(void*,int,const void*,int, const void*);
|
||||
int sqlite3VdbeExec(Vdbe*);
|
||||
|
@ -1461,6 +1461,33 @@ int sqlite3MemCompare(const Mem *pMem1, const Mem *pMem2, const CollSeq *pColl){
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Copy the contents of memory cell pFrom into pTo.
|
||||
*/
|
||||
int sqlite3MemCopy(Mem *pTo, const Mem *pFrom){
|
||||
if( pTo->flags&MEM_Dyn ){
|
||||
sqliteFree(pTo->z);
|
||||
}
|
||||
|
||||
memcpy(pTo, pFrom, sizeof(*pFrom));
|
||||
if( pTo->flags&MEM_Short ){
|
||||
pTo->z = pTo->zShort;
|
||||
}
|
||||
else if( pTo->flags&(MEM_Ephem|MEM_Dyn) ){
|
||||
pTo->flags = pTo->flags&(~(MEM_Static|MEM_Ephem|MEM_Short|MEM_Dyn));
|
||||
if( pTo->n>NBFS ){
|
||||
pTo->z = sqliteMalloc(pTo->n);
|
||||
if( !pTo->z ) return SQLITE_NOMEM;
|
||||
pTo->flags |= MEM_Dyn;
|
||||
}else{
|
||||
pTo->z = pTo->zShort;
|
||||
pTo->flags |= MEM_Short;
|
||||
}
|
||||
memcpy(pTo->z, pFrom->z, pTo->n);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** The following is the comparison function for (non-integer)
|
||||
** keys in the btrees. This function returns negative, zero, or
|
||||
|
Loading…
x
Reference in New Issue
Block a user