]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix the PG-compatible -> and ->> path parsing.
authordrh <>
Tue, 11 Jan 2022 18:01:17 +0000 (18:01 +0000)
committerdrh <>
Tue, 11 Jan 2022 18:01:17 +0000 (18:01 +0000)
FossilOrigin-Name: 22d5138315fb77eeea1c7e66ccc4190bcae18d058a99aa37ddd119e54b52f723

manifest
manifest.uuid
src/json.c

index 4fe6fba3c0d1c1ca478feea38d794b553673e1c2..1af75554281c429cb0a94a62fb6af019aaf6b4e2 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\stypo\sin\sthe\sjson-enhancements.md\sdocument.
-D 2022-01-10T17:43:54.652
+C Fix\sthe\sPG-compatible\s->\sand\s->>\spath\sparsing.
+D 2022-01-11T18:01:17.466
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -512,7 +512,7 @@ F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51
 F src/hwtime.h cb1d7e3e1ed94b7aa6fde95ae2c2daccc3df826be26fc9ed7fd90d1750ae6144
 F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
 F src/insert.c e528416ff5d86fc5d656ea6a26f03fde39836b6175f93048c32a03cb2ee16743
-F src/json.c d3134d392d88cb21ab352dd877b901ee5d46e6404fc1321f77cf67bb4d4dc9d3
+F src/json.c 5dee750a85262600817f20e3ced050f9c2a47d8c3db77f31f4ee379c0f843a8a
 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
 F src/loadext.c 95db1fe62c5973f1c5d9c53f6083e21a73ece14cdd47eeca0639691332e85c4d
 F src/main.c 2b6b0dbfeb14d4bb57e368604b0736b2aa42b51b00339d399b01d6b1fc9b4960
@@ -1938,8 +1938,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 39eff3b9bf1f318d3606d8e5361a2adb2ba8bc1ca2a436ce4f9a204aa4cf20dd
-R 8ac564d1981cf04622f1f15a60ba0e5b
+P feba24ef774d80ebbaf87a93fc106cb7e482edcc3f237edd4c9d4e918ffb3131
+R 0007d377d0ed1c0dc1f81b209b625ab0
 U drh
-Z c237913f633491314765f45ba87ab8df
+Z e45b9675c3fefc0ecfe81398e8f3bbb1
 # Remove this line to create a well-formed Fossil manifest.
index af50a8820d54c7c195bb0fe7dc3d06e4e3059555..d47038dcfc7ad0b9c0a0cbe3600de68526f9f970 100644 (file)
@@ -1 +1 @@
-feba24ef774d80ebbaf87a93fc106cb7e482edcc3f237edd4c9d4e918ffb3131
\ No newline at end of file
+22d5138315fb77eeea1c7e66ccc4190bcae18d058a99aa37ddd119e54b52f723
\ No newline at end of file
index e2dbc7e3078c69e37c6baaa8df3bbab0086786a3..6fe5fa411c1a9e54d65aa8fbaa9956ed5f7ac02f 100644 (file)
@@ -1549,36 +1549,39 @@ static void jsonExtractFunc(
     /* With a single PATH argument */
     zPath = (const char*)sqlite3_value_text(argv[1]);
     if( zPath==0 ) return;
-    if( zPath[0]!='$' && (flags & JSON_ABPATH)!=0 ){
-      /* The -> and ->> operators accept abbreviated PATH arguments.  This
-      ** is mostly for compatibility with PostgreSQL, but also for convenience.
-      **
-      **     NUMBER   ==>  $[NUMBER]     // PG compatible
-      **     LABEL    ==>  $.LABEL       // PG compatible
-      **     [NUMBER] ==>  $[NUMBER]     // Not PG.  Purely for convenience
-      */
-      jsonInit(&jx, ctx);
-      if( sqlite3Isdigit(zPath[0]) ){
-        jsonAppendRaw(&jx, "$[", 2);
-        jsonAppendRaw(&jx, zPath, (int)strlen(zPath));
-        jsonAppendRaw(&jx, "]", 2);
+    if( flags & JSON_ABPATH ){
+      if( zPath[0]!='$' ){
+        /* The -> and ->> operators accept abbreviated PATH arguments.  This
+        ** is mostly for compatibility with PostgreSQL, but also for
+        ** convenience.
+        **
+        **     NUMBER   ==>  $[NUMBER]     // PG compatible
+        **     LABEL    ==>  $.LABEL       // PG compatible
+        **     [NUMBER] ==>  $[NUMBER]     // Not PG.  Purely for convenience
+        */
+        jsonInit(&jx, ctx);
+        if( sqlite3Isdigit(zPath[0]) ){
+          jsonAppendRaw(&jx, "$[", 2);
+          jsonAppendRaw(&jx, zPath, (int)strlen(zPath));
+          jsonAppendRaw(&jx, "]", 2);
+        }else{
+          jsonAppendRaw(&jx, "$.", 1 + (zPath[0]!='['));
+          jsonAppendRaw(&jx, zPath, (int)strlen(zPath));
+          jsonAppendChar(&jx, 0);
+        }
+        pNode = jx.bErr ? 0 : jsonLookup(p, jx.zBuf, 0, ctx);
+        jsonReset(&jx);
       }else{
-        jsonAppendRaw(&jx, "$.", 1 + (zPath[0]!='['));
-        jsonAppendRaw(&jx, zPath, (int)strlen(zPath));
-        jsonAppendChar(&jx, 0);
+        pNode = jsonLookup(p, zPath, 0, ctx);
       }
-      if( jx.bErr==0 ){
-        pNode = jsonLookup(p, jx.zBuf, 0, ctx);
-        if( pNode==0 ){
-          /* No-op.  jsonLookup will have left an error for us */
-        }else if( flags & JSON_JSON ){
+      if( pNode ){
+        if( flags & JSON_JSON ){
           jsonReturnJson(pNode, ctx, 0);
         }else{
           jsonReturn(pNode, ctx, 0);
           sqlite3_result_subtype(ctx, 0);
         }
       }
-      jsonReset(&jx);
     }else{
       pNode = jsonLookup(p, zPath, 0, ctx);
       if( p->nErr==0 && pNode ) jsonReturn(pNode, ctx, 0);