/ Check-in [87f58730]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix the path lookup for objects so that it can handle quoted identifier names and non-alphanumerics in the identifier.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | json
Files: files | file ages | folders
SHA1: 87f5873004f69396baa7c67937342b4e32f79bda
User & Date: drh 2015-08-19 23:02:49
Context
2015-08-20
23:39
Merge the latest changes from trunk, including the table-valued function implementation. check-in: 10c44432 user: drh tags: json
2015-08-19
23:02
Fix the path lookup for objects so that it can handle quoted identifier names and non-alphanumerics in the identifier. check-in: 87f58730 user: drh tags: json
22:47
Add the json_each(JSON,PATH) table-valued-function. check-in: 3335ac17 user: drh tags: json
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/misc/json.c.

   699    699   */
   700    700   static JsonNode *jsonLookup(
   701    701     JsonParse *pParse,      /* The JSON to search */
   702    702     u32 iRoot,              /* Begin the search at this node */
   703    703     const char *zPath,      /* The path to search */
   704    704     int *pApnd              /* Append nodes to complete path if not NULL */
   705    705   ){
   706         -  u32 i, j, k;
          706  +  u32 i, j, k, nKey;
          707  +  const char *zKey;
   707    708     JsonNode *pRoot = &pParse->aNode[iRoot];
   708    709     if( zPath[0]==0 ) return pRoot;
   709    710     if( zPath[0]=='.' ){
   710    711       if( pRoot->eType!=JSON_OBJECT ) return 0;
   711    712       zPath++;
   712         -    for(i=0; isalnum(zPath[i]); i++){}
   713         -    if( i==0 ) return 0;
          713  +    if( zPath[0]=='"' ){
          714  +      zKey = zPath + 1;
          715  +      for(i=1; zPath[i] && zPath[i]!='"'; i++){}
          716  +      nKey = i-1;
          717  +      if( zPath[i] ) i++;
          718  +    }else{
          719  +      zKey = zPath;
          720  +      for(i=0; zPath[i] && zPath[i]!='.' && zPath[i]!='['; i++){}
          721  +      nKey = i;
          722  +    }
          723  +    if( nKey==0 ) return 0;
   714    724       j = 1;
   715    725       for(;;){
   716    726         while( j<=pRoot->n ){
   717         -        if( pRoot[j].n==i+2
   718         -         && strncmp(&pRoot[j].u.zJContent[1],zPath,i)==0
          727  +        if( pRoot[j].n==nKey+2
          728  +         && strncmp(&pRoot[j].u.zJContent[1],zKey,nKey)==0
   719    729           ){
   720    730             return jsonLookup(pParse, iRoot+j+1, &zPath[i], pApnd);
   721    731           }
   722    732           j++;
   723    733           j += jsonSize(&pRoot[j]);
   724    734         }
   725    735         if( (pRoot->jnFlags & JNODE_APPEND)==0 ) break;