From: drh Date: Fri, 19 Jun 2009 16:44:41 +0000 (+0000) Subject: Make sure group_concat() ignores initial NULL values. (CVS 6787) X-Git-Tag: cvs-to-fossil-cutover~185 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8bfd719065bfa66e5447cc290ab0d4a6cb936460;p=thirdparty%2Fsqlite.git Make sure group_concat() ignores initial NULL values. (CVS 6787) FossilOrigin-Name: 90c3b23ccac8a9e7fc1cc831e43888e4e43badc9 --- diff --git a/manifest b/manifest index 4a4ddf8001..128769f287 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Reorganize\sand\scleanup\sthe\sprepared\sstatement\sobject.\s\sRemove\scode\sthat\shas\nbeen\scommented\sout\sfor\sages\sand\sis\sno\slonger\srelevant\sto\sanything.\s(CVS\s6786) -D 2009-06-19T14:06:03 +C Make\ssure\sgroup_concat()\signores\sinitial\sNULL\svalues.\s(CVS\s6787) +D 2009-06-19T16:44:41 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 8b8fb7823264331210cddf103831816c286ba446 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -116,7 +116,7 @@ F src/date.c ab5f7137656652a48434d64f96bdcdc823bb23b3 F src/delete.c cb791855c7948cecc96def9d97989879ca26f257 F src/expr.c 1d580a7b2e51092785cbbc1fb8d2ff84e93c76dc F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff -F src/func.c d108b0028050ecd0fd9508268995892937d577ae +F src/func.c 9856373f5315f6b8690d7f07f7191aa9f279ca87 F src/global.c 448419c44ce0701104c2121b0e06919b44514c0c F src/hash.c ebcaa921ffd9d86f7ea5ae16a0a29d1c871130a7 F src/hash.h 35b216c13343d0b4f87d9f21969ac55ad72174e1 @@ -384,7 +384,7 @@ F test/fts3e.test 1f6c6ac9cc8b772ca256e6b22aaeed50c9350851 F test/fts3expr.test 9764961c3f4ac818dacda01ed35d8bfcef42338b F test/fts3expr2.test 18da930352e5693eaa163a3eacf96233b7290d1a F test/fts3near.test dc196dd17b4606f440c580d45b3d23aa975fd077 -F test/func.test d4a8590511cdc68a136afd00bd989c2584454932 +F test/func.test 004caa157b91986bed8c85d7c7d0a86d6e10528d F test/fuzz.test a4174c3009a3e2c2e14b31b364ebf7ddb49de2c9 F test/fuzz2.test ea38692ce2da99ad79fe0be5eb1a452c1c4d37bb F test/fuzz3.test aec64345184d1662bd30e6a17851ff659d596dc5 @@ -736,7 +736,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746 -P 7d8f178c8145b90da31f6557f7cd99d154eb676e -R b3e036533bac5a29d77c23602f39da64 +P 37ae5f5e8feb34a8e6e8b34aa18df1e9a1ce55cb +R bbe11c7b362a2c517acbc2d78fa4631d U drh -Z f2670ca2615f8f31d0717b2c5d58ef64 +Z 1470050dd5090450f94c26db6cf0c170 diff --git a/manifest.uuid b/manifest.uuid index 00f2f3753c..570d9e4e2f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -37ae5f5e8feb34a8e6e8b34aa18df1e9a1ce55cb \ No newline at end of file +90c3b23ccac8a9e7fc1cc831e43888e4e43badc9 \ No newline at end of file diff --git a/src/func.c b/src/func.c index c48896d4e0..6243536cba 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.238 2009/06/19 14:06:03 drh Exp $ +** $Id: func.c,v 1.239 2009/06/19 16:44:41 drh Exp $ */ #include "sqliteInt.h" #include @@ -1265,15 +1265,10 @@ static void groupConcatStep( if( pAccum ){ sqlite3 *db = sqlite3_context_db_handle(context); - int n; + int firstTerm = pAccum->useMalloc==0; pAccum->useMalloc = 1; pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH]; -#ifdef SQLITE_OMIT_DEPRECATED - n = context->pMem->n; -#else - n = sqlite3_aggregate_count(context); -#endif - if( n>1 ){ + if( !firstTerm ){ 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 6664d27b16..d87c013182 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.92 2009/04/15 15:16:53 drh Exp $ +# $Id: func.test,v 1.93 2009/06/19 16:44:41 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -1057,7 +1057,7 @@ for {set i 1} {$i<[sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG -1]} {incr i} { } # Ticket #3806. If the initial string in a group_concat is an empty -# string, the separate that follows should still be present. +# string, the separator that follows should still be present. # do_test func-24.8 { execsql { @@ -1070,6 +1070,27 @@ do_test func-24.9 { } } {,,,,software} +# Ticket #3923. Initial empty strings have a separator. But initial +# NULLs do not. +# +do_test func-24.10 { + execsql { + SELECT group_concat(CASE t1 WHEN 'this' THEN null ELSE t1 END) FROM tbl1 + } +} {program,is,free,software} +do_test func-24.11 { + execsql { + SELECT group_concat(CASE WHEN t1!='software' THEN null ELSE t1 END) FROM tbl1 + } +} {software} +do_test func-24.12 { + execsql { + SELECT group_concat(CASE t1 WHEN 'this' THEN '' + WHEN 'program' THEN null ELSE t1 END) FROM tbl1 + } +} {,is,free,software} + + # Use the test_isolation function to make sure that type conversions # on function arguments do not effect subsequent arguments. #