UnQL

Check-in [d5e5efe19b]
Login

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

Overview
Comment:Added initial support for array-style lhs in the UPDATE command. Assignments that would grow an array are still unimplemented, as is accessing characters of a string using the array syntax.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d5e5efe19b1b15cf4b965d871f7ae750d5e71935
User & Date: pnr 2011-08-09 21:44:54
Original Comment: Added initial support for array-style lhs in the UPDATE command: a["x"], a[3] Assignments that would grow an array are still unimplemented, as is accessing characters of a string using the [] syntax.
Context
2011-08-11
23:04
Completed handling of array-style lhs in UPDATE. Some semantics need review. Leaf check-in: 8facf6305c user: pnr tags: trunk
2011-08-09
21:44
Added initial support for array-style lhs in the UPDATE command. Assignments that would grow an array are still unimplemented, as is accessing characters of a string using the array syntax. check-in: d5e5efe19b user: pnr tags: trunk
2011-08-02
11:18
minor fixups to compile with windows compilers check-in: 7797f759da user: pnr tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/update.c.

54
55
56
57
58
59
60



61
62
63
64













65

























66

67




68
69
70
71
72
73
74
/*
** The expression p is an L-value.  Find the corresponding JsonNode.
** Create it if necessary.
*/
static JsonNode *findOrCreateJsonNode(JsonNode *pRoot, Expr *p){
  if( p==0 ) return 0;
  switch( p->eType ){



    case TK_DOT: {
      JsonNode *pBase = findOrCreateJsonNode(pRoot, p->u.lvalue.pLeft);
      return findStructElement(pBase, p->u.lvalue.zId);
    }













    case TK_LB: {

























      return 0;   /* TBD */

    }




    case TK_ID: {
      return pRoot;
    }
  }
  return 0;
}








>
>
>




>
>
>
>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
|
>
>
>
>







54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
** The expression p is an L-value.  Find the corresponding JsonNode.
** Create it if necessary.
*/
static JsonNode *findOrCreateJsonNode(JsonNode *pRoot, Expr *p){
  if( p==0 ) return 0;
  switch( p->eType ){
    /* The x.y operator. Here y must be an identifier, and we use its
    ** name string. The reference node is property y of object x.
    */
    case TK_DOT: {
      JsonNode *pBase = findOrCreateJsonNode(pRoot, p->u.lvalue.pLeft);
      return findStructElement(pBase, p->u.lvalue.zId);
    }

    /* The x[y] operator. The result depends on the type of value x.
    **
    ** If x is of type XJD1_STRUCT, then expression y is converted to
    ** a string. The reference node is property y of object x.
    **
    ** If x is of type XJD1_ARRAY, then expression y is converted to
    ** a number. If that number is an integer, then reference node is
    ** element y of array x. ** TBD: extending array size as needed **
    **
    ** If x is of type XJD1_STRING, then it is treated as an array of 
    ** characters. Processing proceeds as for XJD1_ARRAY. ** TBD **
    */
    case TK_LB: {
      JsonNode *pBase = findOrCreateJsonNode(pRoot, p->u.bi.pLeft);
      switch( pBase->eJType ){
        case XJD1_STRUCT: {
          JsonNode *pRes;
          String idx;
          xjd1StringInit(&idx, 0, 0);
          xjd1JsonToString(xjd1ExprEval(p->u.bi.pRight), &idx);
          pRes = findStructElement(pBase, idx.zBuf);
          xjd1StringClear(&idx);
          return pRes;
        }

        case XJD1_ARRAY: {
          double rRight;
          int iIdx;
          if( xjd1JsonToReal(xjd1ExprEval(p->u.bi.pRight), &rRight) ) break;
          iIdx = (int)rRight;
          if( (double)iIdx==rRight && iIdx>=0 && iIdx<pBase->u.ar.nElem ){
            return pBase->u.ar.apElem[iIdx];
            
          }
          break;
        }

        case XJD1_STRING: {
          /* TBD */
          break;
        }
      }
    }
    break;
      
    case TK_ID: {
      return pRoot;
    }
  }
  return 0;
}