From 6b1db922286ac88505854e93ce017e11e4b18cb5 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 28 Sep 2023 17:23:46 +0000 Subject: [PATCH] Extract directly from BLOB is now complete and appears to work. FossilOrigin-Name: 3de58ec99444b16dfcda1e226420e2343450b77abd3faf33a88b6d18339ef17c --- manifest | 12 +++++----- manifest.uuid | 2 +- src/json.c | 61 ++++++++++++++++++++++++--------------------------- 3 files changed, 36 insertions(+), 39 deletions(-) diff --git a/manifest b/manifest index c1019d925c..f6be12b744 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Miscellaneous\sbugs\sfixed. -D 2023-09-28T17:07:43.443 +C Extract\sdirectly\sfrom\sBLOB\sis\snow\scomplete\sand\sappears\sto\swork. +D 2023-09-28T17:23:46.244 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 946e0bbc5070db333a370e2f7b806ad07d2e9fb93d057cf52a9e5fb58fd43768 +F src/json.c 7e68346bfc4f030e454c68751ab7082af52b9925ff28bff88eef03258e486d7c F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 98cfba10989b3da6f1807ad42444017742db7f100a54f1032af7a8b1295912c0 F src/main.c 618aeb399e993cf561864f4b0cf6a331ee4f355cf663635f8d9da3193a46aa40 @@ -2123,8 +2123,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 8c82576176539c4d132b14d46adbf31366c4bcaa59a61dd639dc9cc308fe8825 -R e6233e4f5d16d81e42c25a8ff039c998 +P 5c0815fa2e422d81198a43a2c04a022e319fcbcadfd4be4437f2e663892ca26b +R 0d79abb184ac0c9db2e32b0ee612448c U drh -Z beeeb6a9ecf43431f000f927a20c9a15 +Z dfb6861bdfa5add7990cbc313b482bb0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 5bf7e31c95..6de749eb76 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5c0815fa2e422d81198a43a2c04a022e319fcbcadfd4be4437f2e663892ca26b \ No newline at end of file +3de58ec99444b16dfcda1e226420e2343450b77abd3faf33a88b6d18339ef17c \ No newline at end of file diff --git a/src/json.c b/src/json.c index 322fbc5602..e43240c71c 100644 --- a/src/json.c +++ b/src/json.c @@ -3507,6 +3507,21 @@ static void jsonRenderNodeAsBlob( } } +/* +** Given that a JSONB_ARRAY object starts at offset i, return +** the number of entries in that array. +*/ +static u32 jsonbArrayCount(JsonParse *pParse, u32 iRoot){ + u32 n, sz, i, iEnd; + u32 k = 0; + n = jsonbPayloadSize(pParse, iRoot, &sz); + iEnd = iRoot+n+sz; + for(i=iRoot+n; iiEnd ) return JSON_BLOB_ERROR; }else if( zPath[0]=='[' ){ + x = pParse->aBlob[iRoot] & 0x0f; + if( x!=JSONB_ARRAY ) return JSON_BLOB_NOTFOUND; + n = jsonbPayloadSize(pParse, iRoot, &sz); k = 0; i = 1; while( sqlite3Isdigit(zPath[i]) ){ @@ -3586,49 +3604,28 @@ static u32 jsonLookupBlobStep( i++; } if( i<2 || zPath[i]!=']' ){ -#if 0 if( zPath[1]=='#' ){ - JsonNode *pBase = pRoot; - int iBase = iRoot; - if( pRoot->eType!=JSON_ARRAY ) return 0; - for(;;){ - while( j<=pBase->n ){ - 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]; - j = 1; - } - j = 2; + k = jsonbArrayCount(pParse, iRoot); + i = 2; if( zPath[2]=='-' && sqlite3Isdigit(zPath[3]) ){ unsigned int x = 0; - j = 3; + i = 3; do{ - x = x*10 + zPath[j] - '0'; - j++; - }while( sqlite3Isdigit(zPath[j]) ); - if( x>i ) return 0; - i -= x; + x = x*10 + zPath[i] - '0'; + i++; + }while( sqlite3Isdigit(zPath[i]) ); + if( x>k ) return 0; + k -= x; } - if( zPath[j]!=']' ){ + if( zPath[i]!=']' ){ *pzErr = zPath; - return 0; + return JSON_BLOB_PATHERROR; } }else{ *pzErr = zPath; - return 0; + return JSON_BLOB_PATHERROR; } -#endif - *pzErr = zPath; - return JSON_BLOB_PATHERROR; } - x = pParse->aBlob[iRoot] & 0x0f; - if( x!=JSONB_ARRAY ) return JSON_BLOB_NOTFOUND; - n = jsonbPayloadSize(pParse, iRoot, &sz); j = iRoot+n; iEnd = j+sz; while( j