1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-09 14:21:03 +03:00

Systematize the names of some of the translation function in the JSON

implementation.

FossilOrigin-Name: db44bd1d62084ef69c808f7d07e0a25d5a089dcb8b98b1b5d026777591bbdefc
This commit is contained in:
drh
2023-10-09 18:33:01 +00:00
parent 0dead8d3d1
commit f32aa34346
3 changed files with 78 additions and 75 deletions

View File

@@ -1,5 +1,5 @@
C Merge\sthe\slatest\strunk\sfixes\sand\senhancements\sinto\sthe\sjsonb\sbranch,\sand\nespecially\sthe\sJSON\scache\sspill\sUAF\sfix. C Systematize\sthe\snames\sof\ssome\sof\sthe\stranslation\sfunction\sin\sthe\sJSON\nimplementation.
D 2023-10-09T12:57:03.290 D 2023-10-09T18:33:01.568
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -245,7 +245,7 @@ F ext/jni/src/org/sqlite/jni/AggregateFunction.java 7312486bc65fecdb91753c0a4515
F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java fde5f758ad170ca45ae00b12194c8ba8d8f3090bd64cc3e002dd9c5e7dff8568 F ext/jni/src/org/sqlite/jni/AuthorizerCallback.java fde5f758ad170ca45ae00b12194c8ba8d8f3090bd64cc3e002dd9c5e7dff8568
F ext/jni/src/org/sqlite/jni/AutoExtensionCallback.java c0fbfd3779fc92982c7935325a7484dee43eeb80d716989ed31218f453addb94 F ext/jni/src/org/sqlite/jni/AutoExtensionCallback.java c0fbfd3779fc92982c7935325a7484dee43eeb80d716989ed31218f453addb94
F ext/jni/src/org/sqlite/jni/BusyHandlerCallback.java 4cb7fc70efd55583fed6033c34a8719da42975ca97ef4781dda0b9f6cc8ec2e8 F ext/jni/src/org/sqlite/jni/BusyHandlerCallback.java 4cb7fc70efd55583fed6033c34a8719da42975ca97ef4781dda0b9f6cc8ec2e8
F ext/jni/src/org/sqlite/jni/CApi.java c1dde485a3a3f43c46c8d9c527f9ba5bf303fe0409b2c0de253fb7b6e1055f7e w ext/jni/src/org/sqlite/jni/SQLite3Jni.java F ext/jni/src/org/sqlite/jni/CApi.java c1dde485a3a3f43c46c8d9c527f9ba5bf303fe0409b2c0de253fb7b6e1055f7e
F ext/jni/src/org/sqlite/jni/CallbackProxy.java 064a8a00e4c63cc501c30504f93ca996d422c5f010067f969b2d0a10f0868153 F ext/jni/src/org/sqlite/jni/CallbackProxy.java 064a8a00e4c63cc501c30504f93ca996d422c5f010067f969b2d0a10f0868153
F ext/jni/src/org/sqlite/jni/CollationCallback.java 8cf57cb014a645ecc12609eed17308852a597bc5e83d82a4fdb90f7fadc25f9d F ext/jni/src/org/sqlite/jni/CollationCallback.java 8cf57cb014a645ecc12609eed17308852a597bc5e83d82a4fdb90f7fadc25f9d
F ext/jni/src/org/sqlite/jni/CollationNeededCallback.java 0c62245e000d5db52576c728cac20f6a31f31f5cf40ca4cbcd64b22964e82ae5 F ext/jni/src/org/sqlite/jni/CollationNeededCallback.java 0c62245e000d5db52576c728cac20f6a31f31f5cf40ca4cbcd64b22964e82ae5
@@ -674,7 +674,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51
F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6 F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6
F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276 F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276
F src/json.c 8717fe7a6461f24ba7b92ccd323c8e2417f44f2a959704c5a05a7aac1ca0df12 F src/json.c bbf52181d04e09852e273f11cf31544a8030ffc911359cb7f77e39f252cce7a6
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
F src/loadext.c 98cfba10989b3da6f1807ad42444017742db7f100a54f1032af7a8b1295912c0 F src/loadext.c 98cfba10989b3da6f1807ad42444017742db7f100a54f1032af7a8b1295912c0
F src/main.c 618aeb399e993cf561864f4b0cf6a331ee4f355cf663635f8d9da3193a46aa40 F src/main.c 618aeb399e993cf561864f4b0cf6a331ee4f355cf663635f8d9da3193a46aa40
@@ -2128,8 +2128,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P cbea16c29eb0507f39b5a1cf744a3bb9bb7c71ac156e84a19d03a37cb1816891 a163fecca90cab9d1b7bf8ebac78d498775eed7b6d81e7920e3401633c3a4b60 P 9422c24f4a8b290dcae61e50ec81be5b314b22c61a2bca1e194e47da1316b6e6
R 1dd322f61ae3b783d06705b01094df38 R 3ec6096d3289810ffc9770092e31c712
U drh U drh
Z 41e410a665a938a0454df231f95bd4b4 Z 411045c6779d7c6439ce2a3295f7e71a
# Remove this line to create a well-formed Fossil manifest. # Remove this line to create a well-formed Fossil manifest.

View File

@@ -1 +1 @@
9422c24f4a8b290dcae61e50ec81be5b314b22c61a2bca1e194e47da1316b6e6 db44bd1d62084ef69c808f7d07e0a25d5a089dcb8b98b1b5d026777591bbdefc

View File

@@ -337,7 +337,7 @@ struct JsonParse {
u32 iErr; /* Error location in zJson[] */ u32 iErr; /* Error location in zJson[] */
u32 iSubst; /* Last JSON_SUBST entry in aNode[] */ u32 iSubst; /* Last JSON_SUBST entry in aNode[] */
u32 iHold; /* Age of this entry in the cache for LRU replacement */ u32 iHold; /* Age of this entry in the cache for LRU replacement */
/* Binary format */ /* Storage for the binary JSONB format */
u32 nBlob; /* Bytes of aBlob[] actually used */ u32 nBlob; /* Bytes of aBlob[] actually used */
u32 nBlobAlloc; /* Bytes allocated to aBlob[] */ u32 nBlobAlloc; /* Bytes allocated to aBlob[] */
u8 *aBlob; /* BLOB representation of zJson */ u8 *aBlob; /* BLOB representation of zJson */
@@ -356,12 +356,12 @@ struct JsonParse {
** Forward references ** Forward references
**************************************************************************/ **************************************************************************/
static void jsonReturnStringAsBlob(JsonString*); static void jsonReturnStringAsBlob(JsonString*);
static void jsonRenderNodeAsBlob(JsonParse*,JsonNode*,JsonParse*); static void jsonXlateNodeToBlob(JsonParse*,JsonNode*,JsonParse*);
static int jsonParseAddNode(JsonParse*,u32,u32,const char*); static int jsonParseAddNode(JsonParse*,u32,u32,const char*);
static int jsonParseValueFromBlob(JsonParse *pParse, u32 i); static int jsonXlateBlobToNode(JsonParse *pParse, u32 i);
static int jsonFuncArgMightBeBinary(sqlite3_value *pJson); static int jsonFuncArgMightBeBinary(sqlite3_value *pJson);
static JsonNode *jsonLookupAppend(JsonParse*,const char*,int*,const char**); static JsonNode *jsonLookupAppend(JsonParse*,const char*,int*,const char**);
static u32 jsonRenderBlob(JsonParse*,u32,JsonString*); static u32 jsonXlateBlobToText(JsonParse*,u32,JsonString*);
/************************************************************************** /**************************************************************************
** Utility routines for dealing with JsonString objects ** Utility routines for dealing with JsonString objects
@@ -735,7 +735,7 @@ static void jsonAppendSqlValue(
memset(&px, 0, sizeof(px)); memset(&px, 0, sizeof(px));
px.aBlob = (u8*)sqlite3_value_blob(pValue); px.aBlob = (u8*)sqlite3_value_blob(pValue);
px.nBlob = sqlite3_value_bytes(pValue); px.nBlob = sqlite3_value_bytes(pValue);
jsonRenderBlob(&px, 0, p); jsonXlateBlobToText(&px, 0, p);
}else if( p->eErr==0 ){ }else if( p->eErr==0 ){
sqlite3_result_error(p->pCtx, "JSON cannot hold BLOB values", -1); sqlite3_result_error(p->pCtx, "JSON cannot hold BLOB values", -1);
p->eErr = JSTRING_ERR; p->eErr = JSTRING_ERR;
@@ -868,11 +868,10 @@ static int jsonParseAddCleanup(
} }
/* /*
** Convert the JsonNode pNode into a pure JSON string and ** Translate the JsonNode pNode into a pure JSON string and
** append to pOut. Subsubstructure is also included. Return ** append that string on pOut. Subsubstructure is also included.
** the number of JsonNode objects that are encoded.
*/ */
static void jsonRenderNodeAsText( static void jsonXlateNodeToText(
JsonParse *pParse, /* the complete parse of the JSON */ JsonParse *pParse, /* the complete parse of the JSON */
JsonNode *pNode, /* The node to render */ JsonNode *pNode, /* The node to render */
JsonString *pOut /* Write JSON here */ JsonString *pOut /* Write JSON here */
@@ -947,7 +946,7 @@ static void jsonRenderNodeAsText(
while( j<=pNode->n ){ while( j<=pNode->n ){
if( (pNode[j].jnFlags & JNODE_REMOVE)==0 || pParse->useMod==0 ){ if( (pNode[j].jnFlags & JNODE_REMOVE)==0 || pParse->useMod==0 ){
jsonAppendSeparator(pOut); jsonAppendSeparator(pOut);
jsonRenderNodeAsText(pParse, &pNode[j], pOut); jsonXlateNodeToText(pParse, &pNode[j], pOut);
} }
j += jsonNodeSize(&pNode[j]); j += jsonNodeSize(&pNode[j]);
} }
@@ -967,9 +966,9 @@ static void jsonRenderNodeAsText(
while( j<=pNode->n ){ while( j<=pNode->n ){
if( (pNode[j+1].jnFlags & JNODE_REMOVE)==0 || pParse->useMod==0 ){ if( (pNode[j+1].jnFlags & JNODE_REMOVE)==0 || pParse->useMod==0 ){
jsonAppendSeparator(pOut); jsonAppendSeparator(pOut);
jsonRenderNodeAsText(pParse, &pNode[j], pOut); jsonXlateNodeToText(pParse, &pNode[j], pOut);
jsonAppendChar(pOut, ':'); jsonAppendChar(pOut, ':');
jsonRenderNodeAsText(pParse, &pNode[j+1], pOut); jsonXlateNodeToText(pParse, &pNode[j+1], pOut);
} }
j += 1 + jsonNodeSize(&pNode[j+1]); j += 1 + jsonNodeSize(&pNode[j+1]);
} }
@@ -1012,7 +1011,7 @@ static void jsonReturnNodeAsJson(
if( flags & JSON_BLOB ){ if( flags & JSON_BLOB ){
JsonParse x; JsonParse x;
memset(&x, 0, sizeof(x)); memset(&x, 0, sizeof(x));
jsonRenderNodeAsBlob(pParse, pNode, &x); jsonXlateNodeToBlob(pParse, pNode, &x);
if( x.oom ){ if( x.oom ){
sqlite3_result_error_nomem(pCtx); sqlite3_result_error_nomem(pCtx);
sqlite3_free(x.aBlob); sqlite3_free(x.aBlob);
@@ -1021,7 +1020,7 @@ static void jsonReturnNodeAsJson(
} }
}else{ }else{
jsonStringInit(&s, pCtx); jsonStringInit(&s, pCtx);
jsonRenderNodeAsText(pParse, pNode, &s); jsonXlateNodeToText(pParse, pNode, &s);
if( bGenerateAlt && pParse->zAlt==0 && jsonForceRCStr(&s) ){ if( bGenerateAlt && pParse->zAlt==0 && jsonForceRCStr(&s) ){
pParse->zAlt = sqlite3RCStrRef(s.zBuf); pParse->zAlt = sqlite3RCStrRef(s.zBuf);
pParse->nAlt = s.nUsed; pParse->nAlt = s.nUsed;
@@ -1072,7 +1071,7 @@ static u32 jsonHexToInt4(const char *z){
** value returned is either RFC-8259 JSON text or a BLOB in the JSONB ** value returned is either RFC-8259 JSON text or a BLOB in the JSONB
** format, depending on the JSON_BLOB flag of the function user-data. ** format, depending on the JSON_BLOB flag of the function user-data.
*/ */
static void jsonReturnNodeAsSql( static void jsonReturnFromNode(
JsonParse *pParse, /* Complete JSON parse tree */ JsonParse *pParse, /* Complete JSON parse tree */
JsonNode *pNode, /* Node to return */ JsonNode *pNode, /* Node to return */
sqlite3_context *pCtx /* Return value for this function */ sqlite3_context *pCtx /* Return value for this function */
@@ -1510,8 +1509,11 @@ static const struct NanInfName {
}; };
/* /*
** Parse a single JSON value which begins at pParse->zJson[i]. Return the ** Translate a single element of JSON text beginning at pParse->zJson[i] into
** index of the first character past the end of the value parsed. ** its JsonNode representation. Append the translation onto the
** pParse->aNode[] array, which is increased in size as necessary.
** Return the pJson->zJson[] index of the first character past the end of
** the element that was parsed.
** **
** Special return values: ** Special return values:
** **
@@ -1522,7 +1524,7 @@ static const struct NanInfName {
** -4 ',' seen / the index in zJson[] of the seen character ** -4 ',' seen / the index in zJson[] of the seen character
** -5 ':' seen / ** -5 ':' seen /
*/ */
static int jsonParseValueFromText(JsonParse *pParse, u32 i){ static int jsonXlateTextToNode(JsonParse *pParse, u32 i){
char c; char c;
u32 j; u32 j;
int iThis; int iThis;
@@ -1541,7 +1543,7 @@ json_parse_restart:
} }
for(j=i+1;;j++){ for(j=i+1;;j++){
u32 nNode = pParse->nNode; u32 nNode = pParse->nNode;
x = jsonParseValueFromText(pParse, j); x = jsonXlateTextToNode(pParse, j);
if( x<=0 ){ if( x<=0 ){
if( x==(-2) ){ if( x==(-2) ){
j = pParse->iErr; j = pParse->iErr;
@@ -1584,7 +1586,7 @@ json_parse_restart:
goto parse_object_value; goto parse_object_value;
} }
} }
x = jsonParseValueFromText(pParse, j); x = jsonXlateTextToNode(pParse, j);
if( x!=(-5) ){ if( x!=(-5) ){
if( x!=(-1) ) pParse->iErr = j; if( x!=(-1) ) pParse->iErr = j;
return -1; return -1;
@@ -1592,7 +1594,7 @@ json_parse_restart:
j = pParse->iErr+1; j = pParse->iErr+1;
} }
parse_object_value: parse_object_value:
x = jsonParseValueFromText(pParse, j); x = jsonXlateTextToNode(pParse, j);
if( x<=0 ){ if( x<=0 ){
if( x!=(-1) ) pParse->iErr = j; if( x!=(-1) ) pParse->iErr = j;
return -1; return -1;
@@ -1611,7 +1613,7 @@ json_parse_restart:
break; break;
} }
} }
x = jsonParseValueFromText(pParse, j); x = jsonXlateTextToNode(pParse, j);
if( x==(-4) ){ if( x==(-4) ){
j = pParse->iErr; j = pParse->iErr;
continue; continue;
@@ -1640,7 +1642,7 @@ json_parse_restart:
} }
memset(&pParse->aNode[iThis].u, 0, sizeof(pParse->aNode[iThis].u)); memset(&pParse->aNode[iThis].u, 0, sizeof(pParse->aNode[iThis].u));
for(j=i+1;;j++){ for(j=i+1;;j++){
x = jsonParseValueFromText(pParse, j); x = jsonXlateTextToNode(pParse, j);
if( x<=0 ){ if( x<=0 ){
if( x==(-3) ){ if( x==(-3) ){
j = pParse->iErr; j = pParse->iErr;
@@ -1664,7 +1666,7 @@ json_parse_restart:
break; break;
} }
} }
x = jsonParseValueFromText(pParse, j); x = jsonXlateTextToNode(pParse, j);
if( x==(-4) ){ if( x==(-4) ){
j = pParse->iErr; j = pParse->iErr;
continue; continue;
@@ -2004,9 +2006,9 @@ static int jsonParse(
if( pParse->isBinary ){ if( pParse->isBinary ){
pParse->aBlob = (u8*)pParse->zJson; pParse->aBlob = (u8*)pParse->zJson;
pParse->nBlob = pParse->nJson; pParse->nBlob = pParse->nJson;
i = jsonParseValueFromBlob(pParse, 0); i = jsonXlateBlobToNode(pParse, 0);
}else{ }else{
i = jsonParseValueFromText(pParse, 0); i = jsonXlateTextToNode(pParse, 0);
} }
if( pParse->oom ) i = -1; if( pParse->oom ) i = -1;
if( !pParse->isBinary && i>0 ){ if( !pParse->isBinary && i>0 ){
@@ -2679,12 +2681,12 @@ static int jsonIs4HexB(const char *z, int *pOp){
} }
/* /*
** Parse a single JSON text value which begins at pParse->zJson[i] into ** Translate a single element of JSON text at pParse->zJson[i] into
** its equivalent BLOB representation in pParse->aBlob[]. The parse is ** its equivalent binary JSONB representation. Append the translation into
** appended to pParse->aBlob[] beginning at pParse->nBlob. The size of ** pParse->aBlob[] beginning at pParse->nBlob. The size of
** pParse->aBlob[] is increased as necessary. ** pParse->aBlob[] is increased as necessary.
** **
** Return the index of the first character past the end of the value parsed, ** Return the index of the first character past the end of the element parsed,
** or one of the following special result codes: ** or one of the following special result codes:
** **
** 0 End of input ** 0 End of input
@@ -2694,7 +2696,7 @@ static int jsonIs4HexB(const char *z, int *pOp){
** -4 ',' seen / the index in zJson[] of the seen character ** -4 ',' seen / the index in zJson[] of the seen character
** -5 ':' seen / ** -5 ':' seen /
*/ */
static int jsonTranslateTextValueToBlob(JsonParse *pParse, u32 i){ static int jsonXlateTextToBlob(JsonParse *pParse, u32 i){
char c; char c;
u32 j; u32 j;
u32 iThis, iStart; u32 iThis, iStart;
@@ -2714,7 +2716,7 @@ json_parse_restart:
iStart = pParse->nBlob; iStart = pParse->nBlob;
for(j=i+1;;j++){ for(j=i+1;;j++){
u32 iBlob = pParse->nBlob; u32 iBlob = pParse->nBlob;
x = jsonTranslateTextValueToBlob(pParse, j); x = jsonXlateTextToBlob(pParse, j);
if( x<=0 ){ if( x<=0 ){
int op; int op;
if( x==(-2) ){ if( x==(-2) ){
@@ -2760,7 +2762,7 @@ json_parse_restart:
goto parse_object_value; goto parse_object_value;
} }
} }
x = jsonTranslateTextValueToBlob(pParse, j); x = jsonXlateTextToBlob(pParse, j);
if( x!=(-5) ){ if( x!=(-5) ){
if( x!=(-1) ) pParse->iErr = j; if( x!=(-1) ) pParse->iErr = j;
return -1; return -1;
@@ -2768,7 +2770,7 @@ json_parse_restart:
j = pParse->iErr+1; j = pParse->iErr+1;
} }
parse_object_value: parse_object_value:
x = jsonTranslateTextValueToBlob(pParse, j); x = jsonXlateTextToBlob(pParse, j);
if( x<=0 ){ if( x<=0 ){
if( x!=(-1) ) pParse->iErr = j; if( x!=(-1) ) pParse->iErr = j;
return -1; return -1;
@@ -2787,7 +2789,7 @@ json_parse_restart:
break; break;
} }
} }
x = jsonTranslateTextValueToBlob(pParse, j); x = jsonXlateTextToBlob(pParse, j);
if( x==(-4) ){ if( x==(-4) ){
j = pParse->iErr; j = pParse->iErr;
continue; continue;
@@ -2815,7 +2817,7 @@ json_parse_restart:
return -1; return -1;
} }
for(j=i+1;;j++){ for(j=i+1;;j++){
x = jsonTranslateTextValueToBlob(pParse, j); x = jsonXlateTextToBlob(pParse, j);
if( x<=0 ){ if( x<=0 ){
if( x==(-3) ){ if( x==(-3) ){
j = pParse->iErr; j = pParse->iErr;
@@ -2839,7 +2841,7 @@ json_parse_restart:
break; break;
} }
} }
x = jsonTranslateTextValueToBlob(pParse, j); x = jsonXlateTextToBlob(pParse, j);
if( x==(-4) ){ if( x==(-4) ){
j = pParse->iErr; j = pParse->iErr;
continue; continue;
@@ -3156,7 +3158,7 @@ static int jsonConvertTextToBlob(
){ ){
int i; int i;
const char *zJson = pParse->zJson; const char *zJson = pParse->zJson;
i = jsonTranslateTextValueToBlob(pParse, 0); i = jsonXlateTextToBlob(pParse, 0);
if( pParse->oom ) i = -1; if( pParse->oom ) i = -1;
if( i>0 ){ if( i>0 ){
assert( pParse->iDepth==0 ); assert( pParse->iDepth==0 );
@@ -3194,7 +3196,7 @@ static void jsonReturnStringAsBlob(JsonString *pStr){
memset(&px, 0, sizeof(px)); memset(&px, 0, sizeof(px));
px.zJson = pStr->zBuf; px.zJson = pStr->zBuf;
px.nJson = pStr->nUsed; px.nJson = pStr->nUsed;
(void)jsonTranslateTextValueToBlob(&px, 0); (void)jsonXlateTextToBlob(&px, 0);
if( px.oom ){ if( px.oom ){
sqlite3_free(px.aBlob); sqlite3_free(px.aBlob);
sqlite3_result_error_nomem(pStr->pCtx); sqlite3_result_error_nomem(pStr->pCtx);
@@ -3253,9 +3255,10 @@ static u32 jsonbPayloadSize(JsonParse *pParse, u32 i, u32 *pSz){
/* /*
** Convert the binary BLOB representation of JSON beginning at ** Translate the binary JSONB representation of JSON beginning at
** aBlob[0] and extending for no more than nBlob bytes into ** pParse->aBlob[i] into a JSON text string. Append the JSON
** a pure JSON string. The string is appended to pOut. ** text onto the end of pOut. Return the index in pParse->aBlob[]
** of the first byte past the end of the element that is translated.
** **
** If an error is detected in the BLOB input, the pOut->eErr flag ** If an error is detected in the BLOB input, the pOut->eErr flag
** might get set to JSTRING_MALFORMED. But not all BLOB input errors ** might get set to JSTRING_MALFORMED. But not all BLOB input errors
@@ -3264,7 +3267,7 @@ static u32 jsonbPayloadSize(JsonParse *pParse, u32 i, u32 *pSz){
** **
** The pOut->eErr JSTRING_OOM flag is set on a OOM. ** The pOut->eErr JSTRING_OOM flag is set on a OOM.
*/ */
static u32 jsonRenderBlob( static u32 jsonXlateBlobToText(
JsonParse *pParse, /* the complete parse of the JSON */ JsonParse *pParse, /* the complete parse of the JSON */
u32 i, /* Start rendering at this index */ u32 i, /* Start rendering at this index */
JsonString *pOut /* Write JSON here */ JsonString *pOut /* Write JSON here */
@@ -3403,7 +3406,7 @@ static u32 jsonRenderBlob(
j = i+n; j = i+n;
iEnd = j+sz; iEnd = j+sz;
while( j<iEnd ){ while( j<iEnd ){
j = jsonRenderBlob(pParse, j, pOut); j = jsonXlateBlobToText(pParse, j, pOut);
jsonAppendChar(pOut, ','); jsonAppendChar(pOut, ',');
} }
if( sz>0 ) pOut->nUsed--; if( sz>0 ) pOut->nUsed--;
@@ -3416,7 +3419,7 @@ static u32 jsonRenderBlob(
j = i+n; j = i+n;
iEnd = j+sz; iEnd = j+sz;
while( j<iEnd ){ while( j<iEnd ){
j = jsonRenderBlob(pParse, j, pOut); j = jsonXlateBlobToText(pParse, j, pOut);
jsonAppendChar(pOut, (x++ & 1) ? ',' : ':'); jsonAppendChar(pOut, (x++ & 1) ? ',' : ':');
} }
if( sz>0 ) pOut->nUsed--; if( sz>0 ) pOut->nUsed--;
@@ -3458,14 +3461,13 @@ static int jsonFuncArgMightBeBinary(sqlite3_value *pJson){
return sz+n==(u32)nBlob; return sz+n==(u32)nBlob;
} }
/* Parse a single element of binary JSON into the legacy Node structure. /* Translate a single element of JSONB into the JsonNode format. The
** Return the index of the first byte past the end of the binary JSON element. ** first byte of the element to be translated is at pParse->aBlob[i].
** ** Return the index in pParse->aBlob[] of the first byte past the end
** This routine is a temporary translator while the legacy Node encoding ** of the JSONB element. Append the JsonNode translation in
** is still in use. It will be removed after all processing translates ** pParse->aNode[], which is increased in size as necessary.
** to the new BLOB encoding.
*/ */
static int jsonParseValueFromBlob(JsonParse *pParse, u32 i){ static int jsonXlateBlobToNode(JsonParse *pParse, u32 i){
u8 t; /* Node type */ u8 t; /* Node type */
u32 sz; /* Node size */ u32 sz; /* Node size */
u32 x; /* Index of payload start */ u32 x; /* Index of payload start */
@@ -3535,7 +3537,7 @@ static int jsonParseValueFromBlob(JsonParse *pParse, u32 i){
int iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0); int iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0);
u32 j = i+x; u32 j = i+x;
while( j<i+x+sz ){ while( j<i+x+sz ){
int r = jsonParseValueFromBlob(pParse, j); int r = jsonXlateBlobToNode(pParse, j);
if( r<=0 ) return -1; if( r<=0 ) return -1;
j = (u32)r; j = (u32)r;
} }
@@ -3548,7 +3550,7 @@ static int jsonParseValueFromBlob(JsonParse *pParse, u32 i){
int iThis = jsonParseAddNode(pParse, JSON_OBJECT, 0, 0); int iThis = jsonParseAddNode(pParse, JSON_OBJECT, 0, 0);
u32 j = i+x, k = 0; u32 j = i+x, k = 0;
while( j<i+x+sz ){ while( j<i+x+sz ){
int r = jsonParseValueFromBlob(pParse, j); int r = jsonXlateBlobToNode(pParse, j);
if( r<=0 ) return -1; if( r<=0 ) return -1;
if( (k++&1)==0 && !pParse->oom ){ if( (k++&1)==0 && !pParse->oom ){
pParse->aNode[pParse->nNode-1].jnFlags |= JNODE_LABEL; pParse->aNode[pParse->nNode-1].jnFlags |= JNODE_LABEL;
@@ -3569,10 +3571,11 @@ static int jsonParseValueFromBlob(JsonParse *pParse, u32 i){
} }
/* /*
** Convert pNode that belongs to pParse into the BLOB representation. ** Translate pNode (which is always a node found in pParse->aNode[]) into
** The BLOB representation is added to the pOut->aBlob[] array. ** the JSONB representation and append the translation onto the end of the
** pOut->aBlob[] array.
*/ */
static void jsonRenderNodeAsBlob( static void jsonXlateNodeToBlob(
JsonParse *pParse, /* the complete parse of the JSON */ JsonParse *pParse, /* the complete parse of the JSON */
JsonNode *pNode, /* The node to render */ JsonNode *pNode, /* The node to render */
JsonParse *pOut /* Write the BLOB rendering of JSON here */ JsonParse *pOut /* Write the BLOB rendering of JSON here */
@@ -3661,7 +3664,7 @@ static void jsonRenderNodeAsBlob(
for(;;){ for(;;){
while( j<=pNode->n ){ while( j<=pNode->n ){
if( (pNode[j].jnFlags & JNODE_REMOVE)==0 || pParse->useMod==0 ){ if( (pNode[j].jnFlags & JNODE_REMOVE)==0 || pParse->useMod==0 ){
jsonRenderNodeAsBlob(pParse, &pNode[j], pOut); jsonXlateNodeToBlob(pParse, &pNode[j], pOut);
} }
j += jsonNodeSize(&pNode[j]); j += jsonNodeSize(&pNode[j]);
} }
@@ -3682,8 +3685,8 @@ static void jsonRenderNodeAsBlob(
for(;;){ for(;;){
while( j<=pNode->n ){ while( j<=pNode->n ){
if( (pNode[j+1].jnFlags & JNODE_REMOVE)==0 || pParse->useMod==0 ){ if( (pNode[j+1].jnFlags & JNODE_REMOVE)==0 || pParse->useMod==0 ){
jsonRenderNodeAsBlob(pParse, &pNode[j], pOut); jsonXlateNodeToBlob(pParse, &pNode[j], pOut);
jsonRenderNodeAsBlob(pParse, &pNode[j+1], pOut); jsonXlateNodeToBlob(pParse, &pNode[j+1], pOut);
} }
j += 1 + jsonNodeSize(&pNode[j+1]); j += 1 + jsonNodeSize(&pNode[j+1]);
} }
@@ -3850,7 +3853,7 @@ static void jsonReturnTextJsonFromBlob(
x.aBlob = (u8*)aBlob; x.aBlob = (u8*)aBlob;
x.nBlob = nBlob; x.nBlob = nBlob;
jsonStringInit(&s, ctx); jsonStringInit(&s, ctx);
jsonRenderBlob(&x, 0, &s); jsonXlateBlobToText(&x, 0, &s);
jsonReturnString(&s); jsonReturnString(&s);
} }
@@ -4431,13 +4434,13 @@ static void jsonExtractFunc(
if( flags & JSON_JSON ){ if( flags & JSON_JSON ){
jsonReturnNodeAsJson(p, pNode, ctx, 0); jsonReturnNodeAsJson(p, pNode, ctx, 0);
}else{ }else{
jsonReturnNodeAsSql(p, pNode, ctx); jsonReturnFromNode(p, pNode, ctx);
sqlite3_result_subtype(ctx, 0); sqlite3_result_subtype(ctx, 0);
} }
} }
}else{ }else{
pNode = jsonLookup(p, zPath, 0, ctx); pNode = jsonLookup(p, zPath, 0, ctx);
if( p->nErr==0 && pNode ) jsonReturnNodeAsSql(p, pNode, ctx); if( p->nErr==0 && pNode ) jsonReturnFromNode(p, pNode, ctx);
} }
}else{ }else{
/* Two or more PATH arguments results in a JSON array with each /* Two or more PATH arguments results in a JSON array with each
@@ -4451,7 +4454,7 @@ static void jsonExtractFunc(
if( p->nErr ) break; if( p->nErr ) break;
jsonAppendSeparator(&jx); jsonAppendSeparator(&jx);
if( pNode ){ if( pNode ){
jsonRenderNodeAsText(p, pNode, &jx); jsonXlateNodeToText(p, pNode, &jx);
}else{ }else{
jsonAppendRawNZ(&jx, "null", 4); jsonAppendRawNZ(&jx, "null", 4);
} }
@@ -5379,7 +5382,7 @@ static int jsonEachColumn(
case JEACH_KEY: { case JEACH_KEY: {
if( p->i==0 ) break; if( p->i==0 ) break;
if( p->eType==JSON_OBJECT ){ if( p->eType==JSON_OBJECT ){
jsonReturnNodeAsSql(&p->sParse, pThis, ctx); jsonReturnFromNode(&p->sParse, pThis, ctx);
}else if( p->eType==JSON_ARRAY ){ }else if( p->eType==JSON_ARRAY ){
u32 iKey; u32 iKey;
if( p->bRecursive ){ if( p->bRecursive ){
@@ -5395,7 +5398,7 @@ static int jsonEachColumn(
} }
case JEACH_VALUE: { case JEACH_VALUE: {
if( pThis->jnFlags & JNODE_LABEL ) pThis++; if( pThis->jnFlags & JNODE_LABEL ) pThis++;
jsonReturnNodeAsSql(&p->sParse, pThis, ctx); jsonReturnFromNode(&p->sParse, pThis, ctx);
break; break;
} }
case JEACH_TYPE: { case JEACH_TYPE: {
@@ -5406,7 +5409,7 @@ static int jsonEachColumn(
case JEACH_ATOM: { case JEACH_ATOM: {
if( pThis->jnFlags & JNODE_LABEL ) pThis++; if( pThis->jnFlags & JNODE_LABEL ) pThis++;
if( pThis->eType>=JSON_ARRAY ) break; if( pThis->eType>=JSON_ARRAY ) break;
jsonReturnNodeAsSql(&p->sParse, pThis, ctx); jsonReturnFromNode(&p->sParse, pThis, ctx);
break; break;
} }
case JEACH_ID: { case JEACH_ID: {