]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Aggregate functions also use sqlite_value* instead of const char * for
authordanielk1977 <danielk1977@noemail.net>
Mon, 24 May 2004 23:48:25 +0000 (23:48 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Mon, 24 May 2004 23:48:25 +0000 (23:48 +0000)
arguments. (CVS 1451)

FossilOrigin-Name: 5c28ed5e9b5a3ecb3081ce0c5c9450d6ae8dc77d

manifest
manifest.uuid
src/func.c
src/main.c
src/md5.c
src/sqlite.h.in
src/sqliteInt.h
src/test1.c
src/vdbe.c
src/vdbeInt.h
src/vdbeaux.c

index a9715549a3c7ef7beee069fa0549eeb023aad5ab..6cdcd6a87a7e29973417d80725f3192f710548c1 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Update\sthe\stypeof()\soperator\sto\srespect\smanifest\stypes.\s(CVS\s1450)
-D 2004-05-24T12:55:55
+C Aggregate\sfunctions\salso\suse\ssqlite_value*\sinstead\sof\sconst\schar\s*\sfor\narguments.\s(CVS\s1451)
+D 2004-05-24T23:48:26
 F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a
 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -32,12 +32,12 @@ F src/date.c 64fd7169c7d599ec8eaa99121d59e27ddf3d783d
 F src/delete.c 2e1dda38345416a1ea1c0a6468589a7472334dac
 F src/encode.c a876af473d1d636faa3dca51c7571f2e007eea37
 F src/expr.c 5b283e68bd6df365b7c2ad10bd04cc54c2b4b07c
-F src/func.c c33bad759fa3088612b07caa268d4beb4cc92a38
+F src/func.c 3b511af0823ea32714e1702005b61a6efa2c0d87
 F src/hash.c 440c2f8cb373ee1b4e13a0988489c7cd95d55b6f
 F src/hash.h 762d95f1e567664d1eafc1687de755626be962fb
 F src/insert.c e510d62d23b4de4d901e7ccbbe7833b7fb3b9570
-F src/main.c fface1a6e17ef7b3dd4b55089ababc7a91faa4c8
-F src/md5.c 8e39fdae6d8776b87558e91dcc94740c9b635a9c
+F src/main.c 8279e1160810410bb9ad6608f87b0140db5b1ce0
+F src/md5.c 84c69162ad4c9b8399b522a259c09e256edaf88a
 F src/os.h ab42f4a7c4c716f26b988e759b6e12085a3bfc67
 F src/os_common.h 744286a27de55c52f1b18921e8d17abbf7fafc0f
 F src/os_mac.c b823874690615ace0dd520d3ad1fe8bfd864b7e0
@@ -54,11 +54,11 @@ F src/printf.c ef750e8e2398ca7e8b58be991075f08c6a7f0e53
 F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
 F src/select.c 7d77a8bed7eeac23216d42fc1be006fb4352fcdc
 F src/shell.c ed4d237b3e52a0a42512bfcc53530e46de20c28f
-F src/sqlite.h.in 258c3a11c9c47cf7302cd4e94c1cac296275bb9b
-F src/sqliteInt.h 6498bd799288f0501527f7593356edee02e1b0a1
+F src/sqlite.h.in 3dfba192557c211779fdd48fd25b437b339eabcd
+F src/sqliteInt.h 3ba18f1bbe85c69db1b4882ba899681b0bbac2ae
 F src/table.c af14284fa36c8d41f6829e3f2819dce07d3e2de2
 F src/tclsqlite.c c8b511645f98051f41b5e0d6c3a99feeed9aeeec
-F src/test1.c 27a5994f6ce76d62162dac6d1d926deee70c73dd
+F src/test1.c 045cdd926a8157cd24c6112c2743236063f1bf3e
 F src/test2.c 6195a1ca2c8d0d2d93644e86da3289b403486872
 F src/test3.c 5e4a6d596f982f6f47a5f9f75ede9b4a3b739968
 F src/test4.c b9947c319a5c023c10c1e953e6610abd571c2283
@@ -69,10 +69,10 @@ F src/update.c 1a5e9182596f3ea8c7a141e308a3d2a7e5689fee
 F src/utf.c 1d38da85bffb928fb0d9f301e7db913a6df486ce
 F src/util.c 4c0adcbc9ce6678dd046931253e45d623c6d279f
 F src/vacuum.c 8734f89742f246abd91dbd3e087fc153bddbfbad
-F src/vdbe.c 92994b28770f07c96c5e4777ce22fb78a853bda8
+F src/vdbe.c 11bb4758ae692888ee2a2566be9e0119b489dff3
 F src/vdbe.h 391d5642a83af686f35c228fcd36cb4456d68f44
-F src/vdbeInt.h 6c2444a60fc030b275dc0cff407cdaa79d84ce86
-F src/vdbeaux.c 7f0c4ad22d5e61465d509467e2535293b468373a
+F src/vdbeInt.h 7084fc1b67dbf77a8dff1d923aba2df0313df993
+F src/vdbeaux.c a01d066ff44654e392a405cd010c4391da8bd4d9
 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 1e47d7384d5fdfceb6ec737c656f70be59ba5b01
-R e2f680e7baa92e0e16b93c2c89142f17
+P 162cf42e33691f4c9ec3a25abcaa2bdcdca2b5e0
+R 348a5f0d606240ddcf7fbfd3a2c640f5
 U danielk1977
-Z e9ca420be0cdabd35afa6fc3433fc6b4
+Z a101344ca61df76dd692642ca94ebcaa
index 864e491c336c929922827ae8fcf9b7d430e6b23e..69c2ff7b322b6909707522b992a747a46b4ebbc5 100644 (file)
@@ -1 +1 @@
-162cf42e33691f4c9ec3a25abcaa2bdcdca2b5e0
\ No newline at end of file
+5c28ed5e9b5a3ecb3081ce0c5c9450d6ae8dc77d
\ No newline at end of file
index a5ded41f51bd00604c58c56c8a8ebffb71ecdbba..eec3604297254a0329ed172693ab73d8e6b4e5af 100644 (file)
@@ -16,7 +16,7 @@
 ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
 ** All other code has file scope.
 **
-** $Id: func.c,v 1.51 2004/05/24 12:55:55 danielk1977 Exp $
+** $Id: func.c,v 1.52 2004/05/24 23:48:26 danielk1977 Exp $
 */
 #include <ctype.h>
 #include <math.h>
@@ -444,12 +444,12 @@ struct SumCtx {
 /*
 ** Routines used to compute the sum or average.
 */
-static void sumStep(sqlite_func *context, int argc, const char **argv){
+static void sumStep(sqlite_func *context, int argc, sqlite3_value **argv){
   SumCtx *p;
   if( argc<1 ) return;
   p = sqlite3_aggregate_context(context, sizeof(*p));
-  if( p && argv[0] ){
-    p->sum += sqlite3AtoF(argv[0], 0);
+  if( p && SQLITE3_NULL!=sqlite3_value_type(argv[0]) ){
+    p->sum += sqlite3_value_float(argv[0]);
     p->cnt++;
   }
 }
@@ -516,10 +516,10 @@ struct CountCtx {
 /*
 ** Routines to implement the count() aggregate function.
 */
-static void countStep(sqlite_func *context, int argc, const char **argv){
+static void countStep(sqlite_func *context, int argc, sqlite3_value **argv){
   CountCtx *p;
   p = sqlite3_aggregate_context(context, sizeof(*p));
-  if( (argc==0 || argv[0]) && p ){
+  if( (argc==0 || SQLITE3_NULL!=sqlite3_value_type(argv[0])) && p ){
     p->n++;
   }
 }   
@@ -542,26 +542,28 @@ struct MinMaxCtx {
 /*
 ** Routines to implement min() and max() aggregate functions.
 */
-static void minmaxStep(sqlite_func *context, int argc, const char **argv){
+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]);
 
   assert( argc==2 );
-  if( argv[1][0]=='n' ){
+  if( zArg1[0]=='n' ){
     xCompare = sqlite3Compare;
   }else{
     xCompare = strcmp;
   }
   mask = (int)sqlite3_user_data(context);
   p = sqlite3_aggregate_context(context, sizeof(*p));
-  if( p==0 || argc<1 || argv[0]==0 ) return;
-  if( p->z==0 || (xCompare(argv[0],p->z)^mask)<0 ){
+  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(argv[0]);
+    len = strlen(zArg0);
     if( len < sizeof(p->zBuf)-1 ){
       p->z = &p->zBuf[1];
       p->zBuf[0] = 1;
@@ -570,7 +572,7 @@ static void minmaxStep(sqlite_func *context, int argc, const char **argv){
       p->zBuf[0] = 0;
       if( p->z==0 ) return;
     }
-    strcpy(p->z, argv[0]);
+    strcpy(p->z, zArg0);
   }
 }
 static void minMaxFinalize(sqlite_func *context){
@@ -636,7 +638,7 @@ void sqlite3RegisterBuiltinFunctions(sqlite *db){
     signed char nArg;
     signed char dataType;
     u8 argType;
-    void (*xStep)(sqlite_func*,int,const char**);
+    void (*xStep)(sqlite_func*,int,sqlite3_value**);
     void (*xFinalize)(sqlite_func*);
   } aAggs[] = {
     { "min",    1, 0,              0, minmaxStep,   minMaxFinalize },
index 6ca02495160954f19d0251c41d80963235250059..7d15fdb7aa0140129a3a5dfbe201f4bc21e44ff7 100644 (file)
@@ -14,7 +14,7 @@
 ** other files are for internal use by SQLite and should not be
 ** accessed by users of the library.
 **
-** $Id: main.c,v 1.186 2004/05/24 12:39:02 danielk1977 Exp $
+** $Id: main.c,v 1.187 2004/05/24 23:48:26 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -882,7 +882,7 @@ int sqlite3_create_aggregate(
   sqlite *db,          /* Add the function to this database connection */
   const char *zName,   /* Name of the function to add */
   int nArg,            /* Number of arguments */
-  void (*xStep)(sqlite_func*,int,const char**), /* The step function */
+  void (*xStep)(sqlite_func*,int,sqlite3_value**), /* The step function */
   void (*xFinalize)(sqlite_func*),              /* The finalizer */
   void *pUserData      /* User data */
 ){
index f716dd8dde2ca69d754abd483f6467d3b79d45ec..0d0f3f479459136ecd4cac9b4a8ab9be8efd1307 100644 (file)
--- a/src/md5.c
+++ b/src/md5.c
@@ -356,7 +356,7 @@ int Md5_Init(Tcl_Interp *interp){
 ** During testing, the special md5sum() aggregate function is available.
 ** inside SQLite.  The following routines implement that function.
 */
-static void md5step(sqlite_func *context, int argc, const char **argv){
+static void md5step(sqlite_func *context, int argc, sqlite3_value **argv){
   MD5Context *p;
   int i;
   if( argc<1 ) return;
@@ -366,8 +366,9 @@ static void md5step(sqlite_func *context, int argc, const char **argv){
     MD5Init(p);
   }
   for(i=0; i<argc; i++){
-    if( argv[i] ){
-      MD5Update(p, (unsigned char*)argv[i], strlen(argv[i]));
+    const char *zData = sqlite3_value_data(argv[i]);
+    if( zData ){
+      MD5Update(p, zData, strlen(zData));
     }
   }
 }
index a2d4d0ff551ee48c9396c3615905c62b10d9c24b..ab696c6804dd7d775e96ed6bce13012cdeb80f85 100644 (file)
@@ -12,7 +12,7 @@
 ** This header file defines the interface that the SQLite library
 ** presents to client programs.
 **
-** @(#) $Id: sqlite.h.in,v 1.73 2004/05/24 12:39:02 danielk1977 Exp $
+** @(#) $Id: sqlite.h.in,v 1.74 2004/05/24 23:48:27 danielk1977 Exp $
 */
 #ifndef _SQLITE_H_
 #define _SQLITE_H_
@@ -439,7 +439,7 @@ int sqlite3_create_aggregate(
   sqlite*,                  /* Database where the new function is registered */
   const char *zName,        /* Name of the function */
   int nArg,                 /* Number of arguments */
-  void (*xStep)(sqlite_func*,int,const char**), /* Called for each row */
+  void (*xStep)(sqlite_func*,int,sqlite3_value**), /* Called for each row */
   void (*xFinalize)(sqlite_func*),       /* Called once to get final result */
   void *pUserData           /* Available via the sqlite3_user_data() call */
 );
index 7a518ca8e1e48fd74d81351faee2484add8b5919..49ecb10b669e02bd7aa4b1efde5f90c15d97a221 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.249 2004/05/24 12:55:55 danielk1977 Exp $
+** @(#) $Id: sqliteInt.h,v 1.250 2004/05/24 23:48:27 danielk1977 Exp $
 */
 #include "config.h"
 #include "sqlite.h"
@@ -465,7 +465,7 @@ struct sqlite {
 */
 struct FuncDef {
   void (*xFunc)(sqlite_func*,int,sqlite3_value**);  /* Regular function */
-  void (*xStep)(sqlite_func*,int,const char**);  /* Aggregate function step */
+  void (*xStep)(sqlite_func*,int,sqlite3_value**);  /* Aggregate function step */
   void (*xFinalize)(sqlite_func*);           /* Aggregate function finializer */
   signed char nArg;         /* Number of arguments.  -1 means unlimited */
   signed char dataType;     /* Arg that determines datatype.  -1=NUMERIC, */
index 13f18fbee916c240c828b46caee8f5889e978d3d..57016e320b1dfc5baccca9ec69af0b178eed37e8 100644 (file)
@@ -13,7 +13,7 @@
 ** is not included in the SQLite library.  It is used for automated
 ** testing of the SQLite library.
 **
-** $Id: test1.c,v 1.48 2004/05/24 12:39:02 danielk1977 Exp $
+** $Id: test1.c,v 1.49 2004/05/24 23:48:27 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "tcl.h"
@@ -431,10 +431,10 @@ typedef struct CountCtx CountCtx;
 struct CountCtx {
   int n;
 };
-static void countStep(sqlite_func *context, int argc, const char **argv){
+static void countStep(sqlite_func *context, int argc, sqlite3_value **argv){
   CountCtx *p;
   p = sqlite3_aggregate_context(context, sizeof(*p));
-  if( (argc==0 || argv[0]) && p ){
+  if( (argc==0 || SQLITE3_NULL!=sqlite3_value_type(argv[0]) ) && p ){
     p->n++;
   }
 }   
index 664ee60682b3343a5a858d83b0593fb10011a94f..14cb55035a8db9a769ddc139107a938dafc67108 100644 (file)
@@ -43,7 +43,7 @@
 ** in this file for details.  If in doubt, do not deviate from existing
 ** commenting and indentation practices when changing or adding code.
 **
-** $Id: vdbe.c,v 1.326 2004/05/24 12:39:02 danielk1977 Exp $
+** $Id: vdbe.c,v 1.327 2004/05/24 23:48:27 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -2006,26 +2006,6 @@ case OP_ColumnName: {
 ** 3rd parameter.
 */
 case OP_Callback: {
-#if 0
-  int i;
-  char **azArgv = p->zArgv;
-  Mem *pCol;
-
-  pCol = &pTos[1-pOp->p1];
-  assert( pCol>=p->aStack );
-  for(i=0; i<pOp->p1; i++, pCol++){
-    if( pCol->flags & MEM_Null ){
-      azArgv[i] = 0;
-    }else{
-      Stringify(pCol, db->enc);
-      azArgv[i] = pCol->z;
-    }
-  }
-
-  azArgv[i] = 0;
-  p->azResColumn = azArgv;
-#endif
-
   int i;
   assert( p->nResColumn==pOp->p1 );
 
@@ -2276,7 +2256,7 @@ case OP_Function: {
   int n = pOp->p1;
 
   n = pOp->p1;
-  apVal = sqliteMalloc(sizeof(sqlite3_value*)*n);
+  apVal = p->apArg;
   assert( apVal || n==0 );
 
   pArg = &pTos[1-n];
@@ -2313,7 +2293,6 @@ case OP_Function: {
     SetEncoding(pTos, encToFlags(db->enc)|MEM_Term);
   }
 
-  if( apVal ) sqliteFree(apVal);
   break;
 }
 
@@ -5619,22 +5598,20 @@ case OP_AggFunc: {
   int n = pOp->p2;
   int i;
   Mem *pMem, *pRec;
-  char **azArgv = p->zArgv;
   sqlite_func ctx;
+  sqlite3_value **apVal;
 
   assert( n>=0 );
   assert( pTos->flags==MEM_Int );
   pRec = &pTos[-n];
   assert( pRec>=p->aStack );
+
+  apVal = p->apArg;
+  assert( apVal || n==0 );
+
   for(i=0; i<n; i++, pRec++){
-    if( pRec->flags & MEM_Null ){
-      azArgv[i] = 0;
-    }else{
-      Stringify(pRec, db->enc);
+      apVal[i] = pRec;
       SetEncodingFlags(pRec, db->enc);
-      SetEncoding(pRec, MEM_Utf8|MEM_Term);
-      azArgv[i] = pRec->z;
-    }
   }
   i = pTos->i;
   assert( i>=0 && i<p->agg.nMem );
@@ -5645,7 +5622,7 @@ case OP_AggFunc: {
   ctx.cnt = ++pMem->i;
   ctx.isError = 0;
   ctx.isStep = 1;
-  (ctx.pFunc->xStep)(&ctx, n, (const char**)azArgv);
+  (ctx.pFunc->xStep)(&ctx, n, apVal);
   pMem->z = ctx.pAgg;
   pMem->flags = MEM_AggCtx;
   popStack(&pTos, n+1);
index 23d0c6c5ab9f3d1e2300c42c4628dbb3025f7efd..6d22989204ba768f9663b6305d1b050a1952a9b6 100644 (file)
@@ -293,7 +293,7 @@ struct Vdbe {
   int *aLabel;        /* Space to hold the labels */
   Mem *aStack;        /* The operand stack, except string values */
   Mem *pTos;          /* Top entry in the operand stack */
-  char **zArgv;       /* Text values used by the callback */
+  Mem **apArg;        /* Arguments to currently executing user function */
   char **azColName;   /* Becomes the 4th parameter to callbacks */
   void **azColName16; /* UTF-16 encoded equivalent of azColName */
   int nCursor;        /* Number of slots in apCsr[] */
index 53ed63093d5f0919e3e980bf1f97828b5a2a59b9..be0d446f36896f806dc2d32284fc164fae098df8 100644 (file)
@@ -732,11 +732,11 @@ void sqlite3VdbeMakeReady(
     assert( nVar>=0 );
     n = isExplain ? 10 : p->nOp;
     p->aStack = sqliteMalloc(
-      n*(sizeof(p->aStack[0]) + 2*sizeof(char*))     /* aStack and zArgv */
+      n*(sizeof(p->aStack[0])+sizeof(Mem*)+sizeof(char*)) /* aStack, apArg */
       + p->nVar*sizeof(Mem)                          /* apVar */
     );
-    p->zArgv = (char**)&p->aStack[n];
-    p->azColName = (char**)&p->zArgv[n];
+    p->apArg = (Mem **)&p->aStack[n];
+    p->azColName = (char**)&p->apArg[n];
     p->apVar = (Mem *)&p->azColName[n];
     for(n=0; n<p->nVar; n++){
       p->apVar[n].flags = MEM_Null;