Convert the json_error_position() routine to use only JSONB internally.

FossilOrigin-Name: e7a8ba35bff6fde55827f978de5b343b6c134c7fa53827f5c63915a9dc2598ad
This commit is contained in:
drh 2023-11-29 20:06:49 +00:00
parent da2578391d
commit 694beecf2b
3 changed files with 46 additions and 23 deletions

View File

@ -1,5 +1,5 @@
C The\sjson_patch()\sfunction\snow\soperates\sexclusively\son\sJSONB.\s\sThis\spatch\nalso\sincludes\simprovements\sto\sJSONB\sdebug\sprinting\sroutines.
D 2023-11-29T17:36:54.076
C Convert\sthe\sjson_error_position()\sroutine\sto\suse\sonly\sJSONB\sinternally.
D 2023-11-29T20:06:49.393
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -688,7 +688,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 00b55c9e54047e1412fb7303e954e996c84bb8b06d3e376b12f49178c4fd7b69
F src/json.c d93f5e7d0e0a50c5842657439c3e820802f862da0d2aaf28df08cb3528acc0aa
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36
F src/main.c 1b89f3de98d1b59fec5bac1d66d6ece21f703821b8eaa0d53d9604c35309f6f9
@ -2145,8 +2145,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 1a59fcab2179cc3b52ecd3de7d2018db96ac149aaff521959773a517b8d9ac3e
R 883e1938b9afc8e6538b46e875ce6c0e
P fee19d0098242110d2c44ec7b9620c1210ef3f87913305f66ec85d277dd96ab6
R de34ae25adb13e4614fb6787c64e8886
U drh
Z 19b3c18296db473321d95b26a8cafb5e
Z beaa9ff647aa958b069175a31fff1f35
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
fee19d0098242110d2c44ec7b9620c1210ef3f87913305f66ec85d277dd96ab6
e7a8ba35bff6fde55827f978de5b343b6c134c7fa53827f5c63915a9dc2598ad

View File

@ -5438,25 +5438,48 @@ static void jsonErrorFunc(
int argc,
sqlite3_value **argv
){
JsonParse *p; /* The parse */
i64 iErrPos = 0; /* Error position to be returned */
JsonParse s;
assert( argc==1 );
UNUSED_PARAMETER(argc);
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
p = jsonParseCached(ctx, argv[0], 0, 0);
if( p==0 || p->oom ){
sqlite3_result_error_nomem(ctx);
sqlite3_free(p);
}else if( p->nErr==0 ){
sqlite3_result_int(ctx, 0);
}else{
int n = 1;
u32 i;
const char *z = (const char*)sqlite3_value_text(argv[0]);
for(i=0; i<p->iErr && ALWAYS(z[i]); i++){
if( (z[i]&0xc0)!=0x80 ) n++;
switch( sqlite3_value_type(argv[0]) ){
case SQLITE_NULL: {
return;
}
case SQLITE_BLOB: {
if( !jsonFuncArgMightBeBinary(argv[0]) ) iErrPos = 1;
break;
}
default: {
memset(&s, 0, sizeof(s));
s.zJson = (char*)sqlite3_value_text(argv[0]);
s.nJson = sqlite3_value_bytes(argv[0]);
if( s.nJson==0 ){
iErrPos = 1;
break;
}
if( s.zJson==0 ){
sqlite3_result_error_nomem(ctx);
return;
}
if( jsonConvertTextToBlob(&s,0) ){
u32 k;
if( s.oom ){
sqlite3_result_error_nomem(ctx);
jsonParseReset(&s);
return;
}
/* Convert byte-offset s.iErr into a character offset */
for(k=0; k<s.iErr && s.zJson[k]; k++){
if( (s.zJson[k] & 0xc0)!=0x80 ) iErrPos++;
}
iErrPos++;
}
jsonParseReset(&s);
}
sqlite3_result_int(ctx, n);
jsonParseFree(p);
}
sqlite3_result_int64(ctx, iErrPos);
}