mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-11 01:42:22 +03:00
Switch to using jsonParseCached() for json_patch().
FossilOrigin-Name: 2ed9c59e6a51037e63485d0a92dae25443116beddfca1ac73d2f5d5be38d4ad3
This commit is contained in:
12
manifest
12
manifest
@@ -1,5 +1,5 @@
|
|||||||
C If\sthe\sinput\sJSON\sto\sa\sjson\sfunction\sthat\suses\scache\scomes\sfrom\san\sRCStr\nvalue,\sthen\suse\sthat\sRCStr\svalue\sin\sthe\sparse\srather\sthan\smaking\sa\scopy.
|
C Switch\sto\susing\sjsonParseCached()\sfor\sjson_patch().
|
||||||
D 2023-07-27T20:28:29.957
|
D 2023-07-27T23:51:36.392
|
||||||
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
|
||||||
@@ -598,7 +598,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 481dffa457276d850836953bbd2a61a00a98f8cf09c64c29c6f05ac02a84affd
|
F src/json.c 60b6b0815ddaf546396e3c7328065a114b581721dc1fa20697a52610fb2259aa
|
||||||
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
|
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
|
||||||
F src/loadext.c 176d6b2cb18a6ad73b133db17f6fc351c4d9a2d510deebdb76c22bde9cfd1465
|
F src/loadext.c 176d6b2cb18a6ad73b133db17f6fc351c4d9a2d510deebdb76c22bde9cfd1465
|
||||||
F src/main.c 512b1d45bc556edf4471a845afb7ba79e64bd5b832ab222dc195c469534cd002
|
F src/main.c 512b1d45bc556edf4471a845afb7ba79e64bd5b832ab222dc195c469534cd002
|
||||||
@@ -2044,8 +2044,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 ab1edcc7fedcf27922d5db4bc1bc673b1495ca9c66eb6debdda7b7776c068888
|
P 509ae9c1470dd79d320e84371e1e6662fb85fa0571df5ed8c4d946d10cdfe821
|
||||||
R bc4f27407c20176b7c3faf6538598e39
|
R a667d9301618252314cdf4d506cbebf3
|
||||||
U drh
|
U drh
|
||||||
Z 559a7376c279a69632a349e06eee6ec2
|
Z 152f86b69395ef2af8d236118a3bf25d
|
||||||
# Remove this line to create a well-formed Fossil manifest.
|
# Remove this line to create a well-formed Fossil manifest.
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
509ae9c1470dd79d320e84371e1e6662fb85fa0571df5ed8c4d946d10cdfe821
|
2ed9c59e6a51037e63485d0a92dae25443116beddfca1ac73d2f5d5be38d4ad3
|
||||||
73
src/json.c
73
src/json.c
@@ -1751,26 +1751,15 @@ json_parse_restart:
|
|||||||
** are any errors. If an error occurs, free all memory held by pParse,
|
** are any errors. If an error occurs, free all memory held by pParse,
|
||||||
** but not pParse itself.
|
** but not pParse itself.
|
||||||
**
|
**
|
||||||
** pParse is uninitialized when this routine is called.
|
** pParse must be initialized to an empty parse object prior to calling
|
||||||
**
|
** this routine.
|
||||||
** pParse->nJPRef set to 1. The caller becomes the owner of the
|
|
||||||
** the JsonParse object.
|
|
||||||
**
|
|
||||||
** pParse->bOwnsJson is set to bTakeJson. If bTakeJson is 1, the newly
|
|
||||||
** initialized JsonParse object will become the owner of the zJson input
|
|
||||||
** string. If bTakeJson is 0, then the caller is responsible for
|
|
||||||
** preserving zJson for the lifetime of the JsonParse object.
|
|
||||||
*/
|
*/
|
||||||
static int jsonParse(
|
static int jsonParse(
|
||||||
JsonParse *pParse, /* Initialize and fill this JsonParse object */
|
JsonParse *pParse, /* Initialize and fill this JsonParse object */
|
||||||
sqlite3_context *pCtx, /* Report errors here */
|
sqlite3_context *pCtx /* Report errors here */
|
||||||
char *zJson /* Input JSON text to be parsed */
|
|
||||||
){
|
){
|
||||||
int i;
|
int i;
|
||||||
memset(pParse, 0, sizeof(*pParse));
|
const char *zJson = pParse->zJson;
|
||||||
if( zJson==0 ) return 1;
|
|
||||||
pParse->zJson = zJson;
|
|
||||||
pParse->nJPRef = 1;
|
|
||||||
i = jsonParseValue(pParse, 0);
|
i = jsonParseValue(pParse, 0);
|
||||||
if( pParse->oom ) i = -1;
|
if( pParse->oom ) i = -1;
|
||||||
if( i>0 ){
|
if( i>0 ){
|
||||||
@@ -1891,7 +1880,6 @@ static JsonParse *jsonParseCached(
|
|||||||
u32 iMinHold = 0xffffffff;
|
u32 iMinHold = 0xffffffff;
|
||||||
u32 iMaxHold = 0;
|
u32 iMaxHold = 0;
|
||||||
int bJsonRCStr;
|
int bJsonRCStr;
|
||||||
int rc;
|
|
||||||
|
|
||||||
if( zJson==0 ) return 0;
|
if( zJson==0 ) return 0;
|
||||||
for(iKey=0; iKey<JSON_CACHE_SZ; iKey++){
|
for(iKey=0; iKey<JSON_CACHE_SZ; iKey++){
|
||||||
@@ -1947,13 +1935,13 @@ static JsonParse *jsonParseCached(
|
|||||||
memset(p, 0, sizeof(*p));
|
memset(p, 0, sizeof(*p));
|
||||||
if( bJsonRCStr ){
|
if( bJsonRCStr ){
|
||||||
p->zJson = sqlite3RCStrRef(zJson);
|
p->zJson = sqlite3RCStrRef(zJson);
|
||||||
|
p->bJsonIsRCStr = 1;
|
||||||
}else{
|
}else{
|
||||||
p->zJson = (char*)&p[1];
|
p->zJson = (char*)&p[1];
|
||||||
memcpy(p->zJson, zJson, nJson+1);
|
memcpy(p->zJson, zJson, nJson+1);
|
||||||
}
|
}
|
||||||
rc = jsonParse(p, pErrCtx, p->zJson);
|
p->nJPRef = 1;
|
||||||
p->bJsonIsRCStr = bJsonRCStr;
|
if( jsonParse(p, pErrCtx) ){
|
||||||
if( rc ){
|
|
||||||
if( pErrCtx==0 ){
|
if( pErrCtx==0 ){
|
||||||
p->nErr = 1;
|
p->nErr = 1;
|
||||||
assert( p->nJPRef==1 ); /* Caller will own the new JsonParse object p */
|
assert( p->nJPRef==1 ); /* Caller will own the new JsonParse object p */
|
||||||
@@ -2677,29 +2665,27 @@ static void jsonPatchFunc(
|
|||||||
int argc,
|
int argc,
|
||||||
sqlite3_value **argv
|
sqlite3_value **argv
|
||||||
){
|
){
|
||||||
JsonParse x; /* The JSON that is being patched */
|
JsonParse *pX; /* The JSON that is being patched */
|
||||||
JsonParse y; /* The patch */
|
JsonParse *pY; /* The patch */
|
||||||
JsonNode *pResult; /* The result of the merge */
|
JsonNode *pResult; /* The result of the merge */
|
||||||
|
|
||||||
UNUSED_PARAMETER(argc);
|
UNUSED_PARAMETER(argc);
|
||||||
if( jsonParse(&x, ctx, (char*)sqlite3_value_text(argv[0])) ) return;
|
pX = jsonParseCached(ctx, argv[0], ctx, 1);
|
||||||
if( jsonParse(&y, ctx, (char*)sqlite3_value_text(argv[1])) ){
|
if( pX==0 ) return;
|
||||||
jsonParseReset(&x);
|
pY = jsonParseCached(ctx, argv[1], ctx, 1);
|
||||||
return;
|
if( pY==0 ) return;
|
||||||
}
|
pX->useMod = 1;
|
||||||
x.useMod = 1;
|
pX->hasMod = 1;
|
||||||
y.useMod = 1;
|
pY->useMod = 1;
|
||||||
pResult = jsonMergePatch(&x, 0, y.aNode);
|
pResult = jsonMergePatch(pX, 0, pY->aNode);
|
||||||
assert( pResult!=0 || x.oom );
|
assert( pResult!=0 || pX->oom );
|
||||||
if( pResult && x.oom==0 ){
|
if( pResult && pX->oom==0 ){
|
||||||
jsonDebugPrintParse(&x);
|
jsonDebugPrintParse(pX);
|
||||||
jsonDebugPrintNode(pResult);
|
jsonDebugPrintNode(pResult);
|
||||||
jsonReturnJson(&x, pResult, ctx, 0);
|
jsonReturnJson(pX, pResult, ctx, 0);
|
||||||
}else{
|
}else{
|
||||||
sqlite3_result_error_nomem(ctx);
|
sqlite3_result_error_nomem(ctx);
|
||||||
}
|
}
|
||||||
jsonParseReset(&x);
|
|
||||||
jsonParseReset(&y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -3326,7 +3312,6 @@ static int jsonEachOpenTree(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
|
|||||||
/* Reset a JsonEachCursor back to its original state. Free any memory
|
/* Reset a JsonEachCursor back to its original state. Free any memory
|
||||||
** held. */
|
** held. */
|
||||||
static void jsonEachCursorReset(JsonEachCursor *p){
|
static void jsonEachCursorReset(JsonEachCursor *p){
|
||||||
sqlite3_free(p->zJson);
|
|
||||||
sqlite3_free(p->zRoot);
|
sqlite3_free(p->zRoot);
|
||||||
jsonParseReset(&p->sParse);
|
jsonParseReset(&p->sParse);
|
||||||
p->iRowid = 0;
|
p->iRowid = 0;
|
||||||
@@ -3646,11 +3631,19 @@ static int jsonEachFilter(
|
|||||||
if( idxNum==0 ) return SQLITE_OK;
|
if( idxNum==0 ) return SQLITE_OK;
|
||||||
z = (const char*)sqlite3_value_text(argv[0]);
|
z = (const char*)sqlite3_value_text(argv[0]);
|
||||||
if( z==0 ) return SQLITE_OK;
|
if( z==0 ) return SQLITE_OK;
|
||||||
|
memset(&p->sParse, 0, sizeof(p->sParse));
|
||||||
|
p->sParse.nJPRef = 1;
|
||||||
|
if( sqlite3ValueIsOfClass(argv[0], (void(*)(void*))sqlite3RCStrUnref) ){
|
||||||
|
p->sParse.zJson = sqlite3RCStrRef((char*)z);
|
||||||
|
}else{
|
||||||
n = sqlite3_value_bytes(argv[0]);
|
n = sqlite3_value_bytes(argv[0]);
|
||||||
p->zJson = sqlite3_malloc64( n+1 );
|
p->sParse.zJson = sqlite3RCStrNew( n+1 );
|
||||||
if( p->zJson==0 ) return SQLITE_NOMEM;
|
if( p->sParse.zJson==0 ) return SQLITE_NOMEM;
|
||||||
memcpy(p->zJson, z, (size_t)n+1);
|
memcpy(p->sParse.zJson, z, (size_t)n+1);
|
||||||
if( jsonParse(&p->sParse, 0, p->zJson) ){
|
}
|
||||||
|
p->sParse.bJsonIsRCStr = 1;
|
||||||
|
p->zJson = p->sParse.zJson;
|
||||||
|
if( jsonParse(&p->sParse, 0) ){
|
||||||
int rc = SQLITE_NOMEM;
|
int rc = SQLITE_NOMEM;
|
||||||
if( p->sParse.oom==0 ){
|
if( p->sParse.oom==0 ){
|
||||||
sqlite3_free(cur->pVtab->zErrMsg);
|
sqlite3_free(cur->pVtab->zErrMsg);
|
||||||
|
|||||||
Reference in New Issue
Block a user