]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Improvements to error messages returned when the ->> operator fails.
authordrh <>
Sat, 7 Oct 2023 17:50:06 +0000 (17:50 +0000)
committerdrh <>
Sat, 7 Oct 2023 17:50:06 +0000 (17:50 +0000)
FossilOrigin-Name: 2f3388f14c843f1c02926e8b929365c06c1f1f4ea6fe6316092c3799c14549d3

manifest
manifest.uuid
src/json.c

index 1720248ca60bd946d2dfaa99811423153d3d0fb2..5ccd6fe084da8736d3b30f28671f2aa58f1e0a17 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Merge\sthe\smemory\sleak\sfix\sfrom\strunk.
-D 2023-10-07T11:37:00.963
+C Improvements\sto\serror\smessages\sreturned\swhen\sthe\s->>\soperator\sfails.
+D 2023-10-07T17:50:06.014
 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 969f4897a681aa786f77ed7122db07475cf95f473d3a2de2572ffae600ec0ac1
+F src/json.c a5d273004e0b0d4b961efe59b403c5b118218b3db2c2d61b4512ea2815ada8b2
 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
 F src/loadext.c 98cfba10989b3da6f1807ad42444017742db7f100a54f1032af7a8b1295912c0
 F src/main.c 618aeb399e993cf561864f4b0cf6a331ee4f355cf663635f8d9da3193a46aa40
@@ -2124,8 +2124,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 96cfdc31e305406123f6ef1b920423f71902dc4b34381c3efb720274343d37cc f99ff655d09763c4a22d065041644ece793d84c82c644931e89ccf50c4f4564a
-R 9cb62826bab57bac8933243b48ca592e
+P 358de1b09f3d5ec0fe459775b0a2a99dfa235817327016b472aaa1ed56d952e6
+R 65b1837fdcd2785b2dbe03dd6bcb09bb
 U drh
-Z cdf0570fe999933e060b2c73f0eb1dc1
+Z f25f60a6b37a3fc4a80bb7878104ebfa
 # Remove this line to create a well-formed Fossil manifest.
index 282aac4978ef5ad376c6e947ba948e329b5972e2..f4e3476f43d78078fab95b719c966e164d2d5ca2 100644 (file)
@@ -1 +1 @@
-358de1b09f3d5ec0fe459775b0a2a99dfa235817327016b472aaa1ed56d952e6
\ No newline at end of file
+2f3388f14c843f1c02926e8b929365c06c1f1f4ea6fe6316092c3799c14549d3
\ No newline at end of file
index fdc7df41b2187ecc7cd385337d5c3f6a5a8619c9..fac05a0776f6dfed8271b0baeb21ab93d0ea7a76 100644 (file)
@@ -3696,8 +3696,7 @@ static u32 jsonbArrayCount(JsonParse *pParse, u32 iRoot){
 static u32 jsonLookupBlobStep(
   JsonParse *pParse,      /* The JSON to search */
   u32 iRoot,              /* Begin the search at this element of aBlob[] */
-  const char *zPath,      /* The path to search */
-  const char **pzErr      /* Make *pzErr point to any syntax error in zPath */
+  const char *zPath       /* The path to search */
 ){
   u32 i, j, k, nKey, sz, n, iEnd;
   const char *zKey;
@@ -3707,7 +3706,6 @@ static u32 jsonLookupBlobStep(
   if( zPath[0]==0 ) return iRoot;
   if( zPath[0]=='.' ){
     x = pParse->aBlob[iRoot];
-    if( (x & 0x0f)!=JSONB_OBJECT ) return JSON_BLOB_NOTFOUND;
     zPath++;
     if( zPath[0]=='"' ){
       zKey = zPath + 1;
@@ -3716,7 +3714,6 @@ static u32 jsonLookupBlobStep(
       if( zPath[i] ){
         i++;
       }else{
-        *pzErr = "unterminated \"";
         return JSON_BLOB_PATHERROR;
       }
       testcase( nKey==0 );
@@ -3725,10 +3722,10 @@ static u32 jsonLookupBlobStep(
       for(i=0; zPath[i] && zPath[i]!='.' && zPath[i]!='['; i++){}
       nKey = i;
       if( nKey==0 ){
-        *pzErr = zPath;
-        return 0;
+        return JSON_BLOB_PATHERROR;
       }
     }
+    if( (x & 0x0f)!=JSONB_OBJECT ) return JSON_BLOB_NOTFOUND;
     n = jsonbPayloadSize(pParse, iRoot, &sz);
     j = iRoot + n;
     iEnd = j+sz;
@@ -3744,7 +3741,7 @@ static u32 jsonLookupBlobStep(
         if( ((pParse->aBlob[j])&0x0f)>JSONB_OBJECT ) return JSON_BLOB_ERROR;
         n = jsonbPayloadSize(pParse, j, &sz);
         if( n==0 || j+n+sz>iEnd ) return JSON_BLOB_ERROR;
-        return jsonLookupBlobStep(pParse, j, &zPath[i], pzErr);
+        return jsonLookupBlobStep(pParse, j, &zPath[i]);
       }
       j = k+sz;
       if( ((pParse->aBlob[j])&0x0f)>JSONB_OBJECT ) return JSON_BLOB_ERROR;
@@ -3778,11 +3775,9 @@ static u32 jsonLookupBlobStep(
           k -= nn;
         }
         if( zPath[i]!=']' ){
-          *pzErr = "unterminated [";
           return JSON_BLOB_PATHERROR;
         }
       }else{
-        *pzErr = "bad argument to []";
         return JSON_BLOB_PATHERROR;
       }
     }
@@ -3790,7 +3785,7 @@ static u32 jsonLookupBlobStep(
     iEnd = j+sz;
     while( j<iEnd ){
       if( k==0 ){
-        return jsonLookupBlobStep(pParse, j, &zPath[i+1], pzErr);
+        return jsonLookupBlobStep(pParse, j, &zPath[i+1]);
       }
       k--;
       n = jsonbPayloadSize(pParse, j, &sz);
@@ -3799,7 +3794,6 @@ static u32 jsonLookupBlobStep(
     }
     if( j>iEnd ) return JSON_BLOB_ERROR;
   }else{
-    *pzErr = "syntax error";
     return JSON_BLOB_PATHERROR; 
   }
   return JSON_BLOB_NOTFOUND;
@@ -4011,7 +4005,6 @@ static void jsonExtractFromBlob(
   int flags
 ){
   const char *zPath = (const char*)sqlite3_value_text(pPath);
-  const char *zErr = 0;
   u32 i = 0;
   JsonParse px;
   if( zPath==0 ) return;
@@ -4021,7 +4014,7 @@ static void jsonExtractFromBlob(
   if( px.aBlob==0 ) return;
   if( zPath[0]=='$' ){
     zPath++;
-    i = jsonLookupBlobStep(&px, 0, zPath, &zErr);
+    i = jsonLookupBlobStep(&px, 0, zPath);
   }else if( (flags & JSON_ABPATH) ){
     /* The -> and ->> operators accept abbreviated PATH arguments.  This
     ** is mostly for compatibility with PostgreSQL, but also for
@@ -4044,7 +4037,7 @@ static void jsonExtractFromBlob(
       jsonAppendChar(&jx, 0);
       zPath = jx.zBuf;
     }
-    i = jsonLookupBlobStep(&px, 0, zPath, &zErr);
+    i = jsonLookupBlobStep(&px, 0, zPath);
     jsonStringReset(&jx);
   }else{
     sqlite3_result_error(ctx, "bad path", -1);
@@ -4056,13 +4049,11 @@ static void jsonExtractFromBlob(
     return;  /* Return NULL if not found */
   }else if( i==JSON_BLOB_ERROR ){
     sqlite3_result_error(ctx, "malformed JSON", -1);
-  }else if( i==JSON_BLOB_PATHERROR ){
-    char *zMsg = sqlite3_mprintf("in JSON path '%s': %s",
-                    sqlite3_value_text(pPath), zErr);
+  }else{
+    char *zMsg = sqlite3_mprintf("bad path syntax: %s",
+                    sqlite3_value_text(pPath));
     sqlite3_result_error(ctx, zMsg, -1);
     sqlite3_free(zMsg);
-  }else{
-    sqlite3_result_error(ctx, zErr, -1);
   }
 }