** This implementation parses JSON text at 250 MB/s, so it is hard to see
** how JSONB might improve on that.)
*/
+#if !defined(_SQLITEINT_H_)
#include "sqlite3ext.h"
+#endif
SQLITE_EXTENSION_INIT1
#include <assert.h>
#include <string.h>
}
}
+/*
+** Return a JsonNode and all its descendents as a JSON string.
+*/
+static void jsonReturnJson(
+ JsonNode *pNode, /* Node to return */
+ sqlite3_context *pCtx, /* Return value for this function */
+ sqlite3_value **aReplace /* Array of replacement values */
+){
+ JsonString s;
+ jsonInit(&s, pCtx);
+ jsonRenderNode(pNode, &s, aReplace);
+ jsonResult(&s);
+}
+
/*
** Make the JsonNode the return value of the function.
*/
}
case JSON_ARRAY:
case JSON_OBJECT: {
- JsonString s;
- jsonInit(&s, pCtx);
- jsonRenderNode(pNode, &s, aReplace);
- jsonResult(&s);
+ jsonReturnJson(pNode, pCtx, aReplace);
break;
}
}
if( zJson[i] ) i = -1;
}
if( i<0 ){
- if( pParse->oom && pCtx!=0 ) sqlite3_result_error_nomem(pCtx);
+ if( pCtx!=0 ){
+ if( pParse->oom ){
+ sqlite3_result_error_nomem(pCtx);
+ }else{
+ sqlite3_result_error(pCtx, "malformed JSON", -1);
+ }
+ }
jsonParseReset(pParse);
return 1;
}
){
JsonParse x; /* The parse */
if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return;
- jsonReturn(x.aNode, ctx, 0);
+ jsonReturnJson(x.aNode, ctx, 0);
jsonParseReset(&x);
}
}else{
zPath = 0;
}
- if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0]))==0 ){
- if( x.nNode ){
- JsonNode *pNode = x.aNode;
- if( zPath ) pNode = jsonLookup(&x, 0, zPath, 0);
- if( pNode->eType==JSON_ARRAY ){
- assert( (pNode->jnFlags & JNODE_APPEND)==0 );
- for(i=1; i<=pNode->n; n++){
- i += jsonNodeSize(&pNode[i]);
- }
+ if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return;
+ if( x.nNode ){
+ JsonNode *pNode = x.aNode;
+ if( zPath ) pNode = jsonLookup(&x, 0, zPath, 0);
+ if( pNode->eType==JSON_ARRAY ){
+ assert( (pNode->jnFlags & JNODE_APPEND)==0 );
+ for(i=1; i<=pNode->n; n++){
+ i += jsonNodeSize(&pNode[i]);
}
}
- jsonParseReset(&x);
- }
- if( !x.oom ) sqlite3_result_int64(ctx, n);
-}
-
-/*
-** json_check(JSON)
-**
-** Check the JSON argument to verify that it is well-formed. Return a
-** compacted version of the argument (with white-space removed) if the
-** argument is well-formed. Through an error if the argument is not
-** correctly formatted JSON.
-*/
-static void jsonCheckFunc(
- sqlite3_context *ctx,
- int argc,
- sqlite3_value **argv
-){
- JsonParse x; /* The parse */
- if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ){
- sqlite3_result_error(ctx, "malformed JSON", -1);
- return;
}
- jsonReturn(x.aNode, ctx, argv);
jsonParseReset(&x);
+ sqlite3_result_int64(ctx, n);
}
/*
if( pNode ) pNode->jnFlags |= JNODE_REMOVE;
}
if( (x.aNode[0].jnFlags & JNODE_REMOVE)==0 ){
- jsonReturn(x.aNode, ctx, 0);
+ jsonReturnJson(x.aNode, ctx, 0);
}
}
jsonParseReset(&x);
if( x.aNode[0].jnFlags & JNODE_REPLACE ){
sqlite3_result_value(ctx, argv[x.aNode[0].iVal]);
}else{
- jsonReturn(x.aNode, ctx, argv);
+ jsonReturnJson(x.aNode, ctx, argv);
}
}
jsonParseReset(&x);
if( x.aNode[0].jnFlags & JNODE_REPLACE ){
sqlite3_result_value(ctx, argv[x.aNode[0].iVal]);
}else{
- jsonReturn(x.aNode, ctx, argv);
+ jsonReturnJson(x.aNode, ctx, argv);
}
}
jsonSetDone:
JsonParse x; /* The parse */
int rc = 0;
- if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0]))==0
+ if( jsonParse(&x, 0, (const char*)sqlite3_value_text(argv[0]))==0
&& x.nNode>0
){
rc = 1;
{ "json_array", -1, 0, jsonArrayFunc },
{ "json_array_length", 1, 0, jsonArrayLengthFunc },
{ "json_array_length", 2, 0, jsonArrayLengthFunc },
- { "json_check", 1, 0, jsonCheckFunc },
{ "json_extract", 2, 0, jsonExtractFunc },
{ "json_insert", -1, 0, jsonSetFunc },
{ "json_object", -1, 0, jsonObjectFunc },
-C Fix\scompiler\swarnings\sin\srbu\scode.
-D 2015-08-28T16:41:45.530
+C Back\sout\sthe\sjson_check()\sroutine.\s\sInstead,\sthrow\san\serror\sif\sthe\sinput\sto\na\sjson\sfunction\s(other\sthan\sjson_valid())\sis\snot\svalid\sJSON.
+D 2015-08-28T20:07:40.320
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in e2218eb228374422969de7b1680eda6864affcef
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f
F ext/misc/fuzzer.c 4c84635c71c26cfa7c2e5848cf49fe2d2cfcd767
F ext/misc/ieee754.c b0362167289170627659e84173f5d2e8fee8566e
-F ext/misc/json1.c 0b2bf3f2c3786fd6873b5f9a89023912c28ac889
+F ext/misc/json1.c aa344845c2c211e8a7fd57ccd92901506dacdf5a
F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342
F ext/misc/percentile.c bcbee3c061b884eccb80e21651daaae8e1e43c63
F ext/misc/regexp.c af92cdaa5058fcec1451e49becc7ba44dba023dc
F test/jrnlmode.test 7864d59cf7f6e552b9b99ba0f38acd167edc10fa
F test/jrnlmode2.test 81610545a4e6ed239ea8fa661891893385e23a1d
F test/jrnlmode3.test 556b447a05be0e0963f4311e95ab1632b11c9eaa
-F test/json101.test 420fe3917c9a6a0fb7f967f1f641054509acd0e2
+F test/json101.test 5dfb181790c123123c8e7981d4d3c941b6cc8af4
F test/keyword1.test 37ef6bba5d2ed5b07ecdd6810571de2956599dff
F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63
F test/laststmtchanges.test ae613f53819206b3222771828d024154d51db200
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P a84cf4f5d326270a61faf4ff867260f2dd1e68a6
-R 25627e3633787096f1c6a6ac573b9337
-U dan
-Z 8fac2bb28cf0b676d514df6920f608e8
+P 0fdc36fe35ae2fc8e9688fe6c53437f4d47502d9
+R 72483a04f1004ed82fe324bdb4440aeb
+U drh
+Z 66ee5efb60acb350500ed2a1605628ef