u8 eType; /* Type of top-level element */
u8 bRecursive; /* True for json_tree(). False for json_each() */
char *zJson; /* Input JSON */
- char *zPath; /* Path by which to filter zJson */
+ char *zRoot; /* Path by which to filter zJson */
JsonParse sParse; /* Parse of the input JSON */
};
#define JEACH_ID 4
#define JEACH_PARENT 5
#define JEACH_FULLKEY 6
-#define JEACH_JSON 7
-#define JEACH_PATH 8
+#define JEACH_PATH 7
+#define JEACH_JSON 8
+#define JEACH_ROOT 9
UNUSED_PARAM(pzErr);
UNUSED_PARAM(argv);
UNUSED_PARAM(argc);
UNUSED_PARAM(pAux);
rc = sqlite3_declare_vtab(db,
- "CREATE TABLE x(key,value,type,atom,id,parent,fullkey,"
- "json HIDDEN,path HIDDEN)");
+ "CREATE TABLE x(key,value,type,atom,id,parent,fullkey,path,"
+ "json HIDDEN,root HIDDEN)");
if( rc==SQLITE_OK ){
pNew = *ppVtab = sqlite3_malloc( sizeof(*pNew) );
if( pNew==0 ) return SQLITE_NOMEM;
** held. */
static void jsonEachCursorReset(JsonEachCursor *p){
sqlite3_free(p->zJson);
- sqlite3_free(p->zPath);
+ sqlite3_free(p->zRoot);
jsonParseReset(&p->sParse);
p->iRowid = 0;
p->i = 0;
p->iEnd = 0;
p->eType = 0;
p->zJson = 0;
- p->zPath = 0;
+ p->zRoot = 0;
}
/* Destructor for a jsonEachCursor object */
if( p->bRecursive ){
jsonEachComputePath(p, &x, p->i);
}else{
- if( p->zPath ){
- jsonAppendRaw(&x, p->zPath, (int)strlen(p->zPath));
+ if( p->zRoot ){
+ jsonAppendRaw(&x, p->zRoot, (int)strlen(p->zRoot));
}else{
jsonAppendChar(&x, '$');
}
break;
}
case JEACH_PATH: {
- const char *zPath = p->zPath;
- if( zPath==0 ){
- if( p->bRecursive ){
- JsonString x;
- jsonInit(&x, ctx);
- jsonEachComputePath(p, &x, p->sParse.aUp[p->i]);
- jsonResult(&x);
- break;
- }
- zPath = "$";
+ if( p->bRecursive ){
+ JsonString x;
+ jsonInit(&x, ctx);
+ jsonEachComputePath(p, &x, p->sParse.aUp[p->i]);
+ jsonResult(&x);
+ break;
}
- sqlite3_result_text(ctx, zPath, -1, SQLITE_STATIC);
+ /* For json_each() path and root are the same so fall through
+ ** into the root case */
+ }
+ case JEACH_ROOT: {
+ const char *zRoot = p->zRoot;
+ if( zRoot==0 ) zRoot = "$";
+ sqlite3_result_text(ctx, zRoot, -1, SQLITE_STATIC);
break;
}
default: {
/* The query strategy is to look for an equality constraint on the json
** column. Without such a constraint, the table cannot operate. idxNum is
-** 1 if the constraint is found, 3 if the constraint and zPath are found,
+** 1 if the constraint is found, 3 if the constraint and zRoot are found,
** and 0 otherwise.
*/
static int jsonEachBestIndex(
){
int i;
int jsonIdx = -1;
- int pathIdx = -1;
+ int rootIdx = -1;
const struct sqlite3_index_constraint *pConstraint;
UNUSED_PARAM(tab);
if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
switch( pConstraint->iColumn ){
case JEACH_JSON: jsonIdx = i; break;
- case JEACH_PATH: pathIdx = i; break;
+ case JEACH_ROOT: rootIdx = i; break;
default: /* no-op */ break;
}
}
pIdxInfo->estimatedCost = 1.0;
pIdxInfo->aConstraintUsage[jsonIdx].argvIndex = 1;
pIdxInfo->aConstraintUsage[jsonIdx].omit = 1;
- if( pathIdx<0 ){
+ if( rootIdx<0 ){
pIdxInfo->idxNum = 1;
}else{
- pIdxInfo->aConstraintUsage[pathIdx].argvIndex = 2;
- pIdxInfo->aConstraintUsage[pathIdx].omit = 1;
+ pIdxInfo->aConstraintUsage[rootIdx].argvIndex = 2;
+ pIdxInfo->aConstraintUsage[rootIdx].omit = 1;
pIdxInfo->idxNum = 3;
}
}
){
JsonEachCursor *p = (JsonEachCursor*)cur;
const char *z;
- const char *zPath;
+ const char *zRoot;
sqlite3_int64 n;
UNUSED_PARAM(idxStr);
z = (const char*)sqlite3_value_text(argv[0]);
if( z==0 ) return SQLITE_OK;
if( idxNum&2 ){
- zPath = (const char*)sqlite3_value_text(argv[1]);
- if( zPath==0 ) return SQLITE_OK;
- if( zPath[0]!='$' ){
+ zRoot = (const char*)sqlite3_value_text(argv[1]);
+ if( zRoot==0 ) return SQLITE_OK;
+ if( zRoot[0]!='$' ){
sqlite3_free(cur->pVtab->zErrMsg);
- cur->pVtab->zErrMsg = jsonPathSyntaxError(zPath);
+ cur->pVtab->zErrMsg = jsonPathSyntaxError(zRoot);
return cur->pVtab->zErrMsg ? SQLITE_ERROR : SQLITE_NOMEM;
}
}
if( idxNum==3 ){
const char *zErr = 0;
n = sqlite3_value_bytes(argv[1]);
- p->zPath = sqlite3_malloc64( n+1 );
- if( p->zPath==0 ) return SQLITE_NOMEM;
- memcpy(p->zPath, zPath, (size_t)n+1);
- pNode = jsonLookupStep(&p->sParse, 0, p->zPath+1, 0, &zErr);
+ p->zRoot = sqlite3_malloc64( n+1 );
+ if( p->zRoot==0 ) return SQLITE_NOMEM;
+ memcpy(p->zRoot, zRoot, (size_t)n+1);
+ pNode = jsonLookupStep(&p->sParse, 0, p->zRoot+1, 0, &zErr);
if( p->sParse.nErr ){
sqlite3_free(cur->pVtab->zErrMsg);
cur->pVtab->zErrMsg = jsonPathSyntaxError(zErr);
-C Make\sthe\ssqlite3ext.h\sheader\sfile\sresponsive\sto\s-DSQLITE_OMIT_LOAD_EXTENSION.
-D 2015-09-10T15:24:27.984
+C Create\sseparate\s"path"\sand\s"root"\scolumns\sin\sthe\sjson_each()\sand\sjson_tree()\nvirtual\stables.\s\s"Root"\sis\sthe\s2nd\sparameter\sand\sis\sfixed.\s\s\n"Path"\svaries\sas\sjson_tree()\swalks\sthe\shierarchy.
+D 2015-09-10T17:20:57.334
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in f85066ce844a28b671aaeeff320921cd0ce36239
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 46c2aff110eb8241591cd29267ddb57a8d0ab337
+F ext/misc/json1.c 4387d091c0ec0f4d9ed05560960f03d366db4fe0
F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342
F ext/misc/percentile.c bcbee3c061b884eccb80e21651daaae8e1e43c63
F ext/misc/regexp.c af92cdaa5058fcec1451e49becc7ba44dba023dc
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P bb8ee3b140a0a8b7c89f5debf22369f204ceef0b
-R 9f03517d27368f0ee452371692eeb689
+P 47a46a9fa4a96cdb96a20b6aec802661b1ee4598
+R 8aee48c10c3e97ebfdd79a73a44181a5
U drh
-Z 40738b9489636e13edf984d114f41f8e
+Z 9f31b9d4db81b45c399857b6b93c0174