~ubuntu-branches/ubuntu/hardy/sqlite3/hardy

« back to all changes in this revision

Viewing changes to src/select.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-07-23 14:35:04 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20070723143504-v52h2illx871jas3
Tags: 3.4.1-0ubuntu1
New upstream release. Closes LP: #127223.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
** This file contains C code routines that are called by the parser
13
13
** to handle SELECT statements in SQLite.
14
14
**
15
 
** $Id: select.c,v 1.351 2007/06/15 15:31:50 drh Exp $
 
15
** $Id: select.c,v 1.354 2007/07/18 18:17:12 drh Exp $
16
16
*/
17
17
#include "sqliteInt.h"
18
18
 
186
186
}
187
187
 
188
188
/*
 
189
** Set the token to the double-quoted and escaped version of the string pointed
 
190
** to by z. For example;
 
191
**
 
192
**    {a"bc}  ->  {"a""bc"}
 
193
*/
 
194
static void setQuotedToken(Token *p, const char *z){
 
195
  p->z = (u8 *)sqlite3MPrintf("\"%w\"", z);
 
196
  p->dyn = 1;
 
197
  if( p->z ){
 
198
    p->n = strlen((char *)p->z);
 
199
  }
 
200
}
 
201
 
 
202
/*
189
203
** Create an expression node for an identifier with the name of zName
190
204
*/
191
205
Expr *sqlite3CreateIdExpr(const char *zName){
1320
1334
            Expr *pExpr, *pRight;
1321
1335
            char *zName = pTab->aCol[j].zName;
1322
1336
 
 
1337
            /* If a column is marked as 'hidden' (currently only possible
 
1338
            ** for virtual tables), do not include it in the expanded
 
1339
            ** result-set list.
 
1340
            */
 
1341
            if( IsHiddenColumn(&pTab->aCol[j]) ){
 
1342
              assert(IsVirtual(pTab));
 
1343
              continue;
 
1344
            }
 
1345
 
1323
1346
            if( i>0 ){
1324
1347
              struct SrcList_item *pLeft = &pTabList->a[i-1];
1325
1348
              if( (pLeft[1].jointype & JT_NATURAL)!=0 &&
1336
1359
            }
1337
1360
            pRight = sqlite3Expr(TK_ID, 0, 0, 0);
1338
1361
            if( pRight==0 ) break;
1339
 
            setToken(&pRight->token, zName);
 
1362
            setQuotedToken(&pRight->token, zName);
1340
1363
            if( zTabName && (longNames || pTabList->nSrc>1) ){
1341
1364
              Expr *pLeft = sqlite3Expr(TK_ID, 0, 0, 0);
1342
1365
              pExpr = sqlite3Expr(TK_DOT, pLeft, pRight, 0);
1343
1366
              if( pExpr==0 ) break;
1344
 
              setToken(&pLeft->token, zTabName);
 
1367
              setQuotedToken(&pLeft->token, zTabName);
1345
1368
              setToken(&pExpr->span, sqlite3MPrintf("%s.%s", zTabName, zName));
1346
1369
              pExpr->span.dyn = 1;
1347
1370
              pExpr->token.z = 0;
1350
1373
            }else{
1351
1374
              pExpr = pRight;
1352
1375
              pExpr->span = pExpr->token;
 
1376
              pExpr->span.dyn = 0;
1353
1377
            }
1354
1378
            if( longNames ){
1355
1379
              pNew = sqlite3ExprListAppend(pNew, pExpr, &pExpr->span);
1376
1400
    sqlite3ErrorMsg(pParse, "too many columns in result set");
1377
1401
    rc = SQLITE_ERROR;
1378
1402
  }
 
1403
  if( sqlite3MallocFailed() ){
 
1404
    rc = SQLITE_NOMEM;
 
1405
  }
1379
1406
  return rc;
1380
1407
}
1381
1408
 
2487
2514
      sqlite3VdbeAddOp(v, OP_MakeRecord, 1, 0);
2488
2515
      seekOp = OP_MoveGt;
2489
2516
    }
 
2517
    if( pIdx->aSortOrder[0]==SQLITE_SO_DESC ){
 
2518
      /* Ticket #2514: invert the seek operator if we are using
 
2519
      ** a descending index. */
 
2520
      if( seekOp==OP_Last ){
 
2521
        seekOp = OP_Rewind;
 
2522
      }else{
 
2523
        assert( seekOp==OP_MoveGt );
 
2524
        seekOp = OP_MoveLt;
 
2525
      }
 
2526
    }
2490
2527
    sqlite3VdbeAddOp(v, seekOp, iIdx, 0);
2491
2528
    sqlite3VdbeAddOp(v, OP_IdxRowid, iIdx, 0);
2492
2529
    sqlite3VdbeAddOp(v, OP_Close, iIdx, 0);