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
diff --git a/src/expr.c b/src/expr.c
index 92ae657..4893d4a 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 @@
       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 490ee00..0ac9bd3 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 @@
   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 @@
       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 @@
       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 48a8c7d..415ad5f 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 @@
 ** a coredump.
 */
 case OP_ColumnName: {
-  p->azColName[pOp->p1] = pOp->p3 ? pOp->p3 : "";
+  p->azColName[pOp->p1] = pOp->p3;
   p->nCallback = 0;
   break;
 }