-C Split\sthe\ssqlite3_complete()\sAPI\sout\sinto\sa\sseparate\ssource\sfile\sso\sthat\nin\sstatic\slinks\swhere\sit\sis\snot\sused\sit\swill\snot\stake\sup\sspace\sin\sthe\nresulting\sbinary.\s(CVS\s2594)
-D 2005-08-14T17:53:21
+C General\scode\scleanup\sresulting\sin\ssmaller\sfootprint.\s(CVS\s2595)
+D 2005-08-14T20:47:16
F Makefile.in b109ddb46a5550d0732dcd6caca01c123f6d5cdd
F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
F src/date.c 7444b0900a28da77e57e3337a636873cff0ae940
F src/delete.c be1fc25c9e109cd8cbab42a43ee696263da7c04b
F src/experimental.c 50c1e3b34f752f4ac10c36f287db095c2b61766d
-F src/expr.c cad7f9197587db4897192cf21a8629b3b102c682
+F src/expr.c 24eda6c0502250f3a4259be94d6962f87cd47d87
F src/func.c 5b12db87f0bc7d978eaf87c7a348ada5d1934da4
F src/hash.c 2b1b13f7400e179631c83a1be0c664608c8f021f
F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
F src/prepare.c fa0f6068d9b8ec6d5c419c65d4d8ff747d49c5c6
F src/printf.c 772b15c3395fa60bdbf3aaa03d480ecde38bf192
F src/random.c 90adff4e73a3b249eb4f1fc2a6ff9cf78c7233a4
-F src/select.c c611471052773b94af771693686bd5bcdbbb0dba
+F src/select.c f441648eb191dcf1e67ae61475ea3b40a0eeb787
F src/shell.c 86c16f0d534aa51cc82cf9f66903d4eb681580e7
F src/sqlite.h.in a3b75a6b2e66865fba4ec1b698d00c7d95fe27a2
F src/sqliteInt.h 40370b51b902b4789ca6d4a016d00fa981803661
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
F www/whentouse.tcl 528299b8316726dbcc5548e9aa0648c8b1bd055b
-P 94efd7908880c7d99c08ebc9a3437cfbefc42f7e
-R aba4d0123b815fe8fae7c07e56c29e43
+P 62b87751dea56c565bcc2aca88a2edda7dfc2a57
+R 8a2d641a343930304c476f8e7d5941a6
U drh
-Z a0b138cf78bbb402904383cc3a8c7ee1
+Z 4e9e4effacefcf4b222166a8ff8d216c
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
-** $Id: select.c,v 1.253 2005/07/08 17:13:47 drh Exp $
+** $Id: select.c,v 1.254 2005/08/14 20:47:16 drh Exp $
*/
#include "sqliteInt.h"
Token *apAll[3];
Token *p;
static const struct {
- const char *zKeyword;
+ const char zKeyword[8];
u8 nChar;
u8 code;
} keywords[] = {
p->dyn = 0;
}
+/*
+** Create an expression node for an identifier with the name of zName
+*/
+static Expr *createIdExpr(const char *zName){
+ Token dummy;
+ setToken(&dummy, zName);
+ return sqlite3Expr(TK_ID, 0, 0, &dummy);
+}
+
/*
** Add a term to the WHERE expression in *ppExpr that requires the
const char *zAlias2, /* Alias for second table. May be NULL */
Expr **ppExpr /* Add the equality term to this expression */
){
- Token dummy;
Expr *pE1a, *pE1b, *pE1c;
Expr *pE2a, *pE2b, *pE2c;
Expr *pE;
- setToken(&dummy, zCol);
- pE1a = sqlite3Expr(TK_ID, 0, 0, &dummy);
- pE2a = sqlite3Expr(TK_ID, 0, 0, &dummy);
+ pE1a = createIdExpr(zCol);
+ pE2a = createIdExpr(zCol);
if( zAlias1==0 ){
zAlias1 = pTab1->zName;
}
- setToken(&dummy, zAlias1);
- pE1b = sqlite3Expr(TK_ID, 0, 0, &dummy);
+ pE1b = createIdExpr(zAlias1);
if( zAlias2==0 ){
zAlias2 = pTab2->zName;
}
- setToken(&dummy, zAlias2);
- pE2b = sqlite3Expr(TK_ID, 0, 0, &dummy);
+ pE2b = createIdExpr(zAlias2);
pE1c = sqlite3Expr(TK_DOT, pE1b, pE1a, 0);
pE2c = sqlite3Expr(TK_DOT, pE2b, pE2a, 0);
pE = sqlite3Expr(TK_EQ, pE1c, pE2c, 0);
** stack into the sorter.
*/
static void pushOntoSorter(Parse *pParse, Vdbe *v, ExprList *pOrderBy){
- int i;
- for(i=0; i<pOrderBy->nExpr; i++){
- sqlite3ExprCode(pParse, pOrderBy->a[i].pExpr);
- }
+ sqlite3ExprCodeExprList(pParse, pOrderBy);
sqlite3VdbeAddOp(v, OP_MakeRecord, pOrderBy->nExpr, 0);
sqlite3VdbeAddOp(v, OP_SortInsert, 0, 0);
}
}
}else{
nColumn = pEList->nExpr;
- for(i=0; i<pEList->nExpr; i++){
- sqlite3ExprCode(pParse, pEList->a[i].pExpr);
- }
+ sqlite3ExprCodeExprList(pParse, pEList);
}
/* If the DISTINCT keyword was present on the SELECT statement
** part of the result.
*/
if( hasDistinct ){
+ int n = pEList->nExpr;
#if NULL_ALWAYS_DISTINCT
sqlite3VdbeAddOp(v, OP_IsNull, -pEList->nExpr, sqlite3VdbeCurrentAddr(v)+7);
#endif
/* Deliberately leave the affinity string off of the following
** OP_MakeRecord */
- sqlite3VdbeAddOp(v, OP_MakeRecord, pEList->nExpr * -1, 0);
+ sqlite3VdbeAddOp(v, OP_MakeRecord, -n, 0);
sqlite3VdbeAddOp(v, OP_Distinct, distinct, sqlite3VdbeCurrentAddr(v)+3);
- sqlite3VdbeAddOp(v, OP_Pop, pEList->nExpr+1, 0);
+ sqlite3VdbeAddOp(v, OP_Pop, n+1, 0);
sqlite3VdbeAddOp(v, OP_Goto, 0, iContinue);
VdbeComment((v, "# skip indistinct records"));
sqlite3VdbeAddOp(v, OP_IdxInsert, distinct, 0);
}
#endif /* #ifndef SQLITE_OMIT_SUBQUERY */
- /* Send the data to the callback function.
+ /* Send the data to the callback function or to a subroutine. In the
+ ** case of a subroutine, the subroutine itself is responsible for
+ ** popping the data from the stack.
*/
+ case SRT_Subroutine:
case SRT_Callback:
case SRT_Sorter: {
if( pOrderBy ){
sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0);
pushOntoSorter(pParse, v, pOrderBy);
+ }else if( eDest==SRT_Subroutine ){
+ sqlite3VdbeAddOp(v, OP_Gosub, 0, iParm);
}else{
- assert( eDest==SRT_Callback );
+ assert( eDest!=SRT_Sorter );
sqlite3VdbeAddOp(v, OP_Callback, nColumn, 0);
}
break;
}
- /* Invoke a subroutine to handle the results. The subroutine itself
- ** is responsible for popping the results off of the stack.
- */
- case SRT_Subroutine: {
- if( pOrderBy ){
- sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0);
- pushOntoSorter(pParse, v, pOrderBy);
- }else{
- sqlite3VdbeAddOp(v, OP_Gosub, 0, iParm);
- }
- break;
- }
-
#if !defined(SQLITE_OMIT_TRIGGER)
/* Discard the results. This is used for SELECT statements inside
** the body of a TRIGGER. The purpose of such selects is to call
int lbl1 = 0;
pParse->fillAgg = 1;
if( pGroupBy ){
- for(i=0; i<pGroupBy->nExpr; i++){
- sqlite3ExprCode(pParse, pGroupBy->a[i].pExpr);
- }
+ sqlite3ExprCodeExprList(pParse, pGroupBy);
/* No affinity string is attached to the following OP_MakeRecord
** because we do not need to do any coercion of datatypes. */
sqlite3VdbeAddOp(v, OP_MakeRecord, pGroupBy->nExpr, 0);