mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-11 01:42:22 +03:00
The jsonb_remove() routine now appears to be working.
FossilOrigin-Name: e76d48137ea823b7810dc8c3b70eb21adabdd6cfbac36050c85d1375e94be1de
This commit is contained in:
15
manifest
15
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Work\stoward\sgetting\sjsonb_remove()\sto\swork\sdirectly\son\sJSONB\sblobs.
|
C The\sjsonb_remove()\sroutine\snow\sappears\sto\sbe\sworking.
|
||||||
D 2023-11-15T16:10:31.627
|
D 2023-11-15T18:47:31.537
|
||||||
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
|
||||||
@@ -685,7 +685,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 3ff1ea643cab62e3ddb8be3a64bff2dd94af37ea461ea343054796e7f11638f8
|
F src/json.c a647820e1e82fd516df80328ef3372209006bf99b7008d156411c8cd0d4d9fc4
|
||||||
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
|
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
|
||||||
F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36
|
F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36
|
||||||
F src/main.c 1b89f3de98d1b59fec5bac1d66d6ece21f703821b8eaa0d53d9604c35309f6f9
|
F src/main.c 1b89f3de98d1b59fec5bac1d66d6ece21f703821b8eaa0d53d9604c35309f6f9
|
||||||
@@ -2141,11 +2141,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 ba91408f4c044feda003ef93784ccefb619f99ab64379ced481ee8e9e890fd41
|
P a79ff8e58fcaf718a6fb78e145117f1d6d40d133f31e9752bb9c6d484850a27b
|
||||||
R 58cf82355c33a53c2234fea2c219b8e4
|
R 6ab8908817380ee469413c76bca0c832
|
||||||
T *branch * jsonb-remove
|
|
||||||
T *sym-jsonb-remove *
|
|
||||||
T -sym-jsonb *
|
|
||||||
U drh
|
U drh
|
||||||
Z 367d226fdddcafa052b6fb6b4d87ed0a
|
Z a103fcc805c4c7ff278e886cba60f9d7
|
||||||
# Remove this line to create a well-formed Fossil manifest.
|
# Remove this line to create a well-formed Fossil manifest.
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
a79ff8e58fcaf718a6fb78e145117f1d6d40d133f31e9752bb9c6d484850a27b
|
e76d48137ea823b7810dc8c3b70eb21adabdd6cfbac36050c85d1375e94be1de
|
||||||
55
src/json.c
55
src/json.c
@@ -2465,11 +2465,21 @@ static JsonNode *jsonLookupAppend(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Return the text of a syntax error message on a JSON path. Space is
|
** Compute the text of an error in JSON path syntax.
|
||||||
** obtained from sqlite3_malloc().
|
**
|
||||||
|
** If ctx is not NULL then push the error message into ctx and return NULL.
|
||||||
|
* If ctx is NULL, then return the text of the error message.
|
||||||
*/
|
*/
|
||||||
static char *jsonPathSyntaxError(const char *zErr){
|
static char *jsonPathSyntaxError(const char *zErr, sqlite3_context *ctx){
|
||||||
return sqlite3_mprintf("JSON path error near '%q'", zErr);
|
char *zMsg = sqlite3_mprintf("JSON path error near '%q'", zErr);
|
||||||
|
if( ctx==0 ) return zMsg;
|
||||||
|
if( zMsg==0 ){
|
||||||
|
sqlite3_result_error_nomem(ctx);
|
||||||
|
}else{
|
||||||
|
sqlite3_result_error(ctx, zMsg, -1);
|
||||||
|
sqlite3_free(zMsg);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -2490,7 +2500,6 @@ static JsonNode *jsonLookup(
|
|||||||
){
|
){
|
||||||
const char *zErr = 0;
|
const char *zErr = 0;
|
||||||
JsonNode *pNode = 0;
|
JsonNode *pNode = 0;
|
||||||
char *zMsg;
|
|
||||||
|
|
||||||
if( zPath==0 ) return 0;
|
if( zPath==0 ) return 0;
|
||||||
if( zPath[0]!='$' ){
|
if( zPath[0]!='$' ){
|
||||||
@@ -2504,13 +2513,7 @@ static JsonNode *jsonLookup(
|
|||||||
lookup_err:
|
lookup_err:
|
||||||
pParse->nErr++;
|
pParse->nErr++;
|
||||||
assert( zErr!=0 && pCtx!=0 );
|
assert( zErr!=0 && pCtx!=0 );
|
||||||
zMsg = jsonPathSyntaxError(zErr);
|
jsonPathSyntaxError(zErr, pCtx);
|
||||||
if( zMsg ){
|
|
||||||
sqlite3_result_error(pCtx, zMsg, -1);
|
|
||||||
sqlite3_free(zMsg);
|
|
||||||
}else{
|
|
||||||
sqlite3_result_error_nomem(pCtx);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3814,11 +3817,15 @@ static u32 jsonbArrayCount(JsonParse *pParse, u32 iRoot){
|
|||||||
*/
|
*/
|
||||||
static void jsonAfterEditSizeAdjust(JsonParse *pParse, u32 iRoot){
|
static void jsonAfterEditSizeAdjust(JsonParse *pParse, u32 iRoot){
|
||||||
u32 sz = 0;
|
u32 sz = 0;
|
||||||
|
u32 nBlob;
|
||||||
assert( pParse->delta!=0 );
|
assert( pParse->delta!=0 );
|
||||||
|
assert( pParse->nBlobAlloc >= pParse->nBlob );
|
||||||
|
nBlob = pParse->nBlob;
|
||||||
|
pParse->nBlob = pParse->nBlobAlloc;
|
||||||
(void)jsonbPayloadSize(pParse, iRoot, &sz);
|
(void)jsonbPayloadSize(pParse, iRoot, &sz);
|
||||||
|
pParse->nBlob = nBlob;
|
||||||
sz += pParse->delta;
|
sz += pParse->delta;
|
||||||
jsonBlobChangePayloadSize(pParse, iRoot, sz);
|
jsonBlobChangePayloadSize(pParse, iRoot, sz);
|
||||||
pParse->nBlob += pParse->delta;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -3857,6 +3864,7 @@ static u32 jsonLookupBlobStep(
|
|||||||
memmove(&pParse->aBlob[iRoot], &pParse->aBlob[iRoot+sz],
|
memmove(&pParse->aBlob[iRoot], &pParse->aBlob[iRoot+sz],
|
||||||
pParse->nBlob - (iRoot+sz));
|
pParse->nBlob - (iRoot+sz));
|
||||||
pParse->delta = -(int)sz;
|
pParse->delta = -(int)sz;
|
||||||
|
pParse->nBlob -= sz;
|
||||||
}else if( pParse->eEdit==JEDIT_INS ){
|
}else if( pParse->eEdit==JEDIT_INS ){
|
||||||
/* Already exists, so json_insert() is a no-op */
|
/* Already exists, so json_insert() is a no-op */
|
||||||
}else{
|
}else{
|
||||||
@@ -3871,6 +3879,7 @@ static u32 jsonLookupBlobStep(
|
|||||||
memmove(&pParse->aBlob[iRoot+pParse->nIns],
|
memmove(&pParse->aBlob[iRoot+pParse->nIns],
|
||||||
&pParse->aBlob[iRoot+sz],
|
&pParse->aBlob[iRoot+sz],
|
||||||
pParse->nBlob - iRoot - sz);
|
pParse->nBlob - iRoot - sz);
|
||||||
|
pParse->nBlob += d;
|
||||||
}
|
}
|
||||||
memcpy(&pParse->aBlob[iRoot], pParse->aIns, pParse->nIns);
|
memcpy(&pParse->aBlob[iRoot], pParse->aIns, pParse->nIns);
|
||||||
}
|
}
|
||||||
@@ -3981,6 +3990,7 @@ static u32 jsonLookupBlobStep(
|
|||||||
pParse->nBlob - j);
|
pParse->nBlob - j);
|
||||||
memcpy(&pParse->aBlob[j], pParse->aIns, pParse->nIns);
|
memcpy(&pParse->aBlob[j], pParse->aIns, pParse->nIns);
|
||||||
pParse->delta = pParse->nIns;
|
pParse->delta = pParse->nIns;
|
||||||
|
pParse->nBlob += pParse->nIns;
|
||||||
jsonAfterEditSizeAdjust(pParse, iRoot);
|
jsonAfterEditSizeAdjust(pParse, iRoot);
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
@@ -4254,6 +4264,7 @@ static void jsonRemoveFromBlob(
|
|||||||
){
|
){
|
||||||
int i;
|
int i;
|
||||||
u32 rc;
|
u32 rc;
|
||||||
|
const char *zPath = 0;
|
||||||
JsonParse px;
|
JsonParse px;
|
||||||
memset(&px, 0, sizeof(px));
|
memset(&px, 0, sizeof(px));
|
||||||
px.nBlob = sqlite3_value_bytes(argv[0]);
|
px.nBlob = sqlite3_value_bytes(argv[0]);
|
||||||
@@ -4261,21 +4272,25 @@ static void jsonRemoveFromBlob(
|
|||||||
if( px.aBlob==0 ) return;
|
if( px.aBlob==0 ) return;
|
||||||
for(i=1; i<argc; i++){
|
for(i=1; i<argc; i++){
|
||||||
const char *zPath = (const char*)sqlite3_value_text(argv[i]);
|
const char *zPath = (const char*)sqlite3_value_text(argv[i]);
|
||||||
if( zPath==0 ) goto jsonRemoveFromBlob_error;
|
if( zPath==0 ) goto jsonRemoveFromBlob_patherror;
|
||||||
if( zPath[0]!='$' ) goto jsonRemoveFromBlob_error;
|
if( zPath[0]!='$' ) goto jsonRemoveFromBlob_patherror;
|
||||||
|
if( zPath[1]==0 ){
|
||||||
|
if( px.nBlobAlloc ) sqlite3_free(px.aBlob);
|
||||||
|
return; /* return NULL if $ is removed */
|
||||||
|
}
|
||||||
px.eEdit = JEDIT_DEL;
|
px.eEdit = JEDIT_DEL;
|
||||||
rc = jsonLookupBlobStep(&px, 0, zPath+1, 0);
|
rc = jsonLookupBlobStep(&px, 0, zPath+1, 0);
|
||||||
if( rc==JSON_BLOB_NOTFOUND ) continue;
|
if( rc==JSON_BLOB_NOTFOUND ) continue;
|
||||||
if( JSON_BLOB_ISERROR(rc) ) goto jsonRemoveFromBlob_error;
|
if( JSON_BLOB_ISERROR(rc) ) goto jsonRemoveFromBlob_patherror;
|
||||||
}
|
}
|
||||||
sqlite3_result_blob(ctx, px.aBlob, px.nBlob,
|
sqlite3_result_blob(ctx, px.aBlob, px.nBlob,
|
||||||
px.nBlobAlloc>0 ? sqlite3_free : SQLITE_DYNAMIC);
|
px.nBlobAlloc>0 ? SQLITE_DYNAMIC : SQLITE_TRANSIENT);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
jsonRemoveFromBlob_error:
|
jsonRemoveFromBlob_patherror:
|
||||||
if( px.nBlobAlloc ) sqlite3_free(px.aBlob);
|
if( px.nBlobAlloc ) sqlite3_free(px.aBlob);
|
||||||
|
jsonPathSyntaxError(zPath, ctx);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -5814,7 +5829,7 @@ static int jsonEachFilter(
|
|||||||
}
|
}
|
||||||
if( zErr ){
|
if( zErr ){
|
||||||
sqlite3_free(cur->pVtab->zErrMsg);
|
sqlite3_free(cur->pVtab->zErrMsg);
|
||||||
cur->pVtab->zErrMsg = jsonPathSyntaxError(zErr);
|
cur->pVtab->zErrMsg = jsonPathSyntaxError(zErr, 0);
|
||||||
jsonEachCursorReset(p);
|
jsonEachCursorReset(p);
|
||||||
return cur->pVtab->zErrMsg ? SQLITE_ERROR : SQLITE_NOMEM;
|
return cur->pVtab->zErrMsg ? SQLITE_ERROR : SQLITE_NOMEM;
|
||||||
}else if( pNode==0 ){
|
}else if( pNode==0 ){
|
||||||
|
|||||||
Reference in New Issue
Block a user