]> granicus.if.org Git - php/commitdiff
Upgraded bundled sqlite lib to 3.2.2
authorIlia Alshanetsky <iliaa@php.net>
Thu, 30 Jun 2005 20:58:36 +0000 (20:58 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Thu, 30 Jun 2005 20:58:36 +0000 (20:58 +0000)
51 files changed:
ext/pdo_sqlite/config.m4
ext/pdo_sqlite/config.w32
ext/pdo_sqlite/sqlite/Makefile.in
ext/pdo_sqlite/sqlite/VERSION
ext/pdo_sqlite/sqlite/src/alter.c
ext/pdo_sqlite/sqlite/src/attach.c
ext/pdo_sqlite/sqlite/src/btree.c
ext/pdo_sqlite/sqlite/src/btree.h
ext/pdo_sqlite/sqlite/src/build.c
ext/pdo_sqlite/sqlite/src/callback.c [new file with mode: 0644]
ext/pdo_sqlite/sqlite/src/date.c
ext/pdo_sqlite/sqlite/src/delete.c
ext/pdo_sqlite/sqlite/src/experimental.c
ext/pdo_sqlite/sqlite/src/expr.c
ext/pdo_sqlite/sqlite/src/func.c
ext/pdo_sqlite/sqlite/src/insert.c
ext/pdo_sqlite/sqlite/src/keywordhash.h
ext/pdo_sqlite/sqlite/src/main.c
ext/pdo_sqlite/sqlite/src/opcodes.h
ext/pdo_sqlite/sqlite/src/os.h
ext/pdo_sqlite/sqlite/src/os_test.h
ext/pdo_sqlite/sqlite/src/os_unix.c
ext/pdo_sqlite/sqlite/src/os_unix.h
ext/pdo_sqlite/sqlite/src/os_win.c
ext/pdo_sqlite/sqlite/src/pager.c
ext/pdo_sqlite/sqlite/src/pager.h
ext/pdo_sqlite/sqlite/src/parse.c
ext/pdo_sqlite/sqlite/src/parse.h
ext/pdo_sqlite/sqlite/src/parse.y
ext/pdo_sqlite/sqlite/src/pragma.c
ext/pdo_sqlite/sqlite/src/prepare.c [new file with mode: 0644]
ext/pdo_sqlite/sqlite/src/random.c
ext/pdo_sqlite/sqlite/src/select.c
ext/pdo_sqlite/sqlite/src/shell.c
ext/pdo_sqlite/sqlite/src/sqlite.h.in
ext/pdo_sqlite/sqlite/src/sqliteInt.h
ext/pdo_sqlite/sqlite/src/tclsqlite.c
ext/pdo_sqlite/sqlite/src/test1.c
ext/pdo_sqlite/sqlite/src/test2.c
ext/pdo_sqlite/sqlite/src/tokenize.c
ext/pdo_sqlite/sqlite/src/trigger.c
ext/pdo_sqlite/sqlite/src/update.c
ext/pdo_sqlite/sqlite/src/util.c
ext/pdo_sqlite/sqlite/src/vacuum.c
ext/pdo_sqlite/sqlite/src/vdbe.c
ext/pdo_sqlite/sqlite/src/vdbe.h
ext/pdo_sqlite/sqlite/src/vdbeInt.h
ext/pdo_sqlite/sqlite/src/vdbeapi.c
ext/pdo_sqlite/sqlite/src/vdbeaux.c
ext/pdo_sqlite/sqlite/src/vdbemem.c
ext/pdo_sqlite/sqlite/src/where.c

index 9e6dd18dabe9b2ea832c104e60ab25e3b16d9e5a..90a9bd1d1866f3e3b02c51be1ba99c036f017b03 100644 (file)
@@ -55,10 +55,10 @@ if test "$PHP_PDO_SQLITE" != "no"; then
   else
     # use bundled libs
     pdo_sqlite_sources="sqlite/src/attach.c sqlite/src/auth.c sqlite/src/btree.c \
-      sqlite/src/build.c sqlite/src/date.c sqlite/src/delete.c sqlite/src/expr.c \
+      sqlite/src/build.c sqlite/src/callback.c sqlite/src/date.c sqlite/src/delete.c sqlite/src/expr.c \
       sqlite/src/func.c sqlite/src/hash.c sqlite/src/insert.c sqlite/src/legacy.c \
       sqlite/src/main.c sqlite/src/os_mac.c sqlite/src/os_unix.c sqlite/src/os_win.c \
-      sqlite/src/pager.c sqlite/src/pragma.c \
+      sqlite/src/pager.c sqlite/src/pragma.c sqlite/src/prepare.c \
       sqlite/src/printf.c sqlite/src/random.c sqlite/src/select.c \
       sqlite/src/table.c sqlite/src/tokenize.c \
       sqlite/src/trigger.c sqlite/src/update.c sqlite/src/utf.c sqlite/src/util.c \
index f5c62455607625f7e14d2434473ff89998ca8d7c..297423f045e8e2dddde78027f61040662f8d3fbd 100644 (file)
@@ -21,8 +21,8 @@ if (PHP_PDO_SQLITE != "no") {
                
        EXTENSION("pdo_sqlite", "pdo_sqlite.c sqlite_driver.c sqlite_statement.c", null, "/DSQLITE_OMIT_CURSOR /I" + configure_module_dirname + "/sqlite/src /I pecl /I ..\\pecl /I" + configure_module_dirname);
        ADD_SOURCES(configure_module_dirname + "/sqlite/src",
-               "attach.c auth.c btree.c build.c date.c delete.c expr.c func.c hash.c insert.c \
-                legacy.c main.c os_mac.c os_unix.c os_win.c pager.c pragma.c printf.c random.c \
+               "attach.c auth.c btree.c build.c callback.c date.c delete.c expr.c func.c hash.c insert.c \
+                legacy.c main.c os_mac.c os_unix.c os_win.c pager.c pragma.c prepare.c printf.c random.c \
                 select.c table.c tokenize.c trigger.c update.c utf.c util.c vacuum.c vdbeapi.c \
                 vdbeaux.c vdbe.c vdbemem.c where.c parse.c opcodes.c alter.c experimental.c", "pdo_sqlite");
        
index 198a7877c1319a39558e7b41b2179f0bf822b882..462772a967c28b855341e1bc12477fe6347ba5ee 100644 (file)
@@ -112,10 +112,10 @@ TCC += -DSQLITE_OMIT_CURSOR
 
 # Object files for the SQLite library.
 #
-LIBOBJ = alter.lo attach.lo auth.lo btree.lo build.lo date.lo \
+LIBOBJ = alter.lo attach.lo auth.lo btree.lo build.lo callback.lo date.lo \
          delete.lo expr.lo func.lo hash.lo insert.lo \
          main.lo opcodes.lo os_unix.lo os_win.lo \
-         pager.lo parse.lo pragma.lo printf.lo random.lo \
+         pager.lo parse.lo pragma.lo prepare.lo printf.lo random.lo \
          select.lo table.lo tokenize.lo trigger.lo update.lo \
          util.lo vacuum.lo vdbe.lo vdbeapi.lo vdbeaux.lo vdbemem.lo \
          where.lo utf.lo legacy.lo
@@ -129,6 +129,7 @@ SRC = \
   $(TOP)/src/btree.c \
   $(TOP)/src/btree.h \
   $(TOP)/src/build.c \
+  $(TOP)/src/callback.c \
   $(TOP)/src/date.c \
   $(TOP)/src/delete.c \
   $(TOP)/src/expr.c \
@@ -144,6 +145,7 @@ SRC = \
   $(TOP)/src/pager.h \
   $(TOP)/src/parse.y \
   $(TOP)/src/pragma.c \
+  $(TOP)/src/prepare.c \
   $(TOP)/src/printf.c \
   $(TOP)/src/random.c \
   $(TOP)/src/select.c \
@@ -346,6 +348,9 @@ parse.c:    $(TOP)/src/parse.y lemon$(BEXE)
 pragma.lo:     $(TOP)/src/pragma.c $(HDR)
        $(LTCOMPILE) -c $(TOP)/src/pragma.c
 
+prepare.lo:     $(TOP)/src/prepare.c $(HDR)
+        $(LTCOMPILE) -c $(TOP)/src/prepare.c
+
 printf.lo:     $(TOP)/src/printf.c $(HDR)
        $(LTCOMPILE) -c $(TOP)/src/printf.c
 
index ff365e06b9577c96dfeadddb8c4cccb09b85665c..be94e6f53db6b394e5e7cc7ceb12115a81870306 100644 (file)
@@ -1 +1 @@
-3.1.3
+3.2.2
index 199cdca3839e6fdb08373fae8f32a2e338aaa50a..c5be6b61c7450a2a3d4015b59a653347cba6fab9 100644 (file)
@@ -15,6 +15,7 @@
 ** $Id$
 */
 #include "sqliteInt.h"
+#include <ctype.h>
 
 /*
 ** The code in this file only exists if we are not omitting the
@@ -166,6 +167,78 @@ void sqlite3AlterFunctions(sqlite3 *db){
   }
 }
 
+/*
+** Generate the text of a WHERE expression which can be used to select all
+** temporary triggers on table pTab from the sqlite_temp_master table. If
+** table pTab has no temporary triggers, or is itself stored in the 
+** temporary database, NULL is returned.
+*/
+static char *whereTempTriggers(Parse *pParse, Table *pTab){
+  Trigger *pTrig;
+  char *zWhere = 0;
+  char *tmp = 0;
+  if( pTab->iDb!=1 ){
+    for( pTrig=pTab->pTrigger; pTrig; pTrig=pTrig->pNext ){
+      if( pTrig->iDb==1 ){
+        if( !zWhere ){
+          zWhere = sqlite3MPrintf("name=%Q", pTrig->name);
+        }else{
+          tmp = zWhere;
+          zWhere = sqlite3MPrintf("%s OR name=%Q", zWhere, pTrig->name);
+          sqliteFree(tmp);
+        }
+      }
+    }
+  }
+  return zWhere;
+}
+
+/*
+** Generate code to drop and reload the internal representation of table
+** pTab from the database, including triggers and temporary triggers.
+** Argument zName is the name of the table in the database schema at
+** the time the generated code is executed. This can be different from
+** pTab->zName if this function is being called to code part of an 
+** "ALTER TABLE RENAME TO" statement.
+*/
+static void reloadTableSchema(Parse *pParse, Table *pTab, const char *zName){
+  Vdbe *v;
+  char *zWhere;
+  int iDb;
+#ifndef SQLITE_OMIT_TRIGGER
+  Trigger *pTrig;
+#endif
+
+  v = sqlite3GetVdbe(pParse);
+  if( !v ) return;
+  iDb = pTab->iDb;
+
+#ifndef SQLITE_OMIT_TRIGGER
+  /* Drop any table triggers from the internal schema. */
+  for(pTrig=pTab->pTrigger; pTrig; pTrig=pTrig->pNext){
+    assert( pTrig->iDb==iDb || pTrig->iDb==1 );
+    sqlite3VdbeOp3(v, OP_DropTrigger, pTrig->iDb, 0, pTrig->name, 0);
+  }
+#endif
+
+  /* Drop the table and index from the internal schema */
+  sqlite3VdbeOp3(v, OP_DropTable, iDb, 0, pTab->zName, 0);
+
+  /* Reload the table, index and permanent trigger schemas. */
+  zWhere = sqlite3MPrintf("tbl_name=%Q", zName);
+  if( !zWhere ) return;
+  sqlite3VdbeOp3(v, OP_ParseSchema, iDb, 0, zWhere, P3_DYNAMIC);
+
+#ifndef SQLITE_OMIT_TRIGGER
+  /* Now, if the table is not stored in the temp database, reload any temp 
+  ** triggers. Don't use IN(...) in case SQLITE_OMIT_SUBQUERY is defined. 
+  */
+  if( (zWhere=whereTempTriggers(pParse, pTab)) ){
+    sqlite3VdbeOp3(v, OP_ParseSchema, 1, 0, zWhere, P3_DYNAMIC);
+  }
+#endif
+}
+
 /*
 ** Generate code to implement the "ALTER TABLE xxx RENAME TO yyy" 
 ** command. 
@@ -179,11 +252,10 @@ void sqlite3AlterRenameTable(
   char *zDb;                /* Name of database iDb */
   Table *pTab;              /* Table being renamed */
   char *zName = 0;          /* NULL-terminated version of pName */ 
-  char *zWhere = 0;         /* Where clause of schema elements to reparse */
   sqlite3 *db = pParse->db; /* Database connection */
   Vdbe *v;
 #ifndef SQLITE_OMIT_TRIGGER
-  char *zTempTrig = 0;      /* Where clause to locate temp triggers */
+  char *zWhere = 0;         /* Where clause to locate temp triggers */
 #endif
   
   assert( pSrc->nSrc==1 );
@@ -255,7 +327,7 @@ void sqlite3AlterRenameTable(
           "(type='table' OR type='index' OR type='trigger');", 
       zDb, SCHEMA_TABLE(iDb), zName, zName, zName, 
 #ifndef SQLITE_OMIT_TRIGGER
-zName,
+      zName,
 #endif
       zName, strlen(pTab->zName), pTab->zName
   );
@@ -276,59 +348,206 @@ zName,
   ** table. Don't do this if the table being ALTERed is itself located in
   ** the temp database.
   */
-  if( iDb!=1 ){
-    Trigger *pTrig;
-    char *tmp = 0;
-    for( pTrig=pTab->pTrigger; pTrig; pTrig=pTrig->pNext ){
-      if( pTrig->iDb==1 ){
-        if( !zTempTrig ){
-          zTempTrig = 
-              sqlite3MPrintf("type = 'trigger' AND (name=%Q", pTrig->name);
-        }else{
-          tmp = zTempTrig;
-          zTempTrig = sqlite3MPrintf("%s OR name=%Q", zTempTrig, pTrig->name);
-          sqliteFree(tmp);
-        }
-      }
-    }
-    if( zTempTrig ){
-      tmp = zTempTrig;
-      zTempTrig = sqlite3MPrintf("%s)", zTempTrig);
-      sqliteFree(tmp);
-      sqlite3NestedParse(pParse, 
-          "UPDATE sqlite_temp_master SET "
-              "sql = sqlite_rename_trigger(sql, %Q), "
-              "tbl_name = %Q "
-              "WHERE %s;", zName, zName, zTempTrig);
-    }
+  if( (zWhere=whereTempTriggers(pParse, pTab)) ){
+    sqlite3NestedParse(pParse, 
+        "UPDATE sqlite_temp_master SET "
+            "sql = sqlite_rename_trigger(sql, %Q), "
+            "tbl_name = %Q "
+            "WHERE %s;", zName, zName, zWhere);
+    sqliteFree(zWhere);
   }
 #endif
 
-  /* Drop the elements of the in-memory schema that refered to the table
-  ** renamed and load the new versions from the database.
+  /* Drop and reload the internal table schema. */
+  reloadTableSchema(pParse, pTab, zName);
+
+exit_rename_table:
+  sqlite3SrcListDelete(pSrc);
+  sqliteFree(zName);
+}
+
+
+/*
+** This function is called after an "ALTER TABLE ... ADD" statement
+** has been parsed. Argument pColDef contains the text of the new
+** column definition.
+**
+** The Table structure pParse->pNewTable was extended to include
+** the new column during parsing.
+*/
+void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
+  Table *pNew;              /* Copy of pParse->pNewTable */
+  Table *pTab;              /* Table being altered */
+  int iDb;                  /* Database number */
+  const char *zDb;          /* Database name */
+  const char *zTab;         /* Table name */
+  char *zCol;               /* Null-terminated column definition */
+  Column *pCol;             /* The new column */
+  Expr *pDflt;              /* Default value for the new column */
+  Vdbe *v;
+
+  if( pParse->nErr ) return;
+  pNew = pParse->pNewTable;
+  assert( pNew );
+
+  iDb = pNew->iDb;
+  zDb = pParse->db->aDb[iDb].zName;
+  zTab = pNew->zName;
+  pCol = &pNew->aCol[pNew->nCol-1];
+  pDflt = pCol->pDflt;
+  pTab = sqlite3FindTable(pParse->db, zTab, zDb);
+  assert( pTab );
+
+  /* If the default value for the new column was specified with a 
+  ** literal NULL, then set pDflt to 0. This simplifies checking
+  ** for an SQL NULL default below.
   */
-  if( pParse->nErr==0 ){
-#ifndef SQLITE_OMIT_TRIGGER
-    Trigger *pTrig;
-    for( pTrig=pTab->pTrigger; pTrig; pTrig=pTrig->pNext ){
-      assert( pTrig->iDb==iDb || pTrig->iDb==1 );
-      sqlite3VdbeOp3(v, OP_DropTrigger, pTrig->iDb, 0, pTrig->name, 0);
+  if( pDflt && pDflt->op==TK_NULL ){
+    pDflt = 0;
+  }
+
+  /* Check that the new column is not specified as PRIMARY KEY or UNIQUE.
+  ** If there is a NOT NULL constraint, then the default value for the
+  ** column must not be NULL.
+  */
+  if( pCol->isPrimKey ){
+    sqlite3ErrorMsg(pParse, "Cannot add a PRIMARY KEY column");
+    return;
+  }
+  if( pNew->pIndex ){
+    sqlite3ErrorMsg(pParse, "Cannot add a UNIQUE column");
+    return;
+  }
+  if( pCol->notNull && !pDflt ){
+    sqlite3ErrorMsg(pParse, 
+        "Cannot add a NOT NULL column with default value NULL");
+    return;
+  }
+
+  /* Ensure the default expression is something that sqlite3ValueFromExpr()
+  ** can handle (i.e. not CURRENT_TIME etc.)
+  */
+  if( pDflt ){
+    sqlite3_value *pVal;
+    if( sqlite3ValueFromExpr(pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) ){
+      /* malloc() has failed */
+      return;
     }
-#endif
-    sqlite3VdbeOp3(v, OP_DropTable, iDb, 0, pTab->zName, 0);
-    zWhere = sqlite3MPrintf("tbl_name=%Q", zName);
-    sqlite3VdbeOp3(v, OP_ParseSchema, iDb, 0, zWhere, P3_DYNAMIC);
-#ifndef SQLITE_OMIT_TRIGGER
-    if( zTempTrig ){
-      sqlite3VdbeOp3(v, OP_ParseSchema, 1, 0, zTempTrig, P3_DYNAMIC);
+    if( !pVal ){
+      sqlite3ErrorMsg(pParse, "Cannot add a column with non-constant default");
+      return;
     }
-  }else{
-    sqliteFree(zTempTrig);
-#endif
+    sqlite3ValueFree(pVal);
   }
 
-exit_rename_table:
+  /* Modify the CREATE TABLE statement. */
+  zCol = sqliteStrNDup(pColDef->z, pColDef->n);
+  if( zCol ){
+    char *zEnd = &zCol[pColDef->n-1];
+    while( (zEnd>zCol && *zEnd==';') || isspace(*(unsigned char *)zEnd) ){
+      *zEnd-- = '\0';
+    }
+    sqlite3NestedParse(pParse, 
+        "UPDATE %Q.%s SET "
+          "sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d,length(sql)) "
+        "WHERE type = 'table' AND name = %Q", 
+      zDb, SCHEMA_TABLE(iDb), pNew->addColOffset, zCol, pNew->addColOffset+1,
+      zTab
+    );
+    sqliteFree(zCol);
+  }
+
+  /* If the default value of the new column is NULL, then set the file
+  ** format to 2. If the default value of the new column is not NULL,
+  ** the file format becomes 3.
+  */
+  if( (v=sqlite3GetVdbe(pParse)) ){
+    int f = (pDflt?3:2);
+
+    /* Only set the file format to $f if it is currently less than $f. */
+    sqlite3VdbeAddOp(v, OP_ReadCookie, iDb, 1);
+    sqlite3VdbeAddOp(v, OP_Integer, f, 0);
+    sqlite3VdbeAddOp(v, OP_Ge, 0, sqlite3VdbeCurrentAddr(v)+3);
+    sqlite3VdbeAddOp(v, OP_Integer, f, 0);
+    sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 1);
+  }
+
+  /* Reload the schema of the modified table. */
+  reloadTableSchema(pParse, pTab, pTab->zName);
+}
+
+
+/*
+** This function is called by the parser after the table-name in
+** an "ALTER TABLE <table-name> ADD" statement is parsed. Argument 
+** pSrc is the full-name of the table being altered.
+**
+** This routine makes a (partial) copy of the Table structure
+** for the table being altered and sets Parse.pNewTable to point
+** to it. Routines called by the parser as the column definition
+** is parsed (i.e. sqlite3AddColumn()) add the new Column data to 
+** the copy. The copy of the Table structure is deleted by tokenize.c 
+** after parsing is finished.
+**
+** Routine sqlite3AlterFinishAddColumn() will be called to complete
+** coding the "ALTER TABLE ... ADD" statement.
+*/
+void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){
+  Table *pNew;
+  Table *pTab;
+  Vdbe *v;
+  int iDb;
+  int i;
+  int nAlloc;
+
+  /* Look up the table being altered. */
+  assert( !pParse->pNewTable );
+  pTab = sqlite3LocateTable(pParse, pSrc->a[0].zName, pSrc->a[0].zDatabase);
+  if( !pTab ) goto exit_begin_add_column;
+
+  /* Make sure this is not an attempt to ALTER a view. */
+  if( pTab->pSelect ){
+    sqlite3ErrorMsg(pParse, "Cannot add a column to a view");
+    goto exit_begin_add_column;
+  }
+
+  assert( pTab->addColOffset>0 );
+  iDb = pTab->iDb;
+
+  /* Put a copy of the Table struct in Parse.pNewTable for the
+  ** sqlite3AddColumn() function and friends to modify.
+  */
+  pNew = (Table *)sqliteMalloc(sizeof(Table));
+  if( !pNew ) goto exit_begin_add_column;
+  pParse->pNewTable = pNew;
+  pNew->nCol = pTab->nCol;
+  assert( pNew->nCol>0 );
+  nAlloc = (((pNew->nCol-1)/8)*8)+8;
+  assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 );
+  pNew->aCol = (Column *)sqliteMalloc(sizeof(Column)*nAlloc);
+  pNew->zName = sqliteStrDup(pTab->zName);
+  if( !pNew->aCol || !pNew->zName ){
+    goto exit_begin_add_column;
+  }
+  memcpy(pNew->aCol, pTab->aCol, sizeof(Column)*pNew->nCol);
+  for(i=0; i<pNew->nCol; i++){
+    Column *pCol = &pNew->aCol[i];
+    pCol->zName = sqliteStrDup(pCol->zName);
+    pCol->zType = 0;
+    pCol->pDflt = 0;
+  }
+  pNew->iDb = iDb;
+  pNew->addColOffset = pTab->addColOffset;
+  pNew->nRef = 1;
+
+  /* Begin a transaction and increment the schema cookie.  */
+  sqlite3BeginWriteOperation(pParse, 0, iDb);
+  v = sqlite3GetVdbe(pParse);
+  if( !v ) goto exit_begin_add_column;
+  sqlite3ChangeCookie(pParse->db, v, iDb);
+
+exit_begin_add_column:
   sqlite3SrcListDelete(pSrc);
-  sqliteFree(zName);
+  return;
 }
 #endif  /* SQLITE_ALTER_TABLE */
index 79c325f4c194c9b7f498ac64d19d83cbf0d24030..5c8953467c38b9afa6ba6d10294d52690ecffdc4 100644 (file)
@@ -32,7 +32,8 @@ void sqlite3Attach(
 ){
   Db *aNew;
   int rc, i;
-  char *zFile, *zName;
+  char *zFile = 0;
+  char *zName = 0;
   sqlite3 *db;
   Vdbe *v;
 
@@ -55,34 +56,40 @@ void sqlite3Attach(
     return;
   }
 
-  zFile = sqlite3NameFromToken(pFilename);;
-  if( zFile==0 ) return;
+  zFile = sqlite3NameFromToken(pFilename);
+  if( zFile==0 ){
+    goto attach_end;
+  }
 #ifndef SQLITE_OMIT_AUTHORIZATION
   if( sqlite3AuthCheck(pParse, SQLITE_ATTACH, zFile, 0, 0)!=SQLITE_OK ){
-    sqliteFree(zFile);
-    return;
+    goto attach_end;
   }
 #endif /* SQLITE_OMIT_AUTHORIZATION */
 
   zName = sqlite3NameFromToken(pDbname);
-  if( zName==0 ) return;
+  if( zName==0 ){
+    goto attach_end;
+  }
   for(i=0; i<db->nDb; i++){
     char *z = db->aDb[i].zName;
     if( z && sqlite3StrICmp(z, zName)==0 ){
-      sqlite3ErrorMsg(pParse, "database %z is already in use", zName);
+      sqlite3ErrorMsg(pParse, "database %s is already in use", zName);
       pParse->rc = SQLITE_ERROR;
-      sqliteFree(zFile);
-      return;
+      goto attach_end;
     }
   }
 
   if( db->aDb==db->aDbStatic ){
     aNew = sqliteMalloc( sizeof(db->aDb[0])*3 );
-    if( aNew==0 ) return;
+    if( aNew==0 ){
+      goto attach_end;
+    }
     memcpy(aNew, db->aDb, sizeof(db->aDb[0])*2);
   }else{
     aNew = sqliteRealloc(db->aDb, sizeof(db->aDb[0])*(db->nDb+1) );
-    if( aNew==0 ) return;
+    if( aNew==0 ){
+      goto attach_end;
+    } 
   }
   db->aDb = aNew;
   aNew = &db->aDb[db->nDb++];
@@ -92,6 +99,7 @@ void sqlite3Attach(
   sqlite3HashInit(&aNew->trigHash, SQLITE_HASH_STRING, 0);
   sqlite3HashInit(&aNew->aFKey, SQLITE_HASH_STRING, 1);
   aNew->zName = zName;
+  zName = 0;
   aNew->safety_level = 3;
   rc = sqlite3BtreeFactory(db, zFile, 0, MAX_PAGES, &aNew->pBt);
   if( rc ){
@@ -126,7 +134,6 @@ void sqlite3Attach(
     }
   }
 #endif
-  sqliteFree(zFile);
   db->flags &= ~SQLITE_Initialized;
   if( pParse->nErr==0 && rc==SQLITE_OK ){
     rc = sqlite3ReadSchema(pParse);
@@ -144,6 +151,10 @@ void sqlite3Attach(
       pParse->rc = SQLITE_ERROR;
     }
   }
+
+attach_end:
+  sqliteFree(zFile);
+  sqliteFree(zName);
 }
 
 /*
@@ -158,6 +169,7 @@ void sqlite3Detach(Parse *pParse, Token *pDbname){
   sqlite3 *db;
   Vdbe *v;
   Db *pDb = 0;
+  char *zName;
 
   v = sqlite3GetVdbe(pParse);
   if( !v ) return;
@@ -165,20 +177,22 @@ void sqlite3Detach(Parse *pParse, Token *pDbname){
   sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
   if( pParse->explain ) return;
   db = pParse->db;
+  zName = sqlite3NameFromToken(pDbname);
+  if( zName==0 ) return;
   for(i=0; i<db->nDb; i++){
     pDb = &db->aDb[i];
-    if( pDb->pBt==0 || pDb->zName==0 ) continue;
-    if( strlen(pDb->zName)!=pDbname->n ) continue;
-    if( sqlite3StrNICmp(pDb->zName, pDbname->z, pDbname->n)==0 ) break;
+    if( pDb->pBt==0 ) continue;
+    if( sqlite3StrICmp(pDb->zName, zName)==0 ) break;
   }
   if( i>=db->nDb ){
-    sqlite3ErrorMsg(pParse, "no such database: %T", pDbname);
+    sqlite3ErrorMsg(pParse, "no such database: %z", zName);
     return;
   }
   if( i<2 ){
-    sqlite3ErrorMsg(pParse, "cannot detach database %T", pDbname);
+    sqlite3ErrorMsg(pParse, "cannot detach database %z", zName);
     return;
   }
+  sqliteFree(zName);
   if( !db->autoCommit ){
     sqlite3ErrorMsg(pParse, "cannot DETACH database within transaction");
     pParse->rc = SQLITE_ERROR;
index b4ea019b6eb8efb8c55f221ccecede8698fbff8a..5cfc118d446a2c3653ad35d6834ae9de7c13214f 100644 (file)
 #include "os.h"
 #include <assert.h>
 
-/*
-** This macro rounds values up so that if the value is an address it
-** is guaranteed to be an address that is aligned to an 8-byte boundary.
+/* Round up a number to the next larger multiple of 8.  This is used
+** to force 8-byte alignment on 64-bit architectures.
 */
-#define FORCE_ALIGNMENT(X)   (((X)+7)&~7)
+#define ROUND8(x)   ((x+7)&~7)
+
 
 /* The following value is the maximum cell size assuming a maximum page
 ** size give above.
@@ -308,12 +308,12 @@ struct Btree {
   u8 autoVacuum;        /* True if database supports auto-vacuum */
 #endif
   u16 pageSize;         /* Total number of bytes on a page */
-  u16 psAligned;        /* pageSize rounded up to a multiple of 8 */
   u16 usableSize;       /* Number of usable bytes on each page */
   int maxLocal;         /* Maximum local payload in non-LEAFDATA tables */
   int minLocal;         /* Minimum local payload in non-LEAFDATA tables */
   int maxLeaf;          /* Maximum local payload in a LEAFDATA table */
   int minLeaf;          /* Minimum local payload in a LEAFDATA table */
+  BusyHandler *pBusyHandler;   /* Callback for when there is lock contention */
 };
 typedef Btree Bt;
 
@@ -713,7 +713,7 @@ static void _pageIntegrity(MemPage *pPage){
   used = sqliteMallocRaw( pPage->pBt->pageSize );
   if( used==0 ) return;
   usableSize = pPage->pBt->usableSize;
-  assert( pPage->aData==&((unsigned char*)pPage)[-pPage->pBt->psAligned] );
+  assert( pPage->aData==&((unsigned char*)pPage)[-pPage->pBt->pageSize] );
   hdr = pPage->hdrOffset;
   assert( hdr==(pPage->pgno==1 ? 100 : 0) );
   assert( pPage->pgno==sqlite3pager_pagenumber(pPage->aData) );
@@ -1016,7 +1016,7 @@ static int initPage(
   assert( pBt!=0 );
   assert( pParent==0 || pParent->pBt==pBt );
   assert( pPage->pgno==sqlite3pager_pagenumber(pPage->aData) );
-  assert( pPage->aData == &((unsigned char*)pPage)[-pBt->psAligned] );
+  assert( pPage->aData == &((unsigned char*)pPage)[-pBt->pageSize] );
   if( pPage->pParent!=pParent && (pPage->pParent!=0 || pPage->isInit) ){
     /* The parent page should never change unless the file is corrupt */
     return SQLITE_CORRUPT; /* bkpt-CORRUPT */
@@ -1084,7 +1084,7 @@ static void zeroPage(MemPage *pPage, int flags){
   int first;
 
   assert( sqlite3pager_pagenumber(data)==pPage->pgno );
-  assert( &data[pBt->psAligned] == (unsigned char*)pPage );
+  assert( &data[pBt->pageSize] == (unsigned char*)pPage );
   assert( sqlite3pager_iswriteable(data) );
   memset(&data[hdr], 0, pBt->usableSize - hdr);
   data[hdr] = flags;
@@ -1113,7 +1113,7 @@ static int getPage(Btree *pBt, Pgno pgno, MemPage **ppPage){
   MemPage *pPage;
   rc = sqlite3pager_get(pBt->pPager, pgno, (void**)&aData);
   if( rc ) return rc;
-  pPage = (MemPage*)&aData[pBt->psAligned];
+  pPage = (MemPage*)&aData[pBt->pageSize];
   pPage->aData = aData;
   pPage->pBt = pBt;
   pPage->pgno = pgno;
@@ -1152,7 +1152,7 @@ static void releasePage(MemPage *pPage){
   if( pPage ){
     assert( pPage->aData );
     assert( pPage->pBt );
-    assert( &pPage->aData[pPage->pBt->psAligned]==(unsigned char*)pPage );
+    assert( &pPage->aData[pPage->pBt->pageSize]==(unsigned char*)pPage );
     sqlite3pager_unref(pPage->aData);
   }
 }
@@ -1163,7 +1163,9 @@ static void releasePage(MemPage *pPage){
 ** happens.
 */
 static void pageDestructor(void *pData, int pageSize){
-  MemPage *pPage = (MemPage*)&((char*)pData)[FORCE_ALIGNMENT(pageSize)];
+  MemPage *pPage;
+  assert( (pageSize & 7)==0 );
+  pPage = (MemPage*)&((char*)pData)[pageSize];
   if( pPage->pParent ){
     MemPage *pParent = pPage->pParent;
     pPage->pParent = 0;
@@ -1181,7 +1183,9 @@ static void pageDestructor(void *pData, int pageSize){
 ** page to agree with the restored data.
 */
 static void pageReinit(void *pData, int pageSize){
-  MemPage *pPage = (MemPage*)&((char*)pData)[FORCE_ALIGNMENT(pageSize)];
+  MemPage *pPage;
+  assert( (pageSize & 7)==0 );
+  pPage = (MemPage*)&((char*)pData)[pageSize];
   if( pPage->isInit ){
     pPage->isInit = 0;
     initPage(pPage, pPage->pParent);
@@ -1215,8 +1219,6 @@ int sqlite3BtreeOpen(
   assert( sizeof(u32)==4 );
   assert( sizeof(u16)==2 );
   assert( sizeof(Pgno)==4 );
-  assert( sizeof(ptr)==sizeof(char*) );
-  assert( sizeof(uptr)==sizeof(ptr) );
 
   pBt = sqliteMalloc( sizeof(*pBt) );
   if( pBt==0 ){
@@ -1237,7 +1239,8 @@ int sqlite3BtreeOpen(
   pBt->readOnly = sqlite3pager_isreadonly(pBt->pPager);
   sqlite3pager_read_fileheader(pBt->pPager, sizeof(zDbHeader), zDbHeader);
   pBt->pageSize = get2byte(&zDbHeader[16]);
-  if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE ){
+  if( pBt->pageSize<512 || pBt->pageSize>SQLITE_MAX_PAGE_SIZE
+       || ((pBt->pageSize-1)&pBt->pageSize)!=0 ){
     pBt->pageSize = SQLITE_DEFAULT_PAGE_SIZE;
     pBt->maxEmbedFrac = 64;   /* 25% */
     pBt->minEmbedFrac = 32;   /* 12.5% */
@@ -1269,7 +1272,7 @@ int sqlite3BtreeOpen(
 #endif
   }
   pBt->usableSize = pBt->pageSize - nReserve;
-  pBt->psAligned = FORCE_ALIGNMENT(pBt->pageSize);
+  assert( (pBt->pageSize & 7)==0 );  /* 8-byte alignment of pageSize */
   sqlite3pager_set_pagesize(pBt->pPager, pBt->pageSize);
   *ppBtree = pBt;
   return SQLITE_OK;
@@ -1291,6 +1294,7 @@ int sqlite3BtreeClose(Btree *pBt){
 ** Change the busy handler callback function.
 */
 int sqlite3BtreeSetBusyHandler(Btree *pBt, BusyHandler *pHandler){
+  pBt->pBusyHandler = pHandler;
   sqlite3pager_set_busyhandler(pBt->pPager, pHandler);
   return SQLITE_OK;
 }
@@ -1355,9 +1359,8 @@ int sqlite3BtreeSetPageSize(Btree *pBt, int pageSize, int nReserve){
   }
   if( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE &&
         ((pageSize-1)&pageSize)==0 ){
-    pBt->pageSize = pageSize;
-    pBt->psAligned = FORCE_ALIGNMENT(pageSize);
-    sqlite3pager_set_pagesize(pBt->pPager, pageSize);
+    assert( (pageSize & 7)==0 );
+    pBt->pageSize = sqlite3pager_set_pagesize(pBt->pPager, pageSize);
   }
   pBt->usableSize = pBt->pageSize - nReserve;
   return SQLITE_OK;
@@ -1416,7 +1419,7 @@ int sqlite3BtreeGetAutoVacuum(Btree *pBt){
 ** if there is a locking protocol violation.
 */
 static int lockBtree(Btree *pBt){
-  int rc;
+  int rc, pageSize;
   MemPage *pPage1;
   if( pBt->pPage1 ) return SQLITE_OK;
   rc = getPage(pBt, 1, &pPage1);
@@ -1435,12 +1438,16 @@ static int lockBtree(Btree *pBt){
     if( page1[18]>1 || page1[19]>1 ){
       goto page1_init_failed;
     }
-    pBt->pageSize = get2byte(&page1[16]);
-    pBt->usableSize = pBt->pageSize - page1[20];
+    pageSize = get2byte(&page1[16]);
+    if( ((pageSize-1)&pageSize)!=0 ){
+      goto page1_init_failed;
+    }
+    assert( (pageSize & 7)==0 );
+    pBt->pageSize = pageSize;
+    pBt->usableSize = pageSize - page1[20];
     if( pBt->usableSize<500 ){
       goto page1_init_failed;
     }
-    pBt->psAligned = FORCE_ALIGNMENT(pBt->pageSize);
     pBt->maxEmbedFrac = page1[21];
     pBt->minEmbedFrac = page1[22];
     pBt->minLeafFrac = page1[23];
@@ -1479,6 +1486,20 @@ page1_init_failed:
   return rc;
 }
 
+/*
+** This routine works like lockBtree() except that it also invokes the
+** busy callback if there is lock contention.
+*/
+static int lockBtreeWithRetry(Btree *pBt){
+  int rc = SQLITE_OK;
+  if( pBt->inTrans==TRANS_NONE ){
+    rc = sqlite3BtreeBeginTrans(pBt, 0);
+    pBt->inTrans = TRANS_NONE;
+  }
+  return rc;
+}
+       
+
 /*
 ** If there are no outstanding cursors and we are not in the middle
 ** of a transaction but there is a read lock on the database, then
@@ -1493,7 +1514,7 @@ static void unlockBtreeIfUnused(Btree *pBt){
   if( pBt->inTrans==TRANS_NONE && pBt->pCursor==0 && pBt->pPage1!=0 ){
     if( pBt->pPage1->aData==0 ){
       MemPage *pPage = pBt->pPage1;
-      pPage->aData = &((char*)pPage)[-pBt->psAligned];
+      pPage->aData = &((char*)pPage)[-pBt->pageSize];
       pPage->pBt = pBt;
       pPage->pgno = 1;
     }
@@ -1543,7 +1564,7 @@ static int newDatabase(Btree *pBt){
 ** transaction.  If the second argument is 2 or more and exclusive
 ** transaction is started, meaning that no other process is allowed
 ** to access the database.  A preexisting transaction may not be
-** upgrade to exclusive by calling this routine a second time - the
+** upgraded to exclusive by calling this routine a second time - the
 ** exclusivity flag only works for a new transaction.
 **
 ** A write-transaction must be started before attempting any 
@@ -1558,43 +1579,60 @@ static int newDatabase(Btree *pBt){
 **      sqlite3BtreeDelete()
 **      sqlite3BtreeUpdateMeta()
 **
-** If wrflag is true, then nMaster specifies the maximum length of
-** a master journal file name supplied later via sqlite3BtreeSync().
-** This is so that appropriate space can be allocated in the journal file
-** when it is created..
+** If an initial attempt to acquire the lock fails because of lock contention
+** and the database was previously unlocked, then invoke the busy handler
+** if there is one.  But if there was previously a read-lock, do not
+** invoke the busy handler - just return SQLITE_BUSY.  SQLITE_BUSY is 
+** returned when there is already a read-lock in order to avoid a deadlock.
+**
+** Suppose there are two processes A and B.  A has a read lock and B has
+** a reserved lock.  B tries to promote to exclusive but is blocked because
+** of A's read lock.  A tries to promote to reserved but is blocked by B.
+** One or the other of the two processes must give way or there can be
+** no progress.  By returning SQLITE_BUSY and not invoking the busy callback
+** when A already has a read lock, we encourage A to give up and let B
+** proceed.
 */
 int sqlite3BtreeBeginTrans(Btree *pBt, int wrflag){
   int rc = SQLITE_OK;
+  int busy = 0;
+  BusyHandler *pH;
 
   /* If the btree is already in a write-transaction, or it
   ** is already in a read-transaction and a read-transaction
   ** is requested, this is a no-op.
   */
-  if( pBt->inTrans==TRANS_WRITE || 
-      (pBt->inTrans==TRANS_READ && !wrflag) ){
+  if( pBt->inTrans==TRANS_WRITE || (pBt->inTrans==TRANS_READ && !wrflag) ){
     return SQLITE_OK;
   }
+
+  /* Write transactions are not possible on a read-only database */
   if( pBt->readOnly && wrflag ){
     return SQLITE_READONLY;
   }
 
-  if( pBt->pPage1==0 ){
-    rc = lockBtree(pBt);
-  }
-
-  if( rc==SQLITE_OK && wrflag ){
-    rc = sqlite3pager_begin(pBt->pPage1->aData, wrflag>1);
+  do {
+    if( pBt->pPage1==0 ){
+      rc = lockBtree(pBt);
+    }
+  
+    if( rc==SQLITE_OK && wrflag ){
+      rc = sqlite3pager_begin(pBt->pPage1->aData, wrflag>1);
+      if( rc==SQLITE_OK ){
+        rc = newDatabase(pBt);
+      }
+    }
+  
     if( rc==SQLITE_OK ){
-      rc = newDatabase(pBt);
+      pBt->inTrans = (wrflag?TRANS_WRITE:TRANS_READ);
+      if( wrflag ) pBt->inStmt = 0;
+    }else{
+      unlockBtreeIfUnused(pBt);
     }
-  }
-
-  if( rc==SQLITE_OK ){
-    pBt->inTrans = (wrflag?TRANS_WRITE:TRANS_READ);
-    if( wrflag ) pBt->inStmt = 0;
-  }else{
-    unlockBtreeIfUnused(pBt);
-  }
+  }while( rc==SQLITE_BUSY && pBt->inTrans==TRANS_NONE &&
+      (pH = pBt->pBusyHandler)!=0 && 
+      pH->xFunc && pH->xFunc(pH->pArg, busy++)
+  );
   return rc;
 }
 
@@ -1843,7 +1881,10 @@ static int autoVacuumCommit(Btree *pBt, Pgno *nTrunc){
 
     rc = ptrmapGet(pBt, iDbPage, &eType, &iPtrPage);
     if( rc!=SQLITE_OK ) goto autovacuum_out;
-    assert( eType!=PTRMAP_ROOTPAGE );
+    if( eType==PTRMAP_ROOTPAGE ){
+      rc = SQLITE_CORRUPT;
+      goto autovacuum_out;
+    }
 
     /* If iDbPage is free, do not swap it.  */
     if( eType==PTRMAP_FREEPAGE ){
@@ -2113,7 +2154,7 @@ int sqlite3BtreeCursor(
     }
   }
   if( pBt->pPage1==0 ){
-    rc = lockBtree(pBt);
+    rc = lockBtreeWithRetry(pBt);
     if( rc!=SQLITE_OK ){
       return rc;
     }
@@ -2124,12 +2165,11 @@ int sqlite3BtreeCursor(
     goto create_cursor_exception;
   }
   pCur->pgnoRoot = (Pgno)iTable;
+  pCur->pPage = 0;  /* For exit-handler, in case getAndInitPage() fails. */
   if( iTable==1 && sqlite3pager_pagecount(pBt->pPager)==0 ){
     rc = SQLITE_EMPTY;
-    pCur->pPage = 0;
     goto create_cursor_exception;
   }
-  pCur->pPage = 0;  /* For exit-handler, in case getAndInitPage() fails. */
   rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->pPage, 0);
   if( rc!=SQLITE_OK ){
     goto create_cursor_exception;
@@ -2375,6 +2415,9 @@ static int getPayload(
 int sqlite3BtreeKey(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
   assert( pCur->isValid );
   assert( pCur->pPage!=0 );
+  if( pCur->pPage->intKey ){
+    return SQLITE_CORRUPT;
+  }
   assert( pCur->pPage->intKey==0 );
   assert( pCur->idx>=0 && pCur->idx<pCur->pPage->nCell );
   return getPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
@@ -3213,8 +3256,8 @@ static int clearCell(MemPage *pPage, unsigned char *pCell){
     if( rc ) return rc;
     ovflPgno = get4byte(pOvfl->aData);
     rc = freePage(pOvfl);
-    if( rc ) return rc;
     sqlite3pager_unref(pOvfl->aData);
+    if( rc ) return rc;
   }
   return SQLITE_OK;
 }
@@ -3343,7 +3386,7 @@ static int reparentPage(Btree *pBt, Pgno pgno, MemPage *pNewParent, int idx){
   assert( pBt->pPager!=0 );
   aData = sqlite3pager_lookup(pBt->pPager, pgno);
   if( aData ){
-    pThis = (MemPage*)&aData[pBt->psAligned];
+    pThis = (MemPage*)&aData[pBt->pageSize];
     assert( pThis->aData==aData );
     if( pThis->isInit ){
       if( pThis->pParent!=pNewParent ){
@@ -3486,7 +3529,8 @@ static int insertCell(
     end = cellOffset + 2*pPage->nCell + 2;
     ins = cellOffset + 2*i;
     if( end > top - sz ){
-      defragmentPage(pPage);
+      int rc = defragmentPage(pPage);
+      if( rc!=SQLITE_OK ) return rc;
       top = get2byte(&data[hdr+5]);
       assert( end + sz <= top );
     }
@@ -3718,7 +3762,8 @@ static int balance_quick(MemPage *pPage, MemPage *pParent){
 static int balance_nonroot(MemPage *pPage){
   MemPage *pParent;            /* The parent of pPage */
   Btree *pBt;                  /* The whole database */
-  int nCell = 0;               /* Number of cells in aCell[] */
+  int nCell = 0;               /* Number of cells in apCell[] */
+  int nMaxCells = 0;           /* Allocated size of apCell, szCell, aFrom. */
   int nOld;                    /* Number of pages in apOld[] */
   int nNew;                    /* Number of pages in apNew[] */
   int nDiv;                    /* Number of cells in apDiv[] */
@@ -3732,7 +3777,6 @@ static int balance_nonroot(MemPage *pPage){
   int pageFlags;               /* Value of pPage->aData[0] */
   int subtotal;                /* Subtotal of bytes in cells on one page */
   int iSpace = 0;              /* First unused byte of aSpace[] */
-  int mxCellPerPage;           /* Maximum number of cells in one page */
   MemPage *apOld[NB];          /* pPage and up to two siblings */
   Pgno pgnoOld[NB];            /* Page numbers for each page in apOld[] */
   MemPage *apCopy[NB];         /* Private copies of apOld[] pages */
@@ -3742,7 +3786,7 @@ static int balance_nonroot(MemPage *pPage){
   u8 *apDiv[NB];               /* Divider cells in pParent */
   int cntNew[NB+2];            /* Index in aCell[] of cell after i-th page */
   int szNew[NB+2];             /* Combined size of cells place on i-th page */
-  u8 **apCell;                 /* All cells begin balanced */
+  u8 **apCell = 0;             /* All cells begin balanced */
   int *szCell;                 /* Local size of all cells in apCell[] */
   u8 *aCopy[NB];               /* Space for holding data of apCopy[] */
   u8 *aSpace;                  /* Space to hold copies of dividers cells */
@@ -3786,31 +3830,6 @@ static int balance_nonroot(MemPage *pPage){
   }
 #endif
 
-  /*
-  ** Allocate space for memory structures
-  */
-  mxCellPerPage = MX_CELL(pBt);
-  apCell = sqliteMallocRaw( 
-       (mxCellPerPage+2)*NB*(sizeof(u8*)+sizeof(int))
-     + sizeof(MemPage)*NB
-     + pBt->psAligned*(5+NB)
-     + (ISAUTOVACUUM ? (mxCellPerPage+2)*NN*2 : 0)
-  );
-  if( apCell==0 ){
-    return SQLITE_NOMEM;
-  }
-  szCell = (int*)&apCell[(mxCellPerPage+2)*NB];
-  aCopy[0] = (u8*)&szCell[(mxCellPerPage+2)*NB];
-  for(i=1; i<NB; i++){
-    aCopy[i] = &aCopy[i-1][pBt->psAligned+sizeof(MemPage)];
-  }
-  aSpace = &aCopy[NB-1][pBt->psAligned+sizeof(MemPage)];
-#ifndef SQLITE_OMIT_AUTOVACUUM
-  if( pBt->autoVacuum ){
-    aFrom = &aSpace[5*pBt->psAligned];
-  }
-#endif
-  
   /*
   ** Find the cell in the parent page whose left child points back
   ** to pPage.  The "idx" variable is the index of that cell.  If pPage
@@ -3871,8 +3890,42 @@ static int balance_nonroot(MemPage *pPage){
     apCopy[i] = 0;
     assert( i==nOld );
     nOld++;
+    nMaxCells += 1+apOld[i]->nCell+apOld[i]->nOverflow;
   }
 
+  /* Make nMaxCells a multiple of 2 in order to preserve 8-byte
+  ** alignment */
+  nMaxCells = (nMaxCells + 1)&~1;
+
+  /*
+  ** Allocate space for memory structures
+  */
+  apCell = sqliteMallocRaw( 
+       nMaxCells*sizeof(u8*)                           /* apCell */
+     + nMaxCells*sizeof(int)                           /* szCell */
+     + ROUND8(sizeof(MemPage))*NB                      /* aCopy */
+     + pBt->pageSize*(5+NB)                            /* aSpace */
+     + (ISAUTOVACUUM ? nMaxCells : 0)                  /* aFrom */
+  );
+  if( apCell==0 ){
+    rc = SQLITE_NOMEM;
+    goto balance_cleanup;
+  }
+  szCell = (int*)&apCell[nMaxCells];
+  aCopy[0] = (u8*)&szCell[nMaxCells];
+  assert( ((aCopy[0] - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */
+  for(i=1; i<NB; i++){
+    aCopy[i] = &aCopy[i-1][pBt->pageSize+ROUND8(sizeof(MemPage))];
+    assert( ((aCopy[i] - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */
+  }
+  aSpace = &aCopy[NB-1][pBt->pageSize+ROUND8(sizeof(MemPage))];
+  assert( ((aSpace - (u8*)apCell) & 7)==0 ); /* 8-byte alignment required */
+#ifndef SQLITE_OMIT_AUTOVACUUM
+  if( pBt->autoVacuum ){
+    aFrom = &aSpace[5*pBt->pageSize];
+  }
+#endif
+  
   /*
   ** Make copies of the content of pPage and its siblings into aOld[].
   ** The rest of this function will use data from the copies rather
@@ -3880,10 +3933,12 @@ static int balance_nonroot(MemPage *pPage){
   ** process of being overwritten.
   */
   for(i=0; i<nOld; i++){
-    MemPage *p = apCopy[i] = (MemPage*)&aCopy[i][pBt->psAligned];
-    p->aData = &((u8*)p)[-pBt->psAligned];
-    memcpy(p->aData, apOld[i]->aData, pBt->psAligned + sizeof(MemPage));
-    p->aData = &((u8*)p)[-pBt->psAligned];
+    MemPage *p = apCopy[i] = (MemPage*)&aCopy[i][pBt->pageSize];
+    p->aData = &((u8*)p)[-pBt->pageSize];
+    memcpy(p->aData, apOld[i]->aData, pBt->pageSize + sizeof(MemPage));
+    /* The memcpy() above changes the value of p->aData so we have to
+    ** set it again. */
+    p->aData = &((u8*)p)[-pBt->pageSize];
   }
 
   /*
@@ -3909,6 +3964,7 @@ static int balance_nonroot(MemPage *pPage){
     MemPage *pOld = apCopy[i];
     int limit = pOld->nCell+pOld->nOverflow;
     for(j=0; j<limit; j++){
+      assert( nCell<nMaxCells );
       apCell[nCell] = findOverflowCell(pOld, j);
       szCell[nCell] = cellSizePtr(pOld, apCell[nCell]);
 #ifndef SQLITE_OMIT_AUTOVACUUM
@@ -3936,10 +3992,11 @@ static int balance_nonroot(MemPage *pPage){
         dropCell(pParent, nxDiv, sz);
       }else{
         u8 *pTemp;
+        assert( nCell<nMaxCells );
         szCell[nCell] = sz;
         pTemp = &aSpace[iSpace];
         iSpace += sz;
-        assert( iSpace<=pBt->psAligned*5 );
+        assert( iSpace<=pBt->pageSize*5 );
         memcpy(pTemp, apDiv[i], sz);
         apCell[nCell] = pTemp+leafCorrection;
 #ifndef SQLITE_OMIT_AUTOVACUUM
@@ -3981,6 +4038,7 @@ static int balance_nonroot(MemPage *pPage){
   */
   usableSpace = pBt->usableSize - 12 + leafCorrection;
   for(subtotal=k=i=0; i<nCell; i++){
+    assert( i<nMaxCells );
     subtotal += szCell[i] + 2;
     if( subtotal > usableSpace ){
       szNew[k] = subtotal - szCell[i];
@@ -4012,6 +4070,8 @@ static int balance_nonroot(MemPage *pPage){
 
     r = cntNew[i-1] - 1;
     d = r + 1 - leafData;
+    assert( d<nMaxCells );
+    assert( r<nMaxCells );
     while( szRight==0 || szRight+szCell[d]+2<=szLeft-(szCell[r]+2) ){
       szRight += szCell[d] + 2;
       szLeft -= szCell[r] + 2;
@@ -4108,6 +4168,7 @@ static int balance_nonroot(MemPage *pPage){
   for(i=0; i<nNew; i++){
     /* Assemble the new sibling page. */
     MemPage *pNew = apNew[i];
+    assert( j<nMaxCells );
     assert( pNew->pgno==pgnoNew[i] );
     assemblePage(pNew, cntNew[i]-j, &apCell[j], &szCell[j]);
     assert( pNew->nCell>0 );
@@ -4121,6 +4182,7 @@ static int balance_nonroot(MemPage *pPage){
     */
     if( pBt->autoVacuum ){
       for(k=j; k<cntNew[i]; k++){
+        assert( k<nMaxCells );
         if( aFrom[k]==0xFF || apCopy[aFrom[k]]->pgno!=pNew->pgno ){
           rc = ptrmapPutOvfl(pNew, k-j);
           if( rc!=SQLITE_OK ){
@@ -4140,6 +4202,8 @@ static int balance_nonroot(MemPage *pPage){
       u8 *pCell;
       u8 *pTemp;
       int sz;
+
+      assert( j<nMaxCells );
       pCell = apCell[j];
       sz = szCell[j] + leafCorrection;
       if( !pNew->leaf ){
@@ -4157,13 +4221,13 @@ static int balance_nonroot(MemPage *pPage){
         pCell = &aSpace[iSpace];
         fillInCell(pParent, pCell, 0, info.nKey, 0, 0, &sz);
         iSpace += sz;
-        assert( iSpace<=pBt->psAligned*5 );
+        assert( iSpace<=pBt->pageSize*5 );
         pTemp = 0;
       }else{
         pCell -= 4;
         pTemp = &aSpace[iSpace];
         iSpace += sz;
-        assert( iSpace<=pBt->psAligned*5 );
+        assert( iSpace<=pBt->pageSize*5 );
       }
       rc = insertCell(pParent, nxDiv, pCell, sz, pTemp, 4);
       if( rc!=SQLITE_OK ) goto balance_cleanup;
@@ -4367,7 +4431,7 @@ static int balance_deeper(MemPage *pPage){
   memcpy(&cdata[brk], &data[brk], usableSize-brk);
   assert( pChild->isInit==0 );
   rc = initPage(pChild, pPage);
-  if( rc ) return rc;
+  if( rc ) goto balancedeeper_out;
   memcpy(pChild->aOvfl, pPage->aOvfl, pPage->nOverflow*sizeof(pPage->aOvfl[0]));
   pChild->nOverflow = pPage->nOverflow;
   if( pChild->nOverflow ){
@@ -4381,7 +4445,7 @@ static int balance_deeper(MemPage *pPage){
   if( pBt->autoVacuum ){
     int i;
     rc = ptrmapPut(pBt, pChild->pgno, PTRMAP_BTREE, pPage->pgno);
-    if( rc ) return rc;
+    if( rc ) goto balancedeeper_out;
     for(i=0; i<pChild->nCell; i++){
       rc = ptrmapPutOvfl(pChild, i);
       if( rc!=SQLITE_OK ){
@@ -4391,6 +4455,8 @@ static int balance_deeper(MemPage *pPage){
   }
 #endif
   rc = balance_nonroot(pChild);
+
+balancedeeper_out:
   releasePage(pChild);
   return rc;
 }
@@ -4577,7 +4643,7 @@ int sqlite3BtreeDelete(BtCursor *pCur){
     unsigned char *pNext;
     int szNext;
     int notUsed;
-    unsigned char *tempCell;
+    unsigned char *tempCell = 0;
     assert( !pPage->leafData );
     getTempCursor(pCur, &leafCur);
     rc = sqlite3BtreeNext(&leafCur, &notUsed);
@@ -4585,26 +4651,34 @@ int sqlite3BtreeDelete(BtCursor *pCur){
       if( rc!=SQLITE_NOMEM ){
         rc = SQLITE_CORRUPT;  /* bkpt-CORRUPT */
       }
-      return rc;
     }
-    rc = sqlite3pager_write(leafCur.pPage->aData);
-    if( rc ) return rc;
-    TRACE(("DELETE: table=%d delete internal from %d replace from leaf %d\n",
-       pCur->pgnoRoot, pPage->pgno, leafCur.pPage->pgno));
-    dropCell(pPage, pCur->idx, cellSizePtr(pPage, pCell));
-    pNext = findCell(leafCur.pPage, leafCur.idx);
-    szNext = cellSizePtr(leafCur.pPage, pNext);
-    assert( MX_CELL_SIZE(pBt)>=szNext+4 );
-    tempCell = sqliteMallocRaw( MX_CELL_SIZE(pBt) );
-    if( tempCell==0 ) return SQLITE_NOMEM;
-    rc = insertCell(pPage, pCur->idx, pNext-4, szNext+4, tempCell, 0);
-    if( rc!=SQLITE_OK ) return rc;
-    put4byte(findOverflowCell(pPage, pCur->idx), pgnoChild);
-    rc = balance(pPage, 0);
+    if( rc==SQLITE_OK ){
+      rc = sqlite3pager_write(leafCur.pPage->aData);
+    }
+    if( rc==SQLITE_OK ){
+      TRACE(("DELETE: table=%d delete internal from %d replace from leaf %d\n",
+         pCur->pgnoRoot, pPage->pgno, leafCur.pPage->pgno));
+      dropCell(pPage, pCur->idx, cellSizePtr(pPage, pCell));
+      pNext = findCell(leafCur.pPage, leafCur.idx);
+      szNext = cellSizePtr(leafCur.pPage, pNext);
+      assert( MX_CELL_SIZE(pBt)>=szNext+4 );
+      tempCell = sqliteMallocRaw( MX_CELL_SIZE(pBt) );
+      if( tempCell==0 ){
+        rc = SQLITE_NOMEM;
+      }
+    }
+    if( rc==SQLITE_OK ){
+      rc = insertCell(pPage, pCur->idx, pNext-4, szNext+4, tempCell, 0);
+    }
+    if( rc==SQLITE_OK ){
+      put4byte(findOverflowCell(pPage, pCur->idx), pgnoChild);
+      rc = balance(pPage, 0);
+    }
+    if( rc==SQLITE_OK ){
+      dropCell(leafCur.pPage, leafCur.idx, szNext);
+      rc = balance(leafCur.pPage, 0);
+    }
     sqliteFree(tempCell);
-    if( rc ) return rc;
-    dropCell(leafCur.pPage, leafCur.idx, szNext);
-    rc = balance(leafCur.pPage, 0);
     releaseTempCursor(&leafCur);
   }else{
     TRACE(("DELETE: table=%d delete from leaf %d\n",
@@ -4612,7 +4686,9 @@ int sqlite3BtreeDelete(BtCursor *pCur){
     dropCell(pPage, pCur->idx, cellSizePtr(pPage, pCell));
     rc = balance(pPage, 0);
   }
-  moveToRoot(pCur);
+  if( rc==SQLITE_OK ){
+    moveToRoot(pCur);
+  }
   return rc;
 }
 
@@ -4690,8 +4766,13 @@ int sqlite3BtreeCreateTable(Btree *pBt, int *piTable, int flags){
         return rc;
       }
       rc = ptrmapGet(pBt, pgnoRoot, &eType, &iPtrPage);
+      if( rc!=SQLITE_OK || eType==PTRMAP_ROOTPAGE || eType==PTRMAP_FREEPAGE ){
+        releasePage(pRoot);
+        return rc;
+      }
       assert( eType!=PTRMAP_ROOTPAGE );
       assert( eType!=PTRMAP_FREEPAGE );
+      rc = sqlite3pager_write(pRoot->aData);
       if( rc!=SQLITE_OK ){
         releasePage(pRoot);
         return rc;
@@ -4748,7 +4829,7 @@ static int clearDatabasePage(
   MemPage *pParent,     /* Parent page.  NULL for the root */
   int freePageFlag      /* Deallocate page if true */
 ){
-  MemPage *pPage;
+  MemPage *pPage = 0;
   int rc;
   unsigned char *pCell;
   int i;
@@ -4758,27 +4839,29 @@ static int clearDatabasePage(
   }
 
   rc = getAndInitPage(pBt, pgno, &pPage, pParent);
-  if( rc ) return rc;
+  if( rc ) goto cleardatabasepage_out;
   rc = sqlite3pager_write(pPage->aData);
-  if( rc ) return rc;
+  if( rc ) goto cleardatabasepage_out;
   for(i=0; i<pPage->nCell; i++){
     pCell = findCell(pPage, i);
     if( !pPage->leaf ){
       rc = clearDatabasePage(pBt, get4byte(pCell), pPage->pParent, 1);
-      if( rc ) return rc;
+      if( rc ) goto cleardatabasepage_out;
     }
     rc = clearCell(pPage, pCell);
-    if( rc ) return rc;
+    if( rc ) goto cleardatabasepage_out;
   }
   if( !pPage->leaf ){
     rc = clearDatabasePage(pBt, get4byte(&pPage->aData[8]), pPage->pParent, 1);
-    if( rc ) return rc;
+    if( rc ) goto cleardatabasepage_out;
   }
   if( freePageFlag ){
     rc = freePage(pPage);
   }else{
     zeroPage(pPage, pPage->aData[0] | PTF_LEAF);
   }
+
+cleardatabasepage_out:
   releasePage(pPage);
   return rc;
 }
@@ -4852,7 +4935,10 @@ int sqlite3BtreeDropTable(Btree *pBt, int iTable, int *piMoved){
   rc = getPage(pBt, (Pgno)iTable, &pPage);
   if( rc ) return rc;
   rc = sqlite3BtreeClearTable(pBt, iTable);
-  if( rc ) return rc;
+  if( rc ){
+    releasePage(pPage);
+    return rc;
+  }
 
   *piMoved = 0;
 
@@ -5520,7 +5606,7 @@ char *sqlite3BtreeIntegrityCheck(Btree *pBt, int *aRoot, int nRoot){
   IntegrityCk sCheck;
 
   nRef = *sqlite3pager_stats(pBt->pPager);
-  if( lockBtree(pBt)!=SQLITE_OK ){
+  if( lockBtreeWithRetry(pBt)!=SQLITE_OK ){
     return sqliteStrDup("Unable to acquire a read lock on the database");
   }
   sCheck.pBt = pBt;
@@ -5711,3 +5797,16 @@ int sqlite3BtreeSync(Btree *pBt, const char *zMaster){
   }
   return SQLITE_OK;
 }
+
+#ifndef SQLITE_OMIT_GLOBALRECOVER
+/*
+** Reset the btree and underlying pager after a malloc() failure. Any
+** transaction that was active when malloc() failed is rolled back.
+*/
+int sqlite3BtreeReset(Btree *pBt){
+  if( pBt->pCursor ) return SQLITE_BUSY;
+  pBt->inTrans = TRANS_NONE;
+  unlockBtreeIfUnused(pBt);
+  return sqlite3pager_reset(pBt->pPager);
+}
+#endif
index d4ee97ef38e8390d73387f994643956f2dd8b694..bd09b46423b85e4b33f8847404c960163584fb5c 100644 (file)
@@ -73,6 +73,7 @@ int sqlite3BtreeCreateTable(Btree*, int*, int flags);
 int sqlite3BtreeIsInTrans(Btree*);
 int sqlite3BtreeIsInStmt(Btree*);
 int sqlite3BtreeSync(Btree*, const char *zMaster);
+int sqlite3BtreeReset(Btree *);
 
 const char *sqlite3BtreeGetFilename(Btree *);
 const char *sqlite3BtreeGetDirname(Btree *);
index 1908a4711852b5ca90bcd25267e9bf4a7ea05379..450316e5a4b5defc5919ad66c55ce8d47064cc80 100644 (file)
@@ -168,7 +168,7 @@ Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
   int i;
   assert( zName!=0 );
   assert( (db->flags & SQLITE_Initialized) || db->init.busy );
-  for(i=0; i<db->nDb; i++){
+  for(i=OMIT_TEMPDB; i<db->nDb; i++){
     int j = (i<2) ? i^1 : i;   /* Search TEMP before MAIN */
     if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
     p = sqlite3HashFind(&db->aDb[j].tblHash, zName, strlen(zName)+1);
@@ -227,7 +227,7 @@ Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
   Index *p = 0;
   int i;
   assert( (db->flags & SQLITE_Initialized) || db->init.busy );
-  for(i=0; i<db->nDb; i++){
+  for(i=OMIT_TEMPDB; i<db->nDb; i++){
     int j = (i<2) ? i^1 : i;  /* Search TEMP before MAIN */
     if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
     p = sqlite3HashFind(&db->aDb[j].idxHash, zName, strlen(zName)+1);
@@ -266,9 +266,10 @@ static void sqliteDeleteIndex(sqlite3 *db, Index *p){
 }
 
 /*
-** Unlink the given index from its table, then remove
-** the index from the index hash table and free its memory
-** structures.
+** For the index called zIdxName which is found in the database iDb,
+** unlike that index from its Table then remove the index from
+** the index hash table and free all memory structures associated
+** with the index.
 */
 void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){
   Index *pIndex;
@@ -393,12 +394,14 @@ static void sqliteResetColumnNames(Table *pTable){
   int i;
   Column *pCol;
   assert( pTable!=0 );
-  for(i=0, pCol=pTable->aCol; i<pTable->nCol; i++, pCol++){
-    sqliteFree(pCol->zName);
-    sqlite3ExprDelete(pCol->pDflt);
-    sqliteFree(pCol->zType);
+  if( (pCol = pTable->aCol)!=0 ){
+    for(i=0; i<pTable->nCol; i++, pCol++){
+      sqliteFree(pCol->zName);
+      sqlite3ExprDelete(pCol->pDflt);
+      sqliteFree(pCol->zType);
+    }
+    sqliteFree(pTable->aCol);
   }
-  sqliteFree(pTable->aCol);
   pTable->aCol = 0;
   pTable->nCol = 0;
 }
@@ -424,6 +427,13 @@ void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
 
   if( pTable==0 ) return;
 
+  /* Do not delete the table until the reference count reaches zero. */
+  pTable->nRef--;
+  if( pTable->nRef>0 ){
+    return;
+  }
+  assert( pTable->nRef==0 );
+
   /* Delete all indices associated with this table
   */
   for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){
@@ -494,7 +504,7 @@ void sqlite3UnlinkAndDeleteTable(sqlite3 *db, int iDb, const char *zTabName){
 ** is obtained from sqliteMalloc() and must be freed by the calling
 ** function.
 **
-** Tokens are really just pointers into the original SQL text and so
+** Tokens are often just pointers into the original SQL text and so
 ** are not \000 terminated and are not persistent.  The returned string
 ** is \000 terminated and is persistent.
 */
@@ -535,7 +545,8 @@ static int findDb(sqlite3 *db, Token *pName){
   if( zName ){
     n = strlen(zName);
     for(i=(db->nDb-1), pDb=&db->aDb[i]; i>=0; i--, pDb--){
-      if( n==strlen(pDb->zName) && 0==sqlite3StrICmp(pDb->zName, zName) ){
+      if( (!OMIT_TEMPDB || i!=1 ) && n==strlen(pDb->zName) && 
+          0==sqlite3StrICmp(pDb->zName, zName) ){
         break;
       }
     }
@@ -595,6 +606,7 @@ int sqlite3TwoPartName(
 */
 int sqlite3CheckObjectName(Parse *pParse, const char *zName){
   if( !pParse->db->init.busy && pParse->nested==0 
+          && (pParse->db->flags & SQLITE_WriteSchema)==0
           && 0==sqlite3StrNICmp(zName, "sqlite_", 7) ){
     sqlite3ErrorMsg(pParse, "object name reserved for internal use: %s", zName);
     return SQLITE_ERROR;
@@ -654,12 +666,12 @@ void sqlite3StartTable(
   */
   iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
   if( iDb<0 ) return;
-  if( isTemp && iDb>1 ){
+  if( !OMIT_TEMPDB && isTemp && iDb>1 ){
     /* If creating a temp table, the name may not be qualified */
     sqlite3ErrorMsg(pParse, "temporary table name must be unqualified");
     return;
   }
-  if( isTemp ) iDb = 1;
+  if( !OMIT_TEMPDB && isTemp ) iDb = 1;
 
   pParse->sNameToken = *pName;
   zName = sqlite3NameFromToken(pName);
@@ -677,13 +689,13 @@ void sqlite3StartTable(
       goto begin_table_error;
     }
     if( isView ){
-      if( isTemp ){
+      if( !OMIT_TEMPDB && isTemp ){
         code = SQLITE_CREATE_TEMP_VIEW;
       }else{
         code = SQLITE_CREATE_VIEW;
       }
     }else{
-      if( isTemp ){
+      if( !OMIT_TEMPDB && isTemp ){
         code = SQLITE_CREATE_TEMP_TABLE;
       }else{
         code = SQLITE_CREATE_TABLE;
@@ -724,6 +736,7 @@ void sqlite3StartTable(
   pTable->iPKey = -1;
   pTable->pIndex = 0;
   pTable->iDb = iDb;
+  pTable->nRef = 1;
   if( pParse->pNewTable ) sqlite3DeleteTable(db, pParse->pNewTable);
   pParse->pNewTable = pTable;
 
@@ -778,10 +791,10 @@ void sqlite3StartTable(
       sqlite3VdbeAddOp(v, OP_CreateTable, iDb, 0);
     }
     sqlite3OpenMasterTable(v, iDb);
-    sqlite3VdbeAddOp(v, OP_NewRecno, 0, 0);
+    sqlite3VdbeAddOp(v, OP_NewRowid, 0, 0);
     sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
-    sqlite3VdbeAddOp(v, OP_String8, 0, 0);
-    sqlite3VdbeAddOp(v, OP_PutIntKey, 0, 0);
+    sqlite3VdbeAddOp(v, OP_Null, 0, 0);
+    sqlite3VdbeAddOp(v, OP_Insert, 0, 0);
     sqlite3VdbeAddOp(v, OP_Close, 0, 0);
     sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
   }
@@ -834,7 +847,10 @@ void sqlite3AddColumn(Parse *pParse, Token *pName){
   if( (p->nCol & 0x7)==0 ){
     Column *aNew;
     aNew = sqliteRealloc( p->aCol, (p->nCol+8)*sizeof(p->aCol[0]));
-    if( aNew==0 ) return;
+    if( aNew==0 ){
+      sqliteFree(z);
+      return;
+    }
     p->aCol = aNew;
   }
   pCol = &p->aCol[p->nCol];
@@ -1069,146 +1085,6 @@ void sqlite3AddCollateType(Parse *pParse, const char *zType, int nType){
   }
 }
 
-/*
-** Locate and return an entry from the db.aCollSeq hash table. If the entry
-** specified by zName and nName is not found and parameter 'create' is
-** true, then create a new entry. Otherwise return NULL.
-**
-** Each pointer stored in the sqlite3.aCollSeq hash table contains an
-** array of three CollSeq structures. The first is the collation sequence
-** prefferred for UTF-8, the second UTF-16le, and the third UTF-16be.
-**
-** Stored immediately after the three collation sequences is a copy of
-** the collation sequence name. A pointer to this string is stored in
-** each collation sequence structure.
-*/
-static CollSeq * findCollSeqEntry(
-  sqlite3 *db,
-  const char *zName,
-  int nName,
-  int create
-){
-  CollSeq *pColl;
-  if( nName<0 ) nName = strlen(zName);
-  pColl = sqlite3HashFind(&db->aCollSeq, zName, nName);
-
-  if( 0==pColl && create ){
-    pColl = sqliteMalloc( 3*sizeof(*pColl) + nName + 1 );
-    if( pColl ){
-      pColl[0].zName = (char*)&pColl[3];
-      pColl[0].enc = SQLITE_UTF8;
-      pColl[1].zName = (char*)&pColl[3];
-      pColl[1].enc = SQLITE_UTF16LE;
-      pColl[2].zName = (char*)&pColl[3];
-      pColl[2].enc = SQLITE_UTF16BE;
-      memcpy(pColl[0].zName, zName, nName);
-      pColl[0].zName[nName] = 0;
-      sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, nName, pColl);
-    }
-  }
-  return pColl;
-}
-
-/*
-** Parameter zName points to a UTF-8 encoded string nName bytes long.
-** Return the CollSeq* pointer for the collation sequence named zName
-** for the encoding 'enc' from the database 'db'.
-**
-** If the entry specified is not found and 'create' is true, then create a
-** new entry.  Otherwise return NULL.
-*/
-CollSeq *sqlite3FindCollSeq(
-  sqlite3 *db,
-  u8 enc,
-  const char *zName,
-  int nName,
-  int create
-){
-  CollSeq *pColl = findCollSeqEntry(db, zName, nName, create);
-  assert( SQLITE_UTF8==1 && SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
-  assert( enc>=SQLITE_UTF8 && enc<=SQLITE_UTF16BE );
-  if( pColl ) pColl += enc-1;
-  return pColl;
-}
-
-/*
-** Invoke the 'collation needed' callback to request a collation sequence
-** in the database text encoding of name zName, length nName.
-** If the collation sequence
-*/
-static void callCollNeeded(sqlite3 *db, const char *zName, int nName){
-  assert( !db->xCollNeeded || !db->xCollNeeded16 );
-  if( nName<0 ) nName = strlen(zName);
-  if( db->xCollNeeded ){
-    char *zExternal = sqliteStrNDup(zName, nName);
-    if( !zExternal ) return;
-    db->xCollNeeded(db->pCollNeededArg, db, (int)db->enc, zExternal);
-    sqliteFree(zExternal);
-  }
-#ifndef SQLITE_OMIT_UTF16
-  if( db->xCollNeeded16 ){
-    char const *zExternal;
-    sqlite3_value *pTmp = sqlite3GetTransientValue(db);
-    sqlite3ValueSetStr(pTmp, -1, zName, SQLITE_UTF8, SQLITE_STATIC);
-    zExternal = sqlite3ValueText(pTmp, SQLITE_UTF16NATIVE);
-    if( !zExternal ) return;
-    db->xCollNeeded16(db->pCollNeededArg, db, (int)db->enc, zExternal);
-  }
-#endif
-}
-
-/*
-** This routine is called if the collation factory fails to deliver a
-** collation function in the best encoding but there may be other versions
-** of this collation function (for other text encodings) available. Use one
-** of these instead if they exist. Avoid a UTF-8 <-> UTF-16 conversion if
-** possible.
-*/
-static int synthCollSeq(Parse *pParse, CollSeq *pColl){
-  CollSeq *pColl2;
-  char *z = pColl->zName;
-  int n = strlen(z);
-  sqlite3 *db = pParse->db;
-  int i;
-  static const u8 aEnc[] = { SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF8 };
-  for(i=0; i<3; i++){
-    pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, n, 0);
-    if( pColl2->xCmp!=0 ){
-      memcpy(pColl, pColl2, sizeof(CollSeq));
-      return SQLITE_OK;
-    }
-  }
-  if( pParse->nErr==0 ){
-    sqlite3ErrorMsg(pParse, "no such collation sequence: %.*s", n, z);
-  }
-  pParse->nErr++;
-  return SQLITE_ERROR;
-}
-
-/*
-** This routine is called on a collation sequence before it is used to
-** check that it is defined. An undefined collation sequence exists when
-** a database is loaded that contains references to collation sequences
-** that have not been defined by sqlite3_create_collation() etc.
-**
-** If required, this routine calls the 'collation needed' callback to
-** request a definition of the collating sequence. If this doesn't work, 
-** an equivalent collating sequence that uses a text encoding different
-** from the main database is substituted, if one is available.
-*/
-int sqlite3CheckCollSeq(Parse *pParse, CollSeq *pColl){
-  if( pColl && !pColl->xCmp ){
-    /* No collation sequence of this type for this encoding is registered.
-    ** Call the collation factory to see if it can supply us with one.
-    */
-    callCollNeeded(pParse->db, pColl->zName, strlen(pColl->zName));
-    if( !pColl->xCmp && synthCollSeq(pParse, pColl) ){
-      return SQLITE_ERROR;
-    }
-  }
-  return SQLITE_OK;
-}
-
 /*
 ** Call sqlite3CheckCollSeq() for all collating sequences in an index,
 ** in order to verify that all the necessary collating sequences are
@@ -1241,33 +1117,22 @@ int sqlite3CheckIndexCollSeq(Parse *pParse, Index *pIdx){
 ** pParse.
 */
 CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName){
-  u8 enc = pParse->db->enc;
-  u8 initbusy = pParse->db->init.busy;
-  CollSeq *pColl = sqlite3FindCollSeq(pParse->db, enc, zName, nName, initbusy);
-  if( nName<0 ) nName = strlen(zName);
-  if( !initbusy && (!pColl || !pColl->xCmp) ){
-    /* No collation sequence of this type for this encoding is registered.
-    ** Call the collation factory to see if it can supply us with one.
-    */
-    callCollNeeded(pParse->db, zName, nName);
-    pColl = sqlite3FindCollSeq(pParse->db, enc, zName, nName, 0);
-    if( pColl && !pColl->xCmp ){
-      /* There may be a version of the collation sequence that requires
-      ** translation between encodings. Search for it with synthCollSeq().
-      */
-      if( synthCollSeq(pParse, pColl) ){
-        return 0;
-      }
-    }
-  }
+  sqlite3 *db = pParse->db;
+  u8 enc = db->enc;
+  u8 initbusy = db->init.busy;
 
-  /* If nothing has been found, write the error message into pParse */
+  CollSeq *pColl = sqlite3FindCollSeq(db, enc, zName, nName, initbusy);
   if( !initbusy && (!pColl || !pColl->xCmp) ){
-    if( pParse->nErr==0 ){
+    pColl = sqlite3GetCollSeq(db, pColl, zName, nName);
+    if( !pColl ){
+      if( nName<0 ){
+        nName = strlen(zName);
+      }
       sqlite3ErrorMsg(pParse, "no such collation sequence: %.*s", nName, zName);
+      pColl = 0;
     }
-    pColl = 0;
   }
+
   return pColl;
 }
 
@@ -1363,7 +1228,7 @@ static char *createTableStmt(Table *p){
   n += 35 + 6*p->nCol;
   zStmt = sqliteMallocRaw( n );
   if( zStmt==0 ) return 0;
-  strcpy(zStmt, p->iDb==1 ? "CREATE TEMP TABLE " : "CREATE TABLE ");
+  strcpy(zStmt, !OMIT_TEMPDB&&p->iDb==1 ? "CREATE TEMP TABLE ":"CREATE TABLE ");
   k = strlen(zStmt);
   identPut(zStmt, &k, p->zName);
   zStmt[k++] = '(';
@@ -1394,7 +1259,7 @@ static char *createTableStmt(Table *p){
 ** this is a temporary table or db->init.busy==1.  When db->init.busy==1
 ** it means we are reading the sqlite_master table because we just
 ** connected to the database or because the sqlite_master table has
-** recently changes, so the entry for this table already exists in
+** recently changed, so the entry for this table already exists in
 ** the sqlite_master table.  We do not want to create it again.
 **
 ** If the pSelect argument is not NULL, it means that this routine
@@ -1402,7 +1267,12 @@ static char *createTableStmt(Table *p){
 ** "CREATE TABLE ... AS SELECT ..." statement.  The column names of
 ** the new table will match the result set of the SELECT.
 */
-void sqlite3EndTable(Parse *pParse, Token *pEnd, Select *pSelect){
+void sqlite3EndTable(
+  Parse *pParse,          /* Parse context */
+  Token *pCons,           /* The ',' token after the last column defn. */
+  Token *pEnd,            /* The final ')' token in the CREATE TABLE */
+  Select *pSelect         /* Select from a "CREATE ... AS SELECT" */
+){
   Table *p;
   sqlite3 *db = pParse->db;
 
@@ -1491,7 +1361,7 @@ void sqlite3EndTable(Parse *pParse, Token *pEnd, Select *pSelect){
     if( pSelect ){
       zStmt = createTableStmt(p);
     }else{
-      n = Addr(pEnd->z) - Addr(pParse->sNameToken.z) + 1;
+      n = pEnd->z - pParse->sNameToken.z + 1;
       zStmt = sqlite3MPrintf("CREATE %s %.*s", zType2, n, pParse->sNameToken.z);
     }
 
@@ -1556,6 +1426,14 @@ void sqlite3EndTable(Parse *pParse, Token *pEnd, Select *pSelect){
     pParse->pNewTable = 0;
     db->nTable++;
     db->flags |= SQLITE_InternChanges;
+
+#ifndef SQLITE_OMIT_ALTERTABLE
+    if( !p->pSelect ){
+      assert( !pSelect && pCons && pEnd );
+      if( pCons->z==0 ) pCons = pEnd;
+      p->addColOffset = 13 + (pCons->z - pParse->sNameToken.z);
+    }
+#endif
   }
 }
 
@@ -1578,6 +1456,11 @@ void sqlite3CreateView(
   DbFixer sFix;
   Token *pName;
 
+  if( pParse->nVar>0 ){
+    sqlite3ErrorMsg(pParse, "parameters are not allowed in views");
+    sqlite3SelectDelete(pSelect);
+    return;
+  }
   sqlite3StartTable(pParse, pBegin, pName1, pName2, isTemp, 1);
   p = pParse->pNewTable;
   if( p==0 || pParse->nErr ){
@@ -1618,7 +1501,7 @@ void sqlite3CreateView(
   sEnd.n = 1;
 
   /* Use sqlite3EndTable() to add the view to the SQLITE_MASTER table */
-  sqlite3EndTable(pParse, &sEnd, 0);
+  sqlite3EndTable(pParse, 0, &sEnd, 0);
   return;
 }
 #endif /* SQLITE_OMIT_VIEW */
@@ -1839,13 +1722,13 @@ void sqlite3DropTable(Parse *pParse, SrcList *pName, int isView){
       goto exit_drop_table;
     }
     if( isView ){
-      if( iDb==1 ){
+      if( !OMIT_TEMPDB && iDb==1 ){
         code = SQLITE_DROP_TEMP_VIEW;
       }else{
         code = SQLITE_DROP_VIEW;
       }
     }else{
-      if( iDb==1 ){
+      if( !OMIT_TEMPDB && iDb==1 ){
         code = SQLITE_DROP_TEMP_TABLE;
       }else{
         code = SQLITE_DROP_TABLE;
@@ -2125,7 +2008,7 @@ static void sqlite3RefillIndex(Parse *pParse, Index *pIndex, int memRootPage){
   addr1 = sqlite3VdbeAddOp(v, OP_Rewind, iTab, 0);
   sqlite3GenerateIndexKey(v, pIndex, iTab);
   isUnique = pIndex->onError!=OE_None;
-  sqlite3VdbeAddOp(v, OP_IdxPut, iIdx, isUnique);
+  sqlite3VdbeAddOp(v, OP_IdxInsert, iIdx, isUnique);
   if( isUnique ){
     sqlite3VdbeChangeP3(v, -1, "indexed columns are not unique", P3_STATIC);
   }
@@ -2163,7 +2046,6 @@ void sqlite3CreateIndex(
   int i, j;
   Token nullId;    /* Fake token for an empty ID list */
   DbFixer sFix;    /* For assigning database names to pTable */
-  int isTemp;      /* True for a temporary index */
   sqlite3 *db = pParse->db;
 
   int iDb;          /* Index of the database that is being written */
@@ -2184,6 +2066,7 @@ void sqlite3CreateIndex(
     iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pName);
     if( iDb<0 ) goto exit_create_index;
 
+#ifndef SQLITE_OMIT_TEMPDB
     /* If the index name was unqualified, check if the the table
     ** is a temp table. If so, set the database to 1.
     */
@@ -2191,6 +2074,7 @@ void sqlite3CreateIndex(
     if( pName2 && pName2->n==0 && pTab && pTab->iDb==1 ){
       iDb = 1;
     }
+#endif
 
     if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) &&
         sqlite3FixSrcList(&sFix, pTblName)
@@ -2218,7 +2102,6 @@ void sqlite3CreateIndex(
     goto exit_create_index;
   }
 #endif
-  isTemp = pTab->iDb==1;
 
   /*
   ** Find the name of the index.  Make sure there is not already another
@@ -2268,12 +2151,12 @@ void sqlite3CreateIndex(
   */
 #ifndef SQLITE_OMIT_AUTHORIZATION
   {
-    const char *zDb = db->aDb[pTab->iDb].zName;
-    if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(isTemp), 0, zDb) ){
+    const char *zDb = db->aDb[iDb].zName;
+    if( sqlite3AuthCheck(pParse, SQLITE_INSERT, SCHEMA_TABLE(iDb), 0, zDb) ){
       goto exit_create_index;
     }
     i = SQLITE_CREATE_INDEX;
-    if( isTemp ) i = SQLITE_CREATE_TEMP_INDEX;
+    if( !OMIT_TEMPDB && iDb==1 ) i = SQLITE_CREATE_TEMP_INDEX;
     if( sqlite3AuthCheck(pParse, i, zName, pTab->zName, zDb) ){
       goto exit_create_index;
     }
@@ -2296,7 +2179,7 @@ void sqlite3CreateIndex(
   */
   pIndex = sqliteMalloc( sizeof(Index) + strlen(zName) + 1 +
                         (sizeof(int) + sizeof(CollSeq*))*pList->nExpr );
-  if( pIndex==0 ) goto exit_create_index;
+  if( sqlite3_malloc_failed ) goto exit_create_index;
   pIndex->aiColumn = (int*)&pIndex->keyInfo.aColl[pList->nExpr];
   pIndex->zName = (char*)&pIndex->aiColumn[pList->nExpr];
   strcpy(pIndex->zName, zName);
@@ -2436,7 +2319,7 @@ void sqlite3CreateIndex(
       /* A named index with an explicit CREATE INDEX statement */
       zStmt = sqlite3MPrintf("CREATE%s INDEX %.*s",
         onError==OE_None ? "" : " UNIQUE",
-        Addr(pEnd->z) - Addr(pName->z) + 1,
+        pEnd->z - pName->z + 1,
         pName->z);
     }else{
       /* An automatic index created by a PRIMARY KEY or UNIQUE constraint */
@@ -2509,9 +2392,13 @@ void sqlite3DropIndex(Parse *pParse, SrcList *pName){
   Vdbe *v;
   sqlite3 *db = pParse->db;
 
-  if( pParse->nErr || sqlite3_malloc_failed ) return;
+  if( pParse->nErr || sqlite3_malloc_failed ){
+    goto exit_drop_index;
+  }
   assert( pName->nSrc==1 );
-  if( SQLITE_OK!=sqlite3ReadSchema(pParse) ) return;
+  if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
+    goto exit_drop_index;
+  }
   pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
   if( pIndex==0 ){
     sqlite3ErrorMsg(pParse, "no such index: %S", pName, 0);
@@ -2532,7 +2419,7 @@ void sqlite3DropIndex(Parse *pParse, SrcList *pName){
     if( sqlite3AuthCheck(pParse, SQLITE_DELETE, zTab, 0, zDb) ){
       goto exit_drop_index;
     }
-    if( pIndex->iDb ) code = SQLITE_DROP_TEMP_INDEX;
+    if( !OMIT_TEMPDB && pIndex->iDb ) code = SQLITE_DROP_TEMP_INDEX;
     if( sqlite3AuthCheck(pParse, code, pIndex->zName, pTab->zName, zDb) ){
       goto exit_drop_index;
     }
@@ -2706,9 +2593,7 @@ void sqlite3SrcListDelete(SrcList *pList){
     sqliteFree(pItem->zDatabase);
     sqliteFree(pItem->zName);
     sqliteFree(pItem->zAlias);
-    if( pItem->pTab && pItem->pTab->isTransient ){
-      sqlite3DeleteTable(0, pItem->pTab);
-    }
+    sqlite3DeleteTable(0, pItem->pTab);
     sqlite3SelectDelete(pItem->pSelect);
     sqlite3ExprDelete(pItem->pOn);
     sqlite3IdListDelete(pItem->pUsing);
@@ -2840,7 +2725,7 @@ void sqlite3CodeVerifySchema(Parse *pParse, int iDb){
     if( (pParse->cookieMask & mask)==0 ){
       pParse->cookieMask |= mask;
       pParse->cookieValue[iDb] = db->aDb[iDb].schema_cookie;
-      if( iDb==1 ){
+      if( !OMIT_TEMPDB && iDb==1 ){
         sqlite3OpenTempDatabase(pParse);
       }
     }
@@ -2873,24 +2758,11 @@ void sqlite3BeginWriteOperation(Parse *pParse, int setStatement, int iDb){
   if( setStatement && pParse->nested==0 ){
     sqlite3VdbeAddOp(v, OP_Statement, iDb, 0);
   }
-  if( iDb!=1 && pParse->db->aDb[1].pBt!=0 ){
+  if( (OMIT_TEMPDB || iDb!=1) && pParse->db->aDb[1].pBt!=0 ){
     sqlite3BeginWriteOperation(pParse, setStatement, 1);
   }
 }
 
-#ifndef SQLITE_OMIT_UTF16
-/* 
-** Return the transient sqlite3_value object used for encoding conversions
-** during SQL compilation.
-*/
-sqlite3_value *sqlite3GetTransientValue(sqlite3 *db){
-  if( !db->pValue ){
-    db->pValue = sqlite3ValueNew();
-  }
-  return db->pValue;
-}
-#endif
-
 /*
 ** Check to see if pIndex uses the collating sequence pColl.  Return
 ** true if it does and false if it does not.
diff --git a/ext/pdo_sqlite/sqlite/src/callback.c b/ext/pdo_sqlite/sqlite/src/callback.c
new file mode 100644 (file)
index 0000000..9fa6217
--- /dev/null
@@ -0,0 +1,306 @@
+/*
+** 2005 May 23 
+**
+** The author disclaims copyright to this source code.  In place of
+** a legal notice, here is a blessing:
+**
+**    May you do good and not evil.
+**    May you find forgiveness for yourself and forgive others.
+**    May you share freely, never taking more than you give.
+**
+*************************************************************************
+**
+** This file contains functions used to access the internal hash tables
+** of user defined functions and collation sequences.
+**
+** $Id$
+*/
+
+#include "sqliteInt.h"
+
+/*
+** Invoke the 'collation needed' callback to request a collation sequence
+** in the database text encoding of name zName, length nName.
+** If the collation sequence
+*/
+static void callCollNeeded(sqlite3 *db, const char *zName, int nName){
+  assert( !db->xCollNeeded || !db->xCollNeeded16 );
+  if( nName<0 ) nName = strlen(zName);
+  if( db->xCollNeeded ){
+    char *zExternal = sqliteStrNDup(zName, nName);
+    if( !zExternal ) return;
+    db->xCollNeeded(db->pCollNeededArg, db, (int)db->enc, zExternal);
+    sqliteFree(zExternal);
+  }
+#ifndef SQLITE_OMIT_UTF16
+  if( db->xCollNeeded16 ){
+    char const *zExternal;
+    sqlite3_value *pTmp = sqlite3GetTransientValue(db);
+    sqlite3ValueSetStr(pTmp, -1, zName, SQLITE_UTF8, SQLITE_STATIC);
+    zExternal = sqlite3ValueText(pTmp, SQLITE_UTF16NATIVE);
+    if( !zExternal ) return;
+    db->xCollNeeded16(db->pCollNeededArg, db, (int)db->enc, zExternal);
+  }
+#endif
+}
+
+/*
+** This routine is called if the collation factory fails to deliver a
+** collation function in the best encoding but there may be other versions
+** of this collation function (for other text encodings) available. Use one
+** of these instead if they exist. Avoid a UTF-8 <-> UTF-16 conversion if
+** possible.
+*/
+static int synthCollSeq(sqlite3 *db, CollSeq *pColl){
+  CollSeq *pColl2;
+  char *z = pColl->zName;
+  int n = strlen(z);
+  int i;
+  static const u8 aEnc[] = { SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF8 };
+  for(i=0; i<3; i++){
+    pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, n, 0);
+    if( pColl2->xCmp!=0 ){
+      memcpy(pColl, pColl2, sizeof(CollSeq));
+      return SQLITE_OK;
+    }
+  }
+  return SQLITE_ERROR;
+}
+
+/*
+** This function is responsible for invoking the collation factory callback
+** or substituting a collation sequence of a different encoding when the
+** requested collation sequence is not available in the database native
+** encoding.
+** 
+** If it is not NULL, then pColl must point to the database native encoding 
+** collation sequence with name zName, length nName.
+**
+** The return value is either the collation sequence to be used in database
+** db for collation type name zName, length nName, or NULL, if no collation
+** sequence can be found.
+*/
+CollSeq *sqlite3GetCollSeq(
+  sqlite3* db, 
+  CollSeq *pColl, 
+  const char *zName, 
+  int nName
+){
+  CollSeq *p;
+
+  p = pColl;
+  if( !p ){
+    p = sqlite3FindCollSeq(db, db->enc, zName, nName, 0);
+  }
+  if( !p || !p->xCmp ){
+    /* No collation sequence of this type for this encoding is registered.
+    ** Call the collation factory to see if it can supply us with one.
+    */
+    callCollNeeded(db, zName, nName);
+    p = sqlite3FindCollSeq(db, db->enc, zName, nName, 0);
+  }
+  if( p && !p->xCmp && synthCollSeq(db, p) ){
+    p = 0;
+  }
+  assert( !p || p->xCmp );
+  return p;
+}
+
+/*
+** This routine is called on a collation sequence before it is used to
+** check that it is defined. An undefined collation sequence exists when
+** a database is loaded that contains references to collation sequences
+** that have not been defined by sqlite3_create_collation() etc.
+**
+** If required, this routine calls the 'collation needed' callback to
+** request a definition of the collating sequence. If this doesn't work, 
+** an equivalent collating sequence that uses a text encoding different
+** from the main database is substituted, if one is available.
+*/
+int sqlite3CheckCollSeq(Parse *pParse, CollSeq *pColl){
+  if( pColl ){
+    const char *zName = pColl->zName;
+    CollSeq *p = sqlite3GetCollSeq(pParse->db, pColl, zName, -1);
+    if( !p ){
+      if( pParse->nErr==0 ){
+        sqlite3ErrorMsg(pParse, "no such collation sequence: %s", zName);
+      }
+      pParse->nErr++;
+      return SQLITE_ERROR;
+    }
+  }
+  return SQLITE_OK;
+}
+
+
+
+/*
+** Locate and return an entry from the db.aCollSeq hash table. If the entry
+** specified by zName and nName is not found and parameter 'create' is
+** true, then create a new entry. Otherwise return NULL.
+**
+** Each pointer stored in the sqlite3.aCollSeq hash table contains an
+** array of three CollSeq structures. The first is the collation sequence
+** prefferred for UTF-8, the second UTF-16le, and the third UTF-16be.
+**
+** Stored immediately after the three collation sequences is a copy of
+** the collation sequence name. A pointer to this string is stored in
+** each collation sequence structure.
+*/
+static CollSeq * findCollSeqEntry(
+  sqlite3 *db,
+  const char *zName,
+  int nName,
+  int create
+){
+  CollSeq *pColl;
+  if( nName<0 ) nName = strlen(zName);
+  pColl = sqlite3HashFind(&db->aCollSeq, zName, nName);
+
+  if( 0==pColl && create ){
+    pColl = sqliteMalloc( 3*sizeof(*pColl) + nName + 1 );
+    if( pColl ){
+      CollSeq *pDel = 0;
+      pColl[0].zName = (char*)&pColl[3];
+      pColl[0].enc = SQLITE_UTF8;
+      pColl[1].zName = (char*)&pColl[3];
+      pColl[1].enc = SQLITE_UTF16LE;
+      pColl[2].zName = (char*)&pColl[3];
+      pColl[2].enc = SQLITE_UTF16BE;
+      memcpy(pColl[0].zName, zName, nName);
+      pColl[0].zName[nName] = 0;
+      pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, nName, pColl);
+
+      /* If a malloc() failure occured in sqlite3HashInsert(), it will 
+      ** return the pColl pointer to be deleted (because it wasn't added
+      ** to the hash table).
+      */
+      assert( !pDel || (sqlite3_malloc_failed && pDel==pColl) );
+      sqliteFree(pDel);
+    }
+  }
+  return pColl;
+}
+
+/*
+** Parameter zName points to a UTF-8 encoded string nName bytes long.
+** Return the CollSeq* pointer for the collation sequence named zName
+** for the encoding 'enc' from the database 'db'.
+**
+** If the entry specified is not found and 'create' is true, then create a
+** new entry.  Otherwise return NULL.
+*/
+CollSeq *sqlite3FindCollSeq(
+  sqlite3 *db,
+  u8 enc,
+  const char *zName,
+  int nName,
+  int create
+){
+  CollSeq *pColl = findCollSeqEntry(db, zName, nName, create);
+  assert( SQLITE_UTF8==1 && SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
+  assert( enc>=SQLITE_UTF8 && enc<=SQLITE_UTF16BE );
+  if( pColl ) pColl += enc-1;
+  return pColl;
+}
+
+/*
+** Locate a user function given a name, a number of arguments and a flag
+** indicating whether the function prefers UTF-16 over UTF-8.  Return a
+** pointer to the FuncDef structure that defines that function, or return
+** NULL if the function does not exist.
+**
+** If the createFlag argument is true, then a new (blank) FuncDef
+** structure is created and liked into the "db" structure if a
+** no matching function previously existed.  When createFlag is true
+** and the nArg parameter is -1, then only a function that accepts
+** any number of arguments will be returned.
+**
+** If createFlag is false and nArg is -1, then the first valid
+** function found is returned.  A function is valid if either xFunc
+** or xStep is non-zero.
+**
+** If createFlag is false, then a function with the required name and
+** number of arguments may be returned even if the eTextRep flag does not
+** match that requested.
+*/
+FuncDef *sqlite3FindFunction(
+  sqlite3 *db,       /* An open database */
+  const char *zName, /* Name of the function.  Not null-terminated */
+  int nName,         /* Number of characters in the name */
+  int nArg,          /* Number of arguments.  -1 means any number */
+  u8 enc,            /* Preferred text encoding */
+  int createFlag     /* Create new entry if true and does not otherwise exist */
+){
+  FuncDef *p;         /* Iterator variable */
+  FuncDef *pFirst;    /* First function with this name */
+  FuncDef *pBest = 0; /* Best match found so far */
+  int bestmatch = 0;  
+
+
+  assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
+  if( nArg<-1 ) nArg = -1;
+
+  pFirst = (FuncDef*)sqlite3HashFind(&db->aFunc, zName, nName);
+  for(p=pFirst; p; p=p->pNext){
+    /* During the search for the best function definition, bestmatch is set
+    ** as follows to indicate the quality of the match with the definition
+    ** pointed to by pBest:
+    **
+    ** 0: pBest is NULL. No match has been found.
+    ** 1: A variable arguments function that prefers UTF-8 when a UTF-16
+    **    encoding is requested, or vice versa.
+    ** 2: A variable arguments function that uses UTF-16BE when UTF-16LE is
+    **    requested, or vice versa.
+    ** 3: A variable arguments function using the same text encoding.
+    ** 4: A function with the exact number of arguments requested that
+    **    prefers UTF-8 when a UTF-16 encoding is requested, or vice versa.
+    ** 5: A function with the exact number of arguments requested that
+    **    prefers UTF-16LE when UTF-16BE is requested, or vice versa.
+    ** 6: An exact match.
+    **
+    ** A larger value of 'matchqual' indicates a more desirable match.
+    */
+    if( p->nArg==-1 || p->nArg==nArg || nArg==-1 ){
+      int match = 1;          /* Quality of this match */
+      if( p->nArg==nArg || nArg==-1 ){
+        match = 4;
+      }
+      if( enc==p->iPrefEnc ){
+        match += 2;
+      }
+      else if( (enc==SQLITE_UTF16LE && p->iPrefEnc==SQLITE_UTF16BE) ||
+               (enc==SQLITE_UTF16BE && p->iPrefEnc==SQLITE_UTF16LE) ){
+        match += 1;
+      }
+
+      if( match>bestmatch ){
+        pBest = p;
+        bestmatch = match;
+      }
+    }
+  }
+
+  /* If the createFlag parameter is true, and the seach did not reveal an
+  ** exact match for the name, number of arguments and encoding, then add a
+  ** new entry to the hash table and return it.
+  */
+  if( createFlag && bestmatch<6 && 
+      (pBest = sqliteMalloc(sizeof(*pBest)+nName+1)) ){
+    pBest->nArg = nArg;
+    pBest->pNext = pFirst;
+    pBest->zName = (char*)&pBest[1];
+    pBest->iPrefEnc = enc;
+    memcpy(pBest->zName, zName, nName);
+    pBest->zName[nName] = 0;
+    if( pBest==sqlite3HashInsert(&db->aFunc,pBest->zName,nName,(void*)pBest) ){
+      sqliteFree(pBest);
+      return 0;
+    }
+  }
+
+  if( pBest && (pBest->xStep || pBest->xFunc || createFlag) ){
+    return pBest;
+  }
+  return 0;
+}
index 8780a51b6dd8f36a7dc40c9aa93f28582306ab06..c6872831b9e4216c303113190f0b8251b5c94fc7 100644 (file)
@@ -272,7 +272,7 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){
     return 1;
   }
   zDate += 10;
-  while( isspace(*(u8*)zDate) ){ zDate++; }
+  while( isspace(*(u8*)zDate) || 'T'==*(u8*)zDate ){ zDate++; }
   if( parseHhMmSs(zDate, p)==0 ){
     /* We got the time */
   }else if( *zDate==0 ){
index fa661977d7caefa3cb7824a83ec6c32e7c4f05c8..15eb8f4e8d373e7f13d2b5b047e7226a3db30162 100644 (file)
@@ -27,7 +27,11 @@ Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
   struct SrcList_item *pItem;
   for(i=0, pItem=pSrc->a; i<pSrc->nSrc; i++, pItem++){
     pTab = sqlite3LocateTable(pParse, pItem->zName, pItem->zDatabase);
+    sqlite3DeleteTable(pParse->db, pItem->pTab);
     pItem->pTab = pTab;
+    if( pTab ){
+      pTab->nRef++;
+    }
   }
   return pTab;
 }
@@ -99,7 +103,6 @@ void sqlite3DeleteFrom(
 
   sContext.pParse = 0;
   if( pParse->nErr || sqlite3_malloc_failed ){
-    pTabList = 0;
     goto delete_from_cleanup;
   }
   db = pParse->db;
@@ -231,12 +234,12 @@ void sqlite3DeleteFrom(
 
     /* Begin the database scan
     */
-    pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0);
+    pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0);
     if( pWInfo==0 ) goto delete_from_cleanup;
 
     /* Remember the rowid of every item to be deleted.
     */
-    sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
+    sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
     sqlite3VdbeAddOp(v, OP_ListWrite, 0, 0);
     if( db->flags & SQLITE_CountRows ){
       sqlite3VdbeAddOp(v, OP_AddImm, 1, 0);
@@ -265,21 +268,21 @@ void sqlite3DeleteFrom(
     */
     if( triggers_exist ){
       addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, end);
-      sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
       if( !isView ){
+        sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
         sqlite3OpenTableForReading(v, iCur, pTab);
       }
       sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
-      sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
+      sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
       sqlite3VdbeAddOp(v, OP_RowData, iCur, 0);
-      sqlite3VdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
+      sqlite3VdbeAddOp(v, OP_Insert, oldIdx, 0);
       if( !isView ){
         sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
       }
 
       (void)sqlite3CodeRowTrigger(pParse, TK_DELETE, 0, TRIGGER_BEFORE, pTab,
           -1, oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default,
-         addr);
+          addr);
     }
 
     if( !isView ){
@@ -313,7 +316,7 @@ void sqlite3DeleteFrom(
       }
       (void)sqlite3CodeRowTrigger(pParse, TK_DELETE, 0, TRIGGER_AFTER, pTab, -1,
           oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default,
-         addr);
+          addr);
     }
 
     /* End of the delete loop */
@@ -429,13 +432,14 @@ void sqlite3GenerateIndexKey(
   int j;
   Table *pTab = pIdx->pTable;
 
-  sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
+  sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
   for(j=0; j<pIdx->nColumn; j++){
     int idx = pIdx->aiColumn[j];
     if( idx==pTab->iPKey ){
       sqlite3VdbeAddOp(v, OP_Dup, j, 0);
     }else{
       sqlite3VdbeAddOp(v, OP_Column, iCur, idx);
+      sqlite3ColumnDefault(v, pTab, idx);
     }
   }
   sqlite3VdbeAddOp(v, OP_MakeRecord, pIdx->nColumn, (1<<24));
index 073f21835c28ebd5e4cad26d500a3f32bd0e00d3..0bb0ae334eb2c45793ea150bf262e0fe3bcf0838 100644 (file)
@@ -1,6 +1,5 @@
-
 /*
-** 2001 September 15
+** 2005 January 20
 **
 ** The author disclaims copyright to this source code.  In place of
 ** a legal notice, here is a blessing:
@@ -10,8 +9,8 @@
 **    May you share freely, never taking more than you give.
 **
 *************************************************************************
-** This file contains C code routines that are called by the parser
-** to handle SELECT statements in SQLite.
+** This file contains C code routines that are not a part of the official
+** SQLite API.  These routines are unsupported.
 **
 ** $Id$
 */
@@ -35,4 +34,3 @@ int sqlite3_clear_bindings(sqlite3_stmt *pStmt){
 int sqlite3_sleep(int ms){
   return sqlite3OsSleep(ms);
 }
-
index c4943b1f838c0a8b24acaffa077fd46a77383b98..70bdd8692fa87c4dad5b9f2bc31bb68caa9f700f 100644 (file)
@@ -138,7 +138,7 @@ int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity){
 */
 static int binaryCompareP1(Expr *pExpr1, Expr *pExpr2, int jumpIfNull){
   char aff = sqlite3ExprAffinity(pExpr2);
-  return (((int)sqlite3CompareAffinity(pExpr1, aff))<<8)+(jumpIfNull?1:0);
+  return ((int)sqlite3CompareAffinity(pExpr1, aff))+(jumpIfNull?0x100:0);
 }
 
 /*
@@ -183,7 +183,12 @@ Expr *sqlite3Expr(int op, Expr *pLeft, Expr *pRight, const Token *pToken){
   Expr *pNew;
   pNew = sqliteMalloc( sizeof(Expr) );
   if( pNew==0 ){
-    /* When malloc fails, we leak memory from pLeft and pRight */
+    /* When malloc fails, delete pLeft and pRight. Expressions passed to 
+    ** this function must always be allocated with sqlite3Expr() for this 
+    ** reason. 
+    */
+    sqlite3ExprDelete(pLeft);
+    sqlite3ExprDelete(pRight);
     return 0;
   }
   pNew->op = op;
@@ -260,7 +265,7 @@ void sqlite3ExprSpan(Expr *pExpr, Token *pLeft, Token *pRight){
     assert( pLeft->dyn==0 || pLeft->z[pLeft->n]==0 );
     if( pLeft->dyn==0 && pRight->dyn==0 ){
       pExpr->span.z = pLeft->z;
-      pExpr->span.n = pRight->n + Addr(pRight->z) - Addr(pLeft->z);
+      pExpr->span.n = pRight->n + (pRight->z - pLeft->z);
     }else{
       pExpr->span.z = 0;
     }
@@ -275,7 +280,7 @@ Expr *sqlite3ExprFunction(ExprList *pList, Token *pToken){
   Expr *pNew;
   pNew = sqliteMalloc( sizeof(Expr) );
   if( pNew==0 ){
-    /* sqlite3ExprListDelete(pList); // Leak pList when malloc fails */
+    sqlite3ExprListDelete(pList); /* Avoid leaking memory when malloc fails */
     return 0;
   }
   pNew->op = TK_FUNCTION;
@@ -403,6 +408,7 @@ Expr *sqlite3ExprDup(Expr *p){
   pNew->pRight = sqlite3ExprDup(p->pRight);
   pNew->pList = sqlite3ExprListDup(p->pList);
   pNew->pSelect = sqlite3SelectDup(p->pSelect);
+  pNew->pTab = p->pTab;
   return pNew;
 }
 void sqlite3TokenCopy(Token *pTo, Token *pFrom){
@@ -468,14 +474,15 @@ SrcList *sqlite3SrcListDup(SrcList *p){
   for(i=0; i<p->nSrc; i++){
     struct SrcList_item *pNewItem = &pNew->a[i];
     struct SrcList_item *pOldItem = &p->a[i];
+    Table *pTab;
     pNewItem->zDatabase = sqliteStrDup(pOldItem->zDatabase);
     pNewItem->zName = sqliteStrDup(pOldItem->zName);
     pNewItem->zAlias = sqliteStrDup(pOldItem->zAlias);
     pNewItem->jointype = pOldItem->jointype;
     pNewItem->iCursor = pOldItem->iCursor;
-    pNewItem->pTab = pOldItem->pTab;
-    if( pNewItem->pTab ){
-      pNewItem->pTab->isTransient = 0;
+    pTab = pNewItem->pTab = pOldItem->pTab;
+    if( pTab ){
+      pTab->nRef++;
     }
     pNewItem->pSelect = sqlite3SelectDup(pOldItem->pSelect);
     pNewItem->pOn = sqlite3ExprDup(pOldItem->pOn);
@@ -492,7 +499,10 @@ IdList *sqlite3IdListDup(IdList *p){
   if( pNew==0 ) return 0;
   pNew->nId = pNew->nAlloc = p->nId;
   pNew->a = sqliteMallocRaw( p->nId*sizeof(p->a[0]) );
-  if( pNew->a==0 ) return 0;
+  if( pNew->a==0 ){
+    sqliteFree(pNew);
+    return 0;
+  }
   for(i=0; i<p->nId; i++){
     struct IdList_item *pNewItem = &pNew->a[i];
     struct IdList_item *pOldItem = &p->a[i];
@@ -520,7 +530,6 @@ Select *sqlite3SelectDup(Select *p){
   pNew->iLimit = -1;
   pNew->iOffset = -1;
   pNew->ppOpenTemp = 0;
-  pNew->pFetch = 0;
   pNew->isResolved = p->isResolved;
   pNew->isAgg = p->isAgg;
   return pNew;
@@ -541,28 +550,34 @@ ExprList *sqlite3ExprListAppend(ExprList *pList, Expr *pExpr, Token *pName){
   if( pList==0 ){
     pList = sqliteMalloc( sizeof(ExprList) );
     if( pList==0 ){
-      /* sqlite3ExprDelete(pExpr); // Leak memory if malloc fails */
-      return 0;
+      goto no_mem;
     }
     assert( pList->nAlloc==0 );
   }
   if( pList->nAlloc<=pList->nExpr ){
-    pList->nAlloc = pList->nAlloc*2 + 4;
-    pList->a = sqliteRealloc(pList->a, pList->nAlloc*sizeof(pList->a[0]));
-    if( pList->a==0 ){
-      /* sqlite3ExprDelete(pExpr); // Leak memory if malloc fails */
-      pList->nExpr = pList->nAlloc = 0;
-      return pList;
-    }
+    struct ExprList_item *a;
+    int n = pList->nAlloc*2 + 4;
+    a = sqliteRealloc(pList->a, n*sizeof(pList->a[0]));
+    if( a==0 ){
+      goto no_mem;
+    }
+    pList->a = a;
+    pList->nAlloc = n;
   }
   assert( pList->a!=0 );
   if( pExpr || pName ){
     struct ExprList_item *pItem = &pList->a[pList->nExpr++];
     memset(pItem, 0, sizeof(*pItem));
-    pItem->pExpr = pExpr;
     pItem->zName = sqlite3NameFromToken(pName);
+    pItem->pExpr = pExpr;
   }
   return pList;
+
+no_mem:     
+  /* Avoid leaking memory if malloc has failed. */
+  sqlite3ExprDelete(pExpr);
+  sqlite3ExprListDelete(pList);
+  return 0;
 }
 
 /*
@@ -768,7 +783,7 @@ static int lookupName(
   zTab = sqlite3NameFromToken(pTableToken);
   zCol = sqlite3NameFromToken(pColumnToken);
   if( sqlite3_malloc_failed ){
-    return 1;  /* Leak memory (zDb and zTab) if malloc fails */
+    goto lookupname_end;
   }
 
   pExpr->iTable = -1;
@@ -776,7 +791,6 @@ static int lookupName(
     SrcList *pSrcList = pNC->pSrcList;
     ExprList *pEList = pNC->pEList;
 
-    pNC->nRef++;
     /* assert( zTab==0 || pEList==0 ); */
     if( pSrcList ){
       for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
@@ -804,6 +818,7 @@ static int lookupName(
         }
         for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
           if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
+            IdList *pUsing;
             cnt++;
             pExpr->iTable = pItem->iCursor;
             pMatch = pItem;
@@ -812,6 +827,25 @@ static int lookupName(
             pExpr->iColumn = j==pTab->iPKey ? -1 : j;
             pExpr->affinity = pTab->aCol[j].affinity;
             pExpr->pColl = pTab->aCol[j].pColl;
+            if( pItem->jointype & JT_NATURAL ){
+              /* If this match occurred in the left table of a natural join,
+              ** then skip the right table to avoid a duplicate match */
+              pItem++;
+              i++;
+            }
+            if( (pUsing = pItem->pUsing)!=0 ){
+              /* If this match occurs on a column that is in the USING clause
+              ** of a join, skip the search of the right table of the join
+              ** to avoid a duplicate match there. */
+              int k;
+              for(k=0; k<pUsing->nId; k++){
+                if( sqlite3StrICmp(pUsing->a[k].zName, zCol)==0 ){
+                  pItem++;
+                  i++;
+                  break;
+                }
+              }
+            }
             break;
           }
         }
@@ -847,6 +881,7 @@ static int lookupName(
             pExpr->iColumn = j==pTab->iPKey ? -1 : j;
             pExpr->affinity = pTab->aCol[j].affinity;
             pExpr->pColl = pTab->aCol[j].pColl;
+            pExpr->pTab = pTab;
             break;
           }
         }
@@ -883,9 +918,9 @@ static int lookupName(
           pExpr->op = TK_AS;
           pExpr->iColumn = j;
           pExpr->pLeft = sqlite3ExprDup(pEList->a[j].pExpr);
-          sqliteFree(zCol);
+          cnt = 1;
           assert( zTab==0 && zDb==0 );
-          return 0;
+          goto lookupname_end_2;
         }
       } 
     }
@@ -904,6 +939,9 @@ static int lookupName(
   ** Z is a string literal if it doesn't match any column names.  In that
   ** case, we need to return right away and not make any changes to
   ** pExpr.
+  **
+  ** Because no reference was made to outer contexts, the pNC->nRef
+  ** fields are not changed in any context.
   */
   if( cnt==0 && zTab==0 && pColumnToken->z[0]=='"' ){
     sqliteFree(zCol);
@@ -945,63 +983,35 @@ static int lookupName(
     pMatch->colUsed |= 1<<n;
   }
 
+lookupname_end:
   /* Clean up and return
   */
   sqliteFree(zDb);
   sqliteFree(zTab);
-  sqliteFree(zCol);
   sqlite3ExprDelete(pExpr->pLeft);
   pExpr->pLeft = 0;
   sqlite3ExprDelete(pExpr->pRight);
   pExpr->pRight = 0;
   pExpr->op = TK_COLUMN;
+lookupname_end_2:
+  sqliteFree(zCol);
   if( cnt==1 ){
     assert( pNC!=0 );
     sqlite3AuthRead(pParse, pExpr, pNC->pSrcList);
-  }
-  return cnt!=1;
-}
-
-/*
-** pExpr is a node that defines a function of some kind.  It might
-** be a syntactic function like "count(x)" or it might be a function
-** that implements an operator, like "a LIKE b".  
-**
-** This routine makes *pzName point to the name of the function and 
-** *pnName hold the number of characters in the function name.
-*/
-static void getFunctionName(Expr *pExpr, const char **pzName, int *pnName){
-  switch( pExpr->op ){
-    case TK_FUNCTION: {
-      *pzName = pExpr->token.z;
-      *pnName = pExpr->token.n;
-      break;
-    }
-    case TK_LIKE: {
-      *pzName = "like";
-      *pnName = 4;
-      break;
-    }
-    case TK_GLOB: {
-      *pzName = "glob";
-      *pnName = 4;
-      break;
+    if( pMatch && !pMatch->pSelect ){
+      pExpr->pTab = pMatch->pTab;
     }
-    case TK_CTIME: {
-      *pzName = "current_time";
-      *pnName = 12;
-      break;
-    }
-    case TK_CDATE: {
-      *pzName = "current_date";
-      *pnName = 12;
-      break;
-    }
-    case TK_CTIMESTAMP: {
-      *pzName = "current_timestamp";
-      *pnName = 17;
-      break;
+    /* Increment the nRef value on all name contexts from TopNC up to
+    ** the point where the name matched. */
+    for(;;){
+      assert( pTopNC!=0 );
+      pTopNC->nRef++;
+      if( pTopNC==pNC ) break;
+      pTopNC = pTopNC->pNext;
     }
+    return 0;
+  } else {
+    return 1;
   }
 }
 
@@ -1079,11 +1089,7 @@ static int nameResolverStep(void *pArg, Expr *pExpr){
 
     /* Resolve function names
     */
-    case TK_CTIME:
-    case TK_CTIMESTAMP:
-    case TK_CDATE:
-    case TK_GLOB:
-    case TK_LIKE:
+    case TK_CONST_FUNC:
     case TK_FUNCTION: {
       ExprList *pList = pExpr->pList;    /* The argument list */
       int n = pList ? pList->nExpr : 0;  /* Number of arguments */
@@ -1096,7 +1102,8 @@ static int nameResolverStep(void *pArg, Expr *pExpr){
       FuncDef *pDef;              /* Information about the function */
       int enc = pParse->db->enc;  /* The database encoding */
 
-      getFunctionName(pExpr, &zId, &nId);
+      zId = pExpr->token.z;
+      nId = pExpr->token.n;
       pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
       if( pDef==0 ){
         pDef = sqlite3FindFunction(pParse->db, zId, nId, -1, enc, 0);
@@ -1302,8 +1309,7 @@ void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
           /* Evaluate the expression and insert it into the temp table */
           sqlite3ExprCode(pParse, pE2);
           sqlite3VdbeOp3(v, OP_MakeRecord, 1, 0, &affinity, 1);
-          sqlite3VdbeAddOp(v, OP_String8, 0, 0);
-          sqlite3VdbeAddOp(v, OP_PutStrKey, pExpr->iTable, 0);
+          sqlite3VdbeAddOp(v, OP_IdxInsert, pExpr->iTable, 0);
         }
       }
       sqlite3VdbeChangeP3(v, addr, (void *)&keyInfo, P3_KEYINFO);
@@ -1375,7 +1381,7 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
   int op;
   if( v==0 ) return;
   if( pExpr==0 ){
-    sqlite3VdbeAddOp(v, OP_String8, 0, 0);  /* Empty expression evals to NULL */
+    sqlite3VdbeAddOp(v, OP_Null, 0, 0);
     return;
   }
   op = pExpr->op;
@@ -1385,13 +1391,9 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
         sqlite3VdbeAddOp(v, OP_AggGet, pExpr->iAggCtx, pExpr->iAgg);
       }else if( pExpr->iColumn>=0 ){
         sqlite3VdbeAddOp(v, OP_Column, pExpr->iTable, pExpr->iColumn);
-#ifndef NDEBUG
-        if( pExpr->span.z && pExpr->span.n>0 && pExpr->span.n<100 ){
-          VdbeComment((v, "# %T", &pExpr->span));
-        }
-#endif
+        sqlite3ColumnDefault(v, pExpr->pTab, pExpr->iColumn);
       }else{
-        sqlite3VdbeAddOp(v, OP_Recno, pExpr->iTable, 0);
+        sqlite3VdbeAddOp(v, OP_Rowid, pExpr->iTable, 0);
       }
       break;
     }
@@ -1407,6 +1409,10 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
       sqlite3VdbeDequoteP3(v, -1);
       break;
     }
+    case TK_NULL: {
+      sqlite3VdbeAddOp(v, OP_Null, 0, 0);
+      break;
+    }
 #ifndef SQLITE_OMIT_BLOB_LITERAL
     case TK_BLOB: {
       assert( TK_BLOB==OP_HexBlob );
@@ -1415,10 +1421,6 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
       break;
     }
 #endif
-    case TK_NULL: {
-      sqlite3VdbeAddOp(v, OP_String8, 0, 0);
-      break;
-    }
     case TK_VARIABLE: {
       sqlite3VdbeAddOp(v, OP_Variable, pExpr->iTable, 0);
       if( pExpr->token.n>1 ){
@@ -1516,11 +1518,7 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
       sqlite3VdbeAddOp(v, OP_AggGet, 0, pExpr->iAgg);
       break;
     }
-    case TK_CDATE:
-    case TK_CTIME:
-    case TK_CTIMESTAMP:
-    case TK_GLOB:
-    case TK_LIKE:
+    case TK_CONST_FUNC:
     case TK_FUNCTION: {
       ExprList *pList = pExpr->pList;
       int nExpr = pList ? pList->nExpr : 0;
@@ -1531,7 +1529,8 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
       int i;
       u8 enc = pParse->db->enc;
       CollSeq *pColl = 0;
-      getFunctionName(pExpr, &zId, &nId);
+      zId = pExpr->token.z;
+      nId = pExpr->token.n;
       pDef = sqlite3FindFunction(pParse->db, zId, nId, nExpr, enc, 0);
       assert( pDef!=0 );
       nExpr = sqlite3ExprCodeExprList(pParse, pList);
@@ -1578,7 +1577,7 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
       addr = sqlite3VdbeCurrentAddr(v);
       sqlite3VdbeAddOp(v, OP_NotNull, -1, addr+4);            /* addr + 0 */
       sqlite3VdbeAddOp(v, OP_Pop, 2, 0);
-      sqlite3VdbeAddOp(v, OP_String8, 0, 0);
+      sqlite3VdbeAddOp(v, OP_Null, 0, 0);
       sqlite3VdbeAddOp(v, OP_Goto, 0, addr+7);
       sqlite3VdbeOp3(v, OP_MakeRecord, 1, 0, &affinity, 1);   /* addr + 4 */
       sqlite3VdbeAddOp(v, OP_Found, pExpr->iTable, addr+7);
@@ -1648,7 +1647,7 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
       if( pExpr->pRight ){
         sqlite3ExprCode(pParse, pExpr->pRight);
       }else{
-        sqlite3VdbeAddOp(v, OP_String8, 0, 0);
+        sqlite3VdbeAddOp(v, OP_Null, 0, 0);
       }
       sqlite3VdbeResolveLabel(v, expr_end_label);
       break;
@@ -2070,104 +2069,3 @@ int sqlite3ExprAnalyzeAggregates(NameContext *pNC, Expr *pExpr){
   walkExprTree(pExpr, analyzeAggregate, pNC);
   return pNC->pParse->nErr - nErr;
 }
-
-/*
-** Locate a user function given a name, a number of arguments and a flag
-** indicating whether the function prefers UTF-16 over UTF-8.  Return a
-** pointer to the FuncDef structure that defines that function, or return
-** NULL if the function does not exist.
-**
-** If the createFlag argument is true, then a new (blank) FuncDef
-** structure is created and liked into the "db" structure if a
-** no matching function previously existed.  When createFlag is true
-** and the nArg parameter is -1, then only a function that accepts
-** any number of arguments will be returned.
-**
-** If createFlag is false and nArg is -1, then the first valid
-** function found is returned.  A function is valid if either xFunc
-** or xStep is non-zero.
-**
-** If createFlag is false, then a function with the required name and
-** number of arguments may be returned even if the eTextRep flag does not
-** match that requested.
-*/
-FuncDef *sqlite3FindFunction(
-  sqlite3 *db,       /* An open database */
-  const char *zName, /* Name of the function.  Not null-terminated */
-  int nName,         /* Number of characters in the name */
-  int nArg,          /* Number of arguments.  -1 means any number */
-  u8 enc,            /* Preferred text encoding */
-  int createFlag     /* Create new entry if true and does not otherwise exist */
-){
-  FuncDef *p;         /* Iterator variable */
-  FuncDef *pFirst;    /* First function with this name */
-  FuncDef *pBest = 0; /* Best match found so far */
-  int bestmatch = 0;  
-
-
-  assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
-  if( nArg<-1 ) nArg = -1;
-
-  pFirst = (FuncDef*)sqlite3HashFind(&db->aFunc, zName, nName);
-  for(p=pFirst; p; p=p->pNext){
-    /* During the search for the best function definition, bestmatch is set
-    ** as follows to indicate the quality of the match with the definition
-    ** pointed to by pBest:
-    **
-    ** 0: pBest is NULL. No match has been found.
-    ** 1: A variable arguments function that prefers UTF-8 when a UTF-16
-    **    encoding is requested, or vice versa.
-    ** 2: A variable arguments function that uses UTF-16BE when UTF-16LE is
-    **    requested, or vice versa.
-    ** 3: A variable arguments function using the same text encoding.
-    ** 4: A function with the exact number of arguments requested that
-    **    prefers UTF-8 when a UTF-16 encoding is requested, or vice versa.
-    ** 5: A function with the exact number of arguments requested that
-    **    prefers UTF-16LE when UTF-16BE is requested, or vice versa.
-    ** 6: An exact match.
-    **
-    ** A larger value of 'matchqual' indicates a more desirable match.
-    */
-    if( p->nArg==-1 || p->nArg==nArg || nArg==-1 ){
-      int match = 1;          /* Quality of this match */
-      if( p->nArg==nArg || nArg==-1 ){
-        match = 4;
-      }
-      if( enc==p->iPrefEnc ){
-        match += 2;
-      }
-      else if( (enc==SQLITE_UTF16LE && p->iPrefEnc==SQLITE_UTF16BE) ||
-               (enc==SQLITE_UTF16BE && p->iPrefEnc==SQLITE_UTF16LE) ){
-        match += 1;
-      }
-
-      if( match>bestmatch ){
-        pBest = p;
-        bestmatch = match;
-      }
-    }
-  }
-
-  /* If the createFlag parameter is true, and the seach did not reveal an
-  ** exact match for the name, number of arguments and encoding, then add a
-  ** new entry to the hash table and return it.
-  */
-  if( createFlag && bestmatch<6 && 
-      (pBest = sqliteMalloc(sizeof(*pBest)+nName+1)) ){
-    pBest->nArg = nArg;
-    pBest->pNext = pFirst;
-    pBest->zName = (char*)&pBest[1];
-    pBest->iPrefEnc = enc;
-    memcpy(pBest->zName, zName, nName);
-    pBest->zName[nName] = 0;
-    if( pBest==sqlite3HashInsert(&db->aFunc,pBest->zName,nName,(void*)pBest) ){
-      sqliteFree(pBest);
-      return 0;
-    }
-  }
-
-  if( pBest && (pBest->xStep || pBest->xFunc || createFlag) ){
-    return pBest;
-  }
-  return 0;
-}
index 49ceed39ead275c6e6384ee0b0e482e77ed7e379..92b8625fc6c802d4dca3449c111246ab098e212a 100644 (file)
@@ -1035,4 +1035,9 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
     }
   }
   sqlite3RegisterDateTimeFunctions(db);
+#ifdef SQLITE_SSE
+  {
+    sqlite3SseFunctions(db);
+  }
+#endif
 }
index c9485fe24752c4902332d8feecf05cda85676cd9..ebcc70aedf922f67df225b13aacaf4f19cb08a22 100644 (file)
@@ -108,7 +108,7 @@ static int selectReadsTable(Select *p, int iDb, int iTab){
   if( p->pSrc==0 ) return 0;
   for(i=0, pItem=p->pSrc->a; i<p->pSrc->nSrc; i++, pItem++){
     if( pItem->pSelect ){
-      if( selectReadsTable(p, iDb, iTab) ) return 1;
+      if( selectReadsTable(pItem->pSelect, iDb, iTab) ) return 1;
     }else{
       if( pItem->pTab->iDb==iDb && pItem->pTab->tnum==iTab ) return 1;
     }
@@ -308,7 +308,7 @@ void sqlite3Insert(
     sqlite3VdbeAddOp(v, OP_Column, iCur, 0);
     sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->zName, 0);
     sqlite3VdbeAddOp(v, OP_Ne, 28417, base+12);
-    sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
+    sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
     sqlite3VdbeAddOp(v, OP_MemStore, counterRowid, 1);
     sqlite3VdbeAddOp(v, OP_Column, iCur, 1);
     sqlite3VdbeAddOp(v, OP_MemStore, counterMem, 1);
@@ -363,9 +363,9 @@ void sqlite3Insert(
       sqlite3VdbeResolveLabel(v, iInsertBlock);
       sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, 0);
       sqlite3TableAffinityStr(v, pTab);
-      sqlite3VdbeAddOp(v, OP_NewRecno, srcTab, 0);
+      sqlite3VdbeAddOp(v, OP_NewRowid, srcTab, 0);
       sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
-      sqlite3VdbeAddOp(v, OP_PutIntKey, srcTab, 0);
+      sqlite3VdbeAddOp(v, OP_Insert, srcTab, 0);
       sqlite3VdbeAddOp(v, OP_Return, 0, 0);
 
       /* The following code runs first because the GOTO at the very top
@@ -547,7 +547,7 @@ void sqlite3Insert(
     if( !isView ){
       sqlite3TableAffinityStr(v, pTab);
     }
-    sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0);
+    sqlite3VdbeAddOp(v, OP_Insert, newIdx, 0);
 
     /* Fire BEFORE or INSTEAD OF triggers */
     if( sqlite3CodeRowTrigger(pParse, TK_INSERT, 0, TRIGGER_BEFORE, pTab, 
@@ -565,7 +565,7 @@ void sqlite3Insert(
   }
 
   /* Push the record number for the new entry onto the stack.  The
-  ** record number is a randomly generate integer created by NewRecno
+  ** record number is a randomly generate integer created by NewRowid
   ** except when the table has an INTEGER PRIMARY KEY column, in which
   ** case the record number is the same as that column. 
   */
@@ -578,15 +578,15 @@ void sqlite3Insert(
       }else{
         sqlite3ExprCode(pParse, pList->a[keyColumn].pExpr);
       }
-      /* If the PRIMARY KEY expression is NULL, then use OP_NewRecno
+      /* If the PRIMARY KEY expression is NULL, then use OP_NewRowid
       ** to generate a unique primary key value.
       */
       sqlite3VdbeAddOp(v, OP_NotNull, -1, sqlite3VdbeCurrentAddr(v)+3);
       sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
-      sqlite3VdbeAddOp(v, OP_NewRecno, base, counterMem);
+      sqlite3VdbeAddOp(v, OP_NewRowid, base, counterMem);
       sqlite3VdbeAddOp(v, OP_MustBeInt, 0, 0);
     }else{
-      sqlite3VdbeAddOp(v, OP_NewRecno, base, counterMem);
+      sqlite3VdbeAddOp(v, OP_NewRowid, base, counterMem);
     }
 #ifndef SQLITE_OMIT_AUTOINCREMENT
     if( pTab->autoInc ){
@@ -603,7 +603,7 @@ void sqlite3Insert(
         ** Whenever this column is read, the record number will be substituted
         ** in its place.  So will fill this column with a NULL to avoid
         ** taking up data space with information that will never be used. */
-        sqlite3VdbeAddOp(v, OP_String8, 0, 0);
+        sqlite3VdbeAddOp(v, OP_Null, 0, 0);
         continue;
       }
       if( pColumn==0 ){
@@ -690,11 +690,11 @@ void sqlite3Insert(
     sqlite3VdbeAddOp(v, OP_MemLoad, counterRowid, 0);
     sqlite3VdbeAddOp(v, OP_NotNull, -1, base+7);
     sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
-    sqlite3VdbeAddOp(v, OP_NewRecno, iCur, 0);
+    sqlite3VdbeAddOp(v, OP_NewRowid, iCur, 0);
     sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->zName, 0);
     sqlite3VdbeAddOp(v, OP_MemLoad, counterMem, 0);
     sqlite3VdbeAddOp(v, OP_MakeRecord, 2, 0);
-    sqlite3VdbeAddOp(v, OP_PutIntKey, iCur, 0);
+    sqlite3VdbeAddOp(v, OP_Insert, iCur, 0);
     sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
   }
 #endif
@@ -713,8 +713,8 @@ void sqlite3Insert(
 
 insert_cleanup:
   sqlite3SrcListDelete(pTabList);
-  if( pList ) sqlite3ExprListDelete(pList);
-  if( pSelect ) sqlite3SelectDelete(pSelect);
+  sqlite3ExprListDelete(pList);
+  sqlite3SelectDelete(pSelect);
   sqlite3IdListDelete(pColumn);
 }
 
@@ -724,11 +724,11 @@ insert_cleanup:
 ** When this routine is called, the stack contains (from bottom to top)
 ** the following values:
 **
-**    1.  The recno of the row to be updated before the update.  This
+**    1.  The rowid of the row to be updated before the update.  This
 **        value is omitted unless we are doing an UPDATE that involves a
 **        change to the record number.
 **
-**    2.  The recno of the row after the update.
+**    2.  The rowid of the row after the update.
 **
 **    3.  The data in the first column of the entry after the update.
 **
@@ -736,9 +736,9 @@ insert_cleanup:
 **
 **    N.  The data in the last column of the entry after the update.
 **
-** The old recno shown as entry (1) above is omitted unless both isUpdate
-** and recnoChng are 1.  isUpdate is true for UPDATEs and false for
-** INSERTs and recnoChng is true if the record number is being changed.
+** The old rowid shown as entry (1) above is omitted unless both isUpdate
+** and rowidChng are 1.  isUpdate is true for UPDATEs and false for
+** INSERTs and rowidChng is true if the record number is being changed.
 **
 ** The code generated by this routine pushes additional entries onto
 ** the stack which are the keys for new index entries for the new record.
@@ -802,7 +802,7 @@ void sqlite3GenerateConstraintChecks(
   Table *pTab,        /* the table into which we are inserting */
   int base,           /* Index of a read/write cursor pointing at pTab */
   char *aIdxUsed,     /* Which indices are used.  NULL means all are used */
-  int recnoChng,      /* True if the record number will change */
+  int rowidChng,      /* True if the record number will change */
   int isUpdate,       /* True for UPDATE, False for INSERT */
   int overrideError,  /* Override onError to this if not OE_Default */
   int ignoreDest      /* Jump to this label on an OE_Ignore resolution */
@@ -818,7 +818,7 @@ void sqlite3GenerateConstraintChecks(
   int seenReplace = 0;
   int jumpInst1=0, jumpInst2;
   int contAddr;
-  int hasTwoRecnos = (isUpdate && recnoChng);
+  int hasTwoRowids = (isUpdate && rowidChng);
 
   v = sqlite3GetVdbe(pParse);
   assert( v!=0 );
@@ -857,7 +857,7 @@ void sqlite3GenerateConstraintChecks(
         break;
       }
       case OE_Ignore: {
-        sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRecnos, 0);
+        sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRowids, 0);
         sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest);
         break;
       }
@@ -878,7 +878,7 @@ void sqlite3GenerateConstraintChecks(
   ** of the new record does not previously exist.  Except, if this
   ** is an UPDATE and the primary key is not changing, that is OK.
   */
-  if( recnoChng ){
+  if( rowidChng ){
     onError = pTab->keyConf;
     if( overrideError!=OE_Default ){
       onError = overrideError;
@@ -908,7 +908,7 @@ void sqlite3GenerateConstraintChecks(
       case OE_Replace: {
         sqlite3GenerateRowIndexDelete(pParse->db, v, pTab, base, 0);
         if( isUpdate ){
-          sqlite3VdbeAddOp(v, OP_Dup, nCol+hasTwoRecnos, 1);
+          sqlite3VdbeAddOp(v, OP_Dup, nCol+hasTwoRowids, 1);
           sqlite3VdbeAddOp(v, OP_MoveGe, base, 0);
         }
         seenReplace = 1;
@@ -916,7 +916,7 @@ void sqlite3GenerateConstraintChecks(
       }
       case OE_Ignore: {
         assert( seenReplace==0 );
-        sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRecnos, 0);
+        sqlite3VdbeAddOp(v, OP_Pop, nCol+1+hasTwoRowids, 0);
         sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest);
         break;
       }
@@ -967,7 +967,7 @@ void sqlite3GenerateConstraintChecks(
     
 
     /* Check to see if the new index entry will be unique */
-    sqlite3VdbeAddOp(v, OP_Dup, extra+nCol+1+hasTwoRecnos, 1);
+    sqlite3VdbeAddOp(v, OP_Dup, extra+nCol+1+hasTwoRowids, 1);
     jumpInst2 = sqlite3VdbeAddOp(v, OP_IsUnique, base+iCur+1, 0);
 
     /* Generate code that executes if the new index entry is not unique */
@@ -1004,14 +1004,14 @@ void sqlite3GenerateConstraintChecks(
       }
       case OE_Ignore: {
         assert( seenReplace==0 );
-        sqlite3VdbeAddOp(v, OP_Pop, nCol+extra+3+hasTwoRecnos, 0);
+        sqlite3VdbeAddOp(v, OP_Pop, nCol+extra+3+hasTwoRowids, 0);
         sqlite3VdbeAddOp(v, OP_Goto, 0, ignoreDest);
         break;
       }
       case OE_Replace: {
         sqlite3GenerateRowDelete(pParse->db, v, pTab, base, 0);
         if( isUpdate ){
-          sqlite3VdbeAddOp(v, OP_Dup, nCol+extra+1+hasTwoRecnos, 1);
+          sqlite3VdbeAddOp(v, OP_Dup, nCol+extra+1+hasTwoRowids, 1);
           sqlite3VdbeAddOp(v, OP_MoveGe, base, 0);
         }
         seenReplace = 1;
@@ -1031,7 +1031,7 @@ void sqlite3GenerateConstraintChecks(
 ** This routine generates code to finish the INSERT or UPDATE operation
 ** that was started by a prior call to sqlite3GenerateConstraintChecks.
 ** The stack must contain keys for all active indices followed by data
-** and the recno for the new entry.  This routine creates the new
+** and the rowid for the new entry.  This routine creates the new
 ** entries in all indices and in the main table.
 **
 ** The arguments to this routine should be the same as the first six
@@ -1042,7 +1042,7 @@ void sqlite3CompleteInsertion(
   Table *pTab,        /* the table into which we are inserting */
   int base,           /* Index of a read/write cursor pointing at pTab */
   char *aIdxUsed,     /* Which indices are used.  NULL means all are used */
-  int recnoChng,      /* True if the record number will change */
+  int rowidChng,      /* True if the record number will change */
   int isUpdate,       /* True for UPDATE, False for INSERT */
   int newIdx          /* Index of NEW table for triggers.  -1 if none */
 ){
@@ -1058,7 +1058,7 @@ void sqlite3CompleteInsertion(
   for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){}
   for(i=nIdx-1; i>=0; i--){
     if( aIdxUsed && aIdxUsed[i]==0 ) continue;
-    sqlite3VdbeAddOp(v, OP_IdxPut, base+i+1, 0);
+    sqlite3VdbeAddOp(v, OP_IdxInsert, base+i+1, 0);
   }
   sqlite3VdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
   sqlite3TableAffinityStr(v, pTab);
@@ -1066,7 +1066,7 @@ void sqlite3CompleteInsertion(
   if( newIdx>=0 ){
     sqlite3VdbeAddOp(v, OP_Dup, 1, 0);
     sqlite3VdbeAddOp(v, OP_Dup, 1, 0);
-    sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0);
+    sqlite3VdbeAddOp(v, OP_Insert, newIdx, 0);
   }
 #endif
   if( pParse->nested ){
@@ -1074,9 +1074,9 @@ void sqlite3CompleteInsertion(
   }else{
     pik_flags = (OPFLAG_NCHANGE|(isUpdate?0:OPFLAG_LASTROWID));
   }
-  sqlite3VdbeAddOp(v, OP_PutIntKey, base, pik_flags);
+  sqlite3VdbeAddOp(v, OP_Insert, base, pik_flags);
   
-  if( isUpdate && recnoChng ){
+  if( isUpdate && rowidChng ){
     sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
   }
 }
index 77377b444368a3ac59a03a8d63a0603526e23b6f..2eef13b20d9bec8ffc1ca4e8c5956593f3687dc4 100644 (file)
@@ -1,82 +1,83 @@
-/* Hash score: 148 */
+/* Hash score: 153 */
 static int keywordCode(const char *z, int n){
-  static const char zText[504] =
-    "ABORTABLEFTEMPORARYAFTERAISELECTHENDATABASEACHECKEYALTEREFERENCES"
-    "CAPELSEXCEPTRANSACTIONATURALIKEXCLUSIVEXISTSTATEMENTRIGGEREINDEX"
-    "PLAINITIALLYANDEFAULTATTACHAVINGLOBEFOREIGNORENAMEAUTOINCREMENT"
-    "BEGINNEREPLACEBETWEENOTNULLIMITBYCASCADEFERRABLECASECOLLATECOMMIT"
-    "CONFLICTCONSTRAINTERSECTCREATECROSSCURRENT_DATECURRENT_TIMESTAMP"
-    "RAGMATCHDEFERREDELETEDESCDETACHDISTINCTDROPRIMARYFAILFROMFULL"
-    "GROUPDATEIMMEDIATEINSERTINSTEADINTOFFSETISNULLJOINORDERESTRICT"
-    "OUTERIGHTROLLBACKROWHENUNIONUNIQUEUSINGVACUUMVALUESVIEWHERE";
+  static const char zText[515] =
+    "ABORTABLEFTEMPORARYADDATABASELECTHENDEFAULTRANSACTIONATURALTER"
+    "AISEACHECKEYAFTEREFERENCESCAPELSEXCEPTRIGGEREGEXPLAINITIALLYAND"
+    "EFERRABLEXCLUSIVEXISTSTATEMENTATTACHAVINGLOBEFOREIGNOREINDEXAUTOINCREMENT"
+    "BEGINNERENAMEBETWEENOTNULLIKEBYCASCADEFERREDELETECASECOLLATECOLUMN"
+    "COMMITCONFLICTCONSTRAINTERSECTCREATECROSSCURRENT_DATECURRENT_TIMESTAMP"
+    "RAGMATCHDESCDETACHDISTINCTDROPRIMARYFAILIMITFROMFULLGROUPDATE"
+    "IMMEDIATEINSERTINSTEADINTOFFSETISNULLJOINORDEREPLACEOUTERESTRICT"
+    "RIGHTROLLBACKROWHENUNIONUNIQUEUSINGVACUUMVALUESVIEWHERE";
   static const unsigned char aHash[127] = {
-      87,  78,  99,  86,   0,   4,   0,   0, 106,   0,  72,   0,   0,
-      90,  43,   0,  88,   0,  98, 101,  92,   0,   0,   9,   0,   0,
-     105,   0, 102,  96,   0,  10,  46,   0,  40,   0,   0,  61,  66,
-       0,  60,  14,   0,   0,  35,  80,   0, 100,  69,   0,   0,  26,
-       0,  73,  59,   0,  12,   0, 107,  37,  11,   0,  75,  39,  20,
-       0,   0,   0,  34,  79,  51,  33,  48,  15,  84,   0,  36,   0,
-      70,  21,   0,  67,   0,   0,   0,   0,  45,  62,  17,  83,  32,
-      64,  82,   0,   1,   0,  13,  50,  56,   8,   0, 104,  71,  94,
-      52,   6,  55,   0,   0,  47,  89,   0,  97,   0,  65,   0,   0,
-      23,   0, 108,  49,  54,   0,   2,  53,   0, 103,
+      89,  79, 102,  88,   0,   4,   0,   0, 109,   0,  75,   0,   0,
+      92,  43,   0,  90,   0, 101, 104,  94,   0,   0,  10,   0,   0,
+     108,   0, 105, 100,   0,  28,  47,   0,  40,   0,   0,  63,  69,
+       0,  62,  19,   0,   0,  32,  81,   0, 103,  72,   0,   0,  34,
+       0,  60,  33,   0,   8,   0, 110,  37,  12,   0,  76,  39,  25,
+      64,   0,   0,  31,  80,  52,  30,  49,  20,  86,   0,  35,   0,
+      73,  26,   0,  70,   0,   0,   0,   0,  46,  65,  22,  85,  29,
+      67,  84,   0,   1,   0,   9,  98,  57,  18,   0, 107,  74,  96,
+      53,   6,  83,   0,   0,  48,  91,   0,  99,   0,  68,   0,   0,
+      15,   0, 111,  50,  55,   0,   2,  54,   0, 106,
   };
-  static const unsigned char aNext[108] = {
+  static const unsigned char aNext[111] = {
        0,   0,   0,   0,   0,   3,   0,   0,   0,   0,   0,   0,   0,
-       0,   0,   0,   7,   0,   0,   0,   0,   0,   0,   0,  18,   5,
-       0,   0,   0,   0,   0,   0,   0,   0,   0,  27,   0,   0,   0,
-       0,   0,   0,   0,   0,  42,   0,   0,   0,   0,   0,   0,   0,
-      24,   0,   0,  44,   0,   0,   0,  30,  57,   0,   0,   0,   0,
-       0,   0,   0,  68,  41,   0,   0,   0,   0,  19,  58,  16,   0,
-      77,   0,  63,   0,  81,  31,   0,   0,   0,   0,   0,   0,   0,
-      38,  91,  93,   0,   0,  95,  22,  29,  76,   0,  25,  85,   0,
-      28,   0,  74,   0,
+       0,   0,   0,   0,   0,   0,   0,   0,  17,   0,   0,   0,   0,
+       0,  11,   0,   0,   0,   7,   0,   5,  13,   0,   0,   0,   0,
+       0,   0,   0,   0,   0,   0,  42,   0,   0,   0,   0,   0,   0,
+       0,  16,   0,  23,  51,   0,   0,   0,   0,  44,  58,   0,   0,
+       0,   0,   0,   0,   0,   0,  71,  41,   0,   0,  24,  59,  21,
+       0,  78,   0,  66,   0,   0,  82,  45,   0,   0,   0,   0,   0,
+       0,   0,  38,  93,  95,   0,   0,  97,   0,  14,  27,  77,   0,
+      56,  87,   0,  36,   0,  61,   0,
   };
-  static const unsigned char aLen[108] = {
-       5,   5,   4,   4,   9,   2,   5,   5,   6,   4,   3,   8,   2,
-       4,   5,   3,   5,  10,   6,   4,   6,  11,   2,   7,   4,   9,
-       6,   9,   7,   7,   5,   7,   9,   3,   3,   7,   6,   6,   4,
-       6,   3,   7,   6,   6,  13,   2,   2,   5,   5,   7,   7,   3,
-       7,   4,   5,   2,   7,   3,  10,   4,   7,   6,   8,  10,   9,
-       6,   5,  12,  12,  17,   6,   5,   8,   6,   4,   6,   8,   2,
-       4,   7,   4,   4,   4,   5,   6,   9,   6,   7,   4,   2,   6,
-       3,   6,   4,   5,   8,   5,   5,   8,   3,   4,   5,   6,   5,
-       6,   6,   4,   5,
+  static const unsigned char aLen[111] = {
+       5,   5,   4,   4,   9,   2,   3,   8,   2,   6,   4,   3,   7,
+      11,   2,   7,   5,   5,   4,   5,   3,   5,  10,   6,   4,   6,
+       7,   6,   7,   9,   3,   3,  10,   9,   6,   9,   6,   6,   4,
+       6,   3,   7,   6,   7,   5,  13,   2,   2,   5,   5,   6,   7,
+       3,   7,   4,   4,   2,   7,   3,   8,   6,   4,   7,   6,   6,
+       8,  10,   9,   6,   5,  12,  12,  17,   6,   5,   4,   6,   8,
+       2,   4,   7,   4,   5,   4,   4,   5,   6,   9,   6,   7,   4,
+       2,   6,   3,   6,   4,   5,   7,   5,   8,   5,   8,   3,   4,
+       5,   6,   5,   6,   6,   4,   5,
   };
-  static const unsigned short int aOffset[108] = {
-       0,   4,   7,  10,  10,  14,  19,  23,  26,  31,  33,  35,  40,
-      42,  44,  48,  51,  55,  63,  68,  71,  76,  85,  86,  92,  95,
-     103, 108, 116, 122, 124, 127, 132, 137, 141, 143, 150, 155, 160,
-     163, 165, 165, 169, 173, 179, 181, 183, 192, 195, 199, 206, 212,
-     212, 215, 218, 223, 225, 226, 230, 240, 244, 251, 257, 265, 272,
-     281, 287, 292, 304, 304, 320, 324, 329, 336, 342, 346, 352, 353,
-     360, 363, 370, 374, 378, 382, 385, 391, 400, 406, 413, 416, 416,
-     419, 422, 428, 432, 436, 444, 448, 453, 461, 463, 467, 472, 478,
-     483, 489, 495, 498,
+  static const unsigned short int aOffset[111] = {
+       0,   4,   7,  10,  10,  14,  19,  21,  26,  27,  32,  34,  36,
+      42,  51,  52,  57,  61,  65,  67,  71,  74,  78,  86,  91,  94,
+      99, 105, 108, 113, 118, 122, 124, 133, 141, 146, 155, 160, 165,
+     168, 170, 170, 174, 178, 180, 185, 187, 189, 198, 201, 205, 211,
+     217, 217, 220, 223, 227, 229, 230, 234, 241, 247, 251, 258, 264,
+     270, 278, 285, 294, 300, 305, 317, 317, 333, 337, 342, 346, 352,
+     353, 360, 363, 370, 373, 378, 382, 386, 389, 395, 404, 410, 417,
+     420, 420, 423, 426, 432, 436, 440, 447, 451, 459, 464, 472, 474,
+     478, 483, 489, 494, 500, 506, 509,
   };
-  static const unsigned char aCode[108] = {
+  static const unsigned char aCode[111] = {
     TK_ABORT,      TK_TABLE,      TK_JOIN_KW,    TK_TEMP,       TK_TEMP,       
-    TK_OR,         TK_AFTER,      TK_RAISE,      TK_SELECT,     TK_THEN,       
-    TK_END,        TK_DATABASE,   TK_AS,         TK_EACH,       TK_CHECK,      
-    TK_KEY,        TK_ALTER,      TK_REFERENCES, TK_ESCAPE,     TK_ELSE,       
-    TK_EXCEPT,     TK_TRANSACTION,TK_ON,         TK_JOIN_KW,    TK_LIKE,       
-    TK_EXCLUSIVE,  TK_EXISTS,     TK_STATEMENT,  TK_TRIGGER,    TK_REINDEX,    
-    TK_INDEX,      TK_EXPLAIN,    TK_INITIALLY,  TK_ALL,        TK_AND,        
-    TK_DEFAULT,    TK_ATTACH,     TK_HAVING,     TK_GLOB,       TK_BEFORE,     
-    TK_FOR,        TK_FOREIGN,    TK_IGNORE,     TK_RENAME,     TK_AUTOINCR,   
-    TK_TO,         TK_IN,         TK_BEGIN,      TK_JOIN_KW,    TK_REPLACE,    
-    TK_BETWEEN,    TK_NOT,        TK_NOTNULL,    TK_NULL,       TK_LIMIT,      
-    TK_BY,         TK_CASCADE,    TK_ASC,        TK_DEFERRABLE, TK_CASE,       
-    TK_COLLATE,    TK_COMMIT,     TK_CONFLICT,   TK_CONSTRAINT, TK_INTERSECT,  
-    TK_CREATE,     TK_JOIN_KW,    TK_CDATE,      TK_CTIME,      TK_CTIMESTAMP, 
-    TK_PRAGMA,     TK_MATCH,      TK_DEFERRED,   TK_DELETE,     TK_DESC,       
-    TK_DETACH,     TK_DISTINCT,   TK_IS,         TK_DROP,       TK_PRIMARY,    
-    TK_FAIL,       TK_FROM,       TK_JOIN_KW,    TK_GROUP,      TK_UPDATE,     
-    TK_IMMEDIATE,  TK_INSERT,     TK_INSTEAD,    TK_INTO,       TK_OF,         
-    TK_OFFSET,     TK_SET,        TK_ISNULL,     TK_JOIN,       TK_ORDER,      
-    TK_RESTRICT,   TK_JOIN_KW,    TK_JOIN_KW,    TK_ROLLBACK,   TK_ROW,        
-    TK_WHEN,       TK_UNION,      TK_UNIQUE,     TK_USING,      TK_VACUUM,     
-    TK_VALUES,     TK_VIEW,       TK_WHERE,      
+    TK_OR,         TK_ADD,        TK_DATABASE,   TK_AS,         TK_SELECT,     
+    TK_THEN,       TK_END,        TK_DEFAULT,    TK_TRANSACTION,TK_ON,         
+    TK_JOIN_KW,    TK_ALTER,      TK_RAISE,      TK_EACH,       TK_CHECK,      
+    TK_KEY,        TK_AFTER,      TK_REFERENCES, TK_ESCAPE,     TK_ELSE,       
+    TK_EXCEPT,     TK_TRIGGER,    TK_LIKE_KW,    TK_EXPLAIN,    TK_INITIALLY,  
+    TK_ALL,        TK_AND,        TK_DEFERRABLE, TK_EXCLUSIVE,  TK_EXISTS,     
+    TK_STATEMENT,  TK_ATTACH,     TK_HAVING,     TK_LIKE_KW,    TK_BEFORE,     
+    TK_FOR,        TK_FOREIGN,    TK_IGNORE,     TK_REINDEX,    TK_INDEX,      
+    TK_AUTOINCR,   TK_TO,         TK_IN,         TK_BEGIN,      TK_JOIN_KW,    
+    TK_RENAME,     TK_BETWEEN,    TK_NOT,        TK_NOTNULL,    TK_NULL,       
+    TK_LIKE_KW,    TK_BY,         TK_CASCADE,    TK_ASC,        TK_DEFERRED,   
+    TK_DELETE,     TK_CASE,       TK_COLLATE,    TK_COLUMNKW,   TK_COMMIT,     
+    TK_CONFLICT,   TK_CONSTRAINT, TK_INTERSECT,  TK_CREATE,     TK_JOIN_KW,    
+    TK_CTIME_KW,   TK_CTIME_KW,   TK_CTIME_KW,   TK_PRAGMA,     TK_MATCH,      
+    TK_DESC,       TK_DETACH,     TK_DISTINCT,   TK_IS,         TK_DROP,       
+    TK_PRIMARY,    TK_FAIL,       TK_LIMIT,      TK_FROM,       TK_JOIN_KW,    
+    TK_GROUP,      TK_UPDATE,     TK_IMMEDIATE,  TK_INSERT,     TK_INSTEAD,    
+    TK_INTO,       TK_OF,         TK_OFFSET,     TK_SET,        TK_ISNULL,     
+    TK_JOIN,       TK_ORDER,      TK_REPLACE,    TK_JOIN_KW,    TK_RESTRICT,   
+    TK_JOIN_KW,    TK_ROLLBACK,   TK_ROW,        TK_WHEN,       TK_UNION,      
+    TK_UNIQUE,     TK_USING,      TK_VACUUM,     TK_VALUES,     TK_VIEW,       
+    TK_WHERE,      
   };
   int h, i;
   if( n<2 ) return TK_ID;
index 1d6dec3a3cd0ae481d985fad58cdc617bc5d3b16..dfc9dd7c620cab4cdb1a4e0d5501d45bfd2eb7a0 100644 (file)
 */
 const int sqlite3one = 1;
 
+#ifndef SQLITE_OMIT_GLOBALRECOVER
 /*
-** Fill the InitData structure with an error message that indicates
-** that the database is corrupt.
+** Linked list of all open database handles. This is used by the 
+** sqlite3_global_recover() function. Entries are added to the list
+** by openDatabase() and removed by sqlite3_close().
 */
-static void corruptSchema(InitData *pData, const char *zExtra){
-  if( !sqlite3_malloc_failed ){
-    sqlite3SetString(pData->pzErrMsg, "malformed database schema",
-       zExtra!=0 && zExtra[0]!=0 ? " - " : (char*)0, zExtra, (char*)0);
-  }
-}
-
-/*
-** This is the callback routine for the code that initializes the
-** database.  See sqlite3Init() below for additional information.
-** This routine is also called from the OP_ParseSchema opcode of the VDBE.
-**
-** Each callback contains the following information:
-**
-**     argv[0] = name of thing being created
-**     argv[1] = root page number for table or index.  NULL for trigger or view.
-**     argv[2] = SQL text for the CREATE statement.
-**     argv[3] = "1" for temporary files, "0" for main database, "2" or more
-**               for auxiliary database files.
-**
-*/
-int sqlite3InitCallback(void *pInit, int argc, char **argv, char **azColName){
-  InitData *pData = (InitData*)pInit;
-  sqlite3 *db = pData->db;
-  int iDb;
-
-  assert( argc==4 );
-  if( argv==0 ) return 0;   /* Might happen if EMPTY_RESULT_CALLBACKS are on */
-  if( argv[1]==0 || argv[3]==0 ){
-    corruptSchema(pData, 0);
-    return 1;
-  }
-  iDb = atoi(argv[3]);
-  assert( iDb>=0 && iDb<db->nDb );
-  if( argv[2] && argv[2][0] ){
-    /* Call the parser to process a CREATE TABLE, INDEX or VIEW.
-    ** But because db->init.busy is set to 1, no VDBE code is generated
-    ** or executed.  All the parser does is build the internal data
-    ** structures that describe the table, index, or view.
-    */
-    char *zErr;
-    int rc;
-    assert( db->init.busy );
-    db->init.iDb = iDb;
-    db->init.newTnum = atoi(argv[1]);
-    rc = sqlite3_exec(db, argv[2], 0, 0, &zErr);
-    db->init.iDb = 0;
-    if( SQLITE_OK!=rc ){
-      corruptSchema(pData, zErr);
-      sqlite3_free(zErr);
-      return rc;
-    }
-  }else{
-    /* If the SQL column is blank it means this is an index that
-    ** was created to be the PRIMARY KEY or to fulfill a UNIQUE
-    ** constraint for a CREATE TABLE.  The index should have already
-    ** been created when we processed the CREATE TABLE.  All we have
-    ** to do here is record the root page number for that index.
-    */
-    Index *pIndex;
-    pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName);
-    if( pIndex==0 || pIndex->tnum!=0 ){
-      /* This can occur if there exists an index on a TEMP table which
-      ** has the same name as another index on a permanent index.  Since
-      ** the permanent table is hidden by the TEMP table, we can also
-      ** safely ignore the index on the permanent table.
-      */
-      /* Do Nothing */;
-    }else{
-      pIndex->tnum = atoi(argv[1]);
-    }
-  }
-  return 0;
-}
-
-/*
-** Attempt to read the database schema and initialize internal
-** data structures for a single database file.  The index of the
-** database file is given by iDb.  iDb==0 is used for the main
-** database.  iDb==1 should never be used.  iDb>=2 is used for
-** auxiliary databases.  Return one of the SQLITE_ error codes to
-** indicate success or failure.
-*/
-static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
-  int rc;
-  BtCursor *curMain;
-  int size;
-  Table *pTab;
-  char const *azArg[5];
-  char zDbNum[30];
-  int meta[10];
-  InitData initData;
-  char const *zMasterSchema;
-  char const *zMasterName;
-
-  /*
-  ** The master database table has a structure like this
-  */
-  static const char master_schema[] = 
-     "CREATE TABLE sqlite_master(\n"
-     "  type text,\n"
-     "  name text,\n"
-     "  tbl_name text,\n"
-     "  rootpage integer,\n"
-     "  sql text\n"
-     ")"
-  ;
-  static const char temp_master_schema[] = 
-     "CREATE TEMP TABLE sqlite_temp_master(\n"
-     "  type text,\n"
-     "  name text,\n"
-     "  tbl_name text,\n"
-     "  rootpage integer,\n"
-     "  sql text\n"
-     ")"
-  ;
-
-  assert( iDb>=0 && iDb<db->nDb );
-
-  /* zMasterSchema and zInitScript are set to point at the master schema
-  ** and initialisation script appropriate for the database being
-  ** initialised. zMasterName is the name of the master table.
-  */
-  if( iDb==1 ){
-    zMasterSchema = temp_master_schema;
-    zMasterName = TEMP_MASTER_NAME;
-  }else{
-    zMasterSchema = master_schema;
-    zMasterName = MASTER_NAME;
-  }
-
-  /* Construct the schema tables.  */
-  sqlite3SafetyOff(db);
-  azArg[0] = zMasterName;
-  azArg[1] = "1";
-  azArg[2] = zMasterSchema;
-  sprintf(zDbNum, "%d", iDb);
-  azArg[3] = zDbNum;
-  azArg[4] = 0;
-  initData.db = db;
-  initData.pzErrMsg = pzErrMsg;
-  rc = sqlite3InitCallback(&initData, 4, (char **)azArg, 0);
-  if( rc!=SQLITE_OK ){
-    sqlite3SafetyOn(db);
-    return rc;
-  }
-  pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName);
-  if( pTab ){
-    pTab->readOnly = 1;
-  }
-  sqlite3SafetyOn(db);
-
-  /* Create a cursor to hold the database open
-  */
-  if( db->aDb[iDb].pBt==0 ){
-    if( iDb==1 ) DbSetProperty(db, 1, DB_SchemaLoaded);
-    return SQLITE_OK;
-  }
-  rc = sqlite3BtreeCursor(db->aDb[iDb].pBt, MASTER_ROOT, 0, 0, 0, &curMain);
-  if( rc!=SQLITE_OK && rc!=SQLITE_EMPTY ){
-    sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0);
-    return rc;
-  }
-
-  /* Get the database meta information.
-  **
-  ** Meta values are as follows:
-  **    meta[0]   Schema cookie.  Changes with each schema change.
-  **    meta[1]   File format of schema layer.
-  **    meta[2]   Size of the page cache.
-  **    meta[3]   Use freelist if 0.  Autovacuum if greater than zero.
-  **    meta[4]   Db text encoding. 1:UTF-8 3:UTF-16 LE 4:UTF-16 BE
-  **    meta[5]   The user cookie. Used by the application.
-  **    meta[6]   
-  **    meta[7]
-  **    meta[8]
-  **    meta[9]
-  **
-  ** Note: The hash defined SQLITE_UTF* symbols in sqliteInt.h correspond to
-  ** the possible values of meta[4].
-  */
-  if( rc==SQLITE_OK ){
-    int i;
-    for(i=0; rc==SQLITE_OK && i<sizeof(meta)/sizeof(meta[0]); i++){
-      rc = sqlite3BtreeGetMeta(db->aDb[iDb].pBt, i+1, (u32 *)&meta[i]);
-    }
-    if( rc ){
-      sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0);
-      sqlite3BtreeCloseCursor(curMain);
-      return rc;
-    }
-  }else{
-    memset(meta, 0, sizeof(meta));
-  }
-  db->aDb[iDb].schema_cookie = meta[0];
-
-  /* If opening a non-empty database, check the text encoding. For the
-  ** main database, set sqlite3.enc to the encoding of the main database.
-  ** For an attached db, it is an error if the encoding is not the same
-  ** as sqlite3.enc.
-  */
-  if( meta[4] ){  /* text encoding */
-    if( iDb==0 ){
-      /* If opening the main database, set db->enc. */
-      db->enc = (u8)meta[4];
-      db->pDfltColl = sqlite3FindCollSeq(db, db->enc, "BINARY", 6, 0);
-    }else{
-      /* If opening an attached database, the encoding much match db->enc */
-      if( meta[4]!=db->enc ){
-        sqlite3BtreeCloseCursor(curMain);
-        sqlite3SetString(pzErrMsg, "attached databases must use the same"
-            " text encoding as main database", (char*)0);
-        return SQLITE_ERROR;
-      }
-    }
-  }
-
-  size = meta[2];
-  if( size==0 ){ size = MAX_PAGES; }
-  db->aDb[iDb].cache_size = size;
-
-  if( iDb==0 ){
-    db->file_format = meta[1];
-    if( db->file_format==0 ){
-      /* This happens if the database was initially empty */
-      db->file_format = 1;
-    }
-
-    if( db->file_format==2 ){
-      /* File format 2 is treated exactly as file format 1. New 
-      ** databases are created with file format 1.
-      */ 
-      db->file_format = 1;
-    }
-  }
-
-  /*
-  ** file_format==1    Version 3.0.0.
-  ** file_format==2    Version 3.1.3.
-  **
-  ** Version 3.0 can only use files with file_format==1. Version 3.1.3
-  ** can read and write files with file_format==1 or file_format==2.
-  */
-  if( meta[1]>2 ){
-    sqlite3BtreeCloseCursor(curMain);
-    sqlite3SetString(pzErrMsg, "unsupported file format", (char*)0);
-    return SQLITE_ERROR;
-  }
-
-  sqlite3BtreeSetCacheSize(db->aDb[iDb].pBt, db->aDb[iDb].cache_size);
-
-  /* Read the schema information out of the schema tables
-  */
-  assert( db->init.busy );
-  if( rc==SQLITE_EMPTY ){
-    /* For an empty database, there is nothing to read */
-    rc = SQLITE_OK;
-  }else{
-    char *zSql;
-    zSql = sqlite3MPrintf(
-        "SELECT name, rootpage, sql, '%s' FROM '%q'.%s",
-        zDbNum, db->aDb[iDb].zName, zMasterName);
-    sqlite3SafetyOff(db);
-    rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
-    sqlite3SafetyOn(db);
-    sqliteFree(zSql);
-    sqlite3BtreeCloseCursor(curMain);
-  }
-  if( sqlite3_malloc_failed ){
-    sqlite3SetString(pzErrMsg, "out of memory", (char*)0);
-    rc = SQLITE_NOMEM;
-    sqlite3ResetInternalSchema(db, 0);
-  }
-  if( rc==SQLITE_OK ){
-    DbSetProperty(db, iDb, DB_SchemaLoaded);
-  }else{
-    sqlite3ResetInternalSchema(db, iDb);
-  }
-  return rc;
-}
-
-/*
-** Initialize all database files - the main database file, the file
-** used to store temporary tables, and any additional database files
-** created using ATTACH statements.  Return a success code.  If an
-** error occurs, write an error message into *pzErrMsg.
-**
-** After the database is initialized, the SQLITE_Initialized
-** bit is set in the flags field of the sqlite structure. 
-*/
-int sqlite3Init(sqlite3 *db, char **pzErrMsg){
-  int i, rc;
-  
-  if( db->init.busy ) return SQLITE_OK;
-  assert( (db->flags & SQLITE_Initialized)==0 );
-  rc = SQLITE_OK;
-  db->init.busy = 1;
-  for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
-    if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
-    rc = sqlite3InitOne(db, i, pzErrMsg);
-    if( rc ){
-      sqlite3ResetInternalSchema(db, i);
-    }
-  }
-
-  /* Once all the other databases have been initialised, load the schema
-  ** for the TEMP database. This is loaded last, as the TEMP database
-  ** schema may contain references to objects in other databases.
-  */
-  if( rc==SQLITE_OK && db->nDb>1 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
-    rc = sqlite3InitOne(db, 1, pzErrMsg);
-    if( rc ){
-      sqlite3ResetInternalSchema(db, 1);
-    }
-  }
-
-  db->init.busy = 0;
-  if( rc==SQLITE_OK ){
-    db->flags |= SQLITE_Initialized;
-    sqlite3CommitInternalChanges(db);
-  }
-
-  if( rc!=SQLITE_OK ){
-    db->flags &= ~SQLITE_Initialized;
-  }
-  return rc;
-}
+static sqlite3 *pDbList = 0;
+#endif
 
-/*
-** This routine is a no-op if the database schema is already initialised.
-** Otherwise, the schema is loaded. An error code is returned.
+#ifndef SQLITE_OMIT_UTF16
+/* 
+** Return the transient sqlite3_value object used for encoding conversions
+** during SQL compilation.
 */
-int sqlite3ReadSchema(Parse *pParse){
-  int rc = SQLITE_OK;
-  sqlite3 *db = pParse->db;
-  if( !db->init.busy ){
-    if( (db->flags & SQLITE_Initialized)==0 ){
-      rc = sqlite3Init(db, &pParse->zErrMsg);
-    }
-  }
-  assert( rc!=SQLITE_OK || (db->flags & SQLITE_Initialized)||db->init.busy );
-  if( rc!=SQLITE_OK ){
-    pParse->rc = rc;
-    pParse->nErr++;
+sqlite3_value *sqlite3GetTransientValue(sqlite3 *db){
+  if( !db->pValue ){
+    db->pValue = sqlite3ValueNew();
   }
-  return rc;
+  return db->pValue;
 }
+#endif
 
 /*
 ** The version of the library
@@ -461,6 +131,10 @@ int sqlite3_close(sqlite3 *db){
     return SQLITE_MISUSE;
   }
 
+#ifdef SQLITE_SSE
+  sqlite3_finalize(db->pFetch);
+#endif 
+
   /* If there are any outstanding VMs, return SQLITE_BUSY. */
   if( db->pVdbe ){
     sqlite3Error(db, SQLITE_BUSY, 
@@ -512,6 +186,24 @@ int sqlite3_close(sqlite3 *db){
     sqlite3ValueFree(db->pErr);
   }
 
+#ifndef SQLITE_OMIT_GLOBALRECOVER
+  {
+    sqlite3 *pPrev;
+    sqlite3OsEnterMutex();
+    pPrev = pDbList;
+    while( pPrev && pPrev->pNext!=db ){
+      pPrev = pPrev->pNext;
+    }
+    if( pPrev ){
+      pPrev->pNext = db->pNext;
+    }else{
+      assert( pDbList==db );
+      pDbList = db->pNext;
+    }
+    sqlite3OsLeaveMutex();
+  }
+#endif
+
   db->magic = SQLITE_MAGIC_ERROR;
   sqliteFree(db);
   return SQLITE_OK;
@@ -579,24 +271,25 @@ const char *sqlite3ErrStr(int rc){
 ** argument.
 */
 static int sqliteDefaultBusyCallback(
- void *Timeout,           /* Maximum amount of time to wait */
+ void *ptr,               /* Database connection */
  int count                /* Number of times table has been busy */
 ){
 #if SQLITE_MIN_SLEEP_MS==1
-  static const char delays[] =
-     { 1, 2, 5, 10, 15, 20, 25, 25,  25,  50,  50,  50, 100};
-  static const short int totals[] =
-     { 0, 1, 3,  8, 18, 33, 53, 78, 103, 128, 178, 228, 287};
+  static const u8 delays[] =
+     { 1, 2, 5, 10, 15, 20, 25, 25,  25,  50,  50, 100 };
+  static const u8 totals[] =
+     { 0, 1, 3,  8, 18, 33, 53, 78, 103, 128, 178, 228 };
 # define NDELAY (sizeof(delays)/sizeof(delays[0]))
-  ptr timeout = (ptr)Timeout;
-  ptr delay, prior;
+  int timeout = ((sqlite3 *)ptr)->busyTimeout;
+  int delay, prior;
 
-  if( count <= NDELAY ){
-    delay = delays[count-1];
-    prior = totals[count-1];
+  assert( count>=0 );
+  if( count < NDELAY ){
+    delay = delays[count];
+    prior = totals[count];
   }else{
     delay = delays[NDELAY-1];
-    prior = totals[NDELAY-1] + delay*(count-NDELAY-1);
+    prior = totals[NDELAY-1] + delay*(count-(NDELAY-1));
   }
   if( prior + delay > timeout ){
     delay = timeout - prior;
@@ -664,7 +357,8 @@ void sqlite3_progress_handler(
 */
 int sqlite3_busy_timeout(sqlite3 *db, int ms){
   if( ms>0 ){
-    sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)(ptr)ms);
+    db->busyTimeout = ms;
+    sqlite3_busy_handler(db, sqliteDefaultBusyCallback, (void*)db);
   }else{
     sqlite3_busy_handler(db, 0, 0);
   }
@@ -971,161 +665,10 @@ int sqlite3_errcode(sqlite3 *db){
   return db->errCode;
 }
 
-/*
-** Check schema cookies in all databases.  If any cookie is out
-** of date, return 0.  If all schema cookies are current, return 1.
-*/
-static int schemaIsValid(sqlite3 *db){
-  int iDb;
-  int rc;
-  BtCursor *curTemp;
-  int cookie;
-  int allOk = 1;
-
-  for(iDb=0; allOk && iDb<db->nDb; iDb++){
-    Btree *pBt;
-    pBt = db->aDb[iDb].pBt;
-    if( pBt==0 ) continue;
-    rc = sqlite3BtreeCursor(pBt, MASTER_ROOT, 0, 0, 0, &curTemp);
-    if( rc==SQLITE_OK ){
-      rc = sqlite3BtreeGetMeta(pBt, 1, (u32 *)&cookie);
-      if( rc==SQLITE_OK && cookie!=db->aDb[iDb].schema_cookie ){
-        allOk = 0;
-      }
-      sqlite3BtreeCloseCursor(curTemp);
-    }
-  }
-  return allOk;
-}
-
-/*
-** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
-*/
-int sqlite3_prepare(
-  sqlite3 *db,              /* Database handle. */
-  const char *zSql,         /* UTF-8 encoded SQL statement. */
-  int nBytes,               /* Length of zSql in bytes. */
-  sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
-  const char** pzTail       /* OUT: End of parsed string */
-){
-  Parse sParse;
-  char *zErrMsg = 0;
-  int rc = SQLITE_OK;
-
-  if( sqlite3_malloc_failed ){
-    return SQLITE_NOMEM;
-  }
-
-  assert( ppStmt );
-  *ppStmt = 0;
-  if( sqlite3SafetyOn(db) ){
-    return SQLITE_MISUSE;
-  }
-
-  memset(&sParse, 0, sizeof(sParse));
-  sParse.db = db;
-  sqlite3RunParser(&sParse, zSql, &zErrMsg);
-
-  if( sqlite3_malloc_failed ){
-    rc = SQLITE_NOMEM;
-    sqlite3RollbackAll(db);
-    sqlite3ResetInternalSchema(db, 0);
-    db->flags &= ~SQLITE_InTrans;
-    goto prepare_out;
-  }
-  if( sParse.rc==SQLITE_DONE ) sParse.rc = SQLITE_OK;
-  if( sParse.rc!=SQLITE_OK && sParse.checkSchema && !schemaIsValid(db) ){
-    sParse.rc = SQLITE_SCHEMA;
-  }
-  if( sParse.rc==SQLITE_SCHEMA ){
-    sqlite3ResetInternalSchema(db, 0);
-  }
-  if( pzTail ) *pzTail = sParse.zTail;
-  rc = sParse.rc;
-
-#ifndef SQLITE_OMIT_EXPLAIN
-  if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){
-    sqlite3VdbeSetNumCols(sParse.pVdbe, 5);
-    sqlite3VdbeSetColName(sParse.pVdbe, 0, "addr", P3_STATIC);
-    sqlite3VdbeSetColName(sParse.pVdbe, 1, "opcode", P3_STATIC);
-    sqlite3VdbeSetColName(sParse.pVdbe, 2, "p1", P3_STATIC);
-    sqlite3VdbeSetColName(sParse.pVdbe, 3, "p2", P3_STATIC);
-    sqlite3VdbeSetColName(sParse.pVdbe, 4, "p3", P3_STATIC);
-  } 
-#endif
-
-prepare_out:
-  if( sqlite3SafetyOff(db) ){
-    rc = SQLITE_MISUSE;
-  }
-  if( rc==SQLITE_OK ){
-    *ppStmt = (sqlite3_stmt*)sParse.pVdbe;
-  }else if( sParse.pVdbe ){
-    sqlite3_finalize((sqlite3_stmt*)sParse.pVdbe);
-  }
-
-  if( zErrMsg ){
-    sqlite3Error(db, rc, "%s", zErrMsg);
-    sqliteFree(zErrMsg);
-  }else{
-    sqlite3Error(db, rc, 0);
-  }
-  return rc;
-}
-
-#ifndef SQLITE_OMIT_UTF16
-/*
-** Compile the UTF-16 encoded SQL statement zSql into a statement handle.
-*/
-int sqlite3_prepare16(
-  sqlite3 *db,              /* Database handle. */ 
-  const void *zSql,         /* UTF-8 encoded SQL statement. */
-  int nBytes,               /* Length of zSql in bytes. */
-  sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
-  const void **pzTail       /* OUT: End of parsed string */
-){
-  /* This function currently works by first transforming the UTF-16
-  ** encoded string to UTF-8, then invoking sqlite3_prepare(). The
-  ** tricky bit is figuring out the pointer to return in *pzTail.
-  */
-  char const *zSql8 = 0;
-  char const *zTail8 = 0;
-  int rc;
-  sqlite3_value *pTmp;
-
-  if( sqlite3SafetyCheck(db) ){
-    return SQLITE_MISUSE;
-  }
-  pTmp = sqlite3GetTransientValue(db);
-  sqlite3ValueSetStr(pTmp, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);
-  zSql8 = sqlite3ValueText(pTmp, SQLITE_UTF8);
-  if( !zSql8 ){
-    sqlite3Error(db, SQLITE_NOMEM, 0);
-    return SQLITE_NOMEM;
-  }
-  rc = sqlite3_prepare(db, zSql8, -1, ppStmt, &zTail8);
-
-  if( zTail8 && pzTail ){
-    /* If sqlite3_prepare returns a tail pointer, we calculate the
-    ** equivalent pointer into the UTF-16 string by counting the unicode
-    ** characters between zSql8 and zTail8, and then returning a pointer
-    ** the same number of characters into the UTF-16 string.
-    */
-    int chars_parsed = sqlite3utf8CharLen(zSql8, zTail8-zSql8);
-    *pzTail = (u8 *)zSql + sqlite3utf16ByteLen(zSql, chars_parsed);
-  }
-  return rc;
-}
-#endif /* SQLITE_OMIT_UTF16 */
-
 /*
 ** This routine does the work of opening a database on behalf of
 ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"  
-** is UTF-8 encoded. The fourth argument, "def_enc" is one of the TEXT_*
-** macros from sqliteInt.h. If we end up creating a new database file
-** (not opening an existing one), the text encoding of the database
-** will be set to this value.
+** is UTF-8 encoded.
 */
 static int openDatabase(
   const char *zFilename, /* Database filename UTF-8 encoded */
@@ -1176,13 +719,17 @@ static int openDatabase(
     db->magic = SQLITE_MAGIC_CLOSED;
     goto opendb_out;
   }
-  db->aDb[0].zName = "main";
-  db->aDb[1].zName = "temp";
 
-  /* The default safety_level for the main database is 'full' for the temp
-  ** database it is 'NONE'. This matches the pager layer defaults.  */
+  /* The default safety_level for the main database is 'full'; for the temp
+  ** database it is 'NONE'. This matches the pager layer defaults.  
+  */
+  db->aDb[0].zName = "main";
   db->aDb[0].safety_level = 3;
+#ifndef SQLITE_OMIT_TEMPDB
+  db->aDb[1].zName = "temp";
   db->aDb[1].safety_level = 1;
+#endif
+
 
   /* Register all built-in functions, but do not attempt to read the
   ** database schema yet. This is delayed until the first time the database
@@ -1197,6 +744,14 @@ opendb_out:
     sqlite3Error(db, SQLITE_NOMEM, 0);
   }
   *ppDb = db;
+#ifndef SQLITE_OMIT_GLOBALRECOVER
+  if( db ){
+    sqlite3OsEnterMutex();
+    db->pNext = pDbList;
+    pDbList = db;
+    sqlite3OsLeaveMutex();
+  }
+#endif
   return sqlite3_errcode(db);
 }
 
@@ -1398,3 +953,51 @@ int sqlite3_collation_needed16(
   return SQLITE_OK;
 }
 #endif /* SQLITE_OMIT_UTF16 */
+
+#ifndef SQLITE_OMIT_GLOBALRECOVER
+/*
+** This function is called to recover from a malloc failure that occured
+** within SQLite. 
+**
+** This function is *not* threadsafe. Calling this from within a threaded
+** application when threads other than the caller have used SQLite is 
+** dangerous and will almost certainly result in malfunctions.
+*/
+int sqlite3_global_recover(){
+  int rc = SQLITE_OK;
+
+  if( sqlite3_malloc_failed ){
+    sqlite3 *db;
+    int i;
+    sqlite3_malloc_failed = 0;
+    for(db=pDbList; db; db=db->pNext ){
+      sqlite3ExpirePreparedStatements(db);
+      for(i=0; i<db->nDb; i++){
+        Btree *pBt = db->aDb[i].pBt;
+        if( pBt && (rc=sqlite3BtreeReset(pBt)) ){
+          goto recover_out;
+        }
+      } 
+      db->autoCommit = 1;
+    }
+  }
+
+recover_out:
+  if( rc!=SQLITE_OK ){
+    sqlite3_malloc_failed = 1;
+  }
+  return rc;
+}
+#endif
+
+/*
+** Test to see whether or not the database connection is in autocommit
+** mode.  Return TRUE if it is and FALSE if not.  Autocommit mode is on
+** by default.  Autocommit is disabled by a BEGIN statement and reenabled
+** by the next COMMIT or ROLLBACK.
+**
+******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
+*/
+int sqlite3_get_autocommit(sqlite3 *db){
+  return db->autoCommit;
+}
index 8be3dc7ea17439aabf992ca6604a0022abf0f964..9757cd8ac208772d58d4086ca273204decd7db78 100644 (file)
 /* Automatically generated.  Do not edit */
 /* See the mkopcodeh.awk script for details */
 #define OP_MemLoad                              1
-#define OP_HexBlob                            131   /* same as TK_BLOB     */
+#define OP_HexBlob                            129   /* same as TK_BLOB     */
 #define OP_Column                               2
 #define OP_SetCookie                            3
 #define OP_IfMemPos                             4
-#define OP_Real                               130   /* same as TK_FLOAT    */
+#define OP_Real                               128   /* same as TK_FLOAT    */
 #define OP_MoveGt                               5
-#define OP_Ge                                  77   /* same as TK_GE       */
+#define OP_Ge                                  75   /* same as TK_GE       */
 #define OP_AggFocus                             6
 #define OP_RowKey                               7
-#define OP_IdxRecno                             8
-#define OP_AggNext                              9
-#define OP_Eq                                  73   /* same as TK_EQ       */
-#define OP_OpenWrite                           10
-#define OP_NotNull                             71   /* same as TK_NOTNULL  */
-#define OP_If                                  11
-#define OP_PutStrKey                           12
-#define OP_String8                             92   /* same as TK_STRING   */
-#define OP_Pop                                 13
-#define OP_SortPut                             14
-#define OP_AggContextPush                      15
-#define OP_CollSeq                             16
-#define OP_OpenRead                            17
-#define OP_Expire                              18
-#define OP_SortReset                           19
-#define OP_AutoCommit                          20
-#define OP_Gt                                  74   /* same as TK_GT       */
-#define OP_Sort                                21
-#define OP_ListRewind                          22
-#define OP_IntegrityCk                         23
-#define OP_Function                            24
-#define OP_Subtract                            84   /* same as TK_MINUS    */
-#define OP_And                                 65   /* same as TK_AND      */
-#define OP_Noop                                25
-#define OP_Return                              26
-#define OP_Remainder                           87   /* same as TK_REM      */
-#define OP_Multiply                            85   /* same as TK_STAR     */
-#define OP_Variable                            27
-#define OP_String                              28
-#define OP_ParseSchema                         29
-#define OP_PutIntKey                           30
-#define OP_AggFunc                             31
-#define OP_Close                               32
-#define OP_ListWrite                           33
-#define OP_CreateIndex                         34
-#define OP_IsUnique                            35
-#define OP_IdxIsNull                           36
-#define OP_NotFound                            37
-#define OP_MustBeInt                           38
-#define OP_Halt                                39
-#define OP_IdxLT                               40
-#define OP_AddImm                              41
-#define OP_Statement                           42
-#define OP_RowData                             43
-#define OP_MemMax                              44
-#define OP_Push                                45
-#define OP_Or                                  64   /* same as TK_OR       */
-#define OP_KeyAsData                           46
-#define OP_NotExists                           47
-#define OP_OpenTemp                            48
-#define OP_MemIncr                             49
-#define OP_Gosub                               50
-#define OP_Divide                              86   /* same as TK_SLASH    */
-#define OP_AggSet                              51
-#define OP_Integer                             52
-#define OP_SortNext                            53
-#define OP_Prev                                54
-#define OP_Concat                              88   /* same as TK_CONCAT   */
-#define OP_BitAnd                              79   /* same as TK_BITAND   */
-#define OP_CreateTable                         55
-#define OP_Last                                56
-#define OP_IsNull                              70   /* same as TK_ISNULL   */
-#define OP_ShiftRight                          82   /* same as TK_RSHIFT   */
-#define OP_ResetCount                          57
-#define OP_Callback                            58
-#define OP_ContextPush                         59
-#define OP_DropTrigger                         60
-#define OP_DropIndex                           61
-#define OP_FullKey                             62
-#define OP_IdxGE                               63
-#define OP_IdxDelete                           67
-#define OP_Vacuum                              68
-#define OP_MoveLe                              69
-#define OP_IfNot                               78
-#define OP_DropTable                           90
-#define OP_MakeRecord                          93
-#define OP_Delete                              94
-#define OP_AggContextPop                       95
-#define OP_ListRead                            96
-#define OP_ListReset                           97
-#define OP_ShiftLeft                           81   /* same as TK_LSHIFT   */
-#define OP_Dup                                 98
-#define OP_Goto                                99
-#define OP_Clear                              100
-#define OP_IdxGT                              101
-#define OP_MoveLt                             102
-#define OP_Le                                  75   /* same as TK_LE       */
-#define OP_VerifyCookie                       103
-#define OP_Pull                               104
-#define OP_Not                                 66   /* same as TK_NOT      */
-#define OP_SetNumColumns                      105
-#define OP_AbsValue                           106
-#define OP_Transaction                        107
-#define OP_Negative                            89   /* same as TK_UMINUS   */
-#define OP_Ne                                  72   /* same as TK_NE       */
-#define OP_AggGet                             108
-#define OP_ContextPop                         109
-#define OP_BitOr                               80   /* same as TK_BITOR    */
-#define OP_Next                               110
-#define OP_AggInit                            111
-#define OP_Distinct                           112
-#define OP_NewRecno                           113
-#define OP_Lt                                  76   /* same as TK_LT       */
-#define OP_AggReset                           114
-#define OP_Destroy                            115
-#define OP_ReadCookie                         116
-#define OP_ForceInt                           117
-#define OP_Recno                              118
-#define OP_OpenPseudo                         119
-#define OP_Blob                               120
-#define OP_Add                                 83   /* same as TK_PLUS     */
-#define OP_MemStore                           121
-#define OP_Rewind                             122
-#define OP_MoveGe                             123
-#define OP_IdxPut                             124
-#define OP_BitNot                              91   /* same as TK_BITNOT   */
-#define OP_Found                              125
-#define OP_NullRow                            126
+#define OP_AggNext                              8
+#define OP_Eq                                  71   /* same as TK_EQ       */
+#define OP_OpenWrite                            9
+#define OP_NotNull                             69   /* same as TK_NOTNULL  */
+#define OP_If                                  10
+#define OP_String8                             90   /* same as TK_STRING   */
+#define OP_Pop                                 11
+#define OP_AggContextPush                      12
+#define OP_CollSeq                             13
+#define OP_OpenRead                            14
+#define OP_Expire                              15
+#define OP_SortReset                           16
+#define OP_AutoCommit                          17
+#define OP_Gt                                  72   /* same as TK_GT       */
+#define OP_Sort                                18
+#define OP_ListRewind                          19
+#define OP_IntegrityCk                         20
+#define OP_SortInsert                          21
+#define OP_Function                            22
+#define OP_And                                 63   /* same as TK_AND      */
+#define OP_Subtract                            82   /* same as TK_MINUS    */
+#define OP_Noop                                23
+#define OP_Return                              24
+#define OP_Remainder                           85   /* same as TK_REM      */
+#define OP_NewRowid                            25
+#define OP_Multiply                            83   /* same as TK_STAR     */
+#define OP_Variable                            26
+#define OP_String                              27
+#define OP_ParseSchema                         28
+#define OP_AggFunc                             29
+#define OP_Close                               30
+#define OP_ListWrite                           31
+#define OP_CreateIndex                         32
+#define OP_IsUnique                            33
+#define OP_IdxIsNull                           34
+#define OP_NotFound                            35
+#define OP_MustBeInt                           36
+#define OP_Halt                                37
+#define OP_Rowid                               38
+#define OP_IdxLT                               39
+#define OP_AddImm                              40
+#define OP_Statement                           41
+#define OP_RowData                             42
+#define OP_MemMax                              43
+#define OP_Push                                44
+#define OP_Or                                  62   /* same as TK_OR       */
+#define OP_NotExists                           45
+#define OP_OpenTemp                            46
+#define OP_MemIncr                             47
+#define OP_Gosub                               48
+#define OP_Divide                              84   /* same as TK_SLASH    */
+#define OP_AggSet                              49
+#define OP_Integer                             50
+#define OP_SortNext                            51
+#define OP_Prev                                52
+#define OP_Concat                              86   /* same as TK_CONCAT   */
+#define OP_BitAnd                              77   /* same as TK_BITAND   */
+#define OP_CreateTable                         53
+#define OP_Last                                54
+#define OP_IsNull                              68   /* same as TK_ISNULL   */
+#define OP_IdxRowid                            55
+#define OP_ShiftRight                          80   /* same as TK_RSHIFT   */
+#define OP_ResetCount                          56
+#define OP_Callback                            57
+#define OP_ContextPush                         58
+#define OP_DropTrigger                         59
+#define OP_DropIndex                           60
+#define OP_IdxGE                               61
+#define OP_IdxDelete                           65
+#define OP_Vacuum                              66
+#define OP_MoveLe                              67
+#define OP_IfNot                               76
+#define OP_DropTable                           88
+#define OP_MakeRecord                          91
+#define OP_Delete                              92
+#define OP_AggContextPop                       93
+#define OP_ListRead                            94
+#define OP_ListReset                           95
+#define OP_ShiftLeft                           79   /* same as TK_LSHIFT   */
+#define OP_Dup                                 96
+#define OP_Goto                                97
+#define OP_Clear                               98
+#define OP_IdxGT                               99
+#define OP_MoveLt                             100
+#define OP_Le                                  73   /* same as TK_LE       */
+#define OP_VerifyCookie                       101
+#define OP_Pull                               102
+#define OP_Not                                 64   /* same as TK_NOT      */
+#define OP_SetNumColumns                      103
+#define OP_AbsValue                           104
+#define OP_Transaction                        105
+#define OP_Negative                            87   /* same as TK_UMINUS   */
+#define OP_Ne                                  70   /* same as TK_NE       */
+#define OP_AggGet                             106
+#define OP_ContextPop                         107
+#define OP_BitOr                               78   /* same as TK_BITOR    */
+#define OP_Next                               108
+#define OP_AggInit                            109
+#define OP_IdxInsert                          110
+#define OP_Distinct                           111
+#define OP_Lt                                  74   /* same as TK_LT       */
+#define OP_AggReset                           112
+#define OP_Insert                             113
+#define OP_Destroy                            114
+#define OP_ReadCookie                         115
+#define OP_ForceInt                           116
+#define OP_OpenPseudo                         117
+#define OP_Null                               118
+#define OP_Blob                               119
+#define OP_Add                                 81   /* same as TK_PLUS     */
+#define OP_MemStore                           120
+#define OP_Rewind                             121
+#define OP_MoveGe                             122
+#define OP_BitNot                              89   /* same as TK_BITNOT   */
+#define OP_Found                              123
+#define OP_NullRow                            124
 
 /* The following opcode values are never used */
+#define OP_NotUsed_125                        125
+#define OP_NotUsed_126                        126
 #define OP_NotUsed_127                        127
-#define OP_NotUsed_128                        128
-#define OP_NotUsed_129                        129
+
+#define NOPUSH_MASK_0 65400
+#define NOPUSH_MASK_1 61871
+#define NOPUSH_MASK_2 64446
+#define NOPUSH_MASK_3 65363
+#define NOPUSH_MASK_4 65535
+#define NOPUSH_MASK_5 46015
+#define NOPUSH_MASK_6 64254
+#define NOPUSH_MASK_7 7987
+#define NOPUSH_MASK_8 0
+#define NOPUSH_MASK_9 0
index d39d62d80998a7e2a07e09b306ae4224a24e81f5..4854964fbef9819ff26689762eabb35276f4ae1c 100644 (file)
@@ -23,7 +23,8 @@
 ** N.B. MacOS means Mac Classic (or Carbon). Treat Darwin (OS X) as Unix.
 **      The MacOS build is designed to use CodeWarrior (tested with v8)
 */
-#if !defined(OS_UNIX) && !defined(OS_TEST)
+#if !defined(OS_UNIX) && !defined(OS_TEST) && !defined(OS_OTHER)
+# define OS_OTHER 0
 # ifndef OS_WIN
 #   if defined(_WIN32) || defined(WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
 #     define OS_WIN 1
 # include "os_win.h"
 #endif
 
+/* os_other.c and os_other.h are not delivered with SQLite.  These files
+** are place-holders that can be filled in by third-party developers to
+** implement backends to their on proprietary operating systems.
+*/
+#if OS_OTHER
+# include "os_other.h"
+#endif
+
+/* If the SET_FULLSYNC macro is not defined above, then make it
+** a no-op
+*/
+#ifndef SET_FULLSYNC
+# define SET_FULLSYNC(x,y)
+#endif
+
 /*
 ** Temporary files are named starting with this prefix followed by 16 random
 ** alphanumeric characters, and no file extension. They are stored in the
@@ -168,15 +184,19 @@ int sqlite3OsSeek(OsFile*, i64 offset);
 int sqlite3OsSync(OsFile*);
 int sqlite3OsTruncate(OsFile*, i64 size);
 int sqlite3OsFileSize(OsFile*, i64 *pSize);
+char *sqlite3OsFullPathname(const char*);
+int sqlite3OsLock(OsFile*, int);
+int sqlite3OsUnlock(OsFile*, int);
+int sqlite3OsCheckReservedLock(OsFile *id);
+
+
+/* The interface for file I/O is above.  Other miscellaneous functions
+** are below */
+
 int sqlite3OsRandomSeed(char*);
 int sqlite3OsSleep(int ms);
 int sqlite3OsCurrentTime(double*);
-int sqlite3OsFileModTime(OsFile*, double*);
 void sqlite3OsEnterMutex(void);
 void sqlite3OsLeaveMutex(void);
-char *sqlite3OsFullPathname(const char*);
-int sqlite3OsLock(OsFile*, int);
-int sqlite3OsUnlock(OsFile*, int);
-int sqlite3OsCheckReservedLock(OsFile *id);
 
 #endif /* _SQLITE_OS_H_ */
index 256eaaf17ac8cc6da153a17f14338c81c0a47ab6..dc0a04aae21234b1a8d14c2e2971246fe0e5a0cc 100644 (file)
@@ -19,6 +19,7 @@
 #include "os_unix.h"
 #undef OS_UNIX
 #undef OsFile
+#undef SET_FULLSYNC
 
 /* Include sqliteInt.h now to get the type u8. */
 #include "sqliteInt.h"
index 0e270c0bb6e71f3e474d3a28bac309ae00868a69..9c361a17170609c51f4d6f6ff8d2d351c33549dc 100644 (file)
 #include <time.h>
 #include <errno.h>
 #include <unistd.h>
+
+/*
+** Do not include any of the File I/O interface procedures if the
+** SQLITE_OMIT_DISKIO macro is defined (indicating that there database
+** will be in-memory only)
+*/
+#ifndef SQLITE_OMIT_DISKIO
+
+
+/*
+** Define various macros that are missing from some systems.
+*/
 #ifndef O_LARGEFILE
 # define O_LARGEFILE 0
 #endif
@@ -34,7 +46,6 @@
 # define O_BINARY 0
 #endif
 
-
 /*
 ** The DJGPP compiler environment looks mostly like Unix, but it
 ** lacks the fcntl() system call.  So redefine fcntl() to be something
@@ -432,7 +443,8 @@ int sqlite3OsOpenReadWrite(
   int rc;
   assert( !id->isOpen );
   id->dirfd = -1;
-  id->h = open(zFilename, O_RDWR|O_CREAT|O_LARGEFILE|O_BINARY, 0644);
+  id->h = open(zFilename, O_RDWR|O_CREAT|O_LARGEFILE|O_BINARY,
+                          SQLITE_DEFAULT_FILE_PERMISSIONS);
   if( id->h<0 ){
 #ifdef EISDIR
     if( errno==EISDIR ){
@@ -561,7 +573,7 @@ int sqlite3OsOpenDirectory(
     return SQLITE_CANTOPEN;
   }
   assert( id->dirfd<0 );
-  id->dirfd = open(zDirname, O_RDONLY|O_BINARY, 0644);
+  id->dirfd = open(zDirname, O_RDONLY|O_BINARY, 0);
   if( id->dirfd<0 ){
     return SQLITE_CANTOPEN; 
   }
@@ -644,7 +656,7 @@ int sqlite3OsRead(OsFile *id, void *pBuf, int amt){
   TIMER_START;
   got = read(id->h, pBuf, amt);
   TIMER_END;
-  TRACE4("READ    %-3d %7d %d\n", id->h, last_page, TIMER_ELAPSED);
+  TRACE5("READ    %-3d %5d %7d %d\n", id->h, got, last_page, TIMER_ELAPSED);
   SEEK(0);
   /* if( got<0 ) got = 0; */
   if( got==amt ){
@@ -670,7 +682,7 @@ int sqlite3OsWrite(OsFile *id, const void *pBuf, int amt){
     pBuf = &((char*)pBuf)[wrote];
   }
   TIMER_END;
-  TRACE4("WRITE   %-3d %7d %d\n", id->h, last_page, TIMER_ELAPSED);
+  TRACE5("WRITE   %-3d %5d %7d %d\n", id->h, wrote, last_page, TIMER_ELAPSED);
   SEEK(0);
   if( amt>0 ){
     return SQLITE_FULL;
@@ -688,6 +700,16 @@ int sqlite3OsSeek(OsFile *id, i64 offset){
   return SQLITE_OK;
 }
 
+#ifdef SQLITE_TEST
+/*
+** Count the number of fullsyncs and normal syncs.  This is used to test
+** that syncs and fullsyncs are occuring at the right times.
+*/
+int sqlite3_sync_count = 0;
+int sqlite3_fullsync_count = 0;
+#endif
+
+
 /*
 ** The fsync() system call does not work as advertised on many
 ** unix systems.  The following procedure is an attempt to make
@@ -699,19 +721,40 @@ int sqlite3OsSeek(OsFile *id, i64 offset){
 ** enabled, however, since with SQLITE_NO_SYNC enabled, an OS crash
 ** or power failure will likely corrupt the database file.
 */
-static int full_fsync(int fd){
+static int full_fsync(int fd, int fullSync){
+  int rc;
+
+  /* Record the number of times that we do a normal fsync() and 
+  ** FULLSYNC.  This is used during testing to verify that this procedure
+  ** gets called with the correct arguments.
+  */
+#ifdef SQLITE_TEST
+  if( fullSync ) sqlite3_fullsync_count++;
+  sqlite3_sync_count++;
+#endif
+
+  /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
+  ** no-op
+  */
 #ifdef SQLITE_NO_SYNC
-  return SQLITE_OK;
+  rc = SQLITE_OK;
 #else
-  int rc;
+
 #ifdef F_FULLFSYNC
-  rc = fcntl(fd, F_FULLFSYNC, 0);
+  if( fullSync ){
+    rc = fcntl(fd, F_FULLFSYNC, 0);
+  }else{
+    rc = 1;
+  }
+  /* If the FULLSYNC failed, try to do a normal fsync() */
   if( rc ) rc = fsync(fd);
+
 #else
   rc = fsync(fd);
-#endif
+#endif /* defined(F_FULLFSYNC) */
+#endif /* defined(SQLITE_NO_SYNC) */
+
   return rc;
-#endif
 }
 
 /*
@@ -729,12 +772,12 @@ int sqlite3OsSync(OsFile *id){
   assert( id->isOpen );
   SimulateIOError(SQLITE_IOERR);
   TRACE2("SYNC    %-3d\n", id->h);
-  if( full_fsync(id->h) ){
+  if( full_fsync(id->h, id->fullSync) ){
     return SQLITE_IOERR;
   }
   if( id->dirfd>=0 ){
     TRACE2("DIRSYNC %-3d\n", id->dirfd);
-    full_fsync(id->dirfd);
+    full_fsync(id->dirfd, id->fullSync);
     close(id->dirfd);  /* Only need to sync once, so close the directory */
     id->dirfd = -1;    /* when we are done. */
   }
@@ -744,12 +787,16 @@ int sqlite3OsSync(OsFile *id){
 /*
 ** Sync the directory zDirname. This is a no-op on operating systems other
 ** than UNIX.
+**
+** This is used to make sure the master journal file has truely been deleted
+** before making changes to individual journals on a multi-database commit.
+** The F_FULLFSYNC option is not needed here.
 */
 int sqlite3OsSyncDirectory(const char *zDirname){
   int fd;
   int r;
   SimulateIOError(SQLITE_IOERR);
-  fd = open(zDirname, O_RDONLY|O_BINARY, 0644);
+  fd = open(zDirname, O_RDONLY|O_BINARY, 0);
   TRACE3("DIRSYNC %-3d (%s)\n", fd, zDirname);
   if( fd<0 ){
     return SQLITE_CANTOPEN; 
@@ -906,7 +953,7 @@ int sqlite3OsLock(OsFile *id, int locktype){
   int s;
 
   assert( id->isOpen );
-  TRACE7("LOCK %d %s was %s(%s,%d) pid=%d\n", id->h, locktypeName(locktype), 
+  TRACE7("LOCK    %d %s was %s(%s,%d) pid=%d\n", id->h, locktypeName(locktype), 
       locktypeName(id->locktype), locktypeName(pLock->locktype), pLock->cnt
       ,getpid() );
 
@@ -915,7 +962,7 @@ int sqlite3OsLock(OsFile *id, int locktype){
   ** sqlite3OsEnterMutex() hasn't been called yet.
   */
   if( id->locktype>=locktype ){
-    TRACE3("LOCK %d %s ok (already held)\n", id->h, locktypeName(locktype));
+    TRACE3("LOCK    %d %s ok (already held)\n", id->h, locktypeName(locktype));
     return SQLITE_OK;
   }
 
@@ -1036,7 +1083,7 @@ int sqlite3OsLock(OsFile *id, int locktype){
 
 end_lock:
   sqlite3OsLeaveMutex();
-  TRACE4("LOCK %d %s %s\n", id->h, locktypeName(locktype), 
+  TRACE4("LOCK    %d %s %s\n", id->h, locktypeName(locktype), 
       rc==SQLITE_OK ? "ok" : "failed");
   return rc;
 }
@@ -1058,7 +1105,7 @@ int sqlite3OsUnlock(OsFile *id, int locktype){
   int rc = SQLITE_OK;
 
   assert( id->isOpen );
-  TRACE7("UNLOCK %d %d was %d(%d,%d) pid=%d\n", id->h, locktype, id->locktype, 
+  TRACE7("UNLOCK  %d %d was %d(%d,%d) pid=%d\n", id->h, locktype, id->locktype, 
       id->pLock->locktype, id->pLock->cnt, getpid());
 
   assert( locktype<=SHARED_LOCK );
@@ -1163,6 +1210,33 @@ int sqlite3OsClose(OsFile *id){
   return SQLITE_OK;
 }
 
+/*
+** Turn a relative pathname into a full pathname.  Return a pointer
+** to the full pathname stored in space obtained from sqliteMalloc().
+** The calling function is responsible for freeing this space once it
+** is no longer needed.
+*/
+char *sqlite3OsFullPathname(const char *zRelative){
+  char *zFull = 0;
+  if( zRelative[0]=='/' ){
+    sqlite3SetString(&zFull, zRelative, (char*)0);
+  }else{
+    char zBuf[5000];
+    zBuf[0] = 0;
+    sqlite3SetString(&zFull, getcwd(zBuf, sizeof(zBuf)), "/", zRelative,
+                    (char*)0);
+  }
+  return zFull;
+}
+
+
+#endif /* SQLITE_OMIT_DISKIO */
+/***************************************************************************
+** Everything above deals with file I/O.  Everything that follows deals
+** with other miscellanous aspects of the operating system interface
+****************************************************************************/
+
+
 /*
 ** Get information to seed the random number generator.  The seed
 ** is written into the buffer zBuf[256].  The calling function must
@@ -1243,24 +1317,6 @@ void sqlite3OsLeaveMutex(){
 #endif
 }
 
-/*
-** Turn a relative pathname into a full pathname.  Return a pointer
-** to the full pathname stored in space obtained from sqliteMalloc().
-** The calling function is responsible for freeing this space once it
-** is no longer needed.
-*/
-char *sqlite3OsFullPathname(const char *zRelative){
-  char *zFull = 0;
-  if( zRelative[0]=='/' ){
-    sqlite3SetString(&zFull, zRelative, (char*)0);
-  }else{
-    char zBuf[5000];
-    sqlite3SetString(&zFull, getcwd(zBuf, sizeof(zBuf)), "/", zRelative,
-                    (char*)0);
-  }
-  return zFull;
-}
-
 /*
 ** The following variable, if set to a non-zero value, becomes the result
 ** returned from sqlite3OsCurrentTime().  This is used for testing.
@@ -1286,24 +1342,4 @@ int sqlite3OsCurrentTime(double *prNow){
   return 0;
 }
 
-#if 0 /* NOT USED */
-/*
-** Find the time that the file was last modified.  Write the
-** modification time and date as a Julian Day number into *prNow and
-** return SQLITE_OK.  Return SQLITE_ERROR if the modification
-** time cannot be found.
-*/
-int sqlite3OsFileModTime(OsFile *id, double *prNow){
-  int rc;
-  struct stat statbuf;
-  if( fstat(id->h, &statbuf)==0 ){
-    *prNow = statbuf.st_mtime/86400.0 + 2440587.5;
-    rc = SQLITE_OK;
-  }else{
-    rc = SQLITE_ERROR;
-  }
-  return rc;
-}
-#endif /* NOT USED */
-
 #endif /* OS_UNIX */
index 72f818befeec1165a4254ae7ddd410649c22701d..4ea0aee362d6cc395889cd0b1e7a6944fdae675b 100644 (file)
@@ -68,9 +68,15 @@ struct OsFile {
   int h;                    /* The file descriptor */
   unsigned char locktype;   /* The type of lock held on this fd */
   unsigned char isOpen;     /* True if needs to be closed */
+  unsigned char fullSync;   /* Use F_FULLSYNC if available */
   int dirfd;                /* File descriptor for the directory */
 };
 
+/*
+** A macro to set the OsFile.fullSync flag, if it exists.
+*/
+#define SET_FULLSYNC(x,y)  ((x).fullSync = (y))
+
 /*
 ** Maximum number of characters in a temporary file name
 */
@@ -85,5 +91,12 @@ struct OsFile {
 # define SQLITE_MIN_SLEEP_MS 1000
 #endif
 
+/*
+** Default permissions when creating a new file
+*/
+#ifndef SQLITE_DEFAULT_FILE_PERMISSIONS
+# define SQLITE_DEFAULT_FILE_PERMISSIONS 0644
+#endif
+
 
 #endif /* _SQLITE_OS_UNIX_H_ */
index 2614ed08a6c31624ea037d88cbda5dbb7f0f97f6..ea2ca26089cd5930563a0b853826a69a04bdd6c5 100644 (file)
 
 #include <winbase.h>
 
+#ifdef __CYGWIN__
+# include <sys/cygwin.h>
+#endif
+
 /*
 ** Macros used to determine whether or not to use threads.
 */
 */
 #include "os_common.h"
 
+/*
+** Do not include any of the File I/O interface procedures if the
+** SQLITE_OMIT_DISKIO macro is defined (indicating that there database
+** will be in-memory only)
+*/
+#ifndef SQLITE_OMIT_DISKIO
+
 /*
 ** Delete the named file
 */
@@ -621,6 +632,36 @@ int sqlite3OsUnlock(OsFile *id, int locktype){
   return rc;
 }
 
+/*
+** Turn a relative pathname into a full pathname.  Return a pointer
+** to the full pathname stored in space obtained from sqliteMalloc().
+** The calling function is responsible for freeing this space once it
+** is no longer needed.
+*/
+char *sqlite3OsFullPathname(const char *zRelative){
+  char *zNotUsed;
+  char *zFull;
+  int nByte;
+#ifdef __CYGWIN__
+  nByte = strlen(zRelative) + MAX_PATH + 1001;
+  zFull = sqliteMalloc( nByte );
+  if( zFull==0 ) return 0;
+  if( cygwin_conv_to_full_win32_path(zRelative, zFull) ) return 0;
+#else
+  nByte = GetFullPathNameA(zRelative, 0, 0, &zNotUsed) + 1;
+  zFull = sqliteMalloc( nByte );
+  if( zFull==0 ) return 0;
+  GetFullPathNameA(zRelative, nByte, zFull, &zNotUsed);
+#endif
+  return zFull;
+}
+
+#endif /* SQLITE_OMIT_DISKIO */
+/***************************************************************************
+** Everything above deals with file I/O.  Everything that follows deals
+** with other miscellanous aspects of the operating system interface
+****************************************************************************/
+
 /*
 ** Get information to seed the random number generator.  The seed
 ** is written into the buffer zBuf[256].  The calling function must
@@ -693,23 +734,6 @@ void sqlite3OsLeaveMutex(){
 #endif
 }
 
-/*
-** Turn a relative pathname into a full pathname.  Return a pointer
-** to the full pathname stored in space obtained from sqliteMalloc().
-** The calling function is responsible for freeing this space once it
-** is no longer needed.
-*/
-char *sqlite3OsFullPathname(const char *zRelative){
-  char *zNotUsed;
-  char *zFull;
-  int nByte;
-  nByte = GetFullPathNameA(zRelative, 0, 0, &zNotUsed) + 1;
-  zFull = sqliteMalloc( nByte );
-  if( zFull==0 ) return 0;
-  GetFullPathNameA(zRelative, nByte, zFull, &zNotUsed);
-  return zFull;
-}
-
 /*
 ** The following variable, if set to a non-zero value, becomes the result
 ** returned from sqlite3OsCurrentTime().  This is used for testing.
@@ -740,27 +764,4 @@ int sqlite3OsCurrentTime(double *prNow){
   return 0;
 }
 
-/*
-** Find the time that the file was last modified.  Write the
-** modification time and date as a Julian Day number into *prNow and
-** return SQLITE_OK.  Return SQLITE_ERROR if the modification
-** time cannot be found.
-*/
-int sqlite3OsFileModTime(OsFile *id, double *prMTime){
-  int rc;
-  FILETIME ft;
-  /* FILETIME structure is a 64-bit value representing the number of 
-  ** 100-nanosecond intervals since January 1, 1601 (= JD 2305813.5). 
-  */
-  if( GetFileTime(id->h, 0, 0, &ft) ){
-    double t;
-    t = ((double)ft.dwHighDateTime) * 4294967296.0; 
-    *prMTime = (t + ft.dwLowDateTime)/864000000000.0 + 2305813.5;
-    rc = SQLITE_OK;
-  }else{
-    rc = SQLITE_ERROR;
-  }
-  return rc;
-}
-
 #endif /* OS_WIN */
index 47d895240c5fbede7256df52eb1ee0ef92d99cfd..892757406f95fe00935bfa27f5233807c96f07c0 100644 (file)
@@ -20,6 +20,7 @@
 **
 ** @(#) $Id$
 */
+#ifndef SQLITE_OMIT_DISKIO
 #include "sqliteInt.h"
 #include "os.h"
 #include "pager.h"
@@ -171,7 +172,7 @@ struct PgHdr {
 #ifdef SQLITE_CHECK_PAGES
   u32 pageHash;
 #endif
-  /* pPager->psAligned bytes of page data follow this header */
+  /* pPager->pageSize bytes of page data follow this header */
   /* Pager.nExtra bytes of local data follow the page data */
 };
 
@@ -207,15 +208,22 @@ struct PgHistory {
 */
 #define PGHDR_TO_DATA(P)  ((void*)(&(P)[1]))
 #define DATA_TO_PGHDR(D)  (&((PgHdr*)(D))[-1])
-#define PGHDR_TO_EXTRA(G,P) ((void*)&((char*)(&(G)[1]))[(P)->psAligned])
+#define PGHDR_TO_EXTRA(G,P) ((void*)&((char*)(&(G)[1]))[(P)->pageSize])
 #define PGHDR_TO_HIST(P,PGR)  \
-            ((PgHistory*)&((char*)(&(P)[1]))[(PGR)->psAligned+(PGR)->nExtra])
+            ((PgHistory*)&((char*)(&(P)[1]))[(PGR)->pageSize+(PGR)->nExtra])
 
 /*
 ** How big to make the hash table used for locating in-memory pages
-** by page number.
+** by page number. This macro looks a little silly, but is evaluated
+** at compile-time, not run-time (at least for gcc this is true).
 */
-#define N_PG_HASH 2048
+#define N_PG_HASH (\
+  (MAX_PAGES>1024)?2048: \
+  (MAX_PAGES>512)?1024: \
+  (MAX_PAGES>256)?512: \
+  (MAX_PAGES>128)?256: \
+  (MAX_PAGES>64)?128:64 \
+)
 
 /*
 ** Hash a page number
@@ -226,30 +234,6 @@ struct PgHistory {
 ** A open page cache is an instance of the following structure.
 */
 struct Pager {
-  char *zFilename;            /* Name of the database file */
-  char *zJournal;             /* Name of the journal file */
-  char *zDirectory;           /* Directory hold database and journal files */
-  OsFile fd, jfd;             /* File descriptors for database and journal */
-  OsFile stfd;                /* File descriptor for the statement subjournal*/
-  int dbSize;                 /* Number of pages in the file */
-  int origDbSize;             /* dbSize before the current change */
-  int stmtSize;               /* Size of database (in pages) at stmt_begin() */
-  i64 stmtJSize;              /* Size of journal at stmt_begin() */
-  int nRec;                   /* Number of pages written to the journal */
-  u32 cksumInit;              /* Quasi-random value added to every checksum */
-  int stmtNRec;               /* Number of records in stmt subjournal */
-  int nExtra;                 /* Add this many bytes to each in-memory page */
-  void (*xDestructor)(void*,int); /* Call this routine when freeing pages */
-  void (*xReiniter)(void*,int);   /* Call this routine when reloading pages */
-  int pageSize;               /* Number of bytes in a page */
-  int psAligned;              /* pageSize rounded up to a multiple of 8 */
-  int nPage;                  /* Total number of in-memory pages */
-  int nRef;                   /* Number of in-memory pages with PgHdr.nRef>0 */
-  int mxPage;                 /* Maximum number of pages to hold in cache */
-  int nHit, nMiss, nOvfl;     /* Cache hits, missing, and LRU overflows */
-  int nRead,nWrite;           /* Database pages read/written */
-  void (*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */
-  void *pCodecArg;            /* First argument to xCodec() */
   u8 journalOpen;             /* True if journal file descriptors is valid */
   u8 journalStarted;          /* True if header of journal is synced */
   u8 useJournal;              /* Use a rollback journal on this file */
@@ -267,9 +251,26 @@ struct Pager {
   u8 dirtyCache;              /* True if cached pages have changed */
   u8 alwaysRollback;          /* Disable dont_rollback() for all pages */
   u8 memDb;                   /* True to inhibit all file I/O */
+  u8 setMaster;               /* True if a m-j name has been written to jrnl */
+  int dbSize;                 /* Number of pages in the file */
+  int origDbSize;             /* dbSize before the current change */
+  int stmtSize;               /* Size of database (in pages) at stmt_begin() */
+  int nRec;                   /* Number of pages written to the journal */
+  u32 cksumInit;              /* Quasi-random value added to every checksum */
+  int stmtNRec;               /* Number of records in stmt subjournal */
+  int nExtra;                 /* Add this many bytes to each in-memory page */
+  int pageSize;               /* Number of bytes in a page */
+  int nPage;                  /* Total number of in-memory pages */
+  int nMaxPage;               /* High water mark of nPage */
+  int nRef;                   /* Number of in-memory pages with PgHdr.nRef>0 */
+  int mxPage;                 /* Maximum number of pages to hold in cache */
   u8 *aInJournal;             /* One bit for each page in the database file */
   u8 *aInStmt;                /* One bit for each page in the database */
-  u8 setMaster;               /* True if a m-j name has been written to jrnl */
+  char *zFilename;            /* Name of the database file */
+  char *zJournal;             /* Name of the journal file */
+  char *zDirectory;           /* Directory hold database and journal files */
+  OsFile fd, jfd;             /* File descriptors for database and journal */
+  OsFile stfd;                /* File descriptor for the statement subjournal*/
   BusyHandler *pBusyHandler;  /* Pointer to sqlite.busyHandler */
   PgHdr *pFirst, *pLast;      /* List of free pages */
   PgHdr *pFirstSynced;        /* First free page with PgHdr.needSync==0 */
@@ -279,10 +280,29 @@ struct Pager {
   i64 journalHdr;             /* Byte offset to previous journal header */
   i64 stmtHdrOff;             /* First journal header written this statement */
   i64 stmtCksum;              /* cksumInit when statement was started */
+  i64 stmtJSize;              /* Size of journal at stmt_begin() */
   int sectorSize;             /* Assumed sector size during rollback */
+#ifdef SQLITE_TEST
+  int nHit, nMiss, nOvfl;     /* Cache hits, missing, and LRU overflows */
+  int nRead,nWrite;           /* Database pages read/written */
+#endif
+  void (*xDestructor)(void*,int); /* Call this routine when freeing pages */
+  void (*xReiniter)(void*,int);   /* Call this routine when reloading pages */
+  void (*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */
+  void *pCodecArg;            /* First argument to xCodec() */
   PgHdr *aHash[N_PG_HASH];    /* Hash table to map page number to PgHdr */
 };
 
+/*
+** If SQLITE_TEST is defined then increment the variable given in
+** the argument
+*/
+#ifdef SQLITE_TEST
+# define TEST_INCR(x)  x++
+#else
+# define TEST_INCR(x)
+#endif
+
 /*
 ** These are bits that can be set in Pager.errMask.
 */
@@ -822,6 +842,7 @@ static PgHdr *pager_lookup(Pager *pPager, Pgno pgno){
 */
 static void pager_reset(Pager *pPager){
   PgHdr *pPg, *pNext;
+  if( pPager->errMask ) return;
   for(pPg=pPager->pAll; pPg; pPg=pNext){
     pNext = pPg->pNextAll;
     sqliteFree(pPg);
@@ -842,6 +863,29 @@ static void pager_reset(Pager *pPager){
   assert( pPager->journalOpen==0 );
 }
 
+/*
+** This function is used to reset the pager after a malloc() failure. This
+** doesn't work with in-memory databases. If a malloc() fails when an 
+** in-memory database is in use it is not possible to recover.
+**
+** If a transaction or statement transaction is active, it is rolled back.
+**
+** It is an error to call this function if any pages are in use.
+*/
+#ifndef SQLITE_OMIT_GLOBALRECOVER
+int sqlite3pager_reset(Pager *pPager){
+  if( pPager ){
+    if( pPager->nRef || MEMDB ){
+      return SQLITE_ERROR;
+    }
+    pPager->errMask &= ~(PAGER_ERR_MEM);
+    pager_reset(pPager);
+  }
+  return SQLITE_OK;
+}
+#endif
+
+
 /*
 ** When this routine is called, the pager has the journal file open and
 ** a RESERVED or EXCLUSIVE lock on the database.  This routine releases
@@ -881,6 +925,7 @@ static int pager_unwritelock(Pager *pPager){
     pPager->dirtyCache = 0;
     pPager->nRec = 0;
   }else{
+    assert( pPager->aInJournal==0 );
     assert( pPager->dirtyCache==0 || pPager->useJournal==0 );
   }
   rc = sqlite3OsUnlock(&pPager->fd, SHARED_LOCK);
@@ -935,6 +980,12 @@ static int pager_playback_one_page(Pager *pPager, OsFile *jfd, int useCksum){
   u32 cksum;                    /* Checksum used for sanity checking */
   u8 aData[SQLITE_MAX_PAGE_SIZE];  /* Temp storage for a page */
 
+  /* useCksum should be true for the main journal and false for
+  ** statement journals.  Verify that this is always the case
+  */
+  assert( jfd == (useCksum ? &pPager->jfd : &pPager->stfd) );
+
+
   rc = read32bits(jfd, &pgno);
   if( rc!=SQLITE_OK ) return rc;
   rc = sqlite3OsRead(jfd, &aData, pPager->pageSize);
@@ -969,13 +1020,27 @@ static int pager_playback_one_page(Pager *pPager, OsFile *jfd, int useCksum){
   **
   ** If in EXCLUSIVE state, then we update the pager cache if it exists
   ** and the main file. The page is then marked not dirty.
+  **
+  ** Ticket #1171:  The statement journal might contain page content that is
+  ** different from the page content at the start of the transaction.
+  ** This occurs when a page is changed prior to the start of a statement
+  ** then changed again within the statement.  When rolling back such a
+  ** statement we must not write to the original database unless we know
+  ** for certain that original page contents are in the main rollback
+  ** journal.  Otherwise, if a full ROLLBACK occurs after the statement
+  ** rollback the full ROLLBACK will not restore the page to its original
+  ** content.  Two conditions must be met before writing to the database
+  ** files. (1) the database must be locked.  (2) we know that the original
+  ** page content is in the main journal either because the page is not in
+  ** cache or else it is marked as needSync==0.
   */
   pPg = pager_lookup(pPager, pgno);
-  assert( pPager->state>=PAGER_EXCLUSIVE || pPg );
+  assert( pPager->state>=PAGER_EXCLUSIVE || pPg!=0 );
   TRACE3("PLAYBACK %d page %d\n", PAGERID(pPager), pgno);
-  if( pPager->state>=PAGER_EXCLUSIVE ){
+  if( pPager->state>=PAGER_EXCLUSIVE && (pPg==0 || pPg->needSync==0) ){
     sqlite3OsSeek(&pPager->fd, (pgno-1)*(i64)pPager->pageSize);
     rc = sqlite3OsWrite(&pPager->fd, aData, pPager->pageSize);
+    if( pPg ) pPg->dirty = 0;
   }
   if( pPg ){
     /* No page should ever be explicitly rolled back that is in use, except
@@ -991,13 +1056,9 @@ static int pager_playback_one_page(Pager *pPager, OsFile *jfd, int useCksum){
     if( pPager->xDestructor ){  /*** FIX ME:  Should this be xReinit? ***/
       pPager->xDestructor(pData, pPager->pageSize);
     }
-    if( pPager->state>=PAGER_EXCLUSIVE ){
-      pPg->dirty = 0;
-      pPg->needSync = 0;
 #ifdef SQLITE_CHECK_PAGES
-      pPg->pageHash = pager_pagehash(pPg);
+    pPg->pageHash = pager_pagehash(pPg);
 #endif
-    }
     CODEC(pPager, pData, pPg->pgno, 3);
   }
   return rc;
@@ -1434,22 +1495,8 @@ end_stmt_playback:
 
 /*
 ** Change the maximum number of in-memory pages that are allowed.
-**
-** The maximum number is the absolute value of the mxPage parameter.
-** If mxPage is negative, the noSync flag is also set.  noSync bypasses
-** calls to sqlite3OsSync().  The pager runs much faster with noSync on,
-** but if the operating system crashes or there is an abrupt power 
-** failure, the database file might be left in an inconsistent and
-** unrepairable state.  
 */
 void sqlite3pager_set_cachesize(Pager *pPager, int mxPage){
-  if( mxPage>=0 ){
-    pPager->noSync = pPager->tempFile;
-    if( pPager->noSync ) pPager->needSync = 0; 
-  }else{
-    pPager->noSync = 1;
-    mxPage = -mxPage;
-  }
   if( mxPage>10 ){
     pPager->mxPage = mxPage;
   }else{
@@ -1492,8 +1539,15 @@ void sqlite3pager_set_safety_level(Pager *pPager, int level){
 #endif
 
 /*
-** Open a temporary file.  Write the name of the file into zName
-** (zName must be at least SQLITE_TEMPNAME_SIZE bytes long.)  Write
+** The following global variable is incremented whenever the library
+** attempts to open a temporary file.  This information is used for
+** testing and analysis only.  
+*/
+int sqlite3_opentemp_count = 0;
+
+/*
+** Open a temporary file.  Write the name of the file into zFile
+** (zFile must be at least SQLITE_TEMPNAME_SIZE bytes long.)  Write
 ** the file descriptor into *fd.  Return SQLITE_OK on success or some
 ** other error code if we fail.
 **
@@ -1503,6 +1557,7 @@ void sqlite3pager_set_safety_level(Pager *pPager, int level){
 static int sqlite3pager_opentemp(char *zFile, OsFile *fd){
   int cnt = 8;
   int rc;
+  sqlite3_opentemp_count++;  /* Used for testing and analysis only */
   do{
     cnt--;
     sqlite3OsTempFileName(zFile);
@@ -1610,10 +1665,10 @@ int sqlite3pager_open(
   pPager->nRef = 0;
   pPager->dbSize = memDb-1;
   pPager->pageSize = SQLITE_DEFAULT_PAGE_SIZE;
-  pPager->psAligned = FORCE_ALIGNMENT(pPager->pageSize);
   pPager->stmtSize = 0;
   pPager->stmtJSize = 0;
   pPager->nPage = 0;
+  pPager->nMaxPage = 0;
   pPager->mxPage = 100;
   pPager->state = PAGER_UNLOCK;
   pPager->errMask = 0;
@@ -1665,14 +1720,16 @@ void sqlite3pager_set_reiniter(Pager *pPager, void (*xReinit)(void*,int)){
 }
 
 /*
-** Set the page size.
-**
-** The page size must only be changed when the cache is empty.
+** Set the page size.  Return the new size.  If the suggest new page
+** size is inappropriate, then an alternative page size is selected
+** and returned.
 */
-void sqlite3pager_set_pagesize(Pager *pPager, int pageSize){
+int sqlite3pager_set_pagesize(Pager *pPager, int pageSize){
   assert( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE );
-  pPager->pageSize = pageSize;
-  pPager->psAligned = FORCE_ALIGNMENT(pageSize);
+  if( !pPager->memDb ){
+    pPager->pageSize = pageSize;
+  }
+  return pPager->pageSize;
 }
 
 /*
@@ -1824,12 +1881,12 @@ static int pager_wait_on_lock(Pager *pPager, int locktype){
     rc = SQLITE_OK;
   }else{
     int busy = 1;
+    BusyHandler *pH;
     do {
       rc = sqlite3OsLock(&pPager->fd, locktype);
     }while( rc==SQLITE_BUSY && 
-        pPager->pBusyHandler && 
-        pPager->pBusyHandler->xFunc && 
-        pPager->pBusyHandler->xFunc(pPager->pBusyHandler->pArg, busy++)
+        (pH = pPager->pBusyHandler)!=0 && 
+        pH->xFunc && pH->xFunc(pH->pArg, busy++)
     );
     if( rc==SQLITE_OK ){
       pPager->state = locktype;
@@ -1905,7 +1962,7 @@ int sqlite3pager_close(Pager *pPager){
       if( !MEMDB ){
         sqlite3OsUnlock(&pPager->fd, NO_LOCK);
       }
-      assert( pPager->journalOpen==0 );
+      assert( pPager->errMask || pPager->journalOpen==0 );
       break;
     }
     case PAGER_SHARED: {
@@ -1932,8 +1989,15 @@ int sqlite3pager_close(Pager *pPager){
     sqliteFree(pPg);
   }
   TRACE2("CLOSE %d\n", PAGERID(pPager));
+  assert( pPager->errMask || (pPager->journalOpen==0 && pPager->stmtOpen==0) );
+  if( pPager->journalOpen ){
+    sqlite3OsClose(&pPager->jfd);
+  }
+  sqliteFree(pPager->aInJournal);
+  if( pPager->stmtOpen ){
+    sqlite3OsClose(&pPager->stfd);
+  }
   sqlite3OsClose(&pPager->fd);
-  assert( pPager->journalOpen==0 );
   /* Temp files are automatically deleted by the OS
   ** if( pPager->tempFile ){
   **   sqlite3OsDelete(pPager->zFilename);
@@ -2144,7 +2208,7 @@ static int pager_write_pagelist(PgHdr *pList){
       TRACE3("STORE %d page %d\n", PAGERID(pPager), pList->pgno);
       rc = sqlite3OsWrite(&pPager->fd, PGHDR_TO_DATA(pList), pPager->pageSize);
       CODEC(pPager, PGHDR_TO_DATA(pList), pList->pgno, 0);
-      pPager->nWrite++;
+      TEST_INCR(pPager->nWrite);
     }
 #ifndef NDEBUG
     else{
@@ -2178,6 +2242,26 @@ static PgHdr *pager_get_all_dirty_pages(Pager *pPager){
   return pList;
 }
 
+/*
+** Return TRUE if there is a hot journal on the given pager.
+** A hot journal is one that needs to be played back.
+**
+** If the current size of the database file is 0 but a journal file
+** exists, that is probably an old journal left over from a prior
+** database with the same name.  Just delete the journal.
+*/
+static int hasHotJournal(Pager *pPager){
+  if( !pPager->useJournal ) return 0;
+  if( !sqlite3OsFileExists(pPager->zJournal) ) return 0;
+  if( sqlite3OsCheckReservedLock(&pPager->fd) ) return 0;
+  if( sqlite3pager_pagecount(pPager)==0 ){
+    sqlite3OsDelete(pPager->zJournal);
+    return 0;
+  }else{
+    return 1;
+  }
+}
+
 /*
 ** Acquire a page.
 **
@@ -2203,7 +2287,7 @@ static PgHdr *pager_get_all_dirty_pages(Pager *pPager){
 */
 int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
   PgHdr *pPg;
-  int rc, n;
+  int rc;
 
   /* The maximum page number is 2^31. Return SQLITE_CORRUPT if a page
   ** number greater than this, or zero, is requested.
@@ -2234,10 +2318,7 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
     /* If a journal file exists, and there is no RESERVED lock on the
     ** database file, then it either needs to be played back or deleted.
     */
-    if( pPager->useJournal && 
-        sqlite3OsFileExists(pPager->zJournal) &&
-        !sqlite3OsCheckReservedLock(&pPager->fd) 
-    ){
+    if( hasHotJournal(pPager) ){
        int rc;
 
        /* Get an EXCLUSIVE lock on the database file. At this point it is
@@ -2298,16 +2379,13 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
   if( pPg==0 ){
     /* The requested page is not in the page cache. */
     int h;
-    pPager->nMiss++;
+    TEST_INCR(pPager->nMiss);
     if( pPager->nPage<pPager->mxPage || pPager->pFirst==0 || MEMDB ){
       /* Create a new page */
-      pPg = sqliteMallocRaw( sizeof(*pPg) + pPager->psAligned
+      pPg = sqliteMallocRaw( sizeof(*pPg) + pPager->pageSize
                               + sizeof(u32) + pPager->nExtra
                               + MEMDB*sizeof(PgHistory) );
       if( pPg==0 ){
-        if( !MEMDB ){
-          pager_unwritelock(pPager);
-        }
         pPager->errMask |= PAGER_ERR_MEM;
         return SQLITE_NOMEM;
       }
@@ -2319,6 +2397,10 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
       pPg->pNextAll = pPager->pAll;
       pPager->pAll = pPg;
       pPager->nPage++;
+      if( pPager->nPage>pPager->nMaxPage ){
+        assert( pPager->nMaxPage==(pPager->nPage-1) );
+        pPager->nMaxPage++;
+      }
     }else{
       /* Find a page to recycle.  Try to locate a page that does not
       ** require us to do an fsync() on the journal.
@@ -2383,7 +2465,7 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
       /* Unlink the old page from the free list and the hash table
       */
       unlinkPage(pPg);
-      pPager->nOvfl++;
+      TEST_INCR(pPager->nOvfl);
     }
     pPg->pgno = pgno;
     if( pPager->aInJournal && (int)pgno<=pPager->origDbSize ){
@@ -2415,13 +2497,12 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
     if( pPager->nExtra>0 ){
       memset(PGHDR_TO_EXTRA(pPg, pPager), 0, pPager->nExtra);
     }
-    n = sqlite3pager_pagecount(pPager);
     if( pPager->errMask!=0 ){
       sqlite3pager_unref(PGHDR_TO_DATA(pPg));
       rc = pager_errcode(pPager);
       return rc;
     }
-    if( n<(int)pgno ){
+    if( sqlite3pager_pagecount(pPager)<(int)pgno ){
       memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize);
     }else{
       int rc;
@@ -2440,7 +2521,7 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
           memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize);
         }
       }else{
-        pPager->nRead++;
+        TEST_INCR(pPager->nRead);
       }
     }
 #ifdef SQLITE_CHECK_PAGES
@@ -2448,7 +2529,7 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){
 #endif
   }else{
     /* The requested page is in the page cache. */
-    pPager->nHit++;
+    TEST_INCR(pPager->nHit);
     page_ref(pPg);
   }
   *ppPage = PGHDR_TO_DATA(pPg);
@@ -2546,6 +2627,7 @@ static int pager_open_journal(Pager *pPager){
   assert( pPager->state>=PAGER_RESERVED );
   assert( pPager->journalOpen==0 );
   assert( pPager->useJournal );
+  assert( pPager->aInJournal==0 );
   sqlite3pager_pagecount(pPager);
   pPager->aInJournal = sqliteMalloc( pPager->dbSize/8 + 1 );
   if( pPager->aInJournal==0 ){
@@ -2559,6 +2641,8 @@ static int pager_open_journal(Pager *pPager){
   if( rc!=SQLITE_OK ){
     goto failed_to_open_journal;
   }
+  SET_FULLSYNC(pPager->jfd, pPager->fullSync);
+  SET_FULLSYNC(pPager->fd, pPager->fullSync);
   sqlite3OsOpenDirectory(pPager->zDirectory, &pPager->jfd);
   pPager->journalOpen = 1;
   pPager->journalStarted = 0;
@@ -2567,7 +2651,7 @@ static int pager_open_journal(Pager *pPager){
   pPager->nRec = 0;
   if( pPager->errMask!=0 ){
     rc = pager_errcode(pPager);
-    return rc;
+    goto failed_to_open_journal;
   }
   pPager->origDbSize = pPager->dbSize;
 
@@ -2631,11 +2715,7 @@ int sqlite3pager_begin(void *pData, int exFlag){
       pPager->state = PAGER_EXCLUSIVE;
       pPager->origDbSize = pPager->dbSize;
     }else{
-      if( SQLITE_BUSY_RESERVED_LOCK || exFlag ){
-        rc = pager_wait_on_lock(pPager, RESERVED_LOCK);
-      }else{
-        rc = sqlite3OsLock(&pPager->fd, RESERVED_LOCK);
-      }
+      rc = sqlite3OsLock(&pPager->fd, RESERVED_LOCK);
       if( rc==SQLITE_OK ){
         pPager->state = PAGER_RESERVED;
         if( exFlag ){
@@ -3118,11 +3198,13 @@ int *sqlite3pager_stats(Pager *pPager){
   a[3] = pPager->dbSize;
   a[4] = pPager->state;
   a[5] = pPager->errMask;
+#ifdef SQLITE_TEST
   a[6] = pPager->nHit;
   a[7] = pPager->nMiss;
   a[8] = pPager->nOvfl;
   a[9] = pPager->nRead;
   a[10] = pPager->nWrite;
+#endif
   return a;
 }
 
@@ -3406,8 +3488,10 @@ sync_exit:
 ** meta-data associated with page pData (i.e. data stored in the nExtra bytes
 ** allocated along with the page) is the responsibility of the caller.
 **
-** A transaction must be active when this routine is called, however it is 
-** illegal to call this routine if a statment transaction is active.
+** A transaction must be active when this routine is called. It used to be
+** required that a statement transaction was not active, but this restriction
+** has been removed (CREATE INDEX needs to move a page when a statement
+** transaction is active).
 */
 int sqlite3pager_movepage(Pager *pPager, void *pData, Pgno pgno){
   PgHdr *pPg = DATA_TO_PGHDR(pData);
@@ -3415,7 +3499,6 @@ int sqlite3pager_movepage(Pager *pPager, void *pData, Pgno pgno){
   int h;
   Pgno needSyncPgno = 0;
 
-  assert( !pPager->stmtInUse );
   assert( pPg->nRef>0 );
 
   TRACE5("MOVE %d page %d (needSync=%d) moves to %d\n", 
@@ -3517,3 +3600,5 @@ void sqlite3pager_refdump(Pager *pPager){
   }
 }
 #endif
+
+#endif /* SQLITE_OMIT_DISKIO */
index a592b1944b3de7868b110f576d3c537dffd66c5d..63baf0dfd1e9f6fd7d3b7c72de04d9920d04502c 100644 (file)
 # define SQLITE_DEFAULT_PAGE_SIZE 1024
 #endif
 
-/* Maximum page size.  The upper bound on this value is 65536 (a limit
-** imposed by the 2-byte size of cell array pointers.)  The
-** maximum page size determines the amount of stack space allocated
-** by many of the routines in pager.c and btree.c  On embedded architectures
-** or any machine where memory and especially stack memory is limited,
-** one may wish to chose a smaller value for the maximum page size.
+/* Maximum page size.  The upper bound on this value is 32768.  This a limit
+** imposed by necessity of storing the value in a 2-byte unsigned integer
+** and the fact that the page size must be a power of 2.
+**
+** This value is used to initialize certain arrays on the stack at
+** various places in the code.  On embedded machines where stack space
+** is limited and the flexibility of having large pages is not needed,
+** it makes good sense to reduce the maximum page size to something more
+** reasonable, like 1024.
 */
 #ifndef SQLITE_MAX_PAGE_SIZE
 # define SQLITE_MAX_PAGE_SIZE 8192
@@ -68,7 +71,7 @@ int sqlite3pager_open(Pager **ppPager, const char *zFilename,
 void sqlite3pager_set_busyhandler(Pager*, BusyHandler *pBusyHandler);
 void sqlite3pager_set_destructor(Pager*, void(*)(void*,int));
 void sqlite3pager_set_reiniter(Pager*, void(*)(void*,int));
-void sqlite3pager_set_pagesize(Pager*, int);
+int sqlite3pager_set_pagesize(Pager*, int);
 void sqlite3pager_read_fileheader(Pager*, int, unsigned char*);
 void sqlite3pager_set_cachesize(Pager*, int);
 int sqlite3pager_close(Pager *pPager);
@@ -100,6 +103,7 @@ const char *sqlite3pager_journalname(Pager*);
 int sqlite3pager_rename(Pager*, const char *zNewName);
 void sqlite3pager_set_codec(Pager*,void(*)(void*,void*,Pgno,int),void*);
 int sqlite3pager_movepage(Pager*,void*,Pgno);
+int sqlite3pager_reset(Pager*);
 
 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
 int sqlite3pager_lockstate(Pager*);
index af1e6872c99f110dd42fad734669d982d2ad67a0..85660d61c3a60f74178ee5c1d97f56b5bdac5273 100644 (file)
@@ -1,10 +1,10 @@
-/* Driver template for the LEMON parser generator. 
+/* Driver template for the LEMON parser generator.
 ** The author disclaims copyright to this source code.
 */
 /* First off, code is include which follows the "include" declaration
 ** in the input file. */
 #include <stdio.h>
-#line 33 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 33 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 
 #include "sqliteInt.h"
 #include "parse.h"
@@ -23,8 +23,8 @@ struct LimitVal {
 ** GLOB, NOT LIKE, and NOT GLOB operators.
 */
 struct LikeOp {
-  int opcode;   /* Either TK_GLOB or TK_LIKE */
-  int not;      /* True if the NOT keyword is present */
+  Token operator;  /* "like" or "glob" or "regexp" */
+  int not;         /* True if the NOT keyword is present */
 };
 
 /*
@@ -43,7 +43,7 @@ struct TrigEvent { int a; IdList * b; };
 */
 struct AttachKey { int type;  Token key; };
 
-#line 48 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 48 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
 /* Next is all token values, in a form suitable for use by makeheaders.
 ** This section will be null unless lemon is run with the -m switch.
 */
@@ -93,35 +93,35 @@ struct AttachKey { int type;  Token key; };
 **                       defined, then do no error processing.
 */
 #define YYCODETYPE unsigned char
-#define YYNOCODE 239
+#define YYNOCODE 241
 #define YYACTIONTYPE unsigned short int
 #define sqlite3ParserTOKENTYPE Token
 typedef union {
   sqlite3ParserTOKENTYPE yy0;
-  struct AttachKey yy40;
-  int yy60;
-  struct TrigEvent yy62;
-  struct {int value; int mask;} yy243;
-  struct LikeOp yy258;
-  ExprList* yy266;
-  IdList* yy272;
-  Select* yy331;
-  struct LimitVal yy348;
-  Token yy406;
-  SrcList* yy427;
-  Expr* yy454;
-  TriggerStep* yy455;
-  int yy477;
+  Expr* yy2;
+  struct {int value; int mask;} yy47;
+  SrcList* yy67;
+  ExprList* yy82;
+  struct AttachKey yy132;
+  struct TrigEvent yy210;
+  IdList* yy240;
+  struct LimitVal yy244;
+  Token yy258;
+  TriggerStep* yy347;
+  int yy412;
+  struct LikeOp yy438;
+  Select* yy459;
+  int yy481;
 } YYMINORTYPE;
 #define YYSTACKDEPTH 100
 #define sqlite3ParserARG_SDECL Parse *pParse;
 #define sqlite3ParserARG_PDECL ,Parse *pParse
 #define sqlite3ParserARG_FETCH Parse *pParse = yypParser->pParse
 #define sqlite3ParserARG_STORE yypParser->pParse = pParse
-#define YYNSTATE 564
+#define YYNSTATE 565
 #define YYNRULE 305
 #define YYERRORSYMBOL 141
-#define YYERRSYMDT yy477
+#define YYERRSYMDT yy481
 #define YYFALLBACK 1
 #define YY_NO_ACTION      (YYNSTATE+YYNRULE+2)
 #define YY_ACCEPT_ACTION  (YYNSTATE+YYNRULE+1)
@@ -175,481 +175,467 @@ typedef union {
 **  yy_default[]       Default action for each state.
 */
 static const YYACTIONTYPE yy_action[] = {
- /*     0 */   263,  261,  261,  154,  124,  126,  128,  130,  132,  134,
- /*    10 */   136,  138,  140,  142,  350,  567,  145,  641,  261,  369,
- /*    20 */   144,  114,  116,  112,  118,    7,  124,  126,  128,  130,
- /*    30 */   132,  134,  136,  138,  140,  142,  136,  138,  140,  142,
- /*    40 */   110,   94,  146,  157,  162,  167,  156,  161,  120,  122,
- /*    50 */   114,  116,  112,  118,    9,  124,  126,  128,  130,  132,
- /*    60 */   134,  136,  138,  140,  142,  574,  223,  262,  262,  124,
- /*    70 */   126,  128,  130,  132,  134,  136,  138,  140,  142,   13,
- /*    80 */    96,  145,   13,    2,  262,  144,    4,   78,  371,   92,
- /*    90 */    10,  373,  380,  385,  132,  134,  136,  138,  140,  142,
- /*   100 */    75,    3,  562,  388,  296,  110,   94,  146,  157,  162,
- /*   110 */   167,  156,  161,  120,  122,  114,  116,  112,  118,   77,
- /*   120 */   124,  126,  128,  130,  132,  134,  136,  138,  140,  142,
- /*   130 */   145,   65,  573,   13,  144,   11,  371,   66,  292,  373,
- /*   140 */   380,  385,  870,    1,  563,   14,   15,    4,   14,   15,
- /*   150 */   172,  388,   51,  665,  110,   94,  146,  157,  162,  167,
- /*   160 */   156,  161,  120,  122,  114,  116,  112,  118,   72,  124,
- /*   170 */   126,  128,  130,  132,  134,  136,  138,  140,  142,   51,
- /*   180 */    37,  341,   40,   59,   67,   69,  305,  336,  107,  106,
- /*   190 */   108,  847,  572,   34,  338,   96,  366,  349,   13,   14,
- /*   200 */    15,  371,   12,  145,  373,  380,  385,  144,  564,   40,
- /*   210 */    59,   67,   69,  305,  336,   75,  388,    3,  562,  190,
- /*   220 */   345,  338,   44,   45,   95,  460,  802,  110,   94,  146,
- /*   230 */   157,  162,  167,  156,  161,  120,  122,  114,  116,  112,
- /*   240 */   118,  575,  124,  126,  128,  130,  132,  134,  136,  138,
- /*   250 */   140,  142,   20,   48,  800,  364,  362,  101,  102,  367,
- /*   260 */   499,  295,   49,  596,   14,   15,  191,   32,   33,   27,
- /*   270 */   148,  403,   96,   50,  147,  534,   46,  145,  494,  466,
- /*   280 */   456,  144,  580,  279,   36,  340,   47,  399,  309,   81,
- /*   290 */   368,  401,   75,  335,  398,  505,  176,  501,  150,  151,
- /*   300 */   197,  110,   94,  146,  157,  162,  167,  156,  161,  120,
- /*   310 */   122,  114,  116,  112,  118,   77,  124,  126,  128,  130,
- /*   320 */   132,  134,  136,  138,  140,  142,  149,  280,  258,  169,
- /*   330 */    96,   39,  281,   13,  298,  367,   96,  175,   22,  335,
- /*   340 */    28,  145,  188,  402,   33,  144,  217,    6,    5,  171,
- /*   350 */    75,  173,  174,   25,  176,  581,   75,   57,   58,  507,
- /*   360 */   235,  351,  356,  357,  265,  110,   94,  146,  157,  162,
- /*   370 */   167,  156,  161,  120,  122,  114,  116,  112,  118,  503,
- /*   380 */   124,  126,  128,  130,  132,  134,  136,  138,  140,  142,
- /*   390 */   457,   77,  243,  294,   48,  227,  236,  293,  297,   14,
- /*   400 */    15,  288,   96,   49,  217,  152,  222,  163,  168,  278,
- /*   410 */    24,   13,  687,   13,   50,  145,  518,  201,  152,  144,
- /*   420 */   163,  168,   75,  358,  582,  171,  176,  173,  174,  263,
- /*   430 */   171,  261,  173,  174,  354,  356,  357,  588,  211,  110,
- /*   440 */    94,  146,  157,  162,  167,  156,  161,  120,  122,  114,
- /*   450 */   116,  112,  118,  654,  124,  126,  128,  130,  132,  134,
- /*   460 */   136,  138,  140,  142,  303,   13,  688,   96,  250,  817,
- /*   470 */    96,   16,   17,   18,  246,   81,  216,   14,   15,   14,
- /*   480 */    15,  145,   13,  406,  435,  144,   13,   75,  487,  387,
- /*   490 */    75,  493,  248,  258,  235,  660,  358,  262,  310,  852,
- /*   500 */   171,   26,  173,  174,  253,  110,   94,  146,  157,  162,
- /*   510 */   167,  156,  161,  120,  122,  114,  116,  112,  118,  397,
- /*   520 */   124,  126,  128,  130,  132,  134,  136,  138,  140,  142,
- /*   530 */   229,   14,   15,  489,  250,  152,  252,  163,  168,  171,
- /*   540 */   839,  173,  174,  360,  361,   96,  145,  533,   14,   15,
- /*   550 */   144,  866,   14,   15,  801,  442,  312,  275,  255,  453,
- /*   560 */   850,  338,  251,  535,  536,   75,  662,  247,   13,  493,
- /*   570 */   110,   94,  146,  157,  162,  167,  156,  161,  120,  122,
- /*   580 */   114,  116,  112,  118,  845,  124,  126,  128,  130,  132,
- /*   590 */   134,  136,  138,  140,  142,  726,   96,  171,   96,  173,
- /*   600 */   174,  171,  252,  173,  174,  152,  583,  163,  168,   42,
- /*   610 */   720,  525,   96,  145,  441,  271,   75,  144,   75,  170,
- /*   620 */   302,  640,   91,   31,  358,  313,  320,  322,  251,  432,
- /*   630 */   434,  433,   75,  844,   14,   15,  176,  110,   94,  146,
- /*   640 */   157,  162,  167,  156,  161,  120,  122,  114,  116,  112,
- /*   650 */   118,   77,  124,  126,  128,  130,  132,  134,  136,  138,
- /*   660 */   140,  142,  171,   96,  173,  174,  331,   52,  171,   96,
- /*   670 */   173,  174,   96,  195,  213,  207,   29,  348,  145,   54,
- /*   680 */   310,  318,  144,   75,  455,  342,  217,   93,   83,   75,
- /*   690 */    30,  452,   75,  109,  587,  286,  111,  171,  265,  173,
- /*   700 */   174,  319,  110,   94,  146,  157,  162,  167,  156,  161,
- /*   710 */   120,  122,  114,  116,  112,  118,   77,  124,  126,  128,
- /*   720 */   130,  132,  134,  136,  138,  140,  142,  244,   96,  187,
- /*   730 */    96,   96,  810,  331,  214,  266,  215,   35,  312,   96,
- /*   740 */    96,  479,  328,  145,  623,   38,  327,  144,   75,  455,
- /*   750 */    75,   75,  113,  689,  115,  117,  315,  461,  426,   75,
- /*   760 */    75,   77,  463,  119,  121,  407,  325,  110,  165,  146,
- /*   770 */   157,  162,  167,  156,  161,  120,  122,  114,  116,  112,
- /*   780 */   118,   77,  124,  126,  128,  130,  132,  134,  136,  138,
- /*   790 */   140,  142,   42,   96,   96,   96,   96,  824,  273,  159,
- /*   800 */   415,   96,  410,  272,   96,  273,  479,   41,  145,  332,
- /*   810 */   537,   43,  144,   75,   75,   75,   75,  123,  125,  127,
- /*   820 */   129,   75,  465,   64,   75,  131,   53,  463,  133,  158,
- /*   830 */   317,  316,  265,   94,  146,  157,  162,  167,  156,  161,
- /*   840 */   120,  122,  114,  116,  112,  118,  219,  124,  126,  128,
- /*   850 */   130,  132,  134,  136,  138,  140,  142,   96,  689,   96,
- /*   860 */    96,  532,   96,  331,  299,   96,  215,   96,   96,  283,
- /*   870 */    96,  261,  219,   96,  145,   96,  840,   75,  144,   75,
- /*   880 */    75,  135,   75,  137,  139,   75,  141,   75,   75,  143,
- /*   890 */    75,  153,  155,   75,  164,   75,  376,  166,   56,  178,
- /*   900 */   146,  157,  162,  167,  156,  161,  120,  122,  114,  116,
- /*   910 */   112,  118,  652,  124,  126,  128,  130,  132,  134,  136,
- /*   920 */   138,  140,  142,   76,   96,   96,   96,   71,  438,  364,
- /*   930 */   362,  437,   96,   96,   96,   96,  331,  262,  233,  332,
- /*   940 */    96,   55,  331,  439,   75,   75,   75,  331,  180,  182,
- /*   950 */   184,  199,   75,   75,   75,   75,  196,  198,  208,  210,
- /*   960 */    75,  107,  106,  108,  212,  720,  326,  177,  327,  382,
- /*   970 */   430,  431,  107,  106,  108,  391,  548,   61,   96,   96,
- /*   980 */   449,  471,  458,   45,  183,  181,  300,   96,  476,  352,
- /*   990 */    96,  353,  179,   73,   74,  343,  346,   95,   75,   75,
- /*  1000 */   290,   96,  224,  240,  345,  275,   42,   75,   95,   76,
- /*  1010 */    75,  245,  332,   71,  277,  383,  275,  327,  332,   96,
- /*  1020 */    75,   75,  404,  332,  287,  386,   96,  392,  421,  327,
- /*  1030 */   101,  102,  103,  104,  105,  185,  189,  199,   96,   75,
- /*  1040 */    96,  101,  102,  427,  414,   60,   75,  107,  106,  108,
- /*  1050 */   474,  470,  486,  177,   77,  450,  421,  327,   75,  484,
- /*  1060 */    75,  273,  478,  436,  491,  492,  423,  490,  421,  421,
- /*  1070 */   183,  181,  421,  421,  483,  421,   77,  421,  179,   73,
- /*  1080 */    74,  476,  244,   95,   77,   81,  526,  860,  490,  421,
- /*  1090 */   689,  522,   62,   64,  500,   70,  597,   63,  523,   68,
- /*  1100 */   598,   76,   81,   79,   81,   71,  502,  504,   84,   80,
- /*  1110 */   506,  510,  244,  514,  239,  520,  101,  102,  103,  104,
- /*  1120 */   105,  185,  189,   77,  546,  241,   82,  558,   86,  199,
- /*  1130 */    85,  225,   90,   87,   97,   88,   99,  142,   89,  107,
- /*  1140 */   106,  108,  160,   98,  516,  177,  100,  218,  666,  667,
- /*  1150 */   668,  186,  209,  193,  192,  194,  200,  204,  203,  202,
- /*  1160 */   206,  205,  183,  181,  219,  220,  221,  226,  228,  232,
- /*  1170 */   179,   73,   74,  230,  233,   95,  234,  231,  237,  242,
- /*  1180 */   238,  215,  260,  249,  257,  276,  267,  254,  256,  259,
- /*  1190 */   264,  269,  270,   76,  274,  282,  301,   71,  219,  268,
- /*  1200 */   285,  291,  284,  306,  324,  307,  311,  308,  101,  102,
- /*  1210 */   103,  104,  105,  185,  189,  803,  355,  329,  375,  304,
- /*  1220 */   314,  199,  321,  337,  330,  365,  334,  372,  309,  333,
- /*  1230 */   323,  107,  106,  108,  344,  339,  347,  177,  374,  378,
- /*  1240 */   400,  359,  370,  377,  381,  379,  384,  389,  363,  390,
- /*  1250 */   393,  394,  396,   54,  183,  181,  289,  408,  395,  409,
- /*  1260 */   411,  413,  179,   73,   74,  412,  416,   95,  417,  420,
- /*  1270 */   428,  422,  832,  429,  443,  440,  444,  837,  838,   76,
- /*  1280 */   446,  445,  448,   71,  451,  808,  809,  459,  454,  447,
- /*  1290 */   418,  727,  728,  831,  464,  462,  846,  457,  469,  419,
- /*  1300 */   101,  102,  103,  104,  105,  185,  189,  199,  467,  468,
- /*  1310 */   472,  473,  475,  424,  848,  477,  480,  107,  106,  108,
- /*  1320 */   425,  482,  488,  177,  485,  849,  481,  495,  496,  851,
- /*  1330 */   659,  661,  816,  858,  497,  509,  511,  719,  513,  515,
- /*  1340 */   183,  181,  722,  517,  725,  519,  521,  524,  179,   73,
- /*  1350 */    74,  818,  528,   95,  530,  819,  820,  531,  538,  821,
- /*  1360 */     8,  822,  539,  823,  549,   19,   21,   23,  405,  541,
- /*  1370 */   542,  544,  543,  859,  547,  861,  862,  865,  545,  540,
- /*  1380 */   551,  867,  557,  555,  552,  550,  101,  102,  103,  104,
- /*  1390 */   105,  185,  189,  554,  560,  559,  561,  868,  529,  545,
- /*  1400 */   460,  545,  545,  545,  545,  527,  545,  553,  545,  545,
- /*  1410 */   545,  545,  556,  545,  545,  545,  545,  545,  545,  545,
- /*  1420 */   545,  545,  545,  545,  545,  545,  545,  545,  545,  545,
- /*  1430 */   545,  545,  545,  545,  545,  545,  545,  545,  545,  545,
- /*  1440 */   545,  545,  545,  545,  545,  545,  545,  545,  545,  545,
- /*  1450 */   545,  545,  545,  508,  512,  456,  545,  545,  545,  498,
- /*  1460 */   545,  545,  545,  545,   81,
+ /*     0 */   259,   65,  257,  112,  114,  110,  116,   66,  122,  124,
+ /*    10 */   126,  128,  130,  132,  134,  136,  138,  140,  568,  142,
+ /*    20 */   150,  122,  124,  126,  128,  130,  132,  134,  136,  138,
+ /*    30 */   140,  130,  132,  134,  136,  138,  140,  108,   94,  143,
+ /*    40 */   153,  158,  163,  152,  157,  118,  120,  112,  114,  110,
+ /*    50 */   116,   72,  122,  124,  126,  128,  130,  132,  134,  136,
+ /*    60 */   138,  140,    7,  106,  219,  258,  122,  124,  126,  128,
+ /*    70 */   130,  132,  134,  136,  138,  140,  367,   13,    9,  369,
+ /*    80 */   376,  381,  142,  871,    1,  564,   92,   27,    4,  399,
+ /*    90 */   363,  384,  844,  341,  291,   28,   10,   95,  398,   33,
+ /*   100 */   108,   94,  143,  153,  158,  163,  152,  157,  118,  120,
+ /*   110 */   112,  114,  110,  116,   96,  122,  124,  126,  128,  130,
+ /*   120 */   132,  134,  136,  138,  140,  456,  565,  142,  395,  305,
+ /*   130 */   101,  102,  103,  288,   75,  394,    3,  563,  231,  275,
+ /*   140 */    14,   15,  575,  597,  437,  108,   94,  143,  153,  158,
+ /*   150 */   163,  152,  157,  118,  120,  112,  114,  110,  116,   13,
+ /*   160 */   122,  124,  126,  128,  130,  132,  134,  136,  138,  140,
+ /*   170 */   573,   77,  142,  223,  232,   13,  490,  462,  452,  167,
+ /*   180 */   306,  169,  170,  276,  254,    3,  563,   81,  277,  183,
+ /*   190 */   108,   94,  143,  153,  158,  163,  152,  157,  118,  120,
+ /*   200 */   112,  114,  110,  116,   52,  122,  124,  126,  128,  130,
+ /*   210 */   132,  134,  136,  138,  140,   48,   54,  799,  448,   51,
+ /*   220 */   797,   77,   14,   15,   49,  363,  134,  136,  138,  140,
+ /*   230 */    16,   17,   18,   32,   33,   50,  308,  197,   14,   15,
+ /*   240 */   367,  261,   13,  369,  376,  381,  142,   37,  337,   40,
+ /*   250 */    59,   67,   69,  301,  332,  384,  364,  397,  259,  807,
+ /*   260 */   257,  334,   51,  193,  108,   94,  143,  153,  158,  163,
+ /*   270 */   152,  157,  118,  120,  112,  114,  110,  116,  262,  122,
+ /*   280 */   124,  126,  128,  130,  132,  134,  136,  138,  140,   13,
+ /*   290 */   171,  142,   40,   59,   67,   69,  301,  332,  642,  148,
+ /*   300 */   365,  159,  164,  261,  334,   14,   15,   44,   45,  108,
+ /*   310 */    94,  143,  153,  158,  163,  152,  157,  118,  120,  112,
+ /*   320 */   114,  110,  116,  258,  122,  124,  126,  128,  130,  132,
+ /*   330 */   134,  136,  138,  140,  148,  218,  159,  164,  184,   12,
+ /*   340 */   284,  417,   48,  360,  358,  293,  290,  347,  352,  353,
+ /*   350 */   289,   49,   14,   15,  688,    2,   96,  148,    4,  159,
+ /*   360 */   164,  257,   50,  530,   46,  142,  367,  155,  165,  369,
+ /*   370 */   376,  381,   13,  576,   47,  167,   75,  169,  170,  554,
+ /*   380 */   172,  384,  207,  108,   94,  143,  153,  158,  163,  152,
+ /*   390 */   157,  118,  120,  112,  114,  110,  116,  154,  122,  124,
+ /*   400 */   126,  128,  130,  132,  134,  136,  138,  140,  299,  354,
+ /*   410 */   350,  352,  353,   96,   96,   13,   34,   20,  294,  362,
+ /*   420 */   345,  144,  581,  167,  258,  169,  170,  821,  142,  558,
+ /*   430 */   213,  244,  254,   75,   75,   14,   15,  172,  186,  167,
+ /*   440 */   533,  169,  170,  146,  147,  417,  108,   94,  143,  153,
+ /*   450 */   158,  163,  152,  157,  118,  120,  112,  114,  110,  116,
+ /*   460 */    96,  122,  124,  126,  128,  130,  132,  134,  136,  138,
+ /*   470 */   140,  145,  354,  142,   22,  239,  383,  589,   14,   15,
+ /*   480 */    75,   36,  336,  419,  172,  187,  842,  213,  528,  582,
+ /*   490 */   331,  108,   94,  143,  153,  158,  163,  152,  157,  118,
+ /*   500 */   120,  112,  114,  110,  116,  249,  122,  124,  126,  128,
+ /*   510 */   130,  132,  134,  136,  138,  140,  306,  661,  142,  327,
+ /*   520 */   574,  849,  148,   11,  159,  164,  309,  316,  318,  168,
+ /*   530 */    42,  327,  666,  327,  212,  393,  108,   94,  143,  153,
+ /*   540 */   158,  163,  152,  157,  118,  120,  112,  114,  110,  116,
+ /*   550 */    96,  122,  124,  126,  128,  130,  132,  134,  136,  138,
+ /*   560 */   140,  847,   83,  142,  321,  641,  372,   31,  663,  282,
+ /*   570 */    75,  242,  308,  689,  231,  246,  167,  334,  169,  170,
+ /*   580 */   269,  108,   94,  143,  153,  158,  163,  152,  157,  118,
+ /*   590 */   120,  112,  114,  110,  116,  324,  122,  124,  126,  128,
+ /*   600 */   130,  132,  134,  136,  138,  140,  246,  328,  142,  328,
+ /*   610 */   225,  434,   24,   39,  433,  210,  167,  211,  169,  170,
+ /*   620 */   167,  331,  169,  170,  583,  435,  108,  161,  143,  153,
+ /*   630 */   158,  163,  152,  157,  118,  120,  112,  114,  110,  116,
+ /*   640 */   248,  122,  124,  126,  128,  130,  132,  134,  136,  138,
+ /*   650 */   140,   57,   58,  142,  624,  837,  323,  727,  271,  261,
+ /*   660 */   167,  243,  169,  170,  313,  312,  247,  167,  798,  169,
+ /*   670 */   170,  248,   94,  143,  153,  158,  163,  152,  157,  118,
+ /*   680 */   120,  112,  114,  110,  116,   96,  122,  124,  126,  128,
+ /*   690 */   130,  132,  134,  136,  138,  140,  279,  247,  142,  360,
+ /*   700 */   358,    6,    5,  363,  346,   75,  274,   25,  257,  489,
+ /*   710 */    13,  561,   33,  503,   13,  268,  267,  269,  143,  153,
+ /*   720 */   158,  163,  152,  157,  118,  120,  112,  114,  110,  116,
+ /*   730 */    64,  122,  124,  126,  128,  130,  132,  134,  136,  138,
+ /*   740 */   140,   26,   76,   96,  400,   77,   71,  584,   96,  451,
+ /*   750 */   166,  485,   29,   76,  402,   78,  167,   71,  169,  170,
+ /*   760 */   295,  451,  211,   75,   30,  257,  314,  172,   75,  195,
+ /*   770 */   514,  258,  292,   14,   15,  690,   77,   14,   15,  106,
+ /*   780 */   195,   77,   77,  173,  191,  315,  203,   77,  344,  215,
+ /*   790 */   106,  690,  327,   77,  173,  495,  338,  588,  529,  403,
+ /*   800 */   179,  177,  296,  453,  251,  209,  475,  327,  175,   73,
+ /*   810 */    74,  179,  177,   95,  531,  532,   35,  213,  475,  175,
+ /*   820 */    73,   74,  457,   38,   95,  378,  438,  459,  258,  501,
+ /*   830 */   449,  497,  841,  411,  461,  406,  653,   76,  311,  459,
+ /*   840 */   387,   71,  322,   81,  323,   42,  101,  102,  103,  104,
+ /*   850 */   105,  181,  185,   96,  356,  357,   96,  101,  102,  103,
+ /*   860 */   104,  105,  181,  185,  195,   76,  655,  544,  328,   71,
+ /*   870 */    96,  271,  431,   75,  106,  354,   75,  489,  173,  327,
+ /*   880 */   298,  215,  410,  328,  428,  430,  429,  426,  427,   96,
+ /*   890 */    75,  721,  195,   76,   91,  179,  177,   71,  348,  379,
+ /*   900 */   349,  323,  106,  175,   73,   74,  173,  467,   95,   75,
+ /*   910 */   271,  499,  445,   93,   77,  388,  446,  323,  323,  521,
+ /*   920 */   195,  454,   45,  179,  177,  285,  836,   42,   41,  432,
+ /*   930 */   106,  175,   73,   74,  173,  480,   95,  269,  488,   43,
+ /*   940 */   486,  101,  102,  103,  104,  105,  181,  185,  800,  721,
+ /*   950 */   417,  179,  177,  229,  422,  328,   96,   96,   96,  175,
+ /*   960 */    73,   74,  814,   96,   95,  522,   53,  486,  479,  101,
+ /*   970 */   102,  103,  104,  105,  181,  185,   75,   75,   75,   13,
+ /*   980 */   107,  109,  423,   75,   55,    8,  106,  111,  496,  857,
+ /*   990 */    19,   21,   23,  401,   96,  472,   56,  101,  102,  103,
+ /*  1000 */   104,  105,  181,  185,  536,  240,   81,  339,  342,  863,
+ /*  1010 */   546,   61,   96,   96,   75,   96,  341,  482,  113,  483,
+ /*  1020 */    95,   96,  525,  417,  456,  542,   13,   96,   96,  523,
+ /*  1030 */   417,  549,   75,   75,  552,   75,  115,  117,  472,  119,
+ /*  1040 */    96,   75,   14,   15,   81,  121,   96,   75,   75,   77,
+ /*  1050 */   417,  123,  125,  101,  102,  103,   60,  519,  466,   96,
+ /*  1060 */    75,  498,  417,  240,  127,  417,   75,   64,  500,   62,
+ /*  1070 */   129,   96,   63,  690,   96,  504,  508,  452,   68,   75,
+ /*  1080 */   417,  494,   96,  131,   96,   96,   81,   96,  502,   14,
+ /*  1090 */    15,   75,   96,   96,   75,  133,  555,   70,  135,   96,
+ /*  1100 */   506,  512,   75,  510,   75,   75,  137,   75,  139,  141,
+ /*  1110 */    96,  149,   75,   75,   81,   96,  151,  160,  516,   75,
+ /*  1120 */    96,   96,   96,  162,  598,   80,  599,   96,   96,   82,
+ /*  1130 */    75,  240,  221,   84,  174,   75,   96,   96,   96,  176,
+ /*  1140 */    75,   75,   75,   96,  178,  180,  192,   75,   75,  518,
+ /*  1150 */    96,  194,  204,   96,   79,  286,   75,   75,   75,  237,
+ /*  1160 */   206,  208,  220,   75,   96,   96,   96,  236,   85,  235,
+ /*  1170 */    75,   96,   87,   75,  241,   75,  867,  273,  215,  283,
+ /*  1180 */    86,   77,   90,   97,   75,   75,   75,   88,  382,  470,
+ /*  1190 */   474,   75,   89,   98,   99,  487,  100,  140,  156,  214,
+ /*  1200 */   667,  668,  669,  182,  205,  188,  190,  189,  196,  199,
+ /*  1210 */   198,  201,  215,  200,  202,  216,  217,  224,  222,  228,
+ /*  1220 */   227,  229,  230,  226,  234,  238,  211,  245,  233,  253,
+ /*  1230 */   250,  252,  255,  272,  260,  263,  265,  256,  264,  266,
+ /*  1240 */   270,  278,  287,  280,  297,  281,  300,  320,  303,  302,
+ /*  1250 */   305,  307,  304,  325,  333,  329,  310,  317,  326,  351,
+ /*  1260 */   355,  370,  359,  330,  319,  340,  343,  368,  371,  361,
+ /*  1270 */   374,  377,  385,  335,  375,  373,  396,  386,  380,  389,
+ /*  1280 */   390,   54,  366,  391,  404,  392,  407,  405,  409,  408,
+ /*  1290 */   412,  413,  418,  416,  829,  414,  424,  425,  415,  834,
+ /*  1300 */   420,  439,  835,  421,  436,  440,  441,  442,  443,  444,
+ /*  1310 */   447,  805,  450,  806,  455,  458,  828,  460,  728,  464,
+ /*  1320 */   729,  843,  453,  465,  468,  471,  463,  845,  476,  469,
+ /*  1330 */   481,  478,  473,  477,  484,  846,  493,  491,  848,  492,
+ /*  1340 */   660,  662,  813,  855,  505,  507,  720,  509,  511,  723,
+ /*  1350 */   513,  726,  515,  815,  524,  526,  527,  520,  517,  816,
+ /*  1360 */   817,  818,  819,  534,  535,  820,  856,  539,  858,  540,
+ /*  1370 */   545,  538,  543,  859,  862,  548,  551,  864,  553,  550,
+ /*  1380 */   537,  557,  541,  547,  865,  556,  866,  560,  559,  547,
+ /*  1390 */   562,
 };
 static const YYCODETYPE yy_lookahead[] = {
- /*     0 */    24,   26,   26,   78,   79,   80,   81,   82,   83,   84,
- /*    10 */    85,   86,   87,   88,   22,    9,   40,   23,   26,   25,
- /*    20 */    44,   74,   75,   76,   77,    9,   79,   80,   81,   82,
- /*    30 */    83,   84,   85,   86,   87,   88,   85,   86,   87,   88,
- /*    40 */    64,   65,   66,   67,   68,   69,   70,   71,   72,   73,
- /*    50 */    74,   75,   76,   77,  148,   79,   80,   81,   82,   83,
- /*    60 */    84,   85,   86,   87,   88,    9,   25,   92,   92,   79,
- /*    70 */    80,   81,   82,   83,   84,   85,   86,   87,   88,   26,
- /*    80 */   150,   40,   26,  144,   92,   44,  147,  157,   94,   48,
- /*    90 */   149,   97,   98,   99,   83,   84,   85,   86,   87,   88,
- /*   100 */   170,    9,   10,  109,  174,   64,   65,   66,   67,   68,
- /*   110 */    69,   70,   71,   72,   73,   74,   75,   76,   77,  189,
- /*   120 */    79,   80,   81,   82,   83,   84,   85,   86,   87,   88,
- /*   130 */    40,   29,    9,   26,   44,   12,   94,   35,   85,   97,
- /*   140 */    98,   99,  142,  143,  144,   92,   93,  147,   92,   93,
- /*   150 */   112,  109,   66,  115,   64,   65,   66,   67,   68,   69,
- /*   160 */    70,   71,   72,   73,   74,   75,   76,   77,   22,   79,
- /*   170 */    80,   81,   82,   83,   84,   85,   86,   87,   88,   66,
- /*   180 */    94,   95,   96,   97,   98,   99,  100,  101,   60,   61,
- /*   190 */    62,   17,    9,  160,  108,  150,  163,  164,   26,   92,
- /*   200 */    93,   94,  150,   40,   97,   98,   99,   44,    0,   96,
- /*   210 */    97,   98,   99,  100,  101,  170,  109,    9,   10,  174,
- /*   220 */    92,  108,  186,  187,   96,   51,  136,   64,   65,   66,
- /*   230 */    67,   68,   69,   70,   71,   72,   73,   74,   75,   76,
- /*   240 */    77,    9,   79,   80,   81,   82,   83,   84,   85,   86,
- /*   250 */    87,   88,  149,   18,   17,   83,   84,  129,  130,  150,
- /*   260 */    20,   23,   27,  117,   92,   93,  221,  158,  159,   22,
- /*   270 */    40,   24,  150,   38,   44,  103,   41,   40,  104,  105,
- /*   280 */   106,   44,    9,  157,  168,  169,   51,  177,  178,  115,
- /*   290 */   181,  182,  170,  177,  184,   55,  174,   57,   68,   69,
- /*   300 */   137,   64,   65,   66,   67,   68,   69,   70,   71,   72,
- /*   310 */    73,   74,   75,   76,   77,  189,   79,   80,   81,   82,
- /*   320 */    83,   84,   85,   86,   87,   88,   96,  201,  202,   22,
- /*   330 */   150,  169,  206,   26,  212,  150,  150,   23,  149,  177,
- /*   340 */   155,   40,   23,  158,  159,   44,  224,  145,  146,  111,
- /*   350 */   170,  113,  114,  151,  174,    9,  170,   13,   14,  157,
- /*   360 */   174,  165,  166,  167,  163,   64,   65,   66,   67,   68,
- /*   370 */    69,   70,   71,   72,   73,   74,   75,   76,   77,  139,
- /*   380 */    79,   80,   81,   82,   83,   84,   85,   86,   87,   88,
- /*   390 */    64,  189,  212,  112,   18,  209,  210,  116,   23,   92,
- /*   400 */    93,  200,  150,   27,  224,  217,  218,  219,  220,   22,
- /*   410 */   149,   26,   23,   26,   38,   40,  214,   41,  217,   44,
- /*   420 */   219,  220,  170,  227,    9,  111,  174,  113,  114,   24,
- /*   430 */   111,   26,  113,  114,  165,  166,  167,    9,  137,   64,
- /*   440 */    65,   66,   67,   68,   69,   70,   71,   72,   73,   74,
- /*   450 */    75,   76,   77,  127,   79,   80,   81,   82,   83,   84,
- /*   460 */    85,   86,   87,   88,   23,   26,   23,  150,   25,    9,
- /*   470 */   150,   13,   14,   15,   25,  115,  224,   92,   93,   92,
- /*   480 */    93,   40,   26,  153,   47,   44,   26,  170,  128,  171,
- /*   490 */   170,  174,  201,  202,  174,    9,  227,   92,   45,    9,
- /*   500 */   111,  152,  113,  114,  119,   64,   65,   66,   67,   68,
- /*   510 */    69,   70,   71,   72,   73,   74,   75,   76,   77,   66,
- /*   520 */    79,   80,   81,   82,   83,   84,   85,   86,   87,   88,
- /*   530 */   210,   92,   93,  216,   25,  217,   93,  219,  220,  111,
- /*   540 */   103,  113,  114,  129,  130,  150,   40,  150,   92,   93,
- /*   550 */    44,    9,   92,   93,   17,  225,  103,  150,  119,  229,
- /*   560 */     9,  108,  119,  166,  167,  170,    9,  118,   26,  174,
- /*   570 */    64,   65,   66,   67,   68,   69,   70,   71,   72,   73,
- /*   580 */    74,   75,   76,   77,   11,   79,   80,   81,   82,   83,
- /*   590 */    84,   85,   86,   87,   88,    9,  150,  111,  150,  113,
- /*   600 */   114,  111,   93,  113,  114,  217,    9,  219,  220,  103,
- /*   610 */     9,  216,  150,   40,   21,  208,  170,   44,  170,  157,
- /*   620 */   174,   23,  174,   25,  227,  104,  105,  106,  119,  104,
- /*   630 */   105,  106,  170,   11,   92,   93,  174,   64,   65,   66,
- /*   640 */    67,   68,   69,   70,   71,   72,   73,   74,   75,   76,
- /*   650 */    77,  189,   79,   80,   81,   82,   83,   84,   85,   86,
- /*   660 */    87,   88,  111,  150,  113,  114,  150,   96,  111,  150,
- /*   670 */   113,  114,  150,  136,  212,  138,  156,  162,   40,  108,
- /*   680 */    45,   32,   44,  170,  157,  170,  224,  174,  192,  170,
- /*   690 */    23,   98,  170,  174,    9,  199,  174,  111,  163,  113,
- /*   700 */   114,   52,   64,   65,   66,   67,   68,   69,   70,   71,
- /*   710 */    72,   73,   74,   75,   76,   77,  189,   79,   80,   81,
- /*   720 */    82,   83,   84,   85,   86,   87,   88,  126,  150,  157,
- /*   730 */   150,  150,  139,  150,   23,  200,   25,  161,  103,  150,
- /*   740 */   150,  214,  226,   40,   23,  150,   25,   44,  170,  157,
- /*   750 */   170,  170,  174,   24,  174,  174,  107,  230,  136,  170,
- /*   760 */   170,  189,  235,  174,  174,   20,  183,   64,   65,   66,
- /*   770 */    67,   68,   69,   70,   71,   72,   73,   74,   75,   76,
- /*   780 */    77,  189,   79,   80,   81,   82,   83,   84,   85,   86,
- /*   790 */    87,   88,  103,  150,  150,  150,  150,    9,   25,   66,
- /*   800 */    55,  150,   57,   23,  150,   25,  214,  171,   40,  226,
- /*   810 */    22,   33,   44,  170,  170,  170,  170,  174,  174,  174,
- /*   820 */   174,  170,  230,  102,  170,  174,  171,  235,  174,   96,
- /*   830 */    95,   96,  163,   65,   66,   67,   68,   69,   70,   71,
- /*   840 */    72,   73,   74,   75,   76,   77,  117,   79,   80,   81,
- /*   850 */    82,   83,   84,   85,   86,   87,   88,  150,  103,  150,
- /*   860 */   150,   73,  150,  150,   23,  150,   25,  150,  150,  200,
- /*   870 */   150,   26,  117,  150,   40,  150,  103,  170,   44,  170,
- /*   880 */   170,  174,  170,  174,  174,  170,  174,  170,  170,  174,
- /*   890 */   170,  174,  174,  170,  174,  170,  183,  174,   42,  174,
- /*   900 */    66,   67,   68,   69,   70,   71,   72,   73,   74,   75,
- /*   910 */    76,   77,    9,   79,   80,   81,   82,   83,   84,   85,
- /*   920 */    86,   87,   88,   22,  150,  150,  150,   26,   28,   83,
- /*   930 */    84,   31,  150,  150,  150,  150,  150,   92,   26,  226,
- /*   940 */   150,  180,  150,   43,  170,  170,  170,  150,  174,  174,
- /*   950 */   174,   50,  170,  170,  170,  170,  174,  174,  174,  174,
- /*   960 */   170,   60,   61,   62,  174,    9,   23,   66,   25,  183,
- /*   970 */    53,   54,   60,   61,   62,  183,  131,  172,  150,  150,
- /*   980 */   183,   25,  186,  187,   83,   84,   85,  150,  150,   23,
- /*   990 */   150,   25,   91,   92,   93,   83,   84,   96,  170,  170,
- /*  1000 */   150,  150,  174,  174,   92,  150,  103,  170,   96,   22,
- /*  1010 */   170,  174,  226,   26,  174,   23,  150,   25,  226,  150,
- /*  1020 */   170,  170,  157,  226,  174,  174,  150,   23,  150,   25,
- /*  1030 */   129,  130,  131,  132,  133,  134,  135,   50,  150,  170,
- /*  1040 */   150,  129,  130,  174,  157,   46,  170,   60,   61,   62,
- /*  1050 */   174,  213,  157,   66,  189,   23,  150,   25,  170,   23,
- /*  1060 */   170,   25,  174,  208,  174,   23,  188,   25,  150,  150,
- /*  1070 */    83,   84,  150,  150,  208,  150,  189,  150,   91,   92,
- /*  1080 */    93,  150,  126,   96,  189,  115,   23,    9,   25,  150,
- /*  1090 */     9,  157,  171,  102,  188,   22,  117,  173,  128,  171,
- /*  1100 */   117,   22,  115,  190,  115,   26,  188,  188,  193,  189,
- /*  1110 */   188,  188,  126,  188,  124,  188,  129,  130,  131,  132,
- /*  1120 */   133,  134,  135,  189,   46,  123,  191,  188,  195,   50,
- /*  1130 */   194,  121,  125,  196,  117,  197,  117,   88,  198,   60,
- /*  1140 */    61,   62,   96,  150,  213,   66,  150,  150,  115,  115,
- /*  1150 */   115,   22,  136,  223,  222,   17,   22,   25,  187,   23,
- /*  1160 */    23,  150,   83,   84,  117,  150,  154,  122,   25,  101,
- /*  1170 */    91,   92,   93,  211,   26,   96,  162,  172,  211,  122,
- /*  1180 */   172,   25,  154,  203,  119,  103,  204,  150,  150,  150,
- /*  1190 */   150,  120,   22,   22,  150,   23,   23,   26,  117,  205,
- /*  1200 */   205,  117,  204,  150,   22,  175,  150,  176,  129,  130,
- /*  1210 */   131,  132,  133,  134,  135,  136,   23,  211,   22,  171,
- /*  1220 */   179,   50,  179,  162,  172,  163,  172,  150,  178,  211,
- /*  1230 */   179,   60,   61,   62,  170,  180,  170,   66,   46,   23,
- /*  1240 */   182,  228,  182,  173,   22,  171,  171,   46,  228,   22,
- /*  1250 */   100,  150,  176,  108,   83,   84,   85,  150,  175,  154,
- /*  1260 */   150,   24,   91,   92,   93,  154,  150,   96,  154,  103,
- /*  1270 */    39,  154,   11,   37,  139,   47,  150,  103,  103,   22,
- /*  1280 */   103,  154,   22,   26,  171,    9,  139,  185,   11,  150,
- /*  1290 */   231,  127,  127,    9,    9,   17,   17,   64,  107,  232,
- /*  1300 */   129,  130,  131,  132,  133,  134,  135,   50,  185,  150,
- /*  1310 */   150,   73,  194,  233,    9,   73,  127,   60,   61,   62,
- /*  1320 */   234,   22,   22,   66,  215,    9,  150,  118,  150,    9,
- /*  1330 */     9,    9,    9,    9,  194,  118,  194,    9,  185,  107,
- /*  1340 */    83,   84,    9,  194,    9,  127,  215,   22,   91,   92,
- /*  1350 */    93,    9,  150,   96,  150,    9,    9,  154,  150,    9,
- /*  1360 */    11,    9,   23,    9,   34,   16,   17,   18,   19,  236,
- /*  1370 */   163,  150,   24,    9,  163,    9,    9,    9,  237,   30,
- /*  1380 */   236,    9,   20,  154,  150,   36,  129,  130,  131,  132,
- /*  1390 */   133,  134,  135,  150,  140,   59,  150,    9,   49,  238,
- /*  1400 */    51,  238,  238,  238,  238,   56,  238,   58,  238,  238,
- /*  1410 */   238,  238,   63,  238,  238,  238,  238,  238,  238,  238,
- /*  1420 */   238,  238,  238,  238,  238,  238,  238,  238,  238,  238,
- /*  1430 */   238,  238,  238,  238,  238,  238,  238,  238,  238,  238,
- /*  1440 */   238,  238,  238,  238,  238,  238,  238,  238,  238,  238,
- /*  1450 */   238,  238,  238,  104,  105,  106,  238,  238,  238,  110,
- /*  1460 */   238,  238,  238,  238,  115,
+ /*     0 */    25,   30,   27,   72,   73,   74,   75,   36,   77,   78,
+ /*    10 */    79,   80,   81,   82,   83,   84,   85,   86,   10,   44,
+ /*    20 */    76,   77,   78,   79,   80,   81,   82,   83,   84,   85,
+ /*    30 */    86,   81,   82,   83,   84,   85,   86,   62,   63,   64,
+ /*    40 */    65,   66,   67,   68,   69,   70,   71,   72,   73,   74,
+ /*    50 */    75,   23,   77,   78,   79,   80,   81,   82,   83,   84,
+ /*    60 */    85,   86,   10,   60,   26,   90,   77,   78,   79,   80,
+ /*    70 */    81,   82,   83,   84,   85,   86,   92,   27,  148,   95,
+ /*    80 */    96,   97,   44,  142,  143,  144,   48,   23,  147,   25,
+ /*    90 */   150,  107,   18,   90,   24,  155,  149,   94,  158,  159,
+ /*   100 */    62,   63,   64,   65,   66,   67,   68,   69,   70,   71,
+ /*   110 */    72,   73,   74,   75,  150,   77,   78,   79,   80,   81,
+ /*   120 */    82,   83,   84,   85,   86,   51,    0,   44,  177,  178,
+ /*   130 */   127,  128,  129,   83,  170,  184,   10,   11,  174,  157,
+ /*   140 */    90,   91,   10,  115,   22,   62,   63,   64,   65,   66,
+ /*   150 */    67,   68,   69,   70,   71,   72,   73,   74,   75,   27,
+ /*   160 */    77,   78,   79,   80,   81,   82,   83,   84,   85,   86,
+ /*   170 */    10,  189,   44,  209,  210,   27,  102,  103,  104,  109,
+ /*   180 */    45,  111,  112,  201,  202,   10,   11,  113,  206,  157,
+ /*   190 */    62,   63,   64,   65,   66,   67,   68,   69,   70,   71,
+ /*   200 */    72,   73,   74,   75,   94,   77,   78,   79,   80,   81,
+ /*   210 */    82,   83,   84,   85,   86,   19,  106,  134,   96,   64,
+ /*   220 */    18,  189,   90,   91,   28,  150,   83,   84,   85,   86,
+ /*   230 */    14,   15,   16,  158,  159,   39,  101,   41,   90,   91,
+ /*   240 */    92,  163,   27,   95,   96,   97,   44,   92,   93,   94,
+ /*   250 */    95,   96,   97,   98,   99,  107,  181,  182,   25,  137,
+ /*   260 */    27,  106,   64,  135,   62,   63,   64,   65,   66,   67,
+ /*   270 */    68,   69,   70,   71,   72,   73,   74,   75,  200,   77,
+ /*   280 */    78,   79,   80,   81,   82,   83,   84,   85,   86,   27,
+ /*   290 */    24,   44,   94,   95,   96,   97,   98,   99,   24,  217,
+ /*   300 */    26,  219,  220,  163,  106,   90,   91,  186,  187,   62,
+ /*   310 */    63,   64,   65,   66,   67,   68,   69,   70,   71,   72,
+ /*   320 */    73,   74,   75,   90,   77,   78,   79,   80,   81,   82,
+ /*   330 */    83,   84,   85,   86,  217,  218,  219,  220,   24,  150,
+ /*   340 */   200,  150,   19,   81,   82,   24,  110,  165,  166,  167,
+ /*   350 */   114,   28,   90,   91,   24,  144,  150,  217,  147,  219,
+ /*   360 */   220,   27,   39,  101,   41,   44,   92,   64,   23,   95,
+ /*   370 */    96,   97,   27,   10,   51,  109,  170,  111,  112,  188,
+ /*   380 */   174,  107,  135,   62,   63,   64,   65,   66,   67,   68,
+ /*   390 */    69,   70,   71,   72,   73,   74,   75,   94,   77,   78,
+ /*   400 */    79,   80,   81,   82,   83,   84,   85,   86,   24,  227,
+ /*   410 */   165,  166,  167,  150,  150,   27,  160,  149,  212,  163,
+ /*   420 */   164,   44,   10,  109,   90,  111,  112,   10,   44,  238,
+ /*   430 */   224,  201,  202,  170,  170,   90,   91,  174,  174,  109,
+ /*   440 */    23,  111,  112,   66,   67,  150,   62,   63,   64,   65,
+ /*   450 */    66,   67,   68,   69,   70,   71,   72,   73,   74,   75,
+ /*   460 */   150,   77,   78,   79,   80,   81,   82,   83,   84,   85,
+ /*   470 */    86,   94,  227,   44,  149,  212,  171,   10,   90,   91,
+ /*   480 */   170,  168,  169,  188,  174,  221,   12,  224,   71,   10,
+ /*   490 */   177,   62,   63,   64,   65,   66,   67,   68,   69,   70,
+ /*   500 */    71,   72,   73,   74,   75,  117,   77,   78,   79,   80,
+ /*   510 */    81,   82,   83,   84,   85,   86,   45,   10,   44,  150,
+ /*   520 */    10,   10,  217,   13,  219,  220,  102,  103,  104,  110,
+ /*   530 */   101,  150,  113,  150,  224,   64,   62,   63,   64,   65,
+ /*   540 */    66,   67,   68,   69,   70,   71,   72,   73,   74,   75,
+ /*   550 */   150,   77,   78,   79,   80,   81,   82,   83,   84,   85,
+ /*   560 */    86,   10,  192,   44,  183,   24,  183,   26,   10,  199,
+ /*   570 */   170,   26,  101,   24,  174,   26,  109,  106,  111,  112,
+ /*   580 */    26,   62,   63,   64,   65,   66,   67,   68,   69,   70,
+ /*   590 */    71,   72,   73,   74,   75,  226,   77,   78,   79,   80,
+ /*   600 */    81,   82,   83,   84,   85,   86,   26,  226,   44,  226,
+ /*   610 */   210,   29,  149,  169,   32,   24,  109,   26,  111,  112,
+ /*   620 */   109,  177,  111,  112,   10,   43,   62,   63,   64,   65,
+ /*   630 */    66,   67,   68,   69,   70,   71,   72,   73,   74,   75,
+ /*   640 */    91,   77,   78,   79,   80,   81,   82,   83,   84,   85,
+ /*   650 */    86,   14,   15,   44,   24,  101,   26,   10,  150,  163,
+ /*   660 */   109,  116,  111,  112,   93,   94,  117,  109,   18,  111,
+ /*   670 */   112,   91,   63,   64,   65,   66,   67,   68,   69,   70,
+ /*   680 */    71,   72,   73,   74,   75,  150,   77,   78,   79,   80,
+ /*   690 */    81,   82,   83,   84,   85,   86,  200,  117,   44,   81,
+ /*   700 */    82,  145,  146,  150,   23,  170,   23,  151,   27,  174,
+ /*   710 */    27,  158,  159,  157,   27,   24,  208,   26,   64,   65,
+ /*   720 */    66,   67,   68,   69,   70,   71,   72,   73,   74,   75,
+ /*   730 */   100,   77,   78,   79,   80,   81,   82,   83,   84,   85,
+ /*   740 */    86,  152,   23,  150,  157,  189,   27,   10,  150,  157,
+ /*   750 */   157,  216,  156,   23,  153,  157,  109,   27,  111,  112,
+ /*   760 */    24,  157,   26,  170,   24,   27,   33,  174,  170,   50,
+ /*   770 */   214,   90,  174,   90,   91,  101,  189,   90,   91,   60,
+ /*   780 */    50,  189,  189,   64,  134,   52,  136,  189,  162,  115,
+ /*   790 */    60,   25,  150,  189,   64,   21,  170,   10,  150,   21,
+ /*   800 */    81,   82,   83,   62,  117,  212,  214,  150,   89,   90,
+ /*   810 */    91,   81,   82,   94,  166,  167,  161,  224,  214,   89,
+ /*   820 */    90,   91,  230,  150,   94,  183,  225,  235,   90,   55,
+ /*   830 */   229,   57,   12,   55,  230,   57,   10,   23,  105,  235,
+ /*   840 */   183,   27,   24,  113,   26,  101,  127,  128,  129,  130,
+ /*   850 */   131,  132,  133,  150,  127,  128,  150,  127,  128,  129,
+ /*   860 */   130,  131,  132,  133,   50,   23,  125,  129,  226,   27,
+ /*   870 */   150,  150,   47,  170,   60,  227,  170,  174,   64,  150,
+ /*   880 */   174,  115,  157,  226,  102,  103,  104,   53,   54,  150,
+ /*   890 */   170,   10,   50,   23,  174,   81,   82,   27,   24,   24,
+ /*   900 */    26,   26,   60,   89,   90,   91,   64,   26,   94,  170,
+ /*   910 */   150,  137,  183,  174,  189,   24,   24,   26,   26,  216,
+ /*   920 */    50,  186,  187,   81,   82,   83,  101,  101,  171,  208,
+ /*   930 */    60,   89,   90,   91,   64,   24,   94,   26,   24,   34,
+ /*   940 */    26,  127,  128,  129,  130,  131,  132,  133,  134,   10,
+ /*   950 */   150,   81,   82,   27,  134,  226,  150,  150,  150,   89,
+ /*   960 */    90,   91,   10,  150,   94,   24,  171,   26,  208,  127,
+ /*   970 */   128,  129,  130,  131,  132,  133,  170,  170,  170,   27,
+ /*   980 */   174,  174,  174,  170,  180,   12,   60,  174,  188,   10,
+ /*   990 */    17,   18,   19,   20,  150,  150,   42,  127,  128,  129,
+ /*  1000 */   130,  131,  132,  133,   31,  124,  113,   81,   82,   10,
+ /*  1010 */    37,  172,  150,  150,  170,  150,   90,  157,  174,  126,
+ /*  1020 */    94,  150,   49,  150,   51,   46,   27,  150,  150,   56,
+ /*  1030 */   150,   58,  170,  170,   61,  170,  174,  174,  150,  174,
+ /*  1040 */   150,  170,   90,   91,  113,  174,  150,  170,  170,  189,
+ /*  1050 */   150,  174,  174,  127,  128,  129,   46,  126,  213,  150,
+ /*  1060 */   170,  188,  150,  124,  174,  150,  170,  100,  188,  171,
+ /*  1070 */   174,  150,  173,   10,  150,  102,  103,  104,  171,  170,
+ /*  1080 */   150,  108,  150,  174,  150,  150,  113,  150,  188,   90,
+ /*  1090 */    91,  170,  150,  150,  170,  174,   59,   23,  174,  150,
+ /*  1100 */   188,  213,  170,  188,  170,  170,  174,  170,  174,  174,
+ /*  1110 */   150,  174,  170,  170,  113,  150,  174,  174,  188,  170,
+ /*  1120 */   150,  150,  150,  174,  115,  189,  115,  150,  150,  191,
+ /*  1130 */   170,  124,  119,  193,  174,  170,  150,  150,  150,  174,
+ /*  1140 */   170,  170,  170,  150,  174,  174,  174,  170,  170,  157,
+ /*  1150 */   150,  174,  174,  150,  190,  150,  170,  170,  170,  121,
+ /*  1160 */   174,  174,  174,  170,  150,  150,  150,  174,  194,  122,
+ /*  1170 */   170,  150,  196,  170,  174,  170,  139,  174,  115,  174,
+ /*  1180 */   195,  189,  123,  115,  170,  170,  170,  197,  174,  174,
+ /*  1190 */   174,  170,  198,  150,  115,  174,  150,   86,   94,  150,
+ /*  1200 */   113,  113,  113,   23,  134,  222,   18,  223,   23,  187,
+ /*  1210 */    24,  150,  115,   26,   24,  150,  154,   26,  120,   99,
+ /*  1220 */   172,   27,  162,  211,  172,  120,   26,  203,  211,  117,
+ /*  1230 */   150,  150,  150,  101,  150,  204,  118,  154,  205,   23,
+ /*  1240 */   150,   24,  115,  204,   24,  205,  171,   23,  175,  150,
+ /*  1250 */   178,  150,  176,  211,  162,  211,  179,  179,  172,   24,
+ /*  1260 */   228,   46,  228,  172,  179,  170,  170,  150,   23,  163,
+ /*  1270 */    24,   23,   46,  180,  171,  173,  182,   23,  171,   98,
+ /*  1280 */   150,  106,  182,  175,  150,  176,  150,  154,   25,  154,
+ /*  1290 */   150,  154,  154,  101,   12,  231,   40,   38,  232,  101,
+ /*  1300 */   233,  137,  101,  234,   47,  150,  154,  101,  150,   23,
+ /*  1310 */   171,   10,   12,  137,  185,   18,   10,   10,  125,  150,
+ /*  1320 */   125,   18,   62,  105,  150,  194,  185,   10,  125,   71,
+ /*  1330 */   215,   23,   71,  150,   23,   10,  194,  116,   10,  150,
+ /*  1340 */    10,   10,   10,   10,  116,  194,   10,  185,  105,   10,
+ /*  1350 */   194,   10,  125,   10,  150,  150,  154,   23,  215,   10,
+ /*  1360 */    10,   10,   10,  150,   24,   10,   10,   25,   10,  150,
+ /*  1370 */    35,  163,  163,   10,   10,  150,  154,   10,   21,  150,
+ /*  1380 */   236,  150,  237,  236,   10,  138,   10,  239,  139,  240,
+ /*  1390 */   140,
 };
-#define YY_SHIFT_USE_DFLT (-76)
+#define YY_SHIFT_USE_DFLT (-70)
 static const short yy_shift_ofst[] = {
- /*     0 */    92,  208,  -76,  -76, 1349,    6,   16,  -76,  458,  123,
- /*    10 */   183,   56,  232,  -76,  -76,  -76,  -76,  -76,  -76,  123,
- /*    20 */   273,  123,  346,  123,  415,  247,  597,  456,  598,  667,
- /*    30 */   685,  107,  -76,  -25,  -76,   86,  -76,  456,  113,  -76,
- /*    40 */   689,  -76,  778,  235,  -76,  -76,  -76,  -76,  -76,  -76,
- /*    50 */   -76,  571,  689,  -76,  856,  -76,  344,  -76,  -76,  999,
- /*    60 */   102,  689,  991,  -76,  -76,  -76,  -76,  689,  -76, 1073,
- /*    70 */  1257,  146,  901,  979,  983,  -76,  987,  -76,  238,  989,
- /*    80 */   -76,  281,  -76,  449,  986, 1002,  990, 1010, 1007,  -76,
- /*    90 */  1257,   41, 1257,  638, 1257,  -76, 1017,  456, 1019,  456,
- /*   100 */   -76,  -76,  -76,  -76,  -76,  -76,  -76,  -76,  -76,  834,
- /*   110 */  1257,  768, 1257,  -10, 1257,  -10, 1257,  -10, 1257,  -10,
- /*   120 */  1257,  -53, 1257,  -53, 1257,   11, 1257,   11, 1257,   11,
- /*   130 */  1257,   11, 1257,  -49, 1257,  -49, 1257, 1049, 1257, 1049,
- /*   140 */  1257, 1049, 1257,  -76,  -76,  -76,  230,  -76,  -76,  -76,
- /*   150 */   -76,  -76, 1257,  -75, 1257,  -10,  -76,  733,  -76, 1046,
- /*   160 */   -76,  -76,  -76, 1257,  703, 1257,  -53,  -76,  307,  987,
- /*   170 */   314,   38, 1033, 1034, 1035,  -76,  638, 1257,  834, 1257,
- /*   180 */   -76, 1257,  -76, 1257,  -76, 1129,  989,  319,  -76, 1079,
- /*   190 */    90, 1016,  537, 1138,  -76, 1257,  163, 1257,  638, 1134,
- /*   200 */   376, 1136,  -76, 1132,  456, 1137,  -76, 1257,  237, 1257,
- /*   210 */   301, 1257,  638,  711,  -76, 1257,  -76,  -76, 1047,  456,
- /*   220 */   -76,  -76,  -76, 1257,  638, 1045, 1257, 1143, 1257, 1068,
- /*   230 */   102,  -76, 1148,  -76,  -76,  638, 1068,  102,  -76, 1257,
- /*   240 */   638, 1057, 1257, 1156, 1257,  638,  -76,  -76,  509,  -76,
- /*   250 */   -76,  -76,  385,  -76,  439,  -76, 1065,  -76,  387, 1047,
- /*   260 */   405,  -76,  -76,  456,  -76,  -76, 1082, 1071,  -76, 1170,
- /*   270 */   456,  780,  -76,  456,  -76,  -76, 1257,  638,  989,  389,
- /*   280 */   443, 1172,  405, 1082, 1071,  -76, 1171,  -24,  -76,  -76,
- /*   290 */  1084,   53,  -76,  -76,  -76,  -76,  375,  -76,  841,  -76,
- /*   300 */  1173,  -76,  441,  689,  -76,  456, 1182,  -76,  635,  -76,
- /*   310 */   456,  -76,  521,  649,  -76,  735,  -76,  -76,  -76,  -76,
- /*   320 */   649,  -76,  649,  -76,  456,  943,  -76,  456, 1068,  102,
- /*   330 */   -76,  -76, 1068,  102,  -76,  -76, 1148,  -76,  856,  -76,
- /*   340 */   -76,  912,  -76,  128,  -76,  -76,  128,  -76,  -76,   -8,
- /*   350 */   846,  966,  -76,  846, 1193,  -76,  -76,  -76,  414,  -76,
- /*   360 */   -76,  -76,  414,  -76,  -76,  -76,  -76,  -76,   -6,   42,
- /*   370 */   -76,  456,  -76, 1192, 1196,  456,  721, 1216,  689,  -76,
- /*   380 */  1222,  456,  992,  689,  -76, 1257,  506,  -76, 1201, 1227,
- /*   390 */   456, 1004, 1150,  456, 1182,  -76,  453, 1145,  -76,  -76,
- /*   400 */   -76,  -76,  -76,  989,  428,  593,  745,  456, 1047,  -76,
- /*   410 */   456,  729, 1237,  989,  486,  456, 1047,  900,  525, 1166,
- /*   420 */   456, 1047,  -76, 1231,  622, 1261, 1257,  573, 1236,  917,
- /*   430 */   -76,  -76, 1174, 1175,  437,  456,  773,  -76,  -76, 1228,
- /*   440 */   -76,  -76, 1135,  456,  755, 1177,  456, 1260,  456, 1032,
- /*   450 */   903, 1276, 1147, 1277,  174,  490,  326,  235,  -76, 1164,
- /*   460 */  1165, 1278, 1284, 1285,  174, 1279, 1233,  456, 1191,  456,
- /*   470 */   956,  456, 1238, 1257,  638, 1305, 1242, 1257,  638, 1189,
- /*   480 */   456, 1299,  456, 1036,  -76,  360,  551, 1300, 1257, 1042,
- /*   490 */  1257,  638, 1316,  638, 1209,  456,  601, 1320,  240,  456,
- /*   500 */  1321,  456, 1322,  456, 1323,  456, 1324,  557, 1217,  456,
- /*   510 */   601, 1328, 1233,  456, 1232,  456,  956, 1333, 1218,  456,
- /*   520 */  1299,  970,  586, 1325, 1257, 1063, 1335,  460, 1342,  456,
- /*   530 */  1047,  788,  172, 1346, 1347, 1350, 1352,  456, 1339, 1354,
- /*   540 */  1330,  -25, 1348,  456, 1078, 1364,  845, 1366, 1367,  -76,
- /*   550 */  1330,  456, 1368,  542, 1081, 1372, 1362,  456, 1336, 1254,
- /*   560 */   456, 1388,  -76,  -76,
+ /*     0 */   175,  126,  -70,  -70,  973,    8,   52,  -70,  216,  510,
+ /*    10 */   160,  132,  363,  -70,  -70,  -70,  -70,  -70,  -70,  510,
+ /*    20 */   412,  510,  479,  510,  614,   64,  737,  215,  541,  740,
+ /*    30 */   787,  148,  -70,  334,  -70,  155,  -70,  215,  198,  -70,
+ /*    40 */   744,  -70,  905,  323,  -70,  -70,  -70,  -70,  -70,  -70,
+ /*    50 */   -70,  110,  744,  -70,  954,  -70,  637,  -70,  -70, 1010,
+ /*    60 */   -29,  744,  967,  -70,  -70,  -70,  -70,  744,  -70, 1074,
+ /*    70 */   870,   28,  719, 1009, 1011,  -70,  730,  -70,   70, 1001,
+ /*    80 */   -70,  236,  -70,  545, 1007, 1038, 1047, 1013, 1059,  -70,
+ /*    90 */   870,   38,  870,  519,  870,  -70, 1068,  215, 1079,  215,
+ /*   100 */   -70,  -70,  -70,  -70,  -70,  -70,  -70,  654,  870,  609,
+ /*   110 */   870,  -11,  870,  -11,  870,  -11,  870,  -11,  870,  -69,
+ /*   120 */   870,  -69,  870,  -50,  870,  -50,  870,  -50,  870,  -50,
+ /*   130 */   870,  143,  870,  143,  870, 1111,  870, 1111,  870, 1111,
+ /*   140 */   870,  -70,  -70,  377,  -70,  -70,  -70,  -70,  870,  -56,
+ /*   150 */   870,  -11,  -70,  303,  -70, 1104,  -70,  -70,  -70,  870,
+ /*   160 */   564,  870,  -69,  -70,  345,  730,  266,  419, 1087, 1088,
+ /*   170 */  1089,  -70,  519,  870,  654,  870,  -70,  870,  -70,  870,
+ /*   180 */   -70, 1180, 1001,  314,  -70,  814,   83, 1070,  650, 1188,
+ /*   190 */   -70,  870,  128,  870,  519, 1185,  196, 1186,  -70, 1187,
+ /*   200 */   215, 1190,  -70,  870,  202,  870,  247,  870,  519,  591,
+ /*   210 */   -70,  870,  -70,  -70, 1097,  215,  -70,  -70,  -70,  870,
+ /*   220 */   519, 1098,  870, 1191,  870, 1120,  -29,  -70, 1194,  -70,
+ /*   230 */   -70,  519, 1120,  -29,  -70,  870,  519, 1105,  870, 1200,
+ /*   240 */   870,  519,  -70,  -70,  580,  -70,  -70,  -70,  388,  -70,
+ /*   250 */   687,  -70, 1112,  -70,  683, 1097,  233,  -70,  -70,  215,
+ /*   260 */   -70,  -70, 1132, 1118,  -70, 1216,  215,  691,  -70,  215,
+ /*   270 */   -70,  -70,  870,  519, 1001,  330,  549, 1217,  233, 1132,
+ /*   280 */  1118,  -70,  842,  -25,  -70,  -70, 1127,   50,  -70,  -70,
+ /*   290 */   -70,  -70,  321,  -70,  736,  -70, 1220,  -70,  384,  744,
+ /*   300 */   -70,  215, 1224,  -70,  135,  -70,  215,  -70,  424,  733,
+ /*   310 */   -70,  571,  -70,  -70,  -70,  -70,  733,  -70,  733,  -70,
+ /*   320 */   215,  818,  -70,  215, 1120,  -29,  -70,  -70, 1120,  -29,
+ /*   330 */   -70,  -70, 1194,  -70,  954,  -70,  -70,  926,  -70,    3,
+ /*   340 */   -70,  -70,    3,  -70,  -70,  681,  618,  874,  -70,  618,
+ /*   350 */  1235,  -70,  -70,  -70,  727,  -70,  -70,  -70,  727,  -70,
+ /*   360 */   -70,  -70,  -70,  -70,  274,  -16,  -70,  215,  -70, 1215,
+ /*   370 */  1245,  215,  630, 1246,  744,  -70, 1248,  215,  875,  744,
+ /*   380 */   -70,  870,  429,  -70, 1226, 1254,  215,  891, 1181,  215,
+ /*   390 */  1224,  -70,  471, 1175,  -70,  -70,  -70,  -70,  -70, 1001,
+ /*   400 */   467,  122,  778,  215, 1097,  -70,  215,  766, 1263, 1001,
+ /*   410 */   507,  215, 1097,  582,  782, 1192,  215, 1097,  -70, 1256,
+ /*   420 */   820, 1282,  870,  474, 1259,  834,  -70,  -70, 1198, 1201,
+ /*   430 */   825,  215,  554,  -70,  -70, 1257,  -70,  -70, 1164,  215,
+ /*   440 */   674, 1206,  215, 1286,  215,  892,  826, 1301, 1176, 1300,
+ /*   450 */    74,  511,  741,  323,  -70, 1193, 1195, 1297, 1306, 1307,
+ /*   460 */    74, 1303, 1260,  215, 1218,  215,  881,  215, 1258,  870,
+ /*   470 */   519, 1317, 1261,  870,  519, 1203,  215, 1308,  215,  911,
+ /*   480 */   -70,  893,  551, 1311,  870,  914,  870,  519, 1325,  519,
+ /*   490 */  1221,  215,  939, 1328,  774,  215, 1330,  215, 1331,  215,
+ /*   500 */  1332,  215, 1333,  558, 1228,  215,  939, 1336, 1260,  215,
+ /*   510 */  1243,  215,  881, 1339, 1227,  215, 1308,  931,  647, 1334,
+ /*   520 */   870,  941, 1341,  952, 1343,  215, 1097,  417,  262, 1349,
+ /*   530 */  1350, 1351, 1352,  215, 1340, 1355, 1335,  334, 1342,  215,
+ /*   540 */   979, 1356,  738, 1358, 1363,  -70, 1335,  215, 1364,  999,
+ /*   550 */  1063, 1367, 1357,  215, 1037, 1247,  215, 1374, 1249, 1250,
+ /*   560 */   215, 1376,  -70,  -70,  -70,
 };
-#define YY_REDUCE_USE_DFLT (-95)
+#define YY_REDUCE_USE_DFLT (-71)
 static const short yy_reduce_ofst[] = {
- /*     0 */     0,  -61,  -95,  -95,  202,  -95,  -95,  -95,  -94,  -59,
- /*    10 */   -95,   52,  -95,  -95,  -95,  -95,  -95,  -95,  -95,  103,
- /*    20 */   -95,  189,  -95,  261,  -95,  349,  -95,  185,  520,  -95,
- /*    30 */   -95,  109,  -95,   33,  576,  116,  -95,  595,  162,  -95,
- /*    40 */   636,  -95,  -95,   36,  -95,  -95,  -95,  -95,  -95,  -95,
- /*    50 */   -95,  -95,  655,  -95,  761,  -95,  -95,  -95,  -95,  -95,
- /*    60 */   805,  921,  924,  -95,  -95,  -95,  -95,  928,  -95,  -95,
- /*    70 */   446,  -95,  122,  -95,  -95,  -95,  -70,  -95,  913,  920,
- /*    80 */   -95,  935,  496,  915,  936,  933,  937,  938,  940,  -95,
- /*    90 */   448,  388,  513,  388,  519,  -95,  -95,  993,  -95,  996,
- /*   100 */   -95,  -95,  -95,  -95,  -95,  -95,  -95,  -95,  -95,  388,
- /*   110 */   522,  388,  578,  388,  580,  388,  581,  388,  589,  388,
- /*   120 */   590,  388,  643,  388,  644,  388,  645,  388,  646,  388,
- /*   130 */   651,  388,  654,  388,  707,  388,  709,  388,  710,  388,
- /*   140 */   712,  388,  715,  388,  -95,  -95,  -95,  -95,  -95,  -95,
- /*   150 */   -95,  -95,  717,  188,  718,  388,  -95,  -95,  -95,  -95,
- /*   160 */   -95,  -95,  -95,  720,  388,  723,  388,  -95,  997,  462,
- /*   170 */   913,  -95,  -95,  -95,  -95,  -95,  388,  725,  388,  774,
- /*   180 */   388,  775,  388,  776,  388,  -95,  572,  913,  -95,   45,
- /*   190 */   388,  932,  930,  -95,  -95,  782,  388,  783,  388,  -95,
- /*   200 */   971,  -95,  -95,  -95, 1011,  -95,  -95,  784,  388,  785,
- /*   210 */   388,  790,  388,  -95,  -95,  252,  -95,  -95, 1012, 1015,
- /*   220 */   -95,  -95,  -95,  828,  388,  -95,  186,  -95,  320,  962,
- /*   230 */  1005,  -95, 1014,  -95,  -95,  388,  967, 1008,  -95,  829,
- /*   240 */   388,  -95,  180,  -95,  837,  388,  -95,  291,  980,  -95,
- /*   250 */   -95,  -95, 1037,  -95, 1038,  -95,  -95,  -95, 1039, 1028,
- /*   260 */   535,  -95,  -95, 1040,  -95,  -95,  982,  994,  -95,  -95,
- /*   270 */   407,  -95,  -95, 1044,  -95,  -95,  840,  388,  126,  913,
- /*   280 */   980,  -95,  669,  998,  995,  -95,  850,  201,  -95,  -95,
- /*   290 */   -95,  993,  -95,  -95,  -95,  -95,  388,  -95,  -95,  -95,
- /*   300 */   -95,  -95,  388, 1048,  -95, 1053, 1030, 1031, 1050,  -95,
- /*   310 */  1056,  -95,  -95, 1041,  -95,  -95,  -95,  -95,  -95,  -95,
- /*   320 */  1043,  -95, 1051,  -95,  583,  -95,  -95,  516, 1006, 1052,
- /*   330 */   -95,  -95, 1018, 1054,  -95,  -95, 1061,  -95, 1055,  -95,
- /*   340 */   -95,  515,  -95, 1064,  -95,  -95, 1066,  -95,  -95, 1062,
- /*   350 */   196,  -95,  -95,  269,  -95,  -95,  -95,  -95, 1013,  -95,
- /*   360 */   -95,  -95, 1020,  -95,  -95,  -95,  -95,  -95, 1058, 1060,
- /*   370 */   -95, 1077,  -95,  -95,  -95,  713, 1070,  -95, 1074,  -95,
- /*   380 */   -95,  786,  -95, 1075,  -95,  851,  318,  -95,  -95,  -95,
- /*   390 */   792,  -95,  -95, 1101, 1083, 1076,  110,  -95,  -95,  -95,
- /*   400 */   -95,  -95,  -95,  865,  913,  330,  -95, 1107, 1105,  -95,
- /*   410 */  1110, 1111,  -95,  887,  913, 1116, 1114, 1059, 1067,  -95,
- /*   420 */   878, 1117,  -95, 1080, 1086,  -95,  869,  388,  -95,  -95,
- /*   430 */   -95,  -95,  -95,  -95,  -95,  855,  -95,  -95,  -95,  -95,
- /*   440 */   -95,  -95,  -95, 1126, 1127,  -95, 1139,  -95,  797,  -95,
- /*   450 */  1113,  -95,  -95,  -95,  527,  913, 1102,  796,  -95,  -95,
- /*   460 */   -95,  -95,  -95,  -95,  592,  -95, 1123, 1159,  -95,  838,
- /*   470 */  1118, 1160,  -95,  876,  388,  -95,  -95,  888,  388,  -95,
- /*   480 */  1176, 1109,  866,  -95,  -95,  895,  913,  -95,  317,  -95,
- /*   490 */   890,  388,  -95,  388,  -95, 1178, 1140,  -95,  -95,  906,
- /*   500 */   -95,  918,  -95,  919,  -95,  922,  -95,  913,  -95,  923,
- /*   510 */  1142,  -95, 1153,  925,  -95,  931, 1149,  -95,  -95,  927,
- /*   520 */  1131,  934,  913,  -95,  395,  -95,  -95, 1202,  -95, 1204,
- /*   530 */  1203,  -95,  397,  -95,  -95,  -95,  -95, 1208,  -95,  -95,
- /*   540 */  1133, 1207,  -95, 1221, 1141,  -95, 1211,  -95,  -95,  -95,
- /*   550 */  1144, 1234,  -95, 1243, 1229,  -95,  -95,  939,  -95,  -95,
- /*   560 */  1246,  -95,  -95,  -95,
+ /*     0 */   -59,  211,  -71,  -71,  556,  -71,  -71,  -71,  -70,  -53,
+ /*    10 */   -71,  189,  -71,  -71,  -71,  -71,  -71,  -71,  -71,  268,
+ /*    20 */   -71,  325,  -71,  463,  -71,  589,  -71,  -60,  596,  -71,
+ /*    30 */   -71,   75,  -71,  256,  655,  313,  -71,  673,  444,  -71,
+ /*    40 */   757,  -71,  -71,  121,  -71,  -71,  -71,  -71,  -71,  -71,
+ /*    50 */   -71,  -71,  795,  -71,  804,  -71,  -71,  -71,  -71,  -71,
+ /*    60 */   839,  898,  899,  -71,  -71,  -71,  -71,  907,  -71,  -71,
+ /*    70 */   706,  -71,  206,  -71,  -71,  -71,  598,  -71,  964,  936,
+ /*    80 */   -71,  938,  370,  940,  974,  985,  976,  990,  994,  -71,
+ /*    90 */   720,   82,  739,   82,  806,  -71,  -71, 1043,  -71, 1046,
+ /*   100 */   -71,  -71,  -71,  -71,  -71,  -71,  -71,   82,  807,   82,
+ /*   110 */   813,   82,  844,   82,  862,   82,  863,   82,  865,   82,
+ /*   120 */   871,   82,  877,   82,  878,   82,  890,   82,  896,   82,
+ /*   130 */   909,   82,  921,   82,  924,   82,  932,   82,  934,   82,
+ /*   140 */   935,   82,  -71,  -71,  -71,  -71,  -71,  -71,  937,  117,
+ /*   150 */   942,   82,  -71,  -71,  -71,  -71,  -71,  -71,  -71,  943,
+ /*   160 */    82,  949,   82,  -71, 1049,  593,  964,  -71,  -71,  -71,
+ /*   170 */   -71,  -71,   82,  960,   82,  965,   82,  970,   82,  971,
+ /*   180 */    82,  -71,   32,  964,  -71,  264,   82,  983,  984,  -71,
+ /*   190 */   -71,  972,   82,  977,   82,  -71, 1022,  -71,  -71,  -71,
+ /*   200 */  1061,  -71,  -71,  978,   82,  986,   82,  987,   82,  -71,
+ /*   210 */   -71,  310,  -71,  -71, 1062, 1065,  -71,  -71,  -71,  988,
+ /*   220 */    82,  -71,  -36,  -71,  400, 1012, 1048,  -71, 1060,  -71,
+ /*   230 */   -71,   82, 1017, 1052,  -71,  993,   82,  -71,  263,  -71,
+ /*   240 */  1000,   82,  -71,  230, 1024,  -71,  -71,  -71, 1080,  -71,
+ /*   250 */  1081,  -71,  -71,  -71, 1082, 1083,   78,  -71,  -71, 1084,
+ /*   260 */   -71,  -71, 1031, 1033,  -71,  -71,  508,  -71,  -71, 1090,
+ /*   270 */   -71,  -71, 1003,   82,  -18,  964, 1024,  -71,  496, 1039,
+ /*   280 */  1040,  -71, 1005,  140,  -71,  -71,  -71, 1043,  -71,  -71,
+ /*   290 */   -71,  -71,   82,  -71,  -71,  -71,  -71,  -71,   82, 1075,
+ /*   300 */   -71, 1099, 1073, 1076, 1072,  -71, 1101,  -71,  -71, 1077,
+ /*   310 */   -71,  -71,  -71,  -71,  -71,  -71, 1078,  -71, 1085,  -71,
+ /*   320 */   381,  -71,  -71,  369, 1042, 1086,  -71,  -71, 1044, 1091,
+ /*   330 */   -71,  -71, 1092,  -71, 1093,  -71,  -71,  626,  -71, 1095,
+ /*   340 */   -71,  -71, 1096,  -71,  -71, 1106,  182,  -71,  -71,  245,
+ /*   350 */   -71,  -71,  -71,  -71, 1032,  -71,  -71,  -71, 1034,  -71,
+ /*   360 */   -71,  -71,  -71,  -71, 1094, 1100,  -71, 1117,  -71,  -71,
+ /*   370 */   -71,  383, 1102,  -71, 1103,  -71,  -71,  642,  -71, 1107,
+ /*   380 */   -71, 1014,  305,  -71,  -71,  -71,  657,  -71,  -71, 1130,
+ /*   390 */  1108, 1109,  -49,  -71,  -71,  -71,  -71,  -71,  -71,  587,
+ /*   400 */   964,  601,  -71, 1134, 1133,  -71, 1136, 1135,  -71,  725,
+ /*   410 */   964, 1140, 1137, 1064, 1066,  -71,  295, 1138,  -71, 1067,
+ /*   420 */  1069,  -71,  808,   82,  -71,  -71,  -71,  -71,  -71,  -71,
+ /*   430 */   -71,  721,  -71,  -71,  -71,  -71,  -71,  -71,  -71, 1155,
+ /*   440 */  1152,  -71, 1158,  -71,  729,  -71, 1139,  -71,  -71,  -71,
+ /*   450 */   592,  964, 1129,  735,  -71,  -71,  -71,  -71,  -71,  -71,
+ /*   460 */   604,  -71, 1141, 1169,  -71,  845, 1131, 1174,  -71, 1015,
+ /*   470 */    82,  -71,  -71, 1016,   82,  -71, 1183, 1115,  760,  -71,
+ /*   480 */   -71,  860,  964,  -71,  535,  -71, 1021,   82,  -71,   82,
+ /*   490 */   -71, 1189, 1142,  -71,  -71,  800,  -71,  873,  -71,  880,
+ /*   500 */   -71,  900,  -71,  964,  -71,  912, 1151,  -71, 1162,  915,
+ /*   510 */   -71,  888, 1156,  -71,  -71,  930, 1143,  992,  964,  -71,
+ /*   520 */   703,  -71,  -71, 1204,  -71, 1205, 1202,  -71,  648,  -71,
+ /*   530 */   -71,  -71,  -71, 1213,  -71,  -71, 1144, 1208,  -71, 1219,
+ /*   540 */  1145,  -71, 1209,  -71,  -71,  -71, 1147, 1225,  -71, 1229,
+ /*   550 */  1222,  -71,  -71,  191,  -71,  -71, 1231,  -71,  -71, 1148,
+ /*   560 */   553,  -71,  -71,  -71,  -71,
 };
 static const YYACTIONTYPE yy_default[] = {
- /*     0 */   570,  570,  565,  568,  869,  869,  869,  569,  576,  869,
- /*    10 */   869,  869,  869,  596,  597,  598,  577,  578,  579,  869,
- /*    20 */   869,  869,  869,  869,  869,  869,  869,  869,  869,  869,
- /*    30 */   869,  869,  589,  599,  608,  591,  607,  869,  869,  609,
- /*    40 */   652,  615,  869,  869,  653,  656,  657,  658,  855,  856,
- /*    50 */   857,  869,  652,  616,  637,  635,  869,  638,  639,  869,
- /*    60 */   708,  652,  623,  617,  624,  706,  707,  652,  618,  869,
- /*    70 */   869,  738,  807,  744,  739,  735,  869,  663,  869,  869,
- /*    80 */   664,  672,  674,  681,  720,  711,  713,  701,  715,  669,
- /*    90 */   869,  716,  869,  717,  869,  737,  869,  869,  740,  869,
- /*   100 */   741,  742,  743,  745,  746,  747,  750,  751,  752,  753,
- /*   110 */   869,  754,  869,  755,  869,  756,  869,  757,  869,  758,
- /*   120 */   869,  759,  869,  760,  869,  761,  869,  762,  869,  763,
- /*   130 */   869,  764,  869,  765,  869,  766,  869,  767,  869,  768,
- /*   140 */   869,  769,  869,  770,  771,  772,  869,  773,  774,  781,
- /*   150 */   788,  791,  869,  776,  869,  775,  778,  869,  779,  869,
- /*   160 */   782,  780,  787,  869,  869,  869,  789,  790,  869,  807,
- /*   170 */   869,  869,  869,  869,  869,  794,  806,  869,  783,  869,
- /*   180 */   784,  869,  785,  869,  786,  869,  869,  869,  796,  869,
- /*   190 */   869,  869,  869,  869,  797,  869,  869,  869,  798,  869,
- /*   200 */   869,  869,  853,  869,  869,  869,  854,  869,  869,  869,
- /*   210 */   869,  869,  799,  869,  792,  807,  804,  805,  689,  869,
- /*   220 */   690,  795,  777,  869,  718,  869,  869,  702,  869,  709,
- /*   230 */   708,  703,  869,  593,  710,  705,  709,  708,  704,  869,
- /*   240 */   714,  869,  807,  712,  869,  721,  673,  684,  682,  683,
- /*   250 */   692,  693,  869,  694,  869,  695,  869,  696,  869,  689,
- /*   260 */   680,  594,  595,  869,  678,  679,  698,  700,  685,  869,
- /*   270 */   869,  869,  699,  869,  733,  734,  869,  697,  684,  869,
- /*   280 */   869,  869,  680,  698,  700,  686,  869,  680,  675,  676,
- /*   290 */   869,  869,  677,  670,  671,  793,  869,  736,  869,  748,
- /*   300 */   869,  749,  869,  652,  619,  869,  811,  625,  620,  626,
- /*   310 */   869,  627,  869,  869,  628,  869,  631,  632,  633,  634,
- /*   320 */   869,  629,  869,  630,  869,  869,  812,  869,  709,  708,
- /*   330 */   813,  815,  709,  708,  814,  621,  869,  622,  637,  636,
- /*   340 */   610,  869,  611,  869,  612,  744,  869,  613,  614,  600,
- /*   350 */   830,  869,  601,  830,  869,  602,  605,  606,  869,  825,
- /*   360 */   827,  828,  869,  826,  829,  604,  603,  592,  869,  869,
- /*   370 */   642,  869,  645,  869,  869,  869,  869,  869,  652,  646,
- /*   380 */   869,  869,  869,  652,  647,  869,  652,  648,  869,  869,
- /*   390 */   869,  869,  869,  869,  811,  625,  650,  869,  649,  651,
- /*   400 */   643,  644,  590,  869,  869,  586,  869,  869,  689,  584,
- /*   410 */   869,  869,  869,  869,  869,  869,  689,  836,  869,  869,
- /*   420 */   869,  689,  691,  841,  869,  869,  869,  869,  869,  869,
- /*   430 */   842,  843,  869,  869,  869,  869,  869,  833,  834,  869,
- /*   440 */   835,  585,  869,  869,  869,  869,  869,  869,  869,  869,
- /*   450 */   869,  869,  869,  869,  869,  869,  869,  869,  655,  869,
- /*   460 */   869,  869,  869,  869,  869,  869,  654,  869,  869,  869,
- /*   470 */   869,  869,  869,  869,  723,  869,  869,  869,  724,  869,
- /*   480 */   869,  731,  869,  869,  732,  869,  869,  869,  869,  869,
- /*   490 */   869,  729,  869,  730,  869,  869,  869,  869,  869,  869,
- /*   500 */   869,  869,  869,  869,  869,  869,  869,  869,  869,  869,
- /*   510 */   869,  869,  654,  869,  869,  869,  869,  869,  869,  869,
- /*   520 */   731,  869,  869,  869,  869,  869,  869,  869,  869,  869,
- /*   530 */   689,  869,  830,  869,  869,  869,  869,  869,  869,  869,
- /*   540 */   864,  869,  869,  869,  869,  869,  869,  869,  869,  863,
- /*   550 */   864,  869,  869,  869,  869,  869,  869,  869,  869,  869,
- /*   560 */   869,  869,  571,  566,
+ /*     0 */   571,  571,  566,  569,  870,  870,  870,  570,  577,  870,
+ /*    10 */   870,  870,  870,  597,  598,  599,  578,  579,  580,  870,
+ /*    20 */   870,  870,  870,  870,  870,  870,  870,  870,  870,  870,
+ /*    30 */   870,  870,  590,  600,  609,  592,  608,  870,  870,  610,
+ /*    40 */   653,  616,  870,  870,  654,  657,  658,  659,  852,  853,
+ /*    50 */   854,  870,  653,  617,  638,  636,  870,  639,  640,  870,
+ /*    60 */   709,  653,  624,  618,  625,  707,  708,  653,  619,  870,
+ /*    70 */   870,  739,  804,  745,  740,  736,  870,  664,  870,  870,
+ /*    80 */   665,  673,  675,  682,  721,  712,  714,  702,  716,  670,
+ /*    90 */   870,  717,  870,  718,  870,  738,  870,  870,  741,  870,
+ /*   100 */   742,  743,  744,  746,  747,  748,  751,  752,  870,  753,
+ /*   110 */   870,  754,  870,  755,  870,  756,  870,  757,  870,  758,
+ /*   120 */   870,  759,  870,  760,  870,  761,  870,  762,  870,  763,
+ /*   130 */   870,  764,  870,  765,  870,  766,  870,  767,  870,  768,
+ /*   140 */   870,  769,  770,  870,  771,  778,  785,  788,  870,  773,
+ /*   150 */   870,  772,  775,  870,  776,  870,  779,  777,  784,  870,
+ /*   160 */   870,  870,  786,  787,  870,  804,  870,  870,  870,  870,
+ /*   170 */   870,  791,  803,  870,  780,  870,  781,  870,  782,  870,
+ /*   180 */   783,  870,  870,  870,  793,  870,  870,  870,  870,  870,
+ /*   190 */   794,  870,  870,  870,  795,  870,  870,  870,  850,  870,
+ /*   200 */   870,  870,  851,  870,  870,  870,  870,  870,  796,  870,
+ /*   210 */   789,  804,  801,  802,  690,  870,  691,  792,  774,  870,
+ /*   220 */   719,  870,  870,  703,  870,  710,  709,  704,  870,  594,
+ /*   230 */   711,  706,  710,  709,  705,  870,  715,  870,  804,  713,
+ /*   240 */   870,  722,  674,  685,  683,  684,  693,  694,  870,  695,
+ /*   250 */   870,  696,  870,  697,  870,  690,  681,  595,  596,  870,
+ /*   260 */   679,  680,  699,  701,  686,  870,  870,  870,  700,  870,
+ /*   270 */   734,  735,  870,  698,  685,  870,  870,  870,  681,  699,
+ /*   280 */   701,  687,  870,  681,  676,  677,  870,  870,  678,  671,
+ /*   290 */   672,  790,  870,  737,  870,  749,  870,  750,  870,  653,
+ /*   300 */   620,  870,  808,  626,  621,  627,  870,  628,  870,  870,
+ /*   310 */   629,  870,  632,  633,  634,  635,  870,  630,  870,  631,
+ /*   320 */   870,  870,  809,  870,  710,  709,  810,  812,  710,  709,
+ /*   330 */   811,  622,  870,  623,  638,  637,  611,  870,  612,  870,
+ /*   340 */   613,  745,  870,  614,  615,  601,  827,  870,  602,  827,
+ /*   350 */   870,  603,  606,  607,  870,  822,  824,  825,  870,  823,
+ /*   360 */   826,  605,  604,  593,  870,  870,  643,  870,  646,  870,
+ /*   370 */   870,  870,  870,  870,  653,  647,  870,  870,  870,  653,
+ /*   380 */   648,  870,  653,  649,  870,  870,  870,  870,  870,  870,
+ /*   390 */   808,  626,  651,  870,  650,  652,  644,  645,  591,  870,
+ /*   400 */   870,  587,  870,  870,  690,  585,  870,  870,  870,  870,
+ /*   410 */   870,  870,  690,  833,  870,  870,  870,  690,  692,  838,
+ /*   420 */   870,  870,  870,  870,  870,  870,  839,  840,  870,  870,
+ /*   430 */   870,  870,  870,  830,  831,  870,  832,  586,  870,  870,
+ /*   440 */   870,  870,  870,  870,  870,  870,  870,  870,  870,  870,
+ /*   450 */   870,  870,  870,  870,  656,  870,  870,  870,  870,  870,
+ /*   460 */   870,  870,  655,  870,  870,  870,  870,  870,  870,  870,
+ /*   470 */   724,  870,  870,  870,  725,  870,  870,  732,  870,  870,
+ /*   480 */   733,  870,  870,  870,  870,  870,  870,  730,  870,  731,
+ /*   490 */   870,  870,  870,  870,  870,  870,  870,  870,  870,  870,
+ /*   500 */   870,  870,  870,  870,  870,  870,  870,  870,  655,  870,
+ /*   510 */   870,  870,  870,  870,  870,  870,  732,  870,  870,  870,
+ /*   520 */   870,  870,  870,  870,  870,  870,  690,  870,  827,  870,
+ /*   530 */   870,  870,  870,  870,  870,  870,  861,  870,  870,  870,
+ /*   540 */   870,  870,  870,  870,  870,  860,  861,  870,  870,  870,
+ /*   550 */   870,  870,  870,  870,  870,  870,  870,  870,  870,  868,
+ /*   560 */   870,  870,  869,  572,  567,
 };
 #define YY_SZ_ACTTAB (sizeof(yy_action)/sizeof(yy_action[0]))
 
@@ -674,61 +660,59 @@ static const YYCODETYPE yyFallback[] = {
     0,  /*   FUNCTION => nothing */
     0,  /*     COLUMN => nothing */
     0,  /* AGG_FUNCTION => nothing */
+    0,  /* CONST_FUNC => nothing */
     0,  /*       SEMI => nothing */
-   26,  /*    EXPLAIN => ID */
-   26,  /*      BEGIN => ID */
+   27,  /*    EXPLAIN => ID */
+   27,  /*      BEGIN => ID */
     0,  /* TRANSACTION => nothing */
-   26,  /*   DEFERRED => ID */
-   26,  /*  IMMEDIATE => ID */
-   26,  /*  EXCLUSIVE => ID */
+   27,  /*   DEFERRED => ID */
+   27,  /*  IMMEDIATE => ID */
+   27,  /*  EXCLUSIVE => ID */
     0,  /*     COMMIT => nothing */
-   26,  /*        END => ID */
+   27,  /*        END => ID */
     0,  /*   ROLLBACK => nothing */
     0,  /*     CREATE => nothing */
     0,  /*      TABLE => nothing */
-   26,  /*       TEMP => ID */
+   27,  /*       TEMP => ID */
     0,  /*         LP => nothing */
     0,  /*         RP => nothing */
     0,  /*         AS => nothing */
     0,  /*      COMMA => nothing */
     0,  /*         ID => nothing */
-   26,  /*      ABORT => ID */
-   26,  /*      AFTER => ID */
-   26,  /*        ASC => ID */
-   26,  /*     ATTACH => ID */
-   26,  /*     BEFORE => ID */
-   26,  /*    CASCADE => ID */
-   26,  /*   CONFLICT => ID */
-   26,  /*   DATABASE => ID */
-   26,  /*       DESC => ID */
-   26,  /*     DETACH => ID */
-   26,  /*       EACH => ID */
-   26,  /*       FAIL => ID */
-   26,  /*        FOR => ID */
-   26,  /*       GLOB => ID */
-   26,  /*     IGNORE => ID */
-   26,  /*  INITIALLY => ID */
-   26,  /*    INSTEAD => ID */
-   26,  /*       LIKE => ID */
-   26,  /*      MATCH => ID */
-   26,  /*        KEY => ID */
-   26,  /*         OF => ID */
-   26,  /*     OFFSET => ID */
-   26,  /*     PRAGMA => ID */
-   26,  /*      RAISE => ID */
-   26,  /*    REPLACE => ID */
-   26,  /*   RESTRICT => ID */
-   26,  /*        ROW => ID */
-   26,  /*  STATEMENT => ID */
-   26,  /*    TRIGGER => ID */
-   26,  /*     VACUUM => ID */
-   26,  /*       VIEW => ID */
-   26,  /*    REINDEX => ID */
-   26,  /*     RENAME => ID */
-   26,  /*      CDATE => ID */
-   26,  /*      CTIME => ID */
-   26,  /* CTIMESTAMP => ID */
-   26,  /*      ALTER => ID */
+   27,  /*      ABORT => ID */
+   27,  /*      AFTER => ID */
+   27,  /*        ASC => ID */
+   27,  /*     ATTACH => ID */
+   27,  /*     BEFORE => ID */
+   27,  /*    CASCADE => ID */
+   27,  /*   CONFLICT => ID */
+   27,  /*   DATABASE => ID */
+   27,  /*       DESC => ID */
+   27,  /*     DETACH => ID */
+   27,  /*       EACH => ID */
+   27,  /*       FAIL => ID */
+   27,  /*        FOR => ID */
+   27,  /*     IGNORE => ID */
+   27,  /*  INITIALLY => ID */
+   27,  /*    INSTEAD => ID */
+   27,  /*    LIKE_KW => ID */
+   27,  /*      MATCH => ID */
+   27,  /*        KEY => ID */
+   27,  /*         OF => ID */
+   27,  /*     OFFSET => ID */
+   27,  /*     PRAGMA => ID */
+   27,  /*      RAISE => ID */
+   27,  /*    REPLACE => ID */
+   27,  /*   RESTRICT => ID */
+   27,  /*        ROW => ID */
+   27,  /*  STATEMENT => ID */
+   27,  /*    TRIGGER => ID */
+   27,  /*     VACUUM => ID */
+   27,  /*       VIEW => ID */
+   27,  /*    REINDEX => ID */
+   27,  /*     RENAME => ID */
+   27,  /*   CTIME_KW => ID */
+   27,  /*      ALTER => ID */
     0,  /*         OR => nothing */
     0,  /*        AND => nothing */
     0,  /*        NOT => nothing */
@@ -806,6 +790,8 @@ static const YYCODETYPE yyFallback[] = {
     0,  /*       ELSE => nothing */
     0,  /*      INDEX => nothing */
     0,  /*         TO => nothing */
+    0,  /*        ADD => nothing */
+    0,  /*   COLUMNKW => nothing */
 };
 #endif /* YYFALLBACK */
 
@@ -878,40 +864,40 @@ void sqlite3ParserTrace(FILE *TraceFILE, char *zTracePrompt){
 static const char *const yyTokenName[] = { 
   "$",             "END_OF_FILE",   "ILLEGAL",       "SPACE",       
   "UNCLOSED_STRING",  "COMMENT",       "FUNCTION",      "COLUMN",      
-  "AGG_FUNCTION",  "SEMI",          "EXPLAIN",       "BEGIN",       
-  "TRANSACTION",   "DEFERRED",      "IMMEDIATE",     "EXCLUSIVE",   
-  "COMMIT",        "END",           "ROLLBACK",      "CREATE",      
-  "TABLE",         "TEMP",          "LP",            "RP",          
-  "AS",            "COMMA",         "ID",            "ABORT",       
-  "AFTER",         "ASC",           "ATTACH",        "BEFORE",      
-  "CASCADE",       "CONFLICT",      "DATABASE",      "DESC",        
-  "DETACH",        "EACH",          "FAIL",          "FOR",         
-  "GLOB",          "IGNORE",        "INITIALLY",     "INSTEAD",     
-  "LIKE",          "MATCH",         "KEY",           "OF",          
+  "AGG_FUNCTION",  "CONST_FUNC",    "SEMI",          "EXPLAIN",     
+  "BEGIN",         "TRANSACTION",   "DEFERRED",      "IMMEDIATE",   
+  "EXCLUSIVE",     "COMMIT",        "END",           "ROLLBACK",    
+  "CREATE",        "TABLE",         "TEMP",          "LP",          
+  "RP",            "AS",            "COMMA",         "ID",          
+  "ABORT",         "AFTER",         "ASC",           "ATTACH",      
+  "BEFORE",        "CASCADE",       "CONFLICT",      "DATABASE",    
+  "DESC",          "DETACH",        "EACH",          "FAIL",        
+  "FOR",           "IGNORE",        "INITIALLY",     "INSTEAD",     
+  "LIKE_KW",       "MATCH",         "KEY",           "OF",          
   "OFFSET",        "PRAGMA",        "RAISE",         "REPLACE",     
   "RESTRICT",      "ROW",           "STATEMENT",     "TRIGGER",     
   "VACUUM",        "VIEW",          "REINDEX",       "RENAME",      
-  "CDATE",         "CTIME",         "CTIMESTAMP",    "ALTER",       
-  "OR",            "AND",           "NOT",           "IS",          
-  "BETWEEN",       "IN",            "ISNULL",        "NOTNULL",     
-  "NE",            "EQ",            "GT",            "LE",          
-  "LT",            "GE",            "ESCAPE",        "BITAND",      
-  "BITOR",         "LSHIFT",        "RSHIFT",        "PLUS",        
-  "MINUS",         "STAR",          "SLASH",         "REM",         
-  "CONCAT",        "UMINUS",        "UPLUS",         "BITNOT",      
-  "STRING",        "JOIN_KW",       "CONSTRAINT",    "DEFAULT",     
-  "NULL",          "PRIMARY",       "UNIQUE",        "CHECK",       
-  "REFERENCES",    "COLLATE",       "AUTOINCR",      "ON",          
-  "DELETE",        "UPDATE",        "INSERT",        "SET",         
-  "DEFERRABLE",    "FOREIGN",       "DROP",          "UNION",       
-  "ALL",           "INTERSECT",     "EXCEPT",        "SELECT",      
-  "DISTINCT",      "DOT",           "FROM",          "JOIN",        
-  "USING",         "ORDER",         "BY",            "GROUP",       
-  "HAVING",        "LIMIT",         "WHERE",         "INTO",        
-  "VALUES",        "INTEGER",       "FLOAT",         "BLOB",        
-  "REGISTER",      "VARIABLE",      "EXISTS",        "CASE",        
-  "WHEN",          "THEN",          "ELSE",          "INDEX",       
-  "TO",            "error",         "input",         "cmdlist",     
+  "CTIME_KW",      "ALTER",         "OR",            "AND",         
+  "NOT",           "IS",            "BETWEEN",       "IN",          
+  "ISNULL",        "NOTNULL",       "NE",            "EQ",          
+  "GT",            "LE",            "LT",            "GE",          
+  "ESCAPE",        "BITAND",        "BITOR",         "LSHIFT",      
+  "RSHIFT",        "PLUS",          "MINUS",         "STAR",        
+  "SLASH",         "REM",           "CONCAT",        "UMINUS",      
+  "UPLUS",         "BITNOT",        "STRING",        "JOIN_KW",     
+  "CONSTRAINT",    "DEFAULT",       "NULL",          "PRIMARY",     
+  "UNIQUE",        "CHECK",         "REFERENCES",    "COLLATE",     
+  "AUTOINCR",      "ON",            "DELETE",        "UPDATE",      
+  "INSERT",        "SET",           "DEFERRABLE",    "FOREIGN",     
+  "DROP",          "UNION",         "ALL",           "INTERSECT",   
+  "EXCEPT",        "SELECT",        "DISTINCT",      "DOT",         
+  "FROM",          "JOIN",          "USING",         "ORDER",       
+  "BY",            "GROUP",         "HAVING",        "LIMIT",       
+  "WHERE",         "INTO",          "VALUES",        "INTEGER",     
+  "FLOAT",         "BLOB",          "REGISTER",      "VARIABLE",    
+  "EXISTS",        "CASE",          "WHEN",          "THEN",        
+  "ELSE",          "INDEX",         "TO",            "ADD",         
+  "COLUMNKW",      "error",         "input",         "cmdlist",     
   "ecmd",          "cmdx",          "cmd",           "explain",     
   "transtype",     "trans_opt",     "nm",            "create_table",
   "create_table_args",  "temp",          "dbnm",          "columnlist",  
@@ -935,7 +921,7 @@ static const char *const yyTokenName[] = {
   "expritem",      "uniqueflag",    "idxitem",       "plus_opt",    
   "number",        "trigger_decl",  "trigger_cmd_list",  "trigger_time",
   "trigger_event",  "foreach_clause",  "when_clause",   "trigger_cmd", 
-  "database_kw_opt",  "key_opt",     
+  "database_kw_opt",  "key_opt",       "add_column_fullname",  "kwcolumn_opt",
 };
 #endif /* NDEBUG */
 
@@ -1124,130 +1110,130 @@ static const char *const yyRuleName[] = {
  /* 178 */ "term ::= INTEGER",
  /* 179 */ "term ::= FLOAT",
  /* 180 */ "term ::= STRING",
- /* 181 */ "expr ::= BLOB",
+ /* 181 */ "term ::= BLOB",
  /* 182 */ "expr ::= REGISTER",
  /* 183 */ "expr ::= VARIABLE",
  /* 184 */ "expr ::= ID LP exprlist RP",
  /* 185 */ "expr ::= ID LP STAR RP",
- /* 186 */ "term ::= CTIME",
- /* 187 */ "term ::= CDATE",
- /* 188 */ "term ::= CTIMESTAMP",
- /* 189 */ "expr ::= expr AND expr",
- /* 190 */ "expr ::= expr OR expr",
- /* 191 */ "expr ::= expr LT expr",
- /* 192 */ "expr ::= expr GT expr",
- /* 193 */ "expr ::= expr LE expr",
- /* 194 */ "expr ::= expr GE expr",
- /* 195 */ "expr ::= expr NE expr",
- /* 196 */ "expr ::= expr EQ expr",
- /* 197 */ "expr ::= expr BITAND expr",
- /* 198 */ "expr ::= expr BITOR expr",
- /* 199 */ "expr ::= expr LSHIFT expr",
- /* 200 */ "expr ::= expr RSHIFT expr",
- /* 201 */ "expr ::= expr PLUS expr",
- /* 202 */ "expr ::= expr MINUS expr",
- /* 203 */ "expr ::= expr STAR expr",
- /* 204 */ "expr ::= expr SLASH expr",
- /* 205 */ "expr ::= expr REM expr",
- /* 206 */ "expr ::= expr CONCAT expr",
- /* 207 */ "likeop ::= LIKE",
- /* 208 */ "likeop ::= GLOB",
- /* 209 */ "likeop ::= NOT LIKE",
- /* 210 */ "likeop ::= NOT GLOB",
- /* 211 */ "escape ::= ESCAPE expr",
- /* 212 */ "escape ::=",
- /* 213 */ "expr ::= expr likeop expr escape",
- /* 214 */ "expr ::= expr ISNULL",
- /* 215 */ "expr ::= expr IS NULL",
- /* 216 */ "expr ::= expr NOTNULL",
- /* 217 */ "expr ::= expr NOT NULL",
- /* 218 */ "expr ::= expr IS NOT NULL",
- /* 219 */ "expr ::= NOT expr",
- /* 220 */ "expr ::= BITNOT expr",
- /* 221 */ "expr ::= MINUS expr",
- /* 222 */ "expr ::= PLUS expr",
- /* 223 */ "between_op ::= BETWEEN",
- /* 224 */ "between_op ::= NOT BETWEEN",
- /* 225 */ "expr ::= expr between_op expr AND expr",
- /* 226 */ "in_op ::= IN",
- /* 227 */ "in_op ::= NOT IN",
- /* 228 */ "expr ::= expr in_op LP exprlist RP",
- /* 229 */ "expr ::= LP select RP",
- /* 230 */ "expr ::= expr in_op LP select RP",
- /* 231 */ "expr ::= expr in_op nm dbnm",
- /* 232 */ "expr ::= EXISTS LP select RP",
- /* 233 */ "expr ::= CASE case_operand case_exprlist case_else END",
- /* 234 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
- /* 235 */ "case_exprlist ::= WHEN expr THEN expr",
- /* 236 */ "case_else ::= ELSE expr",
- /* 237 */ "case_else ::=",
- /* 238 */ "case_operand ::= expr",
- /* 239 */ "case_operand ::=",
- /* 240 */ "exprlist ::= exprlist COMMA expritem",
- /* 241 */ "exprlist ::= expritem",
- /* 242 */ "expritem ::= expr",
- /* 243 */ "expritem ::=",
- /* 244 */ "cmd ::= CREATE uniqueflag INDEX nm dbnm ON nm LP idxlist RP onconf",
- /* 245 */ "uniqueflag ::= UNIQUE",
- /* 246 */ "uniqueflag ::=",
- /* 247 */ "idxlist_opt ::=",
- /* 248 */ "idxlist_opt ::= LP idxlist RP",
- /* 249 */ "idxlist ::= idxlist COMMA idxitem collate sortorder",
- /* 250 */ "idxlist ::= idxitem collate sortorder",
- /* 251 */ "idxitem ::= nm",
- /* 252 */ "cmd ::= DROP INDEX fullname",
- /* 253 */ "cmd ::= VACUUM",
- /* 254 */ "cmd ::= VACUUM nm",
- /* 255 */ "cmd ::= PRAGMA nm dbnm EQ nm",
- /* 256 */ "cmd ::= PRAGMA nm dbnm EQ ON",
- /* 257 */ "cmd ::= PRAGMA nm dbnm EQ plus_num",
- /* 258 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
- /* 259 */ "cmd ::= PRAGMA nm dbnm LP nm RP",
- /* 260 */ "cmd ::= PRAGMA nm dbnm",
- /* 261 */ "plus_num ::= plus_opt number",
- /* 262 */ "minus_num ::= MINUS number",
- /* 263 */ "number ::= INTEGER",
- /* 264 */ "number ::= FLOAT",
- /* 265 */ "plus_opt ::= PLUS",
- /* 266 */ "plus_opt ::=",
- /* 267 */ "cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END",
- /* 268 */ "trigger_decl ::= temp TRIGGER nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
- /* 269 */ "trigger_time ::= BEFORE",
- /* 270 */ "trigger_time ::= AFTER",
- /* 271 */ "trigger_time ::= INSTEAD OF",
- /* 272 */ "trigger_time ::=",
- /* 273 */ "trigger_event ::= DELETE",
- /* 274 */ "trigger_event ::= INSERT",
- /* 275 */ "trigger_event ::= UPDATE",
- /* 276 */ "trigger_event ::= UPDATE OF inscollist",
- /* 277 */ "foreach_clause ::=",
- /* 278 */ "foreach_clause ::= FOR EACH ROW",
- /* 279 */ "foreach_clause ::= FOR EACH STATEMENT",
- /* 280 */ "when_clause ::=",
- /* 281 */ "when_clause ::= WHEN expr",
- /* 282 */ "trigger_cmd_list ::= trigger_cmd SEMI trigger_cmd_list",
- /* 283 */ "trigger_cmd_list ::=",
- /* 284 */ "trigger_cmd ::= UPDATE orconf nm SET setlist where_opt",
- /* 285 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP",
- /* 286 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt select",
- /* 287 */ "trigger_cmd ::= DELETE FROM nm where_opt",
- /* 288 */ "trigger_cmd ::= select",
- /* 289 */ "expr ::= RAISE LP IGNORE RP",
- /* 290 */ "expr ::= RAISE LP raisetype COMMA nm RP",
- /* 291 */ "raisetype ::= ROLLBACK",
- /* 292 */ "raisetype ::= ABORT",
- /* 293 */ "raisetype ::= FAIL",
- /* 294 */ "cmd ::= DROP TRIGGER fullname",
- /* 295 */ "cmd ::= ATTACH database_kw_opt ids AS nm key_opt",
- /* 296 */ "key_opt ::=",
- /* 297 */ "key_opt ::= KEY ids",
- /* 298 */ "key_opt ::= KEY BLOB",
- /* 299 */ "database_kw_opt ::= DATABASE",
- /* 300 */ "database_kw_opt ::=",
- /* 301 */ "cmd ::= DETACH database_kw_opt nm",
- /* 302 */ "cmd ::= REINDEX",
- /* 303 */ "cmd ::= REINDEX nm dbnm",
- /* 304 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
+ /* 186 */ "term ::= CTIME_KW",
+ /* 187 */ "expr ::= expr AND expr",
+ /* 188 */ "expr ::= expr OR expr",
+ /* 189 */ "expr ::= expr LT expr",
+ /* 190 */ "expr ::= expr GT expr",
+ /* 191 */ "expr ::= expr LE expr",
+ /* 192 */ "expr ::= expr GE expr",
+ /* 193 */ "expr ::= expr NE expr",
+ /* 194 */ "expr ::= expr EQ expr",
+ /* 195 */ "expr ::= expr BITAND expr",
+ /* 196 */ "expr ::= expr BITOR expr",
+ /* 197 */ "expr ::= expr LSHIFT expr",
+ /* 198 */ "expr ::= expr RSHIFT expr",
+ /* 199 */ "expr ::= expr PLUS expr",
+ /* 200 */ "expr ::= expr MINUS expr",
+ /* 201 */ "expr ::= expr STAR expr",
+ /* 202 */ "expr ::= expr SLASH expr",
+ /* 203 */ "expr ::= expr REM expr",
+ /* 204 */ "expr ::= expr CONCAT expr",
+ /* 205 */ "likeop ::= LIKE_KW",
+ /* 206 */ "likeop ::= NOT LIKE_KW",
+ /* 207 */ "escape ::= ESCAPE expr",
+ /* 208 */ "escape ::=",
+ /* 209 */ "expr ::= expr likeop expr escape",
+ /* 210 */ "expr ::= expr ISNULL",
+ /* 211 */ "expr ::= expr IS NULL",
+ /* 212 */ "expr ::= expr NOTNULL",
+ /* 213 */ "expr ::= expr NOT NULL",
+ /* 214 */ "expr ::= expr IS NOT NULL",
+ /* 215 */ "expr ::= NOT expr",
+ /* 216 */ "expr ::= BITNOT expr",
+ /* 217 */ "expr ::= MINUS expr",
+ /* 218 */ "expr ::= PLUS expr",
+ /* 219 */ "between_op ::= BETWEEN",
+ /* 220 */ "between_op ::= NOT BETWEEN",
+ /* 221 */ "expr ::= expr between_op expr AND expr",
+ /* 222 */ "in_op ::= IN",
+ /* 223 */ "in_op ::= NOT IN",
+ /* 224 */ "expr ::= expr in_op LP exprlist RP",
+ /* 225 */ "expr ::= LP select RP",
+ /* 226 */ "expr ::= expr in_op LP select RP",
+ /* 227 */ "expr ::= expr in_op nm dbnm",
+ /* 228 */ "expr ::= EXISTS LP select RP",
+ /* 229 */ "expr ::= CASE case_operand case_exprlist case_else END",
+ /* 230 */ "case_exprlist ::= case_exprlist WHEN expr THEN expr",
+ /* 231 */ "case_exprlist ::= WHEN expr THEN expr",
+ /* 232 */ "case_else ::= ELSE expr",
+ /* 233 */ "case_else ::=",
+ /* 234 */ "case_operand ::= expr",
+ /* 235 */ "case_operand ::=",
+ /* 236 */ "exprlist ::= exprlist COMMA expritem",
+ /* 237 */ "exprlist ::= expritem",
+ /* 238 */ "expritem ::= expr",
+ /* 239 */ "expritem ::=",
+ /* 240 */ "cmd ::= CREATE uniqueflag INDEX nm dbnm ON nm LP idxlist RP onconf",
+ /* 241 */ "uniqueflag ::= UNIQUE",
+ /* 242 */ "uniqueflag ::=",
+ /* 243 */ "idxlist_opt ::=",
+ /* 244 */ "idxlist_opt ::= LP idxlist RP",
+ /* 245 */ "idxlist ::= idxlist COMMA idxitem collate sortorder",
+ /* 246 */ "idxlist ::= idxitem collate sortorder",
+ /* 247 */ "idxitem ::= nm",
+ /* 248 */ "cmd ::= DROP INDEX fullname",
+ /* 249 */ "cmd ::= VACUUM",
+ /* 250 */ "cmd ::= VACUUM nm",
+ /* 251 */ "cmd ::= PRAGMA nm dbnm EQ nm",
+ /* 252 */ "cmd ::= PRAGMA nm dbnm EQ ON",
+ /* 253 */ "cmd ::= PRAGMA nm dbnm EQ plus_num",
+ /* 254 */ "cmd ::= PRAGMA nm dbnm EQ minus_num",
+ /* 255 */ "cmd ::= PRAGMA nm dbnm LP nm RP",
+ /* 256 */ "cmd ::= PRAGMA nm dbnm",
+ /* 257 */ "plus_num ::= plus_opt number",
+ /* 258 */ "minus_num ::= MINUS number",
+ /* 259 */ "number ::= INTEGER",
+ /* 260 */ "number ::= FLOAT",
+ /* 261 */ "plus_opt ::= PLUS",
+ /* 262 */ "plus_opt ::=",
+ /* 263 */ "cmd ::= CREATE trigger_decl BEGIN trigger_cmd_list END",
+ /* 264 */ "trigger_decl ::= temp TRIGGER nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause",
+ /* 265 */ "trigger_time ::= BEFORE",
+ /* 266 */ "trigger_time ::= AFTER",
+ /* 267 */ "trigger_time ::= INSTEAD OF",
+ /* 268 */ "trigger_time ::=",
+ /* 269 */ "trigger_event ::= DELETE",
+ /* 270 */ "trigger_event ::= INSERT",
+ /* 271 */ "trigger_event ::= UPDATE",
+ /* 272 */ "trigger_event ::= UPDATE OF inscollist",
+ /* 273 */ "foreach_clause ::=",
+ /* 274 */ "foreach_clause ::= FOR EACH ROW",
+ /* 275 */ "foreach_clause ::= FOR EACH STATEMENT",
+ /* 276 */ "when_clause ::=",
+ /* 277 */ "when_clause ::= WHEN expr",
+ /* 278 */ "trigger_cmd_list ::= trigger_cmd SEMI trigger_cmd_list",
+ /* 279 */ "trigger_cmd_list ::=",
+ /* 280 */ "trigger_cmd ::= UPDATE orconf nm SET setlist where_opt",
+ /* 281 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt VALUES LP itemlist RP",
+ /* 282 */ "trigger_cmd ::= insert_cmd INTO nm inscollist_opt select",
+ /* 283 */ "trigger_cmd ::= DELETE FROM nm where_opt",
+ /* 284 */ "trigger_cmd ::= select",
+ /* 285 */ "expr ::= RAISE LP IGNORE RP",
+ /* 286 */ "expr ::= RAISE LP raisetype COMMA nm RP",
+ /* 287 */ "raisetype ::= ROLLBACK",
+ /* 288 */ "raisetype ::= ABORT",
+ /* 289 */ "raisetype ::= FAIL",
+ /* 290 */ "cmd ::= DROP TRIGGER fullname",
+ /* 291 */ "cmd ::= ATTACH database_kw_opt ids AS nm key_opt",
+ /* 292 */ "key_opt ::=",
+ /* 293 */ "key_opt ::= KEY ids",
+ /* 294 */ "key_opt ::= KEY BLOB",
+ /* 295 */ "database_kw_opt ::= DATABASE",
+ /* 296 */ "database_kw_opt ::=",
+ /* 297 */ "cmd ::= DETACH database_kw_opt nm",
+ /* 298 */ "cmd ::= REINDEX",
+ /* 299 */ "cmd ::= REINDEX nm dbnm",
+ /* 300 */ "cmd ::= ALTER TABLE fullname RENAME TO nm",
+ /* 301 */ "cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column",
+ /* 302 */ "add_column_fullname ::= fullname",
+ /* 303 */ "kwcolumn_opt ::=",
+ /* 304 */ "kwcolumn_opt ::= COLUMNKW",
 };
 #endif /* NDEBUG */
 
@@ -1308,9 +1294,9 @@ static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){
     case 157:
     case 189:
     case 206:
-#line 325 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3SelectDelete((yypminor->yy331));}
-#line 1315 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 334 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3SelectDelete((yypminor->yy459));}
+#line 1301 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
       break;
     case 170:
     case 174:
@@ -1319,9 +1305,9 @@ static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){
     case 204:
     case 210:
     case 224:
-#line 584 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3ExprDelete((yypminor->yy454));}
-#line 1326 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 593 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3ExprDelete((yypminor->yy2));}
+#line 1312 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
       break;
     case 175:
     case 183:
@@ -1334,43 +1320,43 @@ static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){
     case 213:
     case 216:
     case 222:
-#line 796 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3ExprListDelete((yypminor->yy266));}
-#line 1341 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 812 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3ExprListDelete((yypminor->yy82));}
+#line 1327 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
       break;
     case 188:
     case 193:
     case 201:
     case 202:
-#line 454 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3SrcListDelete((yypminor->yy427));}
-#line 1349 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 463 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3SrcListDelete((yypminor->yy67));}
+#line 1335 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
       break;
     case 198:
-#line 516 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 525 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  sqlite3ExprDelete((yypminor->yy348).pLimit);
-  sqlite3ExprDelete((yypminor->yy348).pOffset);
+  sqlite3ExprDelete((yypminor->yy244).pLimit);
+  sqlite3ExprDelete((yypminor->yy244).pOffset);
 }
-#line 1357 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 1343 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
       break;
     case 205:
     case 208:
     case 215:
-#line 472 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3IdListDelete((yypminor->yy272));}
-#line 1364 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 481 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3IdListDelete((yypminor->yy240));}
+#line 1350 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
       break;
     case 230:
     case 235:
-#line 889 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3DeleteTriggerStep((yypminor->yy455));}
-#line 1370 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 905 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3DeleteTriggerStep((yypminor->yy347));}
+#line 1356 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
       break;
     case 232:
-#line 873 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3IdListDelete((yypminor->yy62).b);}
-#line 1375 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 889 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3IdListDelete((yypminor->yy210).b);}
+#line 1361 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
       break;
     default:  break;   /* If no destructor action specified: do nothing */
   }
@@ -1477,11 +1463,11 @@ static int yy_find_shift_action(
 ** return YY_NO_ACTION.
 */
 static int yy_find_reduce_action(
-  yyParser *pParser,        /* The parser */
+  int stateno,              /* Current state number */
   int iLookAhead            /* The look-ahead token */
 ){
   int i;
-  int stateno = pParser->yystack[pParser->yyidx].stateno;
+  /* int stateno = pParser->yystack[pParser->yyidx].stateno; */
  
   i = yy_reduce_ofst[stateno];
   if( i==YY_REDUCE_USE_DFLT ){
@@ -1727,14 +1713,12 @@ static const struct {
   { 170, 1 },
   { 170, 1 },
   { 170, 1 },
-  { 174, 1 },
+  { 170, 1 },
   { 174, 1 },
   { 174, 1 },
   { 174, 4 },
   { 174, 4 },
   { 170, 1 },
-  { 170, 1 },
-  { 170, 1 },
   { 174, 3 },
   { 174, 3 },
   { 174, 3 },
@@ -1754,8 +1738,6 @@ static const struct {
   { 174, 3 },
   { 174, 3 },
   { 217, 1 },
-  { 217, 1 },
-  { 217, 2 },
   { 217, 2 },
   { 218, 2 },
   { 218, 0 },
@@ -1851,6 +1833,10 @@ static const struct {
   { 146, 1 },
   { 146, 3 },
   { 146, 6 },
+  { 146, 6 },
+  { 238, 1 },
+  { 239, 0 },
+  { 239, 1 },
 };
 
 static void yy_accept(yyParser*);  /* Forward Declaration */
@@ -1878,6 +1864,18 @@ static void yy_reduce(
   }
 #endif /* NDEBUG */
 
+#ifndef NDEBUG
+  /* Silence complaints from purify about yygotominor being uninitialized
+  ** in some cases when it is copied into the stack after the following
+  ** switch.  yygotominor is uninitialized when a rule reduces that does
+  ** not set the value of its left-hand side nonterminal.  Leaving the
+  ** value of the nonterminal uninitialized is utterly harmless as long
+  ** as the value is never used.  So really the only thing this code
+  ** accomplishes is to quieten purify.  
+  */
+  memset(&yygotominor, 0, sizeof(yygotominor));
+#endif
+
   switch( yyruleno ){
   /* Beginning here are the reduction cases.  A typical example
   ** follows:
@@ -1888,29 +1886,29 @@ static void yy_reduce(
   **     break;
   */
       case 3:
-#line 84 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 84 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 { sqlite3FinishCoding(pParse); }
-#line 1895 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 1893 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 6:
-#line 87 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 87 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 { sqlite3BeginParse(pParse, 0); }
-#line 1900 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 1898 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 7:
-#line 89 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 89 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 { sqlite3BeginParse(pParse, 1); }
-#line 1905 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 1903 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 8:
-#line 95 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy60);}
-#line 1910 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 95 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy412);}
+#line 1908 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 12:
-#line 100 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy60 = TK_DEFERRED;}
-#line 1915 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 100 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy412 = TK_DEFERRED;}
+#line 1913 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 13:
       case 14:
@@ -1918,37 +1916,37 @@ static void yy_reduce(
       case 101:
       case 103:
       case 104:
-#line 101 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy60 = yymsp[0].major;}
-#line 1925 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 101 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy412 = yymsp[0].major;}
+#line 1923 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 16:
       case 17:
-#line 104 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 104 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {sqlite3CommitTransaction(pParse);}
-#line 1931 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 1929 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 18:
-#line 106 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 106 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {sqlite3RollbackTransaction(pParse);}
-#line 1936 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 1934 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 20:
-#line 111 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 111 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-   sqlite3StartTable(pParse,&yymsp[-4].minor.yy0,&yymsp[-1].minor.yy406,&yymsp[0].minor.yy406,yymsp[-3].minor.yy60,0);
+   sqlite3StartTable(pParse,&yymsp[-4].minor.yy0,&yymsp[-1].minor.yy258,&yymsp[0].minor.yy258,yymsp[-3].minor.yy412,0);
 }
-#line 1943 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 1941 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 21:
       case 60:
       case 74:
       case 106:
-      case 224:
-      case 227:
-#line 115 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy60 = 1;}
-#line 1953 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 220:
+      case 223:
+#line 116 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy412 = 1;}
+#line 1951 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 22:
       case 59:
@@ -1957,31 +1955,42 @@ static void yy_reduce(
       case 86:
       case 107:
       case 108:
-      case 223:
-      case 226:
-#line 116 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy60 = 0;}
-#line 1966 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 219:
+      case 222:
+#line 118 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy412 = 0;}
+#line 1964 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 23:
-#line 117 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 119 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  sqlite3EndTable(pParse,&yymsp[0].minor.yy0,0);
+  sqlite3EndTable(pParse,&yymsp[-1].minor.yy258,&yymsp[0].minor.yy0,0);
 }
-#line 1973 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 1971 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 24:
-#line 120 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 122 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{
+  sqlite3EndTable(pParse,0,0,yymsp[0].minor.yy459);
+  sqlite3SelectDelete(yymsp[0].minor.yy459);
+}
+#line 1979 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
+        break;
+      case 27:
+#line 133 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  sqlite3EndTable(pParse,0,yymsp[0].minor.yy331);
-  sqlite3SelectDelete(yymsp[0].minor.yy331);
+  yygotominor.yy258.z = yymsp[-2].minor.yy258.z;
+  yygotominor.yy258.n = (pParse->sLastToken.z-yymsp[-2].minor.yy258.z) + pParse->sLastToken.n;
 }
-#line 1981 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 1987 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 28:
-#line 132 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3AddColumn(pParse,&yymsp[0].minor.yy406);}
-#line 1986 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 137 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{
+  sqlite3AddColumn(pParse,&yymsp[0].minor.yy258);
+  yygotominor.yy258 = yymsp[0].minor.yy258;
+}
+#line 1995 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 29:
       case 30:
@@ -1989,155 +1998,160 @@ static void yy_reduce(
       case 32:
       case 33:
       case 34:
-      case 263:
-      case 264:
-#line 138 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy406 = yymsp[0].minor.yy0;}
-#line 1998 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 259:
+      case 260:
+#line 147 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy258 = yymsp[0].minor.yy0;}
+#line 2007 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 36:
-#line 193 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3AddColumnType(pParse,&yymsp[0].minor.yy406,&yymsp[0].minor.yy406);}
-#line 2003 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 202 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3AddColumnType(pParse,&yymsp[0].minor.yy258,&yymsp[0].minor.yy258);}
+#line 2012 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 37:
-#line 194 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3AddColumnType(pParse,&yymsp[-3].minor.yy406,&yymsp[0].minor.yy0);}
-#line 2008 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 203 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3AddColumnType(pParse,&yymsp[-3].minor.yy258,&yymsp[0].minor.yy0);}
+#line 2017 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 38:
-#line 196 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3AddColumnType(pParse,&yymsp[-5].minor.yy406,&yymsp[0].minor.yy0);}
-#line 2013 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 205 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3AddColumnType(pParse,&yymsp[-5].minor.yy258,&yymsp[0].minor.yy0);}
+#line 2022 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 39:
       case 114:
       case 115:
       case 126:
       case 146:
-      case 251:
-      case 261:
-      case 262:
-#line 198 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy406 = yymsp[0].minor.yy406;}
-#line 2025 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 247:
+      case 257:
+      case 258:
+#line 207 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy258 = yymsp[0].minor.yy258;}
+#line 2034 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 40:
-#line 199 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy406.z=yymsp[-1].minor.yy406.z; yygotominor.yy406.n=yymsp[0].minor.yy406.n+(yymsp[0].minor.yy406.z-yymsp[-1].minor.yy406.z);}
-#line 2030 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 208 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy258.z=yymsp[-1].minor.yy258.z; yygotominor.yy258.n=yymsp[0].minor.yy258.n+(yymsp[0].minor.yy258.z-yymsp[-1].minor.yy258.z);}
+#line 2039 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 41:
-#line 201 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy60 = atoi(yymsp[0].minor.yy406.z); }
-#line 2035 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 210 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy412 = atoi(yymsp[0].minor.yy258.z); }
+#line 2044 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 42:
-#line 202 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy60 = -atoi(yymsp[0].minor.yy406.z); }
-#line 2040 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 211 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy412 = -atoi(yymsp[0].minor.yy258.z); }
+#line 2049 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 47:
       case 48:
-#line 207 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy454);}
-#line 2046 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 216 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3AddDefaultValue(pParse,yymsp[0].minor.yy2);}
+#line 2055 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 49:
-#line 209 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 218 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  Expr *p = sqlite3Expr(TK_UMINUS, yymsp[0].minor.yy454, 0, 0);
+  Expr *p = sqlite3Expr(TK_UMINUS, yymsp[0].minor.yy2, 0, 0);
   sqlite3AddDefaultValue(pParse,p);
 }
-#line 2054 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2063 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 50:
-#line 213 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 222 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  Expr *p = sqlite3Expr(TK_STRING, 0, 0, &yymsp[0].minor.yy406);
+  Expr *p = sqlite3Expr(TK_STRING, 0, 0, &yymsp[0].minor.yy258);
   sqlite3AddDefaultValue(pParse,p);
 }
-#line 2062 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2071 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 52:
-#line 222 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3AddNotNull(pParse, yymsp[0].minor.yy60);}
-#line 2067 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 231 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3AddNotNull(pParse, yymsp[0].minor.yy412);}
+#line 2076 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 53:
-#line 224 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy60,yymsp[0].minor.yy60);}
-#line 2072 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 233 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy412,yymsp[0].minor.yy412);}
+#line 2081 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 54:
-#line 225 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy60,0,0);}
-#line 2077 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 234 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy412,0,0);}
+#line 2086 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
+        break;
+      case 55:
+#line 235 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3ExprDelete(yymsp[-2].minor.yy2);}
+#line 2091 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 56:
-#line 228 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy406,yymsp[-1].minor.yy266,yymsp[0].minor.yy60);}
-#line 2082 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 237 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy258,yymsp[-1].minor.yy82,yymsp[0].minor.yy412);}
+#line 2096 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 57:
-#line 229 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy60);}
-#line 2087 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 238 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy412);}
+#line 2101 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 58:
-#line 230 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3AddCollateType(pParse, yymsp[0].minor.yy406.z, yymsp[0].minor.yy406.n);}
-#line 2092 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 239 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3AddCollateType(pParse, yymsp[0].minor.yy258.z, yymsp[0].minor.yy258.n);}
+#line 2106 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 61:
-#line 243 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy60 = OE_Restrict * 0x010101; }
-#line 2097 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 252 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy412 = OE_Restrict * 0x010101; }
+#line 2111 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 62:
-#line 244 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy60 = (yymsp[-1].minor.yy60 & yymsp[0].minor.yy243.mask) | yymsp[0].minor.yy243.value; }
-#line 2102 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 253 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy412 = (yymsp[-1].minor.yy412 & yymsp[0].minor.yy47.mask) | yymsp[0].minor.yy47.value; }
+#line 2116 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 63:
-#line 246 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy243.value = 0;     yygotominor.yy243.mask = 0x000000; }
-#line 2107 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 255 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy47.value = 0;     yygotominor.yy47.mask = 0x000000; }
+#line 2121 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 64:
-#line 247 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy243.value = yymsp[0].minor.yy60;     yygotominor.yy243.mask = 0x0000ff; }
-#line 2112 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 256 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy47.value = yymsp[0].minor.yy412;     yygotominor.yy47.mask = 0x0000ff; }
+#line 2126 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 65:
-#line 248 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy243.value = yymsp[0].minor.yy60<<8;  yygotominor.yy243.mask = 0x00ff00; }
-#line 2117 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 257 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy47.value = yymsp[0].minor.yy412<<8;  yygotominor.yy47.mask = 0x00ff00; }
+#line 2131 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 66:
-#line 249 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy243.value = yymsp[0].minor.yy60<<16; yygotominor.yy243.mask = 0xff0000; }
-#line 2122 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 258 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy47.value = yymsp[0].minor.yy412<<16; yygotominor.yy47.mask = 0xff0000; }
+#line 2136 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 67:
-#line 251 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy60 = OE_SetNull; }
-#line 2127 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 260 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy412 = OE_SetNull; }
+#line 2141 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 68:
-#line 252 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy60 = OE_SetDflt; }
-#line 2132 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 261 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy412 = OE_SetDflt; }
+#line 2146 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 69:
-#line 253 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy60 = OE_Cascade; }
-#line 2137 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 262 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy412 = OE_Cascade; }
+#line 2151 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 70:
-#line 254 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy60 = OE_Restrict; }
-#line 2142 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 263 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy412 = OE_Restrict; }
+#line 2156 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 71:
       case 72:
@@ -2146,462 +2160,477 @@ static void yy_reduce(
       case 91:
       case 92:
       case 163:
-#line 256 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy60 = yymsp[0].minor.yy60;}
-#line 2153 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 265 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy412 = yymsp[0].minor.yy412;}
+#line 2167 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
+        break;
+      case 76:
+#line 275 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy258.n = 0; yygotominor.yy258.z = 0;}
+#line 2172 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
+        break;
+      case 77:
+#line 276 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy258 = yymsp[-1].minor.yy0;}
+#line 2177 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 82:
-#line 273 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy266,yymsp[0].minor.yy60,yymsp[-2].minor.yy60);}
-#line 2158 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 282 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy82,yymsp[0].minor.yy412,yymsp[-2].minor.yy412);}
+#line 2182 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 83:
-#line 275 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy266,yymsp[0].minor.yy60,0,0);}
-#line 2163 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 284 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy82,yymsp[0].minor.yy412,0,0);}
+#line 2187 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 85:
-#line 278 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 287 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-    sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy266, &yymsp[-3].minor.yy406, yymsp[-2].minor.yy266, yymsp[-1].minor.yy60);
-    sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy60);
+    sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy82, &yymsp[-3].minor.yy258, yymsp[-2].minor.yy82, yymsp[-1].minor.yy412);
+    sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy412);
 }
-#line 2171 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2195 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 88:
       case 90:
-#line 292 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy60 = OE_Default;}
-#line 2177 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 301 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy412 = OE_Default;}
+#line 2201 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 93:
-#line 297 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy60 = OE_Ignore;}
-#line 2182 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 306 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy412 = OE_Ignore;}
+#line 2206 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 94:
       case 164:
-#line 298 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy60 = OE_Replace;}
-#line 2188 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 307 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy412 = OE_Replace;}
+#line 2212 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 95:
-#line 302 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 311 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  sqlite3DropTable(pParse, yymsp[0].minor.yy427, 0);
+  sqlite3DropTable(pParse, yymsp[0].minor.yy67, 0);
 }
-#line 2195 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2219 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 96:
-#line 309 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 318 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  sqlite3CreateView(pParse, &yymsp[-6].minor.yy0, &yymsp[-3].minor.yy406, &yymsp[-2].minor.yy406, yymsp[0].minor.yy331, yymsp[-5].minor.yy60);
+  sqlite3CreateView(pParse, &yymsp[-6].minor.yy0, &yymsp[-3].minor.yy258, &yymsp[-2].minor.yy258, yymsp[0].minor.yy459, yymsp[-5].minor.yy412);
 }
-#line 2202 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2226 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 97:
-#line 312 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 321 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  sqlite3DropTable(pParse, yymsp[0].minor.yy427, 1);
+  sqlite3DropTable(pParse, yymsp[0].minor.yy67, 1);
 }
-#line 2209 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2233 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 98:
-#line 319 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 328 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  sqlite3Select(pParse, yymsp[0].minor.yy331, SRT_Callback, 0, 0, 0, 0, 0);
-  sqlite3SelectDelete(yymsp[0].minor.yy331);
+  sqlite3Select(pParse, yymsp[0].minor.yy459, SRT_Callback, 0, 0, 0, 0, 0);
+  sqlite3SelectDelete(yymsp[0].minor.yy459);
 }
-#line 2217 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2241 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 99:
       case 123:
-#line 329 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy331 = yymsp[0].minor.yy331;}
-#line 2223 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 338 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy459 = yymsp[0].minor.yy459;}
+#line 2247 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 100:
-#line 331 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 340 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  if( yymsp[0].minor.yy331 ){
-    yymsp[0].minor.yy331->op = yymsp[-1].minor.yy60;
-    yymsp[0].minor.yy331->pPrior = yymsp[-2].minor.yy331;
+  if( yymsp[0].minor.yy459 ){
+    yymsp[0].minor.yy459->op = yymsp[-1].minor.yy412;
+    yymsp[0].minor.yy459->pPrior = yymsp[-2].minor.yy459;
   }
-  yygotominor.yy331 = yymsp[0].minor.yy331;
+  yygotominor.yy459 = yymsp[0].minor.yy459;
 }
-#line 2234 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2258 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 102:
-#line 340 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy60 = TK_ALL;}
-#line 2239 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 349 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy412 = TK_ALL;}
+#line 2263 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 105:
-#line 345 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 354 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  yygotominor.yy331 = sqlite3SelectNew(yymsp[-6].minor.yy266,yymsp[-5].minor.yy427,yymsp[-4].minor.yy454,yymsp[-3].minor.yy266,yymsp[-2].minor.yy454,yymsp[-1].minor.yy266,yymsp[-7].minor.yy60,yymsp[0].minor.yy348.pLimit,yymsp[0].minor.yy348.pOffset);
+  yygotominor.yy459 = sqlite3SelectNew(yymsp[-6].minor.yy82,yymsp[-5].minor.yy67,yymsp[-4].minor.yy2,yymsp[-3].minor.yy82,yymsp[-2].minor.yy2,yymsp[-1].minor.yy82,yymsp[-7].minor.yy412,yymsp[0].minor.yy244.pLimit,yymsp[0].minor.yy244.pOffset);
 }
-#line 2246 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2270 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 109:
-      case 248:
-#line 366 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy266 = yymsp[-1].minor.yy266;}
-#line 2252 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 244:
+#line 375 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy82 = yymsp[-1].minor.yy82;}
+#line 2276 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 110:
       case 137:
       case 147:
-      case 247:
-#line 367 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy266 = 0;}
-#line 2260 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 243:
+#line 376 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy82 = 0;}
+#line 2284 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 111:
-#line 368 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 377 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-   yygotominor.yy266 = sqlite3ExprListAppend(yymsp[-2].minor.yy266,yymsp[-1].minor.yy454,yymsp[0].minor.yy406.n?&yymsp[0].minor.yy406:0);
+   yygotominor.yy82 = sqlite3ExprListAppend(yymsp[-2].minor.yy82,yymsp[-1].minor.yy2,yymsp[0].minor.yy258.n?&yymsp[0].minor.yy258:0);
 }
-#line 2267 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2291 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 112:
-#line 371 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 380 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  yygotominor.yy266 = sqlite3ExprListAppend(yymsp[-1].minor.yy266, sqlite3Expr(TK_ALL, 0, 0, 0), 0);
+  yygotominor.yy82 = sqlite3ExprListAppend(yymsp[-1].minor.yy82, sqlite3Expr(TK_ALL, 0, 0, 0), 0);
 }
-#line 2274 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2298 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 113:
-#line 374 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 383 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
   Expr *pRight = sqlite3Expr(TK_ALL, 0, 0, 0);
-  Expr *pLeft = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy406);
-  yygotominor.yy266 = sqlite3ExprListAppend(yymsp[-3].minor.yy266, sqlite3Expr(TK_DOT, pLeft, pRight, 0), 0);
+  Expr *pLeft = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy258);
+  yygotominor.yy82 = sqlite3ExprListAppend(yymsp[-3].minor.yy82, sqlite3Expr(TK_DOT, pLeft, pRight, 0), 0);
 }
-#line 2283 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2307 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 116:
-#line 386 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy406.n = 0;}
-#line 2288 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 395 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy258.n = 0;}
+#line 2312 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 117:
-#line 398 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy427 = sqliteMalloc(sizeof(*yygotominor.yy427));}
-#line 2293 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 407 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy67 = sqliteMalloc(sizeof(*yygotominor.yy67));}
+#line 2317 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 118:
-#line 399 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy427 = yymsp[0].minor.yy427;}
-#line 2298 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 408 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy67 = yymsp[0].minor.yy67;}
+#line 2322 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 119:
-#line 404 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 413 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-   yygotominor.yy427 = yymsp[-1].minor.yy427;
-   if( yygotominor.yy427 && yygotominor.yy427->nSrc>0 ) yygotominor.yy427->a[yygotominor.yy427->nSrc-1].jointype = yymsp[0].minor.yy60;
+   yygotominor.yy67 = yymsp[-1].minor.yy67;
+   if( yygotominor.yy67 && yygotominor.yy67->nSrc>0 ) yygotominor.yy67->a[yygotominor.yy67->nSrc-1].jointype = yymsp[0].minor.yy412;
 }
-#line 2306 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2330 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 120:
-#line 408 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy427 = 0;}
-#line 2311 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 417 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy67 = 0;}
+#line 2335 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 121:
-#line 409 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 418 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  yygotominor.yy427 = sqlite3SrcListAppend(yymsp[-5].minor.yy427,&yymsp[-4].minor.yy406,&yymsp[-3].minor.yy406);
-  if( yymsp[-2].minor.yy406.n ) sqlite3SrcListAddAlias(yygotominor.yy427,&yymsp[-2].minor.yy406);
-  if( yymsp[-1].minor.yy454 ){
-    if( yygotominor.yy427 && yygotominor.yy427->nSrc>1 ){ yygotominor.yy427->a[yygotominor.yy427->nSrc-2].pOn = yymsp[-1].minor.yy454; }
-    else { sqlite3ExprDelete(yymsp[-1].minor.yy454); }
+  yygotominor.yy67 = sqlite3SrcListAppend(yymsp[-5].minor.yy67,&yymsp[-4].minor.yy258,&yymsp[-3].minor.yy258);
+  if( yymsp[-2].minor.yy258.n ) sqlite3SrcListAddAlias(yygotominor.yy67,&yymsp[-2].minor.yy258);
+  if( yymsp[-1].minor.yy2 ){
+    if( yygotominor.yy67 && yygotominor.yy67->nSrc>1 ){ yygotominor.yy67->a[yygotominor.yy67->nSrc-2].pOn = yymsp[-1].minor.yy2; }
+    else { sqlite3ExprDelete(yymsp[-1].minor.yy2); }
   }
-  if( yymsp[0].minor.yy272 ){
-    if( yygotominor.yy427 && yygotominor.yy427->nSrc>1 ){ yygotominor.yy427->a[yygotominor.yy427->nSrc-2].pUsing = yymsp[0].minor.yy272; }
-    else { sqlite3IdListDelete(yymsp[0].minor.yy272); }
+  if( yymsp[0].minor.yy240 ){
+    if( yygotominor.yy67 && yygotominor.yy67->nSrc>1 ){ yygotominor.yy67->a[yygotominor.yy67->nSrc-2].pUsing = yymsp[0].minor.yy240; }
+    else { sqlite3IdListDelete(yymsp[0].minor.yy240); }
   }
 }
-#line 2327 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2351 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 122:
-#line 423 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 432 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-    yygotominor.yy427 = sqlite3SrcListAppend(yymsp[-6].minor.yy427,0,0);
-    yygotominor.yy427->a[yygotominor.yy427->nSrc-1].pSelect = yymsp[-4].minor.yy331;
-    if( yymsp[-2].minor.yy406.n ) sqlite3SrcListAddAlias(yygotominor.yy427,&yymsp[-2].minor.yy406);
-    if( yymsp[-1].minor.yy454 ){
-      if( yygotominor.yy427 && yygotominor.yy427->nSrc>1 ){ yygotominor.yy427->a[yygotominor.yy427->nSrc-2].pOn = yymsp[-1].minor.yy454; }
-      else { sqlite3ExprDelete(yymsp[-1].minor.yy454); }
+    yygotominor.yy67 = sqlite3SrcListAppend(yymsp[-6].minor.yy67,0,0);
+    yygotominor.yy67->a[yygotominor.yy67->nSrc-1].pSelect = yymsp[-4].minor.yy459;
+    if( yymsp[-2].minor.yy258.n ) sqlite3SrcListAddAlias(yygotominor.yy67,&yymsp[-2].minor.yy258);
+    if( yymsp[-1].minor.yy2 ){
+      if( yygotominor.yy67 && yygotominor.yy67->nSrc>1 ){ yygotominor.yy67->a[yygotominor.yy67->nSrc-2].pOn = yymsp[-1].minor.yy2; }
+      else { sqlite3ExprDelete(yymsp[-1].minor.yy2); }
     }
-    if( yymsp[0].minor.yy272 ){
-      if( yygotominor.yy427 && yygotominor.yy427->nSrc>1 ){ yygotominor.yy427->a[yygotominor.yy427->nSrc-2].pUsing = yymsp[0].minor.yy272; }
-      else { sqlite3IdListDelete(yymsp[0].minor.yy272); }
+    if( yymsp[0].minor.yy240 ){
+      if( yygotominor.yy67 && yygotominor.yy67->nSrc>1 ){ yygotominor.yy67->a[yygotominor.yy67->nSrc-2].pUsing = yymsp[0].minor.yy240; }
+      else { sqlite3IdListDelete(yymsp[0].minor.yy240); }
     }
   }
-#line 2344 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2368 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 124:
-#line 444 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 453 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-     yygotominor.yy331 = sqlite3SelectNew(0,yymsp[0].minor.yy427,0,0,0,0,0,0,0);
+     yygotominor.yy459 = sqlite3SelectNew(0,yymsp[0].minor.yy67,0,0,0,0,0,0,0);
   }
-#line 2351 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2375 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 125:
-#line 450 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy406.z=0; yygotominor.yy406.n=0;}
-#line 2356 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 459 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy258.z=0; yygotominor.yy258.n=0;}
+#line 2380 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 127:
-#line 455 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy427 = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy406,&yymsp[0].minor.yy406);}
-#line 2361 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 464 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy67 = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy258,&yymsp[0].minor.yy258);}
+#line 2385 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 128:
       case 129:
-#line 459 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy60 = JT_INNER; }
-#line 2367 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 468 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy412 = JT_INNER; }
+#line 2391 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 130:
-#line 461 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy60 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
-#line 2372 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 470 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy412 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); }
+#line 2396 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 131:
-#line 462 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy60 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy406,0); }
-#line 2377 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 471 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy412 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy258,0); }
+#line 2401 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 132:
-#line 464 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy60 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy406,&yymsp[-1].minor.yy406); }
-#line 2382 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 473 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy412 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy258,&yymsp[-1].minor.yy258); }
+#line 2406 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 133:
       case 141:
       case 150:
       case 157:
       case 171:
-      case 211:
-      case 236:
+      case 207:
+      case 232:
+      case 234:
       case 238:
-      case 242:
-#line 468 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy454 = yymsp[0].minor.yy454;}
-#line 2395 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 477 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy2 = yymsp[0].minor.yy2;}
+#line 2419 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 134:
       case 149:
       case 156:
-      case 212:
-      case 237:
+      case 208:
+      case 233:
+      case 235:
       case 239:
-      case 243:
-#line 469 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy454 = 0;}
-#line 2406 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 478 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy2 = 0;}
+#line 2430 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 135:
       case 168:
-#line 473 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy272 = yymsp[-1].minor.yy272;}
-#line 2412 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 482 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy240 = yymsp[-1].minor.yy240;}
+#line 2436 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 136:
       case 167:
-#line 474 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy272 = 0;}
-#line 2418 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 483 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy240 = 0;}
+#line 2442 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 138:
       case 148:
-#line 485 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy266 = yymsp[0].minor.yy266;}
-#line 2424 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 494 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy82 = yymsp[0].minor.yy82;}
+#line 2448 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 139:
-#line 486 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 495 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  yygotominor.yy266 = sqlite3ExprListAppend(yymsp[-4].minor.yy266,yymsp[-2].minor.yy454,yymsp[-1].minor.yy406.n>0?&yymsp[-1].minor.yy406:0);
-  if( yygotominor.yy266 ) yygotominor.yy266->a[yygotominor.yy266->nExpr-1].sortOrder = yymsp[0].minor.yy60;
+  yygotominor.yy82 = sqlite3ExprListAppend(yymsp[-4].minor.yy82,yymsp[-2].minor.yy2,yymsp[-1].minor.yy258.n>0?&yymsp[-1].minor.yy258:0);
+  if( yygotominor.yy82 ) yygotominor.yy82->a[yygotominor.yy82->nExpr-1].sortOrder = yymsp[0].minor.yy412;
 }
-#line 2432 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2456 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 140:
-#line 490 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 499 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  yygotominor.yy266 = sqlite3ExprListAppend(0,yymsp[-2].minor.yy454,yymsp[-1].minor.yy406.n>0?&yymsp[-1].minor.yy406:0);
-  if( yygotominor.yy266 && yygotominor.yy266->a ) yygotominor.yy266->a[0].sortOrder = yymsp[0].minor.yy60;
+  yygotominor.yy82 = sqlite3ExprListAppend(0,yymsp[-2].minor.yy2,yymsp[-1].minor.yy258.n>0?&yymsp[-1].minor.yy258:0);
+  if( yygotominor.yy82 && yygotominor.yy82->a ) yygotominor.yy82->a[0].sortOrder = yymsp[0].minor.yy412;
 }
-#line 2440 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2464 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 142:
       case 144:
-#line 499 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy60 = SQLITE_SO_ASC;}
-#line 2446 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 508 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy412 = SQLITE_SO_ASC;}
+#line 2470 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 143:
-#line 500 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy60 = SQLITE_SO_DESC;}
-#line 2451 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 509 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy412 = SQLITE_SO_DESC;}
+#line 2475 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 145:
-#line 502 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy406.z = 0; yygotominor.yy406.n = 0;}
-#line 2456 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 511 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy258.z = 0; yygotominor.yy258.n = 0;}
+#line 2480 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 151:
-#line 520 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy348.pLimit = 0; yygotominor.yy348.pOffset = 0;}
-#line 2461 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 529 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy244.pLimit = 0; yygotominor.yy244.pOffset = 0;}
+#line 2485 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 152:
-#line 521 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy348.pLimit = yymsp[0].minor.yy454; yygotominor.yy348.pOffset = 0;}
-#line 2466 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 530 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy244.pLimit = yymsp[0].minor.yy2; yygotominor.yy244.pOffset = 0;}
+#line 2490 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 153:
-#line 523 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy348.pLimit = yymsp[-2].minor.yy454; yygotominor.yy348.pOffset = yymsp[0].minor.yy454;}
-#line 2471 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 532 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy244.pLimit = yymsp[-2].minor.yy2; yygotominor.yy244.pOffset = yymsp[0].minor.yy2;}
+#line 2495 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 154:
-#line 525 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy348.pOffset = yymsp[-2].minor.yy454; yygotominor.yy348.pLimit = yymsp[0].minor.yy454;}
-#line 2476 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 534 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy244.pOffset = yymsp[-2].minor.yy2; yygotominor.yy244.pLimit = yymsp[0].minor.yy2;}
+#line 2500 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 155:
-#line 529 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3DeleteFrom(pParse,yymsp[-1].minor.yy427,yymsp[0].minor.yy454);}
-#line 2481 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 538 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3DeleteFrom(pParse,yymsp[-1].minor.yy67,yymsp[0].minor.yy2);}
+#line 2505 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 158:
-#line 543 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3Update(pParse,yymsp[-3].minor.yy427,yymsp[-1].minor.yy266,yymsp[0].minor.yy454,yymsp[-4].minor.yy60);}
-#line 2486 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 549 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3Update(pParse,yymsp[-3].minor.yy67,yymsp[-1].minor.yy82,yymsp[0].minor.yy2,yymsp[-4].minor.yy412);}
+#line 2510 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 159:
-#line 546 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy266 = sqlite3ExprListAppend(yymsp[-4].minor.yy266,yymsp[0].minor.yy454,&yymsp[-2].minor.yy406);}
-#line 2491 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 555 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy82 = sqlite3ExprListAppend(yymsp[-4].minor.yy82,yymsp[0].minor.yy2,&yymsp[-2].minor.yy258);}
+#line 2515 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 160:
-#line 547 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy266 = sqlite3ExprListAppend(0,yymsp[0].minor.yy454,&yymsp[-2].minor.yy406);}
-#line 2496 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 556 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy82 = sqlite3ExprListAppend(0,yymsp[0].minor.yy2,&yymsp[-2].minor.yy258);}
+#line 2520 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 161:
-#line 553 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3Insert(pParse, yymsp[-5].minor.yy427, yymsp[-1].minor.yy266, 0, yymsp[-4].minor.yy272, yymsp[-7].minor.yy60);}
-#line 2501 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 562 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3Insert(pParse, yymsp[-5].minor.yy67, yymsp[-1].minor.yy82, 0, yymsp[-4].minor.yy240, yymsp[-7].minor.yy412);}
+#line 2525 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 162:
-#line 555 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3Insert(pParse, yymsp[-2].minor.yy427, 0, yymsp[0].minor.yy331, yymsp[-1].minor.yy272, yymsp[-4].minor.yy60);}
-#line 2506 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 564 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3Insert(pParse, yymsp[-2].minor.yy67, 0, yymsp[0].minor.yy459, yymsp[-1].minor.yy240, yymsp[-4].minor.yy412);}
+#line 2530 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 165:
-      case 240:
-#line 565 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy266 = sqlite3ExprListAppend(yymsp[-2].minor.yy266,yymsp[0].minor.yy454,0);}
-#line 2512 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 236:
+#line 574 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy82 = sqlite3ExprListAppend(yymsp[-2].minor.yy82,yymsp[0].minor.yy2,0);}
+#line 2536 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 166:
-      case 241:
-#line 566 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy266 = sqlite3ExprListAppend(0,yymsp[0].minor.yy454,0);}
-#line 2518 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 237:
+#line 575 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy82 = sqlite3ExprListAppend(0,yymsp[0].minor.yy2,0);}
+#line 2542 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 169:
-#line 575 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy272 = sqlite3IdListAppend(yymsp[-2].minor.yy272,&yymsp[0].minor.yy406);}
-#line 2523 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 584 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy240 = sqlite3IdListAppend(yymsp[-2].minor.yy240,&yymsp[0].minor.yy258);}
+#line 2547 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 170:
-#line 576 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy272 = sqlite3IdListAppend(0,&yymsp[0].minor.yy406);}
-#line 2528 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 585 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy240 = sqlite3IdListAppend(0,&yymsp[0].minor.yy258);}
+#line 2552 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 172:
-#line 587 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy454 = yymsp[-1].minor.yy454; sqlite3ExprSpan(yygotominor.yy454,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); }
-#line 2533 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 596 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy2 = yymsp[-1].minor.yy2; sqlite3ExprSpan(yygotominor.yy2,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); }
+#line 2557 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 173:
       case 178:
       case 179:
       case 180:
       case 181:
-#line 588 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy454 = sqlite3Expr(yymsp[0].major, 0, 0, &yymsp[0].minor.yy0);}
-#line 2542 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 597 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy2 = sqlite3Expr(yymsp[0].major, 0, 0, &yymsp[0].minor.yy0);}
+#line 2566 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 174:
       case 175:
-#line 589 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy454 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy0);}
-#line 2548 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 598 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy0);}
+#line 2572 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 176:
-#line 591 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 600 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy406);
-  Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy406);
-  yygotominor.yy454 = sqlite3Expr(TK_DOT, temp1, temp2, 0);
+  Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy258);
+  Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy258);
+  yygotominor.yy2 = sqlite3Expr(TK_DOT, temp1, temp2, 0);
 }
-#line 2557 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2581 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 177:
-#line 596 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 605 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-4].minor.yy406);
-  Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy406);
-  Expr *temp3 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy406);
+  Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-4].minor.yy258);
+  Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &yymsp[-2].minor.yy258);
+  Expr *temp3 = sqlite3Expr(TK_ID, 0, 0, &yymsp[0].minor.yy258);
   Expr *temp4 = sqlite3Expr(TK_DOT, temp2, temp3, 0);
-  yygotominor.yy454 = sqlite3Expr(TK_DOT, temp1, temp4, 0);
+  yygotominor.yy2 = sqlite3Expr(TK_DOT, temp1, temp4, 0);
 }
-#line 2568 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2592 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 182:
-#line 607 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy454 = sqlite3RegisterExpr(pParse, &yymsp[0].minor.yy0);}
-#line 2573 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 616 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy2 = sqlite3RegisterExpr(pParse, &yymsp[0].minor.yy0);}
+#line 2597 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 183:
-#line 608 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 617 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
   Token *pToken = &yymsp[0].minor.yy0;
-  Expr *pExpr = yygotominor.yy454 = sqlite3Expr(TK_VARIABLE, 0, 0, pToken);
+  Expr *pExpr = yygotominor.yy2 = sqlite3Expr(TK_VARIABLE, 0, 0, pToken);
   sqlite3ExprAssignVarNumber(pParse, pExpr);
 }
-#line 2582 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2606 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 184:
-#line 613 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 622 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  yygotominor.yy454 = sqlite3ExprFunction(yymsp[-1].minor.yy266, &yymsp[-3].minor.yy0);
-  sqlite3ExprSpan(yygotominor.yy454,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
+  yygotominor.yy2 = sqlite3ExprFunction(yymsp[-1].minor.yy82, &yymsp[-3].minor.yy0);
+  sqlite3ExprSpan(yygotominor.yy2,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
 }
-#line 2590 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2614 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 185:
-#line 617 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 626 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  yygotominor.yy454 = sqlite3ExprFunction(0, &yymsp[-3].minor.yy0);
-  sqlite3ExprSpan(yygotominor.yy454,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
+  yygotominor.yy2 = sqlite3ExprFunction(0, &yymsp[-3].minor.yy0);
+  sqlite3ExprSpan(yygotominor.yy2,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
 }
-#line 2598 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2622 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 186:
+#line 630 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{
+  /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
+  ** treated as functions that return constants */
+  yygotominor.yy2 = sqlite3ExprFunction(0,&yymsp[0].minor.yy0);
+  if( yygotominor.yy2 ) yygotominor.yy2->op = TK_CONST_FUNC;  
+}
+#line 2632 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
+        break;
       case 187:
       case 188:
-#line 621 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy454 = sqlite3Expr(yymsp[0].major,0,0,0);}
-#line 2605 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
-        break;
       case 189:
       case 190:
       case 191:
@@ -2618,476 +2647,499 @@ static void yy_reduce(
       case 202:
       case 203:
       case 204:
-      case 205:
-      case 206:
-#line 624 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy454 = sqlite3Expr(yymsp[-1].major, yymsp[-2].minor.yy454, yymsp[0].minor.yy454, 0);}
-#line 2627 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 636 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy2 = sqlite3Expr(yymsp[-1].major, yymsp[-2].minor.yy2, yymsp[0].minor.yy2, 0);}
+#line 2654 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 207:
-#line 643 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy258.opcode = TK_LIKE; yygotominor.yy258.not = 0;}
-#line 2632 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 205:
+#line 655 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy438.operator = yymsp[0].minor.yy0; yygotominor.yy438.not = 0;}
+#line 2659 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 208:
-#line 644 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy258.opcode = TK_GLOB; yygotominor.yy258.not = 0;}
-#line 2637 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 206:
+#line 656 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy438.operator = yymsp[0].minor.yy0; yygotominor.yy438.not = 1;}
+#line 2664 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 209:
-#line 645 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy258.opcode = TK_LIKE; yygotominor.yy258.not = 1;}
-#line 2642 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
-        break;
-      case 210:
-#line 646 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy258.opcode = TK_GLOB; yygotominor.yy258.not = 1;}
-#line 2647 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
-        break;
-      case 213:
-#line 650 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 660 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  ExprList *pList = sqlite3ExprListAppend(0, yymsp[-1].minor.yy454, 0);
-  pList = sqlite3ExprListAppend(pList, yymsp[-3].minor.yy454, 0);
-  if( yymsp[0].minor.yy454 ){
-    pList = sqlite3ExprListAppend(pList, yymsp[0].minor.yy454, 0);
+  ExprList *pList = sqlite3ExprListAppend(0, yymsp[-1].minor.yy2, 0);
+  pList = sqlite3ExprListAppend(pList, yymsp[-3].minor.yy2, 0);
+  if( yymsp[0].minor.yy2 ){
+    pList = sqlite3ExprListAppend(pList, yymsp[0].minor.yy2, 0);
   }
-  yygotominor.yy454 = sqlite3ExprFunction(pList, 0);
-  if( yygotominor.yy454 ) yygotominor.yy454->op = yymsp[-2].minor.yy258.opcode;
-  if( yymsp[-2].minor.yy258.not ) yygotominor.yy454 = sqlite3Expr(TK_NOT, yygotominor.yy454, 0, 0);
-  sqlite3ExprSpan(yygotominor.yy454, &yymsp[-3].minor.yy454->span, &yymsp[-1].minor.yy454->span);
+  yygotominor.yy2 = sqlite3ExprFunction(pList, &yymsp[-2].minor.yy438.operator);
+  if( yymsp[-2].minor.yy438.not ) yygotominor.yy2 = sqlite3Expr(TK_NOT, yygotominor.yy2, 0, 0);
+  sqlite3ExprSpan(yygotominor.yy2, &yymsp[-3].minor.yy2->span, &yymsp[-1].minor.yy2->span);
 }
-#line 2662 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2678 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 214:
-#line 662 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 210:
+#line 671 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  yygotominor.yy454 = sqlite3Expr(TK_ISNULL, yymsp[-1].minor.yy454, 0, 0);
-  sqlite3ExprSpan(yygotominor.yy454,&yymsp[-1].minor.yy454->span,&yymsp[0].minor.yy0);
+  yygotominor.yy2 = sqlite3Expr(TK_ISNULL, yymsp[-1].minor.yy2, 0, 0);
+  sqlite3ExprSpan(yygotominor.yy2,&yymsp[-1].minor.yy2->span,&yymsp[0].minor.yy0);
 }
-#line 2670 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2686 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 215:
-#line 666 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 211:
+#line 675 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  yygotominor.yy454 = sqlite3Expr(TK_ISNULL, yymsp[-2].minor.yy454, 0, 0);
-  sqlite3ExprSpan(yygotominor.yy454,&yymsp[-2].minor.yy454->span,&yymsp[0].minor.yy0);
+  yygotominor.yy2 = sqlite3Expr(TK_ISNULL, yymsp[-2].minor.yy2, 0, 0);
+  sqlite3ExprSpan(yygotominor.yy2,&yymsp[-2].minor.yy2->span,&yymsp[0].minor.yy0);
 }
-#line 2678 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2694 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 216:
-#line 670 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 212:
+#line 679 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  yygotominor.yy454 = sqlite3Expr(TK_NOTNULL, yymsp[-1].minor.yy454, 0, 0);
-  sqlite3ExprSpan(yygotominor.yy454,&yymsp[-1].minor.yy454->span,&yymsp[0].minor.yy0);
+  yygotominor.yy2 = sqlite3Expr(TK_NOTNULL, yymsp[-1].minor.yy2, 0, 0);
+  sqlite3ExprSpan(yygotominor.yy2,&yymsp[-1].minor.yy2->span,&yymsp[0].minor.yy0);
 }
-#line 2686 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2702 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 217:
-#line 674 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 213:
+#line 683 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  yygotominor.yy454 = sqlite3Expr(TK_NOTNULL, yymsp[-2].minor.yy454, 0, 0);
-  sqlite3ExprSpan(yygotominor.yy454,&yymsp[-2].minor.yy454->span,&yymsp[0].minor.yy0);
+  yygotominor.yy2 = sqlite3Expr(TK_NOTNULL, yymsp[-2].minor.yy2, 0, 0);
+  sqlite3ExprSpan(yygotominor.yy2,&yymsp[-2].minor.yy2->span,&yymsp[0].minor.yy0);
 }
-#line 2694 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2710 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 218:
-#line 678 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 214:
+#line 687 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  yygotominor.yy454 = sqlite3Expr(TK_NOTNULL, yymsp[-3].minor.yy454, 0, 0);
-  sqlite3ExprSpan(yygotominor.yy454,&yymsp[-3].minor.yy454->span,&yymsp[0].minor.yy0);
+  yygotominor.yy2 = sqlite3Expr(TK_NOTNULL, yymsp[-3].minor.yy2, 0, 0);
+  sqlite3ExprSpan(yygotominor.yy2,&yymsp[-3].minor.yy2->span,&yymsp[0].minor.yy0);
 }
-#line 2702 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2718 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 219:
-      case 220:
-#line 682 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 215:
+      case 216:
+#line 691 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  yygotominor.yy454 = sqlite3Expr(yymsp[-1].major, yymsp[0].minor.yy454, 0, 0);
-  sqlite3ExprSpan(yygotominor.yy454,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy454->span);
+  yygotominor.yy2 = sqlite3Expr(yymsp[-1].major, yymsp[0].minor.yy2, 0, 0);
+  sqlite3ExprSpan(yygotominor.yy2,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy2->span);
 }
-#line 2711 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2727 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 221:
-#line 690 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 217:
+#line 699 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  yygotominor.yy454 = sqlite3Expr(TK_UMINUS, yymsp[0].minor.yy454, 0, 0);
-  sqlite3ExprSpan(yygotominor.yy454,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy454->span);
+  yygotominor.yy2 = sqlite3Expr(TK_UMINUS, yymsp[0].minor.yy2, 0, 0);
+  sqlite3ExprSpan(yygotominor.yy2,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy2->span);
 }
-#line 2719 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2735 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 222:
-#line 694 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 218:
+#line 703 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  yygotominor.yy454 = sqlite3Expr(TK_UPLUS, yymsp[0].minor.yy454, 0, 0);
-  sqlite3ExprSpan(yygotominor.yy454,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy454->span);
+  yygotominor.yy2 = sqlite3Expr(TK_UPLUS, yymsp[0].minor.yy2, 0, 0);
+  sqlite3ExprSpan(yygotominor.yy2,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy2->span);
 }
-#line 2727 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2743 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 225:
-#line 701 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 221:
+#line 710 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  ExprList *pList = sqlite3ExprListAppend(0, yymsp[-2].minor.yy454, 0);
-  pList = sqlite3ExprListAppend(pList, yymsp[0].minor.yy454, 0);
-  yygotominor.yy454 = sqlite3Expr(TK_BETWEEN, yymsp[-4].minor.yy454, 0, 0);
-  if( yygotominor.yy454 ) yygotominor.yy454->pList = pList;
-  if( yymsp[-3].minor.yy60 ) yygotominor.yy454 = sqlite3Expr(TK_NOT, yygotominor.yy454, 0, 0);
-  sqlite3ExprSpan(yygotominor.yy454,&yymsp[-4].minor.yy454->span,&yymsp[0].minor.yy454->span);
+  ExprList *pList = sqlite3ExprListAppend(0, yymsp[-2].minor.yy2, 0);
+  pList = sqlite3ExprListAppend(pList, yymsp[0].minor.yy2, 0);
+  yygotominor.yy2 = sqlite3Expr(TK_BETWEEN, yymsp[-4].minor.yy2, 0, 0);
+  if( yygotominor.yy2 ) yygotominor.yy2->pList = pList;
+  if( yymsp[-3].minor.yy412 ) yygotominor.yy2 = sqlite3Expr(TK_NOT, yygotominor.yy2, 0, 0);
+  sqlite3ExprSpan(yygotominor.yy2,&yymsp[-4].minor.yy2->span,&yymsp[0].minor.yy2->span);
 }
-#line 2739 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2755 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 228:
-#line 713 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 224:
+#line 722 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-    yygotominor.yy454 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy454, 0, 0);
-    if( yygotominor.yy454 ) yygotominor.yy454->pList = yymsp[-1].minor.yy266;
-    if( yymsp[-3].minor.yy60 ) yygotominor.yy454 = sqlite3Expr(TK_NOT, yygotominor.yy454, 0, 0);
-    sqlite3ExprSpan(yygotominor.yy454,&yymsp[-4].minor.yy454->span,&yymsp[0].minor.yy0);
+    yygotominor.yy2 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy2, 0, 0);
+    if( yygotominor.yy2 ){
+      yygotominor.yy2->pList = yymsp[-1].minor.yy82;
+    }else{
+      sqlite3ExprListDelete(yymsp[-1].minor.yy82);
+    }
+    if( yymsp[-3].minor.yy412 ) yygotominor.yy2 = sqlite3Expr(TK_NOT, yygotominor.yy2, 0, 0);
+    sqlite3ExprSpan(yygotominor.yy2,&yymsp[-4].minor.yy2->span,&yymsp[0].minor.yy0);
   }
-#line 2749 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2769 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 229:
-#line 719 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 225:
+#line 732 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-    yygotominor.yy454 = sqlite3Expr(TK_SELECT, 0, 0, 0);
-    if( yygotominor.yy454 ) yygotominor.yy454->pSelect = yymsp[-1].minor.yy331;
-    sqlite3ExprSpan(yygotominor.yy454,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
+    yygotominor.yy2 = sqlite3Expr(TK_SELECT, 0, 0, 0);
+    if( yygotominor.yy2 ) yygotominor.yy2->pSelect = yymsp[-1].minor.yy459;
+    if( !yygotominor.yy2 ) sqlite3SelectDelete(yymsp[-1].minor.yy459);
+    sqlite3ExprSpan(yygotominor.yy2,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
   }
-#line 2758 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2779 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 230:
-#line 724 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 226:
+#line 738 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-    yygotominor.yy454 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy454, 0, 0);
-    if( yygotominor.yy454 ) yygotominor.yy454->pSelect = yymsp[-1].minor.yy331;
-    if( yymsp[-3].minor.yy60 ) yygotominor.yy454 = sqlite3Expr(TK_NOT, yygotominor.yy454, 0, 0);
-    sqlite3ExprSpan(yygotominor.yy454,&yymsp[-4].minor.yy454->span,&yymsp[0].minor.yy0);
+    yygotominor.yy2 = sqlite3Expr(TK_IN, yymsp[-4].minor.yy2, 0, 0);
+    if( yygotominor.yy2 ) yygotominor.yy2->pSelect = yymsp[-1].minor.yy459;
+    if( !yygotominor.yy2 ) sqlite3SelectDelete(yymsp[-1].minor.yy459);
+    if( yymsp[-3].minor.yy412 ) yygotominor.yy2 = sqlite3Expr(TK_NOT, yygotominor.yy2, 0, 0);
+    sqlite3ExprSpan(yygotominor.yy2,&yymsp[-4].minor.yy2->span,&yymsp[0].minor.yy0);
   }
-#line 2768 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2790 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 231:
-#line 730 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 227:
+#line 745 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-    SrcList *pSrc = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy406,&yymsp[0].minor.yy406);
-    yygotominor.yy454 = sqlite3Expr(TK_IN, yymsp[-3].minor.yy454, 0, 0);
-    if( yygotominor.yy454 ) yygotominor.yy454->pSelect = sqlite3SelectNew(0,pSrc,0,0,0,0,0,0,0);
-    if( yymsp[-2].minor.yy60 ) yygotominor.yy454 = sqlite3Expr(TK_NOT, yygotominor.yy454, 0, 0);
-    sqlite3ExprSpan(yygotominor.yy454,&yymsp[-3].minor.yy454->span,yymsp[0].minor.yy406.z?&yymsp[0].minor.yy406:&yymsp[-1].minor.yy406);
+    SrcList *pSrc = sqlite3SrcListAppend(0,&yymsp[-1].minor.yy258,&yymsp[0].minor.yy258);
+    yygotominor.yy2 = sqlite3Expr(TK_IN, yymsp[-3].minor.yy2, 0, 0);
+    if( yygotominor.yy2 ) yygotominor.yy2->pSelect = sqlite3SelectNew(0,pSrc,0,0,0,0,0,0,0);
+    if( yymsp[-2].minor.yy412 ) yygotominor.yy2 = sqlite3Expr(TK_NOT, yygotominor.yy2, 0, 0);
+    sqlite3ExprSpan(yygotominor.yy2,&yymsp[-3].minor.yy2->span,yymsp[0].minor.yy258.z?&yymsp[0].minor.yy258:&yymsp[-1].minor.yy258);
   }
-#line 2779 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2801 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 232:
-#line 737 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 228:
+#line 752 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-    Expr *p = yygotominor.yy454 = sqlite3Expr(TK_EXISTS, 0, 0, 0);
+    Expr *p = yygotominor.yy2 = sqlite3Expr(TK_EXISTS, 0, 0, 0);
     if( p ){
-      p->pSelect = yymsp[-1].minor.yy331;
+      p->pSelect = yymsp[-1].minor.yy459;
       sqlite3ExprSpan(p,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
     }
+    if( !p ) sqlite3SelectDelete(yymsp[-1].minor.yy459);
   }
-#line 2790 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2813 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 233:
-#line 747 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 229:
+#line 763 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  yygotominor.yy454 = sqlite3Expr(TK_CASE, yymsp[-3].minor.yy454, yymsp[-1].minor.yy454, 0);
-  if( yygotominor.yy454 ) yygotominor.yy454->pList = yymsp[-2].minor.yy266;
-  sqlite3ExprSpan(yygotominor.yy454, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0);
+  yygotominor.yy2 = sqlite3Expr(TK_CASE, yymsp[-3].minor.yy2, yymsp[-1].minor.yy2, 0);
+  if( yygotominor.yy2 ) yygotominor.yy2->pList = yymsp[-2].minor.yy82;
+  sqlite3ExprSpan(yygotominor.yy2, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0);
 }
-#line 2799 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2822 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 234:
-#line 754 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 230:
+#line 770 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  yygotominor.yy266 = sqlite3ExprListAppend(yymsp[-4].minor.yy266, yymsp[-2].minor.yy454, 0);
-  yygotominor.yy266 = sqlite3ExprListAppend(yygotominor.yy266, yymsp[0].minor.yy454, 0);
+  yygotominor.yy82 = sqlite3ExprListAppend(yymsp[-4].minor.yy82, yymsp[-2].minor.yy2, 0);
+  yygotominor.yy82 = sqlite3ExprListAppend(yygotominor.yy82, yymsp[0].minor.yy2, 0);
 }
-#line 2807 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2830 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 235:
-#line 758 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 231:
+#line 774 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  yygotominor.yy266 = sqlite3ExprListAppend(0, yymsp[-2].minor.yy454, 0);
-  yygotominor.yy266 = sqlite3ExprListAppend(yygotominor.yy266, yymsp[0].minor.yy454, 0);
+  yygotominor.yy82 = sqlite3ExprListAppend(0, yymsp[-2].minor.yy2, 0);
+  yygotominor.yy82 = sqlite3ExprListAppend(yygotominor.yy82, yymsp[0].minor.yy2, 0);
 }
-#line 2815 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2838 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 244:
-#line 783 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 240:
+#line 799 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  if( yymsp[-9].minor.yy60!=OE_None ) yymsp[-9].minor.yy60 = yymsp[0].minor.yy60;
-  if( yymsp[-9].minor.yy60==OE_Default) yymsp[-9].minor.yy60 = OE_Abort;
-  sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy406, &yymsp[-6].minor.yy406, sqlite3SrcListAppend(0,&yymsp[-4].minor.yy406,0),yymsp[-2].minor.yy266,yymsp[-9].minor.yy60, &yymsp[-10].minor.yy0, &yymsp[-1].minor.yy0);
+  if( yymsp[-9].minor.yy412!=OE_None ) yymsp[-9].minor.yy412 = yymsp[0].minor.yy412;
+  if( yymsp[-9].minor.yy412==OE_Default) yymsp[-9].minor.yy412 = OE_Abort;
+  sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy258, &yymsp[-6].minor.yy258, sqlite3SrcListAppend(0,&yymsp[-4].minor.yy258,0),yymsp[-2].minor.yy82,yymsp[-9].minor.yy412, &yymsp[-10].minor.yy0, &yymsp[-1].minor.yy0);
 }
-#line 2824 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2847 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 245:
-      case 292:
-#line 790 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy60 = OE_Abort;}
-#line 2830 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 241:
+      case 288:
+#line 806 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy412 = OE_Abort;}
+#line 2853 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 246:
-#line 791 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy60 = OE_None;}
-#line 2835 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 242:
+#line 807 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy412 = OE_None;}
+#line 2858 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 249:
-#line 801 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 245:
+#line 817 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
   Expr *p = 0;
-  if( yymsp[-1].minor.yy406.n>0 ){
+  if( yymsp[-1].minor.yy258.n>0 ){
     p = sqlite3Expr(TK_COLUMN, 0, 0, 0);
-    if( p ) p->pColl = sqlite3LocateCollSeq(pParse, yymsp[-1].minor.yy406.z, yymsp[-1].minor.yy406.n);
+    if( p ) p->pColl = sqlite3LocateCollSeq(pParse, yymsp[-1].minor.yy258.z, yymsp[-1].minor.yy258.n);
   }
-  yygotominor.yy266 = sqlite3ExprListAppend(yymsp[-4].minor.yy266, p, &yymsp[-2].minor.yy406);
+  yygotominor.yy82 = sqlite3ExprListAppend(yymsp[-4].minor.yy82, p, &yymsp[-2].minor.yy258);
 }
-#line 2847 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2870 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 250:
-#line 809 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 246:
+#line 825 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
   Expr *p = 0;
-  if( yymsp[-1].minor.yy406.n>0 ){
+  if( yymsp[-1].minor.yy258.n>0 ){
     p = sqlite3Expr(TK_COLUMN, 0, 0, 0);
-    if( p ) p->pColl = sqlite3LocateCollSeq(pParse, yymsp[-1].minor.yy406.z, yymsp[-1].minor.yy406.n);
+    if( p ) p->pColl = sqlite3LocateCollSeq(pParse, yymsp[-1].minor.yy258.z, yymsp[-1].minor.yy258.n);
   }
-  yygotominor.yy266 = sqlite3ExprListAppend(0, p, &yymsp[-2].minor.yy406);
+  yygotominor.yy82 = sqlite3ExprListAppend(0, p, &yymsp[-2].minor.yy258);
 }
-#line 2859 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2882 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 252:
-#line 822 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3DropIndex(pParse, yymsp[0].minor.yy427);}
-#line 2864 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 248:
+#line 838 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3DropIndex(pParse, yymsp[0].minor.yy67);}
+#line 2887 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 253:
-      case 254:
-#line 826 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 249:
+      case 250:
+#line 842 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {sqlite3Vacuum(pParse,0);}
-#line 2870 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2893 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 255:
-      case 257:
-#line 832 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3Pragma(pParse,&yymsp[-3].minor.yy406,&yymsp[-2].minor.yy406,&yymsp[0].minor.yy406,0);}
-#line 2876 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 251:
+      case 253:
+#line 848 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3Pragma(pParse,&yymsp[-3].minor.yy258,&yymsp[-2].minor.yy258,&yymsp[0].minor.yy258,0);}
+#line 2899 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 256:
-#line 833 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3Pragma(pParse,&yymsp[-3].minor.yy406,&yymsp[-2].minor.yy406,&yymsp[0].minor.yy0,0);}
-#line 2881 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 252:
+#line 849 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3Pragma(pParse,&yymsp[-3].minor.yy258,&yymsp[-2].minor.yy258,&yymsp[0].minor.yy0,0);}
+#line 2904 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 258:
-#line 835 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 254:
+#line 851 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  sqlite3Pragma(pParse,&yymsp[-3].minor.yy406,&yymsp[-2].minor.yy406,&yymsp[0].minor.yy406,1);
+  sqlite3Pragma(pParse,&yymsp[-3].minor.yy258,&yymsp[-2].minor.yy258,&yymsp[0].minor.yy258,1);
 }
-#line 2888 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2911 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 259:
-#line 838 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3Pragma(pParse,&yymsp[-4].minor.yy406,&yymsp[-3].minor.yy406,&yymsp[-1].minor.yy406,0);}
-#line 2893 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 255:
+#line 854 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3Pragma(pParse,&yymsp[-4].minor.yy258,&yymsp[-3].minor.yy258,&yymsp[-1].minor.yy258,0);}
+#line 2916 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 260:
-#line 839 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3Pragma(pParse,&yymsp[-1].minor.yy406,&yymsp[0].minor.yy406,0,0);}
-#line 2898 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 256:
+#line 855 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3Pragma(pParse,&yymsp[-1].minor.yy258,&yymsp[0].minor.yy258,0,0);}
+#line 2921 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 267:
-#line 852 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 263:
+#line 868 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
   Token all;
-  all.z = yymsp[-3].minor.yy406.z;
-  all.n = (yymsp[0].minor.yy0.z - yymsp[-3].minor.yy406.z) + yymsp[0].minor.yy0.n;
-  sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy455, &all);
+  all.z = yymsp[-3].minor.yy258.z;
+  all.n = (yymsp[0].minor.yy0.z - yymsp[-3].minor.yy258.z) + yymsp[0].minor.yy0.n;
+  sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy347, &all);
 }
-#line 2908 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2931 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 268:
-#line 861 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 264:
+#line 877 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy406, &yymsp[-6].minor.yy406, yymsp[-5].minor.yy60, yymsp[-4].minor.yy62.a, yymsp[-4].minor.yy62.b, yymsp[-2].minor.yy427, yymsp[-1].minor.yy60, yymsp[0].minor.yy454, yymsp[-9].minor.yy60);
-  yygotominor.yy406 = (yymsp[-6].minor.yy406.n==0?yymsp[-7].minor.yy406:yymsp[-6].minor.yy406);
+  sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy258, &yymsp[-6].minor.yy258, yymsp[-5].minor.yy412, yymsp[-4].minor.yy210.a, yymsp[-4].minor.yy210.b, yymsp[-2].minor.yy67, yymsp[-1].minor.yy412, yymsp[0].minor.yy2, yymsp[-9].minor.yy412);
+  yygotominor.yy258 = (yymsp[-6].minor.yy258.n==0?yymsp[-7].minor.yy258:yymsp[-6].minor.yy258);
 }
-#line 2916 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 2939 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 269:
-      case 272:
-#line 867 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy60 = TK_BEFORE; }
-#line 2922 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 265:
+      case 268:
+#line 883 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy412 = TK_BEFORE; }
+#line 2945 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 270:
-#line 868 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy60 = TK_AFTER;  }
-#line 2927 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 266:
+#line 884 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy412 = TK_AFTER;  }
+#line 2950 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
+        break;
+      case 267:
+#line 885 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy412 = TK_INSTEAD;}
+#line 2955 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
+      case 269:
+      case 270:
       case 271:
-#line 869 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy60 = TK_INSTEAD;}
-#line 2932 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 890 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy210.a = yymsp[0].major; yygotominor.yy210.b = 0;}
+#line 2962 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
+        break;
+      case 272:
+#line 893 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy210.a = TK_UPDATE; yygotominor.yy210.b = yymsp[0].minor.yy240;}
+#line 2967 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 273:
       case 274:
+#line 896 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy412 = TK_ROW; }
+#line 2973 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
+        break;
       case 275:
-#line 874 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy62.a = yymsp[0].major; yygotominor.yy62.b = 0;}
-#line 2939 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 898 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy412 = TK_STATEMENT; }
+#line 2978 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 276:
-#line 877 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy62.a = TK_UPDATE; yygotominor.yy62.b = yymsp[0].minor.yy272;}
-#line 2944 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 901 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy2 = 0; }
+#line 2983 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 277:
+#line 902 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy2 = yymsp[0].minor.yy2; }
+#line 2988 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
+        break;
       case 278:
-#line 880 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy60 = TK_ROW; }
-#line 2950 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 906 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{
+  yymsp[-2].minor.yy347->pNext = yymsp[0].minor.yy347;
+  yygotominor.yy347 = yymsp[-2].minor.yy347;
+}
+#line 2996 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 279:
-#line 882 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy60 = TK_STATEMENT; }
-#line 2955 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 910 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy347 = 0; }
+#line 3001 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 280:
-#line 885 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy454 = 0; }
-#line 2960 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 916 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy347 = sqlite3TriggerUpdateStep(&yymsp[-3].minor.yy258, yymsp[-1].minor.yy82, yymsp[0].minor.yy2, yymsp[-4].minor.yy412); }
+#line 3006 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 281:
-#line 886 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy454 = yymsp[0].minor.yy454; }
-#line 2965 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 921 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy347 = sqlite3TriggerInsertStep(&yymsp[-5].minor.yy258, yymsp[-4].minor.yy240, yymsp[-1].minor.yy82, 0, yymsp[-7].minor.yy412);}
+#line 3011 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 282:
-#line 890 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{
-  yymsp[-2].minor.yy455->pNext = yymsp[0].minor.yy455;
-  yygotominor.yy455 = yymsp[-2].minor.yy455;
-}
-#line 2973 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 924 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy347 = sqlite3TriggerInsertStep(&yymsp[-2].minor.yy258, yymsp[-1].minor.yy240, 0, yymsp[0].minor.yy459, yymsp[-4].minor.yy412);}
+#line 3016 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 283:
-#line 894 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy455 = 0; }
-#line 2978 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 928 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy347 = sqlite3TriggerDeleteStep(&yymsp[-1].minor.yy258, yymsp[0].minor.yy2);}
+#line 3021 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 284:
-#line 900 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy455 = sqlite3TriggerUpdateStep(&yymsp[-3].minor.yy406, yymsp[-1].minor.yy266, yymsp[0].minor.yy454, yymsp[-4].minor.yy60); }
-#line 2983 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 931 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy347 = sqlite3TriggerSelectStep(yymsp[0].minor.yy459); }
+#line 3026 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 285:
-#line 905 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy455 = sqlite3TriggerInsertStep(&yymsp[-5].minor.yy406, yymsp[-4].minor.yy272, yymsp[-1].minor.yy266, 0, yymsp[-7].minor.yy60);}
-#line 2988 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 934 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{
+  yygotominor.yy2 = sqlite3Expr(TK_RAISE, 0, 0, 0); 
+  yygotominor.yy2->iColumn = OE_Ignore;
+  sqlite3ExprSpan(yygotominor.yy2, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0);
+}
+#line 3035 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 286:
-#line 908 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy455 = sqlite3TriggerInsertStep(&yymsp[-2].minor.yy406, yymsp[-1].minor.yy272, 0, yymsp[0].minor.yy331, yymsp[-4].minor.yy60);}
-#line 2993 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 939 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{
+  yygotominor.yy2 = sqlite3Expr(TK_RAISE, 0, 0, &yymsp[-1].minor.yy258); 
+  yygotominor.yy2->iColumn = yymsp[-3].minor.yy412;
+  sqlite3ExprSpan(yygotominor.yy2, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0);
+}
+#line 3044 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 287:
-#line 912 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy455 = sqlite3TriggerDeleteStep(&yymsp[-1].minor.yy406, yymsp[0].minor.yy454);}
-#line 2998 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
-        break;
-      case 288:
-#line 915 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy455 = sqlite3TriggerSelectStep(yymsp[0].minor.yy331); }
-#line 3003 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 947 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy412 = OE_Rollback;}
+#line 3049 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 289:
-#line 918 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{
-  yygotominor.yy454 = sqlite3Expr(TK_RAISE, 0, 0, 0); 
-  yygotominor.yy454->iColumn = OE_Ignore;
-  sqlite3ExprSpan(yygotominor.yy454, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0);
-}
-#line 3012 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 949 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{yygotominor.yy412 = OE_Fail;}
+#line 3054 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 290:
-#line 923 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 954 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  yygotominor.yy454 = sqlite3Expr(TK_RAISE, 0, 0, &yymsp[-1].minor.yy406); 
-  yygotominor.yy454->iColumn = yymsp[-3].minor.yy60;
-  sqlite3ExprSpan(yygotominor.yy454, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0);
+  sqlite3DropTrigger(pParse,yymsp[0].minor.yy67);
 }
-#line 3021 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 3061 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 291:
-#line 931 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy60 = OE_Rollback;}
-#line 3026 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 960 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{
+  sqlite3Attach(pParse, &yymsp[-3].minor.yy258, &yymsp[-1].minor.yy258, yymsp[0].minor.yy132.type, &yymsp[0].minor.yy132.key);
+}
+#line 3068 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
+        break;
+      case 292:
+#line 964 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy132.type = 0; }
+#line 3073 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 293:
-#line 933 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{yygotominor.yy60 = OE_Fail;}
-#line 3031 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 965 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy132.type=1; yygotominor.yy132.key = yymsp[0].minor.yy258; }
+#line 3078 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 294:
-#line 938 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{
-  sqlite3DropTrigger(pParse,yymsp[0].minor.yy427);
-}
-#line 3038 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 966 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{ yygotominor.yy132.type=2; yygotominor.yy132.key = yymsp[0].minor.yy0; }
+#line 3083 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 295:
-#line 944 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+      case 297:
+#line 972 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  sqlite3Attach(pParse, &yymsp[-3].minor.yy406, &yymsp[-1].minor.yy406, yymsp[0].minor.yy40.type, &yymsp[0].minor.yy40.key);
+  sqlite3Detach(pParse, &yymsp[0].minor.yy258);
 }
-#line 3045 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 3090 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 296:
-#line 948 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy40.type = 0; }
-#line 3050 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 298:
+#line 978 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3Reindex(pParse, 0, 0);}
+#line 3095 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 297:
-#line 949 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy40.type=1; yygotominor.yy40.key = yymsp[0].minor.yy406; }
-#line 3055 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 299:
+#line 979 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{sqlite3Reindex(pParse, &yymsp[-1].minor.yy258, &yymsp[0].minor.yy258);}
+#line 3100 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
-      case 298:
-#line 950 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{ yygotominor.yy40.type=2; yygotominor.yy40.key = yymsp[0].minor.yy0; }
-#line 3060 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+      case 300:
+#line 984 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
+{
+  sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy67,&yymsp[0].minor.yy258);
+}
+#line 3107 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 301:
-#line 956 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 987 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  sqlite3Detach(pParse, &yymsp[0].minor.yy406);
+  sqlite3AlterFinishAddColumn(pParse, &yymsp[0].minor.yy258);
 }
-#line 3067 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 3114 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
       case 302:
-#line 962 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3Reindex(pParse, 0, 0);}
-#line 3072 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
-        break;
-      case 303:
-#line 963 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
-{sqlite3Reindex(pParse, &yymsp[-1].minor.yy406, &yymsp[0].minor.yy406);}
-#line 3077 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
-        break;
-      case 304:
-#line 968 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 990 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 {
-  sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy427,&yymsp[0].minor.yy406);
+  sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy67);
 }
-#line 3084 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 3121 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
         break;
   };
   yygoto = yyRuleInfo[yyruleno].lhs;
   yysize = yyRuleInfo[yyruleno].nrhs;
   yypParser->yyidx -= yysize;
-  yyact = yy_find_reduce_action(yypParser,yygoto);
+  yyact = yy_find_reduce_action(yymsp[-yysize].stateno,yygoto);
   if( yyact < YYNSTATE ){
-    yy_shift(yypParser,yyact,yygoto,&yygotominor);
+#ifdef NDEBUG
+    /* If we are not debugging and the reduce action popped at least
+    ** one element off the stack, then we can push the new element back
+    ** onto the stack here, and skip the stack overflow test in yy_shift().
+    ** That gives a significant speed improvement. */
+    if( yysize ){
+      yypParser->yyidx++;
+      yymsp -= yysize-1;
+      yymsp->stateno = yyact;
+      yymsp->major = yygoto;
+      yymsp->minor = yygotominor;
+    }else
+#endif
+    {
+      yy_shift(yypParser,yyact,yygoto,&yygotominor);
+    }
   }else if( yyact == YYNSTATE + YYNRULE + 1 ){
     yy_accept(yypParser);
   }
@@ -3121,7 +3173,7 @@ static void yy_syntax_error(
 ){
   sqlite3ParserARG_FETCH;
 #define TOKEN (yyminor.yy0)
-#line 23 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.y"
+#line 23 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.y"
 
   if( pParse->zErrMsg==0 ){
     if( TOKEN.z[0] ){
@@ -3130,7 +3182,7 @@ static void yy_syntax_error(
       sqlite3ErrorMsg(pParse, "incomplete SQL statement");
     }
   }
-#line 3136 "/home/wez/php5-HEAD/ext/pdo_sqlite/sqlite/src/parse.c"
+#line 3188 "/home/rei/php_dev/php5.1/ext/pdo_sqlite/sqlite/src/parse.c"
   sqlite3ParserARG_STORE; /* Suppress warning about unused %extra_argument variable */
 }
 
@@ -3186,7 +3238,7 @@ void sqlite3Parser(
   /* (re)initialize the parser, if necessary */
   yypParser = (yyParser*)yyp;
   if( yypParser->yyidx<0 ){
-    if( yymajor==0 ) return;
+    /* if( yymajor==0 ) return; // not sure why this was here... */
     yypParser->yyidx = 0;
     yypParser->yyerrcnt = -1;
     yypParser->yystack[0].stateno = 0;
index 8da2135f7f65aff99931d914fa5eb6bc1264f851..9dc0a15f9f18f0c7445ae574cf22b2a04f191f93 100644 (file)
@@ -6,42 +6,42 @@
 #define TK_FUNCTION                        6
 #define TK_COLUMN                          7
 #define TK_AGG_FUNCTION                    8
-#define TK_SEMI                            9
-#define TK_EXPLAIN                        10
-#define TK_BEGIN                          11
-#define TK_TRANSACTION                    12
-#define TK_DEFERRED                       13
-#define TK_IMMEDIATE                      14
-#define TK_EXCLUSIVE                      15
-#define TK_COMMIT                         16
-#define TK_END                            17
-#define TK_ROLLBACK                       18
-#define TK_CREATE                         19
-#define TK_TABLE                          20
-#define TK_TEMP                           21
-#define TK_LP                             22
-#define TK_RP                             23
-#define TK_AS                             24
-#define TK_COMMA                          25
-#define TK_ID                             26
-#define TK_ABORT                          27
-#define TK_AFTER                          28
-#define TK_ASC                            29
-#define TK_ATTACH                         30
-#define TK_BEFORE                         31
-#define TK_CASCADE                        32
-#define TK_CONFLICT                       33
-#define TK_DATABASE                       34
-#define TK_DESC                           35
-#define TK_DETACH                         36
-#define TK_EACH                           37
-#define TK_FAIL                           38
-#define TK_FOR                            39
-#define TK_GLOB                           40
+#define TK_CONST_FUNC                      9
+#define TK_SEMI                           10
+#define TK_EXPLAIN                        11
+#define TK_BEGIN                          12
+#define TK_TRANSACTION                    13
+#define TK_DEFERRED                       14
+#define TK_IMMEDIATE                      15
+#define TK_EXCLUSIVE                      16
+#define TK_COMMIT                         17
+#define TK_END                            18
+#define TK_ROLLBACK                       19
+#define TK_CREATE                         20
+#define TK_TABLE                          21
+#define TK_TEMP                           22
+#define TK_LP                             23
+#define TK_RP                             24
+#define TK_AS                             25
+#define TK_COMMA                          26
+#define TK_ID                             27
+#define TK_ABORT                          28
+#define TK_AFTER                          29
+#define TK_ASC                            30
+#define TK_ATTACH                         31
+#define TK_BEFORE                         32
+#define TK_CASCADE                        33
+#define TK_CONFLICT                       34
+#define TK_DATABASE                       35
+#define TK_DESC                           36
+#define TK_DETACH                         37
+#define TK_EACH                           38
+#define TK_FAIL                           39
+#define TK_FOR                            40
 #define TK_IGNORE                         41
 #define TK_INITIALLY                      42
 #define TK_INSTEAD                        43
-#define TK_LIKE                           44
+#define TK_LIKE_KW                        44
 #define TK_MATCH                          45
 #define TK_KEY                            46
 #define TK_OF                             47
 #define TK_VIEW                           57
 #define TK_REINDEX                        58
 #define TK_RENAME                         59
-#define TK_CDATE                          60
-#define TK_CTIME                          61
-#define TK_CTIMESTAMP                     62
-#define TK_ALTER                          63
-#define TK_OR                             64
-#define TK_AND                            65
-#define TK_NOT                            66
-#define TK_IS                             67
-#define TK_BETWEEN                        68
-#define TK_IN                             69
-#define TK_ISNULL                         70
-#define TK_NOTNULL                        71
-#define TK_NE                             72
-#define TK_EQ                             73
-#define TK_GT                             74
-#define TK_LE                             75
-#define TK_LT                             76
-#define TK_GE                             77
-#define TK_ESCAPE                         78
-#define TK_BITAND                         79
-#define TK_BITOR                          80
-#define TK_LSHIFT                         81
-#define TK_RSHIFT                         82
-#define TK_PLUS                           83
-#define TK_MINUS                          84
-#define TK_STAR                           85
-#define TK_SLASH                          86
-#define TK_REM                            87
-#define TK_CONCAT                         88
-#define TK_UMINUS                         89
-#define TK_UPLUS                          90
-#define TK_BITNOT                         91
-#define TK_STRING                         92
-#define TK_JOIN_KW                        93
-#define TK_CONSTRAINT                     94
-#define TK_DEFAULT                        95
-#define TK_NULL                           96
-#define TK_PRIMARY                        97
-#define TK_UNIQUE                         98
-#define TK_CHECK                          99
-#define TK_REFERENCES                     100
-#define TK_COLLATE                        101
-#define TK_AUTOINCR                       102
-#define TK_ON                             103
-#define TK_DELETE                         104
-#define TK_UPDATE                         105
-#define TK_INSERT                         106
-#define TK_SET                            107
-#define TK_DEFERRABLE                     108
-#define TK_FOREIGN                        109
-#define TK_DROP                           110
-#define TK_UNION                          111
-#define TK_ALL                            112
-#define TK_INTERSECT                      113
-#define TK_EXCEPT                         114
-#define TK_SELECT                         115
-#define TK_DISTINCT                       116
-#define TK_DOT                            117
-#define TK_FROM                           118
-#define TK_JOIN                           119
-#define TK_USING                          120
-#define TK_ORDER                          121
-#define TK_BY                             122
-#define TK_GROUP                          123
-#define TK_HAVING                         124
-#define TK_LIMIT                          125
-#define TK_WHERE                          126
-#define TK_INTO                           127
-#define TK_VALUES                         128
-#define TK_INTEGER                        129
-#define TK_FLOAT                          130
-#define TK_BLOB                           131
-#define TK_REGISTER                       132
-#define TK_VARIABLE                       133
-#define TK_EXISTS                         134
-#define TK_CASE                           135
-#define TK_WHEN                           136
-#define TK_THEN                           137
-#define TK_ELSE                           138
-#define TK_INDEX                          139
-#define TK_TO                             140
-
+#define TK_CTIME_KW                       60
+#define TK_ALTER                          61
+#define TK_OR                             62
+#define TK_AND                            63
+#define TK_NOT                            64
+#define TK_IS                             65
+#define TK_BETWEEN                        66
+#define TK_IN                             67
+#define TK_ISNULL                         68
+#define TK_NOTNULL                        69
+#define TK_NE                             70
+#define TK_EQ                             71
+#define TK_GT                             72
+#define TK_LE                             73
+#define TK_LT                             74
+#define TK_GE                             75
+#define TK_ESCAPE                         76
+#define TK_BITAND                         77
+#define TK_BITOR                          78
+#define TK_LSHIFT                         79
+#define TK_RSHIFT                         80
+#define TK_PLUS                           81
+#define TK_MINUS                          82
+#define TK_STAR                           83
+#define TK_SLASH                          84
+#define TK_REM                            85
+#define TK_CONCAT                         86
+#define TK_UMINUS                         87
+#define TK_UPLUS                          88
+#define TK_BITNOT                         89
+#define TK_STRING                         90
+#define TK_JOIN_KW                        91
+#define TK_CONSTRAINT                     92
+#define TK_DEFAULT                        93
+#define TK_NULL                           94
+#define TK_PRIMARY                        95
+#define TK_UNIQUE                         96
+#define TK_CHECK                          97
+#define TK_REFERENCES                     98
+#define TK_COLLATE                        99
+#define TK_AUTOINCR                       100
+#define TK_ON                             101
+#define TK_DELETE                         102
+#define TK_UPDATE                         103
+#define TK_INSERT                         104
+#define TK_SET                            105
+#define TK_DEFERRABLE                     106
+#define TK_FOREIGN                        107
+#define TK_DROP                           108
+#define TK_UNION                          109
+#define TK_ALL                            110
+#define TK_INTERSECT                      111
+#define TK_EXCEPT                         112
+#define TK_SELECT                         113
+#define TK_DISTINCT                       114
+#define TK_DOT                            115
+#define TK_FROM                           116
+#define TK_JOIN                           117
+#define TK_USING                          118
+#define TK_ORDER                          119
+#define TK_BY                             120
+#define TK_GROUP                          121
+#define TK_HAVING                         122
+#define TK_LIMIT                          123
+#define TK_WHERE                          124
+#define TK_INTO                           125
+#define TK_VALUES                         126
+#define TK_INTEGER                        127
+#define TK_FLOAT                          128
+#define TK_BLOB                           129
+#define TK_REGISTER                       130
+#define TK_VARIABLE                       131
+#define TK_EXISTS                         132
+#define TK_CASE                           133
+#define TK_WHEN                           134
+#define TK_THEN                           135
+#define TK_ELSE                           136
+#define TK_INDEX                          137
+#define TK_TO                             138
+#define TK_ADD                            139
+#define TK_COLUMNKW                       140
index 66398ac4f1d59079d1f9ea8fedbde82e1a4ff365..e5203fdf91f9fad58cfe512e4729f163ff6e7cd1 100644 (file)
@@ -48,8 +48,8 @@ struct LimitVal {
 ** GLOB, NOT LIKE, and NOT GLOB operators.
 */
 struct LikeOp {
-  int opcode;   /* Either TK_GLOB or TK_LIKE */
-  int not;      /* True if the NOT keyword is present */
+  Token operator;  /* "like" or "glob" or "regexp" */
+  int not;         /* True if the NOT keyword is present */
 };
 
 /*
@@ -75,7 +75,7 @@ struct AttachKey { int type;  Token key; };
 // add them to the parse.h output file.
 //
 %nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION
-          COLUMN AGG_FUNCTION.
+          COLUMN AGG_FUNCTION CONST_FUNC.
 
 // Input is a single SQL command
 input ::= cmdlist.
@@ -112,13 +112,15 @@ create_table ::= CREATE(X) temp(T) TABLE nm(Y) dbnm(Z). {
    sqlite3StartTable(pParse,&X,&Y,&Z,T,0);
 }
 %type temp {int}
+%ifndef SQLITE_OMIT_TEMPDB
 temp(A) ::= TEMP.  {A = 1;}
+%endif
 temp(A) ::= .      {A = 0;}
-create_table_args ::= LP columnlist conslist_opt RP(X). {
-  sqlite3EndTable(pParse,&X,0);
+create_table_args ::= LP columnlist conslist_opt(X) RP(Y). {
+  sqlite3EndTable(pParse,&X,&Y,0);
 }
 create_table_args ::= AS select(S). {
-  sqlite3EndTable(pParse,0,S);
+  sqlite3EndTable(pParse,0,0,S);
   sqlite3SelectDelete(S);
 }
 columnlist ::= columnlist COMMA column.
@@ -128,8 +130,15 @@ columnlist ::= column.
 // column.  The type is always just "text".  But the code will accept
 // an elaborate typename.  Perhaps someday we'll do something with it.
 //
-column ::= columnid type carglist. 
-columnid ::= nm(X).                {sqlite3AddColumn(pParse,&X);}
+column(A) ::= columnid(X) type carglist. {
+  A.z = X.z;
+  A.n = (pParse->sLastToken.z-X.z) + pParse->sLastToken.n;
+}
+columnid(A) ::= nm(X). {
+  sqlite3AddColumn(pParse,&X);
+  A = X;
+}
+
 
 // An IDENTIFIER can be a generic identifier, or one of several
 // keywords.  Any non-standard keyword can also be an identifier.
@@ -144,13 +153,13 @@ id(A) ::= ID(X).         {A = X;}
 %fallback ID
   ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CONFLICT
   DATABASE DEFERRED DESC DETACH EACH END EXCLUSIVE EXPLAIN FAIL FOR
-  GLOB IGNORE IMMEDIATE INITIALLY INSTEAD LIKE MATCH KEY
+  IGNORE IMMEDIATE INITIALLY INSTEAD LIKE_KW MATCH KEY
   OF OFFSET PRAGMA RAISE REPLACE RESTRICT ROW STATEMENT
   TEMP TRIGGER VACUUM VIEW
 %ifdef SQLITE_OMIT_COMPOUND_SELECT
   EXCEPT INTERSECT UNION
 %endif
-  REINDEX RENAME CDATE CTIME CTIMESTAMP ALTER
+  REINDEX RENAME CTIME_KW ALTER
   .
 
 // Define operator precedence early so that this is the first occurance
@@ -167,7 +176,7 @@ id(A) ::= ID(X).         {A = X;}
 %left OR.
 %left AND.
 %right NOT.
-%left IS LIKE GLOB BETWEEN IN ISNULL NOTNULL NE EQ.
+%left IS LIKE_KW BETWEEN IN ISNULL NOTNULL NE EQ.
 %left GT LE LT GE.
 %right ESCAPE.
 %left BITAND BITOR LSHIFT RSHIFT.
@@ -223,7 +232,7 @@ ccons ::= NOT NULL onconf(R).               {sqlite3AddNotNull(pParse, R);}
 ccons ::= PRIMARY KEY sortorder onconf(R) autoinc(I).
                                      {sqlite3AddPrimaryKey(pParse,0,R,I);}
 ccons ::= UNIQUE onconf(R).          {sqlite3CreateIndex(pParse,0,0,0,0,R,0,0);}
-ccons ::= CHECK LP expr RP onconf.
+ccons ::= CHECK LP expr(X) RP onconf. {sqlite3ExprDelete(X);}
 ccons ::= REFERENCES nm(T) idxlist_opt(TA) refargs(R).
                                 {sqlite3CreateForeignKey(pParse,0,&T,TA,R);}
 ccons ::= defer_subclause(D).   {sqlite3DeferForeignKey(pParse,D);}
@@ -263,8 +272,8 @@ init_deferred_pred_opt(A) ::= INITIALLY IMMEDIATE.    {A = 0;}
 // For the time being, the only constraint we care about is the primary
 // key and UNIQUE.  Both create indices.
 //
-conslist_opt ::= .
-conslist_opt ::= COMMA conslist.
+conslist_opt(A) ::= .                   {A.n = 0; A.z = 0;}
+conslist_opt(A) ::= COMMA(X) conslist.  {A = X;}
 conslist ::= conslist COMMA tcons.
 conslist ::= conslist tcons.
 conslist ::= tcons.
@@ -534,14 +543,14 @@ cmd ::= DELETE FROM fullname(X) where_opt(Y). {sqlite3DeleteFrom(pParse,X,Y);}
 where_opt(A) ::= .                    {A = 0;}
 where_opt(A) ::= WHERE expr(X).       {A = X;}
 
-%type setlist {ExprList*}
-%destructor setlist {sqlite3ExprListDelete($$);}
-
 ////////////////////////// The UPDATE command ////////////////////////////////
 //
 cmd ::= UPDATE orconf(R) fullname(X) SET setlist(Y) where_opt(Z).
     {sqlite3Update(pParse,X,Y,Z,R);}
 
+%type setlist {ExprList*}
+%destructor setlist {sqlite3ExprListDelete($$);}
+
 setlist(A) ::= setlist(Z) COMMA nm(X) EQ expr(Y).
     {A = sqlite3ExprListAppend(Z,Y,&X);}
 setlist(A) ::= nm(X) EQ expr(Y).   {A = sqlite3ExprListAppend(0,Y,&X);}
@@ -603,7 +612,7 @@ expr(A) ::= nm(X) DOT nm(Y) DOT nm(Z). {
 term(A) ::= INTEGER(X).      {A = sqlite3Expr(@X, 0, 0, &X);}
 term(A) ::= FLOAT(X).        {A = sqlite3Expr(@X, 0, 0, &X);}
 term(A) ::= STRING(X).       {A = sqlite3Expr(@X, 0, 0, &X);}
-expr(A) ::= BLOB(X).         {A = sqlite3Expr(@X, 0, 0, &X);}
+term(A) ::= BLOB(X).         {A = sqlite3Expr(@X, 0, 0, &X);}
 expr(A) ::= REGISTER(X).     {A = sqlite3RegisterExpr(pParse, &X);}
 expr(A) ::= VARIABLE(X).     {
   Token *pToken = &X;
@@ -618,9 +627,12 @@ expr(A) ::= ID(X) LP STAR RP(E). {
   A = sqlite3ExprFunction(0, &X);
   sqlite3ExprSpan(A,&X,&E);
 }
-term(A) ::= CTIME(OP).                  {A = sqlite3Expr(@OP,0,0,0);}
-term(A) ::= CDATE(OP).                  {A = sqlite3Expr(@OP,0,0,0);}
-term(A) ::= CTIMESTAMP(OP).             {A = sqlite3Expr(@OP,0,0,0);}
+term(A) ::= CTIME_KW(OP). {
+  /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
+  ** treated as functions that return constants */
+  A = sqlite3ExprFunction(0,&OP);
+  if( A ) A->op = TK_CONST_FUNC;  
+}
 expr(A) ::= expr(X) AND(OP) expr(Y).    {A = sqlite3Expr(@OP, X, Y, 0);}
 expr(A) ::= expr(X) OR(OP) expr(Y).     {A = sqlite3Expr(@OP, X, Y, 0);}
 expr(A) ::= expr(X) LT(OP) expr(Y).     {A = sqlite3Expr(@OP, X, Y, 0);}
@@ -640,21 +652,18 @@ expr(A) ::= expr(X) SLASH(OP) expr(Y).  {A = sqlite3Expr(@OP, X, Y, 0);}
 expr(A) ::= expr(X) REM(OP) expr(Y).    {A = sqlite3Expr(@OP, X, Y, 0);}
 expr(A) ::= expr(X) CONCAT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);}
 %type likeop {struct LikeOp}
-likeop(A) ::= LIKE.     {A.opcode = TK_LIKE; A.not = 0;}
-likeop(A) ::= GLOB.     {A.opcode = TK_GLOB; A.not = 0;}
-likeop(A) ::= NOT LIKE. {A.opcode = TK_LIKE; A.not = 1;}
-likeop(A) ::= NOT GLOB. {A.opcode = TK_GLOB; A.not = 1;}
+likeop(A) ::= LIKE_KW(X).     {A.operator = X; A.not = 0;}
+likeop(A) ::= NOT LIKE_KW(X). {A.operator = X; A.not = 1;}
 %type escape {Expr*}
 escape(X) ::= ESCAPE expr(A). [ESCAPE] {X = A;}
 escape(X) ::= .               [ESCAPE] {X = 0;}
-expr(A) ::= expr(X) likeop(OP) expr(Y) escape(E).  [LIKE]  {
+expr(A) ::= expr(X) likeop(OP) expr(Y) escape(E).  [LIKE_KW]  {
   ExprList *pList = sqlite3ExprListAppend(0, Y, 0);
   pList = sqlite3ExprListAppend(pList, X, 0);
   if( E ){
     pList = sqlite3ExprListAppend(pList, E, 0);
   }
-  A = sqlite3ExprFunction(pList, 0);
-  if( A ) A->op = OP.opcode;
+  A = sqlite3ExprFunction(pList, &OP.operator);
   if( OP.not ) A = sqlite3Expr(TK_NOT, A, 0, 0);
   sqlite3ExprSpan(A, &X->span, &Y->span);
 }
@@ -712,18 +721,24 @@ expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] {
   in_op(A) ::= NOT IN.  {A = 1;}
   expr(A) ::= expr(X) in_op(N) LP exprlist(Y) RP(E). [IN] {
     A = sqlite3Expr(TK_IN, X, 0, 0);
-    if( A ) A->pList = Y;
+    if( A ){
+      A->pList = Y;
+    }else{
+      sqlite3ExprListDelete(Y);
+    }
     if( N ) A = sqlite3Expr(TK_NOT, A, 0, 0);
     sqlite3ExprSpan(A,&X->span,&E);
   }
   expr(A) ::= LP(B) select(X) RP(E). {
     A = sqlite3Expr(TK_SELECT, 0, 0, 0);
     if( A ) A->pSelect = X;
+    if( !A ) sqlite3SelectDelete(X);
     sqlite3ExprSpan(A,&B,&E);
   }
   expr(A) ::= expr(X) in_op(N) LP select(Y) RP(E).  [IN] {
     A = sqlite3Expr(TK_IN, X, 0, 0);
     if( A ) A->pSelect = Y;
+    if( !A ) sqlite3SelectDelete(Y);
     if( N ) A = sqlite3Expr(TK_NOT, A, 0, 0);
     sqlite3ExprSpan(A,&X->span,&E);
   }
@@ -740,6 +755,7 @@ expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] {
       p->pSelect = Y;
       sqlite3ExprSpan(p,&B,&E);
     }
+    if( !p ) sqlite3SelectDelete(Y);
   }
 %endif // SQLITE_OMIT_SUBQUERY
 
@@ -968,4 +984,12 @@ cmd ::= REINDEX nm(X) dbnm(Y).  {sqlite3Reindex(pParse, &X, &Y);}
 cmd ::= ALTER TABLE fullname(X) RENAME TO nm(Z). {
   sqlite3AlterRenameTable(pParse,X,&Z);
 }
+cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column(Y). {
+  sqlite3AlterFinishAddColumn(pParse, &Y);
+}
+add_column_fullname ::= fullname(X). {
+  sqlite3AlterBeginAddColumn(pParse, X);
+}
+kwcolumn_opt ::= .
+kwcolumn_opt ::= COLUMNKW.
 %endif
index 3c09a4b196dca87c943e605ca6e57c43fd391396..226c1829ae3c1699fd9c6febfa50627ffb008540 100644 (file)
@@ -19,7 +19,7 @@
 
 /* Ignore this whole file if pragmas are disabled
 */
-#ifndef SQLITE_OMIT_PRAGMA
+#if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
 
 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
 # include "pager.h"
@@ -79,7 +79,9 @@ static int getTempStore(const char *z){
     return 0;
   }
 }
+#endif /* SQLITE_PAGER_PRAGMAS */
 
+#ifndef SQLITE_OMIT_PAGER_PRAGMAS
 /*
 ** Invalidate temp storage, either when the temp storage is changed
 ** from default, or when 'file' and the temp_store_directory has changed
@@ -98,7 +100,9 @@ static int invalidateTempStorage(Parse *pParse){
   }
   return SQLITE_OK;
 }
+#endif /* SQLITE_PAGER_PRAGMAS */
 
+#ifndef SQLITE_OMIT_PAGER_PRAGMAS
 /*
 ** If the TEMP database is open, close it and mark the database schema
 ** as needing reloading.  This must be done when using the TEMP_STORE
@@ -114,7 +118,7 @@ static int changeTempStorage(Parse *pParse, const char *zStorageType){
   db->temp_store = ts;
   return SQLITE_OK;
 }
-#endif
+#endif /* SQLITE_PAGER_PRAGMAS */
 
 /*
 ** Generate code to return a single integer value.
@@ -129,6 +133,7 @@ static void returnSingleInt(Parse *pParse, const char *zLabel, int value){
   sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
 }
 
+#ifndef SQLITE_OMIT_FLAG_PRAGMAS
 /*
 ** Check to see if zRight and zLeft refer to a pragma that queries
 ** or changes one of the flags in db->flags.  Return 1 if so and 0 if not.
@@ -177,6 +182,7 @@ static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
   }
   return 0;
 }
+#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
 
 /*
 ** Process a pragma statement.  
@@ -428,10 +434,12 @@ void sqlite3Pragma(
   }else
 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
 
+#ifndef SQLITE_OMIT_FLAG_PRAGMAS
   if( flagPragma(pParse, zLeft, zRight) ){
     /* The flagPragma() subroutine also generates any necessary code
     ** there is nothing more to do here */
   }else
+#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
 
 #ifndef SQLITE_OMIT_SCHEMA_PRAGMAS
   /*
@@ -637,6 +645,8 @@ void sqlite3Pragma(
       HashElem *x;
       int cnt = 0;
 
+      if( OMIT_TEMPDB && i==1 ) continue;
+
       sqlite3CodeVerifySchema(pParse, i);
 
       /* Do an integrity check of the B-Tree
@@ -683,7 +693,7 @@ void sqlite3Pragma(
           static const VdbeOpList idxErr[] = {
             { OP_MemIncr,     0,  0,  0},
             { OP_String8,     0,  0,  "rowid "},
-            { OP_Recno,       1,  0,  0},
+            { OP_Rowid,       1,  0,  0},
             { OP_String8,     0,  0,  " missing from index "},
             { OP_String8,     0,  0,  0},    /* 4 */
             { OP_Concat,      2,  0,  0},
@@ -895,6 +905,17 @@ void sqlite3Pragma(
   }else
 #endif
 
+#ifdef SQLITE_SSE
+  /*
+  ** Check to see if the sqlite_statements table exists.  Create it
+  ** if it does not.
+  */
+  if( sqlite3StrICmp(zLeft, "create_sqlite_statement_table")==0 ){
+    extern int sqlite3CreateStatementsTable(Parse*);
+    sqlite3CreateStatementsTable(pParse);
+  }else
+#endif
+
   {}
 
   if( v ){
@@ -909,4 +930,4 @@ pragma_out:
   sqliteFree(zRight);
 }
 
-#endif /* SQLITE_OMIT_PRAGMA */
+#endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */
diff --git a/ext/pdo_sqlite/sqlite/src/prepare.c b/ext/pdo_sqlite/sqlite/src/prepare.c
new file mode 100644 (file)
index 0000000..d1fec1b
--- /dev/null
@@ -0,0 +1,529 @@
+/*
+** 2005 May 25
+**
+** The author disclaims copyright to this source code.  In place of
+** a legal notice, here is a blessing:
+**
+**    May you do good and not evil.
+**    May you find forgiveness for yourself and forgive others.
+**    May you share freely, never taking more than you give.
+**
+*************************************************************************
+** This file contains the implementation of the sqlite3_prepare()
+** interface, and routines that contribute to loading the database schema
+** from disk.
+**
+** $Id$
+*/
+#include "sqliteInt.h"
+#include "os.h"
+#include <ctype.h>
+
+/*
+** Fill the InitData structure with an error message that indicates
+** that the database is corrupt.
+*/
+static void corruptSchema(InitData *pData, const char *zExtra){
+  if( !sqlite3_malloc_failed ){
+    sqlite3SetString(pData->pzErrMsg, "malformed database schema",
+       zExtra!=0 && zExtra[0]!=0 ? " - " : (char*)0, zExtra, (char*)0);
+  }
+}
+
+/*
+** This is the callback routine for the code that initializes the
+** database.  See sqlite3Init() below for additional information.
+** This routine is also called from the OP_ParseSchema opcode of the VDBE.
+**
+** Each callback contains the following information:
+**
+**     argv[0] = name of thing being created
+**     argv[1] = root page number for table or index.  NULL for trigger or view.
+**     argv[2] = SQL text for the CREATE statement.
+**     argv[3] = "1" for temporary files, "0" for main database, "2" or more
+**               for auxiliary database files.
+**
+*/
+int sqlite3InitCallback(void *pInit, int argc, char **argv, char **azColName){
+  InitData *pData = (InitData*)pInit;
+  sqlite3 *db = pData->db;
+  int iDb;
+
+  assert( argc==4 );
+  if( argv==0 ) return 0;   /* Might happen if EMPTY_RESULT_CALLBACKS are on */
+  if( argv[1]==0 || argv[3]==0 ){
+    corruptSchema(pData, 0);
+    return 1;
+  }
+  iDb = atoi(argv[3]);
+  assert( iDb>=0 && iDb<db->nDb );
+  if( argv[2] && argv[2][0] ){
+    /* Call the parser to process a CREATE TABLE, INDEX or VIEW.
+    ** But because db->init.busy is set to 1, no VDBE code is generated
+    ** or executed.  All the parser does is build the internal data
+    ** structures that describe the table, index, or view.
+    */
+    char *zErr;
+    int rc;
+    assert( db->init.busy );
+    db->init.iDb = iDb;
+    db->init.newTnum = atoi(argv[1]);
+    rc = sqlite3_exec(db, argv[2], 0, 0, &zErr);
+    db->init.iDb = 0;
+    if( SQLITE_OK!=rc ){
+      corruptSchema(pData, zErr);
+      sqlite3_free(zErr);
+      return rc;
+    }
+  }else{
+    /* If the SQL column is blank it means this is an index that
+    ** was created to be the PRIMARY KEY or to fulfill a UNIQUE
+    ** constraint for a CREATE TABLE.  The index should have already
+    ** been created when we processed the CREATE TABLE.  All we have
+    ** to do here is record the root page number for that index.
+    */
+    Index *pIndex;
+    pIndex = sqlite3FindIndex(db, argv[0], db->aDb[iDb].zName);
+    if( pIndex==0 || pIndex->tnum!=0 ){
+      /* This can occur if there exists an index on a TEMP table which
+      ** has the same name as another index on a permanent index.  Since
+      ** the permanent table is hidden by the TEMP table, we can also
+      ** safely ignore the index on the permanent table.
+      */
+      /* Do Nothing */;
+    }else{
+      pIndex->tnum = atoi(argv[1]);
+    }
+  }
+  return 0;
+}
+
+/*
+** Attempt to read the database schema and initialize internal
+** data structures for a single database file.  The index of the
+** database file is given by iDb.  iDb==0 is used for the main
+** database.  iDb==1 should never be used.  iDb>=2 is used for
+** auxiliary databases.  Return one of the SQLITE_ error codes to
+** indicate success or failure.
+*/
+static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
+  int rc;
+  BtCursor *curMain;
+  int size;
+  Table *pTab;
+  char const *azArg[5];
+  char zDbNum[30];
+  int meta[10];
+  InitData initData;
+  char const *zMasterSchema;
+  char const *zMasterName = SCHEMA_TABLE(iDb);
+
+  /*
+  ** The master database table has a structure like this
+  */
+  static const char master_schema[] = 
+     "CREATE TABLE sqlite_master(\n"
+     "  type text,\n"
+     "  name text,\n"
+     "  tbl_name text,\n"
+     "  rootpage integer,\n"
+     "  sql text\n"
+     ")"
+  ;
+#ifndef SQLITE_OMIT_TEMPDB
+  static const char temp_master_schema[] = 
+     "CREATE TEMP TABLE sqlite_temp_master(\n"
+     "  type text,\n"
+     "  name text,\n"
+     "  tbl_name text,\n"
+     "  rootpage integer,\n"
+     "  sql text\n"
+     ")"
+  ;
+#else
+  #define temp_master_schema 0
+#endif
+
+  assert( iDb>=0 && iDb<db->nDb );
+
+  /* zMasterSchema and zInitScript are set to point at the master schema
+  ** and initialisation script appropriate for the database being
+  ** initialised. zMasterName is the name of the master table.
+  */
+  if( !OMIT_TEMPDB && iDb==1 ){
+    zMasterSchema = temp_master_schema;
+  }else{
+    zMasterSchema = master_schema;
+  }
+  zMasterName = SCHEMA_TABLE(iDb);
+
+  /* Construct the schema tables.  */
+  sqlite3SafetyOff(db);
+  azArg[0] = zMasterName;
+  azArg[1] = "1";
+  azArg[2] = zMasterSchema;
+  sprintf(zDbNum, "%d", iDb);
+  azArg[3] = zDbNum;
+  azArg[4] = 0;
+  initData.db = db;
+  initData.pzErrMsg = pzErrMsg;
+  rc = sqlite3InitCallback(&initData, 4, (char **)azArg, 0);
+  if( rc!=SQLITE_OK ){
+    sqlite3SafetyOn(db);
+    return rc;
+  }
+  pTab = sqlite3FindTable(db, zMasterName, db->aDb[iDb].zName);
+  if( pTab ){
+    pTab->readOnly = 1;
+  }
+  sqlite3SafetyOn(db);
+
+  /* Create a cursor to hold the database open
+  */
+  if( db->aDb[iDb].pBt==0 ){
+    if( !OMIT_TEMPDB && iDb==1 ) DbSetProperty(db, 1, DB_SchemaLoaded);
+    return SQLITE_OK;
+  }
+  rc = sqlite3BtreeCursor(db->aDb[iDb].pBt, MASTER_ROOT, 0, 0, 0, &curMain);
+  if( rc!=SQLITE_OK && rc!=SQLITE_EMPTY ){
+    sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0);
+    return rc;
+  }
+
+  /* Get the database meta information.
+  **
+  ** Meta values are as follows:
+  **    meta[0]   Schema cookie.  Changes with each schema change.
+  **    meta[1]   File format of schema layer.
+  **    meta[2]   Size of the page cache.
+  **    meta[3]   Use freelist if 0.  Autovacuum if greater than zero.
+  **    meta[4]   Db text encoding. 1:UTF-8 3:UTF-16 LE 4:UTF-16 BE
+  **    meta[5]   The user cookie. Used by the application.
+  **    meta[6]   
+  **    meta[7]
+  **    meta[8]
+  **    meta[9]
+  **
+  ** Note: The hash defined SQLITE_UTF* symbols in sqliteInt.h correspond to
+  ** the possible values of meta[4].
+  */
+  if( rc==SQLITE_OK ){
+    int i;
+    for(i=0; rc==SQLITE_OK && i<sizeof(meta)/sizeof(meta[0]); i++){
+      rc = sqlite3BtreeGetMeta(db->aDb[iDb].pBt, i+1, (u32 *)&meta[i]);
+    }
+    if( rc ){
+      sqlite3SetString(pzErrMsg, sqlite3ErrStr(rc), (char*)0);
+      sqlite3BtreeCloseCursor(curMain);
+      return rc;
+    }
+  }else{
+    memset(meta, 0, sizeof(meta));
+  }
+  db->aDb[iDb].schema_cookie = meta[0];
+
+  /* If opening a non-empty database, check the text encoding. For the
+  ** main database, set sqlite3.enc to the encoding of the main database.
+  ** For an attached db, it is an error if the encoding is not the same
+  ** as sqlite3.enc.
+  */
+  if( meta[4] ){  /* text encoding */
+    if( iDb==0 ){
+      /* If opening the main database, set db->enc. */
+      db->enc = (u8)meta[4];
+      db->pDfltColl = sqlite3FindCollSeq(db, db->enc, "BINARY", 6, 0);
+    }else{
+      /* If opening an attached database, the encoding much match db->enc */
+      if( meta[4]!=db->enc ){
+        sqlite3BtreeCloseCursor(curMain);
+        sqlite3SetString(pzErrMsg, "attached databases must use the same"
+            " text encoding as main database", (char*)0);
+        return SQLITE_ERROR;
+      }
+    }
+  }
+
+  size = meta[2];
+  if( size==0 ){ size = MAX_PAGES; }
+  db->aDb[iDb].cache_size = size;
+
+  if( iDb==0 ){
+    db->file_format = meta[1];
+    if( db->file_format==0 ){
+      /* This happens if the database was initially empty */
+      db->file_format = 1;
+    }
+
+    if( db->file_format==2 || db->file_format==3 ){
+      /* File format 2 is treated exactly as file format 1. New 
+      ** databases are created with file format 1.
+      */ 
+      db->file_format = 1;
+    }
+  }
+
+  /*
+  ** file_format==1    Version 3.0.0.
+  ** file_format==2    Version 3.1.3.
+  ** file_format==3    Version 3.1.4.
+  **
+  ** Version 3.0 can only use files with file_format==1. Version 3.1.3
+  ** can read and write files with file_format==1 or file_format==2.
+  ** Version 3.1.4 can read and write file formats 1, 2 and 3.
+  */
+  if( meta[1]>3 ){
+    sqlite3BtreeCloseCursor(curMain);
+    sqlite3SetString(pzErrMsg, "unsupported file format", (char*)0);
+    return SQLITE_ERROR;
+  }
+
+  sqlite3BtreeSetCacheSize(db->aDb[iDb].pBt, db->aDb[iDb].cache_size);
+
+  /* Read the schema information out of the schema tables
+  */
+  assert( db->init.busy );
+  if( rc==SQLITE_EMPTY ){
+    /* For an empty database, there is nothing to read */
+    rc = SQLITE_OK;
+  }else{
+    char *zSql;
+    zSql = sqlite3MPrintf(
+        "SELECT name, rootpage, sql, '%s' FROM '%q'.%s",
+        zDbNum, db->aDb[iDb].zName, zMasterName);
+    sqlite3SafetyOff(db);
+    rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
+    sqlite3SafetyOn(db);
+    sqliteFree(zSql);
+    sqlite3BtreeCloseCursor(curMain);
+  }
+  if( sqlite3_malloc_failed ){
+    sqlite3SetString(pzErrMsg, "out of memory", (char*)0);
+    rc = SQLITE_NOMEM;
+    sqlite3ResetInternalSchema(db, 0);
+  }
+  if( rc==SQLITE_OK ){
+    DbSetProperty(db, iDb, DB_SchemaLoaded);
+  }else{
+    sqlite3ResetInternalSchema(db, iDb);
+  }
+  return rc;
+}
+
+/*
+** Initialize all database files - the main database file, the file
+** used to store temporary tables, and any additional database files
+** created using ATTACH statements.  Return a success code.  If an
+** error occurs, write an error message into *pzErrMsg.
+**
+** After the database is initialized, the SQLITE_Initialized
+** bit is set in the flags field of the sqlite structure. 
+*/
+int sqlite3Init(sqlite3 *db, char **pzErrMsg){
+  int i, rc;
+  
+  if( db->init.busy ) return SQLITE_OK;
+  assert( (db->flags & SQLITE_Initialized)==0 );
+  rc = SQLITE_OK;
+  db->init.busy = 1;
+  for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
+    if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
+    rc = sqlite3InitOne(db, i, pzErrMsg);
+    if( rc ){
+      sqlite3ResetInternalSchema(db, i);
+    }
+  }
+
+  /* Once all the other databases have been initialised, load the schema
+  ** for the TEMP database. This is loaded last, as the TEMP database
+  ** schema may contain references to objects in other databases.
+  */
+#ifndef SQLITE_OMIT_TEMPDB
+  if( rc==SQLITE_OK && db->nDb>1 && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
+    rc = sqlite3InitOne(db, 1, pzErrMsg);
+    if( rc ){
+      sqlite3ResetInternalSchema(db, 1);
+    }
+  }
+#endif
+
+  db->init.busy = 0;
+  if( rc==SQLITE_OK ){
+    db->flags |= SQLITE_Initialized;
+    sqlite3CommitInternalChanges(db);
+  }
+
+  if( rc!=SQLITE_OK ){
+    db->flags &= ~SQLITE_Initialized;
+  }
+  return rc;
+}
+
+/*
+** This routine is a no-op if the database schema is already initialised.
+** Otherwise, the schema is loaded. An error code is returned.
+*/
+int sqlite3ReadSchema(Parse *pParse){
+  int rc = SQLITE_OK;
+  sqlite3 *db = pParse->db;
+  if( !db->init.busy ){
+    if( (db->flags & SQLITE_Initialized)==0 ){
+      rc = sqlite3Init(db, &pParse->zErrMsg);
+    }
+  }
+  assert( rc!=SQLITE_OK || (db->flags & SQLITE_Initialized)||db->init.busy );
+  if( rc!=SQLITE_OK ){
+    pParse->rc = rc;
+    pParse->nErr++;
+  }
+  return rc;
+}
+
+
+/*
+** Check schema cookies in all databases.  If any cookie is out
+** of date, return 0.  If all schema cookies are current, return 1.
+*/
+static int schemaIsValid(sqlite3 *db){
+  int iDb;
+  int rc;
+  BtCursor *curTemp;
+  int cookie;
+  int allOk = 1;
+
+  for(iDb=0; allOk && iDb<db->nDb; iDb++){
+    Btree *pBt;
+    pBt = db->aDb[iDb].pBt;
+    if( pBt==0 ) continue;
+    rc = sqlite3BtreeCursor(pBt, MASTER_ROOT, 0, 0, 0, &curTemp);
+    if( rc==SQLITE_OK ){
+      rc = sqlite3BtreeGetMeta(pBt, 1, (u32 *)&cookie);
+      if( rc==SQLITE_OK && cookie!=db->aDb[iDb].schema_cookie ){
+        allOk = 0;
+      }
+      sqlite3BtreeCloseCursor(curTemp);
+    }
+  }
+  return allOk;
+}
+
+/*
+** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
+*/
+int sqlite3_prepare(
+  sqlite3 *db,              /* Database handle. */
+  const char *zSql,         /* UTF-8 encoded SQL statement. */
+  int nBytes,               /* Length of zSql in bytes. */
+  sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
+  const char** pzTail       /* OUT: End of parsed string */
+){
+  Parse sParse;
+  char *zErrMsg = 0;
+  int rc = SQLITE_OK;
+
+  if( sqlite3_malloc_failed ){
+    return SQLITE_NOMEM;
+  }
+
+  assert( ppStmt );
+  *ppStmt = 0;
+  if( sqlite3SafetyOn(db) ){
+    return SQLITE_MISUSE;
+  }
+
+  memset(&sParse, 0, sizeof(sParse));
+  sParse.db = db;
+  sqlite3RunParser(&sParse, zSql, &zErrMsg);
+
+  if( sqlite3_malloc_failed ){
+    rc = SQLITE_NOMEM;
+    sqlite3RollbackAll(db);
+    sqlite3ResetInternalSchema(db, 0);
+    db->flags &= ~SQLITE_InTrans;
+    goto prepare_out;
+  }
+  if( sParse.rc==SQLITE_DONE ) sParse.rc = SQLITE_OK;
+  if( sParse.rc!=SQLITE_OK && sParse.checkSchema && !schemaIsValid(db) ){
+    sParse.rc = SQLITE_SCHEMA;
+  }
+  if( sParse.rc==SQLITE_SCHEMA ){
+    sqlite3ResetInternalSchema(db, 0);
+  }
+  if( pzTail ) *pzTail = sParse.zTail;
+  rc = sParse.rc;
+
+#ifndef SQLITE_OMIT_EXPLAIN
+  if( rc==SQLITE_OK && sParse.pVdbe && sParse.explain ){
+    sqlite3VdbeSetNumCols(sParse.pVdbe, 5);
+    sqlite3VdbeSetColName(sParse.pVdbe, 0, "addr", P3_STATIC);
+    sqlite3VdbeSetColName(sParse.pVdbe, 1, "opcode", P3_STATIC);
+    sqlite3VdbeSetColName(sParse.pVdbe, 2, "p1", P3_STATIC);
+    sqlite3VdbeSetColName(sParse.pVdbe, 3, "p2", P3_STATIC);
+    sqlite3VdbeSetColName(sParse.pVdbe, 4, "p3", P3_STATIC);
+  } 
+#endif
+
+prepare_out:
+  if( sqlite3SafetyOff(db) ){
+    rc = SQLITE_MISUSE;
+  }
+  if( rc==SQLITE_OK ){
+    *ppStmt = (sqlite3_stmt*)sParse.pVdbe;
+  }else if( sParse.pVdbe ){
+    sqlite3_finalize((sqlite3_stmt*)sParse.pVdbe);
+  }
+
+  if( zErrMsg ){
+    sqlite3Error(db, rc, "%s", zErrMsg);
+    sqliteFree(zErrMsg);
+  }else{
+    sqlite3Error(db, rc, 0);
+  }
+  return rc;
+}
+
+#ifndef SQLITE_OMIT_UTF16
+/*
+** Compile the UTF-16 encoded SQL statement zSql into a statement handle.
+*/
+int sqlite3_prepare16(
+  sqlite3 *db,              /* Database handle. */ 
+  const void *zSql,         /* UTF-8 encoded SQL statement. */
+  int nBytes,               /* Length of zSql in bytes. */
+  sqlite3_stmt **ppStmt,    /* OUT: A pointer to the prepared statement */
+  const void **pzTail       /* OUT: End of parsed string */
+){
+  /* This function currently works by first transforming the UTF-16
+  ** encoded string to UTF-8, then invoking sqlite3_prepare(). The
+  ** tricky bit is figuring out the pointer to return in *pzTail.
+  */
+  char const *zSql8 = 0;
+  char const *zTail8 = 0;
+  int rc;
+  sqlite3_value *pTmp;
+
+  if( sqlite3SafetyCheck(db) ){
+    return SQLITE_MISUSE;
+  }
+  pTmp = sqlite3GetTransientValue(db);
+  sqlite3ValueSetStr(pTmp, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);
+  zSql8 = sqlite3ValueText(pTmp, SQLITE_UTF8);
+  if( !zSql8 ){
+    sqlite3Error(db, SQLITE_NOMEM, 0);
+    return SQLITE_NOMEM;
+  }
+  rc = sqlite3_prepare(db, zSql8, -1, ppStmt, &zTail8);
+
+  if( zTail8 && pzTail ){
+    /* If sqlite3_prepare returns a tail pointer, we calculate the
+    ** equivalent pointer into the UTF-16 string by counting the unicode
+    ** characters between zSql8 and zTail8, and then returning a pointer
+    ** the same number of characters into the UTF-16 string.
+    */
+    int chars_parsed = sqlite3utf8CharLen(zSql8, zTail8-zSql8);
+    *pzTail = (u8 *)zSql + sqlite3utf16ByteLen(zSql, chars_parsed);
+  }
+  return rc;
+}
+#endif /* SQLITE_OMIT_UTF16 */
+
index de74e29158a6f3c4e939eb068ab4287694001a92..51d5d72e77827874b99a228c84d8b8d6cf0b27a3 100644 (file)
 ** must be held while executing this routine.
 **
 ** Why not just use a library random generator like lrand48() for this?
-** Because the OP_NewRecno opcode in the VDBE depends on having a very
+** Because the OP_NewRowid opcode in the VDBE depends on having a very
 ** good source of random numbers.  The lrand48() library function may
 ** well be good enough.  But maybe not.  Or maybe lrand48() has some
 ** subtle problems on some systems that could cause problems.  It is hard
 ** to know.  To minimize the risk of problems due to bad lrand48()
 ** implementations, SQLite uses this random number generator based
 ** on RC4, which we know works very well.
+**
+** (Later):  Actually, OP_NewRowid does not depend on a good source of
+** randomness any more.  But we will leave this code in all the same.
 */
 static int randomByte(){
   unsigned char t;
@@ -95,6 +98,3 @@ void sqlite3Randomness(int N, void *pBuf){
   }
   sqlite3OsLeaveMutex();
 }
-
-
-
index 646134df2e68a10aa0206124957b64acf93466c5..4c2a71723944075096e4bc5b83cd09d8dc040a9b 100644 (file)
@@ -326,7 +326,7 @@ static void pushOntoSorter(Parse *pParse, Vdbe *v, ExprList *pOrderBy){
     sqlite3ExprCode(pParse, pOrderBy->a[i].pExpr);
   }
   sqlite3VdbeAddOp(v, OP_MakeRecord, pOrderBy->nExpr, 0);
-  sqlite3VdbeAddOp(v, OP_SortPut, 0, 0);
+  sqlite3VdbeAddOp(v, OP_SortInsert, 0, 0);
 }
 
 /*
@@ -422,8 +422,7 @@ static int selectInnerLoop(
     sqlite3VdbeAddOp(v, OP_Pop, pEList->nExpr+1, 0);
     sqlite3VdbeAddOp(v, OP_Goto, 0, iContinue);
     VdbeComment((v, "# skip indistinct records"));
-    sqlite3VdbeAddOp(v, OP_String8, 0, 0);
-    sqlite3VdbeAddOp(v, OP_PutStrKey, distinct, 0);
+    sqlite3VdbeAddOp(v, OP_IdxInsert, distinct, 0);
     if( pOrderBy==0 ){
       codeLimiter(v, p, iContinue, iBreak, nColumn);
     }
@@ -437,8 +436,7 @@ static int selectInnerLoop(
     case SRT_Union: {
       sqlite3VdbeAddOp(v, OP_MakeRecord, nColumn, NULL_ALWAYS_DISTINCT);
       sqlite3VdbeChangeP3(v, -1, aff, P3_STATIC);
-      sqlite3VdbeAddOp(v, OP_String8, 0, 0);
-      sqlite3VdbeAddOp(v, OP_PutStrKey, iParm, 0);
+      sqlite3VdbeAddOp(v, OP_IdxInsert, iParm, 0);
       break;
     }
 
@@ -464,9 +462,9 @@ static int selectInnerLoop(
       if( pOrderBy ){
         pushOntoSorter(pParse, v, pOrderBy);
       }else{
-        sqlite3VdbeAddOp(v, OP_NewRecno, iParm, 0);
+        sqlite3VdbeAddOp(v, OP_NewRowid, iParm, 0);
         sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
-        sqlite3VdbeAddOp(v, OP_PutIntKey, iParm, 0);
+        sqlite3VdbeAddOp(v, OP_Insert, iParm, 0);
       }
       break;
     }
@@ -490,8 +488,7 @@ static int selectInnerLoop(
         char aff = (iParm>>16)&0xFF;
         aff = sqlite3CompareAffinity(pEList->a[0].pExpr, aff);
         sqlite3VdbeOp3(v, OP_MakeRecord, 1, 0, &aff, 1);
-        sqlite3VdbeAddOp(v, OP_String8, 0, 0);
-        sqlite3VdbeAddOp(v, OP_PutStrKey, (iParm&0x0000FFFF), 0);
+        sqlite3VdbeAddOp(v, OP_IdxInsert, (iParm&0x0000FFFF), 0);
       }
       sqlite3VdbeChangeP2(v, addr2, sqlite3VdbeCurrentAddr(v));
       break;
@@ -603,9 +600,9 @@ static void generateSortTail(
   switch( eDest ){
     case SRT_Table:
     case SRT_TempTable: {
-      sqlite3VdbeAddOp(v, OP_NewRecno, iParm, 0);
+      sqlite3VdbeAddOp(v, OP_NewRowid, iParm, 0);
       sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
-      sqlite3VdbeAddOp(v, OP_PutIntKey, iParm, 0);
+      sqlite3VdbeAddOp(v, OP_Insert, iParm, 0);
       break;
     }
 #ifndef SQLITE_OMIT_SUBQUERY
@@ -615,8 +612,7 @@ static void generateSortTail(
       sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
       sqlite3VdbeAddOp(v, OP_Goto, 0, sqlite3VdbeCurrentAddr(v)+3);
       sqlite3VdbeOp3(v, OP_MakeRecord, 1, 0, "n", P3_STATIC);
-      sqlite3VdbeAddOp(v, OP_String8, 0, 0);
-      sqlite3VdbeAddOp(v, OP_PutStrKey, (iParm&0x0000FFFF), 0);
+      sqlite3VdbeAddOp(v, OP_IdxInsert, (iParm&0x0000FFFF), 0);
       break;
     }
     case SRT_Exists:
@@ -689,6 +685,20 @@ static const char *columnType(NameContext *pNC, Expr *pExpr){
           pNC = pNC->pNext;
         }
       }
+      if( pTab==0 ){
+        /* FIX ME:
+        ** This can occurs if you have something like "SELECT new.x;" inside
+        ** a trigger.  In other words, if you reference the special "new"
+        ** table in the result set of a select.  We do not have a good way
+        ** to find the actual table type, so call it "TEXT".  This is really
+        ** something of a bug, but I do not know how to fix it.
+        **
+        ** This code does not produce the correct answer - it just prevents
+        ** a segfault.  See ticket #1229.
+        */
+        zType = "TEXT";
+        break;
+      }
       assert( pTab );
       if( iCol<0 ) iCol = pTab->iPKey;
       assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
@@ -858,6 +868,7 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){
   if( pTab==0 ){
     return 0;
   }
+  pTab->nRef = 1;
   pTab->zName = zTabName ? sqliteStrDup(zTabName) : 0;
   pEList = pSelect->pEList;
   pTab->nCol = pEList->nExpr;
@@ -890,6 +901,11 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){
       zName = sqlite3MPrintf("column%d", i+1);
     }
     sqlite3Dequote(zName);
+    if( sqlite3_malloc_failed ){
+      sqliteFree(zName);
+      sqlite3DeleteTable(0, pTab);
+      return 0;
+    }
 
     /* Make sure the column name is unique.  If the name is not unique,
     ** append a integer to the name so that it becomes unique.
@@ -899,6 +915,7 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){
       if( sqlite3StrICmp(aCol[j].zName, zName)==0 ){
         zName = sqlite3MPrintf("%s:%d", zBasename, ++cnt);
         j = -1;
+        if( zName==0 ) break;
       }
     }
     if( zBasename!=zName ){
@@ -909,6 +926,7 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, char *zTabName, Select *pSelect){
     /* Get the typename, type affinity, and collating sequence for the
     ** column.
     */
+    memset(&sNC, 0, sizeof(sNC));
     sNC.pSrcList = pSelect->pSrc;
     zType = sqliteStrDup(columnType(&sNC, p));
     pCol->zType = zType;
@@ -955,7 +973,7 @@ static int prepSelectStmt(Parse *pParse, Select *p){
   Table *pTab;
   struct SrcList_item *pFrom;
 
-  if( p==0 || p->pSrc==0 ) return 1;
+  if( p==0 || p->pSrc==0 || sqlite3_malloc_failed ) return 1;
   pTabList = p->pSrc;
   pEList = p->pEList;
 
@@ -983,6 +1001,7 @@ static int prepSelectStmt(Parse *pParse, Select *p){
         pFrom->zAlias =
           sqlite3MPrintf("sqlite_subquery_%p_", (void*)pFrom->pSelect);
       }
+      assert( pFrom->pTab==0 );
       pFrom->pTab = pTab = 
         sqlite3ResultSetOfSelect(pParse, pFrom->zAlias, pFrom->pSelect);
       if( pTab==0 ){
@@ -996,11 +1015,13 @@ static int prepSelectStmt(Parse *pParse, Select *p){
 #endif
     }else{
       /* An ordinary table or view name in the FROM clause */
+      assert( pFrom->pTab==0 );
       pFrom->pTab = pTab = 
         sqlite3LocateTable(pParse,pFrom->zName,pFrom->zDatabase);
       if( pTab==0 ){
         return 1;
       }
+      pTab->nRef++;
 #ifndef SQLITE_OMIT_VIEW
       if( pTab->pSelect ){
         /* We reach here if the named table is a really a view */
@@ -1049,6 +1070,10 @@ static int prepSelectStmt(Parse *pParse, Select *p){
     */
     struct ExprList_item *a = pEList->a;
     ExprList *pNew = 0;
+    int flags = pParse->db->flags;
+    int longNames = (flags & SQLITE_FullColNames)!=0 &&
+                      (flags & SQLITE_ShortColNames)==0;
+
     for(k=0; k<pEList->nExpr; k++){
       Expr *pE = a[k].pExpr;
       if( pE->op!=TK_ALL &&
@@ -1101,7 +1126,7 @@ static int prepSelectStmt(Parse *pParse, Select *p){
             pRight = sqlite3Expr(TK_ID, 0, 0, 0);
             if( pRight==0 ) break;
             setToken(&pRight->token, zName);
-            if( zTabName && pTabList->nSrc>1 ){
+            if( zTabName && (longNames || pTabList->nSrc>1) ){
               pLeft = sqlite3Expr(TK_ID, 0, 0, 0);
               pExpr = sqlite3Expr(TK_DOT, pLeft, pRight, 0);
               if( pExpr==0 ) break;
@@ -1115,7 +1140,11 @@ static int prepSelectStmt(Parse *pParse, Select *p){
               pExpr = pRight;
               pExpr->span = pExpr->token;
             }
-            pNew = sqlite3ExprListAppend(pNew, pExpr, &pRight->token);
+            if( longNames ){
+              pNew = sqlite3ExprListAppend(pNew, pExpr, &pExpr->span);
+            }else{
+              pNew = sqlite3ExprListAppend(pNew, pExpr, &pRight->token);
+            }
           }
         }
         if( !tableSeen ){
@@ -1135,40 +1164,6 @@ static int prepSelectStmt(Parse *pParse, Select *p){
   return rc;
 }
 
-/*
-** This routine recursively unlinks the Select.pSrc.a[].pTab pointers
-** in a select structure.  It just sets the pointers to NULL.  This
-** routine is recursive in the sense that if the Select.pSrc.a[].pSelect
-** pointer is not NULL, this routine is called recursively on that pointer.
-**
-** This routine is called on the Select structure that defines a
-** VIEW in order to undo any bindings to tables.  This is necessary
-** because those tables might be DROPed by a subsequent SQL command.
-** If the bindings are not removed, then the Select.pSrc->a[].pTab field
-** will be left pointing to a deallocated Table structure after the
-** DROP and a coredump will occur the next time the VIEW is used.
-*/
-#if 0
-void sqlite3SelectUnbind(Select *p){
-  int i;
-  SrcList *pSrc = p->pSrc;
-  struct SrcList_item *pItem;
-  Table *pTab;
-  if( p==0 ) return;
-  for(i=0, pItem=pSrc->a; i<pSrc->nSrc; i++, pItem++){
-    if( (pTab = pItem->pTab)!=0 ){
-      if( pTab->isTransient ){
-        sqlite3DeleteTable(0, pTab);
-      }
-      pItem->pTab = 0;
-      if( pItem->pSelect ){
-        sqlite3SelectUnbind(pItem->pSelect);
-      }
-    }
-  }
-}
-#endif
-
 #ifndef SQLITE_OMIT_COMPOUND_SELECT
 /*
 ** This routine associates entries in an ORDER BY expression list with
@@ -1327,11 +1322,9 @@ static void computeLimitRegisters(Parse *pParse, Select *p){
 ** DISTINCT, UNION, INTERSECT and EXCEPT select statements (but not 
 ** UNION ALL).
 **
-** Make the new table a KeyAsData table if keyAsData is true.
-**
 ** The value returned is the address of the OP_OpenTemp instruction.
 */
-static int openTempIndex(Parse *pParse, Select *p, int iTab, int keyAsData){
+static int openTempIndex(Parse *pParse, Select *p, int iTab){
   KeyInfo *pKeyInfo;
   int nColumn;
   sqlite3 *db = pParse->db;
@@ -1355,9 +1348,6 @@ static int openTempIndex(Parse *pParse, Select *p, int iTab, int keyAsData){
   }
   addr = sqlite3VdbeOp3(v, OP_OpenTemp, iTab, 0, 
       (char*)pKeyInfo, P3_KEYINFO_HANDOFF);
-  if( keyAsData ){
-    sqlite3VdbeAddOp(v, OP_KeyAsData, iTab, 1);
-  }
   return addr;
 }
 
@@ -1552,7 +1542,6 @@ static int multiSelect(
           if( rc!=SQLITE_OK ){
             goto multi_select_end;
           }
-          sqlite3VdbeAddOp(v, OP_KeyAsData, unionTab, 1);
         }
        assert( nAddr<sizeof(aAddr)/sizeof(aAddr[0]) );
         aAddr[nAddr++] = sqlite3VdbeAddOp(v, OP_SetNumColumns, unionTab, 0);
@@ -1644,7 +1633,6 @@ static int multiSelect(
       if( rc!=SQLITE_OK ){
         goto multi_select_end;
       }
-      sqlite3VdbeAddOp(v, OP_KeyAsData, tab1, 1);
       assert( nAddr<sizeof(aAddr)/sizeof(aAddr[0]) );
       aAddr[nAddr++] = sqlite3VdbeAddOp(v, OP_SetNumColumns, tab1, 0);
       assert( p->pEList );
@@ -1663,7 +1651,6 @@ static int multiSelect(
       if( rc!=SQLITE_OK ){
         goto multi_select_end;
       }
-      sqlite3VdbeAddOp(v, OP_KeyAsData, tab2, 1);
       assert( nAddr<sizeof(aAddr)/sizeof(aAddr[0]) );
       aAddr[nAddr++] = sqlite3VdbeAddOp(v, OP_SetNumColumns, tab2, 0);
       p->pPrior = 0;
@@ -1691,7 +1678,7 @@ static int multiSelect(
       iCont = sqlite3VdbeMakeLabel(v);
       sqlite3VdbeAddOp(v, OP_Rewind, tab1, iBreak);
       computeLimitRegisters(pParse, p);
-      iStart = sqlite3VdbeAddOp(v, OP_FullKey, tab1, 0);
+      iStart = sqlite3VdbeAddOp(v, OP_RowKey, tab1, 0);
       sqlite3VdbeAddOp(v, OP_NotFound, tab2, iCont);
       rc = selectInnerLoop(pParse, p, p->pEList, tab1, p->pEList->nExpr,
                              p->pOrderBy, -1, eDest, iParm, 
@@ -2019,11 +2006,8 @@ static int flattenSubquery(
   {
     int nSubSrc = pSubSrc->nSrc;
     int jointype = pSubitem->jointype;
-    Table *pTab = pSubitem->pTab;
 
-    if( pTab && pTab->isTransient ){
-      sqlite3DeleteTable(0, pSubitem->pTab);
-    }
+    sqlite3DeleteTable(0, pSubitem->pTab);
     sqliteFree(pSubitem->zDatabase);
     sqliteFree(pSubitem->zName);
     sqliteFree(pSubitem->zAlias);
@@ -2230,12 +2214,12 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){
     sqlite3VdbeOp3(v, OP_OpenRead, iIdx, pIdx->tnum,
                    (char*)&pIdx->keyInfo, P3_KEYINFO);
     if( seekOp==OP_Rewind ){
-      sqlite3VdbeAddOp(v, OP_String, 0, 0);
+      sqlite3VdbeAddOp(v, OP_Null, 0, 0);
       sqlite3VdbeAddOp(v, OP_MakeRecord, 1, 0);
       seekOp = OP_MoveGt;
     }
     sqlite3VdbeAddOp(v, seekOp, iIdx, 0);
-    sqlite3VdbeAddOp(v, OP_IdxRecno, iIdx, 0);
+    sqlite3VdbeAddOp(v, OP_IdxRowid, iIdx, 0);
     sqlite3VdbeAddOp(v, OP_Close, iIdx, 0);
     sqlite3VdbeAddOp(v, OP_MoveGe, base, 0);
   }
@@ -2714,7 +2698,14 @@ int sqlite3Select(
     for(i=0; i<pParse->nAgg; i++){
       FuncDef *pFunc;
       if( (pFunc = pParse->aAgg[i].pFunc)!=0 && pFunc->xFinalize!=0 ){
-        sqlite3VdbeOp3(v, OP_AggInit, 0, i, (char*)pFunc, P3_FUNCDEF);
+        int nExpr = 0;
+#ifdef SQLITE_SSE
+        Expr *pAggExpr = pParse->aAgg[i].pExpr;
+        if( pAggExpr && pAggExpr->pList ){
+          nExpr = pAggExpr->pList->nExpr;
+        }
+#endif
+        sqlite3VdbeOp3(v, OP_AggInit, nExpr, i, (char*)pFunc, P3_FUNCDEF);
       }
     }
     if( pGroupBy ){
@@ -2738,7 +2729,7 @@ int sqlite3Select(
   /* Initialize the memory cell to NULL for SRT_Mem or 0 for SRT_Exists
   */
   if( eDest==SRT_Mem || eDest==SRT_Exists ){
-    sqlite3VdbeAddOp(v, eDest==SRT_Mem ? OP_String8 : OP_Integer, 0, 0);
+    sqlite3VdbeAddOp(v, eDest==SRT_Mem ? OP_Null : OP_Integer, 0, 0);
     sqlite3VdbeAddOp(v, OP_MemStore, iParm, 1);
   }
 
@@ -2746,7 +2737,7 @@ int sqlite3Select(
   */
   if( isDistinct ){
     distinct = pParse->nTab++;
-    openTempIndex(pParse, p, distinct, 0);
+    openTempIndex(pParse, p, distinct);
   }else{
     distinct = -1;
   }
@@ -2754,7 +2745,7 @@ int sqlite3Select(
   /* Begin the database scan
   */
   pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere,
-                             pGroupBy ? 0 : &pOrderBy, p->pFetch);
+                             pGroupBy ? 0 : &pOrderBy);
   if( pWInfo==0 ) goto select_end;
 
   /* Use the standard inner loop if we are not dealing with
@@ -2815,7 +2806,7 @@ int sqlite3Select(
         if( !pColl ) pColl = pParse->db->pDfltColl;
         sqlite3VdbeOp3(v, OP_CollSeq, 0, 0, (char *)pColl, P3_COLLSEQ);
       }
-      sqlite3VdbeOp3(v, OP_AggFunc, 0, nExpr, (char*)pDef, P3_POINTER);
+      sqlite3VdbeOp3(v, OP_AggFunc, 0, nExpr, (char*)pDef, P3_FUNCDEF);
     }
   }
 
index 2b369a210e1ae0d9090ca2c83d57c7f2d04ec220..e6411fc363cbcca83ef3af9c51995fa803fc9586 100644 (file)
@@ -656,7 +656,7 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
   zType = azArg[1];
   zSql = azArg[2];
   
-  if( strcasecmp(zTable,"sqlite_sequence")!=0 ){
+  if( strcmp(zTable,"sqlite_sequence")!=0 ){
     fprintf(p->out, "%s;\n", zSql);
   }else{
     fprintf(p->out, "DELETE FROM sqlite_sequence;\n");
index daffc25c62769c6c8507b627a76c7c8081d0170e..ecd337199ad1c6b8cb7b454737153d09f6cf3637 100644 (file)
@@ -688,8 +688,6 @@ int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName);
 
 /*
 ** Set all the parameters in the compiled SQL statement to NULL.
-**
-******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
 */
 int sqlite3_clear_bindings(sqlite3_stmt*);
 
@@ -1191,23 +1189,29 @@ int sqlite3_rekey(
 ** milisecond time resolution, then the time will be rounded up to 
 ** the nearest second. The number of miliseconds of sleep actually 
 ** requested from the operating system is returned.
-**
-******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
 */
 int sqlite3_sleep(int);
 
 /*
-** Return TRUE (non-zero) of the statement supplied as an argument needs
+** Return TRUE (non-zero) if the statement supplied as an argument needs
 ** to be recompiled.  A statement needs to be recompiled whenever the
 ** execution environment changes in a way that would alter the program
 ** that sqlite3_prepare() generates.  For example, if new functions or
 ** collating sequences are registered or if an authorizer function is
 ** added or changed.
 **
-******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
 */
 int sqlite3_expired(sqlite3_stmt*);
 
+/*
+** Move all bindings from the first prepared statement over to the second.
+** This routine is useful, for example, if the first prepared statement
+** fails with an SQLITE_SCHEMA error.  The same SQL can be prepared into
+** the second prepared statement then all of the bindings transfered over
+** to the second statement before the first statement is finalized.
+*/
+int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*);
+
 /*
 ** If the following global variable is made to point to a
 ** string which is the name of a directory, then all temporary files
@@ -1215,11 +1219,48 @@ int sqlite3_expired(sqlite3_stmt*);
 ** is NULL pointer, then SQLite does a search for an appropriate temporary
 ** file directory.
 **
-** Once sqlite3_open() has been called, changing this variable will invalidate the
-** current temporary database, if any.
+** Once sqlite3_open() has been called, changing this variable will invalidate
+** the current temporary database, if any.
 */
 extern char *sqlite3_temp_directory;
 
+/*
+** This function is called to recover from a malloc() failure that occured
+** within the SQLite library. Normally, after a single malloc() fails the 
+** library refuses to function (all major calls return SQLITE_NOMEM).
+** This function restores the library state so that it can be used again.
+**
+** All existing statements (sqlite3_stmt pointers) must be finalized or
+** reset before this call is made. Otherwise, SQLITE_BUSY is returned.
+** If any in-memory databases are in use, either as a main or TEMP
+** database, SQLITE_ERROR is returned. In either of these cases, the 
+** library is not reset and remains unusable.
+**
+** This function is *not* threadsafe. Calling this from within a threaded
+** application when threads other than the caller have used SQLite is
+** dangerous and will almost certainly result in malfunctions.
+**
+** This functionality can be omitted from a build by defining the 
+** SQLITE_OMIT_GLOBALRECOVER at compile time.
+*/
+int sqlite3_global_recover();
+
+/*
+** Test to see whether or not the database connection is in autocommit
+** mode.  Return TRUE if it is and FALSE if not.  Autocommit mode is on
+** by default.  Autocommit is disabled by a BEGIN statement and reenabled
+** by the next COMMIT or ROLLBACK.
+*/
+int sqlite3_get_autocommit(sqlite3*);
+
+/*
+** Return the sqlite3* database handle to which the prepared statement given
+** in the argument belongs.  This is the same database handle that was
+** the first argument to the sqlite3_prepare() that was used to create
+** the statement in the first place.
+*/
+sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
+
 #ifdef __cplusplus
 }  /* End of the 'extern "C"' block */
 #endif
index a9dde13186cf8d87e104d83e3a3771d5dced74bc..f0ffbd2e85ec5fd7b178ad2c2b40ca1d01f7b7f7 100644 (file)
 # define TEMP_PAGES   500
 #endif
 
+/*
+** OMIT_TEMPDB is set to 1 if SQLITE_OMIT_TEMPDB is defined, or 0
+** afterward. Having this macro allows us to cause the C compiler 
+** to omit code used by TEMP tables without messy #ifndef statements.
+*/
+#ifdef SQLITE_OMIT_TEMPDB
+#define OMIT_TEMPDB 1
+#else
+#define OMIT_TEMPDB 0
+#endif
+
 /*
 ** If the following macro is set to 1, then NULL values are considered
 ** distinct for the SELECT DISTINCT statement and for UNION or EXCEPT
 #ifndef LONGDOUBLE_TYPE
 # define LONGDOUBLE_TYPE long double
 #endif
-#ifndef INTPTR_TYPE
-# if SQLITE_PTR_SZ==4
-#   define INTPTR_TYPE int
-# else
-#   define INTPTR_TYPE sqlite_int64
-# endif
-#endif
-#ifndef UINTPTR_TYPE
-# if SQLITE_PTR_SZ==4
-#   define UINTPTR_TYPE unsigned int
-# else
-#   define UINTPTR_TYPE sqlite_uint64
-# endif
-#endif
 typedef sqlite_int64 i64;          /* 8-byte signed integer */
 typedef UINT64_TYPE u64;           /* 8-byte unsigned integer */
 typedef UINT32_TYPE u32;           /* 4-byte unsigned integer */
@@ -190,8 +187,6 @@ typedef UINT16_TYPE u16;           /* 2-byte unsigned integer */
 typedef INT16_TYPE i16;            /* 2-byte signed integer */
 typedef UINT8_TYPE u8;             /* 1-byte unsigned integer */
 typedef UINT8_TYPE i8;             /* 1-byte signed integer */
-typedef INTPTR_TYPE ptr;           /* Big enough to hold a pointer */
-typedef UINTPTR_TYPE uptr;         /* Big enough to hold a pointer */
 
 /*
 ** Macros to determine whether the machine is big or little endian,
@@ -292,7 +287,7 @@ extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */
 /*
 ** The name of the schema table.
 */
-#define SCHEMA_TABLE(x)  (x==1?TEMP_MASTER_NAME:MASTER_NAME)
+#define SCHEMA_TABLE(x)  ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME)
 
 /*
 ** A convenience macro that returns the number of elements in
@@ -306,7 +301,6 @@ extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */
 typedef struct Column Column;
 typedef struct Table Table;
 typedef struct Index Index;
-typedef struct Instruction Instruction;
 typedef struct Expr Expr;
 typedef struct ExprList ExprList;
 typedef struct Parse Parse;
@@ -328,7 +322,6 @@ typedef struct KeyClass KeyClass;
 typedef struct CollSeq CollSeq;
 typedef struct KeyInfo KeyInfo;
 typedef struct NameContext NameContext;
-typedef struct Fetch Fetch;
 
 /*
 ** Each database file to be accessed by the system is an instance
@@ -407,16 +400,13 @@ struct Db {
 struct sqlite3 {
   int nDb;                      /* Number of backends currently in use */
   Db *aDb;                      /* All backends */
-  Db aDbStatic[2];              /* Static space for the 2 default backends */
   int flags;                    /* Miscellanous flags. See below */
+  int errCode;                  /* Most recent error code (SQLITE_*) */
+  u8 enc;                       /* Text encoding for this database. */
+  u8 autoCommit;                /* The auto-commit flag. */
   u8 file_format;               /* What file format version is this database? */
   u8 temp_store;                /* 1: file 2: memory 0: default */
   int nTable;                   /* Number of tables in the database */
-  BusyHandler busyHandler;      /* Busy callback */
-  void *pCommitArg;             /* Argument to xCommitCallback() */   
-  int (*xCommitCallback)(void*);/* Invoked at every commit. */
-  Hash aFunc;                   /* All functions that can be in SQL exprs */
-  Hash aCollSeq;                /* All collating sequences */
   CollSeq *pDfltColl;           /* The default collating sequence (BINARY) */
   i64 lastRowid;                /* ROWID of most recent insert (see above) */
   i64 priorNewRowid;            /* Last randomly generated ROWID */
@@ -432,6 +422,15 @@ struct sqlite3 {
   int activeVdbeCnt;            /* Number of vdbes currently executing */
   void (*xTrace)(void*,const char*);     /* Trace function */
   void *pTraceArg;                       /* Argument to the trace function */
+  void *pCommitArg;             /* Argument to xCommitCallback() */   
+  int (*xCommitCallback)(void*);/* Invoked at every commit. */
+  void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
+  void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
+  void *pCollNeededArg;
+  sqlite3_value *pValue;        /* Value used for transient conversions */
+  sqlite3_value *pErr;          /* Most recent error message */
+  char *zErrMsg;                /* Most recent error message (UTF-8 encoded) */
+  char *zErrMsg16;              /* Most recent error message (UTF-16 encoded) */
 #ifndef SQLITE_OMIT_AUTHORIZATION
   int (*xAuth)(void*,int,const char*,const char*,const char*,const char*);
                                 /* Access authorization function */
@@ -442,16 +441,17 @@ struct sqlite3 {
   void *pProgressArg;           /* Argument to the progress callback */
   int nProgressOps;             /* Number of opcodes for progress callback */
 #endif
-  int errCode;                  /* Most recent error code (SQLITE_*) */
-  u8 enc;                       /* Text encoding for this database. */
-  u8 autoCommit;                /* The auto-commit flag. */
-  void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
-  void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
-  void *pCollNeededArg;
-  sqlite3_value *pValue;        /* Value used for transient conversions */
-  sqlite3_value *pErr;          /* Most recent error message */
-  char *zErrMsg;                /* Most recent error message (UTF-8 encoded) */
-  char *zErrMsg16;              /* Most recent error message (UTF-16 encoded) */
+#ifndef SQLITE_OMIT_GLOBALRECOVER
+  sqlite3 *pNext;               /* Linked list of open db handles. */
+#endif
+  Hash aFunc;                   /* All functions that can be in SQL exprs */
+  Hash aCollSeq;                /* All collating sequences */
+  BusyHandler busyHandler;      /* Busy callback */
+  int busyTimeout;             /* Busy handler timeout, in msec */
+  Db aDbStatic[2];              /* Static space for the 2 default backends */
+#ifdef SQLITE_SSE
+  sqlite3_stmt *pFetch;         /* Used by SSE to fetch stored statements */
+#endif
 };
 
 /*
@@ -608,9 +608,13 @@ struct Table {
   u8 hasPrimKey;   /* True if there exists a primary key */
   u8 keyConf;      /* What to do in case of uniqueness conflict on iPKey */
   u8 autoInc;      /* True if the integer primary key is autoincrement */
+  int nRef;          /* Number of pointers to this Table */
   Trigger *pTrigger; /* List of SQL triggers on this table */
   FKey *pFKey;       /* Linked list of all foreign keys in this table */
   char *zColAff;     /* String defining the affinity of each column */
+#ifndef SQLITE_OMIT_ALTERTABLE
+  int addColOffset;  /* Offset in CREATE TABLE statement to add a new column */
+#endif
 };
 
 /*
@@ -700,7 +704,8 @@ struct FKey {
 ** comparison of the two index keys.
 **
 ** If the KeyInfo.incrKey value is true and the comparison would
-** otherwise be equal, then return a result as if the second key larger.
+** otherwise be equal, then return a result as if the second key
+** were larger.
 */
 struct KeyInfo {
   u8 enc;             /* Text encoding - one of the TEXT_Utf* values */
@@ -805,6 +810,10 @@ struct Token {
 ** be the right operand of an IN operator.  Or, if a scalar SELECT appears
 ** in an expression the opcode is TK_SELECT and Expr.pSelect is the only
 ** operand.
+**
+** If the Expr is of type OP_Column, and the table it is selecting from
+** is a disk table or the "old.*" pseudo-table, then pTab points to the
+** corresponding table definition.
 */
 struct Expr {
   u8 op;                 /* Operation performed by this node */
@@ -824,6 +833,7 @@ struct Expr {
   int iAggCtx;           /* The value to pass as P1 of OP_AggGet. */
   Select *pSelect;       /* When the expression is a sub-select.  Also the
                          ** right side of "<expr> IN (<select>)" */
+  Table *pTab;           /* Table for OP_Column expressions. */
 };
 
 /*
@@ -1027,7 +1037,6 @@ struct Select {
   Expr *pOffset;         /* OFFSET expression. NULL means not used. */
   int iLimit, iOffset;   /* Memory registers holding LIMIT & OFFSET counters */
   IdList **ppOpenTemp;   /* OP_OpenTemp addresses used by multi-selects */
-  Fetch *pFetch;         /* If this stmt is part of a FETCH command */
   u8 isResolved;         /* True once sqlite3SelectResolve() has run. */
   u8 isAgg;              /* True if this is an aggregate query */
 };
@@ -1091,15 +1100,15 @@ struct Parse {
   u8 nameClash;        /* A permanent table name clashes with temp table name */
   u8 checkSchema;      /* Causes schema cookie check after an error */
   u8 nested;           /* Number of nested calls to the parser/code generator */
+  u8 fillAgg;          /* If true, ignore the Expr.iAgg field. Normally false */
   int nErr;            /* Number of errors seen */
   int nTab;            /* Number of previously allocated VDBE cursors */
   int nMem;            /* Number of memory cells used so far */
   int nSet;            /* Number of sets used so far */
+  u32 writeMask;       /* Start a write transaction on these databases */
   u32 cookieMask;      /* Bitmask of schema verified databases */
-  int cookieValue[MAX_ATTACHED+2];  /* Values of cookies to verify */
   int cookieGoto;      /* Address of OP_Goto to cookie verifier subroutine */
-  u32 writeMask;       /* Start a write transaction on these databases */
-  u8 fillAgg;          /* If true, ignore the Expr.iAgg field. Normally false */
+  int cookieValue[MAX_ATTACHED+2];  /* Values of cookies to verify */
 
   /* Above is constant between recursions.  Below is reset before and after
   ** each recursion */
@@ -1133,7 +1142,7 @@ struct AuthContext {
 };
 
 /*
-** Bitfield flags for P2 value in OP_PutIntKey and OP_Delete
+** Bitfield flags for P2 value in OP_Insert and OP_Delete
 */
 #define OPFLAG_NCHANGE   1    /* Set to update db->nChange */
 #define OPFLAG_LASTROWID 2    /* Set to update db->lastRowid */
@@ -1325,13 +1334,15 @@ void sqlite3RealToSortable(double r, char *);
   char *sqlite3StrDup(const char*);
   char *sqlite3StrNDup(const char*, int);
 # define sqlite3CheckMemory(a,b)
+# define sqlite3MallocX sqlite3Malloc
 #endif
 void sqlite3FreeX(void*);
+void *sqlite3MallocX(int);
 char *sqlite3MPrintf(const char*, ...);
 char *sqlite3VMPrintf(const char*, va_list);
 void sqlite3DebugPrintf(const char*, ...);
 void *sqlite3TextToPtr(const char*);
-void sqlite3SetString(char **, const char *, ...);
+void sqlite3SetString(char **, ...);
 void sqlite3ErrorMsg(Parse*, const char*, ...);
 void sqlite3Dequote(char*);
 int sqlite3KeywordCode(const char*, int);
@@ -1362,7 +1373,7 @@ void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int);
 void sqlite3AddColumnType(Parse*,Token*,Token*);
 void sqlite3AddDefaultValue(Parse*,Expr*);
 void sqlite3AddCollateType(Parse*, const char*, int);
-void sqlite3EndTable(Parse*,Token*,Select*);
+void sqlite3EndTable(Parse*,Token*,Token*,Select*);
 
 #ifndef SQLITE_OMIT_VIEW
   void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int);
@@ -1397,7 +1408,7 @@ void sqlite3OpenTableForReading(Vdbe*, int iCur, Table*);
 void sqlite3OpenTable(Vdbe*, int iCur, Table*, int);
 void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
 void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int);
-WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**, Fetch*);
+WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**);
 void sqlite3WhereEnd(WhereInfo*);
 void sqlite3ExprCode(Parse*, Expr*);
 void sqlite3ExprCodeAndCache(Parse*, Expr*);
@@ -1536,6 +1547,8 @@ void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, void(*)(void*));
 void sqlite3ValueFree(sqlite3_value*);
 sqlite3_value *sqlite3ValueNew();
 sqlite3_value *sqlite3GetTransientValue(sqlite3*db);
+int sqlite3ValueFromExpr(Expr *, u8, u8, sqlite3_value **);
+void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
 extern const unsigned char sqlite3UpperToLower[];
 void sqlite3RootPageMoved(Db*, int, int);
 void sqlite3Reindex(Parse*, Token*, Token*);
@@ -1546,5 +1559,14 @@ void sqlite3NestedParse(Parse*, const char*, ...);
 void sqlite3ExpirePreparedStatements(sqlite3*);
 void sqlite3CodeSubselect(Parse *, Expr *);
 int sqlite3SelectResolve(Parse *, Select *, NameContext *);
+void sqlite3ColumnDefault(Vdbe *, Table *, int);
+void sqlite3AlterFinishAddColumn(Parse *, Token *);
+void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
+const char *sqlite3TestErrorName(int);
+CollSeq *sqlite3GetCollSeq(sqlite3*, CollSeq *, const char *, int);
+
+#ifdef SQLITE_SSE
+#include "sseInt.h"
+#endif
 
 #endif
index 7f1aba3c7e9dfd7d00f5e3082b341e61527b3b41..a443a7746711b9fb4e6dff512e3b8cee499d6afa 100644 (file)
@@ -83,6 +83,7 @@ struct SqliteDb {
   char *zTrace;         /* The trace callback routine */
   char *zProgress;      /* The progress callback routine */
   char *zAuth;          /* The authorization callback routine */
+  char *zNull;          /* Text to substitute for an SQL NULL value */
   SqlFunc *pFunc;       /* List of SQL functions */
   SqlCollate *pCollate; /* List of SQL collation functions */
   int rc;               /* Return code of most recent sqlite3_exec() */
@@ -136,6 +137,9 @@ static void DbDeleteCmd(void *db){
   if( pDb->zAuth ){
     Tcl_Free(pDb->zAuth);
   }
+  if( pDb->zNull ){
+    Tcl_Free(pDb->zNull);
+  }
   Tcl_Free((char*)pDb);
 }
 
@@ -267,12 +271,33 @@ static void tclSqlFunc(sqlite3_context *context, int argc, sqlite3_value**argv){
       Tcl_DStringAppendElement(&cmd, sqlite3_value_text(argv[i]));
     }
   }
-  rc = Tcl_Eval(p->interp, Tcl_DStringValue(&cmd));
-  if( rc ){
+  rc = Tcl_EvalEx(p->interp, Tcl_DStringValue(&cmd), Tcl_DStringLength(&cmd),
+                  TCL_EVAL_DIRECT);
+  Tcl_DStringFree(&cmd);
+
+  if( rc && rc!=TCL_RETURN ){
     sqlite3_result_error(context, Tcl_GetStringResult(p->interp), -1); 
   }else{
-    sqlite3_result_text(context, Tcl_GetStringResult(p->interp), -1, 
-        SQLITE_TRANSIENT);
+    Tcl_Obj *pVar = Tcl_GetObjResult(p->interp);
+    int n;
+    u8 *data;
+    char *zType = pVar->typePtr ? pVar->typePtr->name : "";
+    char c = zType[0];
+    if( c=='b' && strcmp(zType,"bytearray")==0 ){
+      data = Tcl_GetByteArrayFromObj(pVar, &n);
+      sqlite3_result_blob(context, data, n, SQLITE_TRANSIENT);
+    }else if( (c=='b' && strcmp(zType,"boolean")==0) ||
+          (c=='i' && strcmp(zType,"int")==0) ){
+      Tcl_GetIntFromObj(0, pVar, &n);
+      sqlite3_result_int(context, n);
+    }else if( c=='d' && strcmp(zType,"double")==0 ){
+      double r;
+      Tcl_GetDoubleFromObj(0, pVar, &r);
+      sqlite3_result_double(context, r);
+    }else{
+      data = Tcl_GetStringFromObj(pVar, &n);
+      sqlite3_result_text(context, data, n, SQLITE_TRANSIENT);
+    }
   }
 }
 
@@ -441,9 +466,10 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
     "changes",            "close",             "collate",
     "collation_needed",   "commit_hook",       "complete",
     "copy",               "errorcode",         "eval",
-    "function",           "last_insert_rowid", "onecolumn",
-    "progress",           "rekey",             "timeout",
-    "total_changes",      "trace",             "version",
+    "function",           "last_insert_rowid", "nullvalue",
+    "onecolumn",          "progress",          "rekey",
+    "timeout",            "total_changes",     "trace",
+    "version",
     0                    
   };
   enum DB_enum {
@@ -451,9 +477,10 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
     DB_CHANGES,           DB_CLOSE,            DB_COLLATE,
     DB_COLLATION_NEEDED,  DB_COMMIT_HOOK,      DB_COMPLETE,
     DB_COPY,              DB_ERRORCODE,        DB_EVAL,
-    DB_FUNCTION,          DB_LAST_INSERT_ROWID,DB_ONECOLUMN,
-    DB_PROGRESS,          DB_REKEY,            DB_TIMEOUT,
-    DB_TOTAL_CHANGES,     DB_TRACE,            DB_VERSION
+    DB_FUNCTION,          DB_LAST_INSERT_ROWID,DB_NULLVALUE,
+    DB_ONECOLUMN,         DB_PROGRESS,         DB_REKEY,
+    DB_TIMEOUT,           DB_TOTAL_CHANGES,    DB_TRACE,
+    DB_VERSION
   };
   /* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */
 
@@ -729,6 +756,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
   ** built-in "info complete" command of Tcl.
   */
   case DB_COMPLETE: {
+#ifndef SQLITE_OMIT_COMPLETE
     Tcl_Obj *pResult;
     int isComplete;
     if( objc!=3 ){
@@ -738,6 +766,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
     isComplete = sqlite3_complete( Tcl_GetStringFromObj(objv[2], 0) );
     pResult = Tcl_GetObjResult(interp);
     Tcl_SetBooleanObj(pResult, isComplete);
+#endif
     break;
   }
 
@@ -936,11 +965,14 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
       */
       if( pArray ){
         Tcl_Obj *pColList = Tcl_NewObj();
+        Tcl_Obj *pStar = Tcl_NewStringObj("*", -1);
         Tcl_IncrRefCount(pColList);
         for(i=0; i<nCol; i++){
           Tcl_ListObjAppendElement(interp, pColList, apColName[i]);
         }
-        Tcl_ObjSetVar2(interp, pArray, Tcl_NewStringObj("*",-1), pColList,0);
+        Tcl_ObjSetVar2(interp, pArray, pStar, pColList,0);
+        Tcl_DecrRefCount(pColList);
+        Tcl_DecrRefCount(pStar);
       }
 
       /* Execute the SQL
@@ -970,6 +1002,10 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
               pVal = Tcl_NewDoubleObj(r);
               break;
             }
+            case SQLITE_NULL: {
+              pVal = dbTextToObj(pDb->zNull);
+              break;
+            }
             default: {
               pVal = dbTextToObj(sqlite3_column_text(pStmt, i));
               break;
@@ -1241,6 +1277,37 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
     break;
   }
 
+  /*
+  **     $db nullvalue ?STRING?
+  **
+  ** Change text used when a NULL comes back from the database. If ?STRING?
+  ** is not present, then the current string used for NULL is returned.
+  ** If STRING is present, then STRING is returned.
+  **
+  */
+  case DB_NULLVALUE: {
+    if( objc!=2 && objc!=3 ){
+      Tcl_WrongNumArgs(interp, 2, objv, "NULLVALUE");
+      return TCL_ERROR;
+    }
+    if( objc==3 ){
+      int len;
+      char *zNull = Tcl_GetStringFromObj(objv[2], &len);
+      if( pDb->zNull ){
+        Tcl_Free(pDb->zNull);
+      }
+      if( zNull && len>0 ){
+        pDb->zNull = Tcl_Alloc( len + 1 );
+        strncpy(pDb->zNull, zNull, len);
+        pDb->zNull[len] = '\0';
+      }else{
+        pDb->zNull = 0;
+      }
+    }
+    Tcl_SetObjResult(interp, dbTextToObj(pDb->zNull));
+    break;
+  }
+  
   /*
   **     $db total_changes
   **
@@ -1725,12 +1792,17 @@ int TCLSH_MAIN(int argc, char **argv){
     extern int Sqlitetest4_Init(Tcl_Interp*);
     extern int Sqlitetest5_Init(Tcl_Interp*);
     extern int Md5_Init(Tcl_Interp*);
+    extern int Sqlitetestsse_Init(Tcl_Interp*);
+
     Sqlitetest1_Init(interp);
     Sqlitetest2_Init(interp);
     Sqlitetest3_Init(interp);
     Sqlitetest4_Init(interp);
     Sqlitetest5_Init(interp);
     Md5_Init(interp);
+#ifdef SQLITE_SSE
+    Sqlitetestsse_Init(interp);
+#endif
   }
 #endif
   if( argc>=2 || TCLSH==2 ){
index 7a96c378b53d01648af2582f568e51cfcae1e758..de1df80e1d5d3e50cd13044662d91d73832f5e85 100644 (file)
@@ -21,7 +21,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-static const char * errorName(int rc){
+const char *sqlite3TestErrorName(int rc){
   const char *zName = 0;
   switch( rc ){
     case SQLITE_OK:         zName = "SQLITE_OK";          break;
@@ -57,12 +57,13 @@ static const char * errorName(int rc){
   }
   return zName;
 }
+#define errorName sqlite3TestErrorName
 
 /*
 ** Convert an sqlite3_stmt* into an sqlite3*.  This depends on the
 ** fact that the sqlite3* is the first field in the Vdbe structure.
 */
-#define StmtToDb(X)   (*(sqlite3**)(X))
+#define StmtToDb(X)   sqlite3_db_handle(X)
 
 /*
 ** Check a return value to make sure it agrees with the results
@@ -971,6 +972,30 @@ static int test_expired(
   return TCL_OK;
 }
 
+/*
+** Usage:  sqlite3_transfer_bindings FROMSTMT TOSTMT
+**
+** Transfer all bindings from FROMSTMT over to TOSTMT
+*/
+static int test_transfer_bind(
+  void * clientData,
+  Tcl_Interp *interp,
+  int objc,
+  Tcl_Obj *CONST objv[]
+){
+  sqlite3_stmt *pStmt1, *pStmt2;
+  if( objc!=3 ){
+    Tcl_AppendResult(interp, "wrong # args: should be \"",
+        Tcl_GetStringFromObj(objv[0], 0), " FROM-STMT TO-STMT", 0);
+    return TCL_ERROR;
+  }
+  if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt1)) return TCL_ERROR;
+  if( getStmtPointer(interp, Tcl_GetString(objv[2]), &pStmt2)) return TCL_ERROR;
+  Tcl_SetObjResult(interp, 
+     Tcl_NewIntObj(sqlite3_transfer_bindings(pStmt1,pStmt2)));
+  return TCL_OK;
+}
+
 /*
 ** Usage:  sqlite3_changes DB
 **
@@ -1580,6 +1605,7 @@ static int test_bind_text(
   rc = sqlite3_bind_text(pStmt, idx, value, bytes, SQLITE_TRANSIENT);
   if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
   if( rc!=SQLITE_OK ){
+    Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
     return TCL_ERROR;
   }
 
@@ -2032,7 +2058,7 @@ static int test_complete16(
   int objc,
   Tcl_Obj *CONST objv[]
 ){
-#ifndef SQLITE_OMIT_UTF16
+#if !defined(SQLITE_OMIT_COMPLETE) && !defined(SQLITE_OMIT_UTF16)
   char *zBuf;
 
   if( objc!=2 ){
@@ -2042,7 +2068,7 @@ static int test_complete16(
 
   zBuf = Tcl_GetByteArrayFromObj(objv[1], 0);
   Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_complete16(zBuf)));
-#endif /* SQLITE_OMIT_UTF16 */
+#endif /* SQLITE_OMIT_COMPLETE && SQLITE_OMIT_UTF16 */
   return TCL_OK;
 }
 
@@ -2294,6 +2320,24 @@ static int test_stmt_utf8(
   return TCL_OK;
 }
 
+static int test_global_recover(
+  void * clientData,
+  Tcl_Interp *interp,
+  int objc,
+  Tcl_Obj *CONST objv[]
+){
+#ifndef SQLITE_OMIT_GLOBALRECOVER
+  int rc;
+  if( objc!=1 ){
+    Tcl_WrongNumArgs(interp, 1, objv, "");
+    return TCL_ERROR;
+  }
+  rc = sqlite3_global_recover();
+  Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC);
+#endif
+  return TCL_OK;
+}
+
 /*
 ** Usage: sqlite3_column_text STMT column
 **
@@ -2364,6 +2408,7 @@ static int test_stmt_int(
   return TCL_OK;
 }
 
+#ifndef SQLITE_OMIT_DISKIO
 /*
 ** Usage:  sqlite3OsOpenReadWrite <filename>
 */
@@ -2523,6 +2568,7 @@ static int test_sqlite3OsTempFileName(
   Tcl_AppendResult(interp, zFile, 0);
   return TCL_OK;
 }
+#endif
 
 /*
 ** Usage:  sqlite_set_magic  DB  MAGIC-NUMBER
@@ -2651,6 +2697,31 @@ static int delete_collation(
   return TCL_OK;
 }
 
+/*
+** Usage: sqlite3_get_autocommit DB
+**
+** Return true if the database DB is currently in auto-commit mode.
+** Return false if not.
+*/
+static int get_autocommit(
+  void * clientData,
+  Tcl_Interp *interp,
+  int argc,
+  char **argv
+){
+  char zBuf[30];
+  sqlite3 *db;
+  if( argc!=2 ){
+    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], 
+        " DB", 0);
+    return TCL_ERROR;
+  }
+  if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
+  sprintf(zBuf, "%d", sqlite3_get_autocommit(db));
+  Tcl_AppendResult(interp, zBuf, 0);
+  return TCL_OK;
+}
+
 /*
 ** Usage:  tcl_variable_type VARIABLENAME
 **
@@ -2723,6 +2794,12 @@ static void set_options(Tcl_Interp *interp){
   Tcl_SetVar2(interp, "sqlite_options", "bloblit", "1", TCL_GLOBAL_ONLY);
 #endif
 
+#ifdef SQLITE_OMIT_COMPLETE
+  Tcl_SetVar2(interp, "sqlite_options", "complete", "0", TCL_GLOBAL_ONLY);
+#else
+  Tcl_SetVar2(interp, "sqlite_options", "complete", "1", TCL_GLOBAL_ONLY);
+#endif
+
 #ifdef SQLITE_OMIT_COMPOUND_SELECT
   Tcl_SetVar2(interp, "sqlite_options", "compound", "0", TCL_GLOBAL_ONLY);
 #else
@@ -2741,6 +2818,12 @@ static void set_options(Tcl_Interp *interp){
   Tcl_SetVar2(interp, "sqlite_options", "datetime", "1", TCL_GLOBAL_ONLY);
 #endif
 
+#ifdef SQLITE_OMIT_DISKIO
+  Tcl_SetVar2(interp, "sqlite_options", "diskio", "0", TCL_GLOBAL_ONLY);
+#else
+  Tcl_SetVar2(interp, "sqlite_options", "diskio", "1", TCL_GLOBAL_ONLY);
+#endif
+
 #ifdef SQLITE_OMIT_EXPLAIN
   Tcl_SetVar2(interp, "sqlite_options", "explain", "0", TCL_GLOBAL_ONLY);
 #else
@@ -2759,6 +2842,12 @@ static void set_options(Tcl_Interp *interp){
   Tcl_SetVar2(interp, "sqlite_options", "foreignkey", "1", TCL_GLOBAL_ONLY);
 #endif
 
+#ifdef SQLITE_OMIT_GLOBALRECOVER
+  Tcl_SetVar2(interp, "sqlite_options", "globalrecover", "0", TCL_GLOBAL_ONLY);
+#else
+  Tcl_SetVar2(interp, "sqlite_options", "globalrecover", "1", TCL_GLOBAL_ONLY);
+#endif
+
 #ifdef SQLITE_OMIT_INTEGRITY_CHECK
   Tcl_SetVar2(interp, "sqlite_options", "integrityck", "0", TCL_GLOBAL_ONLY);
 #else
@@ -2777,7 +2866,13 @@ static void set_options(Tcl_Interp *interp){
   Tcl_SetVar2(interp, "sqlite_options", "pager_pragmas", "1", TCL_GLOBAL_ONLY);
 #endif
 
-#ifdef SQLITE_OMIT_PRAGMA
+#ifdef SQLITE_OMIT_PARSER
+  Tcl_SetVar2(interp, "sqlite_options", "parser", "0", TCL_GLOBAL_ONLY);
+#else
+  Tcl_SetVar2(interp, "sqlite_options", "parser", "1", TCL_GLOBAL_ONLY);
+#endif
+
+#if defined(SQLITE_OMIT_PRAGMA) || defined(SQLITE_OMIT_FLAG_PRAGMAS)
   Tcl_SetVar2(interp, "sqlite_options", "pragma", "0", TCL_GLOBAL_ONLY);
   Tcl_SetVar2(interp, "sqlite_options", "integrityck", "0", TCL_GLOBAL_ONLY);
 #else
@@ -2832,6 +2927,12 @@ static void set_options(Tcl_Interp *interp){
   Tcl_SetVar2(interp, "sqlite_options", "trigger", "1", TCL_GLOBAL_ONLY);
 #endif
 
+#ifdef SQLITE_OMIT_TEMPDB
+  Tcl_SetVar2(interp, "sqlite_options", "tempdb", "0", TCL_GLOBAL_ONLY);
+#else
+  Tcl_SetVar2(interp, "sqlite_options", "tempdb", "1", TCL_GLOBAL_ONLY);
+#endif
+
 #ifdef SQLITE_OMIT_UTF16
   Tcl_SetVar2(interp, "sqlite_options", "utf16", "0", TCL_GLOBAL_ONLY);
 #else
@@ -2892,8 +2993,9 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
 #if 0
      { "sqlite3_sleep",                 (Tcl_CmdProc*)test_sleep            },
 #endif
-     { "sqlite_delete_function",       (Tcl_CmdProc*)delete_function        },
-     { "sqlite_delete_collation",      (Tcl_CmdProc*)delete_collation       }
+     { "sqlite_delete_function",        (Tcl_CmdProc*)delete_function       },
+     { "sqlite_delete_collation",       (Tcl_CmdProc*)delete_collation      },
+     { "sqlite3_get_autocommit",        (Tcl_CmdProc*)get_autocommit        },
   };
   static struct {
      char *zName;
@@ -2925,6 +3027,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
      { "sqlite3_finalize",              test_finalize      ,0 },
      { "sqlite3_reset",                 test_reset         ,0 },
      { "sqlite3_expired",               test_expired       ,0 },
+     { "sqlite3_transfer_bindings",     test_transfer_bind ,0 },
      { "sqlite3_changes",               test_changes       ,0 },
      { "sqlite3_step",                  test_step          ,0 },
 
@@ -2946,8 +3049,10 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
      { "sqlite3_column_decltype16", test_stmt_utf16, sqlite3_column_decltype16},
      { "sqlite3_column_name16",     test_stmt_utf16, sqlite3_column_name16    },
 #endif
+     { "sqlite3_global_recover",    test_global_recover, 0   },
 
      /* Functions from os.h */
+#ifndef SQLITE_OMIT_DISKIO
      { "sqlite3OsOpenReadWrite",test_sqlite3OsOpenReadWrite, 0 },
      { "sqlite3OsClose",        test_sqlite3OsClose, 0 },
      { "sqlite3OsLock",         test_sqlite3OsLock, 0 },
@@ -2955,6 +3060,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
    
      /* Custom test interfaces */
      { "sqlite3OsUnlock",         test_sqlite3OsUnlock, 0    },
+#endif
 #ifndef SQLITE_OMIT_UTF16
      { "add_test_collate",        test_collate, 0            },
      { "add_test_collate_needed", test_collate_needed, 0     },
@@ -2967,7 +3073,8 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
   static int bitmask_size = sizeof(Bitmask)*8;
   int i;
   extern int sqlite3_os_trace;
+  extern int sqlite3_sync_count, sqlite3_fullsync_count;
+  extern int sqlite3_opentemp_count;
 
   for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
     Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
@@ -2988,12 +3095,22 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
       (char*)&sqlite3_current_time, TCL_LINK_INT);
   Tcl_LinkVar(interp, "sqlite_os_trace",
       (char*)&sqlite3_os_trace, TCL_LINK_INT);
+#ifndef SQLITE_OMIT_DISKIO
+  Tcl_LinkVar(interp, "sqlite_opentemp_count",
+      (char*)&sqlite3_opentemp_count, TCL_LINK_INT);
+#endif
   Tcl_LinkVar(interp, "sqlite_static_bind_value",
       (char*)&sqlite_static_bind_value, TCL_LINK_STRING);
   Tcl_LinkVar(interp, "sqlite_temp_directory",
       (char*)&sqlite3_temp_directory, TCL_LINK_STRING);
   Tcl_LinkVar(interp, "bitmask_size",
       (char*)&bitmask_size, TCL_LINK_INT|TCL_LINK_READ_ONLY);
+#if OS_UNIX
+  Tcl_LinkVar(interp, "sqlite_sync_count",
+      (char*)&sqlite3_sync_count, TCL_LINK_INT);
+  Tcl_LinkVar(interp, "sqlite_fullsync_count",
+      (char*)&sqlite3_fullsync_count, TCL_LINK_INT);
+#endif /* OS_UNIX */
   set_options(interp);
   return TCL_OK;
 }
index 2f8cdf4846cda33c110789035a105e49852cf3b6..f06685606c932648e38d71f0ac29638a1f9830df 100644 (file)
@@ -508,6 +508,7 @@ static int page_write(
   return TCL_OK;
 }
 
+#ifndef SQLITE_OMIT_DISKIO
 /*
 ** Usage:   fake_big_file  N  FILENAME
 **
@@ -555,6 +556,7 @@ static int fake_big_file(
   }
   return TCL_OK;
 }
+#endif
 
 /*
 ** Register commands with the TCL interpreter.
@@ -582,7 +584,9 @@ int Sqlitetest2_Init(Tcl_Interp *interp){
     { "page_write",              (Tcl_CmdProc*)page_write          },
     { "page_number",             (Tcl_CmdProc*)page_number         },
     { "pager_truncate",          (Tcl_CmdProc*)pager_truncate      },
+#ifndef SQLITE_OMIT_DISKIO
     { "fake_big_file",           (Tcl_CmdProc*)fake_big_file       },
+#endif
   };
   int i;
   for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
index fb1f6674dfde1e09b688e6856af1ff49d954910a..578a60bda7b6d13e3c2474d80fce8927ba16ee1c 100644 (file)
@@ -341,10 +341,10 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
   db->flags &= ~SQLITE_Interrupt;
   pParse->rc = SQLITE_OK;
   i = 0;
-  pEngine = sqlite3ParserAlloc((void*(*)(int))malloc);
+  pEngine = sqlite3ParserAlloc((void*(*)(int))sqlite3MallocX);
   if( pEngine==0 ){
     sqlite3SetString(pzErrMsg, "out of memory", (char*)0);
-    return 1;
+    return SQLITE_NOMEM;
   }
   assert( pParse->sLastToken.dyn==0 );
   assert( pParse->pNewTable==0 );
@@ -401,7 +401,7 @@ abort_parse:
     }
     sqlite3Parser(pEngine, 0, pParse->sLastToken, pParse);
   }
-  sqlite3ParserFree(pEngine, free);
+  sqlite3ParserFree(pEngine, sqlite3FreeX);
   if( sqlite3_malloc_failed ){
     pParse->rc = SQLITE_NOMEM;
   }
@@ -431,6 +431,11 @@ abort_parse:
   return nErr;
 }
 
+/* The sqlite3_complete() API may be omitted (to save code space) by
+** defining the following symbol.
+*/
+#ifndef SQLITE_OMIT_COMPLETE
+
 /*
 ** Token types used by the sqlite3_complete() routine.  See the header
 ** comments on that procedure for additional information.
@@ -662,3 +667,4 @@ int sqlite3_complete16(const void *zSql){
   return rc;
 }
 #endif /* SQLITE_OMIT_UTF16 */
+#endif /* SQLITE_OMIT_COMPLETE */
index eccc810e9be328832bd4c1e74f1b6ce12b326018..f39d2bd83fe00a8635291f4788aa267d49b44c2f 100644 (file)
@@ -51,7 +51,7 @@ void sqlite3BeginTrigger(
   Expr *pWhen,        /* WHEN clause */
   int isTemp          /* True if the TEMPORARY keyword is present */
 ){
-  Trigger *pTrigger;
+  Trigger *pTrigger = 0;
   Table *pTab;
   char *zName = 0;        /* Name of the trigger */
   sqlite3 *db = pParse->db;
@@ -161,7 +161,6 @@ void sqlite3BeginTrigger(
   pTrigger->name = zName;
   zName = 0;
   pTrigger->table = sqliteStrDup(pTableName->a[0].zName);
-  if( sqlite3_malloc_failed ) goto trigger_cleanup;
   pTrigger->iDb = iDb;
   pTrigger->iTabDb = pTab->iDb;
   pTrigger->op = op;
@@ -178,6 +177,11 @@ trigger_cleanup:
   sqlite3SrcListDelete(pTableName);
   sqlite3IdListDelete(pColumns);
   sqlite3ExprDelete(pWhen);
+  if( !pParse->pNewTrigger ){
+    sqlite3DeleteTrigger(pTrigger);
+  }else{
+    assert( pParse->pNewTrigger==pTrigger );
+  }
 }
 
 /*
@@ -193,9 +197,9 @@ void sqlite3FinishTrigger(
   sqlite3 *db = pParse->db;  /* The database */
   DbFixer sFix;
 
-  if( pParse->nErr || pParse->pNewTrigger==0 ) goto triggerfinish_cleanup;
   pTrig = pParse->pNewTrigger;
   pParse->pNewTrigger = 0;
+  if( pParse->nErr || pTrig==0 ) goto triggerfinish_cleanup;
   pTrig->step_list = pStepList;
   while( pStepList ){
     pStepList->pTrig = pTrig;
@@ -211,7 +215,7 @@ void sqlite3FinishTrigger(
   */
   if( !db->init.busy ){
     static const VdbeOpList insertTrig[] = {
-      { OP_NewRecno,   0, 0,  0          },
+      { OP_NewRowid,   0, 0,  0          },
       { OP_String8,    0, 0,  "trigger"  },
       { OP_String8,    0, 0,  0          },  /* 2: trigger name */
       { OP_String8,    0, 0,  0          },  /* 3: table name */
@@ -220,7 +224,7 @@ void sqlite3FinishTrigger(
       { OP_String8,    0, 0,  0          },  /* 6: SQL */
       { OP_Concat,     0, 0,  0          }, 
       { OP_MakeRecord, 5, 0,  "tttit"    },
-      { OP_PutIntKey,  0, 0,  0          },
+      { OP_Insert,     0, 0,  0          },
     };
     int addr;
     Vdbe *v;
@@ -242,8 +246,13 @@ void sqlite3FinishTrigger(
 
   if( db->init.busy ){
     Table *pTab;
-    sqlite3HashInsert(&db->aDb[pTrig->iDb].trigHash, 
+    Trigger *pDel;
+    pDel = sqlite3HashInsert(&db->aDb[pTrig->iDb].trigHash, 
                      pTrig->name, strlen(pTrig->name)+1, pTrig);
+    if( pDel ){
+      assert( sqlite3_malloc_failed && pDel==pTrig );
+      goto triggerfinish_cleanup;
+    }
     pTab = sqlite3LocateTable(pParse,pTrig->table,db->aDb[pTrig->iTabDb].zName);
     assert( pTab!=0 );
     pTrig->pNext = pTab->pTrigger;
@@ -328,18 +337,23 @@ TriggerStep *sqlite3TriggerInsertStep(
   int orconf          /* The conflict algorithm (OE_Abort, OE_Replace, etc.) */
 ){
   TriggerStep *pTriggerStep = sqliteMalloc(sizeof(TriggerStep));
-  if( pTriggerStep==0 ) return 0;
 
   assert(pEList == 0 || pSelect == 0);
   assert(pEList != 0 || pSelect != 0);
 
-  pTriggerStep->op = TK_INSERT;
-  pTriggerStep->pSelect = pSelect;
-  pTriggerStep->target  = *pTableName;
-  pTriggerStep->pIdList = pColumn;
-  pTriggerStep->pExprList = pEList;
-  pTriggerStep->orconf = orconf;
-  sqlitePersistTriggerStep(pTriggerStep);
+  if( pTriggerStep ){
+    pTriggerStep->op = TK_INSERT;
+    pTriggerStep->pSelect = pSelect;
+    pTriggerStep->target  = *pTableName;
+    pTriggerStep->pIdList = pColumn;
+    pTriggerStep->pExprList = pEList;
+    pTriggerStep->orconf = orconf;
+    sqlitePersistTriggerStep(pTriggerStep);
+  }else{
+    sqlite3IdListDelete(pColumn);
+    sqlite3ExprListDelete(pEList);
+    sqlite3SelectDup(pSelect);
+  }
 
   return pTriggerStep;
 }
@@ -425,7 +439,7 @@ void sqlite3DropTrigger(Parse *pParse, SrcList *pName){
   zDb = pName->a[0].zDatabase;
   zName = pName->a[0].zName;
   nName = strlen(zName);
-  for(i=0; i<db->nDb; i++){
+  for(i=OMIT_TEMPDB; i<db->nDb; i++){
     int j = (i<2) ? i^1 : i;  /* Search TEMP before MAIN */
     if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
     pTrigger = sqlite3HashFind(&(db->aDb[j].trigHash), zName, nName+1);
index 29ac02a646eab5f755f24be5f9203706aa5d2376..9d96bec182f3c4dab43d561546ebe4af1f24e5ed 100644 (file)
 */
 #include "sqliteInt.h"
 
+/*
+** The most recently coded instruction was an OP_Column to retrieve column
+** 'i' of table pTab. This routine sets the P3 parameter of the 
+** OP_Column to the default value, if any.
+**
+** The default value of a column is specified by a DEFAULT clause in the 
+** column definition. This was either supplied by the user when the table
+** was created, or added later to the table definition by an ALTER TABLE
+** command. If the latter, then the row-records in the table btree on disk
+** may not contain a value for the column and the default value, taken
+** from the P3 parameter of the OP_Column instruction, is returned instead.
+** If the former, then all row-records are guaranteed to include a value
+** for the column and the P3 value is not required.
+**
+** Column definitions created by an ALTER TABLE command may only have 
+** literal default values specified: a number, null or a string. (If a more
+** complicated default expression value was provided, it is evaluated 
+** when the ALTER TABLE is executed and one of the literal values written
+** into the sqlite_master table.)
+**
+** Therefore, the P3 parameter is only required if the default value for
+** the column is a literal number, string or null. The sqlite3ValueFromExpr()
+** function is capable of transforming these types of expressions into
+** sqlite3_value objects.
+*/
+void sqlite3ColumnDefault(Vdbe *v, Table *pTab, int i){
+  if( pTab && !pTab->pSelect ){
+    sqlite3_value *pValue;
+    u8 enc = sqlite3VdbeDb(v)->enc;
+    Column *pCol = &pTab->aCol[i];
+    sqlite3ValueFromExpr(pCol->pDflt, enc, pCol->affinity, &pValue);
+    sqlite3VdbeChangeP3(v, -1, (const char *)pValue, P3_MEM);
+  }
+}
+
 /*
 ** Process an UPDATE statement.
 **
@@ -45,8 +80,8 @@ void sqlite3Update(
   int *aXRef = 0;        /* aXRef[i] is the index in pChanges->a[] of the
                          ** an expression for the i-th column of the table.
                          ** aXRef[i]==-1 if the i-th column is not changed. */
-  int chngRecno;         /* True if the record number is being changed */
-  Expr *pRecnoExpr = 0;  /* Expression defining the new record number */
+  int chngRowid;         /* True if the record number is being changed */
+  Expr *pRowidExpr = 0;  /* Expression defining the new record number */
   int openAll = 0;       /* True if all indices need to be opened */
   AuthContext sContext;  /* The authorization context */
   NameContext sNC;       /* The name-context to resolve expressions in */
@@ -125,7 +160,7 @@ void sqlite3Update(
   ** column to be updated, make sure we have authorization to change
   ** that column.
   */
-  chngRecno = 0;
+  chngRowid = 0;
   for(i=0; i<pChanges->nExpr; i++){
     if( sqlite3ExprResolveNames(&sNC, pChanges->a[i].pExpr) ){
       goto update_cleanup;
@@ -133,8 +168,8 @@ void sqlite3Update(
     for(j=0; j<pTab->nCol; j++){
       if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){
         if( j==pTab->iPKey ){
-          chngRecno = 1;
-          pRecnoExpr = pChanges->a[i].pExpr;
+          chngRowid = 1;
+          pRowidExpr = pChanges->a[i].pExpr;
         }
         aXRef[j] = i;
         break;
@@ -142,8 +177,8 @@ void sqlite3Update(
     }
     if( j>=pTab->nCol ){
       if( sqlite3IsRowid(pChanges->a[i].zName) ){
-        chngRecno = 1;
-        pRecnoExpr = pChanges->a[i].pExpr;
+        chngRowid = 1;
+        pRowidExpr = pChanges->a[i].pExpr;
       }else{
         sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zName);
         goto update_cleanup;
@@ -169,7 +204,7 @@ void sqlite3Update(
   ** number of the original table entry is changing.
   */
   for(nIdx=nIdxTotal=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdxTotal++){
-    if( chngRecno ){
+    if( chngRowid ){
       i = 0;
     }else {
       for(i=0; i<pIdx->nColumn; i++){
@@ -184,7 +219,7 @@ void sqlite3Update(
     aIdxUsed = (char*)&apIdx[nIdx];
   }
   for(nIdx=j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
-    if( chngRecno ){
+    if( chngRowid ){
       i = 0;
     }else{
       for(i=0; i<pIdx->nColumn; i++){
@@ -232,12 +267,12 @@ void sqlite3Update(
 
   /* Begin the database scan
   */
-  pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0);
+  pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0);
   if( pWInfo==0 ) goto update_cleanup;
 
   /* Remember the index of every item to be updated.
   */
-  sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
+  sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
   sqlite3VdbeAddOp(v, OP_ListWrite, 0, 0);
 
   /* End the database scan loop.
@@ -262,38 +297,39 @@ void sqlite3Update(
     */
     sqlite3VdbeAddOp(v, OP_ListRewind, 0, 0);
     addr = sqlite3VdbeAddOp(v, OP_ListRead, 0, 0);
-    sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
 
-    /* Open a cursor and make it point to the record that is
-    ** being updated.
-    */
-    sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
     if( !isView ){
+      sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
+      sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
+      /* Open a cursor and make it point to the record that is
+      ** being updated.
+      */
       sqlite3OpenTableForReading(v, iCur, pTab);
     }
     sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
 
     /* Generate the OLD table
     */
-    sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
+    sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
     sqlite3VdbeAddOp(v, OP_RowData, iCur, 0);
-    sqlite3VdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
+    sqlite3VdbeAddOp(v, OP_Insert, oldIdx, 0);
 
     /* Generate the NEW table
     */
-    if( chngRecno ){
-      sqlite3ExprCodeAndCache(pParse, pRecnoExpr);
+    if( chngRowid ){
+      sqlite3ExprCodeAndCache(pParse, pRowidExpr);
     }else{
-      sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
+      sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
     }
     for(i=0; i<pTab->nCol; i++){
       if( i==pTab->iPKey ){
-        sqlite3VdbeAddOp(v, OP_String8, 0, 0);
+        sqlite3VdbeAddOp(v, OP_Null, 0, 0);
         continue;
       }
       j = aXRef[i];
       if( j<0 ){
         sqlite3VdbeAddOp(v, OP_Column, iCur, i);
+        sqlite3ColumnDefault(v, pTab, i);
       }else{
         sqlite3ExprCodeAndCache(pParse, pChanges->a[j].pExpr);
       }
@@ -303,7 +339,7 @@ void sqlite3Update(
       sqlite3TableAffinityStr(v, pTab);
     }
     if( pParse->nErr ) goto update_cleanup;
-    sqlite3VdbeAddOp(v, OP_PutIntKey, newIdx, 0);
+    sqlite3VdbeAddOp(v, OP_Insert, newIdx, 0);
     if( !isView ){
       sqlite3VdbeAddOp(v, OP_Close, iCur, 0);
     }
@@ -363,8 +399,8 @@ void sqlite3Update(
     ** will be after the update. (The old record number is currently
     ** on top of the stack.)
     */
-    if( chngRecno ){
-      sqlite3ExprCode(pParse, pRecnoExpr);
+    if( chngRowid ){
+      sqlite3ExprCode(pParse, pRowidExpr);
       sqlite3VdbeAddOp(v, OP_MustBeInt, 0, 0);
     }
 
@@ -372,12 +408,13 @@ void sqlite3Update(
     */
     for(i=0; i<pTab->nCol; i++){
       if( i==pTab->iPKey ){
-        sqlite3VdbeAddOp(v, OP_String8, 0, 0);
+        sqlite3VdbeAddOp(v, OP_Null, 0, 0);
         continue;
       }
       j = aXRef[i];
       if( j<0 ){
         sqlite3VdbeAddOp(v, OP_Column, iCur, i);
+        sqlite3ColumnDefault(v, pTab, i);
       }else{
         sqlite3ExprCode(pParse, pChanges->a[j].pExpr);
       }
@@ -385,7 +422,7 @@ void sqlite3Update(
 
     /* Do constraint checks
     */
-    sqlite3GenerateConstraintChecks(pParse, pTab, iCur, aIdxUsed, chngRecno, 1,
+    sqlite3GenerateConstraintChecks(pParse, pTab, iCur, aIdxUsed, chngRowid, 1,
                                    onError, addr);
 
     /* Delete the old indices for the current record.
@@ -394,13 +431,13 @@ void sqlite3Update(
 
     /* If changing the record number, delete the old record.
     */
-    if( chngRecno ){
+    if( chngRowid ){
       sqlite3VdbeAddOp(v, OP_Delete, iCur, 0);
     }
 
     /* Create the new index entries and the new record.
     */
-    sqlite3CompleteInsertion(pParse, pTab, iCur, aIdxUsed, chngRecno, 1, -1);
+    sqlite3CompleteInsertion(pParse, pTab, iCur, aIdxUsed, chngRowid, 1, -1);
   }
 
   /* Increment the row counter 
index bcbfe2493ea417872239044a9be8d3278b793075..90edb98a09975dc1cca8184c2b5f79ac7bb5044d 100644 (file)
@@ -65,9 +65,11 @@ static int memcnt = 0;
 #endif
 
 /*
-** Number of 32-bit guard words
+** Number of 32-bit guard words.  This should probably be a multiple of
+** 2 since on 64-bit machines we want the value returned by sqliteMalloc()
+** to be 8-byte aligned.
 */
-#define N_GUARD 1
+#define N_GUARD 2
 
 /*
 ** Allocate new memory and set it to zero.  Return NULL if
@@ -110,6 +112,13 @@ void *sqlite3Malloc_(int n, int bZero, char *zFile, int line){
   return p;
 }
 
+/*
+** This version of malloc is always a real function, never a macro
+*/
+void *sqlite3MallocX(int n){
+  return sqlite3Malloc_(n, 0, __FILE__, __LINE__);
+}
+
 /*
 ** Check to see if the given pointer was obtained from sqliteMalloc()
 ** and is able to hold at least N bytes.  Raise an exception if this
@@ -338,15 +347,15 @@ char *sqlite3StrNDup(const char *z, int n){
 ** point to that string.  The 1st argument must either be NULL or 
 ** point to memory obtained from sqliteMalloc().
 */
-void sqlite3SetString(char **pz, const char *zFirst, ...){
+void sqlite3SetString(char **pz, ...){
   va_list ap;
   int nByte;
   const char *z;
   char *zResult;
 
   if( pz==0 ) return;
-  nByte = strlen(zFirst) + 1;
-  va_start(ap, zFirst);
+  nByte = 1;
+  va_start(ap, pz);
   while( (z = va_arg(ap, const char*))!=0 ){
     nByte += strlen(z);
   }
@@ -356,9 +365,8 @@ void sqlite3SetString(char **pz, const char *zFirst, ...){
   if( zResult==0 ){
     return;
   }
-  strcpy(zResult, zFirst);
-  zResult += strlen(zResult);
-  va_start(ap, zFirst);
+  *zResult = 0;
+  va_start(ap, pz);
   while( (z = va_arg(ap, const char*))!=0 ){
     strcpy(zResult, z);
     zResult += strlen(zResult);
@@ -388,7 +396,7 @@ void sqlite3SetString(char **pz, const char *zFirst, ...){
 ** zFormat and any string tokens that follow it are assumed to be
 ** encoded in UTF-8.
 **
-** To clear the most recent error for slqite handle "db", sqlite3Error
+** To clear the most recent error for sqlite handle "db", sqlite3Error
 ** should be called with err_code set to SQLITE_OK and zFormat set
 ** to NULL.
 */
@@ -858,18 +866,6 @@ int sqlite3GetVarint32(const unsigned char *p, u32 *v){
   u32 x;
   int n;
   unsigned char c;
-#if 0
-  if( ((c = p[0]) & 0x80)==0 ){
-    *v = c;
-    return 1;
-  }
-  x = c & 0x7f;
-  if( ((c = p[1]) & 0x80)==0 ){
-    *v = (x<<7) | c;
-    return 2;
-  }
-  x = (x<<7) | (c & 0x7f);
-#else
   if( ((signed char*)p)[0]>=0 ){
     *v = p[0];
     return 1;
@@ -880,7 +876,6 @@ int sqlite3GetVarint32(const unsigned char *p, u32 *v){
     return 2;
   }
   x = (x<<7) | (p[1] & 0x7f);
-#endif
   n = 2;
   do{
     x = (x<<7) | ((c = p[n++])&0x7f);
@@ -902,7 +897,7 @@ int sqlite3VarintLen(u64 v){
   return i;
 }
 
-#if (!defined(SQLITE_OMIT_BLOB_LITERAL) && !defined(SQLITE_HAS_CODEC)) \
+#if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC) \
     || defined(SQLITE_TEST)
 /*
 ** Translate a single byte of Hex into an integer.
@@ -917,7 +912,7 @@ static int hexToInt(int h){
     return h - 'A' + 10;
   }
 }
-#endif /* (!SQLITE_OMIT_BLOB_LITERAL && !SQLITE_HAS_CODEC) || SQLITE_TEST */
+#endif /* !SQLITE_OMIT_BLOB_LITERAL || SQLITE_HAS_CODEC || SQLITE_TEST */
 
 #if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC)
 /*
index ed418b0ff6fe32a156d7650e218e9eae2fe2cec0..8254528d9d2fa563b54b2d7d0fe1d6cf909eff5b 100644 (file)
@@ -100,6 +100,11 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
   Btree *pMain;           /* The database being vacuumed */
   Btree *pTemp;
   char *zSql = 0;
+  int writeschema_flag;   /* Saved value of the write-schema flag */
+
+  /* Save the current value of the write-schema flag before setting it. */
+  writeschema_flag = db->flags&SQLITE_WriteSchema;
+  db->flags |= SQLITE_WriteSchema;
 
   if( !db->autoCommit ){
     sqlite3SetString(pzErrMsg, "cannot VACUUM from within a transaction", 
@@ -276,6 +281,10 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
   }
 
 end_of_vacuum:
+  /* Restore the original value of the write-schema flag. */
+  db->flags &= ~SQLITE_WriteSchema;
+  db->flags |= writeschema_flag;
+
   /* Currently there is an SQL level transaction open on the vacuum
   ** database. No locks are held on any other files (since the main file
   ** was committed at the btree level). So it safe to end the transaction
@@ -296,5 +305,6 @@ end_of_vacuum:
   if( zSql ) sqliteFree( zSql );
   sqlite3ResetInternalSchema(db, 0);
 #endif
+
   return rc;
 }
index 485788820cc6d9e0cd62c59e4b2132270d277d50..fe44eed405c0bff0728cb533ead0a7597bb76708 100644 (file)
@@ -303,6 +303,14 @@ static void applyAffinity(Mem *pRec, char affinity, u8 enc){
   }
 }
 
+/*
+** Exported version of applyAffinity(). This one works on sqlite3_value*, 
+** not the internal Mem* type.
+*/
+void sqlite3ValueApplyAffinity(sqlite3_value *pVal, u8 affinity, u8 enc){
+  applyAffinity((Mem *)pVal, affinity, enc);
+}
+
 #ifdef SQLITE_DEBUG
 /*
 ** Write a nice string representation of the contents of cell pMem
@@ -454,6 +462,9 @@ int sqlite3VdbeExec(
 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
   int nProgressOps = 0;      /* Opcodes executed since progress callback. */
 #endif
+#ifndef NDEBUG
+  Mem *pStackLimit;
+#endif
 
   if( p->magic!=VDBE_MAGIC_RUN ) return SQLITE_MISUSE;
   assert( db->magic==SQLITE_MAGIC_BUSY );
@@ -471,6 +482,7 @@ int sqlite3VdbeExec(
   for(pc=p->pc; rc==SQLITE_OK; pc++){
     assert( pc>=0 && pc<p->nOp );
     assert( pTos<=&p->aStack[pc] );
+    if( sqlite3_malloc_failed ) goto no_mem;
 #ifdef VDBE_PROFILE
     origPc = pc;
     start = hwtime();
@@ -524,6 +536,23 @@ int sqlite3VdbeExec(
     }
 #endif
 
+#ifndef NDEBUG
+    /* This is to check that the return value of static function
+    ** opcodeNoPush() (see vdbeaux.c) returns values that match the
+    ** implementation of the virtual machine in this file. If
+    ** opcodeNoPush() returns non-zero, then the stack is guarenteed
+    ** not to grow when the opcode is executed. If it returns zero, then
+    ** the stack may grow by at most 1.
+    **
+    ** The global wrapper function sqlite3VdbeOpcodeUsesStack() is not 
+    ** available if NDEBUG is defined at build time.
+    */ 
+    pStackLimit = pTos;
+    if( !sqlite3VdbeOpcodeNoPush(pOp->opcode) ){
+      pStackLimit++;
+    }
+#endif
+
     switch( pOp->opcode ){
 
 /*****************************************************************************
@@ -544,6 +573,11 @@ int sqlite3VdbeExec(
 ** case statement is followed by a comment of the form "/# same as ... #/"
 ** that comment is used to determine the particular value of the opcode.
 **
+** If a comment on the same line as the "case OP_" construction contains
+** the word "no-push", then the opcode is guarenteed not to grow the 
+** vdbe stack when it is executed. See function opcode() in
+** vdbeaux.c for details.
+**
 ** Documentation about VDBE opcodes is generated by scanning this file
 ** for lines of that contain "Opcode:".  That line and all subsequent
 ** comment lines are used in the generation of the opcode.html documentation
@@ -563,7 +597,7 @@ int sqlite3VdbeExec(
 ** the one at index P2 from the beginning of
 ** the program.
 */
-case OP_Goto: {
+case OP_Goto: {             /* no-push */
   CHECK_FOR_INTERRUPT;
   pc = pOp->p2 - 1;
   break;
@@ -579,7 +613,7 @@ case OP_Goto: {
 ** the return address stack will fill up and processing will abort
 ** with a fatal error.
 */
-case OP_Gosub: {
+case OP_Gosub: {            /* no-push */
   assert( p->returnDepth<sizeof(p->returnStack)/sizeof(p->returnStack[0]) );
   p->returnStack[p->returnDepth++] = pc+1;
   pc = pOp->p2 - 1;
@@ -592,7 +626,7 @@ case OP_Gosub: {
 ** OP_Gosub.  If an OP_Return has occurred for all OP_Gosubs, then
 ** processing aborts with a fatal error.
 */
-case OP_Return: {
+case OP_Return: {           /* no-push */
   assert( p->returnDepth>0 );
   p->returnDepth--;
   pc = p->returnStack[p->returnDepth] - 1;
@@ -616,7 +650,7 @@ case OP_Return: {
 ** every program.  So a jump past the last instruction of the program
 ** is the same as executing Halt.
 */
-case OP_Halt: {
+case OP_Halt: {            /* no-push */
   p->pTos = pTos;
   p->rc = pOp->p1;
   p->pc = pc;
@@ -662,7 +696,7 @@ case OP_Integer: {
 **
 ** The string value P3 is converted to a real and pushed on to the stack.
 */
-case OP_Real: {            /* same as TK_FLOAT */
+case OP_Real: {            /* same as TK_FLOAT, */
   pTos++;
   pTos->flags = MEM_Str|MEM_Static|MEM_Term;
   pTos->z = pOp->p3;
@@ -683,7 +717,8 @@ case OP_String8: {         /* same as TK_STRING */
 #ifndef SQLITE_OMIT_UTF16
   pOp->opcode = OP_String;
 
-  if( db->enc!=SQLITE_UTF8 && pOp->p3 ){
+  assert( pOp->p3!=0 );
+  if( db->enc!=SQLITE_UTF8 ){
     pTos++;
     sqlite3VdbeMemSetStr(pTos, pOp->p3, -1, SQLITE_UTF8, SQLITE_STATIC);
     if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pTos, db->enc) ) goto no_mem;
@@ -709,26 +744,34 @@ case OP_String8: {         /* same as TK_STRING */
 */
 case OP_String: {
   pTos++;
-  if( pOp->p3 ){
-    pTos->flags = MEM_Str|MEM_Static|MEM_Term;
-    pTos->z = pOp->p3;
+  assert( pOp->p3!=0 );
+  pTos->flags = MEM_Str|MEM_Static|MEM_Term;
+  pTos->z = pOp->p3;
 #ifndef SQLITE_OMIT_UTF16
-    if( db->enc==SQLITE_UTF8 ){
-      pTos->n = strlen(pTos->z);
-    }else{
-      pTos->n  = sqlite3utf16ByteLen(pTos->z, -1);
-    }
-#else
-    assert( db->enc==SQLITE_UTF8 );
+  if( db->enc==SQLITE_UTF8 ){
     pTos->n = strlen(pTos->z);
-#endif
-    pTos->enc = db->enc;
   }else{
-    pTos->flags = MEM_Null;
+    pTos->n  = sqlite3utf16ByteLen(pTos->z, -1);
   }
+#else
+  assert( db->enc==SQLITE_UTF8 );
+  pTos->n = strlen(pTos->z);
+#endif
+  pTos->enc = db->enc;
+  break;
+}
+
+/* Opcode: Null * * *
+**
+** Push a NULL onto the stack.
+*/
+case OP_Null: {
+  pTos++;
+  pTos->flags = MEM_Null;
   break;
 }
 
+
 #ifndef SQLITE_OMIT_BLOB_LITERAL
 /* Opcode: HexBlob * * P3
 **
@@ -798,7 +841,7 @@ case OP_Variable: {
 **
 ** P1 elements are popped off of the top of stack and discarded.
 */
-case OP_Pop: {
+case OP_Pop: {            /* no-push */
   assert( pOp->p1>=0 );
   popStack(&pTos, pOp->p1);
   assert( pTos>=&p->aStack[-1] );
@@ -841,7 +884,7 @@ case OP_Dup: {
 **
 ** See also the Dup instruction.
 */
-case OP_Pull: {
+case OP_Pull: {            /* no-push */
   Mem *pFrom = &pTos[-pOp->p1];
   int i;
   Mem ts;
@@ -873,7 +916,7 @@ case OP_Pull: {
 ** stack (P1==0 is the top of the stack) with the value
 ** of the top of the stack.  Then pop the top of the stack.
 */
-case OP_Push: {
+case OP_Push: {            /* no-push */
   Mem *pTo = &pTos[-pOp->p1];
 
   assert( pTo>=p->aStack );
@@ -888,7 +931,7 @@ case OP_Push: {
 ** invoke the callback function using the newly formed array as the
 ** 3rd parameter.
 */
-case OP_Callback: {
+case OP_Callback: {            /* no-push */
   int i;
   assert( p->nResColumn==pOp->p1 );
 
@@ -1024,11 +1067,11 @@ case OP_Concat: {           /* same as TK_CONCAT */
 ** function before the division.  Division by zero returns NULL.
 ** If either operand is NULL, the result is NULL.
 */
-case OP_Add:                   /* same as TK_PLUS */
-case OP_Subtract:              /* same as TK_MINUS */
-case OP_Multiply:              /* same as TK_STAR */
-case OP_Divide:                /* same as TK_SLASH */
-case OP_Remainder: {           /* same as TK_REM */
+case OP_Add:                   /* same as TK_PLUS, no-push */
+case OP_Subtract:              /* same as TK_MINUS, no-push */
+case OP_Multiply:              /* same as TK_STAR, no-push */
+case OP_Divide:                /* same as TK_SLASH, no-push */
+case OP_Remainder: {           /* same as TK_REM, no-push */
   Mem *pNos = &pTos[-1];
   assert( pNos>=p->aStack );
   if( ((pTos->flags | pNos->flags) & MEM_Null)!=0 ){
@@ -1108,7 +1151,7 @@ divide_by_zero:
 ** to retrieve the collation sequence set by this opcode is not available
 ** publicly, only to user functions defined in func.c.
 */
-case OP_CollSeq: {
+case OP_CollSeq: {             /* no-push */
   assert( pOp->p3type==P3_COLLSEQ );
   break;
 }
@@ -1226,10 +1269,10 @@ case OP_Function: {
 ** right by N bits where N is the top element on the stack.
 ** If either operand is NULL, the result is NULL.
 */
-case OP_BitAnd:                 /* same as TK_BITAND */
-case OP_BitOr:                  /* same as TK_BITOR */
-case OP_ShiftLeft:              /* same as TK_LSHIFT */
-case OP_ShiftRight: {           /* same as TK_RSHIFT */
+case OP_BitAnd:                 /* same as TK_BITAND, no-push */
+case OP_BitOr:                  /* same as TK_BITOR, no-push */
+case OP_ShiftLeft:              /* same as TK_LSHIFT, no-push */
+case OP_ShiftRight: {           /* same as TK_RSHIFT, no-push */
   Mem *pNos = &pTos[-1];
   int a, b;
 
@@ -1264,7 +1307,7 @@ case OP_ShiftRight: {           /* same as TK_RSHIFT */
 **
 ** To force the top of the stack to be an integer, just add 0.
 */
-case OP_AddImm: {
+case OP_AddImm: {            /* no-push */
   assert( pTos>=p->aStack );
   Integerify(pTos);
   pTos->i += pOp->p1;
@@ -1281,8 +1324,8 @@ case OP_AddImm: {
 ** current value if P1==0, or to the least integer that is strictly
 ** greater than its current value if P1==1.
 */
-case OP_ForceInt: {
-  int v;
+case OP_ForceInt: {            /* no-push */
+  i64 v;
   assert( pTos>=p->aStack );
   applyAffinity(pTos, SQLITE_AFF_INTEGER, db->enc);
   if( (pTos->flags & (MEM_Int|MEM_Real))==0 ){
@@ -1316,7 +1359,7 @@ case OP_ForceInt: {
 ** P1 is 1, then the stack is popped.  In all other cases, the depth
 ** of the stack is unchanged.
 */
-case OP_MustBeInt: {
+case OP_MustBeInt: {            /* no-push */
   assert( pTos>=p->aStack );
   applyAffinity(pTos, SQLITE_AFF_INTEGER, db->enc);
   if( (pTos->flags & MEM_Int)==0 ){
@@ -1339,11 +1382,11 @@ case OP_MustBeInt: {
 ** Pop the top two elements from the stack.  If they are equal, then
 ** jump to instruction P2.  Otherwise, continue to the next instruction.
 **
-** The least significant byte of P1 may be either 0x00 or 0x01. If either
-** operand is NULL (and thus if the result is unknown) then take the jump
-** only if the least significant byte of P1 is 0x01.
+** If the 0x100 bit of P1 is true and either operand is NULL then take the
+** jump.  If the 0x100 bit of P1 is false then fall thru if either operand
+** is NULL.
 **
-** The second least significant byte of P1 must be an affinity character -
+** The least significant byte of P1 (mask 0xff) must be an affinity character -
 ** 'n', 't', 'i' or 'o' - or 0x00. An attempt is made to coerce both values
 ** according to the affinity before the comparison is made. If the byte is
 ** 0x00, then numeric affinity is used.
@@ -1391,12 +1434,12 @@ case OP_MustBeInt: {
 ** the 2nd element down on the stack is greater than or equal to the
 ** top of the stack.  See the Eq opcode for additional information.
 */
-case OP_Eq:               /* same as TK_EQ */
-case OP_Ne:               /* same as TK_NE */
-case OP_Lt:               /* same as TK_LT */
-case OP_Le:               /* same as TK_LE */
-case OP_Gt:               /* same as TK_GT */
-case OP_Ge: {             /* same as TK_GE */
+case OP_Eq:               /* same as TK_EQ, no-push */
+case OP_Ne:               /* same as TK_NE, no-push */
+case OP_Lt:               /* same as TK_LT, no-push */
+case OP_Le:               /* same as TK_LE, no-push */
+case OP_Gt:               /* same as TK_GT, no-push */
+case OP_Ge: {             /* same as TK_GE, no-push */
   Mem *pNos;
   int flags;
   int res;
@@ -1412,7 +1455,7 @@ case OP_Ge: {             /* same as TK_GE */
   if( flags&MEM_Null ){
     popStack(&pTos, 2);
     if( pOp->p2 ){
-      if( (pOp->p1&0xFF) ) pc = pOp->p2-1;
+      if( pOp->p1 & 0x100 ) pc = pOp->p2-1;
     }else{
       pTos++;
       pTos->flags = MEM_Null;
@@ -1420,7 +1463,7 @@ case OP_Ge: {             /* same as TK_GE */
     break;
   }
 
-  affinity = (pOp->p1>>8)&0xFF;
+  affinity = pOp->p1 & 0xFF;
   if( affinity ){
     applyAffinity(pNos, affinity, db->enc);
     applyAffinity(pTos, affinity, db->enc);
@@ -1462,8 +1505,8 @@ case OP_Ge: {             /* same as TK_GE */
 ** two values and push the resulting boolean value back onto the
 ** stack. 
 */
-case OP_And:              /* same as TK_AND */
-case OP_Or: {             /* same as TK_OR */
+case OP_And:              /* same as TK_AND, no-push */
+case OP_Or: {             /* same as TK_OR, no-push */
   Mem *pNos = &pTos[-1];
   int v1, v2;    /* 0==TRUE, 1==FALSE, 2==UNKNOWN or NULL */
 
@@ -1510,7 +1553,7 @@ case OP_Or: {             /* same as TK_OR */
 ** with its absolute value. If the top of the stack is NULL
 ** its value is unchanged.
 */
-case OP_Negative:              /* same as TK_UMINUS */
+case OP_Negative:              /* same as TK_UMINUS, no-push */
 case OP_AbsValue: {
   assert( pTos>=p->aStack );
   if( pTos->flags & MEM_Real ){
@@ -1543,7 +1586,7 @@ case OP_AbsValue: {
 ** with its complement.  If the top of the stack is NULL its value
 ** is unchanged.
 */
-case OP_Not: {                /* same as TK_NOT */
+case OP_Not: {                /* same as TK_NOT, no-push */
   assert( pTos>=p->aStack );
   if( pTos->flags & MEM_Null ) break;  /* Do nothing to NULLs */
   Integerify(pTos);
@@ -1559,7 +1602,7 @@ case OP_Not: {                /* same as TK_NOT */
 ** with its ones-complement.  If the top of the stack is NULL its
 ** value is unchanged.
 */
-case OP_BitNot: {             /* same as TK_BITNOT */
+case OP_BitNot: {             /* same as TK_BITNOT, no-push */
   assert( pTos>=p->aStack );
   if( pTos->flags & MEM_Null ) break;  /* Do nothing to NULLs */
   Integerify(pTos);
@@ -1574,7 +1617,7 @@ case OP_BitNot: {             /* same as TK_BITNOT */
 ** Do nothing.  This instruction is often useful as a jump
 ** destination.
 */
-case OP_Noop: {
+case OP_Noop: {            /* no-push */
   break;
 }
 
@@ -1598,14 +1641,18 @@ case OP_Noop: {
 ** If the value popped of the stack is NULL, then take the jump if P1
 ** is true and fall through if P1 is false.
 */
-case OP_If:
-case OP_IfNot: {
+case OP_If:                 /* no-push */
+case OP_IfNot: {            /* no-push */
   int c;
   assert( pTos>=p->aStack );
   if( pTos->flags & MEM_Null ){
     c = pOp->p1;
   }else{
+#ifdef SQLITE_OMIT_FLOATING_POINT
     c = sqlite3VdbeIntValue(pTos);
+#else
+    c = sqlite3VdbeRealValue(pTos)!=0.0;
+#endif
     if( pOp->opcode==OP_IfNot ) c = !c;
   }
   Release(pTos);
@@ -1620,7 +1667,7 @@ case OP_IfNot: {
 ** to P2.  Pop the stack P1 times if P1>0.   If P1<0 leave the stack
 ** unchanged.
 */
-case OP_IsNull: {            /* same as TK_ISNULL */
+case OP_IsNull: {            /* same as TK_ISNULL, no-push */
   int i, cnt;
   Mem *pTerm;
   cnt = pOp->p1;
@@ -1643,7 +1690,7 @@ case OP_IsNull: {            /* same as TK_ISNULL */
 ** stack if P1 times if P1 is greater than zero.  If P1 is less than
 ** zero then leave the stack unchanged.
 */
-case OP_NotNull: {            /* same as TK_NOTNULL */
+case OP_NotNull: {            /* same as TK_NOTNULL, no-push */
   int i, cnt;
   cnt = pOp->p1;
   if( cnt<0 ) cnt = -cnt;
@@ -1664,20 +1711,16 @@ case OP_NotNull: {            /* same as TK_NOTNULL */
 ** If OP_KeyAsData is to be applied to cursor P1, it must be executed
 ** before this op-code.
 */
-case OP_SetNumColumns: {
+case OP_SetNumColumns: {       /* no-push */
   Cursor *pC;
   assert( (pOp->p1)<p->nCursor );
   assert( p->apCsr[pOp->p1]!=0 );
   pC = p->apCsr[pOp->p1];
   pC->nField = pOp->p2;
-  if( (!pC->keyAsData && pC->zeroData) || (pC->keyAsData && pC->intKey) ){
-    rc = SQLITE_CORRUPT;
-    goto abort_due_to_error;
-  }
   break;
 }
 
-/* Opcode: Column P1 P2 *
+/* Opcode: Column P1 P2 P3
 **
 ** Interpret the data that cursor P1 points to as a structure built using
 ** the MakeRecord instruction.  (See the MakeRecord opcode for additional
@@ -1757,7 +1800,7 @@ case OP_Column: {
     }else if( pC->cacheValid ){
       payloadSize = pC->payloadSize;
       zRec = pC->aRow;
-    }else if( pC->keyAsData ){
+    }else if( pC->isIndex ){
       i64 payloadSize64;
       sqlite3BtreeKeySize(pCrsr, &payloadSize64);
       payloadSize = payloadSize64;
@@ -1812,7 +1855,7 @@ case OP_Column: {
     if( zRec ){
       zData = zRec;
     }else{
-      if( pC->keyAsData ){
+      if( pC->isIndex ){
         zData = (char*)sqlite3BtreeKeyFetch(pCrsr, &avail);
       }else{
         zData = (char*)sqlite3BtreeDataFetch(pCrsr, &avail);
@@ -1838,7 +1881,7 @@ case OP_Column: {
     ** acquire the complete header text.
     */
     if( !zRec && avail<szHdr ){
-      rc = sqlite3VdbeMemFromBtree(pCrsr, 0, szHdr, pC->keyAsData, &sMem);
+      rc = sqlite3VdbeMemFromBtree(pCrsr, 0, szHdr, pC->isIndex, &sMem);
       if( rc!=SQLITE_OK ){
         goto op_column_out;
       }
@@ -1902,7 +1945,7 @@ case OP_Column: {
       zData = &zRec[aOffset[p2]];
     }else{
       len = sqlite3VdbeSerialTypeLen(aType[p2]);
-      rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len,pC->keyAsData,&sMem);
+      rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, pC->isIndex,&sMem);
       if( rc!=SQLITE_OK ){
         goto op_column_out;
       }
@@ -1911,7 +1954,11 @@ case OP_Column: {
     sqlite3VdbeSerialGet(zData, aType[p2], pTos);
     pTos->enc = db->enc;
   }else{
-    pTos->flags = MEM_Null;
+    if( pOp->p3 ){
+      sqlite3VdbeMemShallowCopy(pTos, (Mem *)(pOp->p3), MEM_Static);
+    }else{
+      pTos->flags = MEM_Null;
+    }
   }
 
   /* If we dynamically allocated space to hold the data (in the
@@ -1996,6 +2043,7 @@ case OP_MakeRecord: {
   int nData = 0;         /* Number of bytes of data space */
   int nHdr = 0;          /* Number of bytes of header space */
   int nByte = 0;         /* Space required for this record */
+  int nVarint;           /* Number of bytes in a varint */
   u32 serial_type;       /* Type field */
   int containsNull = 0;  /* True if any of the data fields are NULL */
   char zTemp[NBFS];      /* Space to hold small records */
@@ -2046,7 +2094,10 @@ case OP_MakeRecord: {
   }
 
   /* Add the initial header varint and total the size */
-  nHdr += sqlite3VarintLen(nHdr);
+  nHdr += nVarint = sqlite3VarintLen(nHdr);
+  if( nVarint<sqlite3VarintLen(nHdr) ){
+    nHdr++;
+  }
   nByte = nHdr+nData;
 
   /* Allocate space for the new record. */
@@ -2114,7 +2165,7 @@ case OP_MakeRecord: {
 ** database file has an index of 0 and the file used for temporary tables
 ** has an index of 1.
 */
-case OP_Statement: {
+case OP_Statement: {       /* no-push */
   int i = pOp->p1;
   Btree *pBt;
   if( i>=0 && i<db->nDb && (pBt = db->aDb[i].pBt) && !(db->autoCommit) ){
@@ -2134,7 +2185,7 @@ case OP_Statement: {
 **
 ** This instruction causes the VM to halt.
 */
-case OP_AutoCommit: {
+case OP_AutoCommit: {       /* no-push */
   u8 i = pOp->p1;
   u8 rollback = pOp->p2;
 
@@ -2195,7 +2246,7 @@ case OP_AutoCommit: {
 **
 ** If P2 is zero, then a read-lock is obtained on the database file.
 */
-case OP_Transaction: {
+case OP_Transaction: {       /* no-push */
   int i = pOp->p1;
   Btree *pBt;
 
@@ -2258,7 +2309,7 @@ case OP_ReadCookie: {
 **
 ** A transaction must be started before executing this opcode.
 */
-case OP_SetCookie: {
+case OP_SetCookie: {       /* no-push */
   Db *pDb;
   assert( pOp->p2<SQLITE_N_BTREE_META );
   assert( pOp->p1>=0 && pOp->p1<db->nDb );
@@ -2294,7 +2345,7 @@ case OP_SetCookie: {
 ** to be executed (to establish a read lock) before this opcode is
 ** invoked.
 */
-case OP_VerifyCookie: {
+case OP_VerifyCookie: {       /* no-push */
   int iMeta;
   Btree *pBt;
   assert( pOp->p1>=0 && pOp->p1<db->nDb );
@@ -2354,8 +2405,8 @@ case OP_VerifyCookie: {
 **
 ** See also OpenRead.
 */
-case OP_OpenRead:
-case OP_OpenWrite: {
+case OP_OpenRead:          /* no-push */
+case OP_OpenWrite: {       /* no-push */
   int i = pOp->p1;
   int p2 = pOp->p2;
   int wrFlag;
@@ -2394,11 +2445,12 @@ case OP_OpenWrite: {
   rc = sqlite3BtreeCursor(pX, p2, wrFlag,
            sqlite3VdbeRecordCompare, pOp->p3,
            &pCur->pCursor);
-  pCur->pKeyInfo = (KeyInfo*)pOp->p3;
-  if( pCur->pKeyInfo ){
+  if( pOp->p3type==P3_KEYINFO ){
+    pCur->pKeyInfo = (KeyInfo*)pOp->p3;
     pCur->pIncrKey = &pCur->pKeyInfo->incrKey;
     pCur->pKeyInfo->enc = p->db->enc;
   }else{
+    pCur->pKeyInfo = 0;
     pCur->pIncrKey = &pCur->bogusIncrKey;
   }
   switch( rc ){
@@ -2410,11 +2462,32 @@ case OP_OpenWrite: {
     }
     case SQLITE_OK: {
       int flags = sqlite3BtreeFlags(pCur->pCursor);
-      pCur->intKey = (flags & BTREE_INTKEY)!=0;
-      pCur->zeroData = (flags & BTREE_ZERODATA)!=0;
+      /* Sanity checking.  Only the lower four bits of the flags byte should
+      ** be used.  Bit 3 (mask 0x08) is unpreditable.  The lower 3 bits
+      ** (mask 0x07) should be either 5 (intkey+leafdata for tables) or
+      ** 2 (zerodata for indices).  If these conditions are not met it can
+      ** only mean that we are dealing with a corrupt database file
+      */
+      if( (flags & 0xf0)!=0 || ((flags & 0x07)!=5 && (flags & 0x07)!=2) ){
+        rc = SQLITE_CORRUPT;
+        goto abort_due_to_error;
+      }
+      pCur->isTable = (flags & BTREE_INTKEY)!=0;
+      pCur->isIndex = (flags & BTREE_ZERODATA)!=0;
+      /* If P3==0 it means we are expected to open a table.  If P3!=0 then
+      ** we expect to be opening an index.  If this is not what happened,
+      ** then the database is corrupt
+      */
+      if( (pCur->isTable && pOp->p3type==P3_KEYINFO)
+       || (pCur->isIndex && pOp->p3type!=P3_KEYINFO) ){
+        rc = SQLITE_CORRUPT;
+        goto abort_due_to_error;
+      }
       break;
     }
     case SQLITE_EMPTY: {
+      pCur->isTable = pOp->p3type!=P3_KEYINFO;
+      pCur->isIndex = !pCur->isTable;
       rc = SQLITE_OK;
       break;
     }
@@ -2443,7 +2516,7 @@ case OP_OpenWrite: {
 ** whereas "Temporary" in the context of CREATE TABLE means for the duration
 ** of the connection to the database.  Same word; different meanings.
 */
-case OP_OpenTemp: {
+case OP_OpenTemp: {       /* no-push */
   int i = pOp->p1;
   Cursor *pCx;
   assert( i>=0 );
@@ -2472,12 +2545,14 @@ case OP_OpenTemp: {
         pCx->pKeyInfo->enc = p->db->enc;
         pCx->pIncrKey = &pCx->pKeyInfo->incrKey;
       }
+      pCx->isTable = 0;
     }else{
       rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, 1, 0, 0, &pCx->pCursor);
-      pCx->intKey = 1;
+      pCx->isTable = 1;
       pCx->pIncrKey = &pCx->bogusIncrKey;
     }
   }
+  pCx->isIndex = !pCx->isTable;
   break;
 }
 
@@ -2492,7 +2567,7 @@ case OP_OpenTemp: {
 ** A pseudo-table created by this opcode is useful for holding the
 ** NEW or OLD tables in a trigger.
 */
-case OP_OpenPseudo: {
+case OP_OpenPseudo: {       /* no-push */
   int i = pOp->p1;
   Cursor *pCx;
   assert( i>=0 );
@@ -2501,6 +2576,8 @@ case OP_OpenPseudo: {
   pCx->nullRow = 1;
   pCx->pseudoTable = 1;
   pCx->pIncrKey = &pCx->bogusIncrKey;
+  pCx->isTable = 1;
+  pCx->isIndex = 0;
   break;
 }
 #endif
@@ -2510,7 +2587,7 @@ case OP_OpenPseudo: {
 ** Close a cursor previously opened as P1.  If P1 is not
 ** currently open, this instruction is a no-op.
 */
-case OP_Close: {
+case OP_Close: {       /* no-push */
   int i = pOp->p1;
   if( i>=0 && i<p->nCursor ){
     sqlite3VdbeFreeCursor(p->apCsr[i]);
@@ -2559,10 +2636,10 @@ case OP_Close: {
 **
 ** See also: Found, NotFound, Distinct, MoveGt, MoveGe, MoveLt
 */
-case OP_MoveLt:
-case OP_MoveLe:
-case OP_MoveGe:
-case OP_MoveGt: {
+case OP_MoveLt:         /* no-push */
+case OP_MoveLe:         /* no-push */
+case OP_MoveGe:         /* no-push */
+case OP_MoveGt: {       /* no-push */
   int i = pOp->p1;
   Cursor *pC;
 
@@ -2575,7 +2652,7 @@ case OP_MoveGt: {
     oc = pOp->opcode;
     pC->nullRow = 0;
     *pC->pIncrKey = oc==OP_MoveGt || oc==OP_MoveLe;
-    if( pC->intKey ){
+    if( pC->isTable ){
       i64 iKey;
       Integerify(pTos);
       iKey = intToKey(pTos->i);
@@ -2590,15 +2667,15 @@ case OP_MoveGt: {
       if( rc!=SQLITE_OK ){
         goto abort_due_to_error;
       }
-      pC->lastRecno = pTos->i;
-      pC->recnoIsValid = res==0;
+      pC->lastRowid = pTos->i;
+      pC->rowidIsValid = res==0;
     }else{
       Stringify(pTos, db->enc);
       rc = sqlite3BtreeMoveto(pC->pCursor, pTos->z, pTos->n, &res);
       if( rc!=SQLITE_OK ){
         goto abort_due_to_error;
       }
-      pC->recnoIsValid = 0;
+      pC->rowidIsValid = 0;
     }
     pC->deferredMoveto = 0;
     pC->cacheValid = 0;
@@ -2608,7 +2685,7 @@ case OP_MoveGt: {
       if( res<0 ){
         rc = sqlite3BtreeNext(pC->pCursor, &res);
         if( rc!=SQLITE_OK ) goto abort_due_to_error;
-        pC->recnoIsValid = 0;
+        pC->rowidIsValid = 0;
       }else{
         res = 0;
       }
@@ -2617,7 +2694,7 @@ case OP_MoveGt: {
       if( res>=0 ){
         rc = sqlite3BtreePrevious(pC->pCursor, &res);
         if( rc!=SQLITE_OK ) goto abort_due_to_error;
-        pC->recnoIsValid = 0;
+        pC->rowidIsValid = 0;
       }else{
         /* res might be negative because the table is empty.  Check to
         ** see if this is the case.
@@ -2640,40 +2717,55 @@ case OP_MoveGt: {
 
 /* Opcode: Distinct P1 P2 *
 **
-** Use the top of the stack as a string key.  If a record with that key does
-** not exist in the table of cursor P1, then jump to P2.  If the record
-** does already exist, then fall thru.  The cursor is left pointing
-** at the record if it exists. The key is not popped from the stack.
+** Use the top of the stack as a record created using MakeRecord.  P1 is a
+** cursor on a table that declared as an index.  If that table contains an
+** entry that matches the top of the stack fall thru.  If the top of the stack
+** matches no entry in P1 then jump to P2.
+**
+** The cursor is left pointing at the matching entry if it exists.  The
+** record on the top of the stack is not popped.
 **
-** This operation is similar to NotFound except that this operation
+** This instruction is similar to NotFound except that this operation
 ** does not pop the key from the stack.
 **
+** The instruction is used to implement the DISTINCT operator on SELECT
+** statements.  The P1 table is not a true index but rather a record of
+** all results that have produced so far.  
+**
 ** See also: Found, NotFound, MoveTo, IsUnique, NotExists
 */
 /* Opcode: Found P1 P2 *
 **
-** Use the top of the stack as a string key.  If a record with that key
-** does exist in table of P1, then jump to P2.  If the record
-** does not exist, then fall thru.  The cursor is left pointing
-** to the record if it exists.  The key is popped from the stack.
+** Top of the stack holds a blob constructed by MakeRecord.  P1 is an index.
+** If an entry that matches the top of the stack exists in P1 then
+** jump to P2.  If the top of the stack does not match any entry in P1
+** then fall thru.  The P1 cursor is left pointing at the matching entry
+** if it exists.  The blob is popped off the top of the stack.
+**
+** This instruction is used to implement the IN operator where the
+** left-hand side is a SELECT statement.  P1 is not a true index but
+** is instead a temporary index that holds the results of the SELECT
+** statement.  This instruction just checks to see if the left-hand side
+** of the IN operator (stored on the top of the stack) exists in the
+** result of the SELECT statement.
 **
 ** See also: Distinct, NotFound, MoveTo, IsUnique, NotExists
 */
 /* Opcode: NotFound P1 P2 *
 **
-** Use the top of the stack as a string key.  If a record with that key
-** does not exist in table of P1, then jump to P2.  If the record
-** does exist, then fall thru.  The cursor is left pointing to the
-** record if it exists.  The key is popped from the stack.
+** The top of the stack holds a blob constructed by MakeRecord.  P1 is
+** an index.  If no entry exists in P1 that matches the blob then jump
+** to P1.  If an entry does existing, fall through.  The cursor is left
+** pointing to the entry that matches.  The blob is popped from the stack.
 **
 ** The difference between this operation and Distinct is that
 ** Distinct does not pop the key from the stack.
 **
 ** See also: Distinct, Found, MoveTo, NotExists, IsUnique
 */
-case OP_Distinct:
-case OP_NotFound:
-case OP_Found: {
+case OP_Distinct:       /* no-push */
+case OP_NotFound:       /* no-push */
+case OP_Found: {        /* no-push */
   int i = pOp->p1;
   int alreadyExists = 0;
   Cursor *pC;
@@ -2682,7 +2774,7 @@ case OP_Found: {
   assert( p->apCsr[i]!=0 );
   if( (pC = p->apCsr[i])->pCursor!=0 ){
     int res, rx;
-    assert( pC->intKey==0 );
+    assert( pC->isTable==0 );
     Stringify(pTos, db->enc);
     rx = sqlite3BtreeMoveto(pC->pCursor, pTos->z, pTos->n, &res);
     alreadyExists = rx==SQLITE_OK && res==0;
@@ -2709,8 +2801,8 @@ case OP_Found: {
 ** stack but it leaves K unchanged.
 **
 ** P1 is an index.  So it has no data and its key consists of a
-** record generated by OP_MakeIdxKey.  This key contains one or more
-** fields followed by a ROWID field.
+** record generated by OP_MakeRecord where the last field is the 
+** rowid of the entry that the index refers to.
 ** 
 ** This instruction asks if there is an entry in P1 where the
 ** fields matches K but the rowid is different from R.
@@ -2722,7 +2814,7 @@ case OP_Found: {
 **
 ** See also: Distinct, NotFound, NotExists, Found
 */
-case OP_IsUnique: {
+case OP_IsUnique: {        /* no-push */
   int i = pOp->p1;
   Mem *pNos = &pTos[-1];
   Cursor *pCx;
@@ -2811,12 +2903,13 @@ case OP_IsUnique: {
 ** record if it exists.  The integer key is popped from the stack.
 **
 ** The difference between this operation and NotFound is that this
-** operation assumes the key is an integer and NotFound assumes it
-** is a string.
+** operation assumes the key is an integer and that P1 is a table whereas
+** NotFound assumes key is a blob constructed from MakeRecord and
+** P1 is an index.
 **
 ** See also: Distinct, Found, MoveTo, NotFound, IsUnique
 */
-case OP_NotExists: {
+case OP_NotExists: {        /* no-push */
   int i = pOp->p1;
   Cursor *pC;
   BtCursor *pCrsr;
@@ -2827,16 +2920,16 @@ case OP_NotExists: {
     int res;
     u64 iKey;
     assert( pTos->flags & MEM_Int );
-    assert( p->apCsr[i]->intKey );
+    assert( p->apCsr[i]->isTable );
     iKey = intToKey(pTos->i);
     rc = sqlite3BtreeMoveto(pCrsr, 0, iKey, &res);
-    pC->lastRecno = pTos->i;
-    pC->recnoIsValid = res==0;
+    pC->lastRowid = pTos->i;
+    pC->rowidIsValid = res==0;
     pC->nullRow = 0;
     pC->cacheValid = 0;
     if( res!=0 ){
       pc = pOp->p2 - 1;
-      pC->recnoIsValid = 0;
+      pC->rowidIsValid = 0;
     }
   }
   Release(pTos);
@@ -2844,9 +2937,9 @@ case OP_NotExists: {
   break;
 }
 
-/* Opcode: NewRecno P1 P2 *
+/* Opcode: NewRowid P1 P2 *
 **
-** Get a new integer record number used as the key to a table.
+** Get a new integer record number (a.k.a "rowid") used as the key to a table.
 ** The record number is not previously used as a key in the database
 ** table that cursor P1 points to.  The new record number is pushed 
 ** onto the stack.
@@ -2858,7 +2951,7 @@ case OP_NotExists: {
 ** record number.  This P2 mechanism is used to help implement the
 ** AUTOINCREMENT feature.
 */
-case OP_NewRecno: {
+case OP_NewRowid: {
   int i = pOp->p1;
   i64 v = 0;
   Cursor *pC;
@@ -2986,7 +3079,7 @@ case OP_NewRecno: {
         goto abort_due_to_error;
       }
     }
-    pC->recnoIsValid = 0;
+    pC->rowidIsValid = 0;
     pC->deferredMoveto = 0;
     pC->cacheValid = 0;
   }
@@ -2996,7 +3089,7 @@ case OP_NewRecno: {
   break;
 }
 
-/* Opcode: PutIntKey P1 P2 *
+/* Opcode: Insert P1 P2 *
 **
 ** Write an entry into the table of cursor P1.  A new entry is
 ** created if it doesn't already exist or the data for an existing
@@ -3008,19 +3101,11 @@ case OP_NewRecno: {
 ** incremented (otherwise not).  If the OPFLAG_LASTROWID flag of P2 is set,
 ** then rowid is stored for subsequent return by the
 ** sqlite3_last_insert_rowid() function (otherwise it's unmodified).
-*/
-/* Opcode: PutStrKey P1 * *
 **
-** Write an entry into the table of cursor P1.  A new entry is
-** created if it doesn't already exist or the data for an existing
-** entry is overwritten.  The data is the value on the top of the
-** stack.  The key is the next value down on the stack.  The key must
-** be a string.  The stack is popped twice by this instruction.
-**
-** P1 may not be a pseudo-table opened using the OpenPseudo opcode.
+** This instruction only works on tables.  The equivalent instruction
+** for indices is OP_IdxInsert.
 */
-case OP_PutIntKey:
-case OP_PutStrKey: {
+case OP_Insert: {         /* no-push */
   Mem *pNos = &pTos[-1];
   int i = pOp->p1;
   Cursor *pC;
@@ -3028,35 +3113,16 @@ case OP_PutStrKey: {
   assert( i>=0 && i<p->nCursor );
   assert( p->apCsr[i]!=0 );
   if( ((pC = p->apCsr[i])->pCursor!=0 || pC->pseudoTable) ){
-    char *zKey;
-    i64 nKey; 
-    i64 iKey;
-    if( pOp->opcode==OP_PutStrKey ){
-      Stringify(pNos, db->enc);
-      nKey = pNos->n;
-      zKey = pNos->z;
-    }else{
-      assert( pNos->flags & MEM_Int );
+    i64 iKey;   /* The integer ROWID or key for the record to be inserted */
 
-      /* If the table is an INTKEY table, set nKey to the value of
-      ** the integer key, and zKey to NULL. Otherwise, set nKey to
-      ** sizeof(i64) and point zKey at iKey. iKey contains the integer
-      ** key in the on-disk byte order.
-      */
-      iKey = intToKey(pNos->i);
-      if( pC->intKey ){
-        nKey = intToKey(pNos->i);
-        zKey = 0;
-      }else{
-        nKey = sizeof(i64);
-        zKey = (char*)&iKey;
-      }
+    assert( pNos->flags & MEM_Int );
+    assert( pC->isTable );
+    iKey = intToKey(pNos->i);
 
-      if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
-      if( pOp->p2 & OPFLAG_LASTROWID ) db->lastRowid = pNos->i;
-      if( pC->nextRowidValid && pTos->i>=pC->nextRowid ){
-        pC->nextRowidValid = 0;
-      }
+    if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;
+    if( pOp->p2 & OPFLAG_LASTROWID ) db->lastRowid = pNos->i;
+    if( pC->nextRowidValid && pTos->i>=pC->nextRowid ){
+      pC->nextRowidValid = 0;
     }
     if( pTos->flags & MEM_Null ){
       pTos->z = 0;
@@ -3066,11 +3132,6 @@ case OP_PutStrKey: {
     }
 #ifndef SQLITE_OMIT_TRIGGER
     if( pC->pseudoTable ){
-      /* PutStrKey does not work for pseudo-tables.
-      ** The following assert makes sure we are not trying to use
-      ** PutStrKey on a pseudo-table
-      */
-      assert( pOp->opcode==OP_PutIntKey );
       sqliteFree(pC->pData);
       pC->iKey = iKey;
       pC->nData = pTos->n;
@@ -3087,12 +3148,12 @@ case OP_PutStrKey: {
       pC->nullRow = 0;
     }else{
 #endif
-      rc = sqlite3BtreeInsert(pC->pCursor, zKey, nKey, pTos->z, pTos->n);
+      rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey, pTos->z, pTos->n);
 #ifndef SQLITE_OMIT_TRIGGER
     }
 #endif
     
-    pC->recnoIsValid = 0;
+    pC->rowidIsValid = 0;
     pC->deferredMoveto = 0;
     pC->cacheValid = 0;
   }
@@ -3114,7 +3175,7 @@ case OP_PutStrKey: {
 **
 ** If P1 is a pseudo-table, then this instruction is a no-op.
 */
-case OP_Delete: {
+case OP_Delete: {        /* no-push */
   int i = pOp->p1;
   Cursor *pC;
   assert( i>=0 && i<p->nCursor );
@@ -3138,7 +3199,7 @@ case OP_Delete: {
 ** change counter (returned by subsequent calls to sqlite3_changes())
 ** before it is reset. This is used by trigger programs.
 */
-case OP_ResetCount: {
+case OP_ResetCount: {        /* no-push */
   if( pOp->p1 ){
     sqlite3VdbeSetChanges(db, p->nChange);
   }
@@ -3146,23 +3207,6 @@ case OP_ResetCount: {
   break;
 }
 
-/* Opcode: KeyAsData P1 P2 *
-**
-** Turn the key-as-data mode for cursor P1 either on (if P2==1) or
-** off (if P2==0).  In key-as-data mode, the OP_Column opcode pulls
-** data off of the key rather than the data.  This is used for
-** processing compound selects.
-*/
-case OP_KeyAsData: {
-  int i = pOp->p1;
-  Cursor *pC;
-  assert( i>=0 && i<p->nCursor );
-  pC = p->apCsr[i];
-  assert( pC!=0 );
-  pC->keyAsData = pOp->p2;
-  break;
-}
-
 /* Opcode: RowData P1 * *
 **
 ** Push onto the stack the complete row data for cursor P1.
@@ -3187,9 +3231,12 @@ case OP_RowData: {
   Cursor *pC;
   u32 n;
 
+  /* Note that RowKey and RowData are really exactly the same instruction */
   pTos++;
   assert( i>=0 && i<p->nCursor );
   pC = p->apCsr[i];
+  assert( pC->isTable || pOp->opcode==OP_RowKey );
+  assert( pC->isIndex || pOp->opcode==OP_RowData );
   assert( pC!=0 );
   if( pC->nullRow ){
     pTos->flags = MEM_Null;
@@ -3200,9 +3247,9 @@ case OP_RowData: {
     if( pC->nullRow ){
       pTos->flags = MEM_Null;
       break;
-    }else if( pC->keyAsData || pOp->opcode==OP_RowKey ){
+    }else if( pC->isIndex ){
       i64 n64;
-      assert( !pC->intKey );
+      assert( !pC->isTable );
       sqlite3BtreeKeySize(pCrsr, &n64);
       n = n64;
     }else{
@@ -3219,7 +3266,7 @@ case OP_RowData: {
       pTos->xDel = 0;
       pTos->z = z;
     }
-    if( pC->keyAsData || pOp->opcode==OP_RowKey ){
+    if( pC->isIndex ){
       sqlite3BtreeKey(pCrsr, 0, n, pTos->z);
     }else{
       sqlite3BtreeData(pCrsr, 0, n, pTos->z);
@@ -3236,14 +3283,12 @@ case OP_RowData: {
   break;
 }
 
-/* Opcode: Recno P1 * *
+/* Opcode: Rowid P1 * *
 **
-** Push onto the stack an integer which is the first 4 bytes of the
-** the key to the current entry in a sequential scan of the database
-** file P1.  The sequential scan should have been started using the 
-** Next opcode.
+** Push onto the stack an integer which is the key of the table entry that
+** P1 is currently point to.
 */
-case OP_Recno: {
+case OP_Rowid: {
   int i = pOp->p1;
   Cursor *pC;
   i64 v;
@@ -3254,8 +3299,8 @@ case OP_Recno: {
   rc = sqlite3VdbeCursorMoveto(pC);
   if( rc ) goto abort_due_to_error;
   pTos++;
-  if( pC->recnoIsValid ){
-    v = pC->lastRecno;
+  if( pC->rowidIsValid ){
+    v = pC->lastRowid;
   }else if( pC->pseudoTable ){
     v = keyToInt(pC->iKey);
   }else if( pC->nullRow || pC->pCursor==0 ){
@@ -3271,65 +3316,13 @@ case OP_Recno: {
   break;
 }
 
-#ifndef SQLITE_OMIT_COMPOUND_SELECT
-/* Opcode: FullKey P1 * *
-**
-** Extract the complete key from the record that cursor P1 is currently
-** pointing to and push the key onto the stack as a string.
-**
-** Compare this opcode to Recno.  The Recno opcode extracts the first
-** 4 bytes of the key and pushes those bytes onto the stack as an
-** integer.  This instruction pushes the entire key as a string.
-**
-** This opcode may not be used on a pseudo-table.
-*/
-case OP_FullKey: {
-  int i = pOp->p1;
-  BtCursor *pCrsr;
-  Cursor *pC;
-
-  assert( i>=0 && i<p->nCursor );
-  assert( p->apCsr[i]!=0 );
-  assert( p->apCsr[i]->keyAsData );
-  assert( !p->apCsr[i]->pseudoTable );
-  pTos++;
-  pTos->flags = MEM_Null;
-  if( (pCrsr = (pC = p->apCsr[i])->pCursor)!=0 ){
-    i64 amt;
-    char *z;
-
-    rc = sqlite3VdbeCursorMoveto(pC);
-    if( rc ) goto abort_due_to_error;
-    assert( pC->intKey==0 );
-    sqlite3BtreeKeySize(pCrsr, &amt);
-    if( amt<=0 ){
-      rc = SQLITE_CORRUPT;
-      goto abort_due_to_error;
-    }
-    if( amt>NBFS ){
-      z = sqliteMallocRaw( amt );
-      if( z==0 ) goto no_mem;
-      pTos->flags = MEM_Blob | MEM_Dyn;
-      pTos->xDel = 0;
-    }else{
-      z = pTos->zShort;
-      pTos->flags = MEM_Blob | MEM_Short;
-    }
-    sqlite3BtreeKey(pCrsr, 0, amt, z);
-    pTos->z = z;
-    pTos->n = amt;
-  }
-  break;
-}
-#endif
-
 /* Opcode: NullRow P1 * *
 **
 ** Move the cursor P1 to a null row.  Any OP_Column operations
 ** that occur while the cursor is on the null row will always push 
 ** a NULL onto the stack.
 */
-case OP_NullRow: {
+case OP_NullRow: {        /* no-push */
   int i = pOp->p1;
   Cursor *pC;
 
@@ -3337,19 +3330,19 @@ case OP_NullRow: {
   pC = p->apCsr[i];
   assert( pC!=0 );
   pC->nullRow = 1;
-  pC->recnoIsValid = 0;
+  pC->rowidIsValid = 0;
   break;
 }
 
 /* Opcode: Last P1 P2 *
 **
-** The next use of the Recno or Column or Next instruction for P1 
+** The next use of the Rowid or Column or Next instruction for P1 
 ** will refer to the last entry in the database table or index.
 ** If the table or index is empty and P2>0, then jump immediately to P2.
 ** If P2 is 0 or if the table or index is not empty, fall through
 ** to the following instruction.
 */
-case OP_Last: {
+case OP_Last: {        /* no-push */
   int i = pOp->p1;
   Cursor *pC;
   BtCursor *pCrsr;
@@ -3374,13 +3367,13 @@ case OP_Last: {
 
 /* Opcode: Rewind P1 P2 *
 **
-** The next use of the Recno or Column or Next instruction for P1 
+** The next use of the Rowid or Column or Next instruction for P1 
 ** will refer to the first entry in the database table or index.
 ** If the table or index is empty and P2>0, then jump immediately to P2.
 ** If P2 is 0 or if the table or index is not empty, fall through
 ** to the following instruction.
 */
-case OP_Rewind: {
+case OP_Rewind: {        /* no-push */
   int i = pOp->p1;
   Cursor *pC;
   BtCursor *pCrsr;
@@ -3420,8 +3413,8 @@ case OP_Rewind: {
 ** to the following instruction.  But if the cursor backup was successful,
 ** jump immediately to P2.
 */
-case OP_Prev:
-case OP_Next: {
+case OP_Prev:          /* no-push */
+case OP_Next: {        /* no-push */
   Cursor *pC;
   BtCursor *pCrsr;
 
@@ -3447,11 +3440,11 @@ case OP_Next: {
   }else{
     pC->nullRow = 1;
   }
-  pC->recnoIsValid = 0;
+  pC->rowidIsValid = 0;
   break;
 }
 
-/* Opcode: IdxPut P1 P2 P3
+/* Opcode: IdxInsert P1 P2 P3
 **
 ** The top of the stack holds a SQL index key made using the
 ** MakeIdxKey instruction.  This opcode writes that key into the
@@ -3461,8 +3454,11 @@ case OP_Next: {
 ** the program aborts with a SQLITE_CONSTRAINT error and the database
 ** is rolled back.  If P3 is not null, then it becomes part of the
 ** error message returned with the SQLITE_CONSTRAINT.
+**
+** This instruction only works for indices.  The equivalent instruction
+** for tables is OP_Insert.
 */
-case OP_IdxPut: {
+case OP_IdxInsert: {        /* no-push */
   int i = pOp->p1;
   Cursor *pC;
   BtCursor *pCrsr;
@@ -3499,7 +3495,7 @@ case OP_IdxPut: {
         }
       }
     }
-    assert( pC->intKey==0 );
+    assert( pC->isTable==0 );
     rc = sqlite3BtreeInsert(pCrsr, zKey, nKey, "", 0);
     assert( pC->deferredMoveto==0 );
     pC->cacheValid = 0;
@@ -3514,7 +3510,7 @@ case OP_IdxPut: {
 ** The top of the stack is an index key built using the MakeIdxKey opcode.
 ** This opcode removes that entry from the index.
 */
-case OP_IdxDelete: {
+case OP_IdxDelete: {        /* no-push */
   int i = pOp->p1;
   Cursor *pC;
   BtCursor *pCrsr;
@@ -3536,15 +3532,15 @@ case OP_IdxDelete: {
   break;
 }
 
-/* Opcode: IdxRecno P1 * *
+/* Opcode: IdxRowid P1 * *
 **
-** Push onto the stack an integer which is the varint located at the
-** end of the index key pointed to by cursor P1.  This integer should be
-** the record number of the table entry to which this index entry points.
+** Push onto the stack an integer which is the last entry in the record at
+** the end of the index key pointed to by cursor P1.  This integer should be
+** the rowid of the table entry to which this index entry points.
 **
-** See also: Recno, MakeIdxKey.
+** See also: Rowid, MakeIdxKey.
 */
-case OP_IdxRecno: {
+case OP_IdxRowid: {
   int i = pOp->p1;
   BtCursor *pCrsr;
   Cursor *pC;
@@ -3557,7 +3553,7 @@ case OP_IdxRecno: {
     i64 rowid;
 
     assert( pC->deferredMoveto==0 );
-    assert( pC->intKey==0 );
+    assert( pC->isTable==0 );
     if( pC->nullRow ){
       pTos->flags = MEM_Null;
     }else{
@@ -3616,9 +3612,9 @@ case OP_IdxRecno: {
 ** an epsilon prior to the comparison.  This makes the opcode work
 ** like IdxLE.
 */
-case OP_IdxLT:
-case OP_IdxGT:
-case OP_IdxGE: {
+case OP_IdxLT:          /* no-push */
+case OP_IdxGT:          /* no-push */
+case OP_IdxGE: {        /* no-push */
   int i= pOp->p1;
   BtCursor *pCrsr;
   Cursor *pC;
@@ -3662,7 +3658,7 @@ case OP_IdxGE: {
 **
 ** The index entry is always popped from the stack.
 */
-case OP_IdxIsNull: {
+case OP_IdxIsNull: {        /* no-push */
   int i = pOp->p1;
   int k, n;
   const char *z;
@@ -3736,7 +3732,7 @@ case OP_Destroy: {
 **
 ** See also: Destroy
 */
-case OP_Clear: {
+case OP_Clear: {        /* no-push */
   rc = sqlite3BtreeClearTable(db->aDb[pOp->p2].pBt, pOp->p1);
   break;
 }
@@ -3794,7 +3790,7 @@ case OP_CreateTable: {
 ** This opcode invokes the parser to create a new virtual machine,
 ** then runs the new virtual machine.  It is thus a reentrant opcode.
 */
-case OP_ParseSchema: {
+case OP_ParseSchema: {        /* no-push */
   char *zSql;
   int iDb = pOp->p1;
   const char *zMaster;
@@ -3802,7 +3798,7 @@ case OP_ParseSchema: {
 
   assert( iDb>=0 && iDb<db->nDb );
   if( !DbHasProperty(db, iDb, DB_SchemaLoaded) ) break;
-  zMaster = iDb==1 ? TEMP_MASTER_NAME : MASTER_NAME;
+  zMaster = SCHEMA_TABLE(iDb);
   initData.db = db;
   initData.pzErrMsg = &p->zErrMsg;
   zSql = sqlite3MPrintf(
@@ -3826,7 +3822,7 @@ case OP_ParseSchema: {
 ** is dropped in order to keep the internal representation of the
 ** schema consistent with what is on disk.
 */
-case OP_DropTable: {
+case OP_DropTable: {        /* no-push */
   sqlite3UnlinkAndDeleteTable(db, pOp->p1, pOp->p3);
   break;
 }
@@ -3838,7 +3834,7 @@ case OP_DropTable: {
 ** is dropped in order to keep the internal representation of the
 ** schema consistent with what is on disk.
 */
-case OP_DropIndex: {
+case OP_DropIndex: {        /* no-push */
   sqlite3UnlinkAndDeleteIndex(db, pOp->p1, pOp->p3);
   break;
 }
@@ -3850,7 +3846,7 @@ case OP_DropIndex: {
 ** is dropped in order to keep the internal representation of the
 ** schema consistent with what is on disk.
 */
-case OP_DropTrigger: {
+case OP_DropTrigger: {        /* no-push */
   sqlite3UnlinkAndDeleteTrigger(db, pOp->p1, pOp->p3);
   break;
 }
@@ -3915,7 +3911,7 @@ case OP_IntegrityCk: {
 ** Write the integer on the top of the stack
 ** into the temporary storage list.
 */
-case OP_ListWrite: {
+case OP_ListWrite: {        /* no-push */
   Keylist *pKeylist;
   assert( pTos>=p->aStack );
   pKeylist = p->pList;
@@ -3939,7 +3935,7 @@ case OP_ListWrite: {
 **
 ** Rewind the temporary buffer back to the beginning.
 */
-case OP_ListRewind: {
+case OP_ListRewind: {        /* no-push */
   /* What this opcode codes, really, is reverse the order of the
   ** linked list of Keylist structures so that they are read out
   ** in the same order that they were read in. */
@@ -3986,7 +3982,7 @@ case OP_ListRead: {
 **
 ** Reset the temporary storage buffer so that it holds nothing.
 */
-case OP_ListReset: {
+case OP_ListReset: {        /* no-push */
   if( p->pList ){
     sqlite3VdbeKeylistFree(p->pList);
     p->pList = 0;
@@ -4001,7 +3997,7 @@ case OP_ListReset: {
 ** AggContextPop opcode.
 ** 
 */
-case OP_AggContextPush: {
+case OP_AggContextPush: {        /* no-push */
   p->pAgg++;
   assert( p->pAgg<&p->apAgg[p->nAgg] );
   break;
@@ -4012,7 +4008,7 @@ case OP_AggContextPush: {
 ** Restore the aggregator to the state it was in when AggContextPush
 ** was last called. Any data in the current aggregator is deleted.
 */
-case OP_AggContextPop: {
+case OP_AggContextPop: {        /* no-push */
   p->pAgg--;
   assert( p->pAgg>=p->apAgg );
   break;
@@ -4026,7 +4022,7 @@ case OP_AggContextPop: {
 ** opcode. The context stores the last insert row id, the last statement change
 ** count, and the current statement change count.
 */
-case OP_ContextPush: {
+case OP_ContextPush: {        /* no-push */
   int i = p->contextStackTop++;
   Context *pContext;
 
@@ -4051,7 +4047,7 @@ case OP_ContextPush: {
 ** executed. The context stores the last insert row id, the last statement
 ** change count, and the current statement change count.
 */
-case OP_ContextPop: {
+case OP_ContextPop: {        /* no-push */
   Context *pContext = &p->contextStack[--p->contextStackTop];
   assert( p->contextStackTop>=0 );
   db->lastRowid = pContext->lastRowid;
@@ -4062,21 +4058,26 @@ case OP_ContextPop: {
 }
 #endif /* #ifndef SQLITE_OMIT_TRIGGER */
 
-/* Opcode: SortPut * * *
+/* Opcode: SortInsert * * *
 **
 ** The TOS is the key and the NOS is the data.  Pop both from the stack
 ** and put them on the sorter.  The key and data should have been
 ** made using the MakeRecord opcode.
 */
-case OP_SortPut: {
+case OP_SortInsert: {        /* no-push */
   Mem *pNos = &pTos[-1];
   Sorter *pSorter;
   assert( pNos>=p->aStack );
   if( Dynamicify(pTos, db->enc) ) goto no_mem;
   pSorter = sqliteMallocRaw( sizeof(Sorter) );
   if( pSorter==0 ) goto no_mem;
-  pSorter->pNext = p->pSort;
-  p->pSort = pSorter;
+  pSorter->pNext = 0;
+  if( p->pSortTail ){
+    p->pSortTail->pNext = pSorter;
+  }else{
+    p->pSort = pSorter;
+  }
+  p->pSortTail = pSorter;
   assert( pTos->flags & MEM_Dyn );
   pSorter->nKey = pTos->n;
   pSorter->zKey = pTos->z;
@@ -4092,7 +4093,7 @@ case OP_SortPut: {
 ** mergesort.  The P3 argument is a pointer to a KeyInfo structure
 ** that describes the keys to be sorted.
 */
-case OP_Sort: {
+case OP_Sort: {        /* no-push */
   int i;
   KeyInfo *pKeyInfo = (KeyInfo*)pOp->p3;
   Sorter *pElem;
@@ -4154,7 +4155,7 @@ case OP_SortNext: {
 **
 ** Remove any elements that remain on the sorter.
 */
-case OP_SortReset: {
+case OP_SortReset: {        /* no-push */
   sqlite3VdbeSorterReset(p);
   break;
 }
@@ -4169,7 +4170,7 @@ case OP_SortReset: {
 ** stack is popped once if P2 is 1.  If P2 is zero, then
 ** the original data remains on the stack.
 */
-case OP_MemStore: {
+case OP_MemStore: {        /* no-push */
   assert( pTos>=p->aStack );
   assert( pOp->p1>=0 && pOp->p1<p->nMem );
   rc = sqlite3VdbeMemMove(&p->aMem[pOp->p1], pTos);
@@ -4208,7 +4209,7 @@ case OP_MemLoad: {
 ** This instruction throws an error if the memory cell is not initially
 ** an integer.
 */
-case OP_MemMax: {
+case OP_MemMax: {        /* no-push */
   int i = pOp->p1;
   Mem *pMem;
   assert( pTos>=p->aStack );
@@ -4232,7 +4233,7 @@ case OP_MemMax: {
 ** This instruction throws an error if the memory cell is not initially
 ** an integer.
 */
-case OP_MemIncr: {
+case OP_MemIncr: {        /* no-push */
   int i = pOp->p1;
   Mem *pMem;
   assert( i>=0 && i<p->nMem );
@@ -4250,7 +4251,7 @@ case OP_MemIncr: {
 ** If the value of memory cell P1 is 1 or greater, jump to P2. This
 ** opcode assumes that memory cell P1 holds an integer value.
 */
-case OP_IfMemPos: {
+case OP_IfMemPos: {        /* no-push */
   int i = pOp->p1;
   Mem *pMem;
   assert( i>=0 && i<p->nMem );
@@ -4272,7 +4273,7 @@ case OP_IfMemPos: {
 ** there is no GROUP BY expression). In this case it is illegal to invoke
 ** OP_AggFocus.
 */
-case OP_AggReset: {
+case OP_AggReset: {        /* no-push */
   assert( !pOp->p3 || pOp->p3type==P3_KEYINFO );
   if( pOp->p1 ){
     rc = sqlite3VdbeAggReset(0, p->pAgg, (KeyInfo *)pOp->p3);
@@ -4290,13 +4291,18 @@ case OP_AggReset: {
   break;
 }
 
-/* Opcode: AggInit * P2 P3
+/* Opcode: AggInit P1 P2 P3
 **
 ** Initialize the function parameters for an aggregate function.
 ** The aggregate will operate out of aggregate column P2.
 ** P3 is a pointer to the FuncDef structure for the function.
+**
+** The P1 argument is not used by this opcode. However if the SSE
+** extension is compiled in, P1 is set to the number of arguments that
+** will be passed to the aggregate function, if any. This is used
+** by SSE to select the correct function when (de)serializing statements.
 */
-case OP_AggInit: {
+case OP_AggInit: {        /* no-push */
   int i = pOp->p2;
   assert( i>=0 && i<p->pAgg->nMem );
   p->pAgg->apFunc[i] = (FuncDef*)pOp->p3;
@@ -4314,7 +4320,7 @@ case OP_AggInit: {
 ** Ideally, this index would be another parameter, but there are
 ** no free parameters left.  The integer is popped from the stack.
 */
-case OP_AggFunc: {
+case OP_AggFunc: {        /* no-push */
   int n = pOp->p2;
   int i;
   Mem *pMem, *pRec;
@@ -4372,7 +4378,7 @@ case OP_AggFunc: {
 ** zero or more AggNext operations.  You must not execute an AggFocus
 ** in between an AggNext and an AggReset.
 */
-case OP_AggFocus: {
+case OP_AggFocus: {        /* no-push */
   char *zKey;
   int nKey;
   int res;
@@ -4406,7 +4412,7 @@ case OP_AggFocus: {
 ** Move the top of the stack into the P2-th field of the current
 ** aggregate.  String values are duplicated into new memory.
 */
-case OP_AggSet: {
+case OP_AggSet: {        /* no-push */
   AggElem *pFocus;
   int i = pOp->p2;
   pFocus = p->pAgg->pCurrent;
@@ -4471,7 +4477,7 @@ case OP_AggGet: {
 ** zero or more AggNext operations.  You must not execute an AggFocus
 ** in between an AggNext and an AggReset.
 */
-case OP_AggNext: {
+case OP_AggNext: {        /* no-push */
   int res;
   assert( rc==SQLITE_OK );
   CHECK_FOR_INTERRUPT;
@@ -4532,7 +4538,7 @@ case OP_AggNext: {
 ** machines to be created and run.  It may not be called from within
 ** a transaction.
 */
-case OP_Vacuum: {
+case OP_Vacuum: {        /* no-push */
   if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse; 
   rc = sqlite3RunVacuum(&p->zErrMsg, db);
   if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse;
@@ -4548,7 +4554,7 @@ case OP_Vacuum: {
 ** If P1 is 0, then all SQL statements become expired. If P1 is non-zero,
 ** then only the currently executing statement is affected. 
 */
-case OP_Expire: {
+case OP_Expire: {        /* no-push */
   if( !pOp->p1 ){
     sqlite3ExpirePreparedStatements(db);
   }else{
@@ -4575,6 +4581,9 @@ default: {
 *****************************************************************************/
     }
 
+    /* Make sure the stack limit was not exceeded */
+    assert( pTos<=pStackLimit );
+
 #ifdef VDBE_PROFILE
     {
       long long elapse = hwtime() - start;
index e1b83986f2d213ccdc3f510bce82a731c6d7cacc..c88a75c134900d7b8363a4b3dd16fc997afa72c8 100644 (file)
@@ -38,7 +38,7 @@ struct VdbeOp {
   int p1;             /* First operand */
   int p2;             /* Second parameter (often the jump destination) */
   char *p3;           /* Third parameter */
-  int p3type;         /* P3_STATIC, P3_DYNAMIC or P3_POINTER */
+  int p3type;         /* One of the P3_xxx constants defined below */
 #ifdef VDBE_PROFILE
   int cnt;            /* Number of times this instruction was executed */
   long long cycles;   /* Total time spend executing this instruction */
@@ -64,11 +64,11 @@ typedef struct VdbeOpList VdbeOpList;
 #define P3_NOTUSED    0   /* The P3 parameter is not used */
 #define P3_DYNAMIC  (-1)  /* Pointer to a string obtained from sqliteMalloc() */
 #define P3_STATIC   (-2)  /* Pointer to a static string */
-#define P3_POINTER  (-3)  /* P3 is a pointer to some structure or object */
 #define P3_COLLSEQ  (-4)  /* P3 is a pointer to a CollSeq structure */
 #define P3_FUNCDEF  (-5)  /* P3 is a pointer to a FuncDef structure */
 #define P3_KEYINFO  (-6)  /* P3 is a pointer to a KeyInfo structure */
 #define P3_VDBEFUNC (-7)  /* P3 is a pointer to a VdbeFunc structure */
+#define P3_MEM      (-8)  /* P3 is a pointer to a Mem*    structure */
 
 /* When adding a P3 argument using P3_KEYINFO, a copy of the KeyInfo structure
 ** is made.  That copy is freed when the Vdbe is finalized.  But if the
@@ -77,7 +77,7 @@ typedef struct VdbeOpList VdbeOpList;
 ** from a single sqliteMalloc().  But no copy is made and the calling
 ** function should *not* try to free the KeyInfo.
 */
-#define P3_KEYINFO_HANDOFF (-7)
+#define P3_KEYINFO_HANDOFF (-9)
 
 /*
 ** The following macro converts a relative address in the p2 field
@@ -120,6 +120,7 @@ int sqliteVdbeSetVariables(Vdbe*,int,const char**);
 void sqlite3VdbeSetNumCols(Vdbe*,int);
 int sqlite3VdbeSetColName(Vdbe*, int, const char *, int);
 void sqlite3VdbeCountChanges(Vdbe*);
+sqlite3 *sqlite3VdbeDb(Vdbe*);
 
 #ifndef NDEBUG
   void sqlite3VdbeComment(Vdbe*, const char*, ...);
index 42682d1e25a4e3727f26a63668a648347f391611..1feb9bab45e76fffa21e3c58e5aadcd136b78114 100644 (file)
@@ -60,19 +60,18 @@ typedef unsigned char Bool;
 */
 struct Cursor {
   BtCursor *pCursor;    /* The cursor structure of the backend */
-  i64 lastRecno;        /* Last recno from a Next or NextIdx operation */
+  i64 lastRowid;        /* Last rowid from a Next or NextIdx operation */
   i64 nextRowid;        /* Next rowid returned by OP_NewRowid */
   Bool zeroed;          /* True if zeroed out and ready for reuse */
-  Bool recnoIsValid;    /* True if lastRecno is valid */
-  Bool keyAsData;       /* The OP_Column command works on key instead of data */
+  Bool rowidIsValid;    /* True if lastRowid is valid */
   Bool atFirst;         /* True if pointing to first entry */
   Bool useRandomRowid;  /* Generate new record numbers semi-randomly */
   Bool nullRow;         /* True if pointing to a row with no data */
   Bool nextRowidValid;  /* True if the nextRowid field is valid */
   Bool pseudoTable;     /* This is a NEW or OLD pseudo-tables of a trigger */
   Bool deferredMoveto;  /* A call to sqlite3BtreeMoveto() is needed */
-  Bool intKey;          /* True if the table requires integer keys */
-  Bool zeroData;        /* True if table contains keys only - no data */
+  Bool isTable;         /* True if a table requiring integer keys */
+  Bool isIndex;         /* True if an index containing keys only - no data */
   u8 bogusIncrKey;      /* Something for pIncrKey to point to if pKeyInfo==0 */
   i64 movetoTarget;     /* Argument to the deferred sqlite3BtreeMoveto() */
   Btree *pBt;           /* Separate file holding temporary table */
@@ -314,6 +313,7 @@ struct Vdbe {
   int nCursor;        /* Number of slots in apCsr[] */
   Cursor **apCsr;     /* One element of this array for each open cursor */
   Sorter *pSort;      /* A linked list of objects to be sorted */
+  Sorter *pSortTail;  /* Last element on the pSort list */
   int nVar;           /* Number of entries in aVar[] */
   Mem *aVar;          /* Values for the OP_Variable opcode. */
   char **azVar;       /* Name of variables */
@@ -406,6 +406,7 @@ int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*);
 void sqlite3VdbeMemRelease(Mem *p);
 #ifndef NDEBUG
 void sqlite3VdbeMemSanity(Mem*, u8);
+int sqlite3VdbeOpcodeNoPush(u8);
 #endif
 int sqlite3VdbeMemTranslate(Mem*, u8);
 void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf, int nBuf);
index ca1612875ab19612afc3d7a221abcfba06956836..f07bc889924be2fc43caffd72f95206f903db3d8 100644 (file)
@@ -23,8 +23,6 @@
 ** that sqlite3_prepare() generates.  For example, if new functions or
 ** collating sequences are registered or if an authorizer function is
 ** added or changed.
-**
-***** EXPERIMENTAL ******
 */
 int sqlite3_expired(sqlite3_stmt *pStmt){
   Vdbe *p = (Vdbe*)pStmt;
@@ -383,8 +381,18 @@ int sqlite3_column_type(sqlite3_stmt *pStmt, int i){
 /*
 ** Convert the N-th element of pStmt->pColName[] into a string using
 ** xFunc() then return that string.  If N is out of range, return 0.
-** If useType is 1, then use the second set of N elements (the datatype
-** names) instead of the first set.
+**
+** There are up to 5 names for each column.  useType determines which
+** name is returned.  Here are the names:
+**
+**    0      The column name as it should be displayed for output
+**    1      The datatype name for the column
+**    2      The name of the database that the column derives from
+**    3      The name of the table that the column derives from
+**    4      The name of the table column that the result column derives from
+**
+** If the result is not a simple column reference (if it is an expression
+** or a constant) then useTypes 2, 3, and 4 return NULL.
 */
 static const void *columnName(
   sqlite3_stmt *pStmt,
@@ -398,9 +406,7 @@ static const void *columnName(
   if( p==0 || N>=n || N<0 ){
     return 0;
   }
-  if( useType ){
-    N += n;
-  }
+  N += useType*n;
   return xFunc(&p->aColName[N]);
 }
 
@@ -412,32 +418,71 @@ static const void *columnName(
 const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){
   return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 0);
 }
+#ifndef SQLITE_OMIT_UTF16
+const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
+  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 0);
+}
+#endif
 
 /*
 ** Return the column declaration type (if applicable) of the 'i'th column
-** of the result set of SQL statement pStmt, encoded as UTF-8.
+** of the result set of SQL statement pStmt.
 */
 const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
   return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 1);
 }
+#ifndef SQLITE_OMIT_UTF16
+const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
+  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 1);
+}
+#endif /* SQLITE_OMIT_UTF16 */
 
+#if !defined(SQLITE_OMIT_ORIGIN_NAMES) && 0
+/*
+** Return the name of the database from which a result column derives.
+** NULL is returned if the result column is an expression or constant or
+** anything else which is not an unabiguous reference to a database column.
+*/
+const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
+  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 2);
+}
 #ifndef SQLITE_OMIT_UTF16
+const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){
+  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 2);
+}
+#endif /* SQLITE_OMIT_UTF16 */
+
 /*
-** Return the name of the 'i'th column of the result set of SQL statement
-** pStmt, encoded as UTF-16.
+** Return the name of the table from which a result column derives.
+** NULL is returned if the result column is an expression or constant or
+** anything else which is not an unabiguous reference to a database column.
 */
-const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
-  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 0);
+const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
+  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 3);
+}
+#ifndef SQLITE_OMIT_UTF16
+const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){
+  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 3);
 }
+#endif /* SQLITE_OMIT_UTF16 */
 
 /*
-** Return the column declaration type (if applicable) of the 'i'th column
-** of the result set of SQL statement pStmt, encoded as UTF-16.
+** Return the name of the table column from which a result column derives.
+** NULL is returned if the result column is an expression or constant or
+** anything else which is not an unabiguous reference to a database column.
 */
-const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
-  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 1);
+const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
+  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, 4);
+}
+#ifndef SQLITE_OMIT_UTF16
+const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
+  return columnName(pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, 4);
 }
 #endif /* SQLITE_OMIT_UTF16 */
+#endif /* SQLITE_OMIT_ORIGIN_NAMES */
+
+
+
 
 /******************************* sqlite3_bind_  ***************************
 ** 
@@ -454,7 +499,7 @@ const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
 static int vdbeUnbind(Vdbe *p, int i){
   Mem *pVar;
   if( p==0 || p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){
-    sqlite3Error(p->db, SQLITE_MISUSE, 0);
+    if( p ) sqlite3Error(p->db, SQLITE_MISUSE, 0);
     return SQLITE_MISUSE;
   }
   if( i<1 || i>p->nVar ){
@@ -622,3 +667,35 @@ int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){
   }
   return 0;
 }
+
+/*
+** Transfer all bindings from the first statement over to the second.
+** If the two statements contain a different number of bindings, then
+** an SQLITE_ERROR is returned.
+*/
+int sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){
+  Vdbe *pFrom = (Vdbe*)pFromStmt;
+  Vdbe *pTo = (Vdbe*)pToStmt;
+  int i, rc = SQLITE_OK;
+  if( (pFrom->magic!=VDBE_MAGIC_RUN && pFrom->magic!=VDBE_MAGIC_HALT)
+    || (pTo->magic!=VDBE_MAGIC_RUN && pTo->magic!=VDBE_MAGIC_HALT) ){
+    return SQLITE_MISUSE;
+  }
+  if( pFrom->nVar!=pTo->nVar ){
+    return SQLITE_ERROR;
+  }
+  for(i=0; rc==SQLITE_OK && i<pFrom->nVar; i++){
+    rc = sqlite3VdbeMemMove(&pTo->aVar[i], &pFrom->aVar[i]);
+  }
+  return rc;
+}
+
+/*
+** Return the sqlite3* database handle to which the prepared statement given
+** in the argument belongs.  This is the same database handle that was
+** the first argument to the sqlite3_prepare() that was used to create
+** the statement in the first place.
+*/
+sqlite3 *sqlite3_db_handle(sqlite3_stmt *pStmt){
+  return pStmt ? ((Vdbe*)pStmt)->db : 0;
+}
index 6d77d725f41335dc8c998c1e3ed26f5ab700e029..e64831e7545275589cb7ae6c9bd7b6c9f7d25728 100644 (file)
@@ -57,10 +57,16 @@ void sqlite3VdbeTrace(Vdbe *p, FILE *trace){
 
 /*
 ** Resize the Vdbe.aOp array so that it contains at least N
+** elements. If the Vdbe is in VDBE_MAGIC_RUN state, then
+** the Vdbe.aOp array will be sized to contain exactly N 
 ** elements.
 */
 static void resizeOpArray(Vdbe *p, int N){
-  if( p->nOpAlloc<N ){
+  if( p->magic==VDBE_MAGIC_RUN ){
+    assert( N==p->nOp );
+    p->nOpAlloc = N;
+    p->aOp = sqliteRealloc(p->aOp, N*sizeof(Op));
+  }else if( p->nOpAlloc<N ){
     int oldSize = p->nOpAlloc;
     p->nOpAlloc = N+100;
     p->aOp = sqliteRealloc(p->aOp, p->nOpAlloc*sizeof(Op));
@@ -160,25 +166,123 @@ void sqlite3VdbeResolveLabel(Vdbe *p, int x){
   }
 }
 
+/*
+** Return non-zero if opcode 'op' is guarenteed not to push more values
+** onto the VDBE stack than it pops off.
+*/
+static int opcodeNoPush(u8 op){
+  /* The 10 NOPUSH_MASK_n constants are defined in the automatically
+  ** generated header file opcodes.h. Each is a 16-bit bitmask, one
+  ** bit corresponding to each opcode implemented by the virtual
+  ** machine in vdbe.c. The bit is true if the word "no-push" appears
+  ** in a comment on the same line as the "case OP_XXX:" in 
+  ** sqlite3VdbeExec() in vdbe.c.
+  **
+  ** If the bit is true, then the corresponding opcode is guarenteed not
+  ** to grow the stack when it is executed. Otherwise, it may grow the
+  ** stack by at most one entry.
+  **
+  ** NOPUSH_MASK_0 corresponds to opcodes 0 to 15. NOPUSH_MASK_1 contains
+  ** one bit for opcodes 16 to 31, and so on.
+  **
+  ** 16-bit bitmasks (rather than 32-bit) are specified in opcodes.h 
+  ** because the file is generated by an awk program. Awk manipulates
+  ** all numbers as floating-point and we don't want to risk a rounding
+  ** error if someone builds with an awk that uses (for example) 32-bit 
+  ** IEEE floats.
+  */ 
+  static const u32 masks[5] = {
+    NOPUSH_MASK_0 + (NOPUSH_MASK_1<<16),
+    NOPUSH_MASK_2 + (NOPUSH_MASK_3<<16),
+    NOPUSH_MASK_4 + (NOPUSH_MASK_5<<16),
+    NOPUSH_MASK_6 + (NOPUSH_MASK_7<<16),
+    NOPUSH_MASK_8 + (NOPUSH_MASK_9<<16)
+  };
+  return (masks[op>>5] & (1<<(op&0x1F)));
+}
+
+#ifndef NDEBUG
+int sqlite3VdbeOpcodeNoPush(u8 op){
+  return opcodeNoPush(op);
+}
+#endif
+
 /*
 ** Loop through the program looking for P2 values that are negative.
 ** Each such value is a label.  Resolve the label by setting the P2
 ** value to its correct non-zero value.
 **
 ** This routine is called once after all opcodes have been inserted.
+**
+** Variable *pMaxFuncArgs is set to the maximum value of any P1 argument 
+** to an OP_Function or P2 to an OP_AggFunc opcode. This is used by 
+** sqlite3VdbeMakeReady() to size the Vdbe.apArg[] array.
+**
+** The integer *pMaxStack is set to the maximum number of vdbe stack
+** entries that static analysis reveals this program might need.
+**
+** This routine also does the following optimization:  It scans for
+** Halt instructions where P1==SQLITE_CONSTRAINT or P2==OE_Abort or for
+** IdxInsert instructions where P2!=0.  If no such instruction is
+** found, then every Statement instruction is changed to a Noop.  In
+** this way, we avoid creating the statement journal file unnecessarily.
 */
-static void resolveP2Values(Vdbe *p){
+static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs, int *pMaxStack){
   int i;
+  int nMaxArgs = 0;
+  int nMaxStack = p->nOp;
   Op *pOp;
   int *aLabel = p->aLabel;
-  if( aLabel==0 ) return;
+  int doesStatementRollback = 0;
+  int hasStatementBegin = 0;
   for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
+    u8 opcode = pOp->opcode;
+
+    /* Todo: Maybe OP_AggFunc should change to use P1 in the same
+     * way as OP_Function. 
+     */
+    if( opcode==OP_Function ){
+      if( pOp->p1>nMaxArgs ) nMaxArgs = pOp->p1;
+    }else if( opcode==OP_AggFunc ){
+      if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
+    }else if( opcode==OP_Halt ){
+      if( pOp->p1==SQLITE_CONSTRAINT && pOp->p2==OE_Abort ){
+        doesStatementRollback = 1;
+      }
+    }else if( opcode==OP_IdxInsert ){
+      if( pOp->p2 ){
+        doesStatementRollback = 1;
+      }
+    }else if( opcode==OP_Statement ){
+      hasStatementBegin = 1;
+    }
+
+    if( opcodeNoPush(opcode) ){
+      nMaxStack--;
+    }
+
     if( pOp->p2>=0 ) continue;
     assert( -1-pOp->p2<p->nLabel );
     pOp->p2 = aLabel[-1-pOp->p2];
   }
   sqliteFree(p->aLabel);
   p->aLabel = 0;
+
+  *pMaxFuncArgs = nMaxArgs;
+  *pMaxStack = nMaxStack;
+
+  /* If we never rollback a statement transaction, then statement
+  ** transactions are not needed.  So change every OP_Statement
+  ** opcode into an OP_Noop.  This avoid a call to sqlite3OsOpenExclusive()
+  ** which can be expensive on some platforms.
+  */
+  if( hasStatementBegin && !doesStatementRollback ){
+    for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
+      if( pOp->opcode==OP_Statement ){
+        pOp->opcode = OP_Noop;
+      }
+    }
+  }
 }
 
 /*
@@ -259,19 +363,32 @@ void sqlite3VdbeChangeP2(Vdbe *p, int addr, int val){
 ** A value of n==0 means copy bytes of zP3 up to and including the
 ** first null byte.  If n>0 then copy n+1 bytes of zP3.
 **
-** If n==P3_STATIC  it means that zP3 is a pointer to a constant static
-** string and we can just copy the pointer.  n==P3_POINTER means zP3 is
-** a pointer to some object other than a string.  n==P3_COLLSEQ and
-** n==P3_KEYINFO mean that zP3 is a pointer to a CollSeq or KeyInfo
-** structure.  A copy is made of KeyInfo structures into memory obtained
-** from sqliteMalloc.
+** If n==P3_KEYINFO it means that zP3 is a pointer to a KeyInfo structure.
+** A copy is made of the KeyInfo structure into memory obtained from
+** sqliteMalloc, to be freed when the Vdbe is finalized.
+** n==P3_KEYINFO_HANDOFF indicates that zP3 points to a KeyInfo structure
+** stored in memory that the caller has obtained from sqliteMalloc. The 
+** caller should not free the allocation, it will be freed when the Vdbe is
+** finalized.
+** 
+** Other values of n (P3_STATIC, P3_COLLSEQ etc.) indicate that zP3 points
+** to a string or structure that is guaranteed to exist for the lifetime of
+** the Vdbe. In these cases we can just copy the pointer.
 **
 ** If addr<0 then change P3 on the most recently inserted instruction.
 */
 void sqlite3VdbeChangeP3(Vdbe *p, int addr, const char *zP3, int n){
   Op *pOp;
   assert( p->magic==VDBE_MAGIC_INIT );
-  if( p==0 || p->aOp==0 ) return;
+  if( p==0 || p->aOp==0 ){
+    if( n==P3_DYNAMIC || n==P3_KEYINFO_HANDOFF ){
+      sqliteFree((void*)zP3);
+    }
+    if( n==P3_MEM ){
+      sqlite3ValueFree((sqlite3_value *)zP3);
+    }
+    return;
+  }
   if( addr<0 || addr>=p->nOp ){
     addr = p->nOp - 1;
     if( addr<0 ) return;
@@ -385,11 +502,6 @@ static char *displayP3(Op *pOp, char *zTemp, int nTemp){
   char *zP3;
   assert( nTemp>=20 );
   switch( pOp->p3type ){
-    case P3_POINTER: {
-      sprintf(zTemp, "ptr(%#x)", (int)pOp->p3);
-      zP3 = zTemp;
-      break;
-    }
     case P3_KEYINFO: {
       int i, j;
       KeyInfo *pKeyInfo = (KeyInfo*)pOp->p3;
@@ -598,20 +710,33 @@ void sqlite3VdbeMakeReady(
   */
   assert( p->nOp>0 );
 
+  /* Set the magic to VDBE_MAGIC_RUN sooner rather than later. This
+   * is because the call to resizeOpArray() below may shrink the
+   * p->aOp[] array to save memory if called when in VDBE_MAGIC_RUN 
+   * state.
+   */
+  p->magic = VDBE_MAGIC_RUN;
+
   /* No instruction ever pushes more than a single element onto the
   ** stack.  And the stack never grows on successive executions of the
   ** same loop.  So the total number of instructions is an upper bound
-  ** on the maximum stack depth required.
+  ** on the maximum stack depth required.  (Added later:)  The
+  ** resolveP2Values() call computes a tighter upper bound on the
+  ** stack size.
   **
   ** Allocation all the stack space we will ever need.
   */
   if( p->aStack==0 ){
-    resolveP2Values(p);
+    int nArg;       /* Maximum number of args passed to a user function. */
+    int nStack;     /* Maximum number of stack entries required */
+    resolveP2Values(p, &nArg, &nStack);
+    resizeOpArray(p, p->nOp);
     assert( nVar>=0 );
-    n = isExplain ? 10 : p->nOp;
+    assert( nStack<p->nOp );
+    nStack = isExplain ? 10 : nStack;
     p->aStack = sqliteMalloc(
-        n*sizeof(p->aStack[0])         /* aStack */
-      + n*sizeof(Mem*)                 /* apArg */
+        nStack*sizeof(p->aStack[0])    /* aStack */
+      + nArg*sizeof(Mem*)              /* apArg */
       + nVar*sizeof(Mem)               /* aVar */
       + nVar*sizeof(char*)             /* azVar */
       + nMem*sizeof(Mem)               /* aMem */
@@ -619,13 +744,13 @@ void sqlite3VdbeMakeReady(
       + nAgg*sizeof(Agg)               /* Aggregate contexts */
     );
     if( !sqlite3_malloc_failed ){
-      p->aMem = &p->aStack[n];
+      p->aMem = &p->aStack[nStack];
       p->nMem = nMem;
       p->aVar = &p->aMem[nMem];
       p->nVar = nVar;
       p->okVar = 0;
       p->apArg = (Mem**)&p->aVar[nVar];
-      p->azVar = (char**)&p->apArg[n];
+      p->azVar = (char**)&p->apArg[nArg];
       p->apCsr = (Cursor**)&p->azVar[nVar];
       if( nAgg>0 ){
         p->nAgg = nAgg;
@@ -690,6 +815,7 @@ void sqlite3VdbeSorterReset(Vdbe *p){
     sqlite3VdbeMemRelease(&pSorter->data);
     sqliteFree(pSorter);
   }
+  p->pSortTail = 0;
 }
 
 /*
@@ -1017,6 +1143,7 @@ static int vdbeCommit(sqlite3 *db){
   ** This requires a master journal file to ensure the transaction is
   ** committed atomicly.
   */
+#ifndef SQLITE_OMIT_DISKIO
   else{
     char *zMaster = 0;   /* File-name for the master journal */
     char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
@@ -1133,6 +1260,7 @@ static int vdbeCommit(sqlite3 *db){
       }
     }
   }
+#endif
 
   return rc;
 }
@@ -1420,6 +1548,9 @@ void sqlite3VdbeDelete(Vdbe *p){
         sqlite3VdbeDeleteAuxData(pVdbeFunc, 0);
         sqliteFree(pVdbeFunc);
       }
+      if( pOp->p3type==P3_MEM ){
+        sqlite3ValueFree((sqlite3_value*)pOp->p3);
+      }
     }
     sqliteFree(p->aOp);
   }
@@ -1441,8 +1572,8 @@ int sqlite3VdbeCursorMoveto(Cursor *p){
   if( p->deferredMoveto ){
     int res, rc;
     extern int sqlite3_search_count;
-    assert( p->intKey );
-    if( p->intKey ){
+    assert( p->isTable );
+    if( p->isTable ){
       rc = sqlite3BtreeMoveto(p->pCursor, 0, p->movetoTarget, &res);
     }else{
       rc = sqlite3BtreeMoveto(p->pCursor,(char*)&p->movetoTarget,
@@ -1450,8 +1581,8 @@ int sqlite3VdbeCursorMoveto(Cursor *p){
     }
     if( rc ) return rc;
     *p->pIncrKey = 0;
-    p->lastRecno = keyToInt(p->movetoTarget);
-    p->recnoIsValid = res==0;
+    p->lastRowid = keyToInt(p->movetoTarget);
+    p->rowidIsValid = res==0;
     if( res<0 ){
       rc = sqlite3BtreeNext(p->pCursor, &res);
       if( rc ) return rc;
@@ -1512,7 +1643,7 @@ u32 sqlite3VdbeSerialType(Mem *pMem){
   }
   if( flags&MEM_Int ){
     /* Figure out whether to use 1, 2, 4, 6 or 8 bytes. */
-#   define MAX_6BYTE ((((i64)0x00010000)<<32)-1)
+#   define MAX_6BYTE ((((i64)0x00001000)<<32)-1)
     i64 i = pMem->i;
     u64 u = i<0 ? -i : i;
     if( u<=127 ) return 1;
@@ -1595,61 +1726,71 @@ int sqlite3VdbeSerialGet(
   u32 serial_type,              /* Serial type to deserialize */
   Mem *pMem                     /* Memory cell to write value into */
 ){
-  int len;
-
-  if( serial_type==0 ){
-    /* NULL */
-    pMem->flags = MEM_Null;
-    return 0;
-  }
-  len = sqlite3VdbeSerialTypeLen(serial_type);
-  if( serial_type<=7 ){
-    /* Integer and Real */
-    if( serial_type<=4 ){
-      /* 32-bit integer type.  This is handled by a special case for
-      ** performance reasons. */
-      int v = buf[0];
-      int n;
-      if( v&0x80 ){
-        v |= -256;
-      }
-      for(n=1; n<len; n++){
-        v = (v<<8) | buf[n];
-      }
+  switch( serial_type ){
+    case 8:    /* Reserved for future use */
+    case 9:    /* Reserved for future use */
+    case 10:   /* Reserved for future use */
+    case 11:   /* Reserved for future use */
+    case 0: {  /* NULL */
+      pMem->flags = MEM_Null;
+      break;
+    }
+    case 1: { /* 1-byte signed integer */
+      pMem->i = (signed char)buf[0];
       pMem->flags = MEM_Int;
-      pMem->i = v;
-      return n;
-    }else{
-      u64 v = 0;
-      int n;
-
-      if( buf[0]&0x80 ){
-        v = -1;
-      }
-      for(n=0; n<len; n++){
-        v = (v<<8) | buf[n];
-      }
-      if( serial_type==7 ){
-        pMem->flags = MEM_Real;
-        pMem->r = *(double*)&v;
-      }else{
+      return 1;
+    }
+    case 2: { /* 2-byte signed integer */
+      pMem->i = (((signed char)buf[0])<<8) | buf[1];
+      pMem->flags = MEM_Int;
+      return 2;
+    }
+    case 3: { /* 3-byte signed integer */
+      pMem->i = (((signed char)buf[0])<<16) | (buf[1]<<8) | buf[2];
+      pMem->flags = MEM_Int;
+      return 3;
+    }
+    case 4: { /* 4-byte signed integer */
+      pMem->i = (buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3];
+      pMem->flags = MEM_Int;
+      return 4;
+    }
+    case 5: { /* 6-byte signed integer */
+      u64 x = (((signed char)buf[0])<<8) | buf[1];
+      u32 y = (buf[2]<<24) | (buf[3]<<16) | (buf[4]<<8) | buf[5];
+      x = (x<<32) | y;
+      pMem->i = *(i64*)&x;
+      pMem->flags = MEM_Int;
+      return 6;
+    }
+    case 6:   /* 6-byte signed integer */
+    case 7: { /* IEEE floating point */
+      u64 x = (buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3];
+      u32 y = (buf[4]<<24) | (buf[5]<<16) | (buf[6]<<8) | buf[7];
+      x = (x<<32) | y;
+      if( serial_type==6 ){
+        pMem->i = *(i64*)&x;
         pMem->flags = MEM_Int;
-        pMem->i = *(i64*)&v;
+      }else{
+        pMem->r = *(double*)&x;
+        pMem->flags = MEM_Real;
       }
+      return 8;
     }
-  }else{
-    /* String or blob */
-    assert( serial_type>=12 );
-    pMem->z = (char *)buf;
-    pMem->n = len;
-    pMem->xDel = 0;
-    if( serial_type&0x01 ){
-      pMem->flags = MEM_Str | MEM_Ephem;
-    }else{
-      pMem->flags = MEM_Blob | MEM_Ephem;
+    default: {
+      int len = (serial_type-12)/2;
+      pMem->z = (char *)buf;
+      pMem->n = len;
+      pMem->xDel = 0;
+      if( serial_type&0x01 ){
+        pMem->flags = MEM_Str | MEM_Ephem;
+      }else{
+        pMem->flags = MEM_Blob | MEM_Ephem;
+      }
+      return len;
     }
   }
-  return len;
+  return 0;
 }
 
 /*
@@ -1703,8 +1844,8 @@ int sqlite3VdbeRecordCompare(
     d2 += sqlite3VdbeSerialGet(&aKey2[d2], serial_type2, &mem2);
 
     rc = sqlite3MemCompare(&mem1, &mem2, i<nField ? pKeyInfo->aColl[i] : 0);
-    sqlite3VdbeMemRelease(&mem1);
-    sqlite3VdbeMemRelease(&mem2);
+    if( mem1.flags & MEM_Dyn ) sqlite3VdbeMemRelease(&mem1);
+    if( mem2.flags & MEM_Dyn ) sqlite3VdbeMemRelease(&mem2);
     if( rc!=0 ){
       break;
     }
@@ -1847,3 +1988,10 @@ void sqlite3ExpirePreparedStatements(sqlite3 *db){
     p->expired = 1;
   }
 }
+
+/*
+** Return the database associated with the Vdbe.
+*/
+sqlite3 *sqlite3VdbeDb(Vdbe *v){
+  return v->db;
+}
index 23da9ced9e518fea94db8a3e7988b2e6789bf8ba..f08671f249c473e9b92f783347857018134578a9 100644 (file)
@@ -608,8 +608,13 @@ int sqlite3VdbeMemFromBtree(
     zData[amt] = 0;
     zData[amt+1] = 0;
     if( rc!=SQLITE_OK ){
-      if( amt>NBFS ){
+      if( amt>NBFS-2 ){
+        assert( zData!=pMem->zShort );
+        assert( pMem->flags & MEM_Dyn );
         sqliteFree(zData);
+      } else {
+        assert( zData==pMem->zShort );
+        assert( pMem->flags & MEM_Short );
       }
       return rc;
     }
@@ -700,6 +705,72 @@ sqlite3_value* sqlite3ValueNew(){
   return p;
 }
 
+/*
+** Create a new sqlite3_value object, containing the value of pExpr.
+**
+** This only works for very simple expressions that consist of one constant
+** token (i.e. "5", "5.1", "NULL", "'a string'"). If the expression can
+** be converted directly into a value, then the value is allocated and
+** a pointer written to *ppVal. The caller is responsible for deallocating
+** the value by passing it to sqlite3ValueFree() later on. If the expression
+** cannot be converted to a value, then *ppVal is set to NULL.
+*/
+int sqlite3ValueFromExpr(
+  Expr *pExpr, 
+  u8 enc, 
+  u8 affinity,
+  sqlite3_value **ppVal
+){
+  int op;
+  char *zVal = 0;
+  sqlite3_value *pVal = 0;
+
+  if( !pExpr ){
+    *ppVal = 0;
+    return SQLITE_OK;
+  }
+  op = pExpr->op;
+
+  if( op==TK_STRING || op==TK_FLOAT || op==TK_INTEGER ){
+    zVal = sqliteStrNDup(pExpr->token.z, pExpr->token.n);
+    pVal = sqlite3ValueNew();
+    if( !zVal || !pVal ) goto no_mem;
+    sqlite3Dequote(zVal);
+    sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, sqlite3FreeX);
+    if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){
+      sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, enc);
+    }else{
+      sqlite3ValueApplyAffinity(pVal, affinity, enc);
+    }
+  }else if( op==TK_UMINUS ) {
+    if( SQLITE_OK==sqlite3ValueFromExpr(pExpr->pLeft, enc, affinity, &pVal) ){
+      pVal->i = -1 * pVal->i;
+      pVal->r = -1.0 * pVal->r;
+    }
+  }
+#ifndef SQLITE_OMIT_BLOB_LITERAL
+  else if( op==TK_BLOB ){
+    int nVal;
+    pVal = sqlite3ValueNew();
+    zVal = sqliteStrNDup(pExpr->token.z+1, pExpr->token.n-1);
+    if( !zVal || !pVal ) goto no_mem;
+    sqlite3Dequote(zVal);
+    nVal = strlen(zVal)/2;
+    sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(zVal), nVal, 0, sqlite3FreeX);
+    sqliteFree(zVal);
+  }
+#endif
+
+  *ppVal = pVal;
+  return SQLITE_OK;
+
+no_mem:
+  sqliteFree(zVal);
+  sqlite3ValueFree(pVal);
+  *ppVal = 0;
+  return SQLITE_NOMEM;
+}
+
 /*
 ** Change the string value of an sqlite3_value object
 */
index b2489a4706d07e958270344fe5605cdf80126e40..553de70a25df7a91682e38b2b4256aa87ee8a9b1 100644 (file)
@@ -497,7 +497,6 @@ static void codeEqualityTerm(
     sqlite3CodeSubselect(pParse, pX);
     iTab = pX->iTable;
     sqlite3VdbeAddOp(v, OP_Rewind, iTab, brk);
-    sqlite3VdbeAddOp(v, OP_KeyAsData, iTab, 1);
     VdbeComment((v, "# %.*s", pX->span.n, pX->span.z));
     pLevel->inP2 = sqlite3VdbeAddOp(v, OP_Column, iTab, 0);
     pLevel->inOp = OP_Next;
@@ -546,7 +545,7 @@ static void codeEqualityTerm(
 **
 ** The code that sqlite3WhereBegin() generates leaves the cursors named
 ** in pTabList pointing at their appropriate entries.  The [...] code
-** can use OP_Column and OP_Recno opcodes on these cursors to extract
+** can use OP_Column and OP_Rowid opcodes on these cursors to extract
 ** data from the various tables of the loop.
 **
 ** If the WHERE clause is empty, the foreach loops must each scan their
@@ -599,8 +598,7 @@ WhereInfo *sqlite3WhereBegin(
   Parse *pParse,        /* The parser context */
   SrcList *pTabList,    /* A list of all tables to be scanned */
   Expr *pWhere,         /* The WHERE clause */
-  ExprList **ppOrderBy, /* An ORDER BY clause, or NULL */
-  Fetch *pFetch         /* Initial location of cursors.  NULL otherwise */
+  ExprList **ppOrderBy  /* An ORDER BY clause, or NULL */
 ){
   int i;                     /* Loop counter */
   WhereInfo *pWInfo;         /* Will become the return value of this function */
@@ -645,7 +643,7 @@ WhereInfo *sqlite3WhereBegin(
   */
   pWInfo = sqliteMalloc( sizeof(WhereInfo) + pTabList->nSrc*sizeof(WhereLevel));
   if( sqlite3_malloc_failed ){
-    /* sqliteFree(pWInfo); // Leak memory when malloc fails */
+    sqliteFree(pWInfo); /* Avoid leaking memory when malloc fails */
     return 0;
   }
   pWInfo->pParse = pParse;
@@ -794,7 +792,7 @@ WhereInfo *sqlite3WhereBegin(
              && (pTerm->prereqRight & loopMask)==pTerm->prereqRight ){
           int iColumn = pX->pLeft->iColumn;
           int k;
-          char idxaff = pIdx->pTable->aCol[iColumn].affinity
+          char idxaff = iColumn>=0 ? pIdx->pTable->aCol[iColumn].affinity : 0
           for(k=0; k<pIdx->nColumn; k++){
             /* If the collating sequences or affinities don't match, 
             ** ignore this index.  */
@@ -950,7 +948,6 @@ WhereInfo *sqlite3WhereBegin(
                      (char*)&pIx->keyInfo, P3_KEYINFO);
     }
     if( (pLevel->score & 1)!=0 ){
-      sqlite3VdbeAddOp(v, OP_KeyAsData, iIdxCur, 1);
       sqlite3VdbeAddOp(v, OP_SetNumColumns, iIdxCur, pIx->nColumn+1);
     }
     sqlite3CodeVerifySchema(pParse, pTab->iDb);
@@ -985,7 +982,7 @@ WhereInfo *sqlite3WhereBegin(
     if( i>0 && (pTabList->a[i-1].jointype & JT_LEFT)!=0 ){
       if( !pParse->nMem ) pParse->nMem++;
       pLevel->iLeftJoin = pParse->nMem++;
-      sqlite3VdbeAddOp(v, OP_String8, 0, 0);
+      sqlite3VdbeAddOp(v, OP_Null, 0, 0);
       sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iLeftJoin, 1);
       VdbeComment((v, "# init LEFT JOIN no-match flag"));
     }
@@ -1062,7 +1059,7 @@ WhereInfo *sqlite3WhereBegin(
       sqlite3VdbeAddOp(v, OP_RowKey, iIdxCur, 0);
       sqlite3VdbeAddOp(v, OP_IdxIsNull, nColumn, cont);
       if( !omitTable ){
-        sqlite3VdbeAddOp(v, OP_IdxRecno, iIdxCur, 0);
+        sqlite3VdbeAddOp(v, OP_IdxRowid, iIdxCur, 0);
         sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
       }
       pLevel->p1 = iIdxCur;
@@ -1121,9 +1118,9 @@ WhereInfo *sqlite3WhereBegin(
       pLevel->p1 = iCur;
       pLevel->p2 = start;
       if( testOp!=OP_Noop ){
-        sqlite3VdbeAddOp(v, OP_Recno, iCur, 0);
+        sqlite3VdbeAddOp(v, OP_Rowid, iCur, 0);
         sqlite3VdbeAddOp(v, OP_MemLoad, pLevel->iMem, 0);
-        sqlite3VdbeAddOp(v, testOp, 0, brk);
+        sqlite3VdbeAddOp(v, testOp, 'n', brk);
       }
     }else if( pIdx==0 ){
       /* Case 4:  There is no usable index.  We must do a complete
@@ -1296,7 +1293,7 @@ WhereInfo *sqlite3WhereBegin(
       sqlite3VdbeAddOp(v, OP_RowKey, iIdxCur, 0);
       sqlite3VdbeAddOp(v, OP_IdxIsNull, nEqColumn + ((score&4)!=0), cont);
       if( !omitTable ){
-        sqlite3VdbeAddOp(v, OP_IdxRecno, iIdxCur, 0);
+        sqlite3VdbeAddOp(v, OP_IdxRowid, iIdxCur, 0);
         sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0);
       }
 
@@ -1425,9 +1422,9 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
               break;
             }
           }
-        }else if( pOp->opcode==OP_Recno ){
+        }else if( pOp->opcode==OP_Rowid ){
           pOp->p1 = pLevel->iIdxCur;
-          pOp->opcode = OP_IdxRecno;
+          pOp->opcode = OP_IdxRowid;
         }else if( pOp->opcode==OP_NullRow ){
           pOp->opcode = OP_Noop;
         }