diff options
author | drh <> | 2023-11-15 20:32:06 +0000 |
---|---|---|
committer | drh <> | 2023-11-15 20:32:06 +0000 |
commit | 11e8242e2eec9172d2c47157900638f568813736 (patch) | |
tree | f74f0717e37544bca065e5c4ea3ca0d107d95336 /src/json.c | |
parent | 5e3ae1ec765fb7b5eb00854e64fbc84090636a9b (diff) | |
download | sqlite-11e8242e2eec9172d2c47157900638f568813736.tar.gz sqlite-11e8242e2eec9172d2c47157900638f568813736.zip |
Both json_remove() jsonb_remove() work on pure JSONB as long as the input
is JSONB.
FossilOrigin-Name: 68d551730be0a3ea9579646ed4836c73554c83ca7f2303b69a18843f1750f1a7
Diffstat (limited to 'src/json.c')
-rw-r--r-- | src/json.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/json.c b/src/json.c index fa7913d94..89109e003 100644 --- a/src/json.c +++ b/src/json.c @@ -4265,7 +4265,9 @@ static void jsonRemoveFromBlob( int i; u32 rc; const char *zPath = 0; + int flgs; JsonParse px; + memset(&px, 0, sizeof(px)); px.nBlob = sqlite3_value_bytes(argv[0]); px.aBlob = (u8*)sqlite3_value_blob(argv[0]); @@ -4283,8 +4285,17 @@ static void jsonRemoveFromBlob( if( rc==JSON_BLOB_NOTFOUND ) continue; if( JSON_BLOB_ISERROR(rc) ) goto jsonRemoveFromBlob_patherror; } - sqlite3_result_blob(ctx, px.aBlob, px.nBlob, - px.nBlobAlloc>0 ? SQLITE_DYNAMIC : SQLITE_TRANSIENT); + flgs = SQLITE_PTR_TO_INT(sqlite3_user_data(ctx)); + if( flgs & JSON_BLOB ){ + sqlite3_result_blob(ctx, px.aBlob, px.nBlob, + px.nBlobAlloc>0 ? SQLITE_DYNAMIC : SQLITE_TRANSIENT); + }else{ + JsonString s; + jsonStringInit(&s, ctx); + jsonXlateBlobToText(&px, 0, &s); + jsonReturnString(&s); + if( px.nBlobAlloc ) sqlite3_free(px.aBlob); + } return; jsonRemoveFromBlob_patherror: @@ -4834,9 +4845,7 @@ static void jsonRemoveFunc( u32 i; if( argc<1 ) return; - if( jsonFuncArgMightBeBinary(argv[0]) - && (SQLITE_PTR_TO_INT(sqlite3_user_data(ctx))&JSON_BLOB)!=0 - ){ + if( jsonFuncArgMightBeBinary(argv[0]) ){ jsonRemoveFromBlob(ctx, argc, argv); return; } |