1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-11 01:42:22 +03:00

Allow the PG-style syntax for the PATH operand on the right-hand side of

the ->> and -> operators.

FossilOrigin-Name: bae5071b0834aa3b7fd4bd871f863e1b148c6558989c8f6cdd02dc4da4770953
This commit is contained in:
drh
2023-10-05 15:02:00 +00:00
parent 0f921e2bac
commit 9061e22a05
3 changed files with 35 additions and 9 deletions

View 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 ){