-C Work\stoward\sgetting\sjson_extract()\sto\soperate\sdirectly\son\sthe\sBLOB,\somitting\nthe\stranslation\sinto\sa\sJsonNode\sarray.
-D 2023-09-28T10:20:56.267
+C Improvements\sto\sjson_extract()\sto\sbetter\ssupport\sJSONB.\sStill\snot\s100%\sworking.
+D 2023-09-28T15:56:35.608
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
F src/hwtime.h f9c2dfb84dce7acf95ce6d289e46f5f9d3d1afd328e53da8f8e9008e3b3caae6
F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
F src/insert.c 3f0a94082d978bbdd33c38fefea15346c6c6bffb70bc645a71dc0f1f87dd3276
-F src/json.c 1f174d19f143e4968ae391de3d504563f320c6dbc2ba437231b40f19631a6dc4
+F src/json.c c9d70a47aabc97b51cd21a33be7602db4760a980920b44b497dbb331a91c12d8
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
F src/loadext.c 98cfba10989b3da6f1807ad42444017742db7f100a54f1032af7a8b1295912c0
F src/main.c 618aeb399e993cf561864f4b0cf6a331ee4f355cf663635f8d9da3193a46aa40
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 7c1be8e361db87458ac9d8fcee080c2b558936539c852bb80f0f7941d61bf15d
-R b9d3bc6ee4123d23cc875353cfd5e9aa
-T *branch * jsonb-direct-extract
-T *sym-jsonb-direct-extract *
-T -sym-jsonb *
+P c1feba70f55a8e5f4696d48e4706855415d173ac8ac3c2656787c242a883b4f5
+R df67f115b3402f37b4410f24659e50ec
U drh
-Z 3a4258d315e3af636c1707e0dba68e38
+Z a8b3beeec30b8fa8de8cb3c4ca40d323
# Remove this line to create a well-formed Fossil manifest.
}
/*
-**
+** Convert a JSON BLOB into text and make that text the return value
+** of an SQL function.
+*/
+static void jsonReturnTextJsonFromBlob(
+ sqlite3_context *ctx,
+ const u8 *aBlob,
+ u32 nBlob
+){
+ JsonParse x;
+ JsonString s;
+
+ if( aBlob==0 ) return;
+ memset(&x, 0, sizeof(x));
+ x.aBlob = (u8*)aBlob;
+ x.nBlob = nBlob;
+ jsonInit(&s, ctx);
+ jsonRenderBlob(&x, 0, &s);
+ jsonResult(&s);
+}
+
+
+/*
+** Return the value of the BLOB node at index i.
+**
+** If the value is a primitive, return it as an SQL value.
+** If the value is an array or object, return it as either
+** JSON text or the BLOB encoding, depending on the JSON_B flag
+** on the userdata.
*/
static void jsonReturnFromBlob(
JsonParse *pParse, /* Complete JSON parse tree */
}
case JSONB_ARRAY:
case JSONB_OBJECT: {
- sqlite3_result_blob(pCtx, &pParse->aBlob[i+n], sz, SQLITE_TRANSIENT);
+ int flags = SQLITE_PTR_TO_INT(sqlite3_user_data(pCtx));
+ if( flags & JSON_BLOB ){
+ sqlite3_result_blob(pCtx, &pParse->aBlob[i], sz+n, SQLITE_TRANSIENT);
+ }else{
+ jsonReturnTextJsonFromBlob(pCtx, &pParse->aBlob[i], sz+n);
+ }
break;
}
}
int argc,
sqlite3_value **argv
){
- JsonParse *pParse;
const u8 *aBlob;
int nBlob;
- JsonParse x;
- JsonString s;
UNUSED_PARAMETER(argc);
aBlob = (const u8*)sqlite3_value_blob(argv[0]);
- if( aBlob==0 ) return;
nBlob = sqlite3_value_bytes(argv[0]);
- pParse = &x;
- memset(&x, 0, sizeof(x));
- x.aBlob = (u8*)aBlob;
- x.nBlob = nBlob;
- jsonInit(&s, ctx);
- jsonRenderBlob(pParse, 0, &s);
- jsonResult(&s);
+ jsonReturnTextJsonFromBlob(ctx, aBlob, nBlob);
}
/*
JFUNCTION(json_array_length, 2, 0, jsonArrayLengthFunc),
JFUNCTION(json_error_position,1, 0, jsonErrorFunc),
JFUNCTION(json_extract, -1, 0, jsonExtractFunc),
+ JFUNCTION(jsonb_extract, -1, JSON_BLOB, jsonExtractFunc),
JFUNCTION(->, 2, JSON_JSON, jsonExtractFunc),
JFUNCTION(->>, 2, JSON_SQL, jsonExtractFunc),
JFUNCTION(json_insert, -1, 0, jsonSetFunc),