Fix many problems with manifest types and column affinity. Most things are
working now. (CVS 1393)

FossilOrigin-Name: ad4a964158ba9ca9d221cf7ea0439577f3894890
diff --git a/src/btree.c b/src/btree.c
index b4a5dcb..cb91dc3 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -9,7 +9,7 @@
 **    May you share freely, never taking more than you give.
 **
 *************************************************************************
-** $Id: btree.c,v 1.141 2004/05/16 16:24:37 drh Exp $
+** $Id: btree.c,v 1.142 2004/05/18 10:06:25 danielk1977 Exp $
 **
 ** This file implements a external (disk-based) database using BTrees.
 ** For a detailed discussion of BTrees, refer to
@@ -1406,6 +1406,15 @@
   return rc;
 }
 
+void sqlite3BtreeSetCompare(
+  BtCursor *pCur,
+  int(* xCmp)(void*,int,const void*,int,const void*),
+  void *pArg
+){
+  pCur->xCompare = xCmp ? xCmp : dfltCompare;
+  pCur->pArg = pArg;
+}
+
 /*
 ** Close a cursor.  The read lock on the database file is released
 ** when the last cursor is closed.
diff --git a/src/btree.h b/src/btree.h
index d36f3aa..78fc61c 100644
--- a/src/btree.h
+++ b/src/btree.h
@@ -13,7 +13,7 @@
 ** subsystem.  See comments in the source code for a detailed description
 ** of what each interface routine does.
 **
-** @(#) $Id: btree.h,v 1.47 2004/05/12 19:18:17 drh Exp $
+** @(#) $Id: btree.h,v 1.48 2004/05/18 10:06:25 danielk1977 Exp $
 */
 #ifndef _BTREE_H_
 #define _BTREE_H_
@@ -73,6 +73,12 @@
   BtCursor **ppCursor                  /* Returned cursor */
 );
 
+void sqlite3BtreeSetCompare(
+  BtCursor *,
+  int(*)(void*,int,const void*,int,const void*),
+  void*
+);
+
 int sqlite3BtreeCloseCursor(BtCursor*);
 int sqlite3BtreeMoveto(BtCursor*, const void *pKey, i64 nKey, int *pRes);
 int sqlite3BtreeDelete(BtCursor*);
diff --git a/src/expr.c b/src/expr.c
index be2c265..a0fff71 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.121 2004/05/17 10:48:58 danielk1977 Exp $
+** $Id: expr.c,v 1.122 2004/05/18 10:06:25 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -45,18 +45,18 @@
 ** SELECT a AS b FROM t1 WHERE b;
 ** SELECT * FROM t1 WHERE (select a from t1);
 */
-static char exprAffinity(Expr *pExpr){
+char sqlite3ExprAffinity(Expr *pExpr){
   if( pExpr->op==TK_AS ){
-    return exprAffinity(pExpr->pLeft);
+    return sqlite3ExprAffinity(pExpr->pLeft);
   }
   if( pExpr->op==TK_SELECT ){
-    return exprAffinity(pExpr->pSelect->pEList->a[0].pExpr);
+    return sqlite3ExprAffinity(pExpr->pSelect->pEList->a[0].pExpr);
   }
   return pExpr->affinity;
 }
 
 char sqlite3CompareAffinity(Expr *pExpr, char aff2){
-  char aff1 = exprAffinity(pExpr);
+  char aff1 = sqlite3ExprAffinity(pExpr);
   if( aff1 && aff2 ){
     /* Both sides of the comparison are columns. If one has numeric or
     ** integer affinity, use that. Otherwise use no affinity.
@@ -85,7 +85,7 @@
           pExpr->op==TK_GT || pExpr->op==TK_GE || pExpr->op==TK_LE ||
           pExpr->op==TK_NE );
   assert( pExpr->pLeft );
-  aff = exprAffinity(pExpr->pLeft);
+  aff = sqlite3ExprAffinity(pExpr->pLeft);
   if( pExpr->pRight ){
     aff = sqlite3CompareAffinity(pExpr->pRight, aff);
   }
@@ -121,7 +121,7 @@
 ** evaluates to NULL.
 */
 static int binaryCompareP1(Expr *pExpr1, Expr *pExpr2, int jumpIfNull){
-  char aff = exprAffinity(pExpr2);
+  char aff = sqlite3ExprAffinity(pExpr2);
   return (((int)sqlite3CompareAffinity(pExpr1, aff))<<8)+(jumpIfNull?1:0);
 }
 
@@ -802,7 +802,7 @@
       if( sqlite3ExprResolveIds(pParse, pSrcList, pEList, pExpr->pLeft) ){
         return 1;
       }
-      affinity = exprAffinity(pExpr->pLeft);
+      affinity = sqlite3ExprAffinity(pExpr->pLeft);
 
       /* Whether this is an 'x IN(SELECT...)' or an 'x IN(<exprlist>)'
       ** expression it is handled the same way. A temporary table is 
@@ -828,7 +828,7 @@
         */
         int iParm = pExpr->iTable +  (((int)affinity)<<16);
         assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
-        sqlite3Select(pParse, pExpr->pSelect, SRT_Set, iParm, 0, 0, 0);
+        sqlite3Select(pParse, pExpr->pSelect, SRT_Set, iParm, 0, 0, 0, 0);
       }else if( pExpr->pList ){
         /* Case 2:     expr IN (exprlist)
         **
@@ -874,7 +874,7 @@
       ** of the memory cell in iColumn.
       */
       pExpr->iColumn = pParse->nMem++;
-      if( sqlite3Select(pParse, pExpr->pSelect, SRT_Mem, pExpr->iColumn,0,0,0) ){
+      if(sqlite3Select(pParse, pExpr->pSelect, SRT_Mem,pExpr->iColumn,0,0,0,0)){
         return 1;
       }
       break;
diff --git a/src/parse.y b/src/parse.y
index 9202a45..952175a 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -14,7 +14,7 @@
 ** the parser.  Lemon will also generate a header file containing
 ** numeric codes for all of the tokens.
 **
-** @(#) $Id: parse.y,v 1.113 2004/05/08 08:23:30 danielk1977 Exp $
+** @(#) $Id: parse.y,v 1.114 2004/05/18 10:06:25 danielk1977 Exp $
 */
 %token_prefix TK_
 %token_type {Token}
@@ -278,7 +278,7 @@
 //////////////////////// The SELECT statement /////////////////////////////////
 //
 cmd ::= select(X).  {
-  sqlite3Select(pParse, X, SRT_Callback, 0, 0, 0, 0);
+  sqlite3Select(pParse, X, SRT_Callback, 0, 0, 0, 0, 0);
   sqlite3SelectDelete(X);
 }
 
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 29aac80..7f1bb00 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.235 2004/05/17 10:48:58 danielk1977 Exp $
+** @(#) $Id: sqliteInt.h,v 1.236 2004/05/18 10:06:26 danielk1977 Exp $
 */
 #include "config.h"
 #include "sqlite.h"
@@ -1191,7 +1191,7 @@
 void sqlite3DropIndex(Parse*, SrcList*);
 void sqlite3AddKeyType(Vdbe*, ExprList*);
 void sqlite3AddIdxKeyType(Vdbe*, Index*);
-int sqlite3Select(Parse*, Select*, int, int, Select*, int, int*);
+int sqlite3Select(Parse*, Select*, int, int, Select*, int, int*, char *aff);
 Select *sqlite3SelectNew(ExprList*,SrcList*,Expr*,ExprList*,Expr*,ExprList*,
                         int,int,int);
 void sqlite3SelectDelete(Select*);
@@ -1309,3 +1309,4 @@
 char sqlite3CompareAffinity(Expr *pExpr, char aff2);
 char const *sqlite3AffinityString(char affinity);
 int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
+char sqlite3ExprAffinity(Expr *pExpr);
diff --git a/src/trigger.c b/src/trigger.c
index 985b0b4..758513e 100644
--- a/src/trigger.c
+++ b/src/trigger.c
@@ -189,7 +189,7 @@
       { OP_String,     0, 0,  0          },  /* 3: table name */
       { OP_Integer,    0, 0,  0          },
       { OP_String,     0, 0,  0          },  /* 5: SQL */
-      { OP_MakeRecord, 5, 0,  0          },
+      { OP_MakeRecord, 5, 0,  "tttit"    },
       { OP_PutIntKey,  0, 0,  0          },
     };
     int addr;
@@ -615,7 +615,7 @@
 	Select * ss = sqlite3SelectDup(pTriggerStep->pSelect);		  
 	assert(ss);
 	assert(ss->pSrc);
-	sqlite3Select(pParse, ss, SRT_Discard, 0, 0, 0, 0);
+	sqlite3Select(pParse, ss, SRT_Discard, 0, 0, 0, 0, 0);
 	sqlite3SelectDelete(ss);
 	break;
       }
diff --git a/src/vdbe.h b/src/vdbe.h
index 7928dbe..393edce 100644
--- a/src/vdbe.h
+++ b/src/vdbe.h
@@ -15,7 +15,7 @@
 ** or VDBE.  The VDBE implements an abstract machine that runs a
 ** simple program to access and modify the underlying database.
 **
-** $Id: vdbe.h,v 1.75 2004/05/13 05:16:17 danielk1977 Exp $
+** $Id: vdbe.h,v 1.76 2004/05/18 10:06:26 danielk1977 Exp $
 */
 #ifndef _SQLITE_VDBE_H_
 #define _SQLITE_VDBE_H_
@@ -94,7 +94,7 @@
 void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
 void sqlite3VdbeChangeP3(Vdbe*, int addr, const char *zP1, int N);
 void sqlite3VdbeDequoteP3(Vdbe*, int addr);
-int sqlite3VdbeFindOp(Vdbe*, int, int);
+int sqlite3VdbeFindOp(Vdbe*, int, int, int);
 VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
 int sqlite3VdbeMakeLabel(Vdbe*);
 void sqlite3VdbeDelete(Vdbe*);
@@ -108,6 +108,5 @@
 void sqlite3VdbeCompressSpace(Vdbe*,int);
 int sqlite3VdbeReset(Vdbe*,char **);
 int sqliteVdbeSetVariables(Vdbe*,int,const char**);
-int sqlite3VdbeKeyCompare(void*,int,const void*,int, const void*);
 
 #endif
diff --git a/src/vdbeInt.h b/src/vdbeInt.h
index 71765a5..bea4d07 100644
--- a/src/vdbeInt.h
+++ b/src/vdbeInt.h
@@ -334,3 +334,5 @@
 int sqlite3VdbeIdxKeyCompare(Cursor*, int , const unsigned char*, int, int*);
 int sqlite3VdbeIdxRowid(BtCursor *, i64 *);
 int sqlite3MemCompare(Mem *, Mem *);
+int sqlite3VdbeKeyCompare(void*,int,const void*,int, const void*);
+int sqlite3VdbeRowCompare(void*,int,const void*,int, const void*);