Bug fixes and enhancements entered while on jury recess. (CVS 2246)

FossilOrigin-Name: 38401dfbd5e3b50dd4e7a11562a7770347cebdf4
diff --git a/src/expr.c b/src/expr.c
index 514566a..c96eb59 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.185 2005/01/20 13:36:20 drh Exp $
+** $Id: expr.c,v 1.186 2005/01/20 22:48:48 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -611,6 +611,10 @@
     case TK_DOT:
     case TK_AGG_FUNCTION:
     case TK_FUNCTION:
+#ifndef SQLITE_OMIT_SUBQUERY
+    case TK_SELECT:
+    case TK_EXISTS:
+#endif
       *((int*)pArg) = 0;
       return 2;
     default:
@@ -1534,6 +1538,8 @@
       sqlite3VdbeOp3(v, OP_Function, nExpr, p2, (char*)pDef, P3_FUNCDEF);
       break;
     }
+#ifndef SQLITE_OMIT_SUBQUERY
+    case TK_EXISTS:
     case TK_SELECT: {
       if( pExpr->iTable>=0 ){
         sqlite3VdbeAddOp(v, OP_Gosub, 0, pExpr->iTable);
@@ -1543,6 +1549,7 @@
       VdbeComment((v, "# load subquery result"));
       break;
     }
+#endif
     case TK_IN: {
       int addr;
       char affinity;
diff --git a/src/select.c b/src/select.c
index a91abbe..74c4c04 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.231 2005/01/20 13:36:20 drh Exp $
+** $Id: select.c,v 1.232 2005/01/20 22:48:48 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -741,7 +741,7 @@
   sqlite3 *db = pParse->db;
   int fullNames, shortNames;
 
-#ifdef SQLITE_OMIT_EXPLAIN
+#ifndef SQLITE_OMIT_EXPLAIN
   /* If this is an EXPLAIN, skip this step */
   if( pParse->explain ){
     return;
diff --git a/src/util.c b/src/util.c
index 9bde974..be4b13a 100644
--- a/src/util.c
+++ b/src/util.c
@@ -14,7 +14,7 @@
 ** This file contains functions for allocating memory, comparing
 ** strings, and stuff like that.
 **
-** $Id: util.c,v 1.127 2005/01/17 07:53:44 danielk1977 Exp $
+** $Id: util.c,v 1.128 2005/01/20 22:48:48 drh Exp $
 */
 #include "sqliteInt.h"
 #include <stdarg.h>
@@ -800,7 +800,7 @@
 int sqlite3PutVarint(unsigned char *p, u64 v){
   int i, j, n;
   u8 buf[10];
-  if( v & 0xff00000000000000 ){
+  if( v & (((u64)0xff000000)<<32) ){
     p[8] = v;
     v >>= 8;
     for(i=7; i>=0; i--){
diff --git a/src/vdbe.c b/src/vdbe.c
index 2ffaa5e..5c0ec7d 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -43,7 +43,7 @@
 ** in this file for details.  If in doubt, do not deviate from existing
 ** commenting and indentation practices when changing or adding code.
 **
-** $Id: vdbe.c,v 1.443 2005/01/17 03:40:08 danielk1977 Exp $
+** $Id: vdbe.c,v 1.444 2005/01/20 22:48:48 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -2868,6 +2868,13 @@
     cnt = 0;
     assert( (sqlite3BtreeFlags(pC->pCursor) & BTREE_INTKEY)!=0 );
     assert( (sqlite3BtreeFlags(pC->pCursor) & BTREE_ZERODATA)==0 );
+
+    /* Some compilers complain about constants of the form 0x7fffffffffffffff.
+    ** Others complain about 0x7ffffffffffffffffLL.  The following macro seems
+    ** to provide the constant while making all compilers happy.
+    */
+#   define MAX_I64  ( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
+
     if( !pC->useRandomRowid ){
       if( pC->nextRowidValid ){
         v = pC->nextRowid;
@@ -2878,7 +2885,7 @@
         }else{
           sqlite3BtreeKeySize(pC->pCursor, &v);
           v = keyToInt(v);
-          if( v==0x7fffffffffffffff ){
+          if( v==MAX_I64 ){
             pC->useRandomRowid = 1;
           }else{
             v++;
@@ -2893,7 +2900,7 @@
         pMem = &p->aMem[pOp->p2];
         Integerify(pMem);
         assert( (pMem->flags & MEM_Int)!=0 );  /* mem(P2) holds an integer */
-        if( pMem->i==0x7fffffffffffffff || pC->useRandomRowid ){
+        if( pMem->i==MAX_I64 || pC->useRandomRowid ){
           rc = SQLITE_FULL;
           goto abort_due_to_error;
         }
@@ -2904,7 +2911,7 @@
       }
 #endif
 
-      if( v<0x7fffffffffffffff ){
+      if( v<MAX_I64 ){
         pC->nextRowidValid = 1;
         pC->nextRowid = v+1;
       }else{
diff --git a/src/vdbeaux.c b/src/vdbeaux.c
index 0392d60..a78f099 100644
--- a/src/vdbeaux.c
+++ b/src/vdbeaux.c
@@ -1487,13 +1487,14 @@
     return 0;
   }
   if( flags&MEM_Int ){
-    /* Figure out whether to use 1, 2, 4 or 8 bytes. */
+    /* Figure out whether to use 1, 2, 4, 6 or 8 bytes. */
+#   define MAX_6BYTE ((((i64)0x00010000)<<32)-1)
     i64 i = pMem->i;
     if( i>=-127 && i<=127 ) return 1;
     if( i>=-32767 && i<=32767 ) return 2;
     if( i>=-8388607 && i<=8388607 ) return 3;
     if( i>=-2147483647 && i<=2147483647 ) return 4;
-    if( i>=-140737488355328L && i<=140737488355328L ) return 5;
+    if( i>=-MAX_6BYTE && i<=MAX_6BYTE ) return 5;
     return 6;
   }
   if( flags&MEM_Real ){
diff --git a/src/where.c b/src/where.c
index 6414c42..1054bf5 100644
--- a/src/where.c
+++ b/src/where.c
@@ -16,7 +16,7 @@
 ** so is applicable.  Because this module is responsible for selecting
 ** indices, you might also think of this module as the "query optimizer".
 **
-** $Id: where.c,v 1.130 2005/01/19 23:24:51 drh Exp $
+** $Id: where.c,v 1.131 2005/01/20 22:48:48 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -650,7 +650,6 @@
     createMask(&maskSet, pTabList->a[i].iCursor);
   }
   for(pTerm=aExpr, i=0; i<nExpr; i++, pTerm++){
-    TriggerStack *pStack;
     exprAnalyze(pTabList, &maskSet, pTerm);
   }