diff options
author | drh <drh@noemail.net> | 2002-06-26 02:45:03 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2002-06-26 02:45:03 +0000 |
commit | b13632063d5cfa89a076f3c4ed3dda62008e9f67 (patch) | |
tree | fdef69a1e0657bfddfe51396072849c0baba15fd /src | |
parent | 411995dc0d1611c8aa2a00c48d0c9cf756a34d98 (diff) | |
download | sqlite-b13632063d5cfa89a076f3c4ed3dda62008e9f67.tar.gz sqlite-b13632063d5cfa89a076f3c4ed3dda62008e9f67.zip |
The datatype of the i-th column in the result set is given by the
azColName(argc+1+i) parameter to the callback. (CVS 647)
FossilOrigin-Name: bdb006b809feb0f29342eb5138c0884d34e95599
Diffstat (limited to 'src')
-rw-r--r-- | src/expr.c | 18 | ||||
-rw-r--r-- | src/select.c | 22 | ||||
-rw-r--r-- | src/vdbe.c | 4 |
3 files changed, 38 insertions, 6 deletions
diff --git a/src/expr.c b/src/expr.c index 92ae65792..4893d4a86 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.73 2002/06/20 11:36:49 drh Exp $ +** $Id: expr.c,v 1.74 2002/06/26 02:45:04 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -889,6 +889,22 @@ int sqliteExprType(Expr *p){ p = p->pSelect->pEList->a[0].pExpr; break; + case TK_CASE: { + if( p->pRight && sqliteExprType(p->pRight)==SQLITE_SO_NUM ){ + return SQLITE_SO_NUM; + } + if( p->pList ){ + int i; + ExprList *pList = p->pList; + for(i=1; i<pList->nExpr; i+=2){ + if( sqliteExprType(pList->a[i].pExpr)==SQLITE_SO_NUM ){ + return SQLITE_SO_NUM; + } + } + } + return SQLITE_SO_TEXT; + } + default: assert( p->op==TK_ABORT ); /* Can't Happen */ break; diff --git a/src/select.c b/src/select.c index 490ee00d1..0ac9bd3a9 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.99 2002/06/24 22:01:58 drh Exp $ +** $Id: select.c,v 1.100 2002/06/26 02:45:04 drh Exp $ */ #include "sqliteInt.h" @@ -562,9 +562,10 @@ static void generateColumnNames( int i; if( pParse->colNamesSet || v==0 || sqlite_malloc_failed ) return; pParse->colNamesSet = 1; - sqliteVdbeAddOp(v, OP_ColumnCount, pEList->nExpr, 0); + sqliteVdbeAddOp(v, OP_ColumnCount, pEList->nExpr*2+1, 0); for(i=0; i<pEList->nExpr; i++){ Expr *p; + char *zType = 0; int showFullNames; if( pEList->a[i].zName ){ char *zName = pEList->a[i].zName; @@ -585,7 +586,13 @@ static void generateColumnNames( int iCol = p->iColumn; if( iCol<0 ) iCol = pTab->iPKey; assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) ); - zCol = iCol<0 ? "_ROWID_" : pTab->aCol[iCol].zName; + if( iCol<0 ){ + zCol = "_ROWID_"; + zType = "INTEGER"; + }else{ + zCol = pTab->aCol[iCol].zName; + zType = pTab->aCol[iCol].zType; + } if( pTabList->nSrc>1 || showFullNames ){ char *zName = 0; char *zTab; @@ -611,6 +618,15 @@ static void generateColumnNames( sqliteVdbeAddOp(v, OP_ColumnName, i, 0); sqliteVdbeChangeP3(v, -1, zName, strlen(zName)); } + if( zType==0 ){ + if( sqliteExprType(p)==SQLITE_SO_TEXT ){ + zType = "TEXT"; + }else{ + zType = "NUMERIC"; + } + } + sqliteVdbeAddOp(v, OP_ColumnName, i + pEList->nExpr + 1, 0); + sqliteVdbeChangeP3(v, -1, zType, P3_STATIC); } } diff --git a/src/vdbe.c b/src/vdbe.c index 48a8c7db8..415ad5f04 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -30,7 +30,7 @@ ** But other routines are also provided to help in building up ** a program instruction by instruction. ** -** $Id: vdbe.c,v 1.160 2002/06/25 13:16:04 drh Exp $ +** $Id: vdbe.c,v 1.161 2002/06/26 02:45:04 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -1578,7 +1578,7 @@ case OP_ColumnCount: { ** a coredump. */ case OP_ColumnName: { - p->azColName[pOp->p1] = pOp->p3 ? pOp->p3 : ""; + p->azColName[pOp->p1] = pOp->p3; p->nCallback = 0; break; } |