]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add the JsonParse.zAlt field to old revised JSON text after a change.
authordrh <>
Wed, 26 Jul 2023 00:48:45 +0000 (00:48 +0000)
committerdrh <>
Wed, 26 Jul 2023 00:48:45 +0000 (00:48 +0000)
Demonstrate that this elminates the need for reparsing after a change
by using it in the json_remove() function.  This is an incremental check-in
containing lots of cruft.

FossilOrigin-Name: f930b139d6db0ee799bc90397b225175103c4bf22923d1c9cbcd32509adc1738

manifest
manifest.uuid
src/json.c
src/printf.c
src/sqliteInt.h
src/vdbemem.c

index 437038d38017c13bf721d9994e23b7a7bf7700ff..875c31732870682811abf7d1da3b69465c23c574 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Clarify\sownership\sof\sthe\svarious\sobjects\sinvolved\sin\sparsing\sJSON.
-D 2023-07-25T20:26:47.054
+C Add\sthe\sJsonParse.zAlt\sfield\sto\sold\srevised\sJSON\stext\safter\sa\schange.\nDemonstrate\sthat\sthis\selminates\sthe\sneed\sfor\sreparsing\safter\sa\schange\nby\susing\sit\sin\sthe\sjson_remove()\sfunction.\s\sThis\sis\san\sincremental\scheck-in\ncontaining\slots\sof\scruft.
+D 2023-07-26T00:48:45.768
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -598,7 +598,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 97f8c20c1cfefbc54e2b8b2143a24aae4993c12de6e74764af443e033b01b013
+F src/json.c a7823b0593eac42a608f8439e6b1f28022ac5fce9aa81a82856e48dd07ab601d
 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
 F src/loadext.c 176d6b2cb18a6ad73b133db17f6fc351c4d9a2d510deebdb76c22bde9cfd1465
 F src/main.c 512b1d45bc556edf4471a845afb7ba79e64bd5b832ab222dc195c469534cd002
@@ -634,7 +634,7 @@ F src/pcache1.c 602acb23c471bb8d557a6f0083cc2be641d6cafcafa19e481eba7ef4c9ca0f00
 F src/pragma.c 37b8fb02d090262280c86e1e2654bf59d8dbfbfe8dc6733f2b968a11374c095a
 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7
 F src/prepare.c d6c4354f8ea0dc06962fbabc4b68c4471a45276a2918c929be00f9f537f69eb1
-F src/printf.c 1406ade1451adfa4374d8e9bbb8606109742c1216f5dbc95e011bf721fd91365
+F src/printf.c 56e362bbefbe61b5b211f1886e3cdb9b25d8ba817c12df3a15f11b9bdc152efd
 F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
 F src/resolve.c 37953a5f36c60bea413c3c04efcd433b6177009f508ef2ace0494728912fe2e9
 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
@@ -643,7 +643,7 @@ F src/shell.c.in d320d8a13636de06d777cc1eab981caca304e175464e98183cf4ea68d93db81
 F src/sqlite.h.in f999ef3642f381d69679b2516b430dbcb6c5a2a951b7f5e43dc4751b474a5774
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h da473ce2b3d0ae407a6300c4a164589b9a6bfdbec9462688a8593ff16f3bb6e4
-F src/sqliteInt.h 59b755dec944aa3b068e962ef53264de6fde3d6b6df2d5869ea3afdb7facdf60
+F src/sqliteInt.h 29c8e6d0b6dfa9c2c356f23ab8349d7fac3679d5f7cfc01d4ee45c9171db2960
 F src/sqliteLimit.h 33b1c9baba578d34efe7dfdb43193b366111cdf41476b1e82699e14c11ee1fb6
 F src/status.c 160c445d7d28c984a0eae38c144f6419311ed3eace59b44ac6dafc20db4af749
 F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1
@@ -714,7 +714,7 @@ F src/vdbeInt.h 401813862f9d75af01bdb2ab99253ad019e9d6ddcc8058e4fa61a43e9a60d1f7
 F src/vdbeapi.c dde6c4d0f87486f056b9db4d1ea185bb1d84a6839102b86e76316ba590d07cc7
 F src/vdbeaux.c b5e3f7e158518b4eca6f166ac43900640a3fe9735c710e12bfa119af21059339
 F src/vdbeblob.c 2516697b3ee8154eb8915f29466fb5d4f1ae39ee8b755ea909cefaf57ec5e2ce
-F src/vdbemem.c aee9ac636666616494d9a395d29efc3fe9e1404a9f043db81c82560b43b78f35
+F src/vdbemem.c 46ea371b10c3573cf9287d385411fbcc6cd42099ad3505d20e33f2f3ed91537d
 F src/vdbesort.c 0d40dca073c94e158ead752ef4225f4fee22dee84145e8c00ca2309afb489015
 F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823
 F src/vdbevtab.c aae4bd769410eb7e1d02c42613eec961d514459b1c3c1c63cfc84e92a137daac
@@ -2044,8 +2044,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 4cb15d934a85ebc290fe6dd8cd3bd47b159561ca75d72bbffef30b9ea4623b09
-R cbb913300d23d0635674a5fded1ff5ab
+P afe02a398a16d51bd7482b6fbe2fbd15d9ac4fd9cdbc9d2bf81f38b3391fc567
+R 33c717c250039ffbe53dc8d7b2094929
 U drh
-Z f943de02bc9e737c29b8eb0aa52b28c4
+Z 96ad60bdf5cbde0ec2b901493a583f6e
 # Remove this line to create a well-formed Fossil manifest.
index f222cbf32362be688b487a2b41e7abd3d226268d..dce111985027b6a8864d728212885941ef7ad11e 100644 (file)
@@ -1 +1 @@
-afe02a398a16d51bd7482b6fbe2fbd15d9ac4fd9cdbc9d2bf81f38b3391fc567
\ No newline at end of file
+f930b139d6db0ee799bc90397b225175103c4bf22923d1c9cbcd32509adc1738
\ No newline at end of file
index 6cb429f407ec13c1d54c536a2e3bcad60507aded..d7d464442b14a1101b66acaf4c63d678316fcd0d 100644 (file)
@@ -142,7 +142,8 @@ struct JsonParse {
   u32 nNode;         /* Number of slots of aNode[] used */
   u32 nAlloc;        /* Number of slots of aNode[] allocated */
   JsonNode *aNode;   /* Array of nodes containing the parse */
-  char *zJson;       /* Original JSON string */
+  char *zJson;       /* Original JSON string (before edits) */
+  char *zAlt;        /* Revised JSON after edits applied.  Maybe NULL */
   u32 *aUp;          /* Index of parent of each node */
   JsonTask *pClean;  /* Cleanup operations prior to freeing this object */
   u16 iDepth;        /* Nesting depth */
@@ -151,8 +152,10 @@ struct JsonParse {
   u8 hasNonstd;      /* True if input uses non-standard features like JSON5 */
   u8 nJPRef;         /* Number of references to this object */
   u8 bOwnsJson;      /* This object owns zJson and response for freeing it */
-  u8 isMod;          /* aNode contains edits from the original zJson */
+  u8 useMod;         /* Actually use the edits contain inside aNode */
+  u8 hasMod;         /* aNode contains edits from the original zJson */
   int nJson;         /* Length of the zJson string in bytes */
+  int nAlt;          /* Length of alternative JSON string zAlt, in bytes */
   u32 iErr;          /* Error location in zJson[] */
   u32 iSubst;        /* Last known JSON_SUBST node */
   u32 iHold;         /* Replace cache line with the lowest iHold value */
@@ -245,6 +248,16 @@ static int jsonGrow(JsonString *p, u32 N){
   return SQLITE_OK;
 }
 
+/* Try to force the string to be an RCStr string, rather than a
+** static string.  Return true on success.  The only reason this
+** might fail is due to an OOM fault.
+*/
+static int jsonForceRCStr(JsonString *p){
+  if( p->bStatic==0 ) return 1;
+  jsonGrow(p, p->nAlloc+1);
+  return p->bStatic==0;
+}
+
 /* Append N bytes from zIn onto the end of the JsonString string.
 */
 static SQLITE_NOINLINE void jsonAppendExpand(
@@ -588,6 +601,11 @@ static void jsonParseReset(JsonParse *pParse){
     sqlite3_free(pParse->aUp);
     pParse->aUp = 0;
   }
+  if( pParse->zAlt ){
+    char *z = pParse->zAlt;
+    pParse->zAlt = 0;
+    sqlite3RCStrUnref(z);
+  }
   if( pParse->bOwnsJson ){
     /* Order operations so that if the destructor for pParse->zJson
     ** invokes jsonParseFree(), the recursion will terminate harmlessly */
@@ -650,7 +668,7 @@ static void jsonRenderNode(
   JsonString *pOut               /* Write JSON here */
 ){
   assert( pNode!=0 );
-  while( (pNode->jnFlags & JNODE_REPLACE)!=0 ){
+  while( (pNode->jnFlags & JNODE_REPLACE)!=0 && pParse->useMod ){
     u32 idx = (u32)(pNode - pParse->aNode);
     u32 i = pParse->iSubst;
     while( 1 /*exit-by-break*/ ){
@@ -722,13 +740,14 @@ static void jsonRenderNode(
       jsonAppendChar(pOut, '[');
       for(;;){
         while( j<=pNode->n ){
-          if( (pNode[j].jnFlags & JNODE_REMOVE)==0 ){
+          if( (pNode[j].jnFlags & JNODE_REMOVE)==0 || pParse->useMod==0 ){
             jsonAppendSeparator(pOut);
             jsonRenderNode(pParse, &pNode[j], pOut);
           }
           j += jsonNodeSize(&pNode[j]);
         }
         if( (pNode->jnFlags & JNODE_APPEND)==0 ) break;
+        if( pParse->useMod==0 ) break;
         assert( pNode->eU==2 );
         pNode = &pParse->aNode[pNode->u.iAppend];
         j = 1;
@@ -741,7 +760,7 @@ static void jsonRenderNode(
       jsonAppendChar(pOut, '{');
       for(;;){
         while( j<=pNode->n ){
-          if( (pNode[j+1].jnFlags & JNODE_REMOVE)==0 ){
+          if( (pNode[j+1].jnFlags & JNODE_REMOVE)==0 || pParse->useMod==0 ){
             jsonAppendSeparator(pOut);
             jsonRenderNode(pParse, &pNode[j], pOut);
             jsonAppendChar(pOut, ':');
@@ -750,6 +769,7 @@ static void jsonRenderNode(
           j += 1 + jsonNodeSize(&pNode[j+1]);
         }
         if( (pNode->jnFlags & JNODE_APPEND)==0 ) break;
+        if( pParse->useMod==0 ) break;
         assert( pNode->eU==2 );
         pNode = &pParse->aNode[pNode->u.iAppend];
         j = 1;
@@ -766,7 +786,8 @@ static void jsonRenderNode(
 static void jsonReturnJson(
   JsonParse *pParse,          /* The complete JSON */
   JsonNode *pNode,            /* Node to return */
-  sqlite3_context *pCtx       /* Return value for this function */
+  sqlite3_context *pCtx,      /* Return value for this function */
+  int bGenerateAlt            /* Also store the rendered text in zAlt */
 ){
   JsonString s;
   if( pParse->oom ){
@@ -776,6 +797,12 @@ static void jsonReturnJson(
   if( pParse->nErr==0 ){
     jsonInit(&s, pCtx);
     jsonRenderNode(pParse, pNode, &s);
+    if( bGenerateAlt && pParse->zAlt==0 && jsonForceRCStr(&s) ){
+      jsonAppendChar(&s, 0);
+      s.nUsed--;
+      pParse->zAlt = sqlite3RCStrRef(s.zBuf);
+      pParse->nAlt = s.nUsed;
+    }
     jsonResult(&s);
     sqlite3_result_subtype(pCtx, JSON_SUBTYPE);
   }
@@ -965,7 +992,7 @@ static void jsonReturn(
     }
     case JSON_ARRAY:
     case JSON_OBJECT: {
-      jsonReturnJson(pParse, pNode, pCtx);
+      jsonReturnJson(pParse, pNode, pCtx, 0);
       break;
     }
   }
@@ -1079,6 +1106,8 @@ static int jsonParseAddSubstNode(
   pParse->aNode[idx].eU = 4;
   pParse->aNode[idx].u.iPrev = pParse->iSubst;
   pParse->iSubst = idx;
+  pParse->hasMod = 1;
+  pParse->useMod = 1;
   return idx;
 }
 
@@ -1729,6 +1758,7 @@ static int jsonParse(
   int i;
   memset(pParse, 0, sizeof(*pParse));
   if( zJson==0 ) return 1;
+//printf("PARSE %s\n", zJson);
   pParse->zJson = zJson;
   pParse->bOwnsJson = bTakeJson;
   pParse->nJPRef = 1;
@@ -1837,9 +1867,10 @@ static int jsonParseFindParents(JsonParse *pParse){
 **                                       and so the caller must free it.
 */
 static JsonParse *jsonParseCached(
-  sqlite3_context *pCtx,
-  sqlite3_value *pJson,
-  sqlite3_context *pErrCtx
+  sqlite3_context *pCtx,         /* Context to use for cache search */
+  sqlite3_value *pJson,          /* Function param containing JSON text */
+  sqlite3_context *pErrCtx,      /* Write parse errors here if not NULL */
+  int bUnedited                  /* No prior edits allowed */
 ){
   char *zJson = (char*)sqlite3_value_text(pJson);
   int nJson = sqlite3_value_bytes(pJson);
@@ -1859,10 +1890,24 @@ static JsonParse *jsonParseCached(
     }
     if( pMatch==0
      && p->nJson==nJson
+     && (p->hasMod==0 || bUnedited==0)
      && memcmp(p->zJson,zJson,nJson)==0
     ){
       p->nErr = 0;
+      p->useMod = 0;
+      pMatch = p;
+//printf("HIT %s at %d\n", zJson, iKey);
+    }else
+    if( pMatch==0
+     && p->zAlt!=0
+     && bUnedited==0
+     && p->nAlt==nJson
+     && memcmp(p->zAlt, zJson, nJson)==0
+    ){
+      p->nErr = 0;
+      p->useMod = 1;
       pMatch = p;
+//printf("HIT %s at %d-alt\n", zJson, iKey);
     }else if( p->iHold<iMinHold ){
       iMinHold = p->iHold;
       iMinKey = iKey;
@@ -1872,11 +1917,18 @@ static JsonParse *jsonParseCached(
     }
   }
   if( pMatch ){
+    /* The input JSON text was found in the cache.  Use the preexisting
+    ** parse of this JSON */
     pMatch->nErr = 0;
     pMatch->iHold = iMaxHold+1;
     assert( pMatch->nJPRef>0 ); /* pMatch is owned by the cache */
     return pMatch;
   }
+
+  /* The input JSON was not found anywhere in the cache.  We will need
+  ** to parse it ourselves and generate a new JsonParse object.
+  */
+//printf("MISS %s\n", zJson);
   p = sqlite3_malloc64( sizeof(*p) );
   if( p==0 ){
     sqlite3_result_error_nomem(pCtx);
@@ -1954,7 +2006,7 @@ static JsonNode *jsonLookupStep(
   u32 i, j, nKey;
   const char *zKey;
   JsonNode *pRoot = &pParse->aNode[iRoot];
-  while( (pRoot->jnFlags & JNODE_REPLACE)!=0 ){
+  while( (pRoot->jnFlags & JNODE_REPLACE)!=0 && pParse->useMod ){
     u32 idx = (u32)(pRoot - pParse->aNode);
     i = pParse->iSubst;
     while( 1 /*exit-by-break*/ ){
@@ -2004,6 +2056,7 @@ static JsonNode *jsonLookupStep(
         j += jsonNodeSize(&pRoot[j]);
       }
       if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break;
+      if( pParse->useMod==0 ) break;
       assert( pRoot->eU==2 );
       iRoot = pRoot->u.iAppend;
       pRoot = &pParse->aNode[iRoot];
@@ -2012,6 +2065,7 @@ static JsonNode *jsonLookupStep(
     if( pApnd ){
       u32 iStart, iLabel;
       JsonNode *pNode;
+      assert( pParse->useMod );
       iStart = jsonParseAddNode(pParse, JSON_OBJECT, 2, 0);
       iLabel = jsonParseAddNode(pParse, JSON_STRING, nKey, zKey);
       zPath += i;
@@ -2041,10 +2095,11 @@ static JsonNode *jsonLookupStep(
         if( pRoot->eType!=JSON_ARRAY ) return 0;
         for(;;){
           while( j<=pBase->n ){
-            if( (pBase[j].jnFlags & JNODE_REMOVE)==0 ) i++;
+            if( (pBase[j].jnFlags & JNODE_REMOVE)==0 || pParse->useMod==0 ) i++;
             j += jsonNodeSize(&pBase[j]);
           }
           if( (pBase->jnFlags & JNODE_APPEND)==0 ) break;
+          if( pParse->useMod==0 ) break;
           assert( pBase->eU==2 );
           iBase = pBase->u.iAppend;
           pBase = &pParse->aNode[iBase];
@@ -2074,11 +2129,14 @@ static JsonNode *jsonLookupStep(
     zPath += j + 1;
     j = 1;
     for(;;){
-      while( j<=pRoot->n && (i>0 || (pRoot[j].jnFlags & JNODE_REMOVE)!=0) ){
-        if( (pRoot[j].jnFlags & JNODE_REMOVE)==0 ) i--;
+      while( j<=pRoot->n 
+         && (i>0 || ((pRoot[j].jnFlags & JNODE_REMOVE)!=0 && pParse->useMod))
+      ){
+        if( (pRoot[j].jnFlags & JNODE_REMOVE)==0 || pParse->useMod==0 ) i--;
         j += jsonNodeSize(&pRoot[j]);
       }
       if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break;
+      if( pParse->useMod==0 ) break;
       assert( pRoot->eU==2 );
       iRoot = pRoot->u.iAppend;
       pRoot = &pParse->aNode[iRoot];
@@ -2090,6 +2148,7 @@ static JsonNode *jsonLookupStep(
     if( i==0 && pApnd ){
       u32 iStart;
       JsonNode *pNode;
+      assert( pParse->useMod );
       iStart = jsonParseAddNode(pParse, JSON_ARRAY, 1, 0);
       pNode = jsonLookupAppend(pParse, zPath, pApnd, pzErr);
       if( pParse->oom ) return 0;
@@ -2392,7 +2451,7 @@ static void jsonArrayLengthFunc(
   u32 i;
   JsonNode *pNode;
 
-  p = jsonParseCached(ctx, argv[0], ctx);
+  p = jsonParseCached(ctx, argv[0], ctx, 0);
   if( p==0 ) return;
   assert( p->nNode );
   if( argc==2 ){
@@ -2405,9 +2464,14 @@ static void jsonArrayLengthFunc(
     return;
   }
   if( pNode->eType==JSON_ARRAY ){
-    assert( (pNode->jnFlags & JNODE_APPEND)==0 );
-    for(i=1; i<=pNode->n; n++){
-      i += jsonNodeSize(&pNode[i]);
+    while( 1 /*exit-by-break*/ ){
+      for(i=1; i<=pNode->n; n++){
+        i += jsonNodeSize(&pNode[i]);
+      }
+      if( (pNode->jnFlags & JNODE_APPEND)==0 ) break;
+      if( p->useMod==0 ) break;
+      assert( pNode->eU==2 );
+      pNode = &p->aNode[pNode->u.iAppend];
     }
   }
   sqlite3_result_int64(ctx, n);
@@ -2454,7 +2518,7 @@ static void jsonExtractFunc(
   JsonString jx;
 
   if( argc<2 ) return;
-  p = jsonParseCached(ctx, argv[0], ctx);
+  p = jsonParseCached(ctx, argv[0], ctx, 0);
   if( p==0 ) return;
   if( argc==2 ){
     /* With a single PATH argument */
@@ -2487,7 +2551,7 @@ static void jsonExtractFunc(
       }
       if( pNode ){
         if( flags & JSON_JSON ){
-          jsonReturnJson(p, pNode, ctx);
+          jsonReturnJson(p, pNode, ctx, 0);
         }else{
           jsonReturn(p, pNode, ctx);
           sqlite3_result_subtype(ctx, 0);
@@ -2613,12 +2677,14 @@ static void jsonPatchFunc(
     jsonParseReset(&x);
     return;
   }
+  x.useMod = 1;
+  y.useMod = 1;
   pResult = jsonMergePatch(&x, 0, y.aNode);
   assert( pResult!=0 || x.oom );
   if( pResult && x.oom==0 ){
     jsonDebugPrintParse(&x);
     jsonDebugPrintNode(pResult);
-    jsonReturnJson(&x, pResult, ctx);
+    jsonReturnJson(&x, pResult, ctx, 0);
   }else{
     sqlite3_result_error_nomem(ctx);
   }
@@ -2679,27 +2745,30 @@ static void jsonRemoveFunc(
   int argc,
   sqlite3_value **argv
 ){
-  JsonParse x;          /* The parse */
+  JsonParse *pParse;          /* The parse */
   JsonNode *pNode;
   const char *zPath;
   u32 i;
 
   if( argc<1 ) return;
-  if( jsonParse(&x, ctx, (char*)sqlite3_value_text(argv[0]), 0) ) return;
-  assert( x.nNode );
+  pParse = jsonParseCached(ctx, argv[0], ctx, argc>1);
+  if( pParse==0 ) return;  
   for(i=1; i<(u32)argc; i++){
     zPath = (const char*)sqlite3_value_text(argv[i]);
     if( zPath==0 ) goto remove_done;
-    pNode = jsonLookup(&x, zPath, 0, ctx);
-    if( x.nErr ) goto remove_done;
-    if( pNode ) pNode->jnFlags |= JNODE_REMOVE;
+    pNode = jsonLookup(pParse, zPath, 0, ctx);
+    if( pParse->nErr ) goto remove_done;
+    if( pNode ){
+      pNode->jnFlags |= JNODE_REMOVE;
+      pParse->hasMod = 1;
+      pParse->useMod = 1;
+    }
   }
-  if( (x.aNode[0].jnFlags & JNODE_REMOVE)==0 ){
-    jsonReturnJson(&x, x.aNode, ctx);
+  if( (pParse->aNode[0].jnFlags & JNODE_REMOVE)==0 ){
+    jsonReturnJson(pParse, pParse->aNode, ctx, 1);
   }
 remove_done:
-  jsonDebugPrintParse(&x);
-  jsonParseReset(&x);
+  jsonDebugPrintParse(p);
 }
 
 /*
@@ -2763,7 +2832,7 @@ static void jsonReplaceNode(
           sqlite3_result_error_nomem(pCtx);
         }
       }else{
-        JsonParse *pPatch = jsonParseCached(pCtx, pValue, pCtx);
+        JsonParse *pPatch = jsonParseCached(pCtx, pValue, pCtx, 1);
         if( pPatch==0 ){
           p->oom = 1;
           break;
@@ -2817,7 +2886,7 @@ static void jsonReplaceFunc(
       jsonReplaceNode(ctx, &x, (u32)(pNode - x.aNode), argv[i+1]);
     }
   }
-  jsonReturnJson(&x, x.aNode, ctx);
+  jsonReturnJson(&x, x.aNode, ctx, 0);
 replace_err:
   jsonDebugPrintParse(&x);
   jsonParseReset(&x);
@@ -2858,6 +2927,7 @@ static void jsonSetFunc(
   for(i=1; i<(u32)argc; i+=2){
     zPath = (const char*)sqlite3_value_text(argv[i]);
     bApnd = 0;
+    x.useMod = 1;
     pNode = jsonLookup(&x, zPath, &bApnd, ctx);
     if( x.oom ){
       sqlite3_result_error_nomem(ctx);
@@ -2869,7 +2939,7 @@ static void jsonSetFunc(
     }
   }
   jsonDebugPrintParse(&x);
-  jsonReturnJson(&x, x.aNode, ctx);
+  jsonReturnJson(&x, x.aNode, ctx, 0);
 
 jsonSetDone:
   jsonParseReset(&x);
@@ -2891,7 +2961,7 @@ static void jsonTypeFunc(
   const char *zPath;
   JsonNode *pNode;
 
-  p = jsonParseCached(ctx, argv[0], ctx);
+  p = jsonParseCached(ctx, argv[0], ctx, 0);
   if( p==0 ) return;
   if( argc==2 ){
     zPath = (const char*)sqlite3_value_text(argv[1]);
@@ -2918,12 +2988,12 @@ static void jsonValidFunc(
   JsonParse *p;          /* The parse */
   UNUSED_PARAMETER(argc);
   if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
-  p = jsonParseCached(ctx, argv[0], 0);
+  p = jsonParseCached(ctx, argv[0], 0, 0);
   if( p==0 || p->oom ){
     sqlite3_result_error_nomem(ctx);
     sqlite3_free(p);
   }else{
-    sqlite3_result_int(ctx, p->nErr==0 && p->hasNonstd==0);
+    sqlite3_result_int(ctx, p->nErr==0 && (p->hasNonstd==0 || p->useMod));
     if( p->nErr ) jsonParseFree(p);
   }
 }
@@ -2964,7 +3034,7 @@ static void jsonErrorFunc(
   JsonParse *p;          /* The parse */
   UNUSED_PARAMETER(argc);
   if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
-  p = jsonParseCached(ctx, argv[0], 0);
+  p = jsonParseCached(ctx, argv[0], 0, 0);
   if( p==0 || p->oom ){
     sqlite3_result_error_nomem(ctx);
     sqlite3_free(p);
index 222e70be294f0c65b4f9a4c7c12378db3f4ef6e1..a55bd2b85b1b55eb33cb89765426cc48bc7ff7db 100644 (file)
@@ -1406,6 +1406,7 @@ void sqlite3RCStrUnref(char *z){
   }
 }
 
+#if 0
 /*
 ** Return true if the reference count on the string is exactly one, meaning
 ** that the string can be modified.  Return false if the reference count
@@ -1419,6 +1420,7 @@ int sqlite3RCStrIsWriteable(char *z){
   assert( p->uMagic==SQLITE_RCSTR_MAGIC );
   return p->nRCRef==1;
 }
+#endif
 
 /*
 ** Create a new string that is capable of holding N bytes of text, not counting
@@ -1441,6 +1443,7 @@ char *sqlite3RCStrNew(u64 N){
   return (char*)&p[1];
 }
 
+#if 0
 /*
 ** Return the number of bytes allocated to the string.  The value returned
 ** does not include the space for the zero-terminator at the end.
@@ -1456,6 +1459,7 @@ u64 sqlite3RCStrSize(char *z){
   N -= sizeof(p) + 1;
   return N;
 }
+#endif
 
 /*
 ** Change the size of the string so that it is able to hold N bytes.
@@ -1477,6 +1481,7 @@ char *sqlite3RCStrResize(char *z, u64 N){
   }
 }
 
+#if 0
 /*
 ** Add a new attachment to the string.
 **
@@ -1494,7 +1499,9 @@ void sqlite3RCStrAttach(char *z, void *pAttach, void(*xFree)(void*)){
   p->xFree = xFree;
   p->pAttach = pAttach;
 }
-  
+#endif
+
+#if 0
 /*
 ** Return the attachment associated with a string if the attachment
 ** has the destructure specified in the second argument.  If the
@@ -1509,3 +1516,4 @@ void *sqlite3RCStrGetAttachment(char *z, void(*xFree)(void*)){
   assert( p->uMagic==SQLITE_RCSTR_MAGIC );
   return p->xFree==xFree ? p->pAttach : 0;
 }
+#endif
index adf4d34dec8fe92c4dfb9d27f9054ce500e279b7..358063534f7a171d8274bf63c7f8413a44d9021c 100644 (file)
@@ -5222,7 +5222,7 @@ void sqlite3FileSuffix3(const char*, char*);
 u8 sqlite3GetBoolean(const char *z,u8);
 
 const void *sqlite3ValueText(sqlite3_value*, u8);
-int sqlite3ValueIsOfClass(const sqlite3_value*, void(*)(void*));
+//int sqlite3ValueIsOfClass(const sqlite3_value*, void(*)(void*));
 int sqlite3ValueBytes(sqlite3_value*, u8);
 void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8,
                         void(*)(void*));
@@ -5333,11 +5333,11 @@ int sqlite3OpenTempDatabase(Parse *);
 char *sqlite3RCStrRef(char*);
 void sqlite3RCStrUnref(char*);
 char *sqlite3RCStrNew(u64);
-u64 sqlite3RCStrSize(char*);
+//u64 sqlite3RCStrSize(char*);
 char *sqlite3RCStrResize(char*,u64);
-int sqlite3RCStrIsWriteable(char*);
-void sqlite3RCStrAttach(char*, void*, void(*)(void*));
-void *sqlite3RCStrGetAttachment(char*,void(*)(void*));
+//int sqlite3RCStrIsWriteable(char*);
+//void sqlite3RCStrAttach(char*, void*, void(*)(void*));
+//void *sqlite3RCStrGetAttachment(char*,void(*)(void*));
 
 void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
 int sqlite3StrAccumEnlarge(StrAccum*, i64);
index 87dfbbebd8cab53365e3bed717779be5ddcc77b1..d44a41716f09e29ea433d1d1562de50fdea35184 100644 (file)
@@ -1368,6 +1368,7 @@ const void *sqlite3ValueText(sqlite3_value* pVal, u8 enc){
   return valueToText(pVal, enc);
 }
 
+#if 0
 /* Return true if sqlit3_value object pVal is a string or blob value
 ** that uses the destructor specified in the second argument.
 **
@@ -1385,6 +1386,7 @@ int sqlite3ValueIsOfClass(const sqlite3_value *pVal, void(*xFree)(void*)){
     return 0;
   }
 }
+#endif
 
 /*
 ** Create a new sqlite3_value object.