]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Allow the PG-style syntax for the PATH operand on the right-hand side of
authordrh <>
Thu, 5 Oct 2023 15:02:00 +0000 (15:02 +0000)
committerdrh <>
Thu, 5 Oct 2023 15:02:00 +0000 (15:02 +0000)
the ->> and -> operators.

FossilOrigin-Name: bae5071b0834aa3b7fd4bd871f863e1b148c6558989c8f6cdd02dc4da4770953

manifest
manifest.uuid
src/json.c

index 6d4d77ef56b72e3d768e85d2dc9eb466bc804fc2..0303e4cd7f38826dff8327c776cb9cb22e5a226e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Merge\strunk\senhancements\sinto\sthe\sjsonb\sbranch.
-D 2023-10-05T11:22:16.707
+C Allow\sthe\sPG-style\ssyntax\sfor\sthe\sPATH\soperand\son\sthe\sright-hand\sside\sof\nthe\s->>\sand\s->\soperators.
+D 2023-10-05T15:02:00.537
 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 52e4fa529ca0a727ece05607fc3641a7ba6734e39ecc1f3e9ba8c1a7caa1f0cc
+F src/json.c 7f765a31a4b0c7df2505a43e74f5059eaff8ed851d60dfc7b6eedfdf9f5b4089
 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 08e7db138b636890cb29a76d65c2069c6e2ff44470fa4bca14f4526fe5f195ae a2464bbb825b5976ef974a2e6c17ea150f5e6fcd0dd0f144b9f9c1c22a9c9c82
-R 84b74e4fd51ca93386cc67654677da5e
+P be5907b648386e05530d1e321e2a3e563e07e99f08373aaf9a3452adc9228dc3
+R a953453e7f2d067ffe8d15205e74a86b
 U drh
-Z 4d31c96be6e146821c899c0f24a5a9d8
+Z 1c88c01c099cd40d1caaee0961805818
 # Remove this line to create a well-formed Fossil manifest.
index 973ac143620fe0928eb26f7c433d65f660415d98..12eff4a58ce53f5913e6fbe1d1f5763179963e3a 100644 (file)
@@ -1 +1 @@
-be5907b648386e05530d1e321e2a3e563e07e99f08373aaf9a3452adc9228dc3
\ No newline at end of file
+bae5071b0834aa3b7fd4bd871f863e1b148c6558989c8f6cdd02dc4da4770953
\ No newline at end of file
index 955c35377b345ec1bbcd42be9c3b47007af3e0ca..3307db0babfc40189faee35ea23fac9c7f214931 100644 (file)
@@ -3990,12 +3990,38 @@ static void jsonExtractFromBlob(
   u32 i;
   JsonParse px;
   if( zPath==0 ) return;
-  if( zPath[0]=='$' ) zPath++;
   memset(&px, 0, sizeof(px));
   px.nBlob = sqlite3_value_bytes(pJson);
   px.aBlob = (u8*)sqlite3_value_blob(pJson);
   if( px.aBlob==0 ) return;
-  i = jsonLookupBlobStep(&px, 0, zPath, &zErr);
+  if( zPath[0]=='$' ){
+    zPath++;
+    i = jsonLookupBlobStep(&px, 0, zPath, &zErr);
+  }else if( (flags & JSON_ABPATH) ){
+    /* 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
+    */
+    JsonString jx;
+    jsonStringInit(&jx, ctx);
+    if( sqlite3Isdigit(zPath[0]) ){
+      jsonAppendRawNZ(&jx, "[", 1);
+      jsonAppendRaw(&jx, zPath, (int)strlen(zPath));
+      jsonAppendRawNZ(&jx, "]", 2);
+      zPath = jx.zBuf;
+    }else if( zPath[0]!='[' ){
+      jsonAppendRawNZ(&jx, ".", 1);
+      jsonAppendRaw(&jx, zPath, (int)strlen(zPath));
+      jsonAppendChar(&jx, 0);
+      zPath = jx.zBuf;
+    }
+    i = jsonLookupBlobStep(&px, 0, zPath, &zErr);
+    jsonStringReset(&jx);
+  }
   if( i<px.nBlob ){
     jsonReturnFromBlob(&px, i, ctx);
   }else if( i==JSON_BLOB_NOTFOUND ){