UnQL

Check-in [0ae879da94]
Login

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

Overview
Comment:Allow an "AS <id>" alias following the result expression of a SELECT.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0ae879da947d0d4b71e69495cabbd498cd9f3551
User & Date: dan 2011-07-23 14:58:55
Context
2011-07-23
15:13
Update the syntax diagrams to include CREATE and DROP INDEX statements. check-in: fda26c957b user: drh tags: trunk
14:58
Allow an "AS <id>" alias following the result expression of a SELECT. check-in: 0ae879da94 user: dan tags: trunk
11:52
Change the way OFFSET, LIMIT and ORDER BY are handled internally. check-in: dbbf1a25b5 user: dan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/parse.y.

357
358
359
360
361
362
363

364
365
366
367
368
369
370
371
372

373
374
375
376
377
378
379
...
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435

436
437

438
439

440
441
442
443
444
445
446
  } GroupByHaving;

  /* Construct a simple query object */
  static Query *simpleQuery(
    Parse *p,
    int isDistinct,
    Expr *pRes,

    DataSrc *pFrom,
    Expr *pWhere,
    GroupByHaving *pGroupBy
  ){
    Query *pNew = xjd1PoolMallocZero(p->pPool, sizeof(*pNew));
    if( pNew ){
      pNew->eQType = TK_SELECT;
      pNew->u.simple.isDistinct = isDistinct;
      pNew->u.simple.pRes = pRes;

      pNew->u.simple.pFrom = pFrom;
      pNew->u.simple.pWhere = pWhere;
      pNew->u.simple.pGroupBy = pGroupBy ? pGroupBy->pGroupBy : 0;
      pNew->u.simple.pHaving = pGroupBy ? pGroupBy->pHaving : 0;
    }
    return pNew;
  }
................................................................................
    if( A->pOrderBy || A->pLimit ){
      xjd1ParseError(p, XJD1_SYNTAX, "syntax error");
    }
  }
}

selectcore(A) ::= SELECT 
  dist_opt(D) expr_opt(S) from(F) where_opt(W) groupby_opt(G).
  {A = simpleQuery(p,D,S,F,W,&G);}


%type dist_opt {int}
dist_opt(A) ::= .                    {A = 0;}
dist_opt(A) ::= DISTINCT.            {A = 1;}
dist_opt(A) ::= ALL.                 {A = 0;}

// The result set of an expression can be either an JSON expression
// or nothing.

//
%type expr_opt {Expr*}

expr_opt(A) ::= .                       {A = 0;}
expr_opt(A) ::= expr(X).                {A = X;}


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







>









>







 







|
|








|
>

<
>
|
|
>







357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
...
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439

440
441
442
443
444
445
446
447
448
449
450
  } GroupByHaving;

  /* Construct a simple query object */
  static Query *simpleQuery(
    Parse *p,
    int isDistinct,
    Expr *pRes,
    const char *zAs,
    DataSrc *pFrom,
    Expr *pWhere,
    GroupByHaving *pGroupBy
  ){
    Query *pNew = xjd1PoolMallocZero(p->pPool, sizeof(*pNew));
    if( pNew ){
      pNew->eQType = TK_SELECT;
      pNew->u.simple.isDistinct = isDistinct;
      pNew->u.simple.pRes = pRes;
      pNew->u.simple.zAs = zAs;
      pNew->u.simple.pFrom = pFrom;
      pNew->u.simple.pWhere = pWhere;
      pNew->u.simple.pGroupBy = pGroupBy ? pGroupBy->pGroupBy : 0;
      pNew->u.simple.pHaving = pGroupBy ? pGroupBy->pHaving : 0;
    }
    return pNew;
  }
................................................................................
    if( A->pOrderBy || A->pLimit ){
      xjd1ParseError(p, XJD1_SYNTAX, "syntax error");
    }
  }
}

selectcore(A) ::= SELECT 
  dist_opt(D) sel_result(S) from(F) where_opt(W) groupby_opt(G).
  {A = simpleQuery(p,D,S.pExpr,S.zAs,F,W,&G);}


%type dist_opt {int}
dist_opt(A) ::= .                    {A = 0;}
dist_opt(A) ::= DISTINCT.            {A = 1;}
dist_opt(A) ::= ALL.                 {A = 0;}

// The result set of an expression can be either an JSON expression
// or nothing. If it is a JSON expression, it may be given an alias
// using the "AS <id>" syntax.
//

%type sel_result {ExprItem}
sel_result(A) ::= .                       {A.pExpr=0;A.zAs=0;}
sel_result(A) ::= expr(X).                {A.pExpr=X;A.zAs=0;}
sel_result(A) ::= expr(X) AS ID(Y).       {A.pExpr=X;A.zAs=tokenStr(p, &Y);}

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

Changes to src/xjd1Int.h.

274
275
276
277
278
279
280

281
282
283
284
285
286
287
      ResultList left;            /* Sorted results of pLeft */
      ResultList right;           /* Sorted results of pRight */
      JsonNode *pOut;
    } compound;
    struct {                    /* For simple queries */
      int isDistinct;             /* True if the DISTINCT keyword is present */
      Expr *pRes;                 /* Result JSON string */

      DataSrc *pFrom;             /* The FROM clause */
      Expr *pWhere;               /* The WHERE clause */
      ExprList *pGroupBy;         /* The GROUP BY clause */
      Expr *pHaving;              /* The HAVING clause */
      Aggregate *pAgg;            /* Aggregation info. 0 for non-aggregates */
      ResultList grouped;         /* Grouped results, for GROUP BY queries */
      ResultList distincted;      /* Distinct results */







>







274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
      ResultList left;            /* Sorted results of pLeft */
      ResultList right;           /* Sorted results of pRight */
      JsonNode *pOut;
    } compound;
    struct {                    /* For simple queries */
      int isDistinct;             /* True if the DISTINCT keyword is present */
      Expr *pRes;                 /* Result JSON string */
      const char *zAs;            /* Alias assigned to result object (if any) */
      DataSrc *pFrom;             /* The FROM clause */
      Expr *pWhere;               /* The WHERE clause */
      ExprList *pGroupBy;         /* The GROUP BY clause */
      Expr *pHaving;              /* The HAVING clause */
      Aggregate *pAgg;            /* Aggregation info. 0 for non-aggregates */
      ResultList grouped;         /* Grouped results, for GROUP BY queries */
      ResultList distincted;      /* Distinct results */