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 Unified Diffs Ignore Whitespace Patch

Changes to src/datasrc.c.

62
63
64
65
66
67
68


69

70
71
72
73
74
75
76
...
109
110
111
112
113
114
115
116



117
118
119
120
121
122
123
      if( rc==XJD1_DONE ){
        xjd1DataSrcRewind(p->u.join.pRight);
        rc = xjd1DataSrcStep(p->u.join.pLeft);
      }
      break;
    }
    case TK_SELECT: {


      rc = xjd1QueryStep(p->u.subq.q);

      break;
    }
    case TK_ID: {
      rc = sqlite3_step(p->u.tab.pStmt);
      xjd1JsonFree(p->pValue);
      p->pValue = 0;
      if( rc==SQLITE_ROW ){
................................................................................
  switch( p->eDSType ){
    case TK_COMMA: {
      pRes = xjd1DataSrcDoc(p->u.join.pLeft, zDocName);
      if( pRes==0 ) pRes = xjd1DataSrcDoc(p->u.join.pRight, zDocName);
      break;
    }
    case TK_SELECT: {
      pRes = xjd1QueryDoc(p->u.subq.q, zDocName);



      break;
    }
    case TK_ID: {
      if( zDocName==0 || (p->zAs==0 && strcmp(p->u.tab.zName, zDocName)==0) ){
        pRes = xjd1JsonRef(p->pValue);
      }
      break;







>
>

>







 







|
>
>
>







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

Changes to test/base02.test.

165
166
167
168
169
170
171
172
























SELECT c3.two FROM c3 AS x;
.result null null

.testcase 22
SELECT x FROM c3 AS x;
SELECT c3 FROM c3 AS x;
.result {"one":1,"two":2} null

































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
SELECT c3.two FROM c3 AS x;
.result null null

.testcase 22
SELECT x FROM c3 AS x;
SELECT c3 FROM c3 AS x;
.result {"one":1,"two":2} null

.testcase 23
SELECT FROM (SELECT FROM c3) AS x;
.result {"one":1,"two":2} 

.testcase 24
SELECT FROM (SELECT {one:c3.two, two:c3.one} FROM c3) AS x;
.result {"one":2,"two":1} 

.testcase 25
SELECT x FROM (SELECT {one:c3.two, two:c3.one} FROM c3) AS x;
.result {"one":2,"two":1} 

.testcase 26
SELECT x.one FROM (SELECT {one:c3.two, two:c3.one} FROM c3) AS x;
.result 2

.testcase 27
SELECT c3 FROM (SELECT {one:c3.two, two:c3.one} FROM c3) AS x;
.result null

.testcase 28
SELECT xyz FROM (SELECT {one:c3.two, two:c3.one} FROM c3) AS x;
.result null