UnQL

Check-in [7b79de2564]
Login

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

Overview
Comment:Fix the UPDATE command so that each changes is independent.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7b79de256484ae3a9d083c9e79a6f2fa835e65b2
User & Date: drh 2011-07-28 15:29:12
Context
2011-07-28
16:00
Add aggregate functions min(), max(), avg(), sum(), and array(). Enhance count() to accept either one or zero arguments. check-in: 0ef5e83925 user: dan tags: trunk
15:29
Fix the UPDATE command so that each changes is independent. check-in: 7b79de2564 user: drh tags: trunk
2011-07-27
16:23
Add the ".json" command to shell.c. ".json" is like ".result", but removes excess white-space and quotes unquoted identifiers from the test result before comparing it with the library output. This allows us to make test files more readable. check-in: 1e6ab63d25 user: dan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/json.c.

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
...
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
...
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145











146
147
148
149
150
151
152
    p->nRef++;
  }
  return p;
}


/*
** Return an editable JSON object.  A JSON object is editable if its
** reference count is exactly 1.  If the input JSON object has a reference
** count greater than 1, then make a copy and return the copy.
*/
JsonNode *xjd1JsonEdit(JsonNode *p){
  JsonNode *pNew;
  if( p==0 ) return 0;
  if( p->nRef==1 ) return p;
  pNew = xjd1JsonNew(0);
  if( pNew==0 ) return 0;
  pNew->eJType = p->eJType;
  pNew->u = p->u;
  switch( pNew->eJType ){
    case XJD1_STRING: {
      pNew->u.z = xjd1PoolDup(0, p->u.z, -1);
................................................................................
      pNew->u.ar.apElem = ap = xjd1_malloc( sizeof(JsonNode*)*p->u.ar.nElem );
      if( ap==0 ){
        pNew->eJType = XJD1_NULL;
      }else{
        int i;
        pNew->u.ar.nElem = p->u.ar.nElem;
        for(i=0; i<p->u.ar.nElem; i++){
          ap[i] = xjd1JsonRef(p->u.ar.apElem[i]);
        }
      }
      break;
    }
    case XJD1_STRUCT: {
      JsonStructElem *pSrc, *pDest, **ppPrev;
      ppPrev = &pNew->u.st.pFirst;
................................................................................
      for(pSrc=p->u.st.pFirst; pSrc; pSrc=pSrc->pNext){
        pNew->u.st.pLast = pDest = xjd1_malloc( sizeof(*pDest) );
        if( pDest==0 ) break;
        memset(pDest, 0, sizeof(*pDest));
        *ppPrev = pDest;
        ppPrev = &pDest->pNext;
        pDest->zLabel = xjd1PoolDup(0, pSrc->zLabel, -1);
        pDest->pValue = xjd1JsonRef(pSrc->pValue);
      }
      break;
    }
  }
  p->nRef--;
  return pNew;
}













/* Render a string as a string literal.
*/
void renderString(String *pOut, const char *z){
  int n, i, j, c;
  char *zOut;







|
<
<

|


<







 







|







 







|




<


>
>
>
>
>
>
>
>
>
>
>







90
91
92
93
94
95
96
97


98
99
100
101

102
103
104
105
106
107
108
...
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
...
128
129
130
131
132
133
134
135
136
137
138
139

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
    p->nRef++;
  }
  return p;
}


/*
** Return a deep copy of a JSON object.


*/
JsonNode *xjd1JsonDeepCopy(JsonNode *p){
  JsonNode *pNew;
  if( p==0 ) return 0;

  pNew = xjd1JsonNew(0);
  if( pNew==0 ) return 0;
  pNew->eJType = p->eJType;
  pNew->u = p->u;
  switch( pNew->eJType ){
    case XJD1_STRING: {
      pNew->u.z = xjd1PoolDup(0, p->u.z, -1);
................................................................................
      pNew->u.ar.apElem = ap = xjd1_malloc( sizeof(JsonNode*)*p->u.ar.nElem );
      if( ap==0 ){
        pNew->eJType = XJD1_NULL;
      }else{
        int i;
        pNew->u.ar.nElem = p->u.ar.nElem;
        for(i=0; i<p->u.ar.nElem; i++){
          ap[i] = xjd1JsonDeepCopy(p->u.ar.apElem[i]);
        }
      }
      break;
    }
    case XJD1_STRUCT: {
      JsonStructElem *pSrc, *pDest, **ppPrev;
      ppPrev = &pNew->u.st.pFirst;
................................................................................
      for(pSrc=p->u.st.pFirst; pSrc; pSrc=pSrc->pNext){
        pNew->u.st.pLast = pDest = xjd1_malloc( sizeof(*pDest) );
        if( pDest==0 ) break;
        memset(pDest, 0, sizeof(*pDest));
        *ppPrev = pDest;
        ppPrev = &pDest->pNext;
        pDest->zLabel = xjd1PoolDup(0, pSrc->zLabel, -1);
        pDest->pValue = xjd1JsonDeepCopy(pSrc->pValue);
      }
      break;
    }
  }

  return pNew;
}

/*
** Return an editable JSON object.  A JSON object is editable if its
** reference count is exactly 1.  If the input JSON object has a reference
** count greater than 1, then make a copy and return the copy.
*/
JsonNode *xjd1JsonEdit(JsonNode *p){
  if( p==0 ) return 0;
  if( p->nRef==1 ) return p;
  return xjd1JsonDeepCopy(p);
}


/* Render a string as a string literal.
*/
void renderString(String *pOut, const char *z){
  int n, i, j, c;
  char *zOut;

Changes to src/update.c.

122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
      pStmt->pDoc = xjd1JsonParse(zJson, -1);
      if( pCmd->u.update.pWhere==0 || xjd1ExprTrue(pCmd->u.update.pWhere) ){
        JsonNode *pNewDoc;  /* Revised document content */
        ExprList *pChng;    /* List of changes */
        String jsonNewDoc;  /* Text rendering of revised document */
        int i, n;

        pNewDoc  = xjd1JsonRef(pStmt->pDoc);
        pChng = pCmd->u.update.pChng;
        n = pChng->nEItem;
        for(i=0; i<n-1; i += 2){
          Expr *pLvalue = pChng->apEItem[i].pExpr;
          Expr *pExpr = pChng->apEItem[i+1].pExpr;
          reviseOneField(pNewDoc, pLvalue, pExpr);
        }







|







122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
      pStmt->pDoc = xjd1JsonParse(zJson, -1);
      if( pCmd->u.update.pWhere==0 || xjd1ExprTrue(pCmd->u.update.pWhere) ){
        JsonNode *pNewDoc;  /* Revised document content */
        ExprList *pChng;    /* List of changes */
        String jsonNewDoc;  /* Text rendering of revised document */
        int i, n;

        pNewDoc = xjd1JsonEdit(xjd1JsonRef(pStmt->pDoc));
        pChng = pCmd->u.update.pChng;
        n = pChng->nEItem;
        for(i=0; i<n-1; i += 2){
          Expr *pLvalue = pChng->apEItem[i].pExpr;
          Expr *pExpr = pChng->apEItem[i+1].pExpr;
          reviseOneField(pNewDoc, pLvalue, pExpr);
        }

Changes to src/xjd1Int.h.

437
438
439
440
441
442
443

444
445
446
447
448
449
450
JsonNode *xjd1JsonRef(JsonNode*);
void xjd1JsonRender(String*, const JsonNode*);
int xjd1JsonToReal(const JsonNode*, double*);
int xjd1JsonToString(const JsonNode*, String*);
int xjd1JsonCompare(const JsonNode*, const JsonNode*);
JsonNode *xjd1JsonNew(Pool*);
JsonNode *xjd1JsonEdit(JsonNode*);

void xjd1JsonFree(JsonNode*);
void xjd1JsonToNull(JsonNode*);
void xjd1DequoteString(char*,int);
int xjd1JsonInsert(JsonNode *, const char *, JsonNode *);
int xjd1JsonTidy(String *, const char *);

/******************************** memory.c ***********************************/







>







437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
JsonNode *xjd1JsonRef(JsonNode*);
void xjd1JsonRender(String*, const JsonNode*);
int xjd1JsonToReal(const JsonNode*, double*);
int xjd1JsonToString(const JsonNode*, String*);
int xjd1JsonCompare(const JsonNode*, const JsonNode*);
JsonNode *xjd1JsonNew(Pool*);
JsonNode *xjd1JsonEdit(JsonNode*);
JsonNode *xjd1JsonDeepCopy(JsonNode*);
void xjd1JsonFree(JsonNode*);
void xjd1JsonToNull(JsonNode*);
void xjd1DequoteString(char*,int);
int xjd1JsonInsert(JsonNode *, const char *, JsonNode *);
int xjd1JsonTidy(String *, const char *);

/******************************** memory.c ***********************************/