]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix the jsonb_group_array() and jsonb_group_object() functions so that they return
authordrh <>
Sun, 25 Jan 2026 15:18:31 +0000 (15:18 +0000)
committerdrh <>
Sun, 25 Jan 2026 15:18:31 +0000 (15:18 +0000)
JSONB as they should, and not text JSON, when the array or object is empty.
[forum:/forumpost/2026-01-25T00:47:06z|Forum post 2026-01-25T00:47:06z].

FossilOrigin-Name: 8b53b97833afe27c0c3782c5fbc0437976215b571579f73a94c33e28d3fedb41

manifest
manifest.uuid
src/json.c
test/json103.test

index df05ee39818ee2f1e428a961079ccf87f199dd5c..599e54a01b0ea506b14fb576fb006823def3d192 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sharmless\scompiler\swarnings\sin\sFTS5.
-D 2026-01-25T11:56:25.815
+C Fix\sthe\sjsonb_group_array()\sand\sjsonb_group_object()\sfunctions\sso\sthat\sthey\sreturn\nJSONB\sas\sthey\sshould,\sand\snot\stext\sJSON,\swhen\sthe\sarray\sor\sobject\sis\sempty.\n[forum:/forumpost/2026-01-25T00:47:06z|Forum\spost\s2026-01-25T00:47:06z].
+D 2026-01-25T15:18:31.737
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -699,7 +699,7 @@ F src/hash.h 46b92795a95bfefb210f52f0c316e9d7cdbcdd7e7fcfb0d8be796d3a5767cddf
 F src/hwtime.h 21c2cf1f736e7b97502c3674d0c386db3f06870d6f10d0cf8174e2a4b8cb726e
 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
 F src/insert.c dfd311b0ac2d4f6359e62013db67799757f4d2cc56cca5c10f4888acfbbfa3fd
-F src/json.c ba253db3d5af854d9785c844426e55bc67224578c8bf6ef1c35db89ba3c25cd1
+F src/json.c 519fa46cc3e11d836c264c628ca9ca537ce6f18042151cf7a5c71e3ac5a4a970
 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
 F src/loadext.c d6559d2b39c9bde6b104b83adeafbe5db3a514aae4d3d40afc58de522a03043b
 F src/main.c e95aa130478fc98a49181ddf094baab45f319286411129253618efe0008f0dc4
@@ -1355,7 +1355,7 @@ F test/json/json-speed-check.sh 7d5898808ce7542762318306ae6075a30f5e7ee115c4a409
 F test/json/jsonb-q1.txt 1e180fe6491efab307e318b22879e3a736ac9a96539bbde7911a13ee5b33abc7
 F test/json101.test cf53254f0f0c1399a01b21fc58fee0e63a12a556be91b9ee9faccdb8b82c083c
 F test/json102.test 9b2e5ada10845ff84853b3feaae2ce51ce7145ae458f74c6a6cecc6ef6ee3ae1
-F test/json103.test 355746a6b66aa438f214b4fae454b13068fad2444b5f693e0d538ad1c059b264
+F test/json103.test e626d109cd0bdb8282ec9bf755af3befa50e3e03a255362fc53433d31e1d66d4
 F test/json104.test 1b844a70cddcfa2e4cd81a5db0657b2e61e7f00868310f24f56a9ba0114348c1
 F test/json105.test 043838b56e68f3252a0dcf5be1689016f6f3f05056f8dcfcdc9d074f4d932988
 F test/json106.test 4aed3afd16549045d198a8d9cea00deea96e1f2ecf55864dce96cac558b8abef
@@ -2193,8 +2193,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee
 F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
 F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c
-P e761fcc6838aee1fa5e098ad167866845a8ee140a3346fb089a1238abb58d998
-R 66c102bc7d5b33ee181aa8942d7a5189
+P 29d9132a768e0460e22e41abb8b6188181ba0fc6c4665161d3d0af28d7583e19
+R a2190275d4fd82c25baf2a871b5c8b0b
 U drh
-Z 6be522562dcaec28604b5686bed7edb0
+Z 097b5abf8d6625e3aeef0e93567c3ee6
 # Remove this line to create a well-formed Fossil manifest.
index 3e73912914e1b27c5314fb478ac08d2404c671ae..7aa29858062298e0ac2bd95c3976ec48bd61a641 100644 (file)
@@ -1 +1 @@
-29d9132a768e0460e22e41abb8b6188181ba0fc6c4665161d3d0af28d7583e19
+8b53b97833afe27c0c3782c5fbc0437976215b571579f73a94c33e28d3fedb41
index 1ba1e1f93b1d8323fb2be328f55b881415077e81..90f5031673eb78a80856f913b690398abcc03e3e 100644 (file)
@@ -4799,12 +4799,11 @@ static void jsonArrayStep(
 }
 static void jsonArrayCompute(sqlite3_context *ctx, int isFinal){
   JsonString *pStr;
+  int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(ctx));
   pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
   if( pStr ){
-    int flags;
     pStr->pCtx = ctx;
     jsonAppendChar(pStr, ']');
-    flags = SQLITE_PTR_TO_INT(sqlite3_user_data(ctx));
     if( pStr->eErr ){
       jsonReturnString(pStr, 0, 0);
       return;
@@ -4825,6 +4824,9 @@ static void jsonArrayCompute(sqlite3_context *ctx, int isFinal){
       sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed, SQLITE_TRANSIENT);
       jsonStringTrimOneChar(pStr);
     }
+  }else if( flags & JSON_BLOB ){
+    static const u8 emptyArray = 0x0b;
+    sqlite3_result_blob(ctx, &emptyArray, 1, SQLITE_STATIC);
   }else{
     sqlite3_result_text(ctx, "[]", 2, SQLITE_STATIC);
   }
@@ -4921,12 +4923,11 @@ static void jsonObjectStep(
 }
 static void jsonObjectCompute(sqlite3_context *ctx, int isFinal){
   JsonString *pStr;
+  int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(ctx));
   pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
   if( pStr ){
-    int flags;
     jsonAppendChar(pStr, '}');
     pStr->pCtx = ctx;
-    flags = SQLITE_PTR_TO_INT(sqlite3_user_data(ctx));
     if( pStr->eErr ){
       jsonReturnString(pStr, 0, 0);
       return;
@@ -4947,6 +4948,9 @@ static void jsonObjectCompute(sqlite3_context *ctx, int isFinal){
       sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed, SQLITE_TRANSIENT);
       jsonStringTrimOneChar(pStr);
     }
+  }else if( flags & JSON_BLOB ){
+    static const unsigned char emptyObject = 0x0c;
+    sqlite3_result_blob(ctx, &emptyObject, 1, SQLITE_STATIC); 
   }else{
     sqlite3_result_text(ctx, "{}", 2, SQLITE_STATIC);
   }
index f94217ac10cb31c67373fbeb7bec6dd6b6683f48..9eadf29f8158da6b547e1b84a21a96d6e58f65dd 100644 (file)
@@ -27,6 +27,9 @@ do_execsql_test json103-100 {
 do_catchsql_test json103-101 {
   SELECT json_group_array(a) FROM t1;
 } {1 {JSON cannot hold BLOB values}}
+do_execsql_test json103-102 {
+  SELECT quote(jsonb_group_array(a)) FROM t1 WHERE a<0 AND typeof(a)!='blob';
+} {X'0B'}
 do_execsql_test json103-110 {
   SELECT json_group_array(a) FROM t1
    WHERE rowid BETWEEN 31 AND 39;
@@ -45,6 +48,10 @@ do_execsql_test json103-200 {
 do_catchsql_test json103-201 {
   SELECT json_group_object(c,a) FROM t1;
 } {1 {JSON cannot hold BLOB values}}
+do_execsql_test json103-202 {
+  SELECT quote(jsonb_group_object(c,a)) FROM t1 WHERE a<0 AND typeof(a)!='blob';
+} {X'0C'}
+
 
 do_execsql_test json103-210 {
   SELECT json_group_object(c,a) FROM t1