mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-09 14:21:03 +03:00
Finish adding jsonb_ versions for all JSON routines that return JSON text.
FossilOrigin-Name: 6daa7b69695e1b68dba317abbcad4d0205c91963d4a9eb2d595a3ec10fa0fdf4
This commit is contained in:
12
manifest
12
manifest
@@ -1,5 +1,5 @@
|
||||
C Update\sjson_each()\sand\sjson_tree()\sso\sthat\sthey\swork\swith\sJSONB\sinputs.
|
||||
D 2023-09-29T22:37:18.176
|
||||
C Finish\sadding\sjsonb_\sversions\sfor\sall\sJSON\sroutines\sthat\sreturn\sJSON\stext.
|
||||
D 2023-09-30T14:34:39.518
|
||||
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 50fb4f1c25eb749e0186fe68f095325d40ebe59aa3a53063f00f382cfd2c36fd
|
||||
F src/json.c d4de26b1c8a18949b80a89d457c4714a00cc65c8b32b965a5f921556daeb48f8
|
||||
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
|
||||
F src/loadext.c 98cfba10989b3da6f1807ad42444017742db7f100a54f1032af7a8b1295912c0
|
||||
F src/main.c 618aeb399e993cf561864f4b0cf6a331ee4f355cf663635f8d9da3193a46aa40
|
||||
@@ -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 96f545f6f839dab4829861361ee3d7a56840217c5f954f334616e77d23c5fe29
|
||||
R 9027bab5f11df4bc07814add94e083b5
|
||||
P bb5e50ff56dff95d954aacdd4c5461790f953cef8d7b89da000d8d587fcdf9b8
|
||||
R 29e50b8d59965f3c05293a631078e5bd
|
||||
U drh
|
||||
Z d0258d856fbcf0571a1fd4c95a27f4d8
|
||||
Z bae80fe0062bce2a09237dc9749d4f41
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
||||
@@ -1 +1 @@
|
||||
bb5e50ff56dff95d954aacdd4c5461790f953cef8d7b89da000d8d587fcdf9b8
|
||||
6daa7b69695e1b68dba317abbcad4d0205c91963d4a9eb2d595a3ec10fa0fdf4
|
||||
45
src/json.c
45
src/json.c
@@ -724,6 +724,8 @@ 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.
|
||||
@@ -732,7 +734,10 @@ static void jsonAppendSqlValue(
|
||||
*/
|
||||
static void jsonReturnString(JsonString *p){
|
||||
if( p->bErr==0 ){
|
||||
if( p->bStatic ){
|
||||
int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(p->pCtx));
|
||||
if( flags & JSON_BLOB ){
|
||||
jsonReturnStringAsBlob(p);
|
||||
}else if( p->bStatic ){
|
||||
sqlite3_result_text64(p->pCtx, p->zBuf, p->nUsed,
|
||||
SQLITE_TRANSIENT, SQLITE_UTF8);
|
||||
}else if( jsonForceRCStr(p) ){
|
||||
@@ -3145,6 +3150,25 @@ static int jsonConvertTextToBlob(
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** The input string pStr is a well-formed JSON text string. Convert
|
||||
** this into the JSONB format and make it the return value of the
|
||||
** SQL function.
|
||||
*/
|
||||
static void jsonReturnStringAsBlob(JsonString *pStr){
|
||||
JsonParse px;
|
||||
memset(&px, 0, sizeof(px));
|
||||
px.zJson = pStr->zBuf;
|
||||
px.nJson = pStr->nUsed;
|
||||
(void)jsonTranslateTextValueToBlob(&px, 0);
|
||||
if( px.oom ){
|
||||
sqlite3_free(px.aBlob);
|
||||
sqlite3_result_error_nomem(pStr->pCtx);
|
||||
}else{
|
||||
sqlite3_result_blob(pStr->pCtx, px.aBlob, px.nBlob, sqlite3_free);
|
||||
}
|
||||
}
|
||||
|
||||
/* The byte at index i is a node type-code. This routine
|
||||
** determines the payload size for that node and writes that
|
||||
** payload size in to *pSz. It returns the offset from i to the
|
||||
@@ -4860,11 +4884,16 @@ static void jsonArrayCompute(sqlite3_context *ctx, int isFinal){
|
||||
JsonString *pStr;
|
||||
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->bErr ){
|
||||
if( pStr->bErr==1 ) sqlite3_result_error_nomem(ctx);
|
||||
assert( pStr->bStatic );
|
||||
}else if( flags & JSON_BLOB ){
|
||||
jsonReturnStringAsBlob(pStr);
|
||||
return;
|
||||
}else if( isFinal ){
|
||||
sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed,
|
||||
pStr->bStatic ? SQLITE_TRANSIENT :
|
||||
@@ -4970,10 +4999,16 @@ static void jsonObjectCompute(sqlite3_context *ctx, int isFinal){
|
||||
JsonString *pStr;
|
||||
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->bErr ){
|
||||
if( pStr->bErr==1 ) sqlite3_result_error_nomem(ctx);
|
||||
assert( pStr->bStatic );
|
||||
}else if( flags & JSON_BLOB ){
|
||||
jsonReturnStringAsBlob(pStr);
|
||||
return;
|
||||
}else if( isFinal ){
|
||||
sqlite3_result_text(ctx, pStr->zBuf, (int)pStr->nUsed,
|
||||
pStr->bStatic ? SQLITE_TRANSIENT :
|
||||
@@ -5557,6 +5592,7 @@ void sqlite3RegisterJsonFunctions(void){
|
||||
JFUNCTION(json, 1, 0, jsonRemoveFunc),
|
||||
JFUNCTION(jsonb, 1, JSON_BLOB, jsonbFunc),
|
||||
JFUNCTION(json_array, -1, 0, jsonArrayFunc),
|
||||
JFUNCTION(jsonb_array, -1, JSON_BLOB, jsonArrayFunc),
|
||||
JFUNCTION(json_array_length, 1, 0, jsonArrayLengthFunc),
|
||||
JFUNCTION(json_array_length, 2, 0, jsonArrayLengthFunc),
|
||||
JFUNCTION(json_error_position,1, 0, jsonErrorFunc),
|
||||
@@ -5567,6 +5603,7 @@ void sqlite3RegisterJsonFunctions(void){
|
||||
JFUNCTION(json_insert, -1, 0, jsonSetFunc),
|
||||
JFUNCTION(jsonb_insert, -1, JSON_BLOB, jsonSetFunc),
|
||||
JFUNCTION(json_object, -1, 0, jsonObjectFunc),
|
||||
JFUNCTION(jsonb_object, -1, JSON_BLOB, jsonObjectFunc),
|
||||
JFUNCTION(json_patch, 2, 0, jsonPatchFunc),
|
||||
JFUNCTION(jsonb_patch, 2, JSON_BLOB, jsonPatchFunc),
|
||||
JFUNCTION(json_quote, 1, 0, jsonQuoteFunc),
|
||||
@@ -5587,7 +5624,13 @@ void sqlite3RegisterJsonFunctions(void){
|
||||
WAGGREGATE(json_group_array, 1, 0, 0,
|
||||
jsonArrayStep, jsonArrayFinal, jsonArrayValue, jsonGroupInverse,
|
||||
SQLITE_SUBTYPE|SQLITE_UTF8|SQLITE_DETERMINISTIC),
|
||||
WAGGREGATE(jsonb_group_array, 1, JSON_BLOB, 0,
|
||||
jsonArrayStep, jsonArrayFinal, jsonArrayValue, jsonGroupInverse,
|
||||
SQLITE_SUBTYPE|SQLITE_UTF8|SQLITE_DETERMINISTIC),
|
||||
WAGGREGATE(json_group_object, 2, 0, 0,
|
||||
jsonObjectStep, jsonObjectFinal, jsonObjectValue, jsonGroupInverse,
|
||||
SQLITE_SUBTYPE|SQLITE_UTF8|SQLITE_DETERMINISTIC),
|
||||
WAGGREGATE(jsonb_group_object,2, JSON_BLOB, 0,
|
||||
jsonObjectStep, jsonObjectFinal, jsonObjectValue, jsonGroupInverse,
|
||||
SQLITE_SUBTYPE|SQLITE_UTF8|SQLITE_DETERMINISTIC)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user