SQLite

Check-in [61987a89d1]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add a prototype "group_concat()" aggregate function to func.c. Disabled by default. No documentation nor test cases. No effort to make it efficient. (CVS 4519)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 61987a89d1c4af59c745d1c5f17bab3301588b6c
User & Date: drh 2007-11-01 17:38:31.000
Context
2007-11-02
09:07
Add some assert() statements to the asychronous backend demo to enforce the strategy used to avoid deadlock. Also a minor change to avoid a potential deadlock. (CVS 4520) (check-in: 6340ca5eee user: danielk1977 tags: trunk)
2007-11-01
17:38
Add a prototype "group_concat()" aggregate function to func.c. Disabled by default. No documentation nor test cases. No effort to make it efficient. (CVS 4519) (check-in: 61987a89d1 user: drh tags: trunk)
2007-10-30
17:28
Avoid leaking a file descriptor after a malloc failure on unix. (CVS 4518) (check-in: c249d5da72 user: danielk1977 tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/func.c.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
** This file contains the C functions that implement various SQL
** functions of SQLite.  
**
** 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.175 2007/10/12 19:11:55 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
#include <stdlib.h>
#include <assert.h>
#include "vdbeInt.h"








|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
** This file contains the C functions that implement various SQL
** functions of SQLite.  
**
** 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.176 2007/11/01 17:38:31 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
#include <stdlib.h>
#include <assert.h>
#include "vdbeInt.h"

1308
1309
1310
1311
1312
1313
1314




































1315
1316
1317
1318
1319
1320
1321
    if( pRes->flags ){
      sqlite3_result_value(context, pRes);
    }
    sqlite3VdbeMemRelease(pRes);
  }
}






































/*
** This function registered all of the above C functions as SQL
** functions.  This should be the only routine in this file with
** external linkage.
*/
void sqlite3RegisterBuiltinFunctions(sqlite3 *db){







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
    if( pRes->flags ){
      sqlite3_result_value(context, pRes);
    }
    sqlite3VdbeMemRelease(pRes);
  }
}

#ifdef SQLITE_GROUP_CONCAT
/*
** group_concat(EXPR, ?SEPARATOR?)
*/
static void groupConcatStep(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  const char *zVal;
  char **pzAccumulator;
  const char *zSep;
  if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
  zVal = sqlite3_value_text(argv[0]);
  pzAccumulator = (char**)sqlite3_aggregate_context(context, sizeof(char*));
  if( pzAccumulator ){
    if( *pzAccumulator==0 ){
      *pzAccumulator = sqlite3_mprintf("%s", zVal);
    }else{
      if( argc==2 ){
        zSep = sqlite3_value_text(argv[1]);
      }else{
        zSep = ",";
      }
      *pzAccumulator = sqlite3_mprintf("%z%s%s", *pzAccumulator, zSep, zVal);
    }
  }
}
static void groupConcatFinalize(sqlite3_context *context){
  char **pzAccum;
  pzAccum = sqlite3_aggregate_context(context, 0);
  if( pzAccum ){
    sqlite3_result_text(context, *pzAccum, -1, sqlite3_free);
  }
}
#endif /*SQLITE_GROUP_CONCAT*/

/*
** This function registered all of the above C functions as SQL
** functions.  This should be the only routine in this file with
** external linkage.
*/
void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
1387
1388
1389
1390
1391
1392
1393




1394
1395
1396
1397
1398
1399
1400
    { "min",    1, 0, 1, minmaxStep,   minMaxFinalize },
    { "max",    1, 1, 1, minmaxStep,   minMaxFinalize },
    { "sum",    1, 0, 0, sumStep,      sumFinalize    },
    { "total",  1, 0, 0, sumStep,      totalFinalize    },
    { "avg",    1, 0, 0, sumStep,      avgFinalize    },
    { "count",  0, 0, 0, countStep,    countFinalize  },
    { "count",  1, 0, 0, countStep,    countFinalize  },




  };
  int i;

  for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
    void *pArg;
    u8 argType = aFuncs[i].argType;
    if( argType==0xff ){







>
>
>
>







1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
    { "min",    1, 0, 1, minmaxStep,   minMaxFinalize },
    { "max",    1, 1, 1, minmaxStep,   minMaxFinalize },
    { "sum",    1, 0, 0, sumStep,      sumFinalize    },
    { "total",  1, 0, 0, sumStep,      totalFinalize    },
    { "avg",    1, 0, 0, sumStep,      avgFinalize    },
    { "count",  0, 0, 0, countStep,    countFinalize  },
    { "count",  1, 0, 0, countStep,    countFinalize  },
#ifdef SQLITE_GROUP_CONCAT
    { "group_concat", 1, 0, 0, groupConcatStep, groupConcatFinalize },
    { "group_concat", 2, 0, 0, groupConcatStep, groupConcatFinalize },
#endif
  };
  int i;

  for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
    void *pArg;
    u8 argType = aFuncs[i].argType;
    if( argType==0xff ){