summaryrefslogtreecommitdiff
path: root/ext/pdo_sqlite/sqlite/src/select.c
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2007-04-18 22:53:46 +0000
committerIlia Alshanetsky <iliaa@php.net>2007-04-18 22:53:46 +0000
commit111df261a58e2dec22b1e6375edcced5ca547344 (patch)
tree5f9dc5caa9926768f8b81540bfe0e4ba8d75e37b /ext/pdo_sqlite/sqlite/src/select.c
parent6a0efe0b7d4833249b500646be207996ed0ab822 (diff)
downloadphp-git-111df261a58e2dec22b1e6375edcced5ca547344.tar.gz
Upgraded SQLite 3 to version 3.3.16
Diffstat (limited to 'ext/pdo_sqlite/sqlite/src/select.c')
-rw-r--r--ext/pdo_sqlite/sqlite/src/select.c53
1 files changed, 30 insertions, 23 deletions
diff --git a/ext/pdo_sqlite/sqlite/src/select.c b/ext/pdo_sqlite/sqlite/src/select.c
index 59120b32ee..120470b565 100644
--- a/ext/pdo_sqlite/sqlite/src/select.c
+++ b/ext/pdo_sqlite/sqlite/src/select.c
@@ -551,6 +551,7 @@ static int selectInnerLoop(
sqlite3VdbeAddOp(v, OP_NotNull, -1, addr1+3);
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
addr2 = sqlite3VdbeAddOp(v, OP_Goto, 0, 0);
+ p->affinity = sqlite3CompareAffinity(pEList->a[0].pExpr,(iParm>>16)&0xff);
if( pOrderBy ){
/* At first glance you would think we could optimize out the
** ORDER BY in this case since the order of entries in the set
@@ -558,9 +559,7 @@ static int selectInnerLoop(
** case the order does matter */
pushOntoSorter(pParse, pOrderBy, p);
}else{
- char affinity = (iParm>>16)&0xFF;
- affinity = sqlite3CompareAffinity(pEList->a[0].pExpr, affinity);
- sqlite3VdbeOp3(v, OP_MakeRecord, 1, 0, &affinity, 1);
+ sqlite3VdbeOp3(v, OP_MakeRecord, 1, 0, &p->affinity, 1);
sqlite3VdbeAddOp(v, OP_IdxInsert, (iParm&0x0000FFFF), 0);
}
sqlite3VdbeJumpHere(v, addr2);
@@ -721,7 +720,7 @@ static void generateSortTail(
sqlite3VdbeAddOp(v, OP_NotNull, -1, sqlite3VdbeCurrentAddr(v)+3);
sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
sqlite3VdbeAddOp(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+3);
- sqlite3VdbeOp3(v, OP_MakeRecord, 1, 0, "c", P3_STATIC);
+ sqlite3VdbeOp3(v, OP_MakeRecord, 1, 0, &p->affinity, 1);
sqlite3VdbeAddOp(v, OP_IdxInsert, (iParm&0x0000FFFF), 0);
break;
}
@@ -1096,7 +1095,7 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){
sqlite3Dequote(zName);
if( sqlite3MallocFailed() ){
sqliteFree(zName);
- sqlite3DeleteTable(0, pTab);
+ sqlite3DeleteTable(pTab);
return 0;
}
@@ -1400,8 +1399,11 @@ static int matchOrderbyToColumn(
}
pEList = pSelect->pEList;
for(i=0; i<pOrderBy->nExpr; i++){
+ struct ExprList_item *pItem;
Expr *pE = pOrderBy->a[i].pExpr;
int iCol = -1;
+ char *zLabel;
+
if( pOrderBy->a[i].done ) continue;
if( sqlite3ExprIsInteger(pE, &iCol) ){
if( iCol<=0 || iCol>pEList->nExpr ){
@@ -1414,20 +1416,23 @@ static int matchOrderbyToColumn(
if( !mustComplete ) continue;
iCol--;
}
- for(j=0; iCol<0 && j<pEList->nExpr; j++){
- if( pEList->a[j].zName && (pE->op==TK_ID || pE->op==TK_STRING) ){
- char *zName, *zLabel;
- zName = pEList->a[j].zName;
- zLabel = sqlite3NameFromToken(&pE->token);
- assert( zLabel!=0 );
- if( sqlite3StrICmp(zName, zLabel)==0 ){
+ if( iCol<0 && (zLabel = sqlite3NameFromToken(&pE->token))!=0 ){
+ for(j=0, pItem=pEList->a; j<pEList->nExpr; j++, pItem++){
+ char *zName;
+ int isMatch;
+ if( pItem->zName ){
+ zName = sqlite3StrDup(pItem->zName);
+ }else{
+ zName = sqlite3NameFromToken(&pItem->pExpr->token);
+ }
+ isMatch = zName && sqlite3StrICmp(zName, zLabel)==0;
+ sqliteFree(zName);
+ if( isMatch ){
iCol = j;
+ break;
}
- sqliteFree(zLabel);
- }
- if( iCol<0 && sqlite3ExprCompare(pE, pEList->a[j].pExpr) ){
- iCol = j;
}
+ sqliteFree(zLabel);
}
if( iCol>=0 ){
pE->op = TK_COLUMN;
@@ -1435,8 +1440,7 @@ static int matchOrderbyToColumn(
pE->iTable = iTable;
pE->iAgg = -1;
pOrderBy->a[i].done = 1;
- }
- if( iCol<0 && mustComplete ){
+ }else if( mustComplete ){
sqlite3ErrorMsg(pParse,
"ORDER BY term number %d does not match any result column", i+1);
nErr++;
@@ -2212,7 +2216,7 @@ static int flattenSubquery(
int nSubSrc = pSubSrc->nSrc;
int jointype = pSubitem->jointype;
- sqlite3DeleteTable(0, pSubitem->pTab);
+ sqlite3DeleteTable(pSubitem->pTab);
sqliteFree(pSubitem->zDatabase);
sqliteFree(pSubitem->zName);
sqliteFree(pSubitem->zAlias);
@@ -2590,12 +2594,15 @@ int sqlite3SelectResolve(
*/
sNC.pEList = p->pEList;
if( sqlite3ExprResolveNames(&sNC, p->pWhere) ||
- sqlite3ExprResolveNames(&sNC, p->pHaving) ||
- processOrderGroupBy(&sNC, p->pOrderBy, "ORDER") ||
- processOrderGroupBy(&sNC, pGroupBy, "GROUP")
- ){
+ sqlite3ExprResolveNames(&sNC, p->pHaving) ){
return SQLITE_ERROR;
}
+ if( p->pPrior==0 ){
+ if( processOrderGroupBy(&sNC, p->pOrderBy, "ORDER") ||
+ processOrderGroupBy(&sNC, pGroupBy, "GROUP") ){
+ return SQLITE_ERROR;
+ }
+ }
/* Make sure the GROUP BY clause does not contain aggregate functions.
*/