UnQL

Check-in [51c49e25e9]
Login

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

Overview
Comment:Allow JSON strings in the column list.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 51c49e25e944b03d271cba26c5868d94f89a129a
User & Date: drh 2011-06-27 17:56:39
Context
2011-06-28
13:46
Change the syntax so that the result specified in between SELECT and FROM keywords is a single JSON structure (actually any expression) rather than a SQL-style list. This check-in compiles and runs, but there are bugs so that the tests fail. check-in: 56a739ec3b user: drh tags: trunk
2011-06-27
17:56
Allow JSON strings in the column list. check-in: 51c49e25e9 user: drh tags: trunk
17:27
Reference counting of JsonNode objects. check-in: 0d3c641331 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/expr.c.

208
209
210
211
212
213
214
215
216
217

218
219
220





221
222
223
224
225
226
227
** Evaluate an expression.  Return the result as a JSON object.
**
** The caller must free the returned JSON by a call xjdJsonFree().
*/
JsonNode *xjd1ExprEval(Expr *p){
  JsonNode *pRes;
  double rLeft, rRight;
  pRes = xjd1JsonNew();
  if( pRes==0 ) return 0;
  if( p==0 ){

    pRes->eJType = XJD1_NULL;
    return pRes;
  }





  switch( p->eType ){
    case TK_INTEGER:
    case TK_FLOAT: {
      pRes->u.r = atof(p->u.tk.z);
      pRes->eJType = XJD1_REAL;
      break;
    }







<
<

>
|


>
>
>
>
>







208
209
210
211
212
213
214


215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
** Evaluate an expression.  Return the result as a JSON object.
**
** The caller must free the returned JSON by a call xjdJsonFree().
*/
JsonNode *xjd1ExprEval(Expr *p){
  JsonNode *pRes;
  double rLeft, rRight;


  if( p==0 ){
    pRes = xjd1JsonNew();
    if( pRes ) pRes->eJType = XJD1_NULL;
    return pRes;
  }
  if( p->eType==TK_JVALUE ){
    return xjd1JsonParse(p->u.tk.z, p->u.tk.n);
  }
  pRes = xjd1JsonNew();
  if( pRes==0 ) return 0;
  switch( p->eType ){
    case TK_INTEGER:
    case TK_FLOAT: {
      pRes->u.r = atof(p->u.tk.z);
      pRes->eJType = XJD1_REAL;
      break;
    }

Changes to src/parse.y.

303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
// selcollist is a list of expressions that are to become the return
// values of the SELECT statement.
//
%type selcollist_opt {ExprList*}
%type selcollist {ExprList*}
selcollist_opt(A) ::= .                             {A = 0;}
selcollist_opt(A) ::= selcollist(X).                {A = X;}
selcollist(A) ::= expr(Y).                          {A = apndExpr(p,0,Y,0);}
selcollist(A) ::= expr(Y) AS ID(Z).                 {A = apndExpr(p,0,Y,&Z);}
selcollist(A) ::= selcollist(X) COMMA expr(Y).      {A = apndExpr(p,X,Y,0);}
selcollist(A) ::= selcollist(X) COMMA expr(Y) AS ID(Z).
                                                    {A = apndExpr(p,X,Y,&Z);}

// A complete FROM clause.
//
%type from {DataSrc*}
%type fromlist {DataSrc*}
%type fromitem {DataSrc*}







|
|
|
|







303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
// selcollist is a list of expressions that are to become the return
// values of the SELECT statement.
//
%type selcollist_opt {ExprList*}
%type selcollist {ExprList*}
selcollist_opt(A) ::= .                             {A = 0;}
selcollist_opt(A) ::= selcollist(X).                {A = X;}
selcollist(A) ::= jexpr(Y).                         {A = apndExpr(p,0,Y,0);}
selcollist(A) ::= jexpr(Y) AS ID(Z).                {A = apndExpr(p,0,Y,&Z);}
selcollist(A) ::= selcollist(X) COMMA jexpr(Y).     {A = apndExpr(p,X,Y,0);}
selcollist(A) ::= selcollist(X) COMMA jexpr(Y) AS ID(Z).
                                                    {A = apndExpr(p,X,Y,&Z);}

// A complete FROM clause.
//
%type from {DataSrc*}
%type fromlist {DataSrc*}
%type fromitem {DataSrc*}

Changes to src/xjd1Int.h.

308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
int xjd1ExprListClose(ExprList*);

/******************************** json.c *************************************/
JsonNode *xjd1JsonParse(const char *zIn, int mxIn);
JsonNode *xjd1JsonRef(JsonNode*);
void xjd1JsonRender(String*, JsonNode*);
JsonNode *xjd1JsonNew(void);
JsonNode *xjd1JsonEditable(JsonNode*);
void xjd1JsonFree(JsonNode*);

/******************************** malloc.c ***********************************/
Pool *xjd1PoolNew(void);
void xjd1PoolClear(Pool*);
void xjd1PoolDelete(Pool*);
void *xjd1PoolMalloc(Pool*, int);







|







308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
int xjd1ExprListClose(ExprList*);

/******************************** json.c *************************************/
JsonNode *xjd1JsonParse(const char *zIn, int mxIn);
JsonNode *xjd1JsonRef(JsonNode*);
void xjd1JsonRender(String*, JsonNode*);
JsonNode *xjd1JsonNew(void);
JsonNode *xjd1JsonEdit(JsonNode*);
void xjd1JsonFree(JsonNode*);

/******************************** malloc.c ***********************************/
Pool *xjd1PoolNew(void);
void xjd1PoolClear(Pool*);
void xjd1PoolDelete(Pool*);
void *xjd1PoolMalloc(Pool*, int);

Changes to test/base01.test.

18
19
20
21
22
23
24




.testcase 130
SELECT 1 AS p, 2 AS q FROM abc;
.result {"p":1,"q":2}
.testcase 131
SELECT 1 AS p, 2+3 AS q FROM abc;
.result {"p":1,"q":5}










>
>
>
18
19
20
21
22
23
24
25
26
27

.testcase 130
SELECT 1 AS p, 2 AS q FROM abc;
.result {"p":1,"q":2}
.testcase 131
SELECT 1 AS p, 2+3 AS q FROM abc;
.result {"p":1,"q":5}
.testcase 132
SELECT 1 AS p, {"x":[1,2,3],"y":11} AS q FROM abc;
.result {"p":1,"q":{"x":[1,2,3],"y":11}}