From: drh Date: Sun, 23 Aug 2015 02:42:30 +0000 (+0000) Subject: Fixes to json_each() and json_tree(). Improved json_parse() debugging output. X-Git-Tag: version-3.9.0~200 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8784eca17f029b709852e8ca8aabfe73d7baf6f1;p=thirdparty%2Fsqlite.git Fixes to json_each() and json_tree(). Improved json_parse() debugging output. FossilOrigin-Name: fc1b24f316af07a64672f6edc14ebcff487dffbb --- diff --git a/ext/misc/json1.c b/ext/misc/json1.c index a68ef7469c..d5d7d5a96c 100644 --- a/ext/misc/json1.c +++ b/ext/misc/json1.c @@ -195,14 +195,6 @@ static void jsonPrintf(int N, JsonString *p, const char *zFormat, ...){ p->nUsed += (int)strlen(p->zBuf+p->nUsed); } -#ifdef SQLITE_DEBUG -/* Append the zero-terminated string zIn -*/ -static void jsonAppend(JsonString *p, const char *zIn){ - jsonAppendRaw(p, zIn, (u32)strlen(zIn)); -} -#endif - /* Append a single character */ static void jsonAppendChar(JsonString *p, char c){ @@ -468,14 +460,12 @@ static void jsonReturn( c = z[++i]; if( c=='u' && z[1] ){ u32 v = 0, k; - z++; - for(k=0; k<4 && z[k]; k++){ - c = z[0]; + for(k=0; k<4 && z[i+1]; i++, k++){ + c = z[i+1]; if( c>='0' && c<='9' ) v = v*16 + c - '0'; else if( c>='A' && c<='F' ) v = v*16 + c - 'A' + 10; else if( c>='a' && c<='f' ) v = v*16 + c - 'a' + 10; else break; - z++; } if( v<=0x7f ){ zOut[j++] = v; @@ -678,7 +668,11 @@ static int jsonParseValue(JsonParse *pParse, u32 i){ if( seenE ) return -1; seenDP = seenE = 1; c = pParse->zJson[j+1]; - if( c=='+' || c=='-' ) j++; + if( c=='+' || c=='-' ){ + j++; + c = pParse->zJson[j+1]; + } + if( c<'0' || c>'0' ) return -1; continue; } break; @@ -837,7 +831,7 @@ static JsonNode *jsonLookup( i = 0; zPath++; while( isdigit(zPath[0]) ){ - i = i + zPath[0] - '0'; + i = i*10 + zPath[0] - '0'; zPath++; } if( zPath[0]!=']' ) return 0; @@ -930,15 +924,14 @@ static void jsonParseFunc( JsonString s; /* Output string - not real JSON */ JsonParse x; /* The parse */ u32 i; - char zBuf[100]; assert( argc==1 ); if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return; + jsonParseFindParents(&x); jsonInit(&s, ctx); for(i=0; ibRecursive ){ if( p->i==0 ){ p->i = 1; - }else if( p->sParse.aNode[p->sParse.aUp[p->i]].eType==JSON_OBJECT ){ - p->i += 2; }else{ + u32 iUp = p->sParse.aUp[p->i]; + JsonNode *pUp = &p->sParse.aNode[iUp]; p->i++; + if( pUp->eType==JSON_OBJECT && (pUp->n + iUp >= p->i) ) p->i++; } p->iRowid++; if( p->isParse.nNode ){ - JsonNode *pUp = &p->sParse.aNode[p->sParse.aUp[p->i]]; + u32 iUp = p->sParse.aUp[p->i]; + JsonNode *pUp = &p->sParse.aNode[iUp]; p->eType = pUp->eType; - if( pUp->eType==JSON_ARRAY ) pUp->u.iKey++; - if( p->sParse.aNode[p->i].eType==JSON_ARRAY ){ - p->sParse.aNode[p->i].u.iKey = 0; + if( pUp->eType==JSON_ARRAY ){ + if( iUp==p->i-1 ){ + pUp->u.iKey = 0; + }else{ + pUp->u.iKey++; + } } } }else{ @@ -1490,13 +1488,14 @@ static int jsonEachColumn( JsonNode *pThis = &p->sParse.aNode[p->i]; switch( i ){ case JEACH_KEY: { + if( p->i==0 ) break; if( p->eType==JSON_OBJECT ){ jsonReturn(pThis, ctx, 0); }else if( p->eType==JSON_ARRAY ){ u32 iKey; if( p->bRecursive ){ if( p->iRowid==0 ) break; - iKey = p->sParse.aNode[p->sParse.aUp[p->i]].u.iKey - 1; + iKey = p->sParse.aNode[p->sParse.aUp[p->i]].u.iKey; }else{ iKey = p->iRowid; } @@ -1505,7 +1504,7 @@ static int jsonEachColumn( break; } case JEACH_VALUE: { - if( p->eType==JSON_OBJECT ) pThis++; + if( p->eType==JSON_OBJECT && p->i>0 ) pThis++; jsonReturn(pThis, ctx, 0); break; } @@ -1672,7 +1671,8 @@ static int jsonEachFilter( p->i = (int)(pNode - p->sParse.aNode); p->eType = pNode->eType; if( p->eType>=JSON_ARRAY ){ - p->i++; + pNode->u.iKey = 0; + if( !p->bRecursive ) p->i++; p->iEnd = p->i + pNode->n; }else{ p->iEnd = p->i+1; diff --git a/manifest b/manifest index f08dd2f05a..34b5e70a87 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sjson_valid()\sfunction\sto\sthe\sjson1.c\sextension.\s\sFix\svarious\sminor\nproblems\sin\sthe\sjson1.c\sextension. -D 2015-08-22T19:39:04.060 +C Fixes\sto\sjson_each()\sand\sjson_tree().\s\sImproved\sjson_parse()\sdebugging\soutput. +D 2015-08-23T02:42:30.942 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e2218eb228374422969de7b1680eda6864affcef F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -192,7 +192,7 @@ F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2 F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f F ext/misc/fuzzer.c 4c84635c71c26cfa7c2e5848cf49fe2d2cfcd767 F ext/misc/ieee754.c b0362167289170627659e84173f5d2e8fee8566e -F ext/misc/json1.c 88273dda16ac505b898be5ba90b29aaabbe37e71 +F ext/misc/json1.c 31bc1babd31190203cb86fcdbe21522756f65b12 F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342 F ext/misc/percentile.c bcbee3c061b884eccb80e21651daaae8e1e43c63 F ext/misc/regexp.c af92cdaa5058fcec1451e49becc7ba44dba023dc @@ -1378,7 +1378,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 213a6c5ccbcfe4495d45e3608e99a6398751aeed -R 71acf7e81664c832e0217a769189f3b7 +P 380a97345b446214843a63ccc017d49a52d884da +R a54dc4e155baa0caa5702a3578af52f1 U drh -Z 942f59d21b0c9aa639cfef239bb85f7f +Z b71b5a39d2829e2cd3b83f4646e372f9 diff --git a/manifest.uuid b/manifest.uuid index db562f929c..29702aa763 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -380a97345b446214843a63ccc017d49a52d884da \ No newline at end of file +fc1b24f316af07a64672f6edc14ebcff487dffbb \ No newline at end of file