UnQL

Check-in [e7c27a9690]
Login

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

Overview
Comment:Fix handling of "AS" in FROM clauses.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e7c27a9690d1b75c750d0bd1d966a882cc30c8cf
User & Date: dan 2011-07-18 09:39:25
Context
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
2011-07-16
20:00
Add support for joins. check-in: 8c6e6a4ed7 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/datasrc.c.

99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
**
** xjd1JsonRef() has been called on the returned string.  The caller
** must invoke xjd1JsonFree().
*/
JsonNode *xjd1DataSrcDoc(DataSrc *p, const char *zDocName){
  JsonNode *pRes = 0;
  if( p==0 ) return 0;
  if( zDocName && p->zAs && strcmp(p->zAs, zDocName) ){
    return xjd1JsonRef(p->pValue);
  }
  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 || strcmp(p->u.tab.zName, zDocName)==0 ){
        pRes = xjd1JsonRef(p->pValue);
      }
      break;
    }
    default: {
      pRes = xjd1JsonRef(p->pValue);
      break;







|













|







99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
**
** xjd1JsonRef() has been called on the returned string.  The caller
** must invoke xjd1JsonFree().
*/
JsonNode *xjd1DataSrcDoc(DataSrc *p, const char *zDocName){
  JsonNode *pRes = 0;
  if( p==0 ) return 0;
  if( zDocName && p->zAs && 0==strcmp(p->zAs, zDocName) ){
    return xjd1JsonRef(p->pValue);
  }
  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;
    }
    default: {
      pRes = xjd1JsonRef(p->pValue);
      break;

Changes to test/base02.test.

149
150
151
152
153
154
155

















.result "a" "b" null "d" null null "a"

.testcase 20
SELECT [];
SELECT {};
.result [] {}

























>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
.result "a" "b" null "d" null null "a"

.testcase 20
SELECT [];
SELECT {};
.result [] {}

.testcase 21
CREATE COLLECTION c3;
INSERT INTO c3 VALUE { one: 1, two: 2 };
SELECT x.one FROM c3 AS x;
SELECT x.two FROM c3 AS x;
.result 1 2

.testcase 21
SELECT c3.one FROM c3 AS x;
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