]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add a prototype "group_concat()" aggregate function to func.c.
authordrh <drh@noemail.net>
Thu, 1 Nov 2007 17:38:30 +0000 (17:38 +0000)
committerdrh <drh@noemail.net>
Thu, 1 Nov 2007 17:38:30 +0000 (17:38 +0000)
Disabled by default.  No documentation nor test cases.  No effort
to make it efficient. (CVS 4519)

FossilOrigin-Name: 61987a89d1c4af59c745d1c5f17bab3301588b6c

manifest
manifest.uuid
src/func.c

index 164a68fc403b0f6087eda34719f5a24edba51352..13f590a3dbcaf3c6d20f19be76fde81c261891ce 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Avoid\sleaking\sa\sfile\sdescriptor\safter\sa\smalloc\sfailure\son\sunix.\s(CVS\s4518)
-D 2007-10-30T17:28:52
+C Add\sa\sprototype\s"group_concat()"\saggregate\sfunction\sto\sfunc.c.\nDisabled\sby\sdefault.\s\sNo\sdocumentation\snor\stest\scases.\s\sNo\seffort\nto\smake\sit\sefficient.\s(CVS\s4519)
+D 2007-11-01T17:38:31
 F Makefile.in 30c7e3ba426ddb253b8ef037d1873425da6009a8
 F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -91,7 +91,7 @@ F src/date.c 49c5a6d2de6c12000905b4d36868b07d3011bbf6
 F src/delete.c 849846d06d29851dde0d9f424a5de5817eb140d1
 F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
 F src/expr.c 23fac3749024deeaaa6c25b6b5c521e8d140a2c5
-F src/func.c e8e8978804ba453e9e1377db8824c90871b53cfb
+F src/func.c 73b4974e5ff03cc71345cc3a33b0022f7b99974a
 F src/hash.c 45a7005aac044b6c86bd7e49c44bc15d30006d6c
 F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53
 F src/insert.c df9712e1f67201573a9677d3a2fe401d52d84dda
@@ -584,7 +584,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P 4ad60bdba0f1aa068dcc42fb58b80d7912e36b1b
-R eab92563ee745f8784bf52cc2537c42c
-U danielk1977
-Z b867cfa02d41c621c1fcb64d6a074295
+P c249d5da721b32f6fe409a5b55a5d49a58994fec
+R dd9daad3a663125d3750f5ba94a500df
+U drh
+Z 6d1463c2813fdf26e95139312eb630a5
index f86f9ce6cc947e6b5387428e538ea09882332cc0..36188967e0461358966209a321e53774f50531c7 100644 (file)
@@ -1 +1 @@
-c249d5da721b32f6fe409a5b55a5d49a58994fec
\ No newline at end of file
+61987a89d1c4af59c745d1c5f17bab3301588b6c
\ No newline at end of file
index 17d19282250b8d7a750865cfdfaaeb19491aead1..fcad3aadf0c7806cfac7ffab27e1165528fb080d 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.175 2007/10/12 19:11:55 drh Exp $
+** $Id: func.c,v 1.176 2007/11/01 17:38:31 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -1312,6 +1312,42 @@ static void minMaxFinalize(sqlite3_context *context){
   }
 }
 
+#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
@@ -1391,6 +1427,10 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
     { "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;