diff options
author | drh <drh@noemail.net> | 2008-07-09 01:39:44 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2008-07-09 01:39:44 +0000 |
commit | e49b146f305cb223efc99cf1a8656f672baac11d (patch) | |
tree | 8a5cd41a9bd2c5915a1858fe622bbe0db5b8a59b /src | |
parent | a9671a22b370710dfc89c0220cf02a1967ac869f (diff) | |
download | sqlite-e49b146f305cb223efc99cf1a8656f672baac11d.tar.gz sqlite-e49b146f305cb223efc99cf1a8656f672baac11d.zip |
Additional test coverage in select.c and expr.c. (CVS 5381)
FossilOrigin-Name: c6cf08477cc4d622a05ad6706cb9418cf7eea432
Diffstat (limited to 'src')
-rw-r--r-- | src/expr.c | 21 | ||||
-rw-r--r-- | src/select.c | 26 |
2 files changed, 18 insertions, 29 deletions
diff --git a/src/expr.c b/src/expr.c index 1929eb7d2..b6f55a19b 100644 --- a/src/expr.c +++ b/src/expr.c @@ -12,7 +12,7 @@ ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.384 2008/07/08 23:40:20 drh Exp $ +** $Id: expr.c,v 1.385 2008/07/09 01:39:44 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -246,7 +246,7 @@ static int codeCompare( addr = sqlite3VdbeAddOp4(pParse->pVdbe, opcode, in2, dest, in1, (void*)p4, P4_COLLSEQ); sqlite3VdbeChangeP5(pParse->pVdbe, p5); - if( p5 & SQLITE_AFF_MASK ){ + if( (p5 & SQLITE_AFF_MASK)!=SQLITE_AFF_NONE ){ sqlite3ExprCacheAffinityChange(pParse, in1, 1); sqlite3ExprCacheAffinityChange(pParse, in2, 1); } @@ -375,12 +375,15 @@ Expr *sqlite3Expr( pNew->pLeft = pLeft; pNew->pRight = pRight; pNew->iAgg = -1; + pNew->span.z = (u8*)""; if( pToken ){ assert( pToken->dyn==0 ); pNew->span = pNew->token = *pToken; }else if( pLeft ){ if( pRight ){ - sqlite3ExprSpan(pNew, &pLeft->span, &pRight->span); + if( pRight->span.dyn==0 && pLeft->span.dyn==0 ){ + sqlite3ExprSpan(pNew, &pLeft->span, &pRight->span); + } if( pRight->flags & EP_ExpCollate ){ pNew->flags |= EP_ExpCollate; pNew->pColl = pRight->pColl; @@ -456,19 +459,15 @@ Expr *sqlite3ExprAnd(sqlite3 *db, Expr *pLeft, Expr *pRight){ /* ** Set the Expr.span field of the given expression to span all -** text between the two given tokens. +** text between the two given tokens. Both tokens must be pointing +** at the same string. */ void sqlite3ExprSpan(Expr *pExpr, Token *pLeft, Token *pRight){ assert( pRight!=0 ); assert( pLeft!=0 ); if( pExpr && pRight->z && pLeft->z ){ - assert( pLeft->dyn==0 || pLeft->z[pLeft->n]==0 ); - if( pLeft->dyn==0 && pRight->dyn==0 ){ - pExpr->span.z = pLeft->z; - pExpr->span.n = pRight->n + (pRight->z - pLeft->z); - }else{ - pExpr->span.z = 0; - } + pExpr->span.z = pLeft->z; + pExpr->span.n = pRight->n + (pRight->z - pLeft->z); } } diff --git a/src/select.c b/src/select.c index 7bd7c59e9..f5ee47d92 100644 --- a/src/select.c +++ b/src/select.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.451 2008/07/08 23:40:20 drh Exp $ +** $Id: select.c,v 1.452 2008/07/09 01:39:44 drh Exp $ */ #include "sqliteInt.h" @@ -542,11 +542,7 @@ static void selectInnerLoop( if( v==0 ) return; assert( pEList!=0 ); - - /* If there was a LIMIT clause on the SELECT statement, then do the check - ** to see if this row should be output. - */ - hasDistinct = distinct>=0 && pEList->nExpr>0; + hasDistinct = distinct>=0; if( pOrderBy==0 && !hasDistinct ){ codeOffset(v, p, iContinue); } @@ -724,7 +720,9 @@ static void selectInnerLoop( /* Jump to the end of the loop if the LIMIT is reached. */ - if( p->iLimit && pOrderBy==0 ){ + if( p->iLimit ){ + assert( pOrderBy==0 ); /* If there is an ORDER BY, the call to + ** pushOntoSorter() would have cleared p->iLimit */ sqlite3VdbeAddOp2(v, OP_AddImm, p->iLimit, -1); sqlite3VdbeAddOp2(v, OP_IfZero, p->iLimit, iBreak); } @@ -1079,9 +1077,7 @@ static void generateColumnNames( if( pEList->a[i].zName ){ char *zName = pEList->a[i].zName; sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, strlen(zName)); - continue; - } - if( p->op==TK_COLUMN && pTabList ){ + }else if( p->op==TK_COLUMN && pTabList ){ Table *pTab; char *zCol; int iCol = p->iColumn; @@ -1095,7 +1091,7 @@ static void generateColumnNames( }else{ zCol = pTab->aCol[iCol].zName; } - if( !shortNames && !fullNames && p->span.z && p->span.z[0] ){ + if( !shortNames && !fullNames ){ sqlite3VdbeSetColName(v, i, COLNAME_NAME, (char*)p->span.z, p->span.n); }else if( fullNames || (!shortNames && pTabList->nSrc>1) ){ char *zName = 0; @@ -1108,14 +1104,8 @@ static void generateColumnNames( }else{ sqlite3VdbeSetColName(v, i, COLNAME_NAME, zCol, strlen(zCol)); } - }else if( p->span.z && p->span.z[0] ){ - sqlite3VdbeSetColName(v, i, COLNAME_NAME, (char*)p->span.z, p->span.n); - /* sqlite3VdbeCompressSpace(v, addr); */ }else{ - char zName[30]; - assert( p->op!=TK_COLUMN || pTabList==0 ); - sqlite3_snprintf(sizeof(zName), zName, "column%d", i+1); - sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, 0); + sqlite3VdbeSetColName(v, i, COLNAME_NAME, (char*)p->span.z, p->span.n); } } generateColumnTypes(pParse, pTabList, pEList); |