From: mistachkin Date: Wed, 5 Jun 2024 20:52:50 +0000 (+0000) Subject: Add an experimental concatb() function. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=da581727587122ac6c0f2b1028455089ccb8fee7;p=thirdparty%2Fsqlite.git Add an experimental concatb() function. FossilOrigin-Name: 07d8420285a49867b9c34f9e344eb666448dd9ce85c7791fa9480d98458684d9 --- diff --git a/manifest b/manifest index 9b693c0779..3a27ee6a20 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sharmless\scompilation\sissues\sseen\swith\sMSVC. -D 2024-06-05T20:50:39.523 +C Add\san\sexperimental\sconcatb()\sfunction. +D 2024-06-05T20:52:50.846 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -708,7 +708,7 @@ F src/delete.c cb766727c78e715f9fb7ec8a7d03658ed2a3016343ca687acfcec9083cdca500 F src/expr.c 585109ab97149b2d484697e7469f28c91d495cd1330cc760d24711b7be8d22fb F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 852f93c0ef995e0c2b8983059a2b97151c194cc8259e21f5bc2b7ac508348c2a -F src/func.c f1f57c6863c1380f31ecf3d61732495bfff847a8e35a832c7e306e310db5a799 +F src/func.c cc8c9cdae9e8ee05a6de9e3b4d7c11400cba8e5e54ba4917a8ec41d68fce8f96 F src/global.c 61a419dd9e993b9be0f91de4c4ccf322b053eb829868e089f0321dd669be3b90 F src/hash.c 9ee4269fb1d6632a6fecfb9479c93a1f29271bddbbaf215dd60420bcb80c7220 F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51 @@ -1237,7 +1237,7 @@ F test/fts4umlaut.test fcaca4471de7e78c9d1f7e8976e3e8704d7d8ad979d57a739d00f3f75 F test/fts4unicode.test 82a9c16b68ba2f358a856226bb2ee02f81583797bc4744061c54401bf1a0f4c9 F test/fts4upfrom.test f25835162c989dffd5e2ef91ec24c4848cc9973093e2d492d1c7b32afac1b49d F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d -F test/func.test b56905748ce0567c01d60005f3e6ad1af19453d224ba4730ee687d048fd09ef9 +F test/func.test 8e18545298489aadc95ee653e2aff1e4a98ebe119d356a52b83f8d528a7ea72c F test/func2.test 69f6ae3751b4ec765bdc3b803c0a255aa0f693f28f44805bef03e6b4a3fd242f F test/func3.test 600a632c305a88f3946d38f9a51efe145c989b2e13bd2b2a488db47fe76bab6a F test/func4.test a3f9062487dbd826776f54f4e0e9517fe8c3cf689af92735308965774d51fac5 @@ -2194,8 +2194,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 8080c6eafd1280ea870a6ab1ba715ac5af67387e69771be6cbd46dda77c3eaa8 -R b1d29e4b163a20c9d9aadcb22bf1cdb9 +P 816d4749384c7f398912c905a16c83b88f4c55632050b4c6117c61301d1a53e1 +R 312e87c7c5f6a411437e7dcf8c9768a7 +T *branch * concatb +T *sym-concatb * +T -sym-trunk * U mistachkin -Z 0cf3ec6bb41ed4737c063035dfa47552 +Z 77b4765c43d95146e57ecf29682d5748 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c4650e9df3..1d613490b3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -816d4749384c7f398912c905a16c83b88f4c55632050b4c6117c61301d1a53e1 \ No newline at end of file +07d8420285a49867b9c34f9e344eb666448dd9ce85c7791fa9480d98458684d9 \ No newline at end of file diff --git a/src/func.c b/src/func.c index 058f71cb64..f7b959e725 100644 --- a/src/func.c +++ b/src/func.c @@ -1551,18 +1551,19 @@ static void trimFunc( sqlite3_result_text(context, (char*)zIn, nIn, SQLITE_TRANSIENT); } -/* The core implementation of the CONCAT(...) and CONCAT_WS(SEP,...) -** functions. +/* The core implementation of the CONCAT(...), CONCATB(...), and +** CONCAT_WS(SEP,...) functions. ** -** Return a string value that is the concatenation of all non-null -** entries in argv[]. Use zSep as the separator. +** Return a string or blob value that is the concatenation of all +** non-null entries in argv[]. Use zSep as the separator. */ static void concatFuncCore( sqlite3_context *context, int argc, sqlite3_value **argv, int nSep, - const char *zSep + const char *zSep, + int bBlob ){ i64 j, k, n = 0; int i; @@ -1577,23 +1578,44 @@ static void concatFuncCore( return; } j = 0; - for(i=0; i0 ){ - const char *v = (const char*)sqlite3_value_text(argv[i]); - if( v!=0 ){ - if( j>0 && nSep>0 ){ - memcpy(&z[j], zSep, nSep); - j += nSep; + if( bBlob ){ + for(i=0; i0 ){ + const char *v = (const char*)sqlite3_value_blob(argv[i]); + if( v!=0 ){ + if( j>0 && nSep>0 ){ + memcpy(&z[j], zSep, nSep); + j += nSep; + } + memcpy(&z[j], v, k); + j += k; + } + } + } + }else{ + for(i=0; i0 ){ + const char *v = (const char*)sqlite3_value_text(argv[i]); + if( v!=0 ){ + if( j>0 && nSep>0 ){ + memcpy(&z[j], zSep, nSep); + j += nSep; + } + memcpy(&z[j], v, k); + j += k; } - memcpy(&z[j], v, k); - j += k; } } } z[j] = 0; assert( j<=n ); - sqlite3_result_text64(context, z, j, sqlite3_free, SQLITE_UTF8); + if( bBlob ){ + sqlite3_result_blob64(context, z, j, sqlite3_free); + }else{ + sqlite3_result_text64(context, z, j, sqlite3_free, SQLITE_UTF8); + } } /* @@ -1605,7 +1627,19 @@ static void concatFunc( int argc, sqlite3_value **argv ){ - concatFuncCore(context, argc, argv, 0, ""); + concatFuncCore(context, argc, argv, 0, "", 0); +} + +/* +** The CONCATB(...) function. Generate a blob result that is the +** concatentation of all non-null arguments. +*/ +static void concatBlobFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + concatFuncCore(context, argc, argv, 0, "", 1); } /* @@ -1623,7 +1657,7 @@ static void concatwsFunc( int nSep = sqlite3_value_bytes(argv[0]); const char *zSep = (const char*)sqlite3_value_text(argv[0]); if( zSep==0 ) return; - concatFuncCore(context, argc-1, argv+1, nSep, zSep); + concatFuncCore(context, argc-1, argv+1, nSep, zSep, 0); } @@ -2641,6 +2675,7 @@ void sqlite3RegisterBuiltinFunctions(void){ FUNCTION(unhex, 1, 0, 0, unhexFunc ), FUNCTION(unhex, 2, 0, 0, unhexFunc ), FUNCTION(concat, -1, 0, 0, concatFunc ), + FUNCTION(concatb, -1, 1, 0, concatBlobFunc ), FUNCTION(concat, 0, 0, 0, 0 ), FUNCTION(concat_ws, -1, 0, 0, concatwsFunc ), FUNCTION(concat_ws, 0, 0, 0, 0 ), diff --git a/test/func.test b/test/func.test index a3ecd4e30b..2f2de0153f 100644 --- a/test/func.test +++ b/test/func.test @@ -1582,4 +1582,14 @@ for {set i 2} {$i<10} {incr i} { } {Inf Inf Inf} } +# Tests for the CONCATB function. +# +do_execsql_test func-40.1 { + SELECT typeof(concatb(NULL, '1', X'ABCD', 'test')); +} {blob} + +do_execsql_test func-40.2 { + SELECT hex(concatb(NULL, '1', X'ABCD', 'test')); +} {31ABCD74657374} + finish_test