]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Enhance the (SQLITE_DEBUG-only) json_parse() routine so that it shows a
authordrh <>
Mon, 27 Nov 2023 17:13:18 +0000 (17:13 +0000)
committerdrh <>
Mon, 27 Nov 2023 17:13:18 +0000 (17:13 +0000)
decoding of JSONB when given a BLOB argument.

FossilOrigin-Name: af267868562e0799ad691dccad05f17afbc34d609eede8c55f57d209290246ef

manifest
manifest.uuid
src/json.c

index 188b5f527747f03468c97a23549470eabce51c78..0989187da0fb9a25988e62e29133ead431739546 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Give\sthe\sjson_valid()\sfunction\san\soptional\ssecond\sargument\sthat\sdetermines\nwhat\sis\smeant\sby\s"valid".
-D 2023-11-27T15:57:11.976
+C Enhance\sthe\s(SQLITE_DEBUG-only)\sjson_parse()\sroutine\sso\sthat\sit\sshows\sa\s\ndecoding\sof\sJSONB\swhen\sgiven\sa\sBLOB\sargument.
+D 2023-11-27T17:13:18.242
 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 6c1de0d7802a15669a78008125b409b67aa23eefcacfc52436d713419d09be9e
+F src/json.c aefd3bf7c225ad03e25680febb2659779a99b227cd98222270e16719b1251bdb
 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 ec18caa3f7790b780dde66c1ccbb6eb09d2f1507629cc45955fc1b08380b4017
-R ae458da46f597856d9232f7ad8297973
+P a4e19ad43dac81e7655ec03ff69bb99d1d02b0c227034c90fb41415fd4793fe3
+R 2b39f71294c83f1ae33c269e29617f78
 U drh
-Z 6c8b34340e171672e2ebcad369756a23
+Z ba17737c2ff9c3cb6da75654e948a46b
 # Remove this line to create a well-formed Fossil manifest.
index c418cd97809566d45ccb68e14ab486fe73aee269..5a42393c1011cc4d6d14e33dcf7bcf0f7f97f8bb 100644 (file)
@@ -1 +1 @@
-a4e19ad43dac81e7655ec03ff69bb99d1d02b0c227034c90fb41415fd4793fe3
\ No newline at end of file
+af267868562e0799ad691dccad05f17afbc34d609eede8c55f57d209290246ef
\ No newline at end of file
index 1107a24f4cfa90eba30ddd18780a15d5e275ad0b..e6729215212d3ac8f65c5413a224797b2a56e743 100644 (file)
@@ -4490,6 +4490,84 @@ static void jsonDebugPrintNodeEntries(
 }
 #endif /* SQLITE_DEBUG */
 
+#if SQLITE_DEBUG
+/*
+** Decode JSONB bytes in aBlob[] starting at iStart through but not 
+** including iEnd.  Indent the
+** content by nIndent spaces.
+*/
+static void jsonDebugPrintBlob(
+  JsonParse *pParse, /* JSON content */
+  u32 iStart,        /* Start rendering here */
+  u32 iEnd,          /* Do not render this byte or any byte after this one */
+  int nIndent        /* Indent by this many spaces */
+){
+  while( iStart<iEnd ){
+    u32 i, n, nn, sz = 0;
+    int showContent = 1;
+    u8 x = pParse->aBlob[iStart] & 0x0f;
+    printf("%5d:%*s", iStart, nIndent, "");
+    nn = n = jsonbPayloadSize(pParse, iStart, &sz);
+    if( nn==0 ) nn = 1;
+    if( sz>0 && x<JSONB_ARRAY ){
+      nn += sz;
+    }
+    for(i=0; i<nn; i++) printf(" %02x", pParse->aBlob[iStart+i]);
+    if( n==0 || iStart+n+sz>iEnd ){
+      printf("   ERROR invalid node size\n");
+      iStart = n==0 ? iStart+1 : iEnd;
+      continue;
+    }
+    printf("  <-- ");
+    switch( x ){
+      case JSONB_NULL:     printf("null"); break;
+      case JSONB_TRUE:     printf("true"); break;
+      case JSONB_FALSE:    printf("false"); break;
+      case JSONB_INT:      printf("int"); break;
+      case JSONB_INT5:     printf("int5"); break;
+      case JSONB_FLOAT:    printf("float"); break;
+      case JSONB_FLOAT5:   printf("float5"); break;
+      case JSONB_TEXT:     printf("text"); break;
+      case JSONB_TEXTJ:    printf("textj"); break;
+      case JSONB_TEXT5:    printf("text5"); break;
+      case JSONB_TEXTRAW:  printf("textraw"); break;
+      case JSONB_ARRAY: {
+        printf("array, %u bytes\n", sz);
+        jsonDebugPrintBlob(pParse, iStart+n, iStart+n+sz, nIndent+2);
+        showContent = 0;
+        break;
+      }
+      case JSONB_OBJECT: {
+        printf("object, %u bytes\n", sz);
+        jsonDebugPrintBlob(pParse, iStart+n, iStart+n+sz, nIndent+2);
+        showContent = 0;
+        break;
+      }
+      default: {
+        printf("ERROR: unknown node type\n");
+        showContent = 0;
+        break;
+      }
+    }
+    if( showContent ){
+      if( sz==0 && x<=JSON_FALSE ){
+        printf("\n");
+      }else{
+        u32 i;
+        printf(": \"");
+        for(i=iStart+n; i<iStart+n+sz; i++){
+          u8 c = pParse->aBlob[i];
+          if( c<0x20 || c>=0x7f ) c = '.';
+          putchar(c);
+        }
+        printf("\"\n");
+      }
+    }
+    iStart += n + sz;
+  }
+}
+#endif /* SQLITE_DEBUG */
+
 
 #if 0  /* 1 for debugging.  0 normally.  Requires -DSQLITE_DEBUG too */
 static void jsonDebugPrintParse(JsonParse *p){
@@ -4520,6 +4598,14 @@ static void jsonParseFunc(
   JsonParse *p;        /* The parse */
 
   assert( argc==1 );
+  if( jsonFuncArgMightBeBinary(argv[0]) ){
+    JsonParse x;
+    memset(&x, 0, sizeof(x));
+    x.nBlob = sqlite3_value_bytes(argv[0]);
+    x.aBlob = (u8*)sqlite3_value_blob(argv[0]);
+    jsonDebugPrintBlob(&x, 0, x.nBlob, 0);
+    return;
+  }
   p = jsonParseCached(ctx, argv[0], ctx, 0);
   if( p==0 ) return;
   printf("nNode     = %u\n", p->nNode);