]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Gather forward references into a single place for the JSON code. Allow
authordrh <>
Mon, 2 Oct 2023 12:40:04 +0000 (12:40 +0000)
committerdrh <>
Mon, 2 Oct 2023 12:40:04 +0000 (12:40 +0000)
JSONB arguments to json_array() and json_object() and similar.

FossilOrigin-Name: c352201b8c299c330d9abbff6dbcbcbcf00ada53183d3cd91020ec772e066357

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

index 892d400ef4c68e9f3cf1e0f17bbcf82a000010f7..ac267d347c32c55d23959d24e9837ceeef9c2d5f 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sproblems\sfollowing\sOOM\sin\sJSONB\sparsing.
-D 2023-10-01T18:59:34.631
+C Gather\sforward\sreferences\sinto\sa\ssingle\splace\sfor\sthe\sJSON\scode.\s\sAllow\nJSONB\sarguments\sto\sjson_array()\sand\sjson_object()\sand\ssimilar.
+D 2023-10-02T12:40:04.670
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -670,7 +670,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51
 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6
 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276
-F src/json.c 253ca59ae7f4be5fa7e0d630f9073f6d2f8b6dd89b47d80192f3b037271fe45e
+F src/json.c e815a5e2f5bac5747e8290216eeb7de209aadc537a3f6a37b2880473bb2a8ed3
 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
 F src/loadext.c 98cfba10989b3da6f1807ad42444017742db7f100a54f1032af7a8b1295912c0
 F src/main.c 618aeb399e993cf561864f4b0cf6a331ee4f355cf663635f8d9da3193a46aa40
@@ -1303,7 +1303,7 @@ F test/json/json-generator.tcl dc0dd0f393800c98658fc4c47eaa6af29d4e17527380cd286
 F test/json/json-q1-b.txt 606818a5fba6d9e418c9f4ea7d8418af026775042dad81439b72447a147a462c
 F test/json/json-q1.txt 65f9d1cdcc4cffa9823fb73ed936aae5658700cd001fde448f68bfb91c807307
 F test/json/json-speed-check.sh b060a9a6c696c0a807d8929400fa11bd7113edc58b0d66b9795f424f8d0db326 x
-F test/json101.test dc9d5a2a5b1fd1b54dbd71c538b17933cc98d84b4c1f821ead754933663dca55
+F test/json101.test 728d90ecd6881a507e4081ed25ce0ac33ec501bbe897568ac47a71d9034561cc
 F test/json102.test 4c69694773a470f1fda34e5f4ba24920b35184fb66050b450fc2ef9ab5ad310b
 F test/json103.test 53df87f83a4e5fa0c0a56eb29ff6c94055c6eb919f33316d62161a8880112dbe
 F test/json104.test 1b844a70cddcfa2e4cd81a5db0657b2e61e7f00868310f24f56a9ba0114348c1
@@ -2123,8 +2123,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 15ffd932fecc82a5791b2024f55d2ec80887e8eb7345de68d6f5cac4912cfbe8
-R 32ce5e0c8d0e91f62fdd054af5b27453
+P 0d8cd6b5fb592f88f593ceaad9cdfa95dcfdf14169c3a56a5becbd66d62fd02b
+R cb29cf34fe33404e23405b0f8bd1299f
 U drh
-Z 6f251c6f66875dddb0d77e3789c48938
+Z e34235bdd2a6e0a4ec57afd79666bb6d
 # Remove this line to create a well-formed Fossil manifest.
index ffd32b4c8c7b42e281421be499fdc21cd828ba0d..cd8719aa9603d20c0d9cb41f55d54ce0c4ee7db8 100644 (file)
@@ -1 +1 @@
-0d8cd6b5fb592f88f593ceaad9cdfa95dcfdf14169c3a56a5becbd66d62fd02b
\ No newline at end of file
+c352201b8c299c330d9abbff6dbcbcbcf00ada53183d3cd91020ec772e066357
\ No newline at end of file
index 9f41ca43431432d27a70e0746cdee454c1bb4dd2..8070c7bdf74c05f64ccbea46f3987eafa0a502d7 100644 (file)
@@ -347,6 +347,17 @@ struct JsonParse {
 */
 #define JSON_MAX_DEPTH  1000
 
+/**************************************************************************
+** Forward references
+**************************************************************************/
+static void jsonReturnStringAsBlob(JsonString*);
+static void jsonRenderNodeAsBlob(JsonParse*,JsonNode*,JsonParse*);
+static int jsonParseAddNode(JsonParse*,u32,u32,const char*);
+static int jsonParseValueFromBlob(JsonParse *pParse, u32 i);
+static int jsonFuncArgMightBeBinary(sqlite3_value *pJson);
+static JsonNode *jsonLookupAppend(JsonParse*,const char*,int*,const char**);
+static u32 jsonRenderBlob(JsonParse*,u32,JsonString*);
+
 /**************************************************************************
 ** Utility routines for dealing with JsonString objects
 **************************************************************************/
@@ -714,7 +725,13 @@ static void jsonAppendSqlValue(
       break;
     }
     default: {
-      if( p->bErr==0 ){
+      if( jsonFuncArgMightBeBinary(pValue) ){
+        JsonParse px;
+        memset(&px, 0, sizeof(px));
+        px.aBlob = (u8*)sqlite3_value_blob(pValue);
+        px.nBlob = sqlite3_value_bytes(pValue);
+        jsonRenderBlob(&px, 0, p);
+      }else if( p->bErr==0 ){
         sqlite3_result_error(p->pCtx, "JSON cannot hold BLOB values", -1);
         p->bErr = 2;
         jsonStringReset(p);
@@ -724,8 +741,6 @@ static void jsonAppendSqlValue(
   }
 }
 
-/* Forward reference */
-static void jsonReturnStringAsBlob(JsonString*);
 
 /* Make the text in p (which is probably a generated JSON text string)
 ** the result of the SQL function.
@@ -968,13 +983,6 @@ static void jsonRenderNodeAsText(
   }
 }
 
-/* Forward reference */
-static void jsonRenderNodeAsBlob(
-  JsonParse *pParse,             /* the complete parse of the JSON */
-  JsonNode *pNode,               /* The node to render */
-  JsonParse *pOut                /* Write the BLOB rendering of JSON here */
-);
-
 /*
 ** Make the return value of an SQL function be the JSON encoded by pNode.
 **
@@ -1220,9 +1228,6 @@ static void jsonReturnNodeAsSql(
   }
 }
 
-/* Forward reference */
-static int jsonParseAddNode(JsonParse*,u32,u32,const char*);
-
 /*
 ** A macro to hint to the compiler that a function should not be
 ** inlined.
@@ -1973,9 +1978,6 @@ static void jsonParseFillInParentage(JsonParse *pParse, u32 i, u32 iParent){
   }
 }
 
-/* Forward reference */
-static int jsonParseValueFromBlob(JsonParse *pParse, u32 i);
-
 /*
 ** Parse JSON (either pure RFC-8259 JSON text, or JSON-5 text, or a JSONB
 ** blob) into the JsonNode representation.
@@ -2047,10 +2049,6 @@ static int jsonParseFindParents(JsonParse *pParse){
 #define JSON_CACHE_ID  (-429938)  /* First cache entry */
 #define JSON_CACHE_SZ  4          /* Max number of cache entries */
 
-/* Forward reference */
-static int jsonFuncArgMightBeBinary(sqlite3_value *pJson);
-
-
 /*
 ** Obtain a complete parse of the JSON found in the pJson argument
 **
@@ -2202,9 +2200,6 @@ static int jsonSameLabel(const JsonNode *p1, const JsonNode *p2){
   }
 }
 
-/* forward declaration */
-static JsonNode *jsonLookupAppend(JsonParse*,const char*,int*,const char**);
-
 /*
 ** Search along zPath to find the node specified.  Return a pointer
 ** to that node, or NULL if zPath is malformed or if there is no such
index 4da1d132cce0bc19131633d47e075b8652580952..5a7d770dde142fa32a7f4b84cff40d3ec54a0c7b 100644 (file)
@@ -36,6 +36,9 @@ do_execsql_test json101-1.2 {
 do_catchsql_test json101-1.3 {
   SELECT json_array(1,printf('%.1000c','x'),x'abcd',3);
 } {1 {JSON cannot hold BLOB values}}
+do_catchsql_test json101-1.3b {
+  SELECT jsonb_array(1,printf('%.1000c','x'),x'abcd',3);
+} {1 {JSON cannot hold BLOB values}}
 do_execsql_test json101-1.4 {
   SELECT json_array(-9223372036854775808,9223372036854775807,0,1,-1,
                     0.0, 1.0, -1.0, -1e99, +2e100,
@@ -47,13 +50,43 @@ do_execsql_test json101-1.4 {
                     'abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ',
                     99);
 } {[-9223372036854775808,9223372036854775807,0,1,-1,0.0,1.0,-1.0,-1.0e+99,2.0e+100,"one","two","three",4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,null,21,22,23,24,25,26,27,28,29,30,31,"abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ",99]}
+do_execsql_test json101-1.4b {
+  SELECT json(jsonb_array(-9223372036854775808,9223372036854775807,0,1,-1,
+                    0.0, 1.0, -1.0, -1e99, +2e100,
+                    'one','two','three',
+                    4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
+                    19, NULL, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+                    'abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ',
+                    'abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ',
+                    'abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ',
+                    99));
+} {[-9223372036854775808,9223372036854775807,0,1,-1,0.0,1.0,-1.0,-1.0e+99,2.0e+100,"one","two","three",4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,null,21,22,23,24,25,26,27,28,29,30,31,"abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ",99]}
 
 do_execsql_test json101-2.1 {
   SELECT json_object('a',1,'b',2.5,'c',null,'d','String Test');
 } {{{"a":1,"b":2.5,"c":null,"d":"String Test"}}}
+do_execsql_test json101-2.1b {
+  SELECT json(jsonb_object('a',1,'b',2.5,'c',null,'d','String Test'));
+} {{{"a":1,"b":2.5,"c":null,"d":"String Test"}}}
 do_catchsql_test json101-2.2 {
   SELECT json_object('a',printf('%.1000c','x'),2,2.5);
 } {1 {json_object() labels must be TEXT}}
+do_catchsql_test json101-2.2b {
+  SELECT jsonb_object('a',printf('%.1000c','x'),2,2.5);
+} {1 {json_object() labels must be TEXT}}
+do_execsql_test json101-2.2.2 {
+  SELECT json_object('a',json_array('xyx',77,4.5),'x',2.5);
+} {{{"a":["xyx",77,4.5],"x":2.5}}}
+do_execsql_test json101-2.2.2b {
+  SELECT json(jsonb_object('a',json_array('xyx',77,4.5),'x',2.5));
+} {{{"a":["xyx",77,4.5],"x":2.5}}}
+do_execsql_test json101-2.2.3 {
+  SELECT json_object('a',jsonb_array('xyx',77,4.5),'x',2.5);
+} {{{"a":["xyx",77,4.5],"x":2.5}}}
+do_execsql_test json101-2.2.3b {
+  SELECT json(jsonb_object('a',jsonb_array('xyx',77,4.5),'x',2.5));
+} {{{"a":["xyx",77,4.5],"x":2.5}}}
+exit
 do_catchsql_test json101-2.3 {
   SELECT json_object('a',1,'b');
 } {1 {json_object() requires an even number of arguments}}