UnQL

Check-in [e4cab3b6a0]
Login

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

Overview
Comment:Fix for queries that feature sub-selects in the FROM clause.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e4cab3b6a030862532fd2f8c99fa2e0709953b10
User & Date: dan 2011-07-18 11:15:04
Context
2011-07-19
13:14
Add support for ORDER BY on SELECT queries. check-in: a399717a11 user: dan tags: trunk
2011-07-18
11:15
Fix for queries that feature sub-selects in the FROM clause. check-in: e4cab3b6a0 user: dan tags: trunk
09:39
Fix handling of "AS" in FROM clauses. check-in: e7c27a9690 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/datasrc.c.

    62     62         if( rc==XJD1_DONE ){
    63     63           xjd1DataSrcRewind(p->u.join.pRight);
    64     64           rc = xjd1DataSrcStep(p->u.join.pLeft);
    65     65         }
    66     66         break;
    67     67       }
    68     68       case TK_SELECT: {
           69  +      xjd1JsonFree(p->pValue);
           70  +      p->pValue = 0;
    69     71         rc = xjd1QueryStep(p->u.subq.q);
           72  +      p->pValue = xjd1QueryDoc(p->u.subq.q, 0);
    70     73         break;
    71     74       }
    72     75       case TK_ID: {
    73     76         rc = sqlite3_step(p->u.tab.pStmt);
    74     77         xjd1JsonFree(p->pValue);
    75     78         p->pValue = 0;
    76     79         if( rc==SQLITE_ROW ){
................................................................................
   109    112     switch( p->eDSType ){
   110    113       case TK_COMMA: {
   111    114         pRes = xjd1DataSrcDoc(p->u.join.pLeft, zDocName);
   112    115         if( pRes==0 ) pRes = xjd1DataSrcDoc(p->u.join.pRight, zDocName);
   113    116         break;
   114    117       }
   115    118       case TK_SELECT: {
   116         -      pRes = xjd1QueryDoc(p->u.subq.q, zDocName);
          119  +      assert( p->zAs );
          120  +      if( zDocName==0 ){
          121  +        pRes = xjd1JsonRef(p->pValue);
          122  +      }
   117    123         break;
   118    124       }
   119    125       case TK_ID: {
   120    126         if( zDocName==0 || (p->zAs==0 && strcmp(p->u.tab.zName, zDocName)==0) ){
   121    127           pRes = xjd1JsonRef(p->pValue);
   122    128         }
   123    129         break;

Changes to test/base02.test.

   165    165   SELECT c3.two FROM c3 AS x;
   166    166   .result null null
   167    167   
   168    168   .testcase 22
   169    169   SELECT x FROM c3 AS x;
   170    170   SELECT c3 FROM c3 AS x;
   171    171   .result {"one":1,"two":2} null
          172  +
          173  +.testcase 23
          174  +SELECT FROM (SELECT FROM c3) AS x;
          175  +.result {"one":1,"two":2} 
          176  +
          177  +.testcase 24
          178  +SELECT FROM (SELECT {one:c3.two, two:c3.one} FROM c3) AS x;
          179  +.result {"one":2,"two":1} 
          180  +
          181  +.testcase 25
          182  +SELECT x FROM (SELECT {one:c3.two, two:c3.one} FROM c3) AS x;
          183  +.result {"one":2,"two":1} 
          184  +
          185  +.testcase 26
          186  +SELECT x.one FROM (SELECT {one:c3.two, two:c3.one} FROM c3) AS x;
          187  +.result 2
          188  +
          189  +.testcase 27
          190  +SELECT c3 FROM (SELECT {one:c3.two, two:c3.one} FROM c3) AS x;
          191  +.result null
          192  +
          193  +.testcase 28
          194  +SELECT xyz FROM (SELECT {one:c3.two, two:c3.one} FROM c3) AS x;
          195  +.result null
   172    196