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

Gather forward references into a single place for the JSON code. Allow

JSONB arguments to json_array() and json_object() and similar.

FossilOrigin-Name: c352201b8c299c330d9abbff6dbcbcbcf00ada53183d3cd91020ec772e066357
This commit is contained in:
drh
2023-10-02 12:40:04 +00:00
parent 9b176f863b
commit 5624b0b4cd
4 changed files with 59 additions and 31 deletions

View 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