From: drh Date: Wed, 15 Apr 2009 15:16:53 +0000 (+0000) Subject: Fix the group_concat() function so that it inserts the separator string X-Git-Tag: version-3.6.15~240 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8dc09a061625839b0b1a907c243ce71728664668;p=thirdparty%2Fsqlite.git Fix the group_concat() function so that it inserts the separator string even if the initial content strings are empty. Ticket #3806. (CVS 6510) FossilOrigin-Name: b83fbf15a3920755ed77dc9c91b4f00a86ddb9ac --- diff --git a/manifest b/manifest index a5b9726180..0f2206c296 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\saccess\sviolation\son\sWinCE\splatforms.\s\sTicket\s#3804.\s(CVS\s6509) -D 2009-04-15T14:36:26 +C Fix\sthe\sgroup_concat()\sfunction\sso\sthat\sit\sinserts\sthe\sseparator\sstring\neven\sif\sthe\sinitial\scontent\sstrings\sare\sempty.\s\sTicket\s#3806.\s(CVS\s6510) +D 2009-04-15T15:16:53 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 583e87706abc3026960ed759aff6371faf84c211 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -113,7 +113,7 @@ F src/date.c 3e5c554b2f4f2d798761597c08147d7b15f35bea F src/delete.c eb1066b2f35489fee46ad765d2b66386fc7d8adf F src/expr.c ccc5b5fa3bac249a9ab6e5e10629d77ff293c9f8 F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff -F src/func.c 4ebe8c365401f6b4a28bc597a420a9a42e50af61 +F src/func.c ac12ea20d1087b99b8806d380914fd0cbb985c06 F src/global.c 448419c44ce0701104c2121b0e06919b44514c0c F src/hash.c 5824e6ff7ba78cd34c8d6cd724367713583e5b55 F src/hash.h 28f38ebb1006a5beedcb013bcdfe31befe7437ae @@ -379,7 +379,7 @@ F test/fts3e.test 1f6c6ac9cc8b772ca256e6b22aaeed50c9350851 F test/fts3expr.test 9764961c3f4ac818dacda01ed35d8bfcef42338b F test/fts3expr2.test 8501de895a4c0631e7226c9bac055cd49c9f6646 F test/fts3near.test dc196dd17b4606f440c580d45b3d23aa975fd077 -F test/func.test 70ea3d5b10d40cbc87a19b0819d2842dbcdb31f2 +F test/func.test d4a8590511cdc68a136afd00bd989c2584454932 F test/fuzz.test 8bad3b9b09bad47c50f3433f9598707a70247ce1 F test/fuzz2.test ea38692ce2da99ad79fe0be5eb1a452c1c4d37bb F test/fuzz3.test aec64345184d1662bd30e6a17851ff659d596dc5 @@ -717,7 +717,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P c0bba77ae619e709f3fb068526073a4a83cf33b6 -R 60499e56429b76b866740226d762ff74 -U shane -Z be286a2bb7817f683580514326b970f8 +P e203ad400dd61431b3e6b8219eb5357b6ca06561 +R 08374e872e7a2a83a20b5c0b0a651c1a +U drh +Z a006ab98ab05ae9fc2b427cfcf96e911 diff --git a/manifest.uuid b/manifest.uuid index c4ec0023c8..c1e5b4922b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e203ad400dd61431b3e6b8219eb5357b6ca06561 \ No newline at end of file +b83fbf15a3920755ed77dc9c91b4f00a86ddb9ac \ No newline at end of file diff --git a/src/func.c b/src/func.c index b90aa55da6..6d7baba416 100644 --- a/src/func.c +++ b/src/func.c @@ -16,7 +16,7 @@ ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: func.c,v 1.232 2009/04/15 13:39:48 drh Exp $ +** $Id: func.c,v 1.233 2009/04/15 15:16:53 drh Exp $ */ #include "sqliteInt.h" #include @@ -1262,7 +1262,7 @@ static void groupConcatStep( sqlite3 *db = sqlite3_context_db_handle(context); pAccum->useMalloc = 1; pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH]; - if( pAccum->nChar ){ + if( sqlite3_aggregate_count(context)>1 ){ if( argc==2 ){ zSep = (char*)sqlite3_value_text(argv[1]); nSep = sqlite3_value_bytes(argv[1]); diff --git a/test/func.test b/test/func.test index ae0f017487..6664d27b16 100644 --- a/test/func.test +++ b/test/func.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing built-in functions. # -# $Id: func.test,v 1.91 2009/02/04 03:59:25 shane Exp $ +# $Id: func.test,v 1.92 2009/04/15 15:16:53 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -1056,6 +1056,20 @@ for {set i 1} {$i<[sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG -1]} {incr i} { } $result } +# Ticket #3806. If the initial string in a group_concat is an empty +# string, the separate that follows should still be present. +# +do_test func-24.8 { + execsql { + SELECT group_concat(CASE t1 WHEN 'this' THEN '' ELSE t1 END) FROM tbl1 + } +} {,program,is,free,software} +do_test func-24.9 { + execsql { + SELECT group_concat(CASE WHEN t1!='software' THEN '' ELSE t1 END) FROM tbl1 + } +} {,,,,software} + # Use the test_isolation function to make sure that type conversions # on function arguments do not effect subsequent arguments. #