<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,9 +1,15 @@
 = Amalgalite Changelog
+== Version 0.7.7 - 2009-03-03
+
+=== Bug Fixes
+
+* roll back to SQLite 3.6.10 because of substr() bug in 3.6.11
+
 == Version 0.7.6 - 2009-03-02
 
 === Enhancements
 
-* Update to SQLite 6.8.11
+* Update to SQLite 3.6.11
 
 === Bug Fixes
 </diff>
      <filename>HISTORY</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 /******************************************************************************
 ** This file is an amalgamation of many separate C source files from SQLite
-** version 3.6.11.  By combining all the individual C code files into this 
+** version 3.6.10.  By combining all the individual C code files into this 
 ** single large file, the entire code can be compiled as a one translation
 ** unit.  This allows many compilers to do optimizations that would not be
 ** possible if the files were compiled separately.  Performance improvements
@@ -11,13 +11,13 @@
 ** programs, you need this file and the &quot;sqlite3.h&quot; header file that defines
 ** the programming interface to the SQLite library.  (If you do not have 
 ** the &quot;sqlite3.h&quot; header file at hand, you will find a copy in the first
-** 6938 lines past this header comment.)  Additional code files may be
+** 6736 lines past this header comment.)  Additional code files may be
 ** needed if you want a wrapper to interface SQLite with your choice of
 ** programming language.  The code for the &quot;sqlite3&quot; command-line shell
 ** is also in a separate file.  This file contains only code for the core
 ** SQLite library.
 **
-** This amalgamation was generated on 2009-02-17 21:02:55 UTC.
+** This amalgamation was generated on 2009-01-15 16:03:22 UTC.
 */
 #define SQLITE_CORE 1
 #define SQLITE_AMALGAMATION 1
@@ -41,7 +41,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.833 2009/02/05 16:53:43 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.824 2009/01/14 23:03:41 drh Exp $
 */
 #ifndef _SQLITEINT_H_
 #define _SQLITEINT_H_
@@ -532,7 +532,7 @@ SQLITE_PRIVATE   int sqlite3Assert(void);
 ** the version number) and changes its name to &quot;sqlite3.h&quot; as
 ** part of the build process.
 **
-** @(#) $Id: sqlite.h.in,v 1.432 2009/02/12 17:07:35 drh Exp $
+** @(#) $Id: sqlite.h.in,v 1.421 2008/12/30 06:24:58 danielk1977 Exp $
 */
 #ifndef _SQLITE3_H_
 #define _SQLITE3_H_
@@ -609,8 +609,8 @@ extern &quot;C&quot; {
 **          with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z
 **          are the major version, minor version, and release number.
 */
-#define SQLITE_VERSION         &quot;3.6.11&quot;
-#define SQLITE_VERSION_NUMBER  3006011
+#define SQLITE_VERSION         &quot;3.6.10&quot;
+#define SQLITE_VERSION_NUMBER  3006010
 
 /*
 ** CAPI3REF: Run-Time Library Version Numbers {H10020} &lt;S60100&gt;
@@ -3291,10 +3291,8 @@ typedef struct sqlite3_stmt sqlite3_stmt;
 ** new limit for that construct.  The function returns the old limit.
 **
 ** If the new limit is a negative number, the limit is unchanged.
-** For the limit category of SQLITE_LIMIT_XYZ there is a 
-** [limits | hard upper bound]
-** set by a compile-time C preprocessor macro named 
-** [limits | SQLITE_MAX_XYZ].
+** For the limit category of SQLITE_LIMIT_XYZ there is a hard upper
+** bound set by a compile-time C preprocessor macro named SQLITE_MAX_XYZ.
 ** (The &quot;_LIMIT_&quot; in the name is changed to &quot;_MAX_&quot;.)
 ** Attempts to increase a limit above its hard upper bound are
 ** silently truncated to the hard upper limit.
@@ -3302,7 +3300,7 @@ typedef struct sqlite3_stmt sqlite3_stmt;
 ** Run time limits are intended for use in applications that manage
 ** both their own internal database and also databases that are controlled
 ** by untrusted external sources.  An example application might be a
-** web browser that has its own databases for storing history and
+** webbrowser that has its own databases for storing history and
 ** separate databases controlled by JavaScript applications downloaded
 ** off the Internet.  The internal databases can be given the
 ** large, default limits.  Databases managed by external sources can
@@ -3334,10 +3332,9 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
 ** CAPI3REF: Run-Time Limit Categories {H12790} &lt;H12760&gt;
 ** KEYWORDS: {limit category} {limit categories}
 **
-** These constants define various performance limits
-** that can be lowered at run-time using [sqlite3_limit()].
-** The synopsis of the meanings of the various limits is shown below.
-** Additional information is available at [limits | Limits in SQLite].
+** These constants define various aspects of a [database connection]
+** that can be limited in size by calls to [sqlite3_limit()].
+** The meanings of the various limits are as follows:
 **
 ** &lt;dl&gt;
 ** &lt;dt&gt;SQLITE_LIMIT_LENGTH&lt;/dt&gt;
@@ -3348,7 +3345,7 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
 **
 ** &lt;dt&gt;SQLITE_LIMIT_COLUMN&lt;/dt&gt;
 ** &lt;dd&gt;The maximum number of columns in a table definition or in the
-** result set of a [SELECT] or the maximum number of columns in an index
+** result set of a SELECT or the maximum number of columns in an index
 ** or in an ORDER BY or GROUP BY clause.&lt;/dd&gt;
 **
 ** &lt;dt&gt;SQLITE_LIMIT_EXPR_DEPTH&lt;/dt&gt;
@@ -3365,11 +3362,11 @@ SQLITE_API int sqlite3_limit(sqlite3*, int id, int newVal);
 ** &lt;dd&gt;The maximum number of arguments on a function.&lt;/dd&gt;
 **
 ** &lt;dt&gt;SQLITE_LIMIT_ATTACHED&lt;/dt&gt;
-** &lt;dd&gt;The maximum number of [ATTACH | attached databases].&lt;/dd&gt;
+** &lt;dd&gt;The maximum number of attached databases.&lt;/dd&gt;
 **
 ** &lt;dt&gt;SQLITE_LIMIT_LIKE_PATTERN_LENGTH&lt;/dt&gt;
-** &lt;dd&gt;The maximum length of the pattern argument to the [LIKE] or
-** [GLOB] operators.&lt;/dd&gt;
+** &lt;dd&gt;The maximum length of the pattern argument to the LIKE or
+** GLOB operators.&lt;/dd&gt;
 **
 ** &lt;dt&gt;SQLITE_LIMIT_VARIABLE_NUMBER&lt;/dt&gt;
 ** &lt;dd&gt;The maximum number of variables in an SQL statement that can
@@ -3604,7 +3601,7 @@ typedef struct sqlite3_context sqlite3_context;
 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
 **
 ** In the SQL strings input to [sqlite3_prepare_v2()] and its variants,
-** literals may be replaced by a [parameter] in one of these forms:
+** literals may be replaced by a parameter in one of these forms:
 **
 ** &lt;ul&gt;
 ** &lt;li&gt;  ?
@@ -5482,8 +5479,8 @@ SQLITE_API int sqlite3_get_autocommit(sqlite3*);
 ** CAPI3REF: Find The Database Handle Of A Prepared Statement {H13120} &lt;S60600&gt;
 **
 ** The sqlite3_db_handle interface returns the [database connection] handle
-** to which a [prepared statement] belongs.  The [database connection]
-** returned by sqlite3_db_handle is the same [database connection] that was the first argument
+** to which a [prepared statement] belongs.  The database handle returned by
+** sqlite3_db_handle is the same database handle that was the first argument
 ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
 ** create the statement in the first place.
 **
@@ -5688,7 +5685,7 @@ SQLITE_API void *sqlite3_update_hook(
 ** to the same database. Sharing is enabled if the argument is true
 ** and disabled if the argument is false.
 **
-** Cache sharing is enabled and disabled for an entire process.
+** Cache sharing is enabled and disabled for an entire process. {END}
 ** This is a change as of SQLite version 3.5.0. In prior versions of SQLite,
 ** sharing was enabled or disabled for each thread separately.
 **
@@ -5708,8 +5705,6 @@ SQLITE_API void *sqlite3_update_hook(
 ** future releases of SQLite.  Applications that care about shared
 ** cache setting should set it explicitly.
 **
-** See Also:  [SQLite Shared-Cache Mode]
-**
 ** INVARIANTS:
 **
 ** {H10331} A successful invocation of [sqlite3_enable_shared_cache(B)]
@@ -6879,7 +6874,6 @@ SQLITE_API int sqlite3_test_control(int op, ...);
 #define SQLITE_TESTCTRL_BITVEC_TEST              8
 #define SQLITE_TESTCTRL_FAULT_INSTALL            9
 #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS     10
-#define SQLITE_TESTCTRL_PENDING_BYTE            11
 
 /*
 ** CAPI3REF: SQLite Runtime Status {H17200} &lt;S60200&gt;
@@ -7169,17 +7163,17 @@ typedef struct sqlite3_pcache sqlite3_pcache;
 **                in which case SQLite will attempt to unpin one or more 
 **                pages before re-requesting the same page, or it can
 **                allocate a new page and return a pointer to it. If a new
-**                page is allocated, then the first sizeof(void*) bytes of
-**                it (at least) must be zeroed before it is returned.
+**                page is allocated, then it must be completely zeroed before 
+**                it is returned.
 **   &lt;tr&gt;&lt;td&gt;2&lt;td&gt;If createFlag is set to 2, then SQLite is not holding any
 **                pinned pages associated with the specific cache passed
 **                as the first argument to xFetch() that can be unpinned. The
 **                cache implementation should attempt to allocate a new
-**                cache entry and return a pointer to it. Again, the first
-**                sizeof(void*) bytes of the page should be zeroed before 
-**                it is returned. If the xFetch() method returns NULL when 
-**                createFlag==2, SQLite assumes that a memory allocation 
-**                failed and returns SQLITE_NOMEM to the user.
+**                cache entry and return a pointer to it. Again, the new
+**                page should be zeroed before it is returned. If the xFetch()
+**                method returns NULL when createFlag==2, SQLite assumes that
+**                a memory allocation failed and returns SQLITE_NOMEM to the
+**                user.
 ** &lt;/table&gt;
 **
 ** xUnpin() is called by SQLite with a pointer to a currently pinned page
@@ -7231,202 +7225,6 @@ struct sqlite3_pcache_methods {
 };
 
 /*
-** CAPI3REF: Online Backup Object
-** EXPERIMENTAL
-**
-** The sqlite3_backup object records state information about an ongoing
-** online backup operation.  The sqlite3_backup object is created by
-** a call to [sqlite3_backup_init()] and is destroyed by a call to
-** [sqlite3_backup_finish()].
-**
-** See Also: [Using the SQLite Online Backup API]
-*/
-typedef struct sqlite3_backup sqlite3_backup;
-
-/*
-** CAPI3REF: Online Backup API.
-** EXPERIMENTAL
-**
-** This API is used to overwrite the contents of one database with that
-** of another. It is useful either for creating backups of databases or
-** for copying in-memory databases to or from persistent files. 
-**
-** See Also: [Using the SQLite Online Backup API]
-**
-** Exclusive access is required to the destination database for the 
-** duration of the operation. However the source database is only
-** read-locked while it is actually being read, it is not locked
-** continuously for the entire operation. Thus, the backup may be
-** performed on a live database without preventing other users from
-** writing to the database for an extended period of time.
-** 
-** To perform a backup operation: 
-**   &lt;ol&gt;
-**     &lt;li&gt;&lt;b&gt;sqlite3_backup_init()&lt;/b&gt; is called once to initialize the
-**         backup, 
-**     &lt;li&gt;&lt;b&gt;sqlite3_backup_step()&lt;/b&gt; is called one or more times to transfer 
-**         the data between the two databases, and finally
-**     &lt;li&gt;&lt;b&gt;sqlite3_backup_finish()&lt;/b&gt; is called to release all resources 
-**         associated with the backup operation. 
-**   &lt;/ol&gt;
-** There should be exactly one call to sqlite3_backup_finish() for each
-** successful call to sqlite3_backup_init().
-**
-** &lt;b&gt;sqlite3_backup_init()&lt;/b&gt;
-**
-** The first two arguments passed to [sqlite3_backup_init()] are the database
-** handle associated with the destination database and the database name 
-** used to attach the destination database to the handle. The database name
-** is &quot;main&quot; for the main database, &quot;temp&quot; for the temporary database, or
-** the name specified as part of the [ATTACH] statement if the destination is
-** an attached database. The third and fourth arguments passed to 
-** sqlite3_backup_init() identify the [database connection]
-** and database name used
-** to access the source database. The values passed for the source and 
-** destination [database connection] parameters must not be the same.
-**
-** If an error occurs within sqlite3_backup_init(), then NULL is returned
-** and an error code and error message written into the [database connection] 
-** passed as the first argument. They may be retrieved using the
-** [sqlite3_errcode()], [sqlite3_errmsg()], and [sqlite3_errmsg16()] functions.
-** Otherwise, if successful, a pointer to an [sqlite3_backup] object is
-** returned. This pointer may be used with the sqlite3_backup_step() and
-** sqlite3_backup_finish() functions to perform the specified backup 
-** operation.
-**
-** &lt;b&gt;sqlite3_backup_step()&lt;/b&gt;
-**
-** Function [sqlite3_backup_step()] is used to copy up to nPage pages between 
-** the source and destination databases, where nPage is the value of the 
-** second parameter passed to sqlite3_backup_step(). If nPage is a negative
-** value, all remaining source pages are copied. If the required pages are 
-** succesfully copied, but there are still more pages to copy before the 
-** backup is complete, it returns [SQLITE_OK]. If no error occured and there 
-** are no more pages to copy, then [SQLITE_DONE] is returned. If an error 
-** occurs, then an SQLite error code is returned. As well as [SQLITE_OK] and
-** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
-** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an
-** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.
-**
-** As well as the case where the destination database file was opened for
-** read-only access, sqlite3_backup_step() may return [SQLITE_READONLY] if
-** the destination is an in-memory database with a different page size
-** from the source database.
-**
-** If sqlite3_backup_step() cannot obtain a required file-system lock, then
-** the [sqlite3_busy_handler | busy-handler function]
-** is invoked (if one is specified). If the 
-** busy-handler returns non-zero before the lock is available, then 
-** [SQLITE_BUSY] is returned to the caller. In this case the call to
-** sqlite3_backup_step() can be retried later. If the source
-** [database connection]
-** is being used to write to the source database when sqlite3_backup_step()
-** is called, then [SQLITE_LOCKED] is returned immediately. Again, in this
-** case the call to sqlite3_backup_step() can be retried later on. If
-** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or
-** [SQLITE_READONLY] is returned, then 
-** there is no point in retrying the call to sqlite3_backup_step(). These 
-** errors are considered fatal. At this point the application must accept 
-** that the backup operation has failed and pass the backup operation handle 
-** to the sqlite3_backup_finish() to release associated resources.
-**
-** Following the first call to sqlite3_backup_step(), an exclusive lock is
-** obtained on the destination file. It is not released until either 
-** sqlite3_backup_finish() is called or the backup operation is complete 
-** and sqlite3_backup_step() returns [SQLITE_DONE]. Additionally, each time 
-** a call to sqlite3_backup_step() is made a [shared lock] is obtained on
-** the source database file. This lock is released before the
-** sqlite3_backup_step() call returns. Because the source database is not
-** locked between calls to sqlite3_backup_step(), it may be modified mid-way
-** through the backup procedure. If the source database is modified by an
-** external process or via a database connection other than the one being
-** used by the backup operation, then the backup will be transparently
-** restarted by the next call to sqlite3_backup_step(). If the source 
-** database is modified by the using the same database connection as is used
-** by the backup operation, then the backup database is transparently 
-** updated at the same time.
-**
-** &lt;b&gt;sqlite3_backup_finish()&lt;/b&gt;
-**
-** Once sqlite3_backup_step() has returned [SQLITE_DONE], or when the 
-** application wishes to abandon the backup operation, the [sqlite3_backup]
-** object should be passed to sqlite3_backup_finish(). This releases all
-** resources associated with the backup operation. If sqlite3_backup_step()
-** has not yet returned [SQLITE_DONE], then any active write-transaction on the
-** destination database is rolled back. The [sqlite3_backup] object is invalid
-** and may not be used following a call to sqlite3_backup_finish().
-**
-** The value returned by sqlite3_backup_finish is [SQLITE_OK] if no error
-** occurred, regardless or whether or not sqlite3_backup_step() was called
-** a sufficient number of times to complete the backup operation. Or, if
-** an out-of-memory condition or IO error occured during a call to
-** sqlite3_backup_step() then [SQLITE_NOMEM] or an
-** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] error code
-** is returned. In this case the error code and an error message are
-** written to the destination [database connection].
-**
-** A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() is
-** not a permanent error and does not affect the return value of
-** sqlite3_backup_finish().
-**
-** &lt;b&gt;sqlite3_backup_remaining(), sqlite3_backup_pagecount()&lt;/b&gt;
-**
-** Each call to sqlite3_backup_step() sets two values stored internally
-** by an [sqlite3_backup] object. The number of pages still to be backed
-** up, which may be queried by sqlite3_backup_remaining(), and the total
-** number of pages in the source database file, which may be queried by
-** sqlite3_backup_pagecount().
-**
-** The values returned by these functions are only updated by
-** sqlite3_backup_step(). If the source database is modified during a backup
-** operation, then the values are not updated to account for any extra
-** pages that need to be updated or the size of the source database file
-** changing.
-**
-** &lt;b&gt;Concurrent Usage of Database Handles&lt;/b&gt;
-**
-** The source [database connection] may be used by the application for other
-** purposes while a backup operation is underway or being initialized.
-** If SQLite is compiled and configured to support threadsafe database
-** connections, then the source database connection may be used concurrently
-** from within other threads.
-**
-** However, the application must guarantee that the destination database
-** connection handle is not passed to any other API (by any thread) after 
-** sqlite3_backup_init() is called and before the corresponding call to
-** sqlite3_backup_finish(). Unfortunately SQLite does not currently check
-** for this, if the application does use the destination [database connection]
-** for some other purpose during a backup operation, things may appear to
-** work correctly but in fact be subtly malfunctioning.  Use of the
-** destination database connection while a backup is in progress might
-** also cause a mutex deadlock.
-**
-** Furthermore, if running in [shared cache mode], the application must
-** guarantee that the shared cache used by the destination database
-** is not accessed while the backup is running. In practice this means
-** that the application must guarantee that the file-system file being 
-** backed up to is not accessed by any connection within the process,
-** not just the specific connection that was passed to sqlite3_backup_init().
-**
-** The [sqlite3_backup] object itself is partially threadsafe. Multiple 
-** threads may safely make multiple concurrent calls to sqlite3_backup_step().
-** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount()
-** APIs are not strictly speaking threadsafe. If they are invoked at the
-** same time as another thread is invoking sqlite3_backup_step() it is
-** possible that they return invalid values.
-*/
-SQLITE_API sqlite3_backup *sqlite3_backup_init(
-  sqlite3 *pDest,                        /* Destination database handle */
-  const char *zDestName,                 /* Destination database name */
-  sqlite3 *pSource,                      /* Source database handle */
-  const char *zSourceName                /* Source database name */
-);
-SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage);
-SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p);
-SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p);
-SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p);
-
-/*
 ** Undo the hack that converts floating point types to integer for
 ** builds on processors without floating point support.
 */
@@ -7567,114 +7365,114 @@ SQLITE_PRIVATE void sqlite3HashClear(Hash*);
 #define TK_ASC                            30
 #define TK_ATTACH                         31
 #define TK_BEFORE                         32
-#define TK_BY                             33
-#define TK_CASCADE                        34
-#define TK_CAST                           35
-#define TK_COLUMNKW                       36
-#define TK_CONFLICT                       37
-#define TK_DATABASE                       38
-#define TK_DESC                           39
-#define TK_DETACH                         40
-#define TK_EACH                           41
-#define TK_FAIL                           42
-#define TK_FOR                            43
-#define TK_IGNORE                         44
-#define TK_INITIALLY                      45
-#define TK_INSTEAD                        46
-#define TK_LIKE_KW                        47
-#define TK_MATCH                          48
-#define TK_KEY                            49
-#define TK_OF                             50
-#define TK_OFFSET                         51
-#define TK_PRAGMA                         52
-#define TK_RAISE                          53
-#define TK_REPLACE                        54
-#define TK_RESTRICT                       55
-#define TK_ROW                            56
-#define TK_TRIGGER                        57
-#define TK_VACUUM                         58
-#define TK_VIEW                           59
-#define TK_VIRTUAL                        60
-#define TK_REINDEX                        61
-#define TK_RENAME                         62
-#define TK_CTIME_KW                       63
-#define TK_ANY                            64
-#define TK_OR                             65
-#define TK_AND                            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_COLLATE                        89
-#define TK_UMINUS                         90
-#define TK_UPLUS                          91
-#define TK_BITNOT                         92
-#define TK_STRING                         93
-#define TK_JOIN_KW                        94
-#define TK_CONSTRAINT                     95
-#define TK_DEFAULT                        96
-#define TK_NULL                           97
-#define TK_PRIMARY                        98
-#define TK_UNIQUE                         99
-#define TK_CHECK                          100
-#define TK_REFERENCES                     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_EXCEPT                         113
-#define TK_INTERSECT                      114
-#define TK_SELECT                         115
-#define TK_DISTINCT                       116
-#define TK_DOT                            117
-#define TK_FROM                           118
-#define TK_JOIN                           119
-#define TK_INDEXED                        120
-#define TK_USING                          121
-#define TK_ORDER                          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_CASE                           134
-#define TK_WHEN                           135
-#define TK_THEN                           136
-#define TK_ELSE                           137
-#define TK_INDEX                          138
-#define TK_ALTER                          139
-#define TK_ADD                            140
+#define TK_CASCADE                        33
+#define TK_CAST                           34
+#define TK_CONFLICT                       35
+#define TK_DATABASE                       36
+#define TK_DESC                           37
+#define TK_DETACH                         38
+#define TK_EACH                           39
+#define TK_FAIL                           40
+#define TK_FOR                            41
+#define TK_IGNORE                         42
+#define TK_INITIALLY                      43
+#define TK_INSTEAD                        44
+#define TK_LIKE_KW                        45
+#define TK_MATCH                          46
+#define TK_KEY                            47
+#define TK_OF                             48
+#define TK_OFFSET                         49
+#define TK_PRAGMA                         50
+#define TK_RAISE                          51
+#define TK_REPLACE                        52
+#define TK_RESTRICT                       53
+#define TK_ROW                            54
+#define TK_TRIGGER                        55
+#define TK_VACUUM                         56
+#define TK_VIEW                           57
+#define TK_VIRTUAL                        58
+#define TK_REINDEX                        59
+#define TK_RENAME                         60
+#define TK_CTIME_KW                       61
+#define TK_ANY                            62
+#define TK_OR                             63
+#define TK_AND                            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_COLLATE                        87
+#define TK_UMINUS                         88
+#define TK_UPLUS                          89
+#define TK_BITNOT                         90
+#define TK_STRING                         91
+#define TK_JOIN_KW                        92
+#define TK_CONSTRAINT                     93
+#define TK_DEFAULT                        94
+#define TK_NULL                           95
+#define TK_PRIMARY                        96
+#define TK_UNIQUE                         97
+#define TK_CHECK                          98
+#define TK_REFERENCES                     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_EXCEPT                         111
+#define TK_INTERSECT                      112
+#define TK_SELECT                         113
+#define TK_DISTINCT                       114
+#define TK_DOT                            115
+#define TK_FROM                           116
+#define TK_JOIN                           117
+#define TK_INDEXED                        118
+#define TK_BY                             119
+#define TK_USING                          120
+#define TK_ORDER                          121
+#define TK_GROUP                          122
+#define TK_HAVING                         123
+#define TK_LIMIT                          124
+#define TK_WHERE                          125
+#define TK_INTO                           126
+#define TK_VALUES                         127
+#define TK_INTEGER                        128
+#define TK_FLOAT                          129
+#define TK_BLOB                           130
+#define TK_REGISTER                       131
+#define TK_VARIABLE                       132
+#define TK_CASE                           133
+#define TK_WHEN                           134
+#define TK_THEN                           135
+#define TK_ELSE                           136
+#define TK_INDEX                          137
+#define TK_ALTER                          138
+#define TK_ADD                            139
+#define TK_COLUMNKW                       140
 #define TK_TO_TEXT                        141
 #define TK_TO_BLOB                        142
 #define TK_TO_NUMERIC                     143
@@ -8013,7 +7811,7 @@ typedef struct WhereLevel WhereLevel;
 ** subsystem.  See comments in the source code for a detailed description
 ** of what each interface routine does.
 **
-** @(#) $Id: btree.h,v 1.108 2009/02/03 16:51:25 danielk1977 Exp $
+** @(#) $Id: btree.h,v 1.106 2008/12/17 17:30:26 danielk1977 Exp $
 */
 #ifndef _BTREE_H_
 #define _BTREE_H_
@@ -8098,13 +7896,13 @@ SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags);
 SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*);
 SQLITE_PRIVATE int sqlite3BtreeIsInStmt(Btree*);
 SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*);
-SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*);
 SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
 SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *);
 SQLITE_PRIVATE int sqlite3BtreeLockTable(Btree *, int, u8);
 SQLITE_PRIVATE int sqlite3BtreeSavepoint(Btree *, int, int);
 
 SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *);
+SQLITE_PRIVATE const char *sqlite3BtreeGetDirname(Btree *);
 SQLITE_PRIVATE const char *sqlite3BtreeGetJournalname(Btree *);
 SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *, Btree *);
 
@@ -8382,24 +8180,24 @@ typedef struct VdbeOpList VdbeOpList;
 #define OP_Column                               3
 #define OP_SetCookie                            4
 #define OP_Seek                                 5
-#define OP_Real                               130   /* same as TK_FLOAT    */
+#define OP_Real                               129   /* same as TK_FLOAT    */
 #define OP_Sequence                             6
 #define OP_Savepoint                            7
-#define OP_Ge                                  77   /* same as TK_GE       */
+#define OP_Ge                                  75   /* same as TK_GE       */
 #define OP_RowKey                               8
 #define OP_SCopy                                9
-#define OP_Eq                                  73   /* same as TK_EQ       */
+#define OP_Eq                                  71   /* same as TK_EQ       */
 #define OP_OpenWrite                           10
-#define OP_NotNull                             71   /* same as TK_NOTNULL  */
+#define OP_NotNull                             69   /* same as TK_NOTNULL  */
 #define OP_If                                  11
 #define OP_ToInt                              144   /* same as TK_TO_INT   */
-#define OP_String8                             93   /* same as TK_STRING   */
+#define OP_String8                             91   /* same as TK_STRING   */
 #define OP_VRowid                              12
 #define OP_CollSeq                             13
 #define OP_OpenRead                            14
 #define OP_Expire                              15
 #define OP_AutoCommit                          16
-#define OP_Gt                                  74   /* same as TK_GT       */
+#define OP_Gt                                  72   /* same as TK_GT       */
 #define OP_Pagecount                           17
 #define OP_IntegrityCk                         18
 #define OP_Sort                                20
@@ -8407,13 +8205,13 @@ typedef struct VdbeOpList VdbeOpList;
 #define OP_Trace                               22
 #define OP_Function                            23
 #define OP_IfNeg                               24
-#define OP_And                                 66   /* same as TK_AND      */
-#define OP_Subtract                            84   /* same as TK_MINUS    */
+#define OP_And                                 64   /* same as TK_AND      */
+#define OP_Subtract                            82   /* same as TK_MINUS    */
 #define OP_Noop                                25
 #define OP_Return                              26
-#define OP_Remainder                           87   /* same as TK_REM      */
+#define OP_Remainder                           85   /* same as TK_REM      */
 #define OP_NewRowid                            27
-#define OP_Multiply                            85   /* same as TK_STAR     */
+#define OP_Multiply                            83   /* same as TK_STAR     */
 #define OP_Variable                            28
 #define OP_String                              29
 #define OP_RealAffinity                        30
@@ -8433,47 +8231,47 @@ typedef struct VdbeOpList VdbeOpList;
 #define OP_Statement                           44
 #define OP_RowData                             45
 #define OP_MemMax                              46
-#define OP_Or                                  65   /* same as TK_OR       */
+#define OP_Or                                  63   /* same as TK_OR       */
 #define OP_NotExists                           47
 #define OP_Gosub                               48
-#define OP_Divide                              86   /* same as TK_SLASH    */
+#define OP_Divide                              84   /* same as TK_SLASH    */
 #define OP_Integer                             49
 #define OP_ToNumeric                          143   /* same as TK_TO_NUMERIC*/
 #define OP_Prev                                50
 #define OP_RowSetRead                          51
-#define OP_Concat                              88   /* same as TK_CONCAT   */
+#define OP_Concat                              86   /* same as TK_CONCAT   */
 #define OP_RowSetAdd                           52
-#define OP_BitAnd                              79   /* same as TK_BITAND   */
+#define OP_BitAnd                              77   /* same as TK_BITAND   */
 #define OP_VColumn                             53
 #define OP_CreateTable                         54
 #define OP_Last                                55
 #define OP_SeekLe                              56
-#define OP_IsNull                              70   /* same as TK_ISNULL   */
+#define OP_IsNull                              68   /* same as TK_ISNULL   */
 #define OP_IncrVacuum                          57
 #define OP_IdxRowid                            58
-#define OP_ShiftRight                          82   /* same as TK_RSHIFT   */
+#define OP_ShiftRight                          80   /* same as TK_RSHIFT   */
 #define OP_ResetCount                          59
 #define OP_ContextPush                         60
 #define OP_Yield                               61
 #define OP_DropTrigger                         62
-#define OP_DropIndex                           63
-#define OP_IdxGE                               64
+#define OP_DropIndex                           65
+#define OP_IdxGE                               66
 #define OP_IdxDelete                           67
-#define OP_Vacuum                              68
-#define OP_IfNot                               69
-#define OP_DropTable                           78
+#define OP_Vacuum                              76
+#define OP_IfNot                               87
+#define OP_DropTable                           88
 #define OP_SeekLt                              89
-#define OP_MakeRecord                          90
+#define OP_MakeRecord                          92
 #define OP_ToBlob                             142   /* same as TK_TO_BLOB  */
-#define OP_ResultRow                           91
+#define OP_ResultRow                           93
 #define OP_Delete                              94
 #define OP_AggFinal                            95
 #define OP_Compare                             96
-#define OP_ShiftLeft                           81   /* same as TK_LSHIFT   */
+#define OP_ShiftLeft                           79   /* same as TK_LSHIFT   */
 #define OP_Goto                                97
 #define OP_TableLock                           98
 #define OP_Clear                               99
-#define OP_Le                                  75   /* same as TK_LE       */
+#define OP_Le                                  73   /* same as TK_LE       */
 #define OP_VerifyCookie                       100
 #define OP_AggStep                            101
 #define OP_ToText                             141   /* same as TK_TO_TEXT  */
@@ -8482,13 +8280,13 @@ typedef struct VdbeOpList VdbeOpList;
 #define OP_SetNumColumns                      102
 #define OP_Transaction                        103
 #define OP_VFilter                            104
-#define OP_Ne                                  72   /* same as TK_NE       */
+#define OP_Ne                                  70   /* same as TK_NE       */
 #define OP_VDestroy                           105
 #define OP_ContextPop                         106
-#define OP_BitOr                               80   /* same as TK_BITOR    */
+#define OP_BitOr                               78   /* same as TK_BITOR    */
 #define OP_Next                               107
 #define OP_IdxInsert                          108
-#define OP_Lt                                  76   /* same as TK_LT       */
+#define OP_Lt                                  74   /* same as TK_LT       */
 #define OP_SeekGe                             109
 #define OP_Insert                             110
 #define OP_Destroy                            111
@@ -8500,18 +8298,18 @@ typedef struct VdbeOpList VdbeOpList;
 #define OP_Null                               117
 #define OP_Move                               118
 #define OP_Blob                               119
-#define OP_Add                                 83   /* same as TK_PLUS     */
+#define OP_Add                                 81   /* same as TK_PLUS     */
 #define OP_Rewind                             120
 #define OP_SeekGt                             121
 #define OP_VBegin                             122
 #define OP_VUpdate                            123
 #define OP_IfZero                             124
-#define OP_BitNot                              92   /* same as TK_BITNOT   */
+#define OP_BitNot                              90   /* same as TK_BITNOT   */
 #define OP_VCreate                            125
 #define OP_Found                              126
 #define OP_IfPos                              127
 #define OP_NullRow                            128
-#define OP_Jump                               129
+#define OP_Jump                               130
 #define OP_Permutation                        131
 
 /* The following opcode values are never used */
@@ -8544,16 +8342,16 @@ typedef struct VdbeOpList VdbeOpList;
 /*  32 */ 0x00, 0x00, 0x00, 0x02, 0x11, 0x11, 0x02, 0x05,\
 /*  40 */ 0x00, 0x02, 0x11, 0x04, 0x00, 0x00, 0x0c, 0x11,\
 /*  48 */ 0x01, 0x02, 0x01, 0x21, 0x08, 0x00, 0x02, 0x01,\
-/*  56 */ 0x11, 0x01, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00,\
-/*  64 */ 0x11, 0x2c, 0x2c, 0x00, 0x00, 0x05, 0x05, 0x05,\
-/*  72 */ 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00, 0x2c,\
-/*  80 */ 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c,\
-/*  88 */ 0x2c, 0x11, 0x00, 0x00, 0x04, 0x02, 0x00, 0x00,\
+/*  56 */ 0x11, 0x01, 0x02, 0x00, 0x00, 0x04, 0x00, 0x2c,\
+/*  64 */ 0x2c, 0x00, 0x11, 0x00, 0x05, 0x05, 0x15, 0x15,\
+/*  72 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x2c, 0x2c, 0x2c,\
+/*  80 */ 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x2c, 0x05,\
+/*  88 */ 0x00, 0x11, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00,\
 /*  96 */ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
 /* 104 */ 0x01, 0x00, 0x00, 0x01, 0x08, 0x11, 0x00, 0x02,\
 /* 112 */ 0x02, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02,\
 /* 120 */ 0x01, 0x11, 0x00, 0x00, 0x05, 0x00, 0x11, 0x05,\
-/* 128 */ 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,\
+/* 128 */ 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,\
 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04,\
 /* 144 */ 0x04, 0x04,}
 
@@ -8638,16 +8436,15 @@ SQLITE_PRIVATE   void sqlite3VdbeNoopComment(Vdbe*, const char*, ...);
 ** subsystem.  The page cache subsystem reads and writes a file a page
 ** at a time and provides a journal for rollback.
 **
-** @(#) $Id: pager.h,v 1.100 2009/02/03 16:51:25 danielk1977 Exp $
+** @(#) $Id: pager.h,v 1.93 2009/01/07 15:18:21 danielk1977 Exp $
 */
 
 #ifndef _PAGER_H_
 #define _PAGER_H_
 
 /*
-** Default maximum size for persistent journal files. A negative 
-** value means no limit. This value may be overridden using the 
-** sqlite3PagerJournalSizeLimit() API. See also &quot;PRAGMA journal_size_limit&quot;.
+** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
+** it must be turned on for each database using &quot;PRAGMA auto_vacuum = 1&quot;.
 */
 #ifndef SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT
   #define SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT -1
@@ -8670,19 +8467,9 @@ typedef struct Pager Pager;
 typedef struct PgHdr DbPage;
 
 /*
-** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
-** reserved for working around a windows/posix incompatibility). It is
-** used in the journal to signify that the remainder of the journal file 
-** is devoted to storing a master journal name - there are no more pages to
-** roll back. See comments for function writeMasterJournal() in pager.c 
-** for details.
-*/
-#define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)-&gt;pageSize))+1))
-
-/*
 ** Allowed values for the flags parameter to sqlite3PagerOpen().
 **
-** NOTE: These values must match the corresponding BTREE_ values in btree.h.
+** NOTE: This values must match the corresponding BTREE_ values in btree.h.
 */
 #define PAGER_OMIT_JOURNAL  0x0001    /* Do not use a rollback journal */
 #define PAGER_NO_READLOCK   0x0002    /* Omit readlocks on readonly files */
@@ -8705,82 +8492,75 @@ typedef struct PgHdr DbPage;
 #define PAGER_JOURNALMODE_MEMORY      4   /* In-memory journal file */
 
 /*
-** The remainder of this file contains the declarations of the functions
-** that make up the Pager sub-system API. See source code comments for 
-** a detailed description of each routine.
+** See source code comments for a detailed description of the following
+** routines:
 */
-
-/* Open and close a Pager connection. */ 
 SQLITE_PRIVATE int sqlite3PagerOpen(sqlite3_vfs *, Pager **ppPager, const char*, int,int,int);
-SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager);
-SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
-
-/* Functions used to configure a Pager object. */
 SQLITE_PRIVATE void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *);
 SQLITE_PRIVATE void sqlite3PagerSetReiniter(Pager*, void(*)(DbPage*));
 SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u16*);
 SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int);
+SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
 SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int);
-SQLITE_PRIVATE void sqlite3PagerSetSafetyLevel(Pager*,int,int);
-SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int);
-SQLITE_PRIVATE int sqlite3PagerJournalMode(Pager *, int);
-SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64);
-sqlite3_backup **sqlite3PagerBackupPtr(Pager*);
-
-/* Functions used to obtain and release page references. */ 
+SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager);
 SQLITE_PRIVATE int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
 #define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0)
 SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
-SQLITE_PRIVATE void sqlite3PagerRef(DbPage*);
-SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*);
-
-/* Operations on page references. */
-SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
-SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*);
-SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
 SQLITE_PRIVATE int sqlite3PagerPageRefcount(DbPage*);
-SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *); 
-SQLITE_PRIVATE void *sqlite3PagerGetExtra(DbPage *); 
-
-/* Functions used to manage pager transactions and savepoints. */
+SQLITE_PRIVATE int sqlite3PagerRef(DbPage*);
+SQLITE_PRIVATE int sqlite3PagerUnref(DbPage*);
+SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
 SQLITE_PRIVATE int sqlite3PagerPagecount(Pager*, int*);
-SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag);
+SQLITE_PRIVATE int sqlite3PagerBegin(DbPage*, int exFlag);
 SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int);
-SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager);
 SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
 SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
-SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
-SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
-
-/* Functions used to query pager state and configuration. */
 SQLITE_PRIVATE u8 sqlite3PagerIsreadonly(Pager*);
+SQLITE_PRIVATE void sqlite3PagerDontRollback(DbPage*);
+SQLITE_PRIVATE int sqlite3PagerDontWrite(DbPage*);
 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
+SQLITE_PRIVATE void sqlite3PagerSetSafetyLevel(Pager*,int,int);
 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*);
 SQLITE_PRIVATE const sqlite3_vfs *sqlite3PagerVfs(Pager*);
 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
+SQLITE_PRIVATE const char *sqlite3PagerDirname(Pager*);
 SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
 SQLITE_PRIVATE int sqlite3PagerNosync(Pager*);
+SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
+SQLITE_PRIVATE void *sqlite3PagerGetData(DbPage *); 
+SQLITE_PRIVATE void *sqlite3PagerGetExtra(DbPage *); 
+SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int);
+SQLITE_PRIVATE int sqlite3PagerJournalMode(Pager *, int);
+SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64);
 SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
-SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*);
+SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager);
+
+SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
+SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
 
-/* Functions used to truncate the database file. */
-SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
+#ifndef SQLITE_OMIT_AUTOVACUUM
+SQLITE_PRIVATE   void sqlite3PagerTruncateImage(Pager*,Pgno);
+SQLITE_PRIVATE   Pgno sqlite3PagerImageSize(Pager *);
+#endif
 
-/* Used by encryption extensions. */
 #ifdef SQLITE_HAS_CODEC
 SQLITE_PRIVATE   void sqlite3PagerSetCodec(Pager*,void*(*)(void*,void*,Pgno,int),void*);
 #endif
 
-/* Functions to support testing and debugging. */
 #if !defined(NDEBUG) || defined(SQLITE_TEST)
 SQLITE_PRIVATE   Pgno sqlite3PagerPagenumber(DbPage*);
 SQLITE_PRIVATE   int sqlite3PagerIswriteable(DbPage*);
 #endif
+
 #ifdef SQLITE_TEST
 SQLITE_PRIVATE   int *sqlite3PagerStats(Pager*);
 SQLITE_PRIVATE   void sqlite3PagerRefdump(Pager*);
-  void disable_simulated_io_errors(void);
-  void enable_simulated_io_errors(void);
+SQLITE_PRIVATE   int sqlite3PagerIsMemdb(Pager*);
+#endif
+
+#ifdef SQLITE_TEST
+void disable_simulated_io_errors(void);
+void enable_simulated_io_errors(void);
 #else
 # define disable_simulated_io_errors()
 # define enable_simulated_io_errors()
@@ -8806,7 +8586,7 @@ SQLITE_PRIVATE   void sqlite3PagerRefdump(Pager*);
 ** This header file defines the interface that the sqlite page cache
 ** subsystem. 
 **
-** @(#) $Id: pcache.h,v 1.19 2009/01/20 17:06:27 danielk1977 Exp $
+** @(#) $Id: pcache.h,v 1.16 2008/11/19 16:52:44 danielk1977 Exp $
 */
 
 #ifndef _PCACHE_H_
@@ -8905,7 +8685,7 @@ SQLITE_PRIVATE void sqlite3PcacheClose(PCache*);
 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *);
 
 /* Discard the contents of the cache */
-SQLITE_PRIVATE void sqlite3PcacheClear(PCache*);
+SQLITE_PRIVATE int sqlite3PcacheClear(PCache*);
 
 /* Return the total number of outstanding page references */
 SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache*);
@@ -8974,7 +8754,7 @@ SQLITE_PRIVATE void sqlite3PCacheSetDefault(void);
 ** This header file is #include-ed by sqliteInt.h and thus ends up
 ** being included by every source file.
 **
-** $Id: os.h,v 1.108 2009/02/05 16:31:46 drh Exp $
+** $Id: os.h,v 1.107 2009/01/14 23:03:41 drh Exp $
 */
 #ifndef _SQLITE_OS_H_
 #define _SQLITE_OS_H_
@@ -9152,7 +8932,9 @@ SQLITE_PRIVATE void sqlite3PCacheSetDefault(void);
 ** a random byte is selected for a shared lock.  The pool of bytes for
 ** shared locks begins at SHARED_FIRST. 
 **
-** The same locking strategy and
+** These #defines are available in sqlite_aux.h so that adaptors for
+** connecting SQLite to other operating systems can use the same byte
+** ranges for locking.  In particular, the same locking strategy and
 ** byte ranges are used for Unix.  This leaves open the possiblity of having
 ** clients on win95, winNT, and unix all talking to the same shared file
 ** and all locking correctly.  To do so would require that samba (or whatever
@@ -9176,7 +8958,13 @@ SQLITE_PRIVATE void sqlite3PCacheSetDefault(void);
 ** 1GB boundary.
 **
 */
-#define PENDING_BYTE      sqlite3PendingByte
+#ifndef SQLITE_TEST
+#define PENDING_BYTE      0x40000000  /* First byte past the 1GB boundary */
+#else
+SQLITE_API extern unsigned int sqlite3_pending_byte;
+#define PENDING_BYTE sqlite3_pending_byte
+#endif
+
 #define RESERVED_BYTE     (PENDING_BYTE+1)
 #define SHARED_FIRST      (PENDING_BYTE+2)
 #define SHARED_SIZE       510
@@ -9208,7 +8996,7 @@ SQLITE_PRIVATE int sqlite3OsFullPathname(sqlite3_vfs *, const char *, int, char
 #ifndef SQLITE_OMIT_LOAD_EXTENSION
 SQLITE_PRIVATE void *sqlite3OsDlOpen(sqlite3_vfs *, const char *);
 SQLITE_PRIVATE void sqlite3OsDlError(sqlite3_vfs *, int, char *);
-SQLITE_PRIVATE void (*sqlite3OsDlSym(sqlite3_vfs *, void *, const char *))(void);
+void (*sqlite3OsDlSym(sqlite3_vfs *, void *, const char *))(void);
 SQLITE_PRIVATE void sqlite3OsDlClose(sqlite3_vfs *, void *);
 #endif /* SQLITE_OMIT_LOAD_EXTENSION */
 SQLITE_PRIVATE int sqlite3OsRandomness(sqlite3_vfs *, int, char *);
@@ -10334,6 +10122,9 @@ struct WhereLevel {
         int addrInTop;         /* Top of the IN loop */
       } *aInLoop;           /* Information about each nested IN operator */
     } in;                 /* Used when plan.wsFlags&amp;WHERE_IN_ABLE */
+    struct {
+      WherePlan *aPlan;     /* Plans for each term of the WHERE clause */
+    } or;                 /* Used when plan.wsFlags&amp;WHERE_MULTI_OR */
   } u;
 
   /* The following field is really not part of the current level.  But
@@ -10864,30 +10655,6 @@ SQLITE_PRIVATE   int sqlite3Corrupt(void);
 #endif
 
 /*
-** The following macros mimic the standard library functions toupper(),
-** isspace(), isalnum(), isdigit() and isxdigit(), respectively. The
-** sqlite versions only work for ASCII characters, regardless of locale.
-*/
-#ifdef SQLITE_ASCII
-# define sqlite3Toupper(x)  ((x)&amp;~(sqlite3CtypeMap[(unsigned char)(x)]&amp;0x20))
-# define sqlite3Isspace(x)   (sqlite3CtypeMap[(unsigned char)(x)]&amp;0x01)
-# define sqlite3Isalnum(x)   (sqlite3CtypeMap[(unsigned char)(x)]&amp;0x06)
-# define sqlite3Isalpha(x)   (sqlite3CtypeMap[(unsigned char)(x)]&amp;0x02)
-# define sqlite3Isdigit(x)   (sqlite3CtypeMap[(unsigned char)(x)]&amp;0x04)
-# define sqlite3Isxdigit(x)  (sqlite3CtypeMap[(unsigned char)(x)]&amp;0x08)
-# define sqlite3Tolower(x)   (sqlite3UpperToLower[(unsigned char)(x)])
-#else
-# include &lt;ctype.h&gt;
-# define sqlite3Toupper(x)   toupper((unsigned char)(x))
-# define sqlite3Isspace(x)   isspace((unsigned char)(x))
-# define sqlite3Isalnum(x)   isalnum((unsigned char)(x))
-# define sqlite3Isalpha(x)   isalpha((unsigned char)(x))
-# define sqlite3Isdigit(x)   isdigit((unsigned char)(x))
-# define sqlite3Isxdigit(x)  isxdigit((unsigned char)(x))
-# define sqlite3Tolower(x)   tolower((unsigned char)(x))
-#endif
-
-/*
 ** Internal function prototypes
 */
 SQLITE_PRIVATE int sqlite3StrICmp(const char *, const char *);
@@ -10995,7 +10762,6 @@ SQLITE_PRIVATE int sqlite3BitvecTest(Bitvec*, u32);
 SQLITE_PRIVATE int sqlite3BitvecSet(Bitvec*, u32);
 SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec*, u32);
 SQLITE_PRIVATE void sqlite3BitvecDestroy(Bitvec*);
-SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec*);
 SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int,int*);
 
 SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3*, void*, unsigned int);
@@ -11244,10 +11010,8 @@ SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value
 SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
 #ifndef SQLITE_AMALGAMATION
 SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[];
-SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[];
 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config;
 SQLITE_PRIVATE SQLITE_WSD FuncDefHash sqlite3GlobalFunctions;
-SQLITE_PRIVATE int sqlite3PendingByte;
 #endif
 SQLITE_PRIVATE void sqlite3RootPageMoved(Db*, int, int);
 SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*);
@@ -11269,7 +11033,6 @@ SQLITE_PRIVATE char sqlite3AffinityType(const Token*);
 SQLITE_PRIVATE void sqlite3Analyze(Parse*, Token*, Token*);
 SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler*);
 SQLITE_PRIVATE int sqlite3FindDb(sqlite3*, Token*);
-SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *, const char *);
 SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3*,int iDB);
 SQLITE_PRIVATE void sqlite3DefaultRowEst(Index*);
 SQLITE_PRIVATE void sqlite3RegisterLikeFunctions(sqlite3*, int);
@@ -11291,9 +11054,6 @@ SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
 
-SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *);
-SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *);
-
 /*
 ** The interface to the LEMON-generated parser
 */
@@ -11442,7 +11202,7 @@ SQLITE_PRIVATE void (*sqlite3IoTrace)(const char*,...);
 **
 ** This file contains definitions of global variables and contants.
 **
-** $Id: global.c,v 1.12 2009/02/05 16:31:46 drh Exp $
+** $Id: global.c,v 1.9 2008/12/08 18:19:18 drh Exp $
 */
 
 
@@ -11492,72 +11252,6 @@ SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[] = {
 };
 
 /*
-** The following 256 byte lookup table is used to support SQLites built-in
-** equivalents to the following standard library functions:
-**
-**   isspace()                        0x01
-**   isalpha()                        0x02
-**   isdigit()                        0x04
-**   isalnum()                        0x06
-**   isxdigit()                       0x08
-**   toupper()                        0x20
-**
-** Bit 0x20 is set if the mapped character requires translation to upper
-** case. i.e. if the character is a lower-case ASCII character.
-** If x is a lower-case ASCII character, then its upper-case equivalent
-** is (x - 0x20). Therefore toupper() can be implemented as:
-**
-**   (x &amp; ~(map[x]&amp;0x20))
-**
-** Standard function tolower() is implemented using the sqlite3UpperToLower[]
-** array. tolower() is used more often than toupper() by SQLite.
-**
-** SQLite's versions are identical to the standard versions assuming a
-** locale of &quot;C&quot;. They are implemented as macros in sqliteInt.h.
-*/
-#ifdef SQLITE_ASCII
-SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256] = {
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* 00..07    ........ */
-  0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,  /* 08..0f    ........ */
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* 10..17    ........ */
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* 18..1f    ........ */
-  0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* 20..27     !&quot;#$%&amp;' */
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* 28..2f    ()*+,-./ */
-  0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,  /* 30..37    01234567 */
-  0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* 38..3f    89:;&lt;=&gt;? */
-
-  0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x02,  /* 40..47    @ABCDEFG */
-  0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,  /* 48..4f    HIJKLMNO */
-  0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,  /* 50..57    PQRSTUVW */
-  0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,  /* 58..5f    XYZ[\]^_ */
-  0x00, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22,  /* 60..67    `abcdefg */
-  0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,  /* 68..6f    hijklmno */
-  0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,  /* 70..77    pqrstuvw */
-  0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00,  /* 78..7f    xyz{|}~. */
-
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* 80..87    ........ */
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* 88..8f    ........ */
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* 90..97    ........ */
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* 98..9f    ........ */
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* a0..a7    ........ */
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* a8..af    ........ */
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* b0..b7    ........ */
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* b8..bf    ........ */
-
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* c0..c7    ........ */
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* c8..cf    ........ */
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* d0..d7    ........ */
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* d8..df    ........ */
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* e0..e7    ........ */
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* e8..ef    ........ */
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /* f0..f7    ........ */
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00   /* f8..ff    ........ */
-};
-#endif
-
-
-
-/*
 ** The following singleton contains the global configuration for
 ** the SQLite library.
 */
@@ -11598,26 +11292,6 @@ SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
 */
 SQLITE_PRIVATE SQLITE_WSD FuncDefHash sqlite3GlobalFunctions;
 
-/*
-** The value of the &quot;pending&quot; byte must be 0x40000000 (1 byte past the
-** 1-gibabyte boundary) in a compatible database.  SQLite never uses
-** the database page that contains the pending byte.  It never attempts
-** to read or write that page.  The pending byte page is set assign
-** for use by the VFS layers as space for managing file locks.
-**
-** During testing, it is often desirable to move the pending byte to
-** a different position in the file.  This allows code that has to
-** deal with the pending byte to run on files that are much smaller
-** than 1 GiB.  The sqlite3_test_control() interface can be used to
-** move the pending byte.
-**
-** IMPORTANT:  Changing the pending byte to any value other than
-** 0x40000000 results in an incompatible database file format!
-** Changing the pending byte during operating results in undefined
-** and dileterious behavior.
-*/
-SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000;
-
 /************** End of global.c **********************************************/
 /************** Begin file status.c ******************************************/
 /*
@@ -11762,7 +11436,7 @@ SQLITE_API int sqlite3_db_status(
 ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
 ** All other code has file scope.
 **
-** $Id: date.c,v 1.103 2009/02/04 03:59:25 shane Exp $
+** $Id: date.c,v 1.99 2008/12/20 13:18:50 drh Exp $
 **
 ** SQLite processes all times and dates as Julian Day numbers.  The
 ** dates and times are stored as the number of days since noon
@@ -11791,6 +11465,7 @@ SQLITE_API int sqlite3_db_status(
 **      Willmann-Bell, Inc
 **      Richmond, Virginia (USA)
 */
+#include &lt;ctype.h&gt;
 #include &lt;time.h&gt;
 
 #ifndef SQLITE_OMIT_DATETIME_FUNCS
@@ -11860,7 +11535,7 @@ static int getDigits(const char *zDate, ...){
     pVal = va_arg(ap, int*);
     val = 0;
     while( N-- ){
-      if( !sqlite3Isdigit(*zDate) ){
+      if( !isdigit(*(u8*)zDate) ){
         goto end_getDigits;
       }
       val = val*10 + *zDate - '0';
@@ -11904,7 +11579,7 @@ static int parseTimezone(const char *zDate, DateTime *p){
   int sgn = 0;
   int nHr, nMn;
   int c;
-  while( sqlite3Isspace(*zDate) ){ zDate++; }
+  while( isspace(*(u8*)zDate) ){ zDate++; }
   p-&gt;tz = 0;
   c = *zDate;
   if( c=='-' ){
@@ -11924,7 +11599,7 @@ static int parseTimezone(const char *zDate, DateTime *p){
   zDate += 5;
   p-&gt;tz = sgn*(nMn + nHr*60);
 zulu_time:
-  while( sqlite3Isspace(*zDate) ){ zDate++; }
+  while( isspace(*(u8*)zDate) ){ zDate++; }
   return *zDate!=0;
 }
 
@@ -11948,10 +11623,10 @@ static int parseHhMmSs(const char *zDate, DateTime *p){
       return 1;
     }
     zDate += 2;
-    if( *zDate=='.' &amp;&amp; sqlite3Isdigit(zDate[1]) ){
+    if( *zDate=='.' &amp;&amp; isdigit((u8)zDate[1]) ){
       double rScale = 1.0;
       zDate++;
-      while( sqlite3Isdigit(*zDate) ){
+      while( isdigit(*(u8*)zDate) ){
         ms = ms*10.0 + *zDate - '0';
         rScale *= 10.0;
         zDate++;
@@ -12036,7 +11711,7 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){
     return 1;
   }
   zDate += 10;
-  while( sqlite3Isspace(*zDate) || 'T'==*(u8*)zDate ){ zDate++; }
+  while( isspace(*(u8*)zDate) || 'T'==*(u8*)zDate ){ zDate++; }
   if( parseHhMmSs(zDate, p)==0 ){
     /* We got the time */
   }else if( *zDate==0 ){
@@ -12372,7 +12047,6 @@ static int parseModifier(const char *zMod, DateTime *p){
     case '7':
     case '8':
     case '9': {
-      double rRounder;
       n = getValue(z, &amp;r);
       assert( n&gt;=1 );
       if( z[n]==':' ){
@@ -12384,7 +12058,7 @@ static int parseModifier(const char *zMod, DateTime *p){
         const char *z2 = z;
         DateTime tx;
         sqlite3_int64 day;
-        if( !sqlite3Isdigit(*z2) ) z2++;
+        if( !isdigit(*(u8*)z2) ) z2++;
         memset(&amp;tx, 0, sizeof(tx));
         if( parseHhMmSs(z2, &amp;tx) ) break;
         computeJD(&amp;tx);
@@ -12399,21 +12073,20 @@ static int parseModifier(const char *zMod, DateTime *p){
         break;
       }
       z += n;
-      while( sqlite3Isspace(*z) ) z++;
+      while( isspace(*(u8*)z) ) z++;
       n = sqlite3Strlen30(z);
       if( n&gt;10 || n&lt;3 ) break;
       if( z[n-1]=='s' ){ z[n-1] = 0; n--; }
       computeJD(p);
       rc = 0;
-      rRounder = r&lt;0 ? -0.5 : +0.5;
       if( n==3 &amp;&amp; strcmp(z,&quot;day&quot;)==0 ){
-        p-&gt;iJD += (sqlite3_int64)(r*86400000.0 + rRounder);
+        p-&gt;iJD += (sqlite3_int64)(r*86400000.0 + 0.5);
       }else if( n==4 &amp;&amp; strcmp(z,&quot;hour&quot;)==0 ){
-        p-&gt;iJD += (sqlite3_int64)(r*(86400000.0/24.0) + rRounder);
+        p-&gt;iJD += (sqlite3_int64)(r*(86400000.0/24.0) + 0.5);
       }else if( n==6 &amp;&amp; strcmp(z,&quot;minute&quot;)==0 ){
-        p-&gt;iJD += (sqlite3_int64)(r*(86400000.0/(24.0*60.0)) + rRounder);
+        p-&gt;iJD += (sqlite3_int64)(r*(86400000.0/(24.0*60.0)) + 0.5);
       }else if( n==6 &amp;&amp; strcmp(z,&quot;second&quot;)==0 ){
-        p-&gt;iJD += (sqlite3_int64)(r*(86400000.0/(24.0*60.0*60.0)) + rRounder);
+        p-&gt;iJD += (sqlite3_int64)(r*(86400000.0/(24.0*60.0*60.0)) + 0.5);
       }else if( n==5 &amp;&amp; strcmp(z,&quot;month&quot;)==0 ){
         int x, y;
         computeYMD_HMS(p);
@@ -12425,17 +12098,13 @@ static int parseModifier(const char *zMod, DateTime *p){
         computeJD(p);
         y = (int)r;
         if( y!=r ){
-          p-&gt;iJD += (sqlite3_int64)((r - y)*30.0*86400000.0 + rRounder);
+          p-&gt;iJD += (sqlite3_int64)((r - y)*30.0*86400000.0 + 0.5);
         }
       }else if( n==4 &amp;&amp; strcmp(z,&quot;year&quot;)==0 ){
-        int y = (int)r;
         computeYMD_HMS(p);
-        p-&gt;Y += y;
+        p-&gt;Y += (int)r;
         p-&gt;validJD = 0;
         computeJD(p);
-        if( y!=r ){
-          p-&gt;iJD += (sqlite3_int64)((r - y)*365.0*86400000.0 + rRounder);
-        }
       }else{
         rc = 1;
       }
@@ -12635,10 +12304,6 @@ static void strftimeFunc(
       i++;
     }
   }
-  testcase( n==sizeof(zBuf)-1 );
-  testcase( n==sizeof(zBuf) );
-  testcase( n==(u64)db-&gt;aLimit[SQLITE_LIMIT_LENGTH]+1 );
-  testcase( n==(u64)db-&gt;aLimit[SQLITE_LIMIT_LENGTH] );
   if( n&lt;sizeof(zBuf) ){
     z = zBuf;
   }else if( n&gt;(u64)db-&gt;aLimit[SQLITE_LIMIT_LENGTH] ){
@@ -12785,19 +12450,9 @@ static void currentTimeFunc(
   double rT;
   char zBuf[20];
 
-  UNUSED_PARAMETER(argc);
-  UNUSED_PARAMETER(argv);
-
   db = sqlite3_context_db_handle(context);
   sqlite3OsCurrentTime(db-&gt;pVfs, &amp;rT);
-#ifndef SQLITE_OMIT_FLOATING_POINT
   t = 86400.0*(rT - 2440587.5) + 0.5;
-#else
-  /* without floating point support, rT will have
-  ** already lost fractional day precision.
-  */
-  t = 86400 * (rT - 2440587) - 43200;
-#endif
 #ifdef HAVE_GMTIME_R
   {
     struct tm sNow;
@@ -12994,7 +12649,7 @@ SQLITE_PRIVATE void *sqlite3OsDlOpen(sqlite3_vfs *pVfs, const char *zPath){
 SQLITE_PRIVATE void sqlite3OsDlError(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
   pVfs-&gt;xDlError(pVfs, nByte, zBufOut);
 }
-SQLITE_PRIVATE void (*sqlite3OsDlSym(sqlite3_vfs *pVfs, void *pHdle, const char *zSym))(void){
+void (*sqlite3OsDlSym(sqlite3_vfs *pVfs, void *pHdle, const char *zSym))(void){
   return pVfs-&gt;xDlSym(pVfs, pHdle, zSym);
 }
 SQLITE_PRIVATE void sqlite3OsDlClose(sqlite3_vfs *pVfs, void *pHandle){
@@ -13455,7 +13110,7 @@ SQLITE_PRIVATE void sqlite3MemSetDefault(void){
 ** This file contains implementations of the low-level memory allocation
 ** routines specified in the sqlite3_mem_methods object.
 **
-** $Id: mem2.c,v 1.43 2009/02/05 03:00:06 shane Exp $
+** $Id: mem2.c,v 1.42 2008/12/10 19:26:24 drh Exp $
 */
 
 /*
@@ -13597,11 +13252,9 @@ static struct MemBlockHdr *sqlite3MemsysGetHeader(void *pAllocation){
   pInt = (int*)pAllocation;
   pU8 = (u8*)pAllocation;
   assert( pInt[nReserve/sizeof(int)]==(int)REARGUARD );
-  /* This checks any of the &quot;extra&quot; bytes allocated due
-  ** to rounding up to an 8 byte boundary to ensure 
-  ** they haven't been overwritten.
-  */
-  while( nReserve-- &gt; p-&gt;iSize ) assert( pU8[nReserve]==0x65 );
+  assert( (nReserve-0)&lt;=p-&gt;iSize || pU8[nReserve-1]==0x65 );
+  assert( (nReserve-1)&lt;=p-&gt;iSize || pU8[nReserve-2]==0x65 );
+  assert( (nReserve-2)&lt;=p-&gt;iSize || pU8[nReserve-3]==0x65 );
   return p;
 }
 
@@ -13622,7 +13275,6 @@ static int sqlite3MemSize(void *p){
 */
 static int sqlite3MemInit(void *NotUsed){
   UNUSED_PARAMETER(NotUsed);
-  assert( (sizeof(struct MemBlockHdr)&amp;7) == 0 );
   if( !sqlite3GlobalConfig.bMemstat ){
     /* If memory status is enabled, then the malloc.c wrapper will already
     ** hold the STATIC_MEM mutex when the routines here are invoked. */
@@ -15074,7 +14726,7 @@ SQLITE_PRIVATE const sqlite3_mem_methods *sqlite3MemGetMemsys5(void){
 ** This file contains code that is common across all mutex implementations.
 
 **
-** $Id: mutex.c,v 1.30 2009/02/17 16:29:11 danielk1977 Exp $
+** $Id: mutex.c,v 1.29 2008/10/07 15:25:48 drh Exp $
 */
 
 #ifndef SQLITE_MUTEX_OMIT
@@ -15126,9 +14778,7 @@ SQLITE_PRIVATE int sqlite3MutexInit(void){
 */
 SQLITE_PRIVATE int sqlite3MutexEnd(void){
   int rc = SQLITE_OK;
-  if( sqlite3GlobalConfig.mutex.xMutexEnd ){
-    rc = sqlite3GlobalConfig.mutex.xMutexEnd();
-  }
+  rc = sqlite3GlobalConfig.mutex.xMutexEnd();
   return rc;
 }
 
@@ -16015,7 +15665,7 @@ SQLITE_PRIVATE sqlite3_mutex_methods *sqlite3DefaultMutex(void){
 *************************************************************************
 ** This file contains the C functions that implement mutexes for win32
 **
-** $Id: mutex_w32.c,v 1.15 2009/01/30 16:09:23 shane Exp $
+** $Id: mutex_w32.c,v 1.13 2008/12/08 18:19:18 drh Exp $
 */
 
 /*
@@ -16216,8 +15866,6 @@ static int winMutexTry(sqlite3_mutex *p){
     p-&gt;nRef++;
     rc = SQLITE_OK;
   }
-#else
-  UNUSED_PARAMETER(p);
 #endif
   return rc;
 }
@@ -16274,7 +15922,7 @@ SQLITE_PRIVATE sqlite3_mutex_methods *sqlite3DefaultMutex(void){
 **
 ** Memory allocation functions used throughout sqlite.
 **
-** $Id: malloc.c,v 1.56 2009/02/17 18:37:29 drh Exp $
+** $Id: malloc.c,v 1.53 2008/12/16 17:20:38 shane Exp $
 */
 
 /*
@@ -16413,9 +16061,7 @@ SQLITE_PRIVATE int sqlite3MallocInit(void){
 ** Deinitialize the memory allocation subsystem.
 */
 SQLITE_PRIVATE void sqlite3MallocEnd(void){
-  if( sqlite3GlobalConfig.m.xShutdown ){
-    sqlite3GlobalConfig.m.xShutdown(sqlite3GlobalConfig.m.pAppData);
-  }
+  sqlite3GlobalConfig.m.xShutdown(sqlite3GlobalConfig.m.pAppData);
   memset(&amp;mem0, 0, sizeof(mem0));
 }
 
@@ -16526,15 +16172,7 @@ static int mallocWithAlarm(int n, void **pp){
 */
 SQLITE_PRIVATE void *sqlite3Malloc(int n){
   void *p;
-  if( n&lt;=0 || NEVER(n&gt;=0x7fffff00) ){
-    /* The NEVER(n&gt;=0x7fffff00) term is added out of paranoia.  We want to make
-    ** absolutely sure that there is nothing within SQLite that can cause a
-    ** memory allocation of a number of bytes which is near the maximum signed
-    ** integer value and thus cause an integer overflow inside of the xMalloc()
-    ** implementation.  The n&gt;=0x7fffff00 gives us 255 bytes of headroom.  The
-    ** test should never be true because SQLITE_MAX_LENGTH should be much
-    ** less than 0x7fffff00 and it should catch large memory allocations
-    ** before they reach this point. */
+  if( n&lt;=0 ){
     p = 0;
   }else if( sqlite3GlobalConfig.bMemstat ){
     sqlite3_mutex_enter(mem0.mutex);
@@ -16823,8 +16461,7 @@ SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, int nBytes){
   if( pOld==0 ){
     return sqlite3Malloc(nBytes);
   }
-  if( nBytes&lt;=0 || NEVER(nBytes&gt;=0x7fffff00) ){
-    /* The NEVER(...) term is explained in comments on sqlite3Malloc() */
+  if( nBytes&lt;=0 ){
     sqlite3_free(pOld);
     return 0;
   }
@@ -18206,7 +17843,7 @@ SQLITE_PRIVATE void sqlite3PrngResetState(void){
 ** 6000 lines long) it was split up into several smaller files and
 ** this header information was factored out.
 **
-** $Id: vdbeInt.h,v 1.162 2009/02/03 15:39:01 drh Exp $
+** $Id: vdbeInt.h,v 1.161 2009/01/05 18:02:27 drh Exp $
 */
 #ifndef _VDBEINT_H_
 #define _VDBEINT_H_
@@ -18573,6 +18210,9 @@ SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
 SQLITE_PRIVATE int sqlite3VdbeReleaseBuffers(Vdbe *p);
 #endif
 
+#ifndef NDEBUG
+SQLITE_PRIVATE   void sqlite3VdbeMemSanity(Mem*);
+#endif
 SQLITE_PRIVATE int sqlite3VdbeMemTranslate(Mem*, u8);
 #ifdef SQLITE_DEBUG
 SQLITE_PRIVATE   void sqlite3VdbePrintSql(Vdbe*);
@@ -19105,9 +18745,10 @@ SQLITE_PRIVATE void sqlite3UtfSelfTest(void){
 ** This file contains functions for allocating memory, comparing
 ** strings, and stuff like that.
 **
-** $Id: util.c,v 1.248 2009/02/04 03:59:25 shane Exp $
+** $Id: util.c,v 1.246 2009/01/10 16:15:22 drh Exp $
 */
 
+
 /*
 ** Routine needed to support the testcase() macro.
 */
@@ -19343,23 +18984,23 @@ SQLITE_PRIVATE int sqlite3IsNumber(const char *z, int *realnum, u8 enc){
   int incr = (enc==SQLITE_UTF8?1:2);
   if( enc==SQLITE_UTF16BE ) z++;
   if( *z=='-' || *z=='+' ) z += incr;
-  if( !sqlite3Isdigit(*z) ){
+  if( !isdigit(*(u8*)z) ){
     return 0;
   }
   z += incr;
   if( realnum ) *realnum = 0;
-  while( sqlite3Isdigit(*z) ){ z += incr; }
+  while( isdigit(*(u8*)z) ){ z += incr; }
   if( *z=='.' ){
     z += incr;
-    if( !sqlite3Isdigit(*z) ) return 0;
-    while( sqlite3Isdigit(*z) ){ z += incr; }
+    if( !isdigit(*(u8*)z) ) return 0;
+    while( isdigit(*(u8*)z) ){ z += incr; }
     if( realnum ) *realnum = 1;
   }
   if( *z=='e' || *z=='E' ){
     z += incr;
     if( *z=='+' || *z=='-' ) z += incr;
-    if( !sqlite3Isdigit(*z) ) return 0;
-    while( sqlite3Isdigit(*z) ){ z += incr; }
+    if( !isdigit(*(u8*)z) ) return 0;
+    while( isdigit(*(u8*)z) ){ z += incr; }
     if( realnum ) *realnum = 1;
   }
   return *z==0;
@@ -19383,7 +19024,7 @@ SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult){
   const char *zBegin = z;
   LONGDOUBLE_TYPE v1 = 0.0;
   int nSignificant = 0;
-  while( sqlite3Isspace(*z) ) z++;
+  while( isspace(*(u8*)z) ) z++;
   if( *z=='-' ){
     sign = -1;
     z++;
@@ -19393,7 +19034,7 @@ SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult){
   while( z[0]=='0' ){
     z++;
   }
-  while( sqlite3Isdigit(*z) ){
+  while( isdigit(*(u8*)z) ){
     v1 = v1*10.0 + (*z - '0');
     z++;
     nSignificant++;
@@ -19407,7 +19048,7 @@ SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult){
         z++;
       }
     }
-    while( sqlite3Isdigit(*z) ){
+    while( isdigit(*(u8*)z) ){
       if( nSignificant&lt;18 ){
         v1 = v1*10.0 + (*z - '0');
         divisor *= 10.0;
@@ -19428,7 +19069,7 @@ SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult){
     }else if( *z=='+' ){
       z++;
     }
-    while( sqlite3Isdigit(*z) ){
+    while( isdigit(*(u8*)z) ){
       eval = eval*10 + *z - '0';
       z++;
     }
@@ -19487,7 +19128,7 @@ SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum){
   int neg;
   int i, c;
   const char *zStart;
-  while( sqlite3Isspace(*zNum) ) zNum++;
+  while( isspace(*(u8*)zNum) ) zNum++;
   if( *zNum=='-' ){
     neg = 1;
     zNum++;
@@ -20452,37 +20093,37 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
      /*  60 */ &quot;ContextPush&quot;,
      /*  61 */ &quot;Yield&quot;,
      /*  62 */ &quot;DropTrigger&quot;,
-     /*  63 */ &quot;DropIndex&quot;,
-     /*  64 */ &quot;IdxGE&quot;,
-     /*  65 */ &quot;Or&quot;,
-     /*  66 */ &quot;And&quot;,
+     /*  63 */ &quot;Or&quot;,
+     /*  64 */ &quot;And&quot;,
+     /*  65 */ &quot;DropIndex&quot;,
+     /*  66 */ &quot;IdxGE&quot;,
      /*  67 */ &quot;IdxDelete&quot;,
-     /*  68 */ &quot;Vacuum&quot;,
-     /*  69 */ &quot;IfNot&quot;,
-     /*  70 */ &quot;IsNull&quot;,
-     /*  71 */ &quot;NotNull&quot;,
-     /*  72 */ &quot;Ne&quot;,
-     /*  73 */ &quot;Eq&quot;,
-     /*  74 */ &quot;Gt&quot;,
-     /*  75 */ &quot;Le&quot;,
-     /*  76 */ &quot;Lt&quot;,
-     /*  77 */ &quot;Ge&quot;,
-     /*  78 */ &quot;DropTable&quot;,
-     /*  79 */ &quot;BitAnd&quot;,
-     /*  80 */ &quot;BitOr&quot;,
-     /*  81 */ &quot;ShiftLeft&quot;,
-     /*  82 */ &quot;ShiftRight&quot;,
-     /*  83 */ &quot;Add&quot;,
-     /*  84 */ &quot;Subtract&quot;,
-     /*  85 */ &quot;Multiply&quot;,
-     /*  86 */ &quot;Divide&quot;,
-     /*  87 */ &quot;Remainder&quot;,
-     /*  88 */ &quot;Concat&quot;,
+     /*  68 */ &quot;IsNull&quot;,
+     /*  69 */ &quot;NotNull&quot;,
+     /*  70 */ &quot;Ne&quot;,
+     /*  71 */ &quot;Eq&quot;,
+     /*  72 */ &quot;Gt&quot;,
+     /*  73 */ &quot;Le&quot;,
+     /*  74 */ &quot;Lt&quot;,
+     /*  75 */ &quot;Ge&quot;,
+     /*  76 */ &quot;Vacuum&quot;,
+     /*  77 */ &quot;BitAnd&quot;,
+     /*  78 */ &quot;BitOr&quot;,
+     /*  79 */ &quot;ShiftLeft&quot;,
+     /*  80 */ &quot;ShiftRight&quot;,
+     /*  81 */ &quot;Add&quot;,
+     /*  82 */ &quot;Subtract&quot;,
+     /*  83 */ &quot;Multiply&quot;,
+     /*  84 */ &quot;Divide&quot;,
+     /*  85 */ &quot;Remainder&quot;,
+     /*  86 */ &quot;Concat&quot;,
+     /*  87 */ &quot;IfNot&quot;,
+     /*  88 */ &quot;DropTable&quot;,
      /*  89 */ &quot;SeekLt&quot;,
-     /*  90 */ &quot;MakeRecord&quot;,
-     /*  91 */ &quot;ResultRow&quot;,
-     /*  92 */ &quot;BitNot&quot;,
-     /*  93 */ &quot;String8&quot;,
+     /*  90 */ &quot;BitNot&quot;,
+     /*  91 */ &quot;String8&quot;,
+     /*  92 */ &quot;MakeRecord&quot;,
+     /*  93 */ &quot;ResultRow&quot;,
      /*  94 */ &quot;Delete&quot;,
      /*  95 */ &quot;AggFinal&quot;,
      /*  96 */ &quot;Compare&quot;,
@@ -20518,8 +20159,8 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
      /* 126 */ &quot;Found&quot;,
      /* 127 */ &quot;IfPos&quot;,
      /* 128 */ &quot;NullRow&quot;,
-     /* 129 */ &quot;Jump&quot;,
-     /* 130 */ &quot;Real&quot;,
+     /* 129 */ &quot;Real&quot;,
+     /* 130 */ &quot;Jump&quot;,
      /* 131 */ &quot;Permutation&quot;,
      /* 132 */ &quot;NotUsed_132&quot;,
      /* 133 */ &quot;NotUsed_133&quot;,
@@ -21948,7 +21589,7 @@ SQLITE_API int sqlite3_os_end(void){
 **   *  Definitions of sqlite3_vfs objects for all locking methods
 **      plus implementations of sqlite3_os_init() and sqlite3_os_end().
 **
-** $Id: os_unix.c,v 1.241 2009/02/09 17:34:07 drh Exp $
+** $Id: os_unix.c,v 1.237 2009/01/15 04:30:03 drh Exp $
 */
 #if SQLITE_OS_UNIX              /* This file is used on unix only */
 
@@ -22085,9 +21726,7 @@ struct unixFile {
   unsigned char locktype;          /* The type of lock held on this fd */
   int lastErrno;                   /* The unix errno from the last I/O error */
   void *lockingContext;            /* Locking style specific state */
-#if SQLITE_ENABLE_LOCKING_STYLE
-  int openFlags;                   /* The flags specified at open() */
-#endif
+  int openFlags;                   /* The flags specified at open */
 #if SQLITE_THREADSAFE &amp;&amp; defined(__linux__)
   pthread_t tid;                   /* The thread that &quot;owns&quot; this unixFile */
 #endif
@@ -22106,11 +21745,6 @@ struct unixFile {
   unsigned char transCntrChng;   /* True if the transaction counter changed */
   unsigned char dbUpdate;        /* True if any part of database file changed */
   unsigned char inNormalWrite;   /* True if in a normal write operation */
-
-  /* If true, that means we are dealing with a database file that has
-  ** a range of locking bytes from PENDING_BYTE through PENDING_BYTE+511
-  ** which should never be read or written.  Asserts() will verify this */
-  unsigned char isLockable;      /* True if file might be locked */
 #endif
 #ifdef SQLITE_TEST
   /* In test mode, increase the size of this structure a bit so that 
@@ -23061,7 +22695,6 @@ static int findLockInfo(
     return SQLITE_IOERR;
   }
 
-#ifdef __APPLE__
   /* On OS X on an msdos filesystem, the inode number is reported
   ** incorrectly for zero-size files.  See ticket #3260.  To work
   ** around this problem (we consider it a bug in OS X, not SQLite)
@@ -23073,17 +22706,13 @@ static int findLockInfo(
   ** the first page of the database, no damage is done.
   */
   if( statbuf.st_size==0 ){
-    rc = write(fd, &quot;S&quot;, 1);
-    if( rc!=1 ){
-      return SQLITE_IOERR;
-    }
+    write(fd, &quot;S&quot;, 1);
     rc = fstat(fd, &amp;statbuf);
     if( rc!=0 ){
       pFile-&gt;lastErrno = errno;
       return SQLITE_IOERR;
     }
   }
-#endif
 
   memset(&amp;lockKey, 0, sizeof(lockKey));
   lockKey.fid.dev = statbuf.st_dev;
@@ -23230,7 +22859,6 @@ static int unixCheckReservedLock(sqlite3_file *id, int *pResOut){
 
   /* Otherwise see if some other process holds it.
   */
-#ifndef __DJGPP__
   if( !reserved ){
     struct flock lock;
     lock.l_whence = SEEK_SET;
@@ -23245,7 +22873,6 @@ static int unixCheckReservedLock(sqlite3_file *id, int *pResOut){
       reserved = 1;
     }
   }
-#endif
   
   unixLeaveMutex();
   OSTRACE4(&quot;TEST WR-LOCK %d %d %d\n&quot;, pFile-&gt;h, rc, reserved);
@@ -23573,7 +23200,7 @@ static int unixUnlock(sqlite3_file *id, int locktype){
         if( IS_LOCK_ERROR(rc) ){
           pFile-&gt;lastErrno = tErrno;
         }
-        goto end_unlock;
+				goto end_unlock;
       }
     }
     lock.l_type = F_UNLCK;
@@ -24830,12 +24457,6 @@ static int unixRead(
 ){
   int got;
   assert( id );
-
-  /* Never read or write any of the bytes in the locking range */
-  assert( ((unixFile*)id)-&gt;isLockable==0
-          || offset&gt;=PENDING_BYTE+512
-          || offset+amt&lt;=PENDING_BYTE );
-
   got = seekAndRead((unixFile*)id, offset, pBuf, amt);
   if( got==amt ){
     return SQLITE_OK;
@@ -24901,11 +24522,6 @@ static int unixWrite(
   assert( id );
   assert( amt&gt;0 );
 
-  /* Never read or write any of the bytes in the locking range */
-  assert( ((unixFile*)id)-&gt;isLockable==0
-          || offset&gt;=PENDING_BYTE+512
-          || offset+amt&lt;=PENDING_BYTE );
-
 #ifndef NDEBUG
   /* If we are doing a normal write to a database file (as opposed to
   ** doing a hot-journal rollback or a write to some file other than a
@@ -24917,12 +24533,11 @@ static int unixWrite(
     unixFile *pFile = (unixFile*)id;
     pFile-&gt;dbUpdate = 1;  /* The database has been modified */
     if( offset&lt;=24 &amp;&amp; offset+amt&gt;=27 ){
-      int rc;
       char oldCntr[4];
       SimulateIOErrorBenign(1);
-      rc = seekAndRead(pFile, 24, oldCntr, 4);
+      seekAndRead(pFile, 24, oldCntr, 4);
       SimulateIOErrorBenign(0);
-      if( rc!=4 || memcmp(oldCntr, &amp;((char*)pBuf)[24-offset], 4)!=0 ){
+      if( memcmp(oldCntr, &amp;((char*)pBuf)[24-offset], 4)!=0 ){
         pFile-&gt;transCntrChng = 1;  /* The transaction counter has changed */
       }
     }
@@ -25830,12 +25445,6 @@ static int unixOpen(
     *pOutFlags = flags;
   }
 
-#ifndef NDEBUG
-  if( (flags &amp; SQLITE_OPEN_MAIN_DB)!=0 ){
-    ((unixFile*)pFile)-&gt;isLockable = 1;
-  }
-#endif
-
   assert(fd!=0);
   if( isOpenDirectory ){
     rc = openDirectory(zPath, &amp;dirfd);
@@ -27236,7 +26845,7 @@ SQLITE_API int sqlite3_os_end(void){
 **
 ** This file contains code that is specific to windows.
 **
-** $Id: os_win.c,v 1.148 2009/02/05 03:16:21 shane Exp $
+** $Id: os_win.c,v 1.145 2008/12/11 02:58:27 shane Exp $
 */
 #if SQLITE_OS_WIN               /* This file is used for windows only */
 
@@ -27555,7 +27164,6 @@ struct winFile {
   HANDLE h;               /* Handle for accessing the file */
   unsigned char locktype; /* Type of lock currently held on this file */
   short sharedLockByte;   /* Randomly chosen byte used as a shared lock */
-  DWORD lastErrno;        /* The Windows errno from the last I/O error */
 #if SQLITE_OS_WINCE
   WCHAR *zDeleteOnClose;  /* Name of file to delete when closing */
   HANDLE hMutex;          /* Mutex used to control access to shared lock */  
@@ -27813,7 +27421,6 @@ static BOOL winceCreateLock(const char *zFilename, winFile *pFile){
   /* Create/open the named mutex */
   pFile-&gt;hMutex = CreateMutexW(NULL, FALSE, zName);
   if (!pFile-&gt;hMutex){
-    pFile-&gt;lastErrno = GetLastError();
     free(zName);
     return FALSE;
   }
@@ -27844,7 +27451,6 @@ static BOOL winceCreateLock(const char *zFilename, winFile *pFile){
              FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, sizeof(winceLock));
     /* If mapping failed, close the shared memory handle and erase it */
     if (!pFile-&gt;shared){
-      pFile-&gt;lastErrno = GetLastError();
       CloseHandle(pFile-&gt;hShared);
       pFile-&gt;hShared = NULL;
     }
@@ -28110,17 +27716,14 @@ static int winRead(
   DWORD rc;
   DWORD got;
   winFile *pFile = (winFile*)id;
-  DWORD error;
   assert( id!=0 );
   SimulateIOError(return SQLITE_IOERR_READ);
   OSTRACE3(&quot;READ %d lock=%d\n&quot;, pFile-&gt;h, pFile-&gt;locktype);
   rc = SetFilePointer(pFile-&gt;h, lowerBits, &amp;upperBits, FILE_BEGIN);
-  if( rc==INVALID_SET_FILE_POINTER &amp;&amp; (error=GetLastError())!=NO_ERROR ){
-    pFile-&gt;lastErrno = error;
+  if( rc==INVALID_SET_FILE_POINTER &amp;&amp; GetLastError()!=NO_ERROR ){
     return SQLITE_FULL;
   }
   if( !ReadFile(pFile-&gt;h, pBuf, amt, &amp;got, 0) ){
-    pFile-&gt;lastErrno = GetLastError();
     return SQLITE_IOERR_READ;
   }
   if( got==(DWORD)amt ){
@@ -28147,14 +27750,12 @@ static int winWrite(
   DWORD rc;
   DWORD wrote = 0;
   winFile *pFile = (winFile*)id;
-  DWORD error;
   assert( id!=0 );
   SimulateIOError(return SQLITE_IOERR_WRITE);
   SimulateDiskfullError(return SQLITE_FULL);
   OSTRACE3(&quot;WRITE %d lock=%d\n&quot;, pFile-&gt;h, pFile-&gt;locktype);
   rc = SetFilePointer(pFile-&gt;h, lowerBits, &amp;upperBits, FILE_BEGIN);
-  if( rc==INVALID_SET_FILE_POINTER &amp;&amp; (error=GetLastError())!=NO_ERROR ){
-    pFile-&gt;lastErrno = error;
+  if( rc==INVALID_SET_FILE_POINTER &amp;&amp; GetLastError()!=NO_ERROR ){
     return SQLITE_FULL;
   }
   assert( amt&gt;0 );
@@ -28167,7 +27768,6 @@ static int winWrite(
     pBuf = &amp;((char*)pBuf)[wrote];
   }
   if( !rc || amt&gt;(int)wrote ){
-    pFile-&gt;lastErrno = GetLastError();
     return SQLITE_FULL;
   }
   return SQLITE_OK;
@@ -28181,21 +27781,15 @@ static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){
   LONG upperBits = (LONG)((nByte&gt;&gt;32) &amp; 0x7fffffff);
   LONG lowerBits = (LONG)(nByte &amp; 0xffffffff);
   winFile *pFile = (winFile*)id;
-  DWORD error = NO_ERROR;
   OSTRACE3(&quot;TRUNCATE %d %lld\n&quot;, pFile-&gt;h, nByte);
   SimulateIOError(return SQLITE_IOERR_TRUNCATE);
   rc = SetFilePointer(pFile-&gt;h, lowerBits, &amp;upperBits, FILE_BEGIN);
-  if( INVALID_SET_FILE_POINTER == rc ){
-    error = GetLastError();
-  }
-  if( error == NO_ERROR ){
+  if( INVALID_SET_FILE_POINTER != rc ){
     /* SetEndOfFile will fail if nByte is negative */
     if( SetEndOfFile(pFile-&gt;h) ){
       return SQLITE_OK;
     }
-    error = GetLastError();
   }
-  pFile-&gt;lastErrno = error;
   return SQLITE_IOERR_TRUNCATE;
 }
 
@@ -28214,10 +27808,10 @@ SQLITE_API int sqlite3_fullsync_count = 0;
 static int winSync(sqlite3_file *id, int flags){
 #ifndef SQLITE_NO_SYNC
   winFile *pFile = (winFile*)id;
-  OSTRACE3(&quot;SYNC %d lock=%d\n&quot;, pFile-&gt;h, pFile-&gt;locktype);
 #else
   UNUSED_PARAMETER(id);
 #endif
+  OSTRACE3(&quot;SYNC %d lock=%d\n&quot;, pFile-&gt;h, pFile-&gt;locktype);
 #ifndef SQLITE_TEST
   UNUSED_PARAMETER(flags);
 #else
@@ -28235,7 +27829,6 @@ static int winSync(sqlite3_file *id, int flags){
   if( FlushFileBuffers(pFile-&gt;h) ){
     return SQLITE_OK;
   }else{
-    pFile-&gt;lastErrno = GetLastError();
     return SQLITE_IOERR;
   }
 #endif
@@ -28247,15 +27840,8 @@ static int winSync(sqlite3_file *id, int flags){
 static int winFileSize(sqlite3_file *id, sqlite3_int64 *pSize){
   winFile *pFile = (winFile*)id;
   DWORD upperBits, lowerBits;
-  DWORD error;
   SimulateIOError(return SQLITE_IOERR_FSTAT);
   lowerBits = GetFileSize(pFile-&gt;h, &amp;upperBits);
-  if(   (lowerBits == INVALID_FILE_SIZE)
-     &amp;&amp; ((error = GetLastError()) != NO_ERROR) )
-  {
-    pFile-&gt;lastErrno = error;
-    return SQLITE_IOERR_FSTAT;
-  }
   *pSize = (((sqlite3_int64)upperBits)&lt;&lt;32) + lowerBits;
   return SQLITE_OK;
 }
@@ -28291,9 +27877,6 @@ static int getReadLock(winFile *pFile){
     res = LockFile(pFile-&gt;h, SHARED_FIRST+pFile-&gt;sharedLockByte, 0, 1, 0);
 #endif
   }
-  if( res == 0 ){
-    pFile-&gt;lastErrno = GetLastError();
-  }
   return res;
 }
 
@@ -28311,9 +27894,6 @@ static int unlockReadLock(winFile *pFile){
     res = UnlockFile(pFile-&gt;h, SHARED_FIRST + pFile-&gt;sharedLockByte, 0, 1, 0);
 #endif
   }
-  if( res == 0 ){
-    pFile-&gt;lastErrno = GetLastError();
-  }
   return res;
 }
 
@@ -28349,7 +27929,6 @@ static int winLock(sqlite3_file *id, int locktype){
   int newLocktype;       /* Set pFile-&gt;locktype to this value before exiting */
   int gotPendingLock = 0;/* True if we acquired a PENDING lock this time */
   winFile *pFile = (winFile*)id;
-  DWORD error = NO_ERROR;
 
   assert( pFile!=0 );
   OSTRACE5(&quot;LOCK %d %d was %d(%d)\n&quot;,
@@ -28374,9 +27953,8 @@ static int winLock(sqlite3_file *id, int locktype){
   ** the PENDING_LOCK byte is temporary.
   */
   newLocktype = pFile-&gt;locktype;
-  if(   (pFile-&gt;locktype==NO_LOCK)
-     || (   (locktype==EXCLUSIVE_LOCK)
-         &amp;&amp; (pFile-&gt;locktype==RESERVED_LOCK))
+  if( pFile-&gt;locktype==NO_LOCK
+   || (locktype==EXCLUSIVE_LOCK &amp;&amp; pFile-&gt;locktype==RESERVED_LOCK)
   ){
     int cnt = 3;
     while( cnt--&gt;0 &amp;&amp; (res = LockFile(pFile-&gt;h, PENDING_BYTE, 0, 1, 0))==0 ){
@@ -28387,9 +27965,6 @@ static int winLock(sqlite3_file *id, int locktype){
       Sleep(1);
     }
     gotPendingLock = res;
-    if( !res ){
-      error = GetLastError();
-    }
   }
 
   /* Acquire a shared lock
@@ -28399,8 +27974,6 @@ static int winLock(sqlite3_file *id, int locktype){
     res = getReadLock(pFile);
     if( res ){
       newLocktype = SHARED_LOCK;
-    }else{
-      error = GetLastError();
     }
   }
 
@@ -28411,8 +27984,6 @@ static int winLock(sqlite3_file *id, int locktype){
     res = LockFile(pFile-&gt;h, RESERVED_BYTE, 0, 1, 0);
     if( res ){
       newLocktype = RESERVED_LOCK;
-    }else{
-      error = GetLastError();
     }
   }
 
@@ -28433,8 +28004,7 @@ static int winLock(sqlite3_file *id, int locktype){
     if( res ){
       newLocktype = EXCLUSIVE_LOCK;
     }else{
-      error = GetLastError();
-      OSTRACE2(&quot;error-code = %d\n&quot;, error);
+      OSTRACE2(&quot;error-code = %d\n&quot;, GetLastError());
       getReadLock(pFile);
     }
   }
@@ -28454,7 +28024,6 @@ static int winLock(sqlite3_file *id, int locktype){
   }else{
     OSTRACE4(&quot;LOCK FAILED %d trying for %d but got %d\n&quot;, pFile-&gt;h,
            locktype, newLocktype);
-    pFile-&gt;lastErrno = error;
     rc = SQLITE_BUSY;
   }
   pFile-&gt;locktype = (u8)newLocktype;
@@ -28535,10 +28104,6 @@ static int winFileControl(sqlite3_file *id, int op, void *pArg){
       *(int*)pArg = ((winFile*)id)-&gt;locktype;
       return SQLITE_OK;
     }
-    case SQLITE_LAST_ERRNO: {
-      *(int*)pArg = (int)((winFile*)id)-&gt;lastErrno;
-      return SQLITE_OK;
-    }
   }
   return SQLITE_ERROR;
 }
@@ -28818,7 +28383,6 @@ static int winOpen(
   memset(pFile, 0, sizeof(*pFile));
   pFile-&gt;pMethod = &amp;winIoMethod;
   pFile-&gt;h = h;
-  pFile-&gt;lastErrno = NO_ERROR;
 #if SQLITE_OS_WINCE
   if( (flags &amp; (SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_DB)) ==
                (SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_DB)
@@ -29131,7 +28695,7 @@ int winCurrentTime(sqlite3_vfs *pVfs, double *prNow){
   /* FILETIME structure is a 64-bit value representing the number of 
      100-nanosecond intervals since January 1, 1601 (= JD 2305813.5). 
   */
-  sqlite3_int64 timeW, timeF;
+  double now;
 #if SQLITE_OS_WINCE
   SYSTEMTIME time;
   GetSystemTime(&amp;time);
@@ -29143,28 +28707,11 @@ int winCurrentTime(sqlite3_vfs *pVfs, double *prNow){
   GetSystemTimeAsFileTime( &amp;ft );
 #endif
   UNUSED_PARAMETER(pVfs);
-#if defined(_MSC_VER)
-  timeW = (((sqlite3_int64)ft.dwHighDateTime)*4294967296) + ft.dwLowDateTime;
-  timeF = timeW % 864000000000;           /* fractional days (100-nanoseconds) */
-  timeW = timeW / 864000000000;           /* whole days */
-  timeW = timeW + 2305813;                /* add whole days (from 2305813.5) */
-  timeF = timeF + 432000000000;           /* add half a day (from 2305813.5) */
-  timeW = timeW + (timeF / 864000000000); /* add whole day if half day made one */
-  timeF = timeF % 864000000000;           /* compute new fractional days */
-  *prNow = (double)timeW + ((double)timeF / (double)864000000000);
-#else
-  timeW = (((sqlite3_int64)ft.dwHighDateTime)*4294967296LL) + ft.dwLowDateTime;
-  timeF = timeW % 864000000000LL;           /* fractional days (100-nanoseconds) */
-  timeW = timeW / 864000000000LL;           /* whole days */
-  timeW = timeW + 2305813;                  /* add whole days (from 2305813.5) */
-  timeF = timeF + 432000000000LL;           /* add half a day (from 2305813.5) */
-  timeW = timeW + (timeF / 864000000000LL); /* add whole day if half day made one */
-  timeF = timeF % 864000000000LL;           /* compute new fractional days */
-  *prNow = (double)timeW + ((double)timeF / (double)864000000000LL);
-#endif
+  now = ((double)ft.dwHighDateTime) * 4294967296.0; 
+  *prNow = (now + ft.dwLowDateTime)/864000000000.0 + 2305813.5;
 #ifdef SQLITE_TEST
   if( sqlite3_current_time ){
-    *prNow = ((double)sqlite3_current_time + (double)43200) / (double)86400 + (double)2440587;
+    *prNow = sqlite3_current_time/86400.0 + 2440587.5;
   }
 #endif
   return 0;
@@ -29277,7 +28824,7 @@ SQLITE_API int sqlite3_os_end(void){
 ** start of a transaction, and is thus usually less than a few thousand,
 ** but can be as large as 2 billion for a really big database.
 **
-** @(#) $Id: bitvec.c,v 1.13 2009/01/20 17:06:27 danielk1977 Exp $
+** @(#) $Id: bitvec.c,v 1.10 2009/01/02 21:39:39 drh Exp $
 */
 
 /* Size of the Bitvec structure in bytes. */
@@ -29517,14 +29064,6 @@ SQLITE_PRIVATE void sqlite3BitvecDestroy(Bitvec *p){
   sqlite3_free(p);
 }
 
-/*
-** Return the value of the iSize parameter specified when Bitvec *p
-** was created.
-*/
-SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec *p){
-  return p-&gt;iSize;
-}
-
 #ifndef SQLITE_OMIT_BUILTIN_TEST
 /*
 ** Let V[] be an array of unsigned characters sufficient to hold
@@ -29650,7 +29189,7 @@ bitvec_end:
 *************************************************************************
 ** This file implements that page cache.
 **
-** @(#) $Id: pcache.c,v 1.43 2009/01/23 16:45:01 danielk1977 Exp $
+** @(#) $Id: pcache.c,v 1.39 2008/12/04 20:40:10 drh Exp $
 */
 
 /*
@@ -29661,13 +29200,14 @@ struct PCache {
   PgHdr *pSynced;                     /* Last synced page in dirty page list */
   int nRef;                           /* Number of referenced pages */
   int nMax;                           /* Configured cache size */
+  int nMin;                           /* Configured minimum cache size */
   int szPage;                         /* Size of every page in this cache */
   int szExtra;                        /* Size of extra space for each page */
   int bPurgeable;                     /* True if pages are on backing store */
   int (*xStress)(void*,PgHdr*);       /* Call to try make a page clean */
   void *pStress;                      /* Argument to xStress */
   sqlite3_pcache *pCache;             /* Pluggable cache module */
-  PgHdr *pPage1;                      /* Reference to page 1 */
+  PgHdr *pPage1;
 };
 
 /*
@@ -29818,6 +29358,7 @@ SQLITE_PRIVATE void sqlite3PcacheOpen(
   p-&gt;xStress = xStress;
   p-&gt;pStress = pStress;
   p-&gt;nMax = 100;
+  p-&gt;nMin = 10;
 }
 
 /*
@@ -29899,21 +29440,14 @@ SQLITE_PRIVATE int sqlite3PcacheFetch(
   }
 
   if( pPage ){
-    if( !pPage-&gt;pData ){
-      memset(pPage, 0, sizeof(PgHdr) + pCache-&gt;szExtra);
-      pPage-&gt;pExtra = (void*)&amp;pPage[1];
-      pPage-&gt;pData = (void *)&amp;((char *)pPage)[sizeof(PgHdr) + pCache-&gt;szExtra];
-      pPage-&gt;pCache = pCache;
-      pPage-&gt;pgno = pgno;
-    }
-    assert( pPage-&gt;pCache==pCache );
-    assert( pPage-&gt;pgno==pgno );
-    assert( pPage-&gt;pExtra==(void *)&amp;pPage[1] );
-
     if( 0==pPage-&gt;nRef ){
       pCache-&gt;nRef++;
     }
     pPage-&gt;nRef++;
+    pPage-&gt;pData = (void*)&amp;pPage[1];
+    pPage-&gt;pExtra = (void*)&amp;((char*)pPage-&gt;pData)[pCache-&gt;szPage];
+    pPage-&gt;pCache = pCache;
+    pPage-&gt;pgno = pgno;
     if( pgno==1 ){
       pCache-&gt;pPage1 = pPage;
     }
@@ -30074,8 +29608,9 @@ SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){
 /* 
 ** Discard the contents of the cache.
 */
-SQLITE_PRIVATE void sqlite3PcacheClear(PCache *pCache){
+SQLITE_PRIVATE int sqlite3PcacheClear(PCache *pCache){
   sqlite3PcacheTruncate(pCache, 0);
+  return SQLITE_OK;
 }
 
 /*
@@ -30241,7 +29776,7 @@ SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHd
 ** If the default page cache implementation is overriden, then neither of
 ** these two features are available.
 **
-** @(#) $Id: pcache1.c,v 1.8 2009/01/23 16:45:01 danielk1977 Exp $
+** @(#) $Id: pcache1.c,v 1.7 2009/01/07 15:18:21 danielk1977 Exp $
 */
 
 
@@ -30425,6 +29960,7 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
   int nByte = sizeof(PgHdr1) + pCache-&gt;szPage;
   PgHdr1 *p = (PgHdr1 *)pcache1Alloc(nByte);
   if( p ){
+    memset(p, 0, nByte);
     if( pCache-&gt;bPurgeable ){
       pcache1.nCurrentPage++;
     }
@@ -30773,13 +30309,11 @@ static void *pcache1Fetch(sqlite3_pcache *p, unsigned int iKey, int createFlag){
 
   if( pPage ){
     unsigned int h = iKey % pCache-&gt;nHash;
-    *(void **)(PGHDR1_TO_PAGE(pPage)) = 0;
+    memset(pPage, 0, pCache-&gt;szPage + sizeof(PgHdr1));
     pCache-&gt;nPage++;
     pPage-&gt;iKey = iKey;
     pPage-&gt;pNext = pCache-&gt;apHash[h];
     pPage-&gt;pCache = pCache;
-    pPage-&gt;pLruPrev = 0;
-    pPage-&gt;pLruNext = 0;
     pCache-&gt;apHash[h] = pPage;
   }
 
@@ -31237,7 +30771,7 @@ SQLITE_PRIVATE int sqlite3RowSetNext(RowSet *p, i64 *pRowid){
 ** file simultaneously, or one process from reading the database while
 ** another is writing.
 **
-** @(#) $Id: pager.c,v 1.570 2009/02/17 17:56:30 danielk1977 Exp $
+** @(#) $Id: pager.c,v 1.551 2009/01/14 23:03:41 drh Exp $
 */
 #ifndef SQLITE_OMIT_DISKIO
 
@@ -31367,151 +30901,73 @@ struct PagerSavepoint {
 /*
 ** A open page cache is an instance of the following structure.
 **
-** errCode
-**
-**   Pager.errCode may be set to SQLITE_IOERR, SQLITE_CORRUPT, or
-**   or SQLITE_FULL. Once one of the first three errors occurs, it persists
-**   and is returned as the result of every major pager API call.  The
-**   SQLITE_FULL return code is slightly different. It persists only until the
-**   next successful rollback is performed on the pager cache. Also,
-**   SQLITE_FULL does not affect the sqlite3PagerGet() and sqlite3PagerLookup()
-**   APIs, they may still be used successfully.
-**
-** dbSizeValid, dbSize, dbOrigSize, dbFileSize
-**
-**   Managing the size of the database file in pages is a little complicated.
-**   The variable Pager.dbSize contains the number of pages that the database
-**   image currently contains. As the database image grows or shrinks this
-**   variable is updated. The variable Pager.dbFileSize contains the number
-**   of pages in the database file. This may be different from Pager.dbSize
-**   if some pages have been appended to the database image but not yet written
-**   out from the cache to the actual file on disk. Or if the image has been
-**   truncated by an incremental-vacuum operation. The Pager.dbOrigSize variable
-**   contains the number of pages in the database image when the current
-**   transaction was opened. The contents of all three of these variables is
-**   only guaranteed to be correct if the boolean Pager.dbSizeValid is true.
-**
-**   TODO: Under what conditions is dbSizeValid set? Cleared?
-**
-** changeCountDone
-**
-**   This boolean variable is used to make sure that the change-counter 
-**   (the 4-byte header field at byte offset 24 of the database file) is 
-**   not updated more often than necessary. 
-**
-**   It is set to true when the change-counter field is updated, which 
-**   can only happen if an exclusive lock is held on the database file.
-**   It is cleared (set to false) whenever an exclusive lock is 
-**   relinquished on the database file. Each time a transaction is committed,
-**   The changeCountDone flag is inspected. If it is true, the work of
-**   updating the change-counter is omitted for the current transaction.
-**
-**   This mechanism means that when running in exclusive mode, a connection 
-**   need only update the change-counter once, for the first transaction
-**   committed.
-**
-** dbModified
-**
-**   The dbModified flag is set whenever a database page is dirtied.
-**   It is cleared at the end of each transaction.
-**
-**   It is used when committing or otherwise ending a transaction. If
-**   the dbModified flag is clear then less work has to be done.
-**
-** journalStarted
-**
-**   This flag is set whenever the the main journal is synced. 
-**
-**   The point of this flag is that it must be set after the 
-**   first journal header in a journal file has been synced to disk.
-**   After this has happened, new pages appended to the database 
-**   do not need the PGHDR_NEED_SYNC flag set, as they do not need
-**   to wait for a journal sync before they can be written out to
-**   the database file (see function pager_write()).
-**   
-** setMaster
-**
-**   This variable is used to ensure that the master journal file name
-**   (if any) is only written into the journal file once.
-**
-**   When committing a transaction, the master journal file name (if any)
-**   may be written into the journal file while the pager is still in
-**   PAGER_RESERVED state (see CommitPhaseOne() for the action). It
-**   then attempts to upgrade to an exclusive lock. If this attempt
-**   fails, then SQLITE_BUSY may be returned to the user and the user
-**   may attempt to commit the transaction again later (calling
-**   CommitPhaseOne() again). This flag is used to ensure that the 
-**   master journal name is only written to the journal file the first
-**   time CommitPhaseOne() is called.
-**
-** doNotSync
-**
-**   This variable is set and cleared by sqlite3PagerWrite().
-**
-** needSync
-**
-**   TODO: It might be easier to set this variable in writeJournalHdr()
-**   and writeMasterJournal() only. Change its meaning to &quot;unsynced data
-**   has been written to the journal&quot;.
+** Pager.errCode may be set to SQLITE_IOERR, SQLITE_CORRUPT, or
+** or SQLITE_FULL. Once one of the first three errors occurs, it persists
+** and is returned as the result of every major pager API call.  The
+** SQLITE_FULL return code is slightly different. It persists only until the
+** next successful rollback is performed on the pager cache. Also,
+** SQLITE_FULL does not affect the sqlite3PagerGet() and sqlite3PagerLookup()
+** APIs, they may still be used successfully.
+**
+** Managing the size of the database file in pages is a little complicated.
+** The variable Pager.dbSize contains the number of pages that the database
+** image currently contains. As the database image grows or shrinks this
+** variable is updated. The variable Pager.dbFileSize contains the number
+** of pages in the database file. This may be different from Pager.dbSize
+** if some pages have been appended to the database image but not yet written
+** out from the cache to the actual file on disk. Or if the image has been
+** truncated by an incremental-vacuum operation. The Pager.dbOrigSize variable
+** contains the number of pages in the database image when the current
+** transaction was opened. The contents of all three of these variables is
+** only guaranteed to be correct if the boolean Pager.dbSizeValid is true.
 */
 struct Pager {
   sqlite3_vfs *pVfs;          /* OS functions to use for IO */
-  u8 exclusiveMode;           /* Boolean. True if locking_mode==EXCLUSIVE */
-  u8 journalMode;             /* On of the PAGER_JOURNALMODE_* values */
+  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 */
   u8 noReadlock;              /* Do not bother to obtain readlocks */
   u8 noSync;                  /* Do not sync the journal if true */
   u8 fullSync;                /* Do extra syncs of the journal for robustness */
   u8 sync_flags;              /* One of SYNC_NORMAL or SYNC_FULL */
+  u8 state;                   /* PAGER_UNLOCK, _SHARED, _RESERVED, etc. */
   u8 tempFile;                /* zFilename is a temporary file */
   u8 readOnly;                /* True for a read-only database */
-  u8 memDb;                   /* True to inhibit all file I/O */
-
-  /* The following block contains those class members that are dynamically
-  ** modified during normal operations. The other variables in this structure
-  ** are either constant throughout the lifetime of the pager, or else
-  ** used to store configuration parameters that affect the way the pager 
-  ** operates.
-  **
-  ** The 'state' variable is described in more detail along with the
-  ** descriptions of the values it may take - PAGER_UNLOCK etc. Many of the
-  ** other variables in this block are described in the comment directly 
-  ** above this class definition.
-  */
-  u8 state;                   /* PAGER_UNLOCK, _SHARED, _RESERVED, etc. */
-  u8 dbModified;              /* True if there are any changes to the Db */
   u8 needSync;                /* True if an fsync() is needed on the journal */
-  u8 journalStarted;          /* True if header of journal is synced */
-  u8 changeCountDone;         /* Set after incrementing the change-counter */
+  u8 dirtyCache;              /* True if cached pages have changed */
+  u8 memDb;                   /* True to inhibit all file I/O */
   u8 setMaster;               /* True if a m-j name has been written to jrnl */
   u8 doNotSync;               /* Boolean. While true, do not spill the cache */
+  u8 exclusiveMode;           /* Boolean. True if locking_mode==EXCLUSIVE */
+  u8 journalMode;             /* On of the PAGER_JOURNALMODE_* values */
+  u8 dbModified;              /* True if there are any changes to the Db */
+  u8 changeCountDone;         /* Set after incrementing the change-counter */
   u8 dbSizeValid;             /* Set when dbSize is correct */
   Pgno dbSize;                /* Number of pages in the database */
   Pgno dbOrigSize;            /* dbSize before the current transaction */
   Pgno dbFileSize;            /* Number of pages in the database file */
+  u32 vfsFlags;               /* Flags for sqlite3_vfs.xOpen() */
   int errCode;                /* One of several kinds of errors */
-  int nRec;                   /* Pages journalled since last j-header written */
+  int nRec;                   /* Number of pages written to the journal */
   u32 cksumInit;              /* Quasi-random value added to every checksum */
-  u32 nSubRec;                /* Number of records written to sub-journal */
-  Bitvec *pInJournal;         /* One bit for each page in the database file */
-  sqlite3_file *fd;           /* File descriptor for database */
-  sqlite3_file *jfd;          /* File descriptor for main journal */
-  sqlite3_file *sjfd;         /* File descriptor for sub-journal */
-  i64 journalOff;             /* Current write offset in the journal file */
-  i64 journalHdr;             /* Byte offset to previous journal header */
-  PagerSavepoint *aSavepoint; /* Array of active savepoints */
-  int nSavepoint;             /* Number of elements in aSavepoint[] */
-  char dbFileVers[16];        /* Changes whenever database file changes */
-  u32 sectorSize;             /* Assumed sector size during rollback */
-
+  int stmtNRec;               /* Number of records in stmt subjournal */
   int nExtra;                 /* Add this many bytes to each in-memory page */
-  u32 vfsFlags;               /* Flags for sqlite3_vfs.xOpen() */
   int pageSize;               /* Number of bytes in a page */
+  int nPage;                  /* Total number of in-memory pages */
+  int mxPage;                 /* Maximum number of pages to hold in cache */
   Pgno mxPgno;                /* Maximum allowed size of the database */
+  Bitvec *pInJournal;         /* One bit for each page in the database file */
+  Bitvec *pAlwaysRollback;    /* One bit for each page marked always-rollback */
   char *zFilename;            /* Name of the database file */
   char *zJournal;             /* Name of the journal file */
+  char *zDirectory;           /* Directory hold database and journal files */
+  sqlite3_file *fd, *jfd;     /* File descriptors for database and journal */
+  sqlite3_file *sjfd;         /* File descriptor for the sub-journal*/
   int (*xBusyHandler)(void*); /* Function to call when busy */
   void *pBusyHandlerArg;      /* Context argument for xBusyHandler */
+  i64 journalOff;             /* Current byte offset in the journal file */
+  i64 journalHdr;             /* Byte offset to previous journal header */
+  u32 sectorSize;             /* Assumed sector size during rollback */
 #ifdef SQLITE_TEST
   int nHit, nMiss;            /* Cache hits and missing */
   int nRead, nWrite;          /* Database pages read/written */
@@ -31522,9 +30978,11 @@ struct Pager {
   void *pCodecArg;            /* First argument to xCodec() */
 #endif
   char *pTmpSpace;            /* Pager.pageSize bytes of space for tmp use */
+  char dbFileVers[16];        /* Changes whenever database file changes */
   i64 journalSizeLimit;       /* Size limit for persistent journal files */
   PCache *pPCache;            /* Pointer to page cache object */
-  sqlite3_backup *pBackup;    /* Pointer to list of ongoing backup processes */
+  PagerSavepoint *aSavepoint; /* Array of active savepoints */
+  int nSavepoint;             /* Number of elements in aSavepoint[] */
 };
 
 /*
@@ -31571,14 +31029,15 @@ static const unsigned char aJournalMagic[] = {
 };
 
 /*
-** The size of the of each page record in the journal is given by
-** the following macro.
+** The size of the header and of each page in the journal is determined
+** by the following macros.
 */
 #define JOURNAL_PG_SZ(pPager)  ((pPager-&gt;pageSize) + 8)
 
 /*
-** The journal header size for this pager. This is usually the same 
-** size as a single disk sector. See also setSectorSize().
+** The journal header size for this pager. In the future, this could be
+** set to some value read from the disk controller. The important
+** characteristic is that it is the same size as a disk sector.
 */
 #define JOURNAL_HDR_SZ(pPager) (pPager-&gt;sectorSize)
 
@@ -31595,27 +31054,19 @@ static const unsigned char aJournalMagic[] = {
 #endif
 
 /*
-** The maximum legal page number is (2^31 - 1).
+** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
+** reserved for working around a windows/posix incompatibility). It is
+** used in the journal to signify that the remainder of the journal file 
+** is devoted to storing a master journal name - there are no more pages to
+** roll back. See comments for function writeMasterJournal() for details.
 */
-#define PAGER_MAX_PGNO 2147483647
+/* #define PAGER_MJ_PGNO(x) (PENDING_BYTE/((x)-&gt;pageSize)) */
+#define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)-&gt;pageSize))+1))
 
-#ifndef NDEBUG 
 /*
-** Usage:
-**
-**   assert( assert_pager_state(pPager) );
+** The maximum legal page number is (2^31 - 1).
 */
-static int assert_pager_state(Pager *pPager){
-
-  /* A temp-file is always in PAGER_EXCLUSIVE or PAGER_SYNCED state. */
-  assert( pPager-&gt;tempFile==0 || pPager-&gt;state&gt;=PAGER_EXCLUSIVE );
-
-  /* The changeCountDone flag is always set for temp-files */
-  assert( pPager-&gt;tempFile==0 || pPager-&gt;changeCountDone );
-
-  return 1;
-}
-#endif
+#define PAGER_MAX_PGNO 2147483647
 
 /*
 ** Return true if it is necessary to write page *pPg into the sub-journal.
@@ -31678,24 +31129,10 @@ static int write32bits(sqlite3_file *fd, i64 offset, u32 val){
 }
 
 /*
-** The argument to this macro is a file descriptor (type sqlite3_file*).
-** Return 0 if it is not open, or non-zero (but not 1) if it is.
-**
-** This is so that expressions can be written as:
-**
-**   if( isOpen(pPager-&gt;jfd) ){ ...
-**
-** instead of
-**
-**   if( pPager-&gt;jfd-&gt;pMethods ){ ...
-*/
-#define isOpen(pFd) ((pFd)-&gt;pMethods)
-
-/*
 ** If file pFd is open, call sqlite3OsUnlock() on it.
 */
 static int osUnlock(sqlite3_file *pFd, int eLock){
-  if( !isOpen(pFd) ){
+  if( !pFd-&gt;pMethods ){
     return SQLITE_OK;
   }
   return sqlite3OsUnlock(pFd, eLock);
@@ -31710,39 +31147,79 @@ static int osUnlock(sqlite3_file *pFd, int eLock){
 **  (b) the value returned by OsSectorSize() is less than or equal
 **      to the page size.
 **
-** The optimization is also always enabled for temporary files. It is
-** an error to call this function if pPager is opened on an in-memory
-** database.
-**
 ** If the optimization cannot be used, 0 is returned. If it can be used,
 ** then the value returned is the size of the journal file when it
 ** contains rollback data for exactly one page.
 */
 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
 static int jrnlBufferSize(Pager *pPager){
-  assert( !MEMDB );
-  if( !pPager-&gt;tempFile ){
-    int dc;                           /* Device characteristics */
-    int nSector;                      /* Sector size */
-    int szPage;                       /* Page size */
+  int dc;           /* Device characteristics */
+  int nSector;      /* Sector size */
+  int szPage;        /* Page size */
+  sqlite3_file *fd = pPager-&gt;fd;
 
-    assert( isOpen(pPager-&gt;fd) );
-    dc = sqlite3OsDeviceCharacteristics(pPager-&gt;fd);
+  if( fd-&gt;pMethods ){
+    dc = sqlite3OsDeviceCharacteristics(fd);
     nSector = pPager-&gt;sectorSize;
     szPage = pPager-&gt;pageSize;
-
-    assert(SQLITE_IOCAP_ATOMIC512==(512&gt;&gt;8));
-    assert(SQLITE_IOCAP_ATOMIC64K==(65536&gt;&gt;8));
-    if( 0==(dc&amp;(SQLITE_IOCAP_ATOMIC|(szPage&gt;&gt;8)) || nSector&gt;szPage) ){
-      return 0;
-    }
   }
 
-  return JOURNAL_HDR_SZ(pPager) + JOURNAL_PG_SZ(pPager);
+  assert(SQLITE_IOCAP_ATOMIC512==(512&gt;&gt;8));
+  assert(SQLITE_IOCAP_ATOMIC64K==(65536&gt;&gt;8));
+
+  if( !fd-&gt;pMethods || 
+       (dc &amp; (SQLITE_IOCAP_ATOMIC|(szPage&gt;&gt;8)) &amp;&amp; nSector&lt;=szPage) ){
+    return JOURNAL_HDR_SZ(pPager) + JOURNAL_PG_SZ(pPager);
+  }
+  return 0;
 }
 #endif
 
 /*
+** This function should be called when an error occurs within the pager
+** code. The first argument is a pointer to the pager structure, the
+** second the error-code about to be returned by a pager API function. 
+** The value returned is a copy of the second argument to this function. 
+**
+** If the second argument is SQLITE_IOERR, SQLITE_CORRUPT, or SQLITE_FULL
+** the error becomes persistent. Until the persisten error is cleared,
+** subsequent API calls on this Pager will immediately return the same 
+** error code.
+**
+** A persistent error indicates that the contents of the pager-cache 
+** cannot be trusted. This state can be cleared by completely discarding 
+** the contents of the pager-cache. If a transaction was active when
+** the persistent error occured, then the rollback journal may need
+** to be replayed.
+*/
+static void pager_unlock(Pager *pPager);
+static int pager_error(Pager *pPager, int rc){
+  int rc2 = rc &amp; 0xff;
+  assert(
+       pPager-&gt;errCode==SQLITE_FULL ||
+       pPager-&gt;errCode==SQLITE_OK ||
+       (pPager-&gt;errCode &amp; 0xff)==SQLITE_IOERR
+  );
+  if(
+    rc2==SQLITE_FULL ||
+    rc2==SQLITE_IOERR ||
+    rc2==SQLITE_CORRUPT
+  ){
+    pPager-&gt;errCode = rc;
+    if( pPager-&gt;state==PAGER_UNLOCK 
+     &amp;&amp; sqlite3PcacheRefCount(pPager-&gt;pPCache)==0 
+    ){
+      /* If the pager is already unlocked, call pager_unlock() now to
+      ** clear the error state and ensure that the pager-cache is 
+      ** completely empty.
+      */
+      pager_unlock(pPager);
+    }
+  }
+  return rc;
+}
+
+/*
 ** If SQLITE_CHECK_PAGES is defined then we do some sanity checking
 ** on the cache using a hash function.  This is used for testing
 ** and debugging only.
@@ -31786,10 +31263,8 @@ static void checkPage(PgHdr *pPg){
 
 /*
 ** When this is called the journal file for pager pPager must be open.
-** This function attempts to read a master journal file name from the 
-** end of the file and, if successful, copies it into memory supplied 
-** by the caller. See comments above writeMasterJournal() for the format
-** used to store a master journal file name at the end of a journal file.
+** The master journal file name is read from the end of the file and 
+** written into memory supplied by the caller. 
 **
 ** zMaster must point to a buffer of at least nMaster bytes allocated by
 ** the caller. This should be sqlite3_vfs.mxPathname+1 (to ensure there is
@@ -31798,68 +31273,70 @@ static void checkPage(PgHdr *pPg){
 ** nul-terminator), then this is handled as if no master journal name
 ** were present in the journal.
 **
-** If a master journal file name is present at the end of the journal
-** file, then it is copied into the buffer pointed to by zMaster. A
-** nul-terminator byte is appended to the buffer following the master
-** journal file name.
-**
-** If it is determined that no master journal file name is present 
-** zMaster[0] is set to 0 and SQLITE_OK returned.
-**
-** If an error occurs while reading from the journal file, an SQLite
-** error code is returned.
+** If no master journal file name is present zMaster[0] is set to 0 and
+** SQLITE_OK returned.
 */
 static int readMasterJournal(sqlite3_file *pJrnl, char *zMaster, u32 nMaster){
-  int rc;                    /* Return code */
-  u32 len;                   /* Length in bytes of master journal name */
-  i64 szJ;                   /* Total size in bytes of journal file pJrnl */
-  u32 cksum;                 /* MJ checksum value read from journal */
-  u32 u;                     /* Unsigned loop counter */
-  unsigned char aMagic[8];   /* A buffer to hold the magic header */
+  int rc;
+  u32 len;
+  i64 szJ;
+  u32 cksum;
+  u32 u;                   /* Unsigned loop counter */
+  unsigned char aMagic[8]; /* A buffer to hold the magic header */
+
   zMaster[0] = '\0';
 
-  if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &amp;szJ))
-   || szJ&lt;16
-   || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &amp;len))
-   || len&gt;=nMaster 
-   || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &amp;cksum))
-   || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
-   || memcmp(aMagic, aJournalMagic, 8)
-   || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zMaster, len, szJ-16-len))
-  ){
+  rc = sqlite3OsFileSize(pJrnl, &amp;szJ);
+  if( rc!=SQLITE_OK || szJ&lt;16 ) return rc;
+
+  rc = read32bits(pJrnl, szJ-16, &amp;len);
+  if( rc!=SQLITE_OK ) return rc;
+
+  if( len&gt;=nMaster ){
+    return SQLITE_OK;
+  }
+
+  rc = read32bits(pJrnl, szJ-12, &amp;cksum);
+  if( rc!=SQLITE_OK ) return rc;
+
+  rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8);
+  if( rc!=SQLITE_OK || memcmp(aMagic, aJournalMagic, 8) ) return rc;
+
+  rc = sqlite3OsRead(pJrnl, zMaster, len, szJ-16-len);
+  if( rc!=SQLITE_OK ){
     return rc;
   }
+  zMaster[len] = '\0';
 
   /* See if the checksum matches the master journal name */
   for(u=0; u&lt;len; u++){
     cksum -= zMaster[u];
-  }
+   }
   if( cksum ){
     /* If the checksum doesn't add up, then one or more of the disk sectors
     ** containing the master journal filename is corrupted. This means
     ** definitely roll back, so just return SQLITE_OK and report a (nul)
     ** master-journal filename.
     */
-    len = 0;
+    zMaster[0] = '\0';
   }
-  zMaster[len] = '\0';
    
   return SQLITE_OK;
 }
 
 /*
-** Return the offset of the sector boundary at or immediately 
-** following the value in pPager-&gt;journalOff, assuming a sector 
-** size of pPager-&gt;sectorSize bytes.
+** Seek the journal file descriptor to the next sector boundary where a
+** journal header may be read or written. Pager.journalOff is updated with
+** the new seek offset.
 **
 ** i.e for a sector size of 512:
 **
-**   Pager.journalOff          Return value
-**   ---------------------------------------
-**   0                         0
-**   512                       512
-**   100                       512
-**   2000                      2048
+** Input Offset              Output Offset
+** ---------------------------------------
+** 0                         0
+** 512                       512
+** 100                       512
+** 2000                      2048
 ** 
 */
 static i64 journalHdrOffset(Pager *pPager){
@@ -31873,39 +31350,26 @@ static i64 journalHdrOffset(Pager *pPager){
   assert( (offset-c)&lt;JOURNAL_HDR_SZ(pPager) );
   return offset;
 }
+static void seekJournalHdr(Pager *pPager){
+  pPager-&gt;journalOff = journalHdrOffset(pPager);
+}
 
 /*
-** The journal file must be open when this function is called.
-**
-** This function is a no-op if the journal file has not been written to
-** within the current transaction (i.e. if Pager.journalOff==0).
-**
-** If doTruncate is non-zero or the Pager.journalSizeLimit variable is
-** set to 0, then truncate the journal file to zero bytes in size. Otherwise,
-** zero the 28-byte header at the start of the journal file. In either case, 
-** if the pager is not in no-sync mode, sync the journal file immediately 
-** after writing or truncating it.
-**
-** If Pager.journalSizeLimit is set to a positive, non-zero value, and
-** following the truncation or zeroing described above the size of the 
-** journal file in bytes is larger than this value, then truncate the
-** journal file to Pager.journalSizeLimit bytes. The journal file does
-** not need to be synced following this operation.
-**
-** If an IO error occurs, abandon processing and return the IO error code.
-** Otherwise, return SQLITE_OK.
+** Write zeros over the header of the journal file.  This has the
+** effect of invalidating the journal file and committing the
+** transaction.
 */
 static int zeroJournalHdr(Pager *pPager, int doTruncate){
-  int rc = SQLITE_OK;                               /* Return code */
-  assert( isOpen(pPager-&gt;jfd) );
+  int rc = SQLITE_OK;
+  static const char zeroHdr[28] = {0};
+
   if( pPager-&gt;journalOff ){
-    const i64 iLimit = pPager-&gt;journalSizeLimit;    /* Local cache of jsl */
+    i64 iLimit = pPager-&gt;journalSizeLimit;
 
     IOTRACE((&quot;JZEROHDR %p\n&quot;, pPager))
     if( doTruncate || iLimit==0 ){
       rc = sqlite3OsTruncate(pPager-&gt;jfd, 0);
     }else{
-      static const char zeroHdr[28] = {0};
       rc = sqlite3OsWrite(pPager-&gt;jfd, zeroHdr, sizeof(zeroHdr), 0);
     }
     if( rc==SQLITE_OK &amp;&amp; !pPager-&gt;noSync ){
@@ -31945,21 +31409,19 @@ static int zeroJournalHdr(Pager *pPager, int doTruncate){
 ** Followed by (JOURNAL_HDR_SZ - 28) bytes of unused space.
 */
 static int writeJournalHdr(Pager *pPager){
-  int rc = SQLITE_OK;                 /* Return code */
-  char *zHeader = pPager-&gt;pTmpSpace;  /* Temporary space used to build header */
-  u32 nHeader = pPager-&gt;pageSize;     /* Size of buffer pointed to by zHeader */
-  u32 nWrite;                         /* Bytes of header sector written */
-  int ii;                             /* Loop counter */
-
-  assert( isOpen(pPager-&gt;jfd) );      /* Journal file must be open. */
+  int rc = SQLITE_OK;
+  char *zHeader = pPager-&gt;pTmpSpace;
+  u32 nHeader = pPager-&gt;pageSize;
+  u32 nWrite;
+  int ii;
 
   if( nHeader&gt;JOURNAL_HDR_SZ(pPager) ){
     nHeader = JOURNAL_HDR_SZ(pPager);
   }
 
-  /* If there are active savepoints and any of them were created 
-  ** since the most recent journal header was written, update the 
-  ** PagerSavepoint.iHdrOffset fields now.
+  /* If there are active savepoints and any of them were created since the
+  ** most recent journal header was written, update the PagerSavepoint.iHdrOff
+  ** fields now.
   */
   for(ii=0; ii&lt;pPager-&gt;nSavepoint; ii++){
     if( pPager-&gt;aSavepoint[ii].iHdrOffset==0 ){
@@ -31967,7 +31429,9 @@ static int writeJournalHdr(Pager *pPager){
     }
   }
 
-  pPager-&gt;journalHdr = pPager-&gt;journalOff = journalHdrOffset(pPager);
+  seekJournalHdr(pPager);
+  pPager-&gt;journalHdr = pPager-&gt;journalOff;
+
   memcpy(zHeader, aJournalMagic, sizeof(aJournalMagic));
 
   /* 
@@ -31990,7 +31454,7 @@ static int writeJournalHdr(Pager *pPager){
   **   * When the SQLITE_IOCAP_SAFE_APPEND flag is set. This guarantees
   **     that garbage data is never appended to the journal file.
   */
-  assert( isOpen(pPager-&gt;fd) || pPager-&gt;noSync );
+  assert(pPager-&gt;fd-&gt;pMethods||pPager-&gt;noSync);
   if( (pPager-&gt;noSync) || (pPager-&gt;journalMode==PAGER_JOURNALMODE_MEMORY)
    || (sqlite3OsDeviceCharacteristics(pPager-&gt;fd)&amp;SQLITE_IOCAP_SAFE_APPEND) 
   ){
@@ -32007,34 +31471,19 @@ static int writeJournalHdr(Pager *pPager){
   /* The assumed sector size for this process */
   put32bits(&amp;zHeader[sizeof(aJournalMagic)+12], pPager-&gt;sectorSize);
 
-  /* The page size */
-  put32bits(&amp;zHeader[sizeof(aJournalMagic)+16], pPager-&gt;pageSize);
-
   /* Initializing the tail of the buffer is not necessary.  Everything
   ** works find if the following memset() is omitted.  But initializing
   ** the memory prevents valgrind from complaining, so we are willing to
   ** take the performance hit.
   */
-  memset(&amp;zHeader[sizeof(aJournalMagic)+20], 0,
-         nHeader-(sizeof(aJournalMagic)+20));
+  memset(&amp;zHeader[sizeof(aJournalMagic)+16], 0,
+         nHeader-(sizeof(aJournalMagic)+16));
+
+  if( pPager-&gt;journalHdr==0 ){
+    /* The page size */
+    put32bits(&amp;zHeader[sizeof(aJournalMagic)+16], pPager-&gt;pageSize);
+  }
 
-  /* In theory, it is only necessary to write the 28 bytes that the 
-  ** journal header consumes to the journal file here. Then increment the 
-  ** Pager.journalOff variable by JOURNAL_HDR_SZ so that the next 
-  ** record is written to the following sector (leaving a gap in the file
-  ** that will be implicitly filled in by the OS).
-  **
-  ** However it has been discovered that on some systems this pattern can 
-  ** be significantly slower than contiguously writing data to the file,
-  ** even if that means explicitly writing data to the block of 
-  ** (JOURNAL_HDR_SZ - 28) bytes that will not be used. So that is what
-  ** is done. 
-  **
-  ** The loop is required here in case the sector-size is larger than the 
-  ** database page size. Since the zHeader buffer is only Pager.pageSize
-  ** bytes in size, more than one call to sqlite3OsWrite() may be required
-  ** to populate the entire journal header sector.
-  */ 
   for(nWrite=0; rc==SQLITE_OK&amp;&amp;nWrite&lt;JOURNAL_HDR_SZ(pPager); nWrite+=nHeader){
     IOTRACE((&quot;JHDR %p %lld %d\n&quot;, pPager, pPager-&gt;journalHdr, nHeader))
     rc = sqlite3OsWrite(pPager-&gt;jfd, zHeader, nHeader, pPager-&gt;journalOff);
@@ -32048,114 +31497,93 @@ static int writeJournalHdr(Pager *pPager){
 ** The journal file must be open when this is called. A journal header file
 ** (JOURNAL_HDR_SZ bytes) is read from the current location in the journal
 ** file. The current location in the journal file is given by
-** pPager-&gt;journalOff. See comments above function writeJournalHdr() for
+** pPager-&gt;journalOff.  See comments above function writeJournalHdr() for
 ** a description of the journal header format.
 **
-** If the header is read successfully, *pNRec is set to the number of
-** page records following this header and *pDbSize is set to the size of the
+** If the header is read successfully, *nRec is set to the number of
+** page records following this header and *dbSize is set to the size of the
 ** database before the transaction began, in pages. Also, pPager-&gt;cksumInit
 ** is set to the value read from the journal header. SQLITE_OK is returned
 ** in this case.
 **
 ** If the journal header file appears to be corrupted, SQLITE_DONE is
-** returned and *pNRec and *PDbSize are undefined.  If JOURNAL_HDR_SZ bytes
+** returned and *nRec and *dbSize are undefined.  If JOURNAL_HDR_SZ bytes
 ** cannot be read from the journal file an error code is returned.
 */
 static int readJournalHdr(
-  Pager *pPager,               /* Pager object */
-  i64 journalSize,             /* Size of the open journal file in bytes */
-  u32 *pNRec,                  /* OUT: Value read from the nRec field */
-  u32 *pDbSize                 /* OUT: Value of original database size field */
+  Pager *pPager, 
+  i64 journalSize,
+  u32 *pNRec, 
+  u32 *pDbSize
 ){
-  int rc;                      /* Return code */
-  unsigned char aMagic[8];     /* A buffer to hold the magic header */
-  i64 iHdrOff;                 /* Offset of journal header being read */
-
-  assert( isOpen(pPager-&gt;jfd) );      /* Journal file must be open. */
+  int rc;
+  unsigned char aMagic[8]; /* A buffer to hold the magic header */
+  i64 jrnlOff;
+  u32 iPageSize;
+  u32 iSectorSize;
 
-  /* Advance Pager.journalOff to the start of the next sector. If the
-  ** journal file is too small for there to be a header stored at this
-  ** point, return SQLITE_DONE.
-  */
-  pPager-&gt;journalOff = journalHdrOffset(pPager);
+  seekJournalHdr(pPager);
   if( pPager-&gt;journalOff+JOURNAL_HDR_SZ(pPager) &gt; journalSize ){
     return SQLITE_DONE;
   }
-  iHdrOff = pPager-&gt;journalOff;
+  jrnlOff = pPager-&gt;journalOff;
+
+  rc = sqlite3OsRead(pPager-&gt;jfd, aMagic, sizeof(aMagic), jrnlOff);
+  if( rc ) return rc;
+  jrnlOff += sizeof(aMagic);
 
-  /* Read in the first 8 bytes of the journal header. If they do not match
-  ** the  magic string found at the start of each journal header, return
-  ** SQLITE_DONE. If an IO error occurs, return an error code. Otherwise,
-  ** proceed.
-  */
-  rc = sqlite3OsRead(pPager-&gt;jfd, aMagic, sizeof(aMagic), iHdrOff);
-  if( rc ){
-    return rc;
-  }
   if( memcmp(aMagic, aJournalMagic, sizeof(aMagic))!=0 ){
     return SQLITE_DONE;
   }
 
-  /* Read the first three 32-bit fields of the journal header: The nRec
-  ** field, the checksum-initializer and the database size at the start
-  ** of the transaction. Return an error code if anything goes wrong.
-  */
-  if( SQLITE_OK!=(rc = read32bits(pPager-&gt;jfd, iHdrOff+8, pNRec))
-   || SQLITE_OK!=(rc = read32bits(pPager-&gt;jfd, iHdrOff+12, &amp;pPager-&gt;cksumInit))
-   || SQLITE_OK!=(rc = read32bits(pPager-&gt;jfd, iHdrOff+16, pDbSize))
-  ){
-    return rc;
-  }
+  rc = read32bits(pPager-&gt;jfd, jrnlOff, pNRec);
+  if( rc ) return rc;
 
-  if( pPager-&gt;journalOff==0 ){
-    u32 iPageSize;               /* Page-size field of journal header */
-    u32 iSectorSize;             /* Sector-size field of journal header */
-    u16 iPageSize16;             /* Copy of iPageSize in 16-bit variable */
+  rc = read32bits(pPager-&gt;jfd, jrnlOff+4, &amp;pPager-&gt;cksumInit);
+  if( rc ) return rc;
 
-    /* Read the page-size and sector-size journal header fields. */
-    if( SQLITE_OK!=(rc = read32bits(pPager-&gt;jfd, iHdrOff+20, &amp;iSectorSize))
-     || SQLITE_OK!=(rc = read32bits(pPager-&gt;jfd, iHdrOff+24, &amp;iPageSize))
-    ){
-      return rc;
-    }
+  rc = read32bits(pPager-&gt;jfd, jrnlOff+8, pDbSize);
+  if( rc ) return rc;
 
-    /* Check that the values read from the page-size and sector-size fields
-    ** are within range. To be 'in range', both values need to be a power
-    ** of two greater than or equal to 512, and not greater than their 
-    ** respective compile time maximum limits.
-    */
-    if( iPageSize&lt;512                  || iSectorSize&lt;512
-     || iPageSize&gt;SQLITE_MAX_PAGE_SIZE || iSectorSize&gt;MAX_SECTOR_SIZE
-     || ((iPageSize-1)&amp;iPageSize)!=0   || ((iSectorSize-1)&amp;iSectorSize)!=0 
+  if( pPager-&gt;journalOff==0 ){
+    rc = read32bits(pPager-&gt;jfd, jrnlOff+16, &amp;iPageSize);
+    if( rc ) return rc;
+
+    if( iPageSize&lt;512 
+     || iPageSize&gt;SQLITE_MAX_PAGE_SIZE 
+     || ((iPageSize-1)&amp;iPageSize)!=0 
     ){
-      /* If the either the page-size or sector-size in the journal-header is 
-      ** invalid, then the process that wrote the journal-header must have 
-      ** crashed before the header was synced. In this case stop reading 
-      ** the journal file here.
+      /* If the page-size in the journal-header is invalid, then the process
+      ** that wrote the journal-header must have crashed before the header
+      ** was synced. In this case stop reading the journal file here.
       */
-      return SQLITE_DONE;
+      rc = SQLITE_DONE;
+    }else{
+      u16 pagesize = (u16)iPageSize;
+      rc = sqlite3PagerSetPagesize(pPager, &amp;pagesize);
+      assert( rc!=SQLITE_OK || pagesize==(u16)iPageSize );
     }
-
-    /* Update the page-size to match the value read from the journal. 
-    ** Use a testcase() macro to make sure that malloc failure within 
-    ** PagerSetPagesize() is tested.
-    */
-    iPageSize16 = (u16)iPageSize;
-    rc = sqlite3PagerSetPagesize(pPager, &amp;iPageSize16);
-    testcase( rc!=SQLITE_OK );
-    assert( rc!=SQLITE_OK || iPageSize16==(u16)iPageSize );
-
+    if( rc ) return rc;
+  
     /* Update the assumed sector-size to match the value used by 
     ** the process that created this journal. If this journal was
     ** created by a process other than this one, then this routine
     ** is being called from within pager_playback(). The local value
     ** of Pager.sectorSize is restored at the end of that routine.
     */
+    rc = read32bits(pPager-&gt;jfd, jrnlOff+12, &amp;iSectorSize);
+    if( rc ) return rc;
+    if( (iSectorSize&amp;(iSectorSize-1))
+      || iSectorSize&lt;512
+      || iSectorSize&gt;MAX_SECTOR_SIZE
+    ){
+      return SQLITE_DONE;
+    }
     pPager-&gt;sectorSize = iSectorSize;
   }
 
   pPager-&gt;journalOff += JOURNAL_HDR_SZ(pPager);
-  return rc;
+  return SQLITE_OK;
 }
 
 
@@ -32166,37 +31594,34 @@ static int readJournalHdr(
 ** journal file descriptor is advanced to the next sector boundary before
 ** anything is written. The format is:
 **
-**   + 4 bytes: PAGER_MJ_PGNO.
-**   + N bytes: Master journal filename in utf-8.
-**   + 4 bytes: N (length of master journal name in bytes, no nul-terminator).
-**   + 4 bytes: Master journal name checksum.
-**   + 8 bytes: aJournalMagic[].
+** + 4 bytes: PAGER_MJ_PGNO.
+** + N bytes: length of master journal name.
+** + 4 bytes: N
+** + 4 bytes: Master journal name checksum.
+** + 8 bytes: aJournalMagic[].
 **
 ** The master journal page checksum is the sum of the bytes in the master
-** journal name, where each byte is interpreted as a signed 8-bit integer.
+** journal name.
 **
 ** If zMaster is a NULL pointer (occurs for a single database transaction), 
 ** this call is a no-op.
 */
 static int writeMasterJournal(Pager *pPager, const char *zMaster){
-  int rc;                          /* Return code */
-  int nMaster;                     /* Length of string zMaster */
-  i64 iHdrOff;                     /* Offset of header in journal file */
-  i64 jrnlSize;                    /* Size of journal file on disk */
-  u32 cksum = 0;                   /* Checksum of string zMaster */
-
-  if( !zMaster || pPager-&gt;setMaster
-   || pPager-&gt;journalMode==PAGER_JOURNALMODE_MEMORY 
-   || pPager-&gt;journalMode==PAGER_JOURNALMODE_OFF 
-  ){
-    return SQLITE_OK;
-  }
+  int rc;
+  int len; 
+  int i; 
+  i64 jrnlOff;
+  i64 jrnlSize;
+  u32 cksum = 0;
+  char zBuf[sizeof(aJournalMagic)+2*4];
+
+  if( !zMaster || pPager-&gt;setMaster ) return SQLITE_OK;
+  if( pPager-&gt;journalMode==PAGER_JOURNALMODE_MEMORY ) return SQLITE_OK;
   pPager-&gt;setMaster = 1;
-  assert( isOpen(pPager-&gt;jfd) );
 
-  /* Calculate the length in bytes and the checksum of zMaster */
-  for(nMaster=0; zMaster[nMaster]; nMaster++){
-    cksum += zMaster[nMaster];
+  len = sqlite3Strlen30(zMaster);
+  for(i=0; i&lt;len; i++){
+    cksum += zMaster[i];
   }
 
   /* If in full-sync mode, advance to the next disk sector before writing
@@ -32204,22 +31629,24 @@ static int writeMasterJournal(Pager *pPager, const char *zMaster){
   ** the journal has already been synced.
   */
   if( pPager-&gt;fullSync ){
-    pPager-&gt;journalOff = journalHdrOffset(pPager);
+    seekJournalHdr(pPager);
   }
-  iHdrOff = pPager-&gt;journalOff;
+  jrnlOff = pPager-&gt;journalOff;
+  pPager-&gt;journalOff += (len+20);
 
-  /* Write the master journal data to the end of the journal file. If
-  ** an error occurs, return the error code to the caller.
-  */
-  if( (0 != (rc = write32bits(pPager-&gt;jfd, iHdrOff, PAGER_MJ_PGNO(pPager))))
-   || (0 != (rc = sqlite3OsWrite(pPager-&gt;jfd, zMaster, nMaster, iHdrOff+4)))
-   || (0 != (rc = write32bits(pPager-&gt;jfd, iHdrOff+4+nMaster, nMaster)))
-   || (0 != (rc = write32bits(pPager-&gt;jfd, iHdrOff+4+nMaster+4, cksum)))
-   || (0 != (rc = sqlite3OsWrite(pPager-&gt;jfd, aJournalMagic, 8, iHdrOff+4+nMaster+8)))
-  ){
-    return rc;
-  }
-  pPager-&gt;journalOff += (nMaster+20);
+  rc = write32bits(pPager-&gt;jfd, jrnlOff, PAGER_MJ_PGNO(pPager));
+  if( rc!=SQLITE_OK ) return rc;
+  jrnlOff += 4;
+
+  rc = sqlite3OsWrite(pPager-&gt;jfd, zMaster, len, jrnlOff);
+  if( rc!=SQLITE_OK ) return rc;
+  jrnlOff += len;
+
+  put32bits(zBuf, len);
+  put32bits(&amp;zBuf[4], cksum);
+  memcpy(&amp;zBuf[8], aJournalMagic, sizeof(aJournalMagic));
+  rc = sqlite3OsWrite(pPager-&gt;jfd, zBuf, 8+sizeof(aJournalMagic), jrnlOff);
+  jrnlOff += 8+sizeof(aJournalMagic);
   pPager-&gt;needSync = !pPager-&gt;noSync;
 
   /* If the pager is in peristent-journal mode, then the physical 
@@ -32232,40 +31659,34 @@ static int writeMasterJournal(Pager *pPager, const char *zMaster){
   ** Easiest thing to do in this scenario is to truncate the journal 
   ** file to the required size.
   */ 
-  if( SQLITE_OK==(rc = sqlite3OsFileSize(pPager-&gt;jfd, &amp;jrnlSize))
-   &amp;&amp; jrnlSize&gt;pPager-&gt;journalOff
+  if( (rc==SQLITE_OK)
+   &amp;&amp; (rc = sqlite3OsFileSize(pPager-&gt;jfd, &amp;jrnlSize))==SQLITE_OK
+   &amp;&amp; jrnlSize&gt;jrnlOff
   ){
-    rc = sqlite3OsTruncate(pPager-&gt;jfd, pPager-&gt;journalOff);
+    rc = sqlite3OsTruncate(pPager-&gt;jfd, jrnlOff);
   }
   return rc;
 }
 
 /*
-** Find a page in the hash table given its page number. Return
-** a pointer to the page or NULL if the requested page is not 
-** already in memory.
+** Find a page in the hash table given its page number.  Return
+** a pointer to the page or NULL if not found.
 */
 static PgHdr *pager_lookup(Pager *pPager, Pgno pgno){
-  PgHdr *p;                         /* Return value */
-
-  /* It is not possible for a call to PcacheFetch() with createFlag==0 to
-  ** fail, since no attempt to allocate dynamic memory will be made.
-  */
-  (void)sqlite3PcacheFetch(pPager-&gt;pPCache, pgno, 0, &amp;p);
+  PgHdr *p;
+  sqlite3PcacheFetch(pPager-&gt;pPCache, pgno, 0, &amp;p);
   return p;
 }
 
 /*
-** Unless the pager is in error-state, discard all in-memory pages. If
-** the pager is in error-state, then this call is a no-op.
-**
-** TODO: Why can we not reset the pager while in error state?
+** Clear the in-memory cache.  This routine
+** sets the state of the pager back to what it was when it was first
+** opened.  Any outstanding pages are invalidated and subsequent attempts
+** to access those pages will likely result in a coredump.
 */
 static void pager_reset(Pager *pPager){
-  if( SQLITE_OK==pPager-&gt;errCode ){
-    sqlite3BackupRestart(pPager-&gt;pBackup);
-    sqlite3PcacheClear(pPager-&gt;pPCache);
-  }
+  if( pPager-&gt;errCode ) return;
+  sqlite3PcacheClear(pPager-&gt;pPCache);
 }
 
 /*
@@ -32273,8 +31694,8 @@ static void pager_reset(Pager *pPager){
 ** Pager.aSavepoint and Pager.nSavepoint to zero. Close the sub-journal
 ** if it is open and the pager is not in exclusive mode.
 */
-static void releaseAllSavepoints(Pager *pPager){
-  int ii;               /* Iterator for looping through Pager.aSavepoint */
+static void releaseAllSavepoint(Pager *pPager){
+  int ii;
   for(ii=0; ii&lt;pPager-&gt;nSavepoint; ii++){
     sqlite3BitvecDestroy(pPager-&gt;aSavepoint[ii].pInSavepoint);
   }
@@ -32284,13 +31705,12 @@ static void releaseAllSavepoints(Pager *pPager){
   sqlite3_free(pPager-&gt;aSavepoint);
   pPager-&gt;aSavepoint = 0;
   pPager-&gt;nSavepoint = 0;
-  pPager-&gt;nSubRec = 0;
+  pPager-&gt;stmtNRec = 0;
 }
 
 /*
-** Set the bit number pgno in the PagerSavepoint.pInSavepoint 
-** bitvecs of all open savepoints. Return SQLITE_OK if successful
-** or SQLITE_NOMEM if a malloc failure occurs.
+** Set the bit number pgno in the PagerSavepoint.pInSavepoint bitvecs of
+** all open savepoints.
 */
 static int addToSavepointBitvecs(Pager *pPager, Pgno pgno){
   int ii;                   /* Loop counter */
@@ -32300,7 +31720,6 @@ static int addToSavepointBitvecs(Pager *pPager, Pgno pgno){
     PagerSavepoint *p = &amp;pPager-&gt;aSavepoint[ii];
     if( pgno&lt;=p-&gt;nOrig ){
       rc |= sqlite3BitvecSet(p-&gt;pInSavepoint, pgno);
-      testcase( rc==SQLITE_NOMEM );
       assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
     }
   }
@@ -32308,8 +31727,7 @@ static int addToSavepointBitvecs(Pager *pPager, Pgno pgno){
 }
 
 /*
-** Unlock the database file. This function is a no-op if the pager
-** is in exclusive mode.
+** Unlock the database file. 
 **
 ** If the pager is currently in error state, discard the contents of 
 ** the cache and reset the Pager structure internal state. If there is
@@ -32319,28 +31737,24 @@ static int addToSavepointBitvecs(Pager *pPager, Pgno pgno){
 */
 static void pager_unlock(Pager *pPager){
   if( !pPager-&gt;exclusiveMode ){
-    int rc;                      /* Return code */
+    int rc;
 
     /* Always close the journal file when dropping the database lock.
     ** Otherwise, another connection with journal_mode=delete might
     ** delete the file out from under us.
     */
-    sqlite3OsClose(pPager-&gt;jfd);
-    sqlite3BitvecDestroy(pPager-&gt;pInJournal);
-    pPager-&gt;pInJournal = 0;
-    releaseAllSavepoints(pPager);
-
-    /* If the file is unlocked, somebody else might change it. The
-    ** values stored in Pager.dbSize etc. might become invalid if
-    ** this happens. TODO: Really, this doesn't need to be cleared
-    ** until the change-counter check fails in pagerSharedLock().
-    */
-    pPager-&gt;dbSizeValid = 0;
+    if( pPager-&gt;journalOpen ){
+      sqlite3OsClose(pPager-&gt;jfd);
+      pPager-&gt;journalOpen = 0;
+      sqlite3BitvecDestroy(pPager-&gt;pInJournal);
+      pPager-&gt;pInJournal = 0;
+      sqlite3BitvecDestroy(pPager-&gt;pAlwaysRollback);
+      pPager-&gt;pAlwaysRollback = 0;
+    }
 
     rc = osUnlock(pPager-&gt;fd, NO_LOCK);
-    if( rc ){
-      pPager-&gt;errCode = rc;
-    }
+    if( rc ) pPager-&gt;errCode = rc;
+    pPager-&gt;dbSizeValid = 0;
     IOTRACE((&quot;UNLOCK %p\n&quot;, pPager))
 
     /* If Pager.errCode is set, the contents of the pager cache cannot be
@@ -32348,173 +31762,67 @@ static void pager_unlock(Pager *pPager){
     ** cache can be discarded and the error code safely cleared.
     */
     if( pPager-&gt;errCode ){
-      if( rc==SQLITE_OK ){
-        pPager-&gt;errCode = SQLITE_OK;
-      }
+      if( rc==SQLITE_OK ) pPager-&gt;errCode = SQLITE_OK;
       pager_reset(pPager);
+      releaseAllSavepoint(pPager);
+      pPager-&gt;journalOff = 0;
+      pPager-&gt;journalStarted = 0;
+      pPager-&gt;dbOrigSize = 0;
     }
 
-    pPager-&gt;changeCountDone = 0;
     pPager-&gt;state = PAGER_UNLOCK;
+    pPager-&gt;changeCountDone = 0;
   }
 }
 
 /*
-** This function should be called when an IOERR, CORRUPT or FULL error
-** may have occured. The first argument is a pointer to the pager 
-** structure, the second the error-code about to be returned by a pager 
-** API function. The value returned is a copy of the second argument 
-** to this function. 
-**
-** If the second argument is SQLITE_IOERR, SQLITE_CORRUPT, or SQLITE_FULL
-** the error becomes persistent. Until the persisten error is cleared,
-** subsequent API calls on this Pager will immediately return the same 
-** error code.
-**
-** A persistent error indicates that the contents of the pager-cache 
-** cannot be trusted. This state can be cleared by completely discarding 
-** the contents of the pager-cache. If a transaction was active when
-** the persistent error occured, then the rollback journal may need
-** to be replayed to restore the contents of the database file (as if
-** it were a hot-journal).
-*/
-static int pager_error(Pager *pPager, int rc){
-  int rc2 = rc &amp; 0xff;
-  assert(
-       pPager-&gt;errCode==SQLITE_FULL ||
-       pPager-&gt;errCode==SQLITE_OK ||
-       (pPager-&gt;errCode &amp; 0xff)==SQLITE_IOERR
-  );
-  if(
-    rc2==SQLITE_FULL ||
-    rc2==SQLITE_IOERR ||
-    rc2==SQLITE_CORRUPT
-  ){
-    pPager-&gt;errCode = rc;
-    if( pPager-&gt;state==PAGER_UNLOCK 
-     &amp;&amp; sqlite3PcacheRefCount(pPager-&gt;pPCache)==0 
-    ){
-      /* If the pager is already unlocked, call pager_unlock() now to
-      ** clear the error state and ensure that the pager-cache is 
-      ** completely empty.
-      */
-      pager_unlock(pPager);
-    }
-  }
-  return rc;
-}
-
-/*
 ** Execute a rollback if a transaction is active and unlock the 
-** database file. 
-**
-** If the pager has already entered the error state, do not attempt 
-** the rollback at this time. Instead, pager_unlock() is called. The
-** call to pager_unlock() will discard all in-memory pages, unlock
-** the database file and clear the error state. If this means that
-** there is a hot-journal left in the file-system, the next connection
-** to obtain a shared lock on the pager (which may be this one) will
-** roll it back.
-**
-** If the pager has not already entered the error state, but an IO or
-** malloc error occurs during a rollback, then this will itself cause 
-** the pager to enter the error state. Which will be cleared by the
-** call to pager_unlock(), as described above.
-*/
-static void pagerUnlockAndRollback(Pager *pPager){
-  if( pPager-&gt;errCode==SQLITE_OK &amp;&amp; pPager-&gt;state&gt;=PAGER_RESERVED ){
+** database file. If the pager has already entered the error state, 
+** do not attempt the rollback.
+*/
+static void pagerUnlockAndRollback(Pager *p){
+  if( p-&gt;errCode==SQLITE_OK &amp;&amp; p-&gt;state&gt;=PAGER_RESERVED ){
     sqlite3BeginBenignMalloc();
-    sqlite3PagerRollback(pPager);
+    sqlite3PagerRollback(p);
     sqlite3EndBenignMalloc();
   }
-  pager_unlock(pPager);
+  pager_unlock(p);
 }
 
 /*
-** This routine ends a transaction. A transaction is usually ended by 
-** either a COMMIT or a ROLLBACK operation. This routine may be called 
-** after rollback of a hot-journal, or if an error occurs while opening
-** the journal file or writing the very first journal-header of a
-** database transaction.
-** 
-** If the pager is in PAGER_SHARED or PAGER_UNLOCK state when this
-** routine is called, it is a no-op (returns SQLITE_OK).
-**
-** Otherwise, any active savepoints are released.
-**
-** If the journal file is open, then it is &quot;finalized&quot;. Once a journal 
-** file has been finalized it is not possible to use it to roll back a 
-** transaction. Nor will it be considered to be a hot-journal by this
-** or any other database connection. Exactly how a journal is finalized
-** depends on whether or not the pager is running in exclusive mode and
-** the current journal-mode (Pager.journalMode value), as follows:
-**
-**   journalMode==MEMORY
-**     Journal file descriptor is simply closed. This destroys an 
-**     in-memory journal.
-**
-**   journalMode==TRUNCATE
-**     Journal file is truncated to zero bytes in size.
-**
-**   journalMode==PERSIST
-**     The first 28 bytes of the journal file are zeroed. This invalidates
-**     the first journal header in the file, and hence the entire journal
-**     file. An invalid journal file cannot be rolled back.
-**
-**   journalMode==DELETE
-**     The journal file is closed and deleted using sqlite3OsDelete().
-**
-**     If the pager is running in exclusive mode, this method of finalizing
-**     the journal file is never used. Instead, if the journalMode is
-**     DELETE and the pager is in exclusive mode, the method described under
-**     journalMode==PERSIST is used instead.
-**
-** After the journal is finalized, if running in non-exclusive mode, the
-** pager moves to PAGER_SHARED state (and downgrades the lock on the
-** database file accordingly).
-**
-** If the pager is running in exclusive mode and is in PAGER_SYNCED state,
-** it moves to PAGER_EXCLUSIVE. No locks are downgraded when running in
-** exclusive mode.
-**
-** SQLITE_OK is returned if no error occurs. If an error occurs during
-** any of the IO operations to finalize the journal file or unlock the
-** database then the IO error code is returned to the user. If the 
-** operation to finalize the journal file fails, then the code still
-** tries to unlock the database file if not in exclusive mode. If the
-** unlock operation fails as well, then the first error code related
-** to the first error encountered (the journal finalization one) is
-** returned.
+** This routine ends a transaction.  A transaction is ended by either
+** a COMMIT or a ROLLBACK.
+**
+** When this routine is called, the pager has the journal file open and
+** a RESERVED or EXCLUSIVE lock on the database.  This routine will release
+** the database lock and acquires a SHARED lock in its place if that is
+** the appropriate thing to do.  Release locks usually is appropriate,
+** unless we are in exclusive access mode or unless this is a 
+** COMMIT AND BEGIN or ROLLBACK AND BEGIN operation.
+**
+** The journal file is either deleted or truncated.
+**
+** TODO: Consider keeping the journal file open for temporary databases.
+** This might give a performance improvement on windows where opening
+** a file is an expensive operation.
 */
 static int pager_end_transaction(Pager *pPager, int hasMaster){
-  int rc = SQLITE_OK;      /* Error code from journal finalization operation */
-  int rc2 = SQLITE_OK;     /* Error code from db file unlock operation */
-
+  int rc = SQLITE_OK;
+  int rc2 = SQLITE_OK;
   if( pPager-&gt;state&lt;PAGER_RESERVED ){
     return SQLITE_OK;
   }
-  releaseAllSavepoints(pPager);
-
-  assert( isOpen(pPager-&gt;jfd) || pPager-&gt;pInJournal==0 );
-  if( isOpen(pPager-&gt;jfd) ){
-
-    /* TODO: There's a problem here if a journal-file was opened in MEMORY
-    ** mode and then the journal-mode is changed to TRUNCATE or PERSIST
-    ** during the transaction. This code should be changed to assume
-    ** that the journal mode has not changed since the transaction was
-    ** started. And the sqlite3PagerJournalMode() function should be
-    ** changed to make sure that this is the case too.
-    */
-
-    /* Finalize the journal file. */
+  releaseAllSavepoint(pPager);
+  if( pPager-&gt;journalOpen ){
     if( pPager-&gt;journalMode==PAGER_JOURNALMODE_MEMORY ){
       int isMemoryJournal = sqlite3IsMemJournal(pPager-&gt;jfd);
       sqlite3OsClose(pPager-&gt;jfd);
+      pPager-&gt;journalOpen = 0;
       if( !isMemoryJournal ){
         rc = sqlite3OsDelete(pPager-&gt;pVfs, pPager-&gt;zJournal, 0);
       }
-    }else if( pPager-&gt;journalMode==PAGER_JOURNALMODE_TRUNCATE ){
-      rc = sqlite3OsTruncate(pPager-&gt;jfd, 0);
+    }else if( pPager-&gt;journalMode==PAGER_JOURNALMODE_TRUNCATE
+         &amp;&amp; (rc = sqlite3OsTruncate(pPager-&gt;jfd, 0))==SQLITE_OK ){
       pPager-&gt;journalOff = 0;
       pPager-&gt;journalStarted = 0;
     }else if( pPager-&gt;exclusiveMode 
@@ -32527,19 +31835,23 @@ static int pager_end_transaction(Pager *pPager, int hasMaster){
     }else{
       assert( pPager-&gt;journalMode==PAGER_JOURNALMODE_DELETE || rc );
       sqlite3OsClose(pPager-&gt;jfd);
+      pPager-&gt;journalOpen = 0;
       if( rc==SQLITE_OK &amp;&amp; !pPager-&gt;tempFile ){
         rc = sqlite3OsDelete(pPager-&gt;pVfs, pPager-&gt;zJournal, 0);
       }
     }
-
+    sqlite3BitvecDestroy(pPager-&gt;pInJournal);
+    pPager-&gt;pInJournal = 0;
+    sqlite3BitvecDestroy(pPager-&gt;pAlwaysRollback);
+    pPager-&gt;pAlwaysRollback = 0;
 #ifdef SQLITE_CHECK_PAGES
     sqlite3PcacheIterateDirty(pPager-&gt;pPCache, pager_set_pagehash);
 #endif
-
     sqlite3PcacheCleanAll(pPager-&gt;pPCache);
-    sqlite3BitvecDestroy(pPager-&gt;pInJournal);
-    pPager-&gt;pInJournal = 0;
+    pPager-&gt;dirtyCache = 0;
     pPager-&gt;nRec = 0;
+  }else{
+    assert( pPager-&gt;pInJournal==0 );
   }
 
   if( !pPager-&gt;exclusiveMode ){
@@ -32549,43 +31861,42 @@ static int pager_end_transaction(Pager *pPager, int hasMaster){
   }else if( pPager-&gt;state==PAGER_SYNCED ){
     pPager-&gt;state = PAGER_EXCLUSIVE;
   }
+  pPager-&gt;dbOrigSize = 0;
   pPager-&gt;setMaster = 0;
   pPager-&gt;needSync = 0;
-  pPager-&gt;dbModified = 0;
-
-  /* TODO: Is this optimal? Why is the db size invalidated here 
-  ** when the database file is not unlocked? */
-  pPager-&gt;dbOrigSize = 0;
+  /* lruListSetFirstSynced(pPager); */
   sqlite3PcacheTruncate(pPager-&gt;pPCache, pPager-&gt;dbSize);
   if( !MEMDB ){
     pPager-&gt;dbSizeValid = 0;
   }
+  pPager-&gt;dbModified = 0;
 
   return (rc==SQLITE_OK?rc2:rc);
 }
 
 /*
-** Parameter aData must point to a buffer of pPager-&gt;pageSize bytes
-** of data. Compute and return a checksum based ont the contents of the 
-** page of data and the current value of pPager-&gt;cksumInit.
+** Compute and return a checksum for the page of data.
 **
-** This is not a real checksum. It is really just the sum of the 
-** random initial value (pPager-&gt;cksumInit) and every 200th byte
-** of the page data, starting with byte offset (pPager-&gt;pageSize%200).
-** Each byte is interpreted as an 8-bit unsigned integer.
+** This is not a real checksum.  It is really just the sum of the 
+** random initial value and the page number.  We experimented with
+** a checksum of the entire data, but that was found to be too slow.
 **
-** Changing the formula used to compute this checksum results in an
-** incompatible journal file format.
-**
-** If journal corruption occurs due to a power failure, the most likely 
-** scenario is that one end or the other of the record will be changed. 
-** It is much less likely that the two ends of the journal record will be
+** Note that the page number is stored at the beginning of data and
+** the checksum is stored at the end.  This is important.  If journal
+** corruption occurs due to a power failure, the most likely scenario
+** is that one end or the other of the record will be changed.  It is
+** much less likely that the two ends of the journal record will be
 ** correct and the middle be corrupt.  Thus, this &quot;checksum&quot; scheme,
 ** though fast and simple, catches the mostly likely kind of corruption.
+**
+** FIX ME:  Consider adding every 200th (or so) byte of the data to the
+** checksum.  That way if a single page spans 3 or more disk sectors and
+** only the middle sector is corrupt, we will still have a reasonable
+** chance of failing the checksum and thus detecting the problem.
 */
 static u32 pager_cksum(Pager *pPager, const u8 *aData){
-  u32 cksum = pPager-&gt;cksumInit;         /* Checksum value to return */
-  int i = pPager-&gt;pageSize-200;          /* Loop counter */
+  u32 cksum = pPager-&gt;cksumInit;
+  int i = pPager-&gt;pageSize-200;
   while( i&gt;0 ){
     cksum += aData[i];
     i -= 200;
@@ -32596,45 +31907,22 @@ static u32 pager_cksum(Pager *pPager, const u8 *aData){
 /*
 ** Read a single page from either the journal file (if isMainJrnl==1) or
 ** from the sub-journal (if isMainJrnl==0) and playback that page.
-** The page begins at offset *pOffset into the file. The *pOffset
+** The page begins at offset *pOffset into the file.  The  *pOffset
 ** value is increased to the start of the next page in the journal.
 **
 ** The isMainJrnl flag is true if this is the main rollback journal and
 ** false for the statement journal.  The main rollback journal uses
 ** checksums - the statement journal does not.
 **
-** If the page number of the page record read from the (sub-)journal file
-** is greater than the current value of Pager.dbSize, then playback is
-** skipped and SQLITE_OK is returned.
-**
 ** If pDone is not NULL, then it is a record of pages that have already
 ** been played back.  If the page at *pOffset has already been played back
 ** (if the corresponding pDone bit is set) then skip the playback.
 ** Make sure the pDone bit corresponding to the *pOffset page is set
 ** prior to returning.
-**
-** If the page record is successfully read from the (sub-)journal file
-** and played back, then SQLITE_OK is returned. If an IO error occurs
-** while reading the record from the (sub-)journal file or while writing
-** to the database file, then the IO error code is returned. If data
-** is successfully read from the (sub-)journal file but appears to be
-** corrupted, SQLITE_DONE is returned. Data is considered corrupted in
-** two circumstances:
-** 
-**   * If the record page-number is illegal (0 or PAGER_MJ_PGNO), or
-**   * If the record is being rolled back from the main journal file
-**     and the checksum field does not match the record content.
-**
-** Neither of these two scenarios are possible during a savepoint rollback.
-**
-** If this is a savepoint rollback, then memory may have to be dynamically
-** allocated by this function. If this is the case and an allocation fails,
-** SQLITE_NOMEM is returned.
 */
 static int pager_playback_one_page(
   Pager *pPager,                /* The pager being played back */
   int isMainJrnl,               /* 1 -&gt; main journal. 0 -&gt; sub-journal. */
-  int isUnsync,                 /* True if reading from unsynced main journal */
   i64 *pOffset,                 /* Offset of record to playback */
   int isSavepnt,                /* True for a savepoint rollback */
   Bitvec *pDone                 /* Bitvec of pages already played back */
@@ -32654,10 +31942,8 @@ static int pager_playback_one_page(
   aData = (u8*)pPager-&gt;pTmpSpace;
   assert( aData );         /* Temp storage must have already been allocated */
 
-  /* Read the page number and page data from the journal or sub-journal
-  ** file. Return an error code to the caller if an IO error occurs.
-  */
   jfd = isMainJrnl ? pPager-&gt;jfd : pPager-&gt;sjfd;
+
   rc = read32bits(jfd, *pOffset, &amp;pgno);
   if( rc!=SQLITE_OK ) return rc;
   rc = sqlite3OsRead(jfd, aData, pPager-&gt;pageSize, (*pOffset)+4);
@@ -32670,7 +31956,6 @@ static int pager_playback_one_page(
   ** detect this invalid data (with high probability) and ignore it.
   */
   if( pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){
-    assert( !isSavepnt );
     return SQLITE_DONE;
   }
   if( pgno&gt;(Pgno)pPager-&gt;dbSize || sqlite3BitvecTest(pDone, pgno) ){
@@ -32683,8 +31968,7 @@ static int pager_playback_one_page(
       return SQLITE_DONE;
     }
   }
-
-  if( pDone &amp;&amp; (rc = sqlite3BitvecSet(pDone, pgno))!=SQLITE_OK ){
+  if( pDone &amp;&amp; (rc = sqlite3BitvecSet(pDone, pgno)) ){
     return rc;
   }
 
@@ -32729,15 +32013,13 @@ static int pager_playback_one_page(
   ));
   if( (pPager-&gt;state&gt;=PAGER_EXCLUSIVE)
    &amp;&amp; (pPg==0 || 0==(pPg-&gt;flags&amp;PGHDR_NEED_SYNC))
-   &amp;&amp; isOpen(pPager-&gt;fd)
-   &amp;&amp; !isUnsync
+   &amp;&amp; (pPager-&gt;fd-&gt;pMethods)
   ){
     i64 ofst = (pgno-1)*(i64)pPager-&gt;pageSize;
     rc = sqlite3OsWrite(pPager-&gt;fd, aData, pPager-&gt;pageSize, ofst);
     if( pgno&gt;pPager-&gt;dbFileSize ){
       pPager-&gt;dbFileSize = pgno;
     }
-    sqlite3BackupUpdate(pPager-&gt;pBackup, pgno, aData);
   }else if( !isMainJrnl &amp;&amp; pPg==0 ){
     /* If this is a rollback of a savepoint and data was not written to
     ** the database and the page is not in-memory, there is a potential
@@ -32756,7 +32038,7 @@ static int pager_playback_one_page(
     ** requiring a journal-sync before it is written.
     */
     assert( isSavepnt );
-    if( (rc = sqlite3PagerAcquire(pPager, pgno, &amp;pPg, 1))!=SQLITE_OK ){
+    if( (rc = sqlite3PagerAcquire(pPager, pgno, &amp;pPg, 1)) ){
       return rc;
     }
     pPg-&gt;flags &amp;= ~PGHDR_NEED_READ;
@@ -32775,7 +32057,7 @@ static int pager_playback_one_page(
     if( pPager-&gt;xReiniter ){
       pPager-&gt;xReiniter(pPg);
     }
-    if( isMainJrnl &amp;&amp; (!isSavepnt || *pOffset&lt;=pPager-&gt;journalHdr) ){
+    if( isMainJrnl &amp;&amp; (!isSavepnt || pPager-&gt;journalOff&lt;=pPager-&gt;journalHdr) ){
       /* If the contents of this page were just restored from the main 
       ** journal file, then its content must be as they were when the 
       ** transaction was first opened. In this case we can mark the page
@@ -32861,60 +32143,34 @@ static int pagerNextJournalPageIsValid(Pager *pPager){
 ** Argument zMaster may point to Pager.pTmpSpace. So that buffer is not 
 ** available for use within this function.
 **
-** When a master journal file is created, it is populated with the names 
-** of all of its child journals, one after another, formatted as utf-8 
-** encoded text. The end of each child journal file is marked with a 
-** nul-terminator byte (0x00). i.e. the entire contents of a master journal
-** file for a transaction involving two databases might be:
-**
-**   &quot;/home/bill/a.db-journal\x00/home/bill/b.db-journal\x00&quot;
-**
-** A master journal file may only be deleted once all of its child 
-** journals have been rolled back.
-**
-** This function reads the contents of the master-journal file into 
-** memory and loops through each of the child journal names. For
-** each child journal, it checks if:
 **
-**   * if the child journal exists, and if so
-**   * if the child journal contains a reference to master journal 
-**     file zMaster
-**
-** If a child journal can be found that matches both of the criteria
-** above, this function returns without doing anything. Otherwise, if
-** no such child journal can be found, file zMaster is deleted from
-** the file-system using sqlite3OsDelete().
-**
-** If an IO error within this function, an error code is returned. This
-** function allocates memory by calling sqlite3Malloc(). If an allocation
-** fails, SQLITE_NOMEM is returned. Otherwise, if no IO or malloc errors 
-** occur, SQLITE_OK is returned.
-**
-** TODO: This function allocates a single block of memory to load
-** the entire contents of the master journal file. This could be
-** a couple of kilobytes or so - potentially larger than the page 
-** size.
+** The master journal file contains the names of all child journals.
+** To tell if a master journal can be deleted, check to each of the
+** children.  If all children are either missing or do not refer to
+** a different master journal, then this master journal can be deleted.
 */
 static int pager_delmaster(Pager *pPager, const char *zMaster){
   sqlite3_vfs *pVfs = pPager-&gt;pVfs;
-  int rc;                   /* Return code */
-  sqlite3_file *pMaster;    /* Malloc'd master-journal file descriptor */
-  sqlite3_file *pJournal;   /* Malloc'd child-journal file descriptor */
+  int rc;
+  int master_open = 0;
+  sqlite3_file *pMaster;
+  sqlite3_file *pJournal;
   char *zMasterJournal = 0; /* Contents of master journal file */
   i64 nMasterJournal;       /* Size of master journal file */
 
-  /* Allocate space for both the pJournal and pMaster file descriptors.
-  ** If successful, open the master journal file for reading.
+  /* Open the master journal file exclusively in case some other process
+  ** is running this routine also. Not that it makes too much difference.
   */
-  pMaster = (sqlite3_file *)sqlite3MallocZero(pVfs-&gt;szOsFile * 2);
+  pMaster = (sqlite3_file *)sqlite3Malloc(pVfs-&gt;szOsFile * 2);
   pJournal = (sqlite3_file *)(((u8 *)pMaster) + pVfs-&gt;szOsFile);
   if( !pMaster ){
     rc = SQLITE_NOMEM;
   }else{
-    const int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MASTER_JOURNAL);
+    int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MASTER_JOURNAL);
     rc = sqlite3OsOpen(pVfs, zMaster, pMaster, flags, 0);
   }
   if( rc!=SQLITE_OK ) goto delmaster_out;
+  master_open = 1;
 
   rc = sqlite3OsFileSize(pMaster, &amp;nMasterJournal);
   if( rc!=SQLITE_OK ) goto delmaster_out;
@@ -32922,7 +32178,7 @@ static int pager_delmaster(Pager *pPager, const char *zMaster){
   if( nMasterJournal&gt;0 ){
     char *zJournal;
     char *zMasterPtr = 0;
-    int nMasterPtr = pVfs-&gt;mxPathname+1;
+    int nMasterPtr = pPager-&gt;pVfs-&gt;mxPathname+1;
 
     /* Load the entire master journal file into space obtained from
     ** sqlite3_malloc() and pointed to by zMasterJournal. 
@@ -32977,9 +32233,8 @@ delmaster_out:
   if( zMasterJournal ){
     sqlite3_free(zMasterJournal);
   }  
-  if( pMaster ){
+  if( master_open ){
     sqlite3OsClose(pMaster);
-    assert( !isOpen(pJournal) );
   }
   sqlite3_free(pMaster);
   return rc;
@@ -32987,30 +32242,23 @@ delmaster_out:
 
 
 /*
-** This function is used to change the actual size of the database 
-** file in the file-system. This only happens when committing a transaction,
-** or rolling back a transaction (including rolling back a hot-journal).
+** If the main database file is open and an exclusive lock is held, 
+** truncate the main file of the given pager to the specified number 
+** of pages.
 **
-** If the main database file is not open, or an exclusive lock is not
-** held, this function is a no-op. Otherwise, the size of the file is
-** changed to nPage pages (nPage*pPager-&gt;pageSize bytes). If the file
-** on disk is currently larger than nPage pages, then use the VFS
-** xTruncate() method to truncate it.
-**
-** Or, it might might be the case that the file on disk is smaller than 
-** nPage pages. Some operating system implementations can get confused if 
-** you try to truncate a file to some size that is larger than it 
-** currently is, so detect this case and write a single zero byte to 
-** the end of the new file instead.
-**
-** If successful, return SQLITE_OK. If an IO error occurs while modifying
-** the database file, return the error code to the caller.
+** It might might be the case that the file on disk is smaller than nPage.
+** This can happen, for example, if we are in the middle of a transaction
+** which has extended the file size and the new pages are still all held
+** in cache, then an INSERT or UPDATE does a statement rollback.  Some
+** operating system implementations can get confused if you try to
+** truncate a file to some size that is larger than it currently is,
+** so detect this case and write a single zero byte to the end of the new
+** file instead.
 */
 static int pager_truncate(Pager *pPager, Pgno nPage){
   int rc = SQLITE_OK;
-  if( pPager-&gt;state&gt;=PAGER_EXCLUSIVE &amp;&amp; isOpen(pPager-&gt;fd) ){
+  if( pPager-&gt;state&gt;=PAGER_EXCLUSIVE &amp;&amp; pPager-&gt;fd-&gt;pMethods ){
     i64 currentSize, newSize;
-    /* TODO: Is it safe to use Pager.dbFileSize here? */
     rc = sqlite3OsFileSize(pPager-&gt;fd, &amp;currentSize);
     newSize = pPager-&gt;pageSize*(i64)nPage;
     if( rc==SQLITE_OK &amp;&amp; currentSize!=newSize ){
@@ -33028,25 +32276,16 @@ static int pager_truncate(Pager *pPager, Pgno nPage){
 }
 
 /*
-** Set the value of the Pager.sectorSize variable for the given
-** pager based on the value returned by the xSectorSize method
-** of the open database file. The sector size will be used used 
-** to determine the size and alignment of journal header and 
-** master journal pointers within created journal files.
-**
-** For temporary files the effective sector size is always 512 bytes.
+** Set the sectorSize for the given pager.
 **
-** Otherwise, for non-temporary files, the effective sector size is
-** the value returned by the xSectorSize() method rounded up to 512 if
-** it is less than 512, or rounded down to MAX_SECTOR_SIZE if it
-** is greater than MAX_SECTOR_SIZE.
+** The sector size is at least as big as the sector size reported
+** by sqlite3OsSectorSize(). The minimum sector size is 512.
 */
 static void setSectorSize(Pager *pPager){
-  assert( isOpen(pPager-&gt;fd) || pPager-&gt;tempFile );
-
+  assert(pPager-&gt;fd-&gt;pMethods||pPager-&gt;tempFile);
   if( !pPager-&gt;tempFile ){
     /* Sector size doesn't matter for temporary files. Also, the file
-    ** may not have been opened yet, in which case the OsSectorSize()
+    ** may not have been opened yet, in whcih case the OsSectorSize()
     ** call will segfault.
     */
     pPager-&gt;sectorSize = sqlite3OsSectorSize(pPager-&gt;fd);
@@ -33055,7 +32294,6 @@ static void setSectorSize(Pager *pPager){
     pPager-&gt;sectorSize = 512;
   }
   if( pPager-&gt;sectorSize&gt;MAX_SECTOR_SIZE ){
-    assert( MAX_SECTOR_SIZE&gt;=512 );
     pPager-&gt;sectorSize = MAX_SECTOR_SIZE;
   }
 }
@@ -33115,13 +32353,6 @@ static void setSectorSize(Pager *pPager){
 **
 ** If an I/O or malloc() error occurs, the journal-file is not deleted
 ** and an error code is returned.
-**
-** The isHot parameter indicates that we are trying to rollback a journal
-** that might be a hot journal.  Or, it could be that the journal is 
-** preserved because of JOURNALMODE_PERSIST or JOURNALMODE_TRUNCATE.
-** If the journal really is hot, reset the pager cache prior rolling
-** back any content.  If the journal is merely persistent, no reset is
-** needed.
 */
 static int pager_playback(Pager *pPager, int isHot){
   sqlite3_vfs *pVfs = pPager-&gt;pVfs;
@@ -33132,12 +32363,11 @@ static int pager_playback(Pager *pPager, int isHot){
   int rc;                  /* Result code of a subroutine */
   int res = 1;             /* Value returned by sqlite3OsAccess() */
   char *zMaster = 0;       /* Name of master journal file if any */
-  int needPagerReset;      /* True to reset page prior to first page rollback */
 
   /* Figure out how many records are in the journal.  Abort early if
   ** the journal is empty.
   */
-  assert( isOpen(pPager-&gt;jfd) );
+  assert( pPager-&gt;journalOpen );
   rc = sqlite3OsFileSize(pPager-&gt;jfd, &amp;szJ);
   if( rc!=SQLITE_OK || szJ==0 ){
     goto end_playback;
@@ -33147,12 +32377,6 @@ static int pager_playback(Pager *pPager, int isHot){
   ** If a master journal file name is specified, but the file is not
   ** present on disk, then the journal is not hot and does not need to be
   ** played back.
-  **
-  ** TODO: Technically the following is an error because it assumes that
-  ** buffer Pager.pTmpSpace is (mxPathname+1) bytes or larger. i.e. that
-  ** (pPager-&gt;pageSize &gt;= pPager-&gt;pVfs-&gt;mxPathname+1). Using os_unix.c,
-  **  mxPathname is 512, which is the same as the minimum allowable value
-  ** for pageSize.
   */
   zMaster = pPager-&gt;pTmpSpace;
   rc = readMasterJournal(pPager-&gt;jfd, zMaster, pPager-&gt;pVfs-&gt;mxPathname+1);
@@ -33164,14 +32388,10 @@ static int pager_playback(Pager *pPager, int isHot){
     goto end_playback;
   }
   pPager-&gt;journalOff = 0;
-  needPagerReset = isHot;
 
-  /* This loop terminates either when a readJournalHdr() or 
-  ** pager_playback_one_page() call returns SQLITE_DONE or an IO error 
-  ** occurs. 
-  */
+  /* This loop terminates either when the readJournalHdr() call returns
+  ** SQLITE_DONE or an IO error occurs. */
   while( 1 ){
-    int isUnsync = 0;
 
     /* Read the next journal header from the journal file.  If there are
     ** not enough bytes left in the journal file for a complete header, or
@@ -33218,7 +32438,6 @@ static int pager_playback(Pager *pPager, int isHot){
     if( nRec==0 &amp;&amp; !isHot &amp;&amp;
         pPager-&gt;journalHdr+JOURNAL_HDR_SZ(pPager)==pPager-&gt;journalOff ){
       nRec = (int)((szJ - pPager-&gt;journalOff) / JOURNAL_PG_SZ(pPager));
-      isUnsync = 1;
     }
 
     /* If this is the first header read from the journal, truncate the
@@ -33232,15 +32451,10 @@ static int pager_playback(Pager *pPager, int isHot){
       pPager-&gt;dbSize = mxPg;
     }
 
-    /* Copy original pages out of the journal and back into the 
-    ** database file and/or page cache.
+    /* Copy original pages out of the journal and back into the database file.
     */
     for(u=0; u&lt;nRec; u++){
-      if( needPagerReset ){
-        pager_reset(pPager);
-        needPagerReset = 0;
-      }
-      rc = pager_playback_one_page(pPager,1,isUnsync,&amp;pPager-&gt;journalOff,0,0);
+      rc = pager_playback_one_page(pPager, 1, &amp;pPager-&gt;journalOff, 0, 0);
       if( rc!=SQLITE_OK ){
         if( rc==SQLITE_DONE ){
           rc = SQLITE_OK;
@@ -33271,32 +32485,18 @@ end_playback:
     sqlite3OsFileControl(pPager-&gt;fd,SQLITE_FCNTL_DB_UNCHANGED,0)&gt;=SQLITE_OK
   );
 
-  /* If this playback is happening automatically as a result of an IO or 
-  ** malloc error that occured after the change-counter was updated but 
-  ** before the transaction was committed, then the change-counter 
-  ** modification may just have been reverted. If this happens in exclusive 
-  ** mode, then subsequent transactions performed by the connection will not
-  ** update the change-counter at all. This may lead to cache inconsistency
-  ** problems for other processes at some point in the future. So, just
-  ** in case this has happened, clear the changeCountDone flag now.
-  */
-  pPager-&gt;changeCountDone = pPager-&gt;tempFile;
-
   if( rc==SQLITE_OK ){
     zMaster = pPager-&gt;pTmpSpace;
     rc = readMasterJournal(pPager-&gt;jfd, zMaster, pPager-&gt;pVfs-&gt;mxPathname+1);
-    testcase( rc!=SQLITE_OK );
   }
   if( rc==SQLITE_OK ){
     rc = pager_end_transaction(pPager, zMaster[0]!='\0');
-    testcase( rc!=SQLITE_OK );
   }
   if( rc==SQLITE_OK &amp;&amp; zMaster[0] &amp;&amp; res ){
     /* If there was a master journal and this routine will return success,
     ** see if it is possible to delete the master journal.
     */
     rc = pager_delmaster(pPager, zMaster);
-    testcase( rc!=SQLITE_OK );
   }
 
   /* The Pager.sectorSize variable may have been updated while rolling
@@ -33308,49 +32508,19 @@ end_playback:
 }
 
 /*
-** Playback savepoint pSavepoint. Or, if pSavepoint==NULL, then playback
-** the entire master journal file. The case pSavepoint==NULL occurs when 
-** a ROLLBACK TO command is invoked on a SAVEPOINT that is a transaction 
-** savepoint.
-**
-** When pSavepoint is not NULL (meaning a non-transaction savepoint is 
-** being rolled back), then the rollback consists of up to three stages,
-** performed in the order specified:
-**
-**   * Pages are played back from the main journal starting at byte
-**     offset PagerSavepoint.iOffset and continuing to 
-**     PagerSavepoint.iHdrOffset, or to the end of the main journal
-**     file if PagerSavepoint.iHdrOffset is zero.
-**
-**   * If PagerSavepoint.iHdrOffset is not zero, then pages are played
-**     back starting from the journal header immediately following 
-**     PagerSavepoint.iHdrOffset to the end of the main journal file.
-**
-**   * Pages are then played back from the sub-journal file, starting
-**     with the PagerSavepoint.iSubRec and continuing to the end of
-**     the journal file.
-**
-** Throughout the rollback process, each time a page is rolled back, the
-** corresponding bit is set in a bitvec structure (variable pDone in the
-** implementation below). This is used to ensure that a page is only
-** rolled back the first time it is encountered in either journal.
-**
-** If pSavepoint is NULL, then pages are only played back from the main
-** journal file. There is no need for a bitvec in this case.
+** Playback savepoint pSavepoint.  Or, if pSavepoint==NULL, then playback
+** the entire master journal file.
 **
-** In either case, before playback commences the Pager.dbSize variable
-** is reset to the value that it held at the start of the savepoint 
-** (or transaction). No page with a page-number greater than this value
-** is played back. If one is encountered it is simply skipped.
+** The case pSavepoint==NULL occurs when a ROLLBACK TO command is invoked
+** on a SAVEPOINT that is a transaction savepoint.
 */
 static int pagerPlaybackSavepoint(Pager *pPager, PagerSavepoint *pSavepoint){
   i64 szJ;                 /* Effective size of the main journal */
   i64 iHdrOff;             /* End of first segment of main-journal records */
+  Pgno ii;                 /* Loop counter */
   int rc = SQLITE_OK;      /* Return code */
   Bitvec *pDone = 0;       /* Bitvec to ensure pages played back only once */
 
-  assert( pPager-&gt;state&gt;=PAGER_SHARED );
-
   /* Allocate a bitvec to use to store the set of pages rolled back */
   if( pSavepoint ){
     pDone = sqlite3BitvecCreate(pSavepoint-&gt;nOrig);
@@ -33359,10 +32529,11 @@ static int pagerPlaybackSavepoint(Pager *pPager, PagerSavepoint *pSavepoint){
     }
   }
 
-  /* Set the database size back to the value it was before the savepoint 
-  ** being reverted was opened.
+  /* Truncate the database back to the size it was before the 
+  ** savepoint being reverted was opened.
   */
   pPager-&gt;dbSize = pSavepoint ? pSavepoint-&gt;nOrig : pPager-&gt;dbOrigSize;
+  assert( pPager-&gt;state&gt;=PAGER_SHARED );
 
   /* Use pPager-&gt;journalOff as the effective size of the main rollback
   ** journal.  The actual file might be larger than this in
@@ -33382,9 +32553,9 @@ static int pagerPlaybackSavepoint(Pager *pPager, PagerSavepoint *pSavepoint){
     iHdrOff = pSavepoint-&gt;iHdrOffset ? pSavepoint-&gt;iHdrOffset : szJ;
     pPager-&gt;journalOff = pSavepoint-&gt;iOffset;
     while( rc==SQLITE_OK &amp;&amp; pPager-&gt;journalOff&lt;iHdrOff ){
-      rc = pager_playback_one_page(pPager, 1, 0, &amp;pPager-&gt;journalOff, 1, pDone);
+      rc = pager_playback_one_page(pPager, 1, &amp;pPager-&gt;journalOff, 1, pDone);
+      assert( rc!=SQLITE_DONE );
     }
-    assert( rc!=SQLITE_DONE );
   }else{
     pPager-&gt;journalOff = 0;
   }
@@ -33395,7 +32566,6 @@ static int pagerPlaybackSavepoint(Pager *pPager, PagerSavepoint *pSavepoint){
   ** continue adding pages rolled back to pDone.
   */
   while( rc==SQLITE_OK &amp;&amp; pPager-&gt;journalOff&lt;szJ ){
-    u32 ii;            /* Loop counter */
     u32 nJRec = 0;     /* Number of Journal Records */
     u32 dummy;
     rc = readJournalHdr(pPager, szJ, &amp;nJRec, &amp;dummy);
@@ -33414,12 +32584,12 @@ static int pagerPlaybackSavepoint(Pager *pPager, PagerSavepoint *pSavepoint){
     if( nJRec==0 
      &amp;&amp; pPager-&gt;journalHdr+JOURNAL_HDR_SZ(pPager)==pPager-&gt;journalOff
     ){
-      nJRec = (u32)((szJ - pPager-&gt;journalOff)/JOURNAL_PG_SZ(pPager));
+      nJRec = (szJ - pPager-&gt;journalOff)/JOURNAL_PG_SZ(pPager);
     }
     for(ii=0; rc==SQLITE_OK &amp;&amp; ii&lt;nJRec &amp;&amp; pPager-&gt;journalOff&lt;szJ; ii++){
-      rc = pager_playback_one_page(pPager, 1, 0, &amp;pPager-&gt;journalOff, 1, pDone);
+      rc = pager_playback_one_page(pPager, 1, &amp;pPager-&gt;journalOff, 1, pDone);
+      assert( rc!=SQLITE_DONE );
     }
-    assert( rc!=SQLITE_DONE );
   }
   assert( rc!=SQLITE_OK || pPager-&gt;journalOff==szJ );
 
@@ -33428,13 +32598,12 @@ static int pagerPlaybackSavepoint(Pager *pPager, PagerSavepoint *pSavepoint){
   ** will be skipped.  Out-of-range pages are also skipped.
   */
   if( pSavepoint ){
-    u32 ii;            /* Loop counter */
     i64 offset = pSavepoint-&gt;iSubRec*(4+pPager-&gt;pageSize);
-    for(ii=pSavepoint-&gt;iSubRec; rc==SQLITE_OK &amp;&amp; ii&lt;pPager-&gt;nSubRec; ii++){
-      assert( offset==ii*(4+pPager-&gt;pageSize) );
-      rc = pager_playback_one_page(pPager, 0, 0, &amp;offset, 1, pDone);
+    for(ii=pSavepoint-&gt;iSubRec; rc==SQLITE_OK&amp;&amp;ii&lt;(u32)pPager-&gt;stmtNRec; ii++){
+      assert( offset == ii*(4+pPager-&gt;pageSize) );
+      rc = pager_playback_one_page(pPager, 0, &amp;offset, 1, pDone);
+      assert( rc!=SQLITE_DONE );
     }
-    assert( rc!=SQLITE_DONE );
   }
 
   sqlite3BitvecDestroy(pDone);
@@ -33496,26 +32665,18 @@ SQLITE_API int sqlite3_opentemp_count = 0;
 #endif
 
 /*
-** Open a temporary file.
-**
-** Write the file descriptor into *pFile. Return SQLITE_OK on success 
-** or some other error code if we fail. The OS will automatically 
-** delete the temporary file when it is closed.
-**
-** The flags passed to the VFS layer xOpen() call are those specified
-** by parameter vfsFlags ORed with the following:
+** Open a temporary file. 
 **
-**     SQLITE_OPEN_READWRITE
-**     SQLITE_OPEN_CREATE
-**     SQLITE_OPEN_EXCLUSIVE
-**     SQLITE_OPEN_DELETEONCLOSE
+** Write the file descriptor into *fd.  Return SQLITE_OK on success or some
+** other error code if we fail. The OS will automatically delete the temporary
+** file when it is closed.
 */
-static int pagerOpentemp(
+static int sqlite3PagerOpentemp(
   Pager *pPager,        /* The pager object */
   sqlite3_file *pFile,  /* Write the file descriptor here */
   int vfsFlags          /* Flags passed through to the VFS */
 ){
-  int rc;               /* Return code */
+  int rc;
 
 #ifdef SQLITE_TEST
   sqlite3_opentemp_count++;  /* Used for testing and analysis only */
@@ -33524,80 +32685,272 @@ static int pagerOpentemp(
   vfsFlags |=  SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
             SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_DELETEONCLOSE;
   rc = sqlite3OsOpen(pPager-&gt;pVfs, 0, pFile, vfsFlags, 0);
-  assert( rc!=SQLITE_OK || isOpen(pFile) );
+  assert( rc!=SQLITE_OK || pFile-&gt;pMethods );
   return rc;
 }
 
+static int pagerStress(void *,PgHdr *);
+
 /*
-** Set the busy handler function.
-**
-** The pager invokes the busy-handler if sqlite3OsLock() returns 
-** SQLITE_BUSY when trying to upgrade from no-lock to a SHARED lock,
-** or when trying to upgrade from a RESERVED lock to an EXCLUSIVE 
-** lock. It does *not* invoke the busy handler when upgrading from
-** SHARED to RESERVED, or when upgrading from SHARED to EXCLUSIVE
-** (which occurs during hot-journal rollback). Summary:
+** Create a new page cache and put a pointer to the page cache in *ppPager.
+** The file to be cached need not exist.  The file is not locked until
+** the first call to sqlite3PagerGet() and is only held open until the
+** last page is released using sqlite3PagerUnref().
 **
-**   Transition                        | Invokes xBusyHandler
-**   --------------------------------------------------------
-**   NO_LOCK       -&gt; SHARED_LOCK      | Yes
-**   SHARED_LOCK   -&gt; RESERVED_LOCK    | No
-**   SHARED_LOCK   -&gt; EXCLUSIVE_LOCK   | No
-**   RESERVED_LOCK -&gt; EXCLUSIVE_LOCK   | Yes
+** If zFilename is NULL then a randomly-named temporary file is created
+** and used as the file to be cached.  The file will be deleted
+** automatically when it is closed.
 **
-** If the busy-handler callback returns non-zero, the lock is 
-** retried. If it returns zero, then the SQLITE_BUSY error is
-** returned to the caller of the pager API function.
+** If zFilename is &quot;:memory:&quot; then all information is held in cache.
+** It is never written to disk.  This can be used to implement an
+** in-memory database.
+*/
+SQLITE_PRIVATE int sqlite3PagerOpen(
+  sqlite3_vfs *pVfs,       /* The virtual file system to use */
+  Pager **ppPager,         /* Return the Pager structure here */
+  const char *zFilename,   /* Name of the database file to open */
+  int nExtra,              /* Extra bytes append to each in-memory page */
+  int flags,               /* flags controlling this file */
+  int vfsFlags             /* flags passed through to sqlite3_vfs.xOpen() */
+){
+  u8 *pPtr;
+  Pager *pPager = 0;
+  int rc = SQLITE_OK;
+  int i;
+  int tempFile = 0;
+  int memDb = 0;
+  int readOnly = 0;
+  int useJournal = (flags &amp; PAGER_OMIT_JOURNAL)==0;
+  int noReadlock = (flags &amp; PAGER_NO_READLOCK)!=0;
+  int journalFileSize;
+  int pcacheSize = sqlite3PcacheSize();
+  int szPageDflt = SQLITE_DEFAULT_PAGE_SIZE;
+  char *zPathname = 0;
+  int nPathname = 0;
+
+  if( sqlite3JournalSize(pVfs)&gt;sqlite3MemJournalSize() ){
+    journalFileSize = sqlite3JournalSize(pVfs);
+  }else{
+    journalFileSize = sqlite3MemJournalSize();
+  }
+
+  /* The default return is a NULL pointer */
+  *ppPager = 0;
+
+  /* Compute and store the full pathname in an allocated buffer pointed
+  ** to by zPathname, length nPathname. Or, if this is a temporary file,
+  ** leave both nPathname and zPathname set to 0.
+  */
+  if( zFilename &amp;&amp; zFilename[0] ){
+    nPathname = pVfs-&gt;mxPathname+1;
+    zPathname = sqlite3Malloc(nPathname*2);
+    if( zPathname==0 ){
+      return SQLITE_NOMEM;
+    }
+#ifndef SQLITE_OMIT_MEMORYDB
+    if( strcmp(zFilename,&quot;:memory:&quot;)==0 ){
+      memDb = 1;
+      zPathname[0] = 0;
+    }else
+#endif
+    {
+      rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
+    }
+    if( rc!=SQLITE_OK ){
+      sqlite3_free(zPathname);
+      return rc;
+    }
+    nPathname = sqlite3Strlen30(zPathname);
+  }
+
+  /* Allocate memory for the pager structure */
+  pPager = sqlite3MallocZero(
+    sizeof(*pPager) +           /* Pager structure */
+    pcacheSize      +           /* PCache object */
+    journalFileSize +           /* The journal file structure */ 
+    pVfs-&gt;szOsFile  +           /* The main db file */
+    journalFileSize * 2 +       /* The two journal files */ 
+    3*nPathname + 40            /* zFilename, zDirectory, zJournal */
+  );
+  if( !pPager ){
+    sqlite3_free(zPathname);
+    return SQLITE_NOMEM;
+  }
+  pPager-&gt;pPCache = (PCache *)&amp;pPager[1];
+  pPtr = ((u8 *)&amp;pPager[1]) + pcacheSize;
+  pPager-&gt;vfsFlags = vfsFlags;
+  pPager-&gt;fd = (sqlite3_file*)&amp;pPtr[pVfs-&gt;szOsFile*0];
+  pPager-&gt;sjfd = (sqlite3_file*)&amp;pPtr[pVfs-&gt;szOsFile];
+  pPager-&gt;jfd = (sqlite3_file*)&amp;pPtr[pVfs-&gt;szOsFile+journalFileSize];
+  pPager-&gt;zFilename = (char*)&amp;pPtr[pVfs-&gt;szOsFile+2*journalFileSize];
+  pPager-&gt;zDirectory = &amp;pPager-&gt;zFilename[nPathname+1];
+  pPager-&gt;zJournal = &amp;pPager-&gt;zDirectory[nPathname+1];
+  pPager-&gt;pVfs = pVfs;
+  if( zPathname ){
+    memcpy(pPager-&gt;zFilename, zPathname, nPathname+1);
+    sqlite3_free(zPathname);
+  }
+
+  /* Open the pager file.
+  */
+  if( zFilename &amp;&amp; zFilename[0] &amp;&amp; !memDb ){
+    if( nPathname&gt;(pVfs-&gt;mxPathname - (int)sizeof(&quot;-journal&quot;)) ){
+      rc = SQLITE_CANTOPEN;
+    }else{
+      int fout = 0;
+      rc = sqlite3OsOpen(pVfs, pPager-&gt;zFilename, pPager-&gt;fd,
+                         pPager-&gt;vfsFlags, &amp;fout);
+      readOnly = (fout&amp;SQLITE_OPEN_READONLY);
+
+      /* If the file was successfully opened for read/write access,
+      ** choose a default page size in case we have to create the
+      ** database file. The default page size is the maximum of:
+      **
+      **    + SQLITE_DEFAULT_PAGE_SIZE,
+      **    + The value returned by sqlite3OsSectorSize()
+      **    + The largest page size that can be written atomically.
+      */
+      if( rc==SQLITE_OK &amp;&amp; !readOnly ){
+        setSectorSize(pPager);
+        if( szPageDflt&lt;pPager-&gt;sectorSize ){
+          szPageDflt = pPager-&gt;sectorSize;
+        }
+#ifdef SQLITE_ENABLE_ATOMIC_WRITE
+        {
+          int iDc = sqlite3OsDeviceCharacteristics(pPager-&gt;fd);
+          int ii;
+          assert(SQLITE_IOCAP_ATOMIC512==(512&gt;&gt;8));
+          assert(SQLITE_IOCAP_ATOMIC64K==(65536&gt;&gt;8));
+          assert(SQLITE_MAX_DEFAULT_PAGE_SIZE&lt;=65536);
+          for(ii=szPageDflt; ii&lt;=SQLITE_MAX_DEFAULT_PAGE_SIZE; ii=ii*2){
+            if( iDc&amp;(SQLITE_IOCAP_ATOMIC|(ii&gt;&gt;8)) ) szPageDflt = ii;
+          }
+        }
+#endif
+        if( szPageDflt&gt;SQLITE_MAX_DEFAULT_PAGE_SIZE ){
+          szPageDflt = SQLITE_MAX_DEFAULT_PAGE_SIZE;
+        }
+      }
+    }
+  }else{
+    /* If a temporary file is requested, it is not opened immediately.
+    ** In this case we accept the default page size and delay actually
+    ** opening the file until the first call to OsWrite().
+    **
+    ** This branch is also run for an in-memory database. An in-memory
+    ** database is the same as a temp-file that is never written out to
+    ** disk and uses an in-memory rollback journal.
+    */ 
+    tempFile = 1;
+    pPager-&gt;state = PAGER_EXCLUSIVE;
+  }
+
+  if( pPager &amp;&amp; rc==SQLITE_OK ){
+    pPager-&gt;pTmpSpace = sqlite3PageMalloc(szPageDflt);
+  }
+
+  /* If an error occured in either of the blocks above.
+  ** Free the Pager structure and close the file.
+  ** Since the pager is not allocated there is no need to set 
+  ** any Pager.errMask variables.
+  */
+  if( !pPager || !pPager-&gt;pTmpSpace ){
+    sqlite3OsClose(pPager-&gt;fd);
+    sqlite3_free(pPager);
+    return ((rc==SQLITE_OK)?SQLITE_NOMEM:rc);
+  }
+  nExtra = FORCE_ALIGNMENT(nExtra);
+  sqlite3PcacheOpen(szPageDflt, nExtra, !memDb,
+                    !memDb?pagerStress:0, (void *)pPager, pPager-&gt;pPCache);
+
+  PAGERTRACE((&quot;OPEN %d %s\n&quot;, FILEHANDLEID(pPager-&gt;fd), pPager-&gt;zFilename));
+  IOTRACE((&quot;OPEN %p %s\n&quot;, pPager, pPager-&gt;zFilename))
+
+  /* Fill in Pager.zDirectory[] */
+  memcpy(pPager-&gt;zDirectory, pPager-&gt;zFilename, nPathname+1);
+  for(i=sqlite3Strlen30(pPager-&gt;zDirectory); 
+      i&gt;0 &amp;&amp; pPager-&gt;zDirectory[i-1]!='/'; i--){}
+  if( i&gt;0 ) pPager-&gt;zDirectory[i-1] = 0;
+
+  /* Fill in Pager.zJournal[] */
+  if( zPathname ){
+    memcpy(pPager-&gt;zJournal, pPager-&gt;zFilename, nPathname);
+    memcpy(&amp;pPager-&gt;zJournal[nPathname], &quot;-journal&quot;, 9);
+  }else{
+    pPager-&gt;zJournal = 0;
+  }
+
+  /* pPager-&gt;journalOpen = 0; */
+  pPager-&gt;useJournal = (u8)useJournal;
+  pPager-&gt;noReadlock = (noReadlock &amp;&amp; readOnly) ?1:0;
+  /* pPager-&gt;stmtOpen = 0; */
+  /* pPager-&gt;stmtInUse = 0; */
+  /* pPager-&gt;nRef = 0; */
+  pPager-&gt;dbSizeValid = (u8)memDb;
+  pPager-&gt;pageSize = szPageDflt;
+  /* pPager-&gt;stmtSize = 0; */
+  /* pPager-&gt;stmtJSize = 0; */
+  /* pPager-&gt;nPage = 0; */
+  pPager-&gt;mxPage = 100;
+  pPager-&gt;mxPgno = SQLITE_MAX_PAGE_COUNT;
+  /* pPager-&gt;state = PAGER_UNLOCK; */
+  assert( pPager-&gt;state == (tempFile ? PAGER_EXCLUSIVE : PAGER_UNLOCK) );
+  /* pPager-&gt;errMask = 0; */
+  pPager-&gt;tempFile = (u8)tempFile;
+  assert( tempFile==PAGER_LOCKINGMODE_NORMAL 
+          || tempFile==PAGER_LOCKINGMODE_EXCLUSIVE );
+  assert( PAGER_LOCKINGMODE_EXCLUSIVE==1 );
+  pPager-&gt;exclusiveMode = (u8)tempFile; 
+  pPager-&gt;memDb = (u8)memDb;
+  pPager-&gt;readOnly = (u8)readOnly;
+  /* pPager-&gt;needSync = 0; */
+  pPager-&gt;noSync = (pPager-&gt;tempFile || !useJournal) ?1:0;
+  pPager-&gt;fullSync = pPager-&gt;noSync ?0:1;
+  pPager-&gt;sync_flags = SQLITE_SYNC_NORMAL;
+  /* pPager-&gt;pFirst = 0; */
+  /* pPager-&gt;pFirstSynced = 0; */
+  /* pPager-&gt;pLast = 0; */
+  pPager-&gt;nExtra = nExtra;
+  pPager-&gt;journalSizeLimit = SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT;
+  assert(pPager-&gt;fd-&gt;pMethods||tempFile);
+  setSectorSize(pPager);
+  if( memDb ){
+    pPager-&gt;journalMode = PAGER_JOURNALMODE_MEMORY;
+  }
+  /* pPager-&gt;xBusyHandler = 0; */
+  /* pPager-&gt;pBusyHandlerArg = 0; */
+  /* memset(pPager-&gt;aHash, 0, sizeof(pPager-&gt;aHash)); */
+  *ppPager = pPager;
+  return SQLITE_OK;
+}
+
+/*
+** Set the busy handler function.
 */
 SQLITE_PRIVATE void sqlite3PagerSetBusyhandler(
-  Pager *pPager,                       /* Pager object */
-  int (*xBusyHandler)(void *),         /* Pointer to busy-handler function */
-  void *pBusyHandlerArg                /* Argument to pass to xBusyHandler */
+  Pager *pPager, 
+  int (*xBusyHandler)(void *),
+  void *pBusyHandlerArg
 ){  
   pPager-&gt;xBusyHandler = xBusyHandler;
   pPager-&gt;pBusyHandlerArg = pBusyHandlerArg;
 }
 
 /*
-** Set the reinitializer for this pager. If not NULL, the reinitializer
-** is called when the content of a page in cache is modified (restored)
-** as part of a transaction or savepoint rollback. The callback gives 
-** higher-level code an opportunity to restore the EXTRA section to 
-** agree with the restored page data.
+** Set the reinitializer for this pager.  If not NULL, the reinitializer
+** is called when the content of a page in cache is restored to its original
+** value as a result of a rollback.  The callback gives higher-level code
+** an opportunity to restore the EXTRA section to agree with the restored
+** page data.
 */
 SQLITE_PRIVATE void sqlite3PagerSetReiniter(Pager *pPager, void (*xReinit)(DbPage*)){
   pPager-&gt;xReiniter = xReinit;
 }
 
 /*
-** Change the page size used by the Pager object. The new page size 
-** is passed in *pPageSize.
-**
-** If the pager is in the error state when this function is called, it
-** is a no-op. The value returned is the error state error code (i.e. 
-** one of SQLITE_IOERR, SQLITE_CORRUPT or SQLITE_FULL).
-**
-** Otherwise, if all of the following are true:
-**
-**   * the new page size (value of *pPageSize) is valid (a power 
-**     of two between 512 and SQLITE_MAX_PAGE_SIZE, inclusive), and
-**
-**   * there are no outstanding page references, and
-**
-**   * the database is either not an in-memory database or it is
-**     an in-memory database that currently consists of zero pages.
-**
-** then the pager object page size is set to *pPageSize.
-**
-** If the page size is changed, then this function uses sqlite3PagerMalloc() 
-** to obtain a new Pager.pTmpSpace buffer. If this allocation attempt 
-** fails, SQLITE_NOMEM is returned and the page size remains unchanged. 
-** In all other cases, SQLITE_OK is returned.
-**
-** If the page size is not changed, either because one of the enumerated
-** conditions above is not true, the pager was in error state when this
-** function was called, or because the memory allocation attempt failed, 
-** then *pPageSize is set to the old, retained page size before returning.
+** Set the page size to *pPageSize. If the suggest new page size is
+** inappropriate, then an alternative page size is set to that
+** value before returning.
 */
 SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager *pPager, u16 *pPageSize){
   int rc = pPager-&gt;errCode;
@@ -33614,6 +32967,7 @@ SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager *pPager, u16 *pPageSize){
       }else{
         pager_reset(pPager);
         pPager-&gt;pageSize = pageSize;
+        if( !pPager-&gt;memDb ) setSectorSize(pPager);
         sqlite3PageFree(pPager-&gt;pTmpSpace);
         pPager-&gt;pTmpSpace = pNew;
         sqlite3PcacheSetPageSize(pPager-&gt;pPCache, pageSize);
@@ -33679,21 +33033,17 @@ void enable_simulated_io_errors(void){
 ** Read the first N bytes from the beginning of the file into memory
 ** that pDest points to. 
 **
-** If the pager was opened on a transient file (zFilename==&quot;&quot;), or
-** opened on a file less than N bytes in size, the output buffer is
-** zeroed and SQLITE_OK returned. The rationale for this is that this 
-** function is used to read database headers, and a new transient or
-** zero sized database has a header than consists entirely of zeroes.
-**
-** If any IO error apart from SQLITE_IOERR_SHORT_READ is encountered,
-** the error code is returned to the caller and the contents of the
-** output buffer undefined.
+** No error checking is done. The rational for this is that this function 
+** may be called even if the file does not exist or contain a header. In 
+** these cases sqlite3OsRead() will return an error, to which the correct 
+** response is to zero the memory at pDest and continue.  A real IO error 
+** will presumably recur and be picked up later (Todo: Think about this).
 */
 SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager *pPager, int N, unsigned char *pDest){
   int rc = SQLITE_OK;
   memset(pDest, 0, N);
-  assert( isOpen(pPager-&gt;fd) || pPager-&gt;tempFile );
-  if( isOpen(pPager-&gt;fd) ){
+  assert(pPager-&gt;fd-&gt;pMethods||pPager-&gt;tempFile);
+  if( pPager-&gt;fd-&gt;pMethods ){
     IOTRACE((&quot;DBHDR %p 0 %d\n&quot;, pPager, N))
     rc = sqlite3OsRead(pPager-&gt;fd, pDest, N, 0);
     if( rc==SQLITE_IOERR_SHORT_READ ){
@@ -33704,84 +33054,69 @@ SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager *pPager, int N, unsigned cha
 }
 
 /*
-** Return the total number of pages in the database file associated 
-** with pPager. Normally, this is calculated as (&lt;db file size&gt;/&lt;page-size&gt;).
-** However, if the file is between 1 and &lt;page-size&gt; bytes in size, then 
-** this is considered a 1 page file.
-**
-** If the pager is in error state when this function is called, then the
-** error state error code is returned and *pnPage left unchanged. Or,
-** if the file system has to be queried for the size of the file and
-** the query attempt returns an IO error, the IO error code is returned
-** and *pnPage is left unchanged.
+** Return the total number of pages in the disk file associated with
+** pPager. 
 **
-** Otherwise, if everything is successful, then SQLITE_OK is returned
-** and *pnPage is set to the number of pages in the database.
+** If the PENDING_BYTE lies on the page directly after the end of the
+** file, then consider this page part of the file too. For example, if
+** PENDING_BYTE is byte 4096 (the first byte of page 5) and the size of the
+** file is 4096 bytes, 5 is returned instead of 4.
 */
 SQLITE_PRIVATE int sqlite3PagerPagecount(Pager *pPager, int *pnPage){
-  Pgno nPage;               /* Value to return via *pnPage */
-
-  /* If the pager is already in the error state, return the error code. */
+  i64 n = 0;
+  int rc;
+  assert( pPager!=0 );
   if( pPager-&gt;errCode ){
-    return pPager-&gt;errCode;
+    rc = pPager-&gt;errCode;
+    return rc;
   }
-
-  /* Determine the number of pages in the file. Store this in nPage. */
   if( pPager-&gt;dbSizeValid ){
-    nPage = pPager-&gt;dbSize;
-  }else{
-    int rc;                 /* Error returned by OsFileSize() */
-    i64 n = 0;              /* File size in bytes returned by OsFileSize() */
-
-    assert( isOpen(pPager-&gt;fd) || pPager-&gt;tempFile );
-    if( isOpen(pPager-&gt;fd) &amp;&amp; (0 != (rc = sqlite3OsFileSize(pPager-&gt;fd, &amp;n))) ){
+    n = pPager-&gt;dbSize;
+  } else {
+    assert(pPager-&gt;fd-&gt;pMethods||pPager-&gt;tempFile);
+    if( (pPager-&gt;fd-&gt;pMethods)
+     &amp;&amp; (rc = sqlite3OsFileSize(pPager-&gt;fd, &amp;n))!=SQLITE_OK ){
       pager_error(pPager, rc);
       return rc;
     }
     if( n&gt;0 &amp;&amp; n&lt;pPager-&gt;pageSize ){
-      nPage = 1;
+      n = 1;
     }else{
-      nPage = (Pgno)(n / pPager-&gt;pageSize);
+      n /= pPager-&gt;pageSize;
     }
     if( pPager-&gt;state!=PAGER_UNLOCK ){
-      pPager-&gt;dbSize = nPage;
-      pPager-&gt;dbFileSize = nPage;
+      pPager-&gt;dbSize = (Pgno)n;
+      pPager-&gt;dbFileSize = (Pgno)n;
       pPager-&gt;dbSizeValid = 1;
     }
   }
-
-  /* If the current number of pages in the file is greater than the 
-  ** configured maximum pager number, increase the allowed limit so
-  ** that the file can be read.
-  */
-  if( nPage&gt;pPager-&gt;mxPgno ){
-    pPager-&gt;mxPgno = (Pgno)nPage;
+  if( n==(PENDING_BYTE/pPager-&gt;pageSize) ){
+    n++;
+  }
+  if( n&gt;pPager-&gt;mxPgno ){
+    pPager-&gt;mxPgno = (Pgno)n;
   }
-
-  /* Set the output variable and return SQLITE_OK */
   if( pnPage ){
-    *pnPage = nPage;
+    *pnPage = (int)n;
   }
   return SQLITE_OK;
 }
 
+/*
+** Forward declaration
+*/
+static int syncJournal(Pager*);
 
 /*
-** Try to obtain a lock of type locktype on the database file. If
-** a similar or greater lock is already held, this function is a no-op
-** (returning SQLITE_OK immediately).
-**
-** Otherwise, attempt to obtain the lock using sqlite3OsLock(). Invoke 
-** the busy callback if the lock is currently not available. Repeat 
-** until the busy callback returns false or until the attempt to 
-** obtain the lock succeeds.
+** Try to obtain a lock on a file.  Invoke the busy callback if the lock
+** is currently not available.  Repeat until the busy callback returns
+** false or until the lock succeeds.
 **
 ** Return SQLITE_OK on success and an error code if we cannot obtain
-** the lock. If the lock is obtained successfully, set the Pager.state 
-** variable to locktype before returning.
+** the lock.
 */
 static int pager_wait_on_lock(Pager *pPager, int locktype){
-  int rc;                              /* Return code */
+  int rc;
 
   /* The OS lock values must be the same as the Pager lock values */
   assert( PAGER_SHARED==SHARED_LOCK );
@@ -33791,16 +33126,6 @@ static int pager_wait_on_lock(Pager *pPager, int locktype){
   /* If the file is currently unlocked then the size must be unknown */
   assert( pPager-&gt;state&gt;=PAGER_SHARED || pPager-&gt;dbSizeValid==0 );
 
-  /* Check that this is either a no-op (because the requested lock is 
-  ** already held, or one of the transistions that the busy-handler
-  ** may be invoked during, according to the comment above
-  ** sqlite3PagerSetBusyhandler().
-  */
-  assert( (pPager-&gt;state&gt;=locktype)
-       || (pPager-&gt;state==PAGER_UNLOCK &amp;&amp; locktype==PAGER_SHARED)
-       || (pPager-&gt;state==PAGER_RESERVED &amp;&amp; locktype==PAGER_EXCLUSIVE)
-  );
-
   if( pPager-&gt;state&gt;=locktype ){
     rc = SQLITE_OK;
   }else{
@@ -33815,6 +33140,7 @@ static int pager_wait_on_lock(Pager *pPager, int locktype){
   return rc;
 }
 
+#ifndef SQLITE_OMIT_AUTOVACUUM
 /*
 ** Truncate the in-memory database file image to nPage pages. This 
 ** function does not actually modify the database file on disk. It 
@@ -33824,11 +33150,26 @@ static int pager_wait_on_lock(Pager *pPager, int locktype){
 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
   assert( pPager-&gt;dbSizeValid );
   assert( pPager-&gt;dbSize&gt;=nPage );
-  assert( pPager-&gt;state&gt;=PAGER_RESERVED );
   pPager-&gt;dbSize = nPage;
 }
 
 /*
+** Return the current size of the database file image in pages. This
+** function differs from sqlite3PagerPagecount() in two ways:
+**
+**  a) It may only be called when at least one reference to a database
+**     page is held. This guarantees that the database size is already
+**     known and a call to sqlite3OsFileSize() is not required.
+**
+**  b) The return value is not adjusted for the locking page.
+*/
+SQLITE_PRIVATE Pgno sqlite3PagerImageSize(Pager *pPager){
+  assert( pPager-&gt;dbSizeValid );
+  return pPager-&gt;dbSize;
+}
+#endif  /* ifndef SQLITE_OMIT_AUTOVACUUM */
+
+/*
 ** Shutdown the page cache.  Free all memory and close all files.
 **
 ** If a transaction was in progress when this routine is called, that
@@ -33843,14 +33184,13 @@ SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
 ** to the caller.
 */
 SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager){
+
   disable_simulated_io_errors();
   sqlite3BeginBenignMalloc();
   pPager-&gt;errCode = 0;
   pPager-&gt;exclusiveMode = 0;
   pager_reset(pPager);
-  if( MEMDB ){
-    pager_unlock(pPager);
-  }else{
+  if( !MEMDB ){
     /* Set Pager.journalHdr to -1 for the benefit of the pager_playback() 
     ** call which may be made from within pagerUnlockAndRollback(). If it
     ** is not -1, then the unsynced portion of an open journal file may
@@ -33860,89 +33200,87 @@ SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager){
     pPager-&gt;journalHdr = -1;
     pagerUnlockAndRollback(pPager);
   }
-  sqlite3EndBenignMalloc();
   enable_simulated_io_errors();
+  sqlite3EndBenignMalloc();
   PAGERTRACE((&quot;CLOSE %d\n&quot;, PAGERID(pPager)));
   IOTRACE((&quot;CLOSE %p\n&quot;, pPager))
+  if( pPager-&gt;journalOpen ){
+    sqlite3OsClose(pPager-&gt;jfd);
+  }
+  sqlite3BitvecDestroy(pPager-&gt;pInJournal);
+  sqlite3BitvecDestroy(pPager-&gt;pAlwaysRollback);
+  releaseAllSavepoint(pPager);
   sqlite3OsClose(pPager-&gt;fd);
+  /* Temp files are automatically deleted by the OS
+  ** if( pPager-&gt;tempFile ){
+  **   sqlite3OsDelete(pPager-&gt;zFilename);
+  ** }
+  */
+
   sqlite3PageFree(pPager-&gt;pTmpSpace);
   sqlite3PcacheClose(pPager-&gt;pPCache);
-
-  assert( !pPager-&gt;aSavepoint &amp;&amp; !pPager-&gt;pInJournal );
-  assert( !isOpen(pPager-&gt;jfd) &amp;&amp; !isOpen(pPager-&gt;sjfd) );
-
   sqlite3_free(pPager);
   return SQLITE_OK;
 }
 
 #if !defined(NDEBUG) || defined(SQLITE_TEST)
 /*
-** Return the page number for page pPg.
+** Return the page number for the given page data.
 */
-SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage *pPg){
-  return pPg-&gt;pgno;
+SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage *p){
+  return p-&gt;pgno;
 }
 #endif
 
 /*
-** Increment the reference count for page pPg.
+** Increment the reference count for a page.  The input pointer is
+** a reference to the page data.
 */
-SQLITE_PRIVATE void sqlite3PagerRef(DbPage *pPg){
+SQLITE_PRIVATE int sqlite3PagerRef(DbPage *pPg){
   sqlite3PcacheRef(pPg);
+  return SQLITE_OK;
 }
 
 /*
-** Sync the journal. In other words, make sure all the pages that have
+** Sync the journal.  In other words, make sure all the pages that have
 ** been written to the journal have actually reached the surface of the
-** disk and can be restored in the event of a hot-journal rollback.
-**
-** If the Pager.needSync flag is not set, then this function is a
-** no-op. Otherwise, the actions required depend on the journal-mode
-** and the device characteristics of the the file-system, as follows:
-**
-**   * If the journal file is an in-memory journal file, no action need
-**     be taken.
-**
-**   * Otherwise, if the device does not support the SAFE_APPEND property,
-**     then the nRec field of the most recently written journal header
-**     is updated to contain the number of journal records that have
-**     been written following it. If the pager is operating in full-sync
-**     mode, then the journal file is synced before this field is updated.
-**
-**   * If the device does not support the SEQUENTIAL property, then 
-**     journal file is synced.
-**
-** Or, in pseudo-code:
+** disk.  It is not safe to modify the original database file until after
+** the journal has been synced.  If the original database is modified before
+** the journal is synced and a power failure occurs, the unsynced journal
+** data would be lost and we would be unable to completely rollback the
+** database changes.  Database corruption would occur.
+** 
+** This routine also updates the nRec field in the header of the journal.
+** (See comments on the pager_playback() routine for additional information.)
+** If the sync mode is FULL, two syncs will occur.  First the whole journal
+** is synced, then the nRec field is updated, then a second sync occurs.
 **
-**   if( NOT &lt;in-memory journal&gt; ){
-**     if( NOT SAFE_APPEND ){
-**       if( &lt;full-sync mode&gt; ) xSync(&lt;journal file&gt;);
-**       &lt;update nRec field&gt;
-**     } 
-**     if( NOT SEQUENTIAL ) xSync(&lt;journal file&gt;);
-**   }
+** For temporary databases, we do not care if we are able to rollback
+** after a power failure, so no sync occurs.
 **
-** The Pager.needSync flag is never be set for temporary files, or any
-** file operating in no-sync mode (Pager.noSync set to non-zero).
+** If the IOCAP_SEQUENTIAL flag is set for the persistent media on which
+** the database is stored, then OsSync() is never called on the journal
+** file. In this case all that is required is to update the nRec field in
+** the journal header.
 **
-** If successful, this routine clears the PGHDR_NEED_SYNC flag of every 
-** page currently held in memory before returning SQLITE_OK. If an IO
-** error is encountered, then the IO error code is returned to the caller.
+** This routine clears the needSync field of every page current held in
+** memory.
 */
 static int syncJournal(Pager *pPager){
+  int rc = SQLITE_OK;
+
+  /* Sync the journal before modifying the main database
+  ** (assuming there is a journal and it needs to be synced.)
+  */
   if( pPager-&gt;needSync ){
     assert( !pPager-&gt;tempFile );
     if( pPager-&gt;journalMode!=PAGER_JOURNALMODE_MEMORY ){
-      int rc;                              /* Return code */
-      const int iDc = sqlite3OsDeviceCharacteristics(pPager-&gt;fd);
-      assert( isOpen(pPager-&gt;jfd) );
+      int iDc = sqlite3OsDeviceCharacteristics(pPager-&gt;fd);
+      assert( pPager-&gt;journalOpen );
 
       if( 0==(iDc&amp;SQLITE_IOCAP_SAFE_APPEND) ){
-        /* Variable iNRecOffset is set to the offset in the journal file
-        ** of the nRec field of the most recently written journal header.
-        ** This field will be updated following the xSync() operation
-        ** on the journal file. */
-        i64 iNRecOffset = pPager-&gt;journalHdr + sizeof(aJournalMagic);
+        i64 jrnlOff = journalHdrOffset(pPager);
+        u8 zMagic[8];
 
         /* This block deals with an obscure problem. If the last connection
         ** that wrote to this database was operating in persistent-journal
@@ -33960,18 +33298,11 @@ static int syncJournal(Pager *pPager){
         ** To work around this, if the journal file does appear to contain
         ** a valid header following Pager.journalOff, then write a 0x00
         ** byte to the start of it to prevent it from being recognized.
-        **
-        ** Variable iNextHdrOffset is set to the offset at which this
-        ** problematic header will occur, if it exists. aMagic is used 
-        ** as a temporary buffer to inspect the first couple of bytes of
-        ** the potential journal header.
         */
-        i64 iNextHdrOffset = journalHdrOffset(pPager);
-        u8 aMagic[8];
-        rc = sqlite3OsRead(pPager-&gt;jfd, aMagic, 8, iNextHdrOffset);
-        if( rc==SQLITE_OK &amp;&amp; 0==memcmp(aMagic, aJournalMagic, 8) ){
+        rc = sqlite3OsRead(pPager-&gt;jfd, zMagic, 8, jrnlOff);
+        if( rc==SQLITE_OK &amp;&amp; 0==memcmp(zMagic, aJournalMagic, 8) ){
           static const u8 zerobyte = 0;
-          rc = sqlite3OsWrite(pPager-&gt;jfd, &amp;zerobyte, 1, iNextHdrOffset);
+          rc = sqlite3OsWrite(pPager-&gt;jfd, &amp;zerobyte, 1, jrnlOff);
         }
         if( rc!=SQLITE_OK &amp;&amp; rc!=SQLITE_IOERR_SHORT_READ ){
           return rc;
@@ -33992,11 +33323,13 @@ static int syncJournal(Pager *pPager){
           PAGERTRACE((&quot;SYNC journal of %d\n&quot;, PAGERID(pPager)));
           IOTRACE((&quot;JSYNC %p\n&quot;, pPager))
           rc = sqlite3OsSync(pPager-&gt;jfd, pPager-&gt;sync_flags);
-          if( rc!=SQLITE_OK ) return rc;
+          if( rc!=0 ) return rc;
         }
-        IOTRACE((&quot;JHDR %p %lld %d\n&quot;, pPager, iNRecOffset, 4));
-        rc = write32bits(pPager-&gt;jfd, iNRecOffset, pPager-&gt;nRec);
-        if( rc!=SQLITE_OK ) return rc;
+
+        jrnlOff = pPager-&gt;journalHdr + sizeof(aJournalMagic);
+        IOTRACE((&quot;JHDR %p %lld %d\n&quot;, pPager, jrnlOff, 4));
+        rc = write32bits(pPager-&gt;jfd, jrnlOff, pPager-&gt;nRec);
+        if( rc ) return rc;
       }
       if( 0==(iDc&amp;SQLITE_IOCAP_SEQUENTIAL) ){
         PAGERTRACE((&quot;SYNC journal of %d\n&quot;, PAGERID(pPager)));
@@ -34004,63 +33337,37 @@ static int syncJournal(Pager *pPager){
         rc = sqlite3OsSync(pPager-&gt;jfd, pPager-&gt;sync_flags| 
           (pPager-&gt;sync_flags==SQLITE_SYNC_FULL?SQLITE_SYNC_DATAONLY:0)
         );
-        if( rc!=SQLITE_OK ) return rc;
+        if( rc!=0 ) return rc;
       }
+      pPager-&gt;journalStarted = 1;
     }
+    pPager-&gt;needSync = 0;
 
-    /* The journal file was just successfully synced. Set Pager.needSync 
-    ** to zero and clear the PGHDR_NEED_SYNC flag on all pagess.
+    /* Erase the needSync flag from every page.
     */
-    pPager-&gt;needSync = 0;
-    pPager-&gt;journalStarted = 1;
     sqlite3PcacheClearSyncFlags(pPager-&gt;pPCache);
   }
 
-  return SQLITE_OK;
+  return rc;
 }
 
 /*
-** The argument is the first in a linked list of dirty pages connected
-** by the PgHdr.pDirty pointer. This function writes each one of the
-** in-memory pages in the list to the database file. The argument may
-** be NULL, representing an empty list. In this case this function is
-** a no-op.
-**
-** The pager must hold at least a RESERVED lock when this function
-** is called. Before writing anything to the database file, this lock
-** is upgraded to an EXCLUSIVE lock. If the lock cannot be obtained,
-** SQLITE_BUSY is returned and no data is written to the database file.
-** 
-** If the pager is a temp-file pager and the actual file-system file
-** is not yet open, it is created and opened before any data is 
-** written out.
-**
-** Once the lock has been upgraded and, if necessary, the file opened,
-** the pages are written out to the database file in list order. Writing
-** a page is skipped if it meets either of the following criteria:
-**
-**   * The page number is greater than Pager.dbSize, or
-**   * The PGHDR_DONT_WRITE flag is set on the page.
-**
-** If writing out a page causes the database file to grow, Pager.dbFileSize
-** is updated accordingly. If page 1 is written out, then the value cached
-** in Pager.dbFileVers[] is updated to match the new value stored in
-** the database file.
-**
-** If everything is successful, SQLITE_OK is returned. If an IO error 
-** occurs, an IO error code is returned. Or, if the EXCLUSIVE lock cannot
-** be obtained, SQLITE_BUSY is returned.
+** Given a list of pages (connected by the PgHdr.pDirty pointer) write
+** every one of those pages out to the database file. No calls are made
+** to the page-cache to mark the pages as clean. It is the responsibility
+** of the caller to use PcacheCleanAll() or PcacheMakeClean() to mark
+** the pages as clean.
 */
 static int pager_write_pagelist(PgHdr *pList){
-  Pager *pPager;                       /* Pager object */
-  int rc;                              /* Return code */
+  Pager *pPager;
+  int rc;
 
   if( pList==0 ) return SQLITE_OK;
   pPager = pList-&gt;pPager;
 
   /* At this point there may be either a RESERVED or EXCLUSIVE lock on the
   ** database file. If there is already an EXCLUSIVE lock, the following
-  ** call is a no-op.
+  ** calls to sqlite3OsLock() are no-ops.
   **
   ** Moving the lock from RESERVED to EXCLUSIVE actually involves going
   ** through an intermediate state PENDING.   A PENDING lock prevents new
@@ -34074,101 +33381,80 @@ static int pager_write_pagelist(PgHdr *pList){
   ** EXCLUSIVE, it means the database file has been changed and any rollback
   ** will require a journal playback.
   */
-  assert( pPager-&gt;state&gt;=PAGER_RESERVED );
   rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK);
-
-  /* If the file is a temp-file has not yet been opened, open it now. It
-  ** is not possible for rc to be other than SQLITE_OK if this branch
-  ** is taken, as pager_wait_on_lock() is a no-op for temp-files.
-  */
-  if( !isOpen(pPager-&gt;fd) ){
-    assert( pPager-&gt;tempFile &amp;&amp; rc==SQLITE_OK );
-    rc = pagerOpentemp(pPager, pPager-&gt;fd, pPager-&gt;vfsFlags);
+  if( rc!=SQLITE_OK ){
+    return rc;
   }
 
-  while( rc==SQLITE_OK &amp;&amp; pList ){
-    Pgno pgno = pList-&gt;pgno;
+  while( pList ){
+
+    /* If the file has not yet been opened, open it now. */
+    if( !pPager-&gt;fd-&gt;pMethods ){
+      assert(pPager-&gt;tempFile);
+      rc = sqlite3PagerOpentemp(pPager, pPager-&gt;fd, pPager-&gt;vfsFlags);
+      if( rc ) return rc;
+    }
 
     /* If there are dirty pages in the page cache with page numbers greater
     ** than Pager.dbSize, this means sqlite3PagerTruncateImage() was called to
     ** make the file smaller (presumably by auto-vacuum code). Do not write
     ** any such pages to the file.
-    **
-    ** Also, do not write out any page that has the PGHDR_DONT_WRITE flag
-    ** set (set by sqlite3PagerDontWrite()).
     */
-    if( pgno&lt;=pPager-&gt;dbSize &amp;&amp; 0==(pList-&gt;flags&amp;PGHDR_DONT_WRITE) ){
-      i64 offset = (pgno-1)*(i64)pPager-&gt;pageSize;         /* Offset to write */
-      char *pData = CODEC2(pPager, pList-&gt;pData, pgno, 6); /* Data to write */
+    if( pList-&gt;pgno&lt;=pPager-&gt;dbSize &amp;&amp; 0==(pList-&gt;flags&amp;PGHDR_DONT_WRITE) ){
+      i64 offset = (pList-&gt;pgno-1)*(i64)pPager-&gt;pageSize;
+      char *pData = CODEC2(pPager, pList-&gt;pData, pList-&gt;pgno, 6);
 
-      /* Write out the page data. */
+      PAGERTRACE((&quot;STORE %d page %d hash(%08x)\n&quot;,
+                   PAGERID(pPager), pList-&gt;pgno, pager_pagehash(pList)));
+      IOTRACE((&quot;PGOUT %p %d\n&quot;, pPager, pList-&gt;pgno));
       rc = sqlite3OsWrite(pPager-&gt;fd, pData, pPager-&gt;pageSize, offset);
-
-      /* If page 1 was just written, update Pager.dbFileVers to match
-      ** the value now stored in the database file. If writing this 
-      ** page caused the database file to grow, update dbFileSize. 
-      */
-      if( pgno==1 ){
+      PAGER_INCR(sqlite3_pager_writedb_count);
+      PAGER_INCR(pPager-&gt;nWrite);
+      if( pList-&gt;pgno==1 ){
         memcpy(&amp;pPager-&gt;dbFileVers, &amp;pData[24], sizeof(pPager-&gt;dbFileVers));
       }
-      if( pgno&gt;pPager-&gt;dbFileSize ){
-        pPager-&gt;dbFileSize = pgno;
+      if( pList-&gt;pgno&gt;pPager-&gt;dbFileSize ){
+        pPager-&gt;dbFileSize = pList-&gt;pgno;
       }
-
-      /* Update any backup objects copying the contents of this pager. */
-      sqlite3BackupUpdate(pPager-&gt;pBackup, pgno, (u8 *)pData);
-
-      PAGERTRACE((&quot;STORE %d page %d hash(%08x)\n&quot;,
-                   PAGERID(pPager), pgno, pager_pagehash(pList)));
-      IOTRACE((&quot;PGOUT %p %d\n&quot;, pPager, pgno));
-      PAGER_INCR(sqlite3_pager_writedb_count);
-      PAGER_INCR(pPager-&gt;nWrite);
-    }else{
-      PAGERTRACE((&quot;NOSTORE %d page %d\n&quot;, PAGERID(pPager), pgno));
     }
+#ifndef NDEBUG
+    else{
+      PAGERTRACE((&quot;NOSTORE %d page %d\n&quot;, PAGERID(pPager), pList-&gt;pgno));
+    }
+#endif
+    if( rc ) return rc;
 #ifdef SQLITE_CHECK_PAGES
     pList-&gt;pageHash = pager_pagehash(pList);
 #endif
     pList = pList-&gt;pDirty;
   }
 
-  return rc;
+  return SQLITE_OK;
 }
 
 /*
-** Append a record of the current state of page pPg to the sub-journal. 
-** It is the callers responsibility to use subjRequiresPage() to check 
-** that it is really required before calling this function.
-**
-** If successful, set the bit corresponding to pPg-&gt;pgno in the bitvecs
-** for all open savepoints before returning.
-**
-** This function returns SQLITE_OK if everything is successful, an IO
-** error code if the attempt to write to the sub-journal fails, or 
-** SQLITE_NOMEM if a malloc fails while setting a bit in a savepoint
-** bitvec.
+** Add the page to the sub-journal. It is the callers responsibility to
+** use subjRequiresPage() to check that it is really required before 
+** calling this function.
 */
 static int subjournalPage(PgHdr *pPg){
-  int rc = SQLITE_OK;
+  int rc;
+  void *pData = pPg-&gt;pData;
   Pager *pPager = pPg-&gt;pPager;
-  if( isOpen(pPager-&gt;sjfd) ){
-    void *pData = pPg-&gt;pData;
-    i64 offset = pPager-&gt;nSubRec*(4+pPager-&gt;pageSize);
-    char *pData2 = CODEC2(pPager, pData, pPg-&gt;pgno, 7);
-  
-    PAGERTRACE((&quot;STMT-JOURNAL %d page %d\n&quot;, PAGERID(pPager), pPg-&gt;pgno));
-  
-    assert( pageInJournal(pPg) || pPg-&gt;pgno&gt;pPager-&gt;dbOrigSize );
-    rc = write32bits(pPager-&gt;sjfd, offset, pPg-&gt;pgno);
-    if( rc==SQLITE_OK ){
-      rc = sqlite3OsWrite(pPager-&gt;sjfd, pData2, pPager-&gt;pageSize, offset+4);
-    }
+  i64 offset = pPager-&gt;stmtNRec*(4+pPager-&gt;pageSize);
+  char *pData2 = CODEC2(pPager, pData, pPg-&gt;pgno, 7);
+
+  PAGERTRACE((&quot;STMT-JOURNAL %d page %d\n&quot;, PAGERID(pPager), pPg-&gt;pgno));
+
+  assert( pageInJournal(pPg) || pPg-&gt;pgno&gt;pPager-&gt;dbOrigSize );
+  rc = write32bits(pPager-&gt;sjfd, offset, pPg-&gt;pgno);
+  if( rc==SQLITE_OK ){
+    rc = sqlite3OsWrite(pPager-&gt;sjfd, pData2, pPager-&gt;pageSize, offset+4);
   }
   if( rc==SQLITE_OK ){
-    pPager-&gt;nSubRec++;
+    pPager-&gt;stmtNRec++;
     assert( pPager-&gt;nSavepoint&gt;0 );
     rc = addToSavepointBitvecs(pPager, pPg-&gt;pgno);
-    testcase( rc!=SQLITE_OK );
   }
   return rc;
 }
@@ -34176,394 +33462,62 @@ static int subjournalPage(PgHdr *pPg){
 
 /*
 ** This function is called by the pcache layer when it has reached some
-** soft memory limit. The first argument is a pointer to a Pager object
-** (cast as a void*). The pager is always 'purgeable' (not an in-memory
-** database). The second argument is a reference to a page that is 
-** currently dirty but has no outstanding references. The page
-** is always associated with the Pager object passed as the first 
-** argument.
-**
-** The job of this function is to make pPg clean by writing its contents
-** out to the database file, if possible. This may involve syncing the
-** journal file. 
-**
-** If successful, sqlite3PcacheMakeClean() is called on the page and
-** SQLITE_OK returned. If an IO error occurs while trying to make the
-** page clean, the IO error code is returned. If the page cannot be
-** made clean for some other reason, but no error occurs, then SQLITE_OK
-** is returned by sqlite3PcacheMakeClean() is not called.
+** soft memory limit. The argument is a pointer to a purgeable Pager 
+** object. This function attempts to make a single dirty page that has no
+** outstanding references (if one exists) clean so that it can be recycled 
+** by the pcache layer.
 */
 static int pagerStress(void *p, PgHdr *pPg){
   Pager *pPager = (Pager *)p;
   int rc = SQLITE_OK;
 
-  assert( pPg-&gt;pPager==pPager );
-  assert( pPg-&gt;flags&amp;PGHDR_DIRTY );
-
-  /* The doNotSync flag is set by the sqlite3PagerWrite() function while it
-  ** is journalling a set of two or more database pages that are stored
-  ** on the same disk sector. Syncing the journal is not allowed while
-  ** this is happening as it is important that all members of such a
-  ** set of pages are synced to disk together. So, if the page this function
-  ** is trying to make clean will require a journal sync and the doNotSync
-  ** flag is set, return without doing anything. The pcache layer will
-  ** just have to go ahead and allocate a new page buffer instead of
-  ** reusing pPg.
-  **
-  ** Similarly, if the pager has already entered the error state, do not
-  ** try to write the contents of pPg to disk.
-  */
-  if( pPager-&gt;errCode || (pPager-&gt;doNotSync &amp;&amp; pPg-&gt;flags&amp;PGHDR_NEED_SYNC) ){
+  if( pPager-&gt;doNotSync ){
     return SQLITE_OK;
   }
 
-  /* Sync the journal file if required. */
-  if( pPg-&gt;flags&amp;PGHDR_NEED_SYNC ){
-    rc = syncJournal(pPager);
-    if( rc==SQLITE_OK &amp;&amp; pPager-&gt;fullSync &amp;&amp; 
-      !(pPager-&gt;journalMode==PAGER_JOURNALMODE_MEMORY) &amp;&amp;
-      !(sqlite3OsDeviceCharacteristics(pPager-&gt;fd)&amp;SQLITE_IOCAP_SAFE_APPEND)
-    ){
-      pPager-&gt;nRec = 0;
-      rc = writeJournalHdr(pPager);
-    }
-  }
-
-  /* If the page number of this page is larger than the current size of
-  ** the database image, it may need to be written to the sub-journal.
-  ** This is because the call to pager_write_pagelist() below will not
-  ** actually write data to the file in this case.
-  **
-  ** Consider the following sequence of events:
-  **
-  **   BEGIN;
-  **     &lt;journal page X&gt;
-  **     &lt;modify page X&gt;
-  **     SAVEPOINT sp;
-  **       &lt;shrink database file to Y pages&gt;
-  **       pagerStress(page X)
-  **     ROLLBACK TO sp;
-  **
-  ** If (X&gt;Y), then when pagerStress is called page X will not be written
-  ** out to the database file, but will be dropped from the cache. Then,
-  ** following the &quot;ROLLBACK TO sp&quot; statement, reading page X will read
-  ** data from the database file. This will be the copy of page X as it
-  ** was when the transaction started, not as it was when &quot;SAVEPOINT sp&quot;
-  ** was executed.
-  **
-  ** The solution is to write the current data for page X into the 
-  ** sub-journal file now (if it is not already there), so that it will
-  ** be restored to its current value when the &quot;ROLLBACK TO sp&quot; is 
-  ** executed.
-  */
-  if( rc==SQLITE_OK &amp;&amp; pPg-&gt;pgno&gt;pPager-&gt;dbSize &amp;&amp; subjRequiresPage(pPg) ){
-    rc = subjournalPage(pPg);
-  }
-
-  /* Write the contents of the page out to the database file. */
-  if( rc==SQLITE_OK ){
-    pPg-&gt;pDirty = 0;
-    rc = pager_write_pagelist(pPg);
-  }
-
-  /* Mark the page as clean. */
-  if( rc==SQLITE_OK ){
-    PAGERTRACE((&quot;STRESS %d page %d\n&quot;, PAGERID(pPager), pPg-&gt;pgno));
-    sqlite3PcacheMakeClean(pPg);
-  }
-
-  return pager_error(pPager, rc);
-}
-
-
-/*
-** Allocate and initialize a new Pager object and put a pointer to it
-** in *ppPager. The pager should eventually be freed by passing it
-** to sqlite3PagerClose().
-**
-** The zFilename argument is the path to the database file to open.
-** If zFilename is NULL then a randomly-named temporary file is created
-** and used as the file to be cached. Temporary files are be deleted
-** automatically when they are closed. If zFilename is &quot;:memory:&quot; then 
-** all information is held in cache. It is never written to disk. 
-** This can be used to implement an in-memory database.
-**
-** The nExtra parameter specifies the number of bytes of space allocated
-** along with each page reference. This space is available to the user
-** via the sqlite3PagerGetExtra() API.
-**
-** The flags argument is used to specify properties that affect the
-** operation of the pager. It should be passed some bitwise combination
-** of the PAGER_OMIT_JOURNAL and PAGER_NO_READLOCK flags.
-**
-** The vfsFlags parameter is a bitmask to pass to the flags parameter
-** of the xOpen() method of the supplied VFS when opening files. 
-**
-** If the pager object is allocated and the specified file opened 
-** successfully, SQLITE_OK is returned and *ppPager set to point to
-** the new pager object. If an error occurs, *ppPager is set to NULL
-** and error code returned. This function may return SQLITE_NOMEM
-** (sqlite3Malloc() is used to allocate memory), SQLITE_CANTOPEN or 
-** various SQLITE_IO_XXX errors.
-*/
-SQLITE_PRIVATE int sqlite3PagerOpen(
-  sqlite3_vfs *pVfs,       /* The virtual file system to use */
-  Pager **ppPager,         /* OUT: Return the Pager structure here */
-  const char *zFilename,   /* Name of the database file to open */
-  int nExtra,              /* Extra bytes append to each in-memory page */
-  int flags,               /* flags controlling this file */
-  int vfsFlags             /* flags passed through to sqlite3_vfs.xOpen() */
-){
-  u8 *pPtr;
-  Pager *pPager = 0;       /* Pager object to allocate and return */
-  int rc = SQLITE_OK;      /* Return code */
-  int tempFile = 0;        /* True for temp files (incl. in-memory files) */
-  int memDb = 0;           /* True if this is an in-memory file */
-  int readOnly = 0;        /* True if this is a read-only file */
-  int journalFileSize;     /* Bytes to allocate for each journal fd */
-  char *zPathname = 0;     /* Full path to database file */
-  int nPathname = 0;       /* Number of bytes in zPathname */
-  int useJournal = (flags &amp; PAGER_OMIT_JOURNAL)==0; /* False to omit journal */
-  int noReadlock = (flags &amp; PAGER_NO_READLOCK)!=0;  /* True to omit read-lock */
-  int pcacheSize = sqlite3PcacheSize();       /* Bytes to allocate for PCache */
-  u16 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE;  /* Default page size */
-
-  /* Figure out how much space is required for each journal file-handle
-  ** (there are two of them, the main journal and the sub-journal). This
-  ** is the maximum space required for an in-memory journal file handle 
-  ** and a regular journal file-handle. Note that a &quot;regular journal-handle&quot;
-  ** may be a wrapper capable of caching the first portion of the journal
-  ** file in memory to implement the atomic-write optimization (see 
-  ** source file journal.c).
-  */
-  if( sqlite3JournalSize(pVfs)&gt;sqlite3MemJournalSize() ){
-    journalFileSize = sqlite3JournalSize(pVfs);
-  }else{
-    journalFileSize = sqlite3MemJournalSize();
-  }
-
-  /* Set the output variable to NULL in case an error occurs. */
-  *ppPager = 0;
-
-  /* Compute and store the full pathname in an allocated buffer pointed
-  ** to by zPathname, length nPathname. Or, if this is a temporary file,
-  ** leave both nPathname and zPathname set to 0.
-  */
-  if( zFilename &amp;&amp; zFilename[0] ){
-    nPathname = pVfs-&gt;mxPathname+1;
-    zPathname = sqlite3Malloc(nPathname*2);
-    if( zPathname==0 ){
-      return SQLITE_NOMEM;
-    }
-#ifndef SQLITE_OMIT_MEMORYDB
-    if( strcmp(zFilename,&quot;:memory:&quot;)==0 ){
-      memDb = 1;
-      zPathname[0] = 0;
-    }else
-#endif
-    {
-      zPathname[0] = 0; /* Make sure initialized even if FullPathname() fails */
-      rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
-    }
-
-    nPathname = sqlite3Strlen30(zPathname);
-    if( rc==SQLITE_OK &amp;&amp; nPathname+8&gt;pVfs-&gt;mxPathname ){
-      /* This branch is taken when the journal path required by
-      ** the database being opened will be more than pVfs-&gt;mxPathname
-      ** bytes in length. This means the database cannot be opened,
-      ** as it will not be possible to open the journal file or even
-      ** check for a hot-journal before reading.
-      */
-      rc = SQLITE_CANTOPEN;
-    }
-    if( rc!=SQLITE_OK ){
-      sqlite3_free(zPathname);
-      return rc;
+  assert( pPg-&gt;flags&amp;PGHDR_DIRTY );
+  if( pPager-&gt;errCode==SQLITE_OK ){
+    if( pPg-&gt;flags&amp;PGHDR_NEED_SYNC ){
+      rc = syncJournal(pPager);
+      if( rc==SQLITE_OK &amp;&amp; pPager-&gt;fullSync &amp;&amp; 
+        !(pPager-&gt;journalMode==PAGER_JOURNALMODE_MEMORY) &amp;&amp;
+        !(sqlite3OsDeviceCharacteristics(pPager-&gt;fd)&amp;SQLITE_IOCAP_SAFE_APPEND)
+      ){
+        pPager-&gt;nRec = 0;
+        rc = writeJournalHdr(pPager);
+      }
     }
-  }
-
-  /* Allocate memory for the Pager structure, PCache object, the
-  ** three file descriptors, the database file name and the journal 
-  ** file name. The layout in memory is as follows:
-  **
-  **     Pager object                    (sizeof(Pager) bytes)
-  **     PCache object                   (sqlite3PcacheSize() bytes)
-  **     Database file handle            (pVfs-&gt;szOsFile bytes)
-  **     Sub-journal file handle         (journalFileSize bytes)
-  **     Main journal file handle        (journalFileSize bytes)
-  **     Database file name              (nPathname+1 bytes)
-  **     Journal file name               (nPathname+8+1 bytes)
-  */
-  pPtr = (u8 *)sqlite3MallocZero(
-    sizeof(*pPager) +           /* Pager structure */
-    pcacheSize      +           /* PCache object */
-    pVfs-&gt;szOsFile  +           /* The main db file */
-    journalFileSize * 2 +       /* The two journal files */ 
-    nPathname + 1 +             /* zFilename */
-    nPathname + 8 + 1           /* zJournal */
-  );
-  if( !pPtr ){
-    sqlite3_free(zPathname);
-    return SQLITE_NOMEM;
-  }
-  pPager =              (Pager*)(pPtr);
-  pPager-&gt;pPCache =    (PCache*)(pPtr += sizeof(*pPager));
-  pPager-&gt;fd =   (sqlite3_file*)(pPtr += pcacheSize);
-  pPager-&gt;sjfd = (sqlite3_file*)(pPtr += pVfs-&gt;szOsFile);
-  pPager-&gt;jfd =  (sqlite3_file*)(pPtr += journalFileSize);
-  pPager-&gt;zFilename =    (char*)(pPtr += journalFileSize);
-
-  /* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */
-  if( zPathname ){
-    pPager-&gt;zJournal =   (char*)(pPtr += nPathname + 1);
-    memcpy(pPager-&gt;zFilename, zPathname, nPathname);
-    memcpy(pPager-&gt;zJournal, zPathname, nPathname);
-    memcpy(&amp;pPager-&gt;zJournal[nPathname], &quot;-journal&quot;, 8);
-    sqlite3_free(zPathname);
-  }
-  pPager-&gt;pVfs = pVfs;
-  pPager-&gt;vfsFlags = vfsFlags;
-
-  /* Open the pager file.
-  */
-  if( zFilename &amp;&amp; zFilename[0] &amp;&amp; !memDb ){
-    int fout = 0;                    /* VFS flags returned by xOpen() */
-    rc = sqlite3OsOpen(pVfs, pPager-&gt;zFilename, pPager-&gt;fd, vfsFlags, &amp;fout);
-    readOnly = (fout&amp;SQLITE_OPEN_READONLY);
-
-    /* If the file was successfully opened for read/write access,
-    ** choose a default page size in case we have to create the
-    ** database file. The default page size is the maximum of:
-    **
-    **    + SQLITE_DEFAULT_PAGE_SIZE,
-    **    + The value returned by sqlite3OsSectorSize()
-    **    + The largest page size that can be written atomically.
-    */
-    if( rc==SQLITE_OK &amp;&amp; !readOnly ){
-      setSectorSize(pPager);
-      assert(SQLITE_DEFAULT_PAGE_SIZE&lt;=SQLITE_MAX_DEFAULT_PAGE_SIZE);
-      if( szPageDflt&lt;pPager-&gt;sectorSize ){
-        if( pPager-&gt;sectorSize&gt;SQLITE_MAX_DEFAULT_PAGE_SIZE ){
-          szPageDflt = SQLITE_MAX_DEFAULT_PAGE_SIZE;
-        }else{
-          szPageDflt = (u16)pPager-&gt;sectorSize;
-        }
+    if( rc==SQLITE_OK ){
+      pPg-&gt;pDirty = 0;
+      if( pPg-&gt;pgno&gt;pPager-&gt;dbSize &amp;&amp; subjRequiresPage(pPg) ){
+        rc = subjournalPage(pPg);
       }
-#ifdef SQLITE_ENABLE_ATOMIC_WRITE
-      {
-        int iDc = sqlite3OsDeviceCharacteristics(pPager-&gt;fd);
-        int ii;
-        assert(SQLITE_IOCAP_ATOMIC512==(512&gt;&gt;8));
-        assert(SQLITE_IOCAP_ATOMIC64K==(65536&gt;&gt;8));
-        assert(SQLITE_MAX_DEFAULT_PAGE_SIZE&lt;=65536);
-        for(ii=szPageDflt; ii&lt;=SQLITE_MAX_DEFAULT_PAGE_SIZE; ii=ii*2){
-          if( iDc&amp;(SQLITE_IOCAP_ATOMIC|(ii&gt;&gt;8)) ){
-            szPageDflt = ii;
-          }
-        }
+      if( rc==SQLITE_OK ){
+        rc = pager_write_pagelist(pPg);
       }
-#endif
     }
-  }else{
-    /* If a temporary file is requested, it is not opened immediately.
-    ** In this case we accept the default page size and delay actually
-    ** opening the file until the first call to OsWrite().
-    **
-    ** This branch is also run for an in-memory database. An in-memory
-    ** database is the same as a temp-file that is never written out to
-    ** disk and uses an in-memory rollback journal.
-    */ 
-    tempFile = 1;
-    pPager-&gt;state = PAGER_EXCLUSIVE;
+    if( rc!=SQLITE_OK ){
+      pager_error(pPager, rc);
+    }
   }
 
-  /* The following call to PagerSetPagesize() serves to set the value of 
-  ** Pager.pageSize and to allocate the Pager.pTmpSpace buffer.
-  */
   if( rc==SQLITE_OK ){
-    assert( pPager-&gt;memDb==0 );
-    rc = sqlite3PagerSetPagesize(pPager, &amp;szPageDflt);
-    testcase( rc!=SQLITE_OK );
-  }
-
-  /* If an error occured in either of the blocks above, free the 
-  ** Pager structure and close the file.
-  */
-  if( rc!=SQLITE_OK ){
-    assert( !pPager-&gt;pTmpSpace );
-    sqlite3OsClose(pPager-&gt;fd);
-    sqlite3_free(pPager);
-    return rc;
-  }
-
-  /* Initialize the PCache object. */
-  nExtra = FORCE_ALIGNMENT(nExtra);
-  sqlite3PcacheOpen(szPageDflt, nExtra, !memDb,
-                    !memDb?pagerStress:0, (void *)pPager, pPager-&gt;pPCache);
-
-  PAGERTRACE((&quot;OPEN %d %s\n&quot;, FILEHANDLEID(pPager-&gt;fd), pPager-&gt;zFilename));
-  IOTRACE((&quot;OPEN %p %s\n&quot;, pPager, pPager-&gt;zFilename))
-
-  pPager-&gt;useJournal = (u8)useJournal;
-  pPager-&gt;noReadlock = (noReadlock &amp;&amp; readOnly) ?1:0;
-  /* pPager-&gt;stmtOpen = 0; */
-  /* pPager-&gt;stmtInUse = 0; */
-  /* pPager-&gt;nRef = 0; */
-  pPager-&gt;dbSizeValid = (u8)memDb;
-  /* pPager-&gt;stmtSize = 0; */
-  /* pPager-&gt;stmtJSize = 0; */
-  /* pPager-&gt;nPage = 0; */
-  pPager-&gt;mxPgno = SQLITE_MAX_PAGE_COUNT;
-  /* pPager-&gt;state = PAGER_UNLOCK; */
-  assert( pPager-&gt;state == (tempFile ? PAGER_EXCLUSIVE : PAGER_UNLOCK) );
-  /* pPager-&gt;errMask = 0; */
-  pPager-&gt;tempFile = (u8)tempFile;
-  assert( tempFile==PAGER_LOCKINGMODE_NORMAL 
-          || tempFile==PAGER_LOCKINGMODE_EXCLUSIVE );
-  assert( PAGER_LOCKINGMODE_EXCLUSIVE==1 );
-  pPager-&gt;exclusiveMode = (u8)tempFile; 
-  pPager-&gt;changeCountDone = pPager-&gt;tempFile;
-  pPager-&gt;memDb = (u8)memDb;
-  pPager-&gt;readOnly = (u8)readOnly;
-  /* pPager-&gt;needSync = 0; */
-  pPager-&gt;noSync = (pPager-&gt;tempFile || !useJournal) ?1:0;
-  pPager-&gt;fullSync = pPager-&gt;noSync ?0:1;
-  pPager-&gt;sync_flags = SQLITE_SYNC_NORMAL;
-  /* pPager-&gt;pFirst = 0; */
-  /* pPager-&gt;pFirstSynced = 0; */
-  /* pPager-&gt;pLast = 0; */
-  pPager-&gt;nExtra = nExtra;
-  pPager-&gt;journalSizeLimit = SQLITE_DEFAULT_JOURNAL_SIZE_LIMIT;
-  assert( isOpen(pPager-&gt;fd) || tempFile );
-  setSectorSize(pPager);
-  if( memDb ){
-    pPager-&gt;journalMode = PAGER_JOURNALMODE_MEMORY;
+    PAGERTRACE((&quot;STRESS %d page %d\n&quot;, PAGERID(pPager), pPg-&gt;pgno));
+    sqlite3PcacheMakeClean(pPg);
   }
-  /* pPager-&gt;xBusyHandler = 0; */
-  /* pPager-&gt;pBusyHandlerArg = 0; */
-  /* memset(pPager-&gt;aHash, 0, sizeof(pPager-&gt;aHash)); */
-  *ppPager = pPager;
-  return SQLITE_OK;
+  return rc;
 }
 
 
-
 /*
-** This function is called after transitioning from PAGER_UNLOCK to
-** PAGER_SHARED state. It tests if there is a hot journal present in
-** the file-system for the given pager. A hot journal is one that 
-** needs to be played back. According to this function, a hot-journal
-** file exists if the following three criteria are met:
-**
-**   * The journal file exists in the file system, and
-**   * No process holds a RESERVED or greater lock on the database file, and
-**   * The database file itself is greater than 0 bytes in size.
+** Return 1 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. In this case the journal file is
-** just deleted using OsDelete, *pExists is set to 0 and SQLITE_OK
-** is returned.
+** database with the same name.  Just delete the journal.
+**
+** Return negative if unable to determine the status of the journal.
 **
 ** This routine does not open the journal file to examine its
 ** content.  Hence, the journal might contain the name of a master
@@ -34573,36 +33527,28 @@ SQLITE_PRIVATE int sqlite3PagerOpen(
 ** journal file exists and is not empty this routine assumes it
 ** is hot.  The pager_playback() routine will discover that the
 ** journal file is not really hot and will no-op.
-**
-** If a hot-journal file is found to exist, *pExists is set to 1 and 
-** SQLITE_OK returned. If no hot-journal file is present, *pExists is
-** set to 0 and SQLITE_OK returned. If an IO error occurs while trying
-** to determine whether or not a hot-journal file exists, the IO error
-** code is returned and the value of *pExists is undefined.
 */
 static int hasHotJournal(Pager *pPager, int *pExists){
-  sqlite3_vfs * const pVfs = pPager-&gt;pVfs;
-  int rc;                       /* Return code */
-  int exists = 0;               /* True if a journal file is present */
-  int locked = 0;               /* True if some process holds a RESERVED lock */
-
+  sqlite3_vfs *pVfs = pPager-&gt;pVfs;
+  int rc = SQLITE_OK;
+  int exists = 0;
+  int locked = 0;
   assert( pPager!=0 );
   assert( pPager-&gt;useJournal );
-  assert( isOpen(pPager-&gt;fd) );
-
+  assert( pPager-&gt;fd-&gt;pMethods );
   *pExists = 0;
   rc = sqlite3OsAccess(pVfs, pPager-&gt;zJournal, SQLITE_ACCESS_EXISTS, &amp;exists);
   if( rc==SQLITE_OK &amp;&amp; exists ){
     rc = sqlite3OsCheckReservedLock(pPager-&gt;fd, &amp;locked);
-    if( rc==SQLITE_OK &amp;&amp; !locked ){
-      int nPage;
-      rc = sqlite3PagerPagecount(pPager, &amp;nPage);
-      if( rc==SQLITE_OK ){
-       if( nPage==0 ){
-          sqlite3OsDelete(pVfs, pPager-&gt;zJournal, 0);
-        }else{
-          *pExists = 1;
-        }
+  }
+  if( rc==SQLITE_OK &amp;&amp; exists &amp;&amp; !locked ){
+    int nPage;
+    rc = sqlite3PagerPagecount(pPager, &amp;nPage);
+    if( rc==SQLITE_OK ){
+     if( nPage==0 ){
+        sqlite3OsDelete(pVfs, pPager-&gt;zJournal, 0);
+      }else{
+        *pExists = 1;
       }
     }
   }
@@ -34610,89 +33556,54 @@ static int hasHotJournal(Pager *pPager, int *pExists){
 }
 
 /*
-** Read the content for page pPg out of the database file and into 
-** pPg-&gt;pData. A shared lock or greater must be held on the database
-** file before this function is called.
-**
-** If page 1 is read, then the value of Pager.dbFileVers[] is set to
-** the value read from the database file.
-**
-** If an IO error occurs, then the IO error is returned to the caller.
-** Otherwise, SQLITE_OK is returned.
+** Read the content of page pPg out of the database file.
 */
-static int readDbPage(PgHdr *pPg){
-  Pager *pPager = pPg-&gt;pPager; /* Pager object associated with page pPg */
-  Pgno pgno = pPg-&gt;pgno;       /* Page number to read */
-  int rc;                      /* Return code */
-  i64 iOffset;                 /* Byte offset of file to read from */
-
-  assert( pPager-&gt;state&gt;=PAGER_SHARED &amp;&amp; !MEMDB );
-
-  if( !isOpen(pPager-&gt;fd) ){
-    assert( pPager-&gt;tempFile );
-    memset(pPg-&gt;pData, 0, pPager-&gt;pageSize);
+static int readDbPage(Pager *pPager, PgHdr *pPg, Pgno pgno){
+  int rc;
+  i64 offset;
+  assert( MEMDB==0 );
+  assert(pPager-&gt;fd-&gt;pMethods||pPager-&gt;tempFile);
+  if( !pPager-&gt;fd-&gt;pMethods ){
     return SQLITE_IOERR_SHORT_READ;
   }
-  iOffset = (pgno-1)*(i64)pPager-&gt;pageSize;
-  rc = sqlite3OsRead(pPager-&gt;fd, pPg-&gt;pData, pPager-&gt;pageSize, iOffset);
-  if( pgno==1 ){
-    u8 *dbFileVers = &amp;((u8*)pPg-&gt;pData)[24];
-    memcpy(&amp;pPager-&gt;dbFileVers, dbFileVers, sizeof(pPager-&gt;dbFileVers));
-  }
-  CODEC1(pPager, pPg-&gt;pData, pgno, 3);
-
+  offset = (pgno-1)*(i64)pPager-&gt;pageSize;
+  rc = sqlite3OsRead(pPager-&gt;fd, pPg-&gt;pData, pPager-&gt;pageSize, offset);
   PAGER_INCR(sqlite3_pager_readdb_count);
   PAGER_INCR(pPager-&gt;nRead);
   IOTRACE((&quot;PGIN %p %d\n&quot;, pPager, pgno));
+  if( pgno==1 ){
+    memcpy(&amp;pPager-&gt;dbFileVers, &amp;((u8*)pPg-&gt;pData)[24],
+                                              sizeof(pPager-&gt;dbFileVers));
+  }
+  CODEC1(pPager, pPg-&gt;pData, pPg-&gt;pgno, 3);
   PAGERTRACE((&quot;FETCH %d page %d hash(%08x)\n&quot;,
-               PAGERID(pPager), pgno, pager_pagehash(pPg)));
-
+               PAGERID(pPager), pPg-&gt;pgno, pager_pagehash(pPg)));
   return rc;
 }
 
+
 /*
-** This function is called whenever the upper layer requests a database
-** page is requested, before the cache is checked for a suitable page
-** or any data is read from the database. It performs the following
-** two functions:
-**
-**   1) If the pager is currently in PAGER_UNLOCK state (no lock held
-**      on the database file), then an attempt is made to obtain a
-**      SHARED lock on the database file. Immediately after obtaining
-**      the SHARED lock, the file-system is checked for a hot-journal,
-**      which is played back if present. Following any hot-journal 
-**      rollback, the contents of the cache are validated by checking
-**      the 'change-counter' field of the database file header and
-**      discarded if they are found to be invalid.
-**
-**   2) If the pager is running in exclusive-mode, and there are currently
-**      no outstanding references to any pages, and is in the error state,
-**      then an attempt is made to clear the error state by discarding
-**      the contents of the page cache and rolling back any open journal
-**      file.
+** This function is called to obtain the shared lock required before
+** data may be read from the pager cache. If the shared lock has already
+** been obtained, this function is a no-op.
 **
-** If the operation described by (2) above is not attempted, and if the
-** pager is in an error state other than SQLITE_FULL when this is called,
-** the error state error code is returned. It is permitted to read the
-** database when in SQLITE_FULL error state.
-**
-** Otherwise, if everything is successful, SQLITE_OK is returned. If an
-** IO error occurs while locking the database, checking for a hot-journal
-** file or rolling back a journal file, the IO error code is returned.
+** Immediately after obtaining the shared lock (if required), this function
+** checks for a hot-journal file. If one is found, an emergency rollback
+** is performed immediately.
 */
 static int pagerSharedLock(Pager *pPager){
-  int rc = SQLITE_OK;                /* Return code */
-  int isErrorReset = 0;              /* True if recovering from error state */
+  int rc = SQLITE_OK;
+  int isErrorReset = 0;
 
   /* If this database is opened for exclusive access, has no outstanding 
-  ** page references and is in an error-state, this is a chance to clear
+  ** page references and is in an error-state, now is the chance to clear
   ** the error. Discard the contents of the pager-cache and treat any
   ** open journal file as a hot-journal.
   */
   if( !MEMDB &amp;&amp; pPager-&gt;exclusiveMode 
    &amp;&amp; sqlite3PcacheRefCount(pPager-&gt;pPCache)==0 &amp;&amp; pPager-&gt;errCode 
   ){
-    if( isOpen(pPager-&gt;jfd) ){
+    if( pPager-&gt;journalOpen ){
       isErrorReset = 1;
     }
     pPager-&gt;errCode = SQLITE_OK;
@@ -34708,7 +33619,7 @@ static int pagerSharedLock(Pager *pPager){
   }
 
   if( pPager-&gt;state==PAGER_UNLOCK || isErrorReset ){
-    sqlite3_vfs * const pVfs = pPager-&gt;pVfs;
+    sqlite3_vfs *pVfs = pPager-&gt;pVfs;
     int isHotJournal = 0;
     assert( !MEMDB );
     assert( sqlite3PcacheRefCount(pPager-&gt;pPCache)==0 );
@@ -34737,13 +33648,12 @@ static int pagerSharedLock(Pager *pPager){
       ** important that a RESERVED lock is not obtained on the way to the
       ** EXCLUSIVE lock. If it were, another process might open the
       ** database file, detect the RESERVED lock, and conclude that the
-      ** database is safe to read while this process is still rolling the 
-      ** hot-journal back.
+      ** database is safe to read while this process is still rolling it 
+      ** back.
       ** 
-      ** Because the intermediate RESERVED lock is not requested, any
-      ** other process attempting to access the database file will get to 
-      ** this point in the code and fail to obtain its own EXCLUSIVE lock 
-      ** on the database file.
+      ** Because the intermediate RESERVED lock is not requested, the
+      ** second process will get to this point in the code and fail to
+      ** obtain its own EXCLUSIVE lock on the database file.
       */
       if( pPager-&gt;state&lt;EXCLUSIVE_LOCK ){
         rc = sqlite3OsLock(pPager-&gt;fd, EXCLUSIVE_LOCK);
@@ -34760,7 +33670,7 @@ static int pagerSharedLock(Pager *pPager){
       ** OsTruncate() call used in exclusive-access mode also requires
       ** a read/write file handle.
       */
-      if( !isOpen(pPager-&gt;jfd) ){
+      if( !isErrorReset &amp;&amp; pPager-&gt;journalOpen==0 ){
         int res;
         rc = sqlite3OsAccess(pVfs,pPager-&gt;zJournal,SQLITE_ACCESS_EXISTS,&amp;res);
         if( rc==SQLITE_OK ){
@@ -34769,7 +33679,7 @@ static int pagerSharedLock(Pager *pPager){
             int f = SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_JOURNAL;
             assert( !pPager-&gt;tempFile );
             rc = sqlite3OsOpen(pVfs, pPager-&gt;zJournal, pPager-&gt;jfd, f, &amp;fout);
-            assert( rc!=SQLITE_OK || isOpen(pPager-&gt;jfd) );
+            assert( rc!=SQLITE_OK || pPager-&gt;jfd-&gt;pMethods );
             if( rc==SQLITE_OK &amp;&amp; fout&amp;SQLITE_OPEN_READONLY ){
               rc = SQLITE_CANTOPEN;
               sqlite3OsClose(pPager-&gt;jfd);
@@ -34784,8 +33694,7 @@ static int pagerSharedLock(Pager *pPager){
       if( rc!=SQLITE_OK ){
         goto failed;
       }
-
-      /* TODO: Why are these cleared here? Is it necessary? */
+      pPager-&gt;journalOpen = 1;
       pPager-&gt;journalStarted = 0;
       pPager-&gt;journalOff = 0;
       pPager-&gt;setMaster = 0;
@@ -34796,13 +33705,14 @@ static int pagerSharedLock(Pager *pPager){
       ** playing back the hot-journal so that we don't end up with
       ** an inconsistent cache.
       */
+      sqlite3PcacheClear(pPager-&gt;pPCache);
       rc = pager_playback(pPager, 1);
       if( rc!=SQLITE_OK ){
         rc = pager_error(pPager, rc);
         goto failed;
       }
-      assert( (pPager-&gt;state==PAGER_SHARED)
-           || (pPager-&gt;exclusiveMode &amp;&amp; pPager-&gt;state&gt;PAGER_SHARED)
+      assert(pPager-&gt;state==PAGER_SHARED || 
+          (pPager-&gt;exclusiveMode &amp;&amp; pPager-&gt;state&gt;PAGER_SHARED)
       );
     }
 
@@ -34858,11 +33768,32 @@ static int pagerSharedLock(Pager *pPager){
 }
 
 /*
-** If the reference count has reached zero, rollback any active
-** transaction and unlock the pager.
+** Make sure we have the content for a page.  If the page was
+** previously acquired with noContent==1, then the content was
+** just initialized to zeros instead of being read from disk.
+** But now we need the real data off of disk.  So make sure we
+** have it.  Read it in if we do not have it already.
+*/
+static int pager_get_content(PgHdr *pPg){
+  if( pPg-&gt;flags&amp;PGHDR_NEED_READ ){
+    int rc = readDbPage(pPg-&gt;pPager, pPg, pPg-&gt;pgno);
+    if( rc==SQLITE_OK ){
+      pPg-&gt;flags &amp;= ~PGHDR_NEED_READ;
+    }else{
+      return rc;
+    }
+  }
+  return SQLITE_OK;
+}
+
+/*
+** If the reference count has reached zero, and the pager is not in the
+** middle of a write transaction or opened in exclusive mode, unlock it.
 */ 
 static void pagerUnlockIfUnused(Pager *pPager){
-  if( sqlite3PcacheRefCount(pPager-&gt;pPCache)==0 ){
+  if( (sqlite3PcacheRefCount(pPager-&gt;pPCache)==0)
+    &amp;&amp; (!pPager-&gt;exclusiveMode || pPager-&gt;journalOff&gt;0) 
+  ){
     pagerUnlockAndRollback(pPager);
   }
 }
@@ -34880,48 +33811,16 @@ static void pagerDropPage(DbPage *pPg){
 }
 
 /*
-** Acquire a reference to page number pgno in pager pPager (a page
-** reference has type DbPage*). If the requested reference is 
-** successfully obtained, it is copied to *ppPage and SQLITE_OK returned.
-**
-** This function calls pagerSharedLock() to obtain a SHARED lock on
-** the database file if such a lock or greater is not already held.
-** This may cause hot-journal rollback or a cache purge. See comments
-** above function pagerSharedLock() for details.
+** Acquire a page.
 **
-** If the requested page is already in the cache, it is returned. 
-** Otherwise, a new page object is allocated and populated with data
-** read from the database file. In some cases, the pcache module may
-** choose not to allocate a new page object and may reuse an existing
-** object with no outstanding references.
+** A read lock on the disk file is obtained when the first page is acquired. 
+** This read lock is dropped when the last page is released.
 **
-** The extra data appended to a page is always initialized to zeros the 
-** first time a page is loaded into memory. If the page requested is 
-** already in the cache when this function is called, then the extra
-** data is left as it was when the page object was last used.
-**
-** If the database image is smaller than the requested page or if a 
-** non-zero value is passed as the noContent parameter and the 
-** requested page is not already stored in the cache, then no 
-** actual disk read occurs. In this case the memory image of the 
-** page is initialized to all zeros. 
-**
-** If noContent is true, it means that we do not care about the contents
-** of the page. This occurs in two seperate scenarios:
-**
-**   a) When reading a free-list leaf page from the database, and
-**
-**   b) When a savepoint is being rolled back and we need to load
-**      a new page into the cache to populate with the data read
-**      from the savepoint journal.
-**
-** If noContent is true, then the data returned is zeroed instead of
-** being read from the database. Additionally, the bits corresponding
-** to pgno in Pager.pInJournal (bitvec of pages already written to the
-** journal file) and the PagerSavepoint.pInSavepoint bitvecs of any open
-** savepoints are set. This means if the page is made writable at any
-** point in the future, using a call to sqlite3PagerWrite(), its contents
-** will not be journaled. This saves IO.
+** This routine works for any page number greater than 0.  If the database
+** file is smaller than the requested page, then no actual disk
+** read occurs and the memory image of the page is initialized to
+** all zeros.  The extra data appended to a page is always initialized
+** to zeros the first time a page is loaded into memory.
 **
 ** The acquisition might fail for several reasons.  In all cases,
 ** an appropriate error code is returned and *ppPage is set to NULL.
@@ -34933,6 +33832,15 @@ static void pagerDropPage(DbPage *pPg){
 ** has to go to disk, and could also playback an old journal if necessary.
 ** Since Lookup() never goes to disk, it never has to deal with locks
 ** or journal files.
+**
+** If noContent is false, the page contents are actually read from disk.
+** If noContent is true, it means that we do not care about the contents
+** of the page at this time, so do not do a disk read.  Just fill in the
+** page content with zeros.  But mark the fact that we have not read the
+** content by setting the PgHdr.needRead flag.  Later on, if 
+** sqlite3PagerWrite() is called on this page or if this routine is
+** called again with noContent==0, that means that the content is needed
+** and the disk read should occur at that point.
 */
 SQLITE_PRIVATE int sqlite3PagerAcquire(
   Pager *pPager,      /* The pager open on the database file */
@@ -34943,7 +33851,6 @@ SQLITE_PRIVATE int sqlite3PagerAcquire(
   PgHdr *pPg = 0;
   int rc;
 
-  assert( assert_pager_state(pPager) );
   assert( pPager-&gt;state==PAGER_UNLOCK 
        || sqlite3PcacheRefCount(pPager-&gt;pPCache)&gt;0 
        || pgno==1
@@ -34975,8 +33882,6 @@ SQLITE_PRIVATE int sqlite3PagerAcquire(
   if( rc!=SQLITE_OK ){
     return rc;
   }
-  assert( pPg-&gt;pgno==pgno );
-  assert( pPg-&gt;pPager==pPager || pPg-&gt;pPager==0 );
   if( pPg-&gt;pPager==0 ){
     /* The pager cache has created a new page. Its content needs to 
     ** be initialized.
@@ -34984,6 +33889,7 @@ SQLITE_PRIVATE int sqlite3PagerAcquire(
     int nMax;
     PAGER_INCR(pPager-&gt;nMiss);
     pPg-&gt;pPager = pPager;
+    memset(pPg-&gt;pExtra, 0, pPager-&gt;nExtra);
 
     rc = sqlite3PagerPagecount(pPager, &amp;nMax);
     if( rc!=SQLITE_OK ){
@@ -34996,29 +33902,15 @@ SQLITE_PRIVATE int sqlite3PagerAcquire(
         sqlite3PagerUnref(pPg);
         return SQLITE_FULL;
       }
+      memset(pPg-&gt;pData, 0, pPager-&gt;pageSize);
       if( noContent ){
-        /* Failure to set the bits in the InJournal bit-vectors is benign.
-        ** It merely means that we might do some extra work to journal a 
-        ** page that does not need to be journaled.  Nevertheless, be sure 
-        ** to test the case where a malloc error occurs while trying to set 
-        ** a bit in a bit vector.
-        */
-        sqlite3BeginBenignMalloc();
-        if( pgno&lt;=pPager-&gt;dbOrigSize ){
-          TESTONLY( rc = ) sqlite3BitvecSet(pPager-&gt;pInJournal, pgno);
-          testcase( rc==SQLITE_NOMEM );
-        }
-        TESTONLY( rc = ) addToSavepointBitvecs(pPager, pgno);
-        testcase( rc==SQLITE_NOMEM );
-        sqlite3EndBenignMalloc();
-      }else{
-        memset(pPg-&gt;pData, 0, pPager-&gt;pageSize);
+        pPg-&gt;flags |= PGHDR_NEED_READ;
       }
       IOTRACE((&quot;ZERO %p %d\n&quot;, pPager, pgno));
     }else{
-      assert( pPg-&gt;pPager==pPager );
-      rc = readDbPage(pPg);
+      rc = readDbPage(pPager, pPg, pgno);
       if( rc!=SQLITE_OK &amp;&amp; rc!=SQLITE_IOERR_SHORT_READ ){
+        /* sqlite3PagerUnref(pPg); */
         pagerDropPage(pPg);
         return rc;
       }
@@ -35028,7 +33920,15 @@ SQLITE_PRIVATE int sqlite3PagerAcquire(
 #endif
   }else{
     /* The requested page is in the page cache. */
+    assert(sqlite3PcacheRefCount(pPager-&gt;pPCache)&gt;0 || pgno==1);
     PAGER_INCR(pPager-&gt;nHit);
+    if( !noContent ){
+      rc = pager_get_content(pPg);
+      if( rc ){
+        sqlite3PagerUnref(pPg);
+        return rc;
+      }
+    }
   }
 
   *ppPage = pPg;
@@ -35038,9 +33938,7 @@ SQLITE_PRIVATE int sqlite3PagerAcquire(
 /*
 ** Acquire a page if it is already in the in-memory cache.  Do
 ** not read the page from disk.  Return a pointer to the page,
-** or 0 if the page is not in cache. Also, return 0 if the 
-** pager is in PAGER_UNLOCK state when this function is called,
-** or if the pager is in an error state other than SQLITE_FULL.
+** or 0 if the page is not in cache.
 **
 ** See also sqlite3PagerGet().  The difference between this routine
 ** and sqlite3PagerGet() is that _get() will go to the disk and read
@@ -35063,19 +33961,20 @@ SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno){
 }
 
 /*
-** Release a page reference.
+** Release a page.
 **
 ** If the number of references to the page drop to zero, then the
 ** page is added to the LRU list.  When all references to all pages
 ** are released, a rollback occurs and the lock on the database is
 ** removed.
 */
-SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){
+SQLITE_PRIVATE int sqlite3PagerUnref(DbPage *pPg){
   if( pPg ){
     Pager *pPager = pPg-&gt;pPager;
     sqlite3PcacheRelease(pPg);
     pagerUnlockIfUnused(pPager);
   }
+  return SQLITE_OK;
 }
 
 /*
@@ -35083,79 +33982,54 @@ SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){
 ** sub-journal file is open too. If the main journal is not open,
 ** this function is a no-op.
 **
-** SQLITE_OK is returned if everything goes according to plan. 
-** An SQLITE_IOERR_XXX error code is returned if a call to 
+** SQLITE_OK is returned if everything goes according to plan. An 
+** SQLITE_IOERR_XXX error code is returned if the call to 
 ** sqlite3OsOpen() fails.
 */
 static int openSubJournal(Pager *pPager){
   int rc = SQLITE_OK;
-  if( isOpen(pPager-&gt;jfd) &amp;&amp; !isOpen(pPager-&gt;sjfd) ){
+  if( pPager-&gt;journalOpen &amp;&amp; !pPager-&gt;sjfd-&gt;pMethods ){
     if( pPager-&gt;journalMode==PAGER_JOURNALMODE_MEMORY ){
       sqlite3MemJournalOpen(pPager-&gt;sjfd);
     }else{
-      rc = pagerOpentemp(pPager, pPager-&gt;sjfd, SQLITE_OPEN_SUBJOURNAL);
+      rc = sqlite3PagerOpentemp(pPager, pPager-&gt;sjfd, SQLITE_OPEN_SUBJOURNAL);
     }
   }
   return rc;
 }
 
 /*
-** This function is called at the start of every write transaction.
-** There must already be a RESERVED or EXCLUSIVE lock on the database 
-** file when this routine is called.
-**
-** Open the journal file for pager pPager and write a journal header
-** to the start of it. If there are active savepoints, open the sub-journal
-** as well. This function is only used when the journal file is being 
-** opened to write a rollback log for a transaction. It is not used 
-** when opening a hot journal file to roll it back.
-**
-** If the journal file is already open (as it may be in exclusive mode),
-** then this function just writes a journal header to the start of the
-** already open file. 
-**
-** Whether or not the journal file is opened by this function, the
-** Pager.pInJournal bitvec structure is allocated.
+** Create a journal file for pPager.  There should already be a RESERVED
+** or EXCLUSIVE lock on the database file when this routine is called.
 **
-** Return SQLITE_OK if everything is successful. Otherwise, return 
-** SQLITE_NOMEM if the attempt to allocate Pager.pInJournal fails, or 
-** an IO error code if opening or writing the journal file fails.
+** Return SQLITE_OK if everything.  Return an error code and release the
+** write lock if anything goes wrong.
 */
 static int pager_open_journal(Pager *pPager){
-  int rc = SQLITE_OK;                        /* Return code */
-  sqlite3_vfs * const pVfs = pPager-&gt;pVfs;   /* Local cache of vfs pointer */
+  sqlite3_vfs *pVfs = pPager-&gt;pVfs;
+  int flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_EXCLUSIVE|SQLITE_OPEN_CREATE);
 
+  int rc;
   assert( pPager-&gt;state&gt;=PAGER_RESERVED );
   assert( pPager-&gt;useJournal );
   assert( pPager-&gt;pInJournal==0 );
-  
-  /* If already in the error state, this function is a no-op. */
-  if( pPager-&gt;errCode ){
-    return pPager-&gt;errCode;
-  }
-
-  /* TODO: Is it really possible to get here with dbSizeValid==0? If not,
-  ** the call to PagerPagecount() can be removed.
-  */
-  testcase( pPager-&gt;dbSizeValid==0 );
   sqlite3PagerPagecount(pPager, 0);
-
   pPager-&gt;pInJournal = sqlite3BitvecCreate(pPager-&gt;dbSize);
   if( pPager-&gt;pInJournal==0 ){
-    return SQLITE_NOMEM;
+    rc = SQLITE_NOMEM;
+    goto failed_to_open_journal;
   }
 
-  /* Open the journal file if it is not already open. */
-  if( !isOpen(pPager-&gt;jfd) ){
+  if( pPager-&gt;journalOpen==0 ){
+    if( pPager-&gt;tempFile ){
+      flags |= (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL);
+    }else{
+      flags |= (SQLITE_OPEN_MAIN_JOURNAL);
+    }
     if( pPager-&gt;journalMode==PAGER_JOURNALMODE_MEMORY ){
       sqlite3MemJournalOpen(pPager-&gt;jfd);
+      rc = SQLITE_OK;
     }else{
-      const int flags =                   /* VFS flags to open journal file */
-        SQLITE_OPEN_READWRITE|SQLITE_OPEN_EXCLUSIVE|SQLITE_OPEN_CREATE|
-        (pPager-&gt;tempFile ? 
-          (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL):
-          (SQLITE_OPEN_MAIN_JOURNAL)
-        );
 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
       rc = sqlite3JournalOpen(
           pVfs, pPager-&gt;zJournal, pPager-&gt;jfd, flags, jrnlBufferSize(pPager)
@@ -35164,64 +34038,81 @@ static int pager_open_journal(Pager *pPager){
       rc = sqlite3OsOpen(pVfs, pPager-&gt;zJournal, pPager-&gt;jfd, flags, 0);
 #endif
     }
-    assert( rc!=SQLITE_OK || isOpen(pPager-&gt;jfd) );
-  }
-
-
-  /* Write the first journal header to the journal file and open 
-  ** the sub-journal if necessary.
-  */
-  if( rc==SQLITE_OK ){
-    /* TODO: Check if all of these are really required. */
-    pPager-&gt;dbOrigSize = pPager-&gt;dbSize;
-    pPager-&gt;journalStarted = 0;
-    pPager-&gt;needSync = 0;
-    pPager-&gt;nRec = 0;
+    assert( rc!=SQLITE_OK || pPager-&gt;jfd-&gt;pMethods );
     pPager-&gt;journalOff = 0;
     pPager-&gt;setMaster = 0;
     pPager-&gt;journalHdr = 0;
-    rc = writeJournalHdr(pPager);
+    if( rc!=SQLITE_OK ){
+      if( rc==SQLITE_NOMEM ){
+        sqlite3OsDelete(pVfs, pPager-&gt;zJournal, 0);
+      }
+      goto failed_to_open_journal;
+    }
   }
-  if( rc==SQLITE_OK &amp;&amp; pPager-&gt;nSavepoint ){
-    rc = openSubJournal(pPager);
+  pPager-&gt;journalOpen = 1;
+  pPager-&gt;journalStarted = 0;
+  pPager-&gt;needSync = 0;
+  pPager-&gt;nRec = 0;
+  if( pPager-&gt;errCode ){
+    rc = pPager-&gt;errCode;
+    goto failed_to_open_journal;
   }
+  pPager-&gt;dbOrigSize = pPager-&gt;dbSize;
 
-  if( rc!=SQLITE_OK ){
-    sqlite3BitvecDestroy(pPager-&gt;pInJournal);
-    pPager-&gt;pInJournal = 0;
+  rc = writeJournalHdr(pPager);
+
+  if( pPager-&gt;nSavepoint &amp;&amp; rc==SQLITE_OK ){
+    rc = openSubJournal(pPager);
   }
+  if( rc!=SQLITE_OK &amp;&amp; rc!=SQLITE_NOMEM &amp;&amp; rc!=SQLITE_IOERR_NOMEM ){
+    rc = pager_end_transaction(pPager, 0);
+    if( rc==SQLITE_OK ){
+      rc = SQLITE_FULL;
+    }
+  }
+  return rc;
+
+failed_to_open_journal:
+  sqlite3BitvecDestroy(pPager-&gt;pInJournal);
+  pPager-&gt;pInJournal = 0;
   return rc;
 }
 
 /*
-** Begin a write-transaction on the specified pager object. If a 
-** write-transaction has already been opened, this function is a no-op.
+** Acquire a write-lock on the database.  The lock is removed when
+** the any of the following happen:
+**
+**   *  sqlite3PagerCommitPhaseTwo() is called.
+**   *  sqlite3PagerRollback() is called.
+**   *  sqlite3PagerClose() is called.
+**   *  sqlite3PagerUnref() is called to on every outstanding page.
 **
-** If the exFlag argument is false, then acquire at least a RESERVED
-** lock on the database file. If exFlag is true, then acquire at least
-** an EXCLUSIVE lock. If such a lock is already held, no locking 
-** functions need be called.
+** The first parameter to this routine is a pointer to any open page of the
+** database file.  Nothing changes about the page - it is used merely to
+** acquire a pointer to the Pager structure and as proof that there is
+** already a read-lock on the database.
 **
-** If this is not a temporary or in-memory file and, the journal file is 
-** opened if it has not been already. For a temporary file, the opening 
-** of the journal file is deferred until there is an actual need to 
-** write to the journal. TODO: Why handle temporary files differently?
+** The second parameter indicates how much space in bytes to reserve for a
+** master journal file-name at the start of the journal when it is created.
 **
-** If the journal file is opened (or if it is already open), then a
-** journal-header is written to the start of it.
+** A journal file is opened if this is not a temporary file.  For temporary
+** files, the opening of the journal file is deferred until there is an
+** actual need to write to the journal.
+**
+** If the database is already reserved for writing, this routine is a no-op.
+**
+** If exFlag is true, go ahead and get an EXCLUSIVE lock on the file
+** immediately instead of waiting until we try to flush the cache.  The
+** exFlag is ignored if a transaction is already active.
 */
-SQLITE_PRIVATE int sqlite3PagerBegin(Pager *pPager, int exFlag){
+SQLITE_PRIVATE int sqlite3PagerBegin(DbPage *pPg, int exFlag){
+  Pager *pPager = pPg-&gt;pPager;
   int rc = SQLITE_OK;
+  assert( pPg-&gt;nRef&gt;0 );
   assert( pPager-&gt;state!=PAGER_UNLOCK );
   if( pPager-&gt;state==PAGER_SHARED ){
     assert( pPager-&gt;pInJournal==0 );
-    assert( !MEMDB &amp;&amp; !pPager-&gt;tempFile );
-
-    /* Obtain a RESERVED lock on the database file. If the exFlag parameter
-    ** is true, then immediately upgrade this to an EXCLUSIVE lock. The
-    ** busy-handler callback can be used when upgrading to the EXCLUSIVE
-    ** lock, but not when obtaining the RESERVED lock.
-    */
+    assert( !MEMDB );
     rc = sqlite3OsLock(pPager-&gt;fd, RESERVED_LOCK);
     if( rc==SQLITE_OK ){
       pPager-&gt;state = PAGER_RESERVED;
@@ -35229,16 +34120,16 @@ SQLITE_PRIVATE int sqlite3PagerBegin(Pager *pPager, int exFlag){
         rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK);
       }
     }
-
-    /* If the required locks were successfully obtained, open the journal
-    ** file and write the first journal-header to it.
-    */
-    if( rc==SQLITE_OK &amp;&amp; pPager-&gt;useJournal
-     &amp;&amp; pPager-&gt;journalMode!=PAGER_JOURNALMODE_OFF 
-    ){
+    if( rc!=SQLITE_OK ){
+      return rc;
+    }
+    pPager-&gt;dirtyCache = 0;
+    PAGERTRACE((&quot;TRANSACTION %d\n&quot;, PAGERID(pPager)));
+    if( pPager-&gt;useJournal &amp;&amp; !pPager-&gt;tempFile
+           &amp;&amp; pPager-&gt;journalMode!=PAGER_JOURNALMODE_OFF ){
       rc = pager_open_journal(pPager);
     }
-  }else if( isOpen(pPager-&gt;jfd) &amp;&amp; pPager-&gt;journalOff==0 ){
+  }else if( pPager-&gt;journalOpen &amp;&amp; pPager-&gt;journalOff==0 ){
     /* This happens when the pager was in exclusive-access mode the last
     ** time a (read or write) transaction was successfully concluded
     ** by this connection. Instead of deleting the journal file it was 
@@ -35248,20 +34139,35 @@ SQLITE_PRIVATE int sqlite3PagerBegin(Pager *pPager, int exFlag){
     assert( pPager-&gt;nRec==0 );
     assert( pPager-&gt;dbOrigSize==0 );
     assert( pPager-&gt;pInJournal==0 );
-    rc = pager_open_journal(pPager);
+    sqlite3PagerPagecount(pPager, 0);
+    pPager-&gt;pInJournal = sqlite3BitvecCreate( pPager-&gt;dbSize );
+    if( !pPager-&gt;pInJournal ){
+      rc = SQLITE_NOMEM;
+    }else{
+      pPager-&gt;dbOrigSize = pPager-&gt;dbSize;
+      rc = writeJournalHdr(pPager);
+    }
   }
-
-  PAGERTRACE((&quot;TRANSACTION %d\n&quot;, PAGERID(pPager)));
-  assert( !isOpen(pPager-&gt;jfd) || pPager-&gt;journalOff&gt;0 || rc!=SQLITE_OK );
+  assert( !pPager-&gt;journalOpen || pPager-&gt;journalOff&gt;0 || rc!=SQLITE_OK );
   return rc;
 }
 
 /*
-** Mark a single data page as writeable. The page is written into the 
-** main journal or sub-journal as required. If the page is written into
-** one of the journals, the corresponding bit is set in the 
-** Pager.pInJournal bitvec and the PagerSavepoint.pInSavepoint bitvecs
-** of any open savepoints as appropriate.
+** Mark a data page as writeable.  The page is written into the journal 
+** if it is not there already.  This routine must be called before making
+** changes to a page.
+**
+** The first time this routine is called, the pager creates a new
+** journal and acquires a RESERVED lock on the database.  If the RESERVED
+** lock could not be acquired, this routine returns SQLITE_BUSY.  The
+** calling routine must check for that return value and be careful not to
+** change any page data until this routine returns SQLITE_OK.
+**
+** If the journal file could not be written because the disk is full,
+** then this routine returns SQLITE_FULL and does an immediate rollback.
+** All subsequent write attempts also return SQLITE_FULL until there
+** is a call to sqlite3PagerCommit() or sqlite3PagerRollback() to
+** reset.
 */
 static int pager_write(PgHdr *pPg){
   void *pData = pPg-&gt;pData;
@@ -35281,11 +34187,25 @@ static int pager_write(PgHdr *pPg){
 
   CHECK_PAGE(pPg);
 
+  /* If this page was previously acquired with noContent==1, that means
+  ** we didn't really read in the content of the page.  This can happen
+  ** (for example) when the page is being moved to the freelist.  But
+  ** now we are (perhaps) moving the page off of the freelist for
+  ** reuse and we need to know its original content so that content
+  ** can be stored in the rollback journal.  So do the read at this
+  ** time.
+  */
+  rc = pager_get_content(pPg);
+  if( rc ){
+    return rc;
+  }
+
   /* Mark the page as dirty.  If the page has already been written
   ** to the journal then we can return right away.
   */
   sqlite3PcacheMakeDirty(pPg);
   if( pageInJournal(pPg) &amp;&amp; !subjRequiresPage(pPg) ){
+    pPager-&gt;dirtyCache = 1;
     pPager-&gt;dbModified = 1;
   }else{
 
@@ -35297,23 +34217,24 @@ static int pager_write(PgHdr *pPg){
     ** create it if it does not.
     */
     assert( pPager-&gt;state!=PAGER_UNLOCK );
-    rc = sqlite3PagerBegin(pPager, 0);
+    rc = sqlite3PagerBegin(pPg, 0);
     if( rc!=SQLITE_OK ){
       return rc;
     }
     assert( pPager-&gt;state&gt;=PAGER_RESERVED );
-    if( !isOpen(pPager-&gt;jfd) &amp;&amp; pPager-&gt;useJournal
+    if( !pPager-&gt;journalOpen &amp;&amp; pPager-&gt;useJournal
           &amp;&amp; pPager-&gt;journalMode!=PAGER_JOURNALMODE_OFF ){
       rc = pager_open_journal(pPager);
       if( rc!=SQLITE_OK ) return rc;
     }
+    pPager-&gt;dirtyCache = 1;
     pPager-&gt;dbModified = 1;
   
     /* The transaction journal now exists and we have a RESERVED or an
     ** EXCLUSIVE lock on the main database file.  Write the current page to
     ** the transaction journal if it is not there already.
     */
-    if( !pageInJournal(pPg) &amp;&amp; isOpen(pPager-&gt;jfd) ){
+    if( !pageInJournal(pPg) &amp;&amp; pPager-&gt;journalOpen ){
       if( pPg-&gt;pgno&lt;=pPager-&gt;dbOrigSize ){
         u32 cksum;
         char *pData2;
@@ -35396,23 +34317,22 @@ static int pager_write(PgHdr *pPg){
   assert( pPager-&gt;state&gt;=PAGER_SHARED );
   if( pPager-&gt;dbSize&lt;pPg-&gt;pgno ){
     pPager-&gt;dbSize = pPg-&gt;pgno;
+    if( pPager-&gt;dbSize==(PAGER_MJ_PGNO(pPager)-1) ){
+      pPager-&gt;dbSize++;
+    }
   }
   return rc;
 }
 
 /*
-** Mark a data page as writeable. This routine must be called before 
-** making changes to a page. The caller must check the return value 
-** of this function and be careful not to change any page data unless 
-** this routine returns SQLITE_OK.
+** This function is used to mark a data-page as writable. It uses 
+** pager_write() to open a journal file (if it is not already open)
+** and write the page *pData to the journal.
 **
 ** The difference between this function and pager_write() is that this
 ** function also deals with the special case where 2 or more pages
 ** fit on a single disk sector. In this case all co-resident pages
 ** must have been written to the journal file before returning.
-**
-** If an error occurs, SQLITE_NOMEM or an IO error code is returned
-** as appropriate. Otherwise, SQLITE_OK.
 */
 SQLITE_PRIVATE int sqlite3PagerWrite(DbPage *pDbPage){
   int rc = SQLITE_OK;
@@ -35425,8 +34345,8 @@ SQLITE_PRIVATE int sqlite3PagerWrite(DbPage *pDbPage){
     Pgno nPageCount;          /* Total number of pages in database file */
     Pgno pg1;                 /* First page of the sector pPg is located on. */
     int nPage;                /* Number of pages starting at pg1 to journal */
-    int ii;                   /* Loop counter */
-    int needSync = 0;         /* True if any page has PGHDR_NEED_SYNC */
+    int ii;
+    int needSync = 0;
 
     /* Set the doNotSync flag to 1. This is because we cannot allow a journal
     ** header to be written between the pages journaled by this function.
@@ -35521,114 +34441,184 @@ SQLITE_PRIVATE int sqlite3PagerIswriteable(DbPage *pPg){
 ** content no longer matters.
 **
 ** The overlying software layer calls this routine when all of the data
-** on the given page is unused. The pager marks the page as clean so
+** on the given page is unused.  The pager marks the page as clean so
 ** that it does not get written to disk.
 **
-** Tests show that this optimization can quadruple the speed of large 
-** DELETE operations.
-*/
-SQLITE_PRIVATE void sqlite3PagerDontWrite(PgHdr *pPg){
+** Tests show that this optimization, together with the
+** sqlite3PagerDontRollback() below, more than double the speed
+** of large INSERT operations and quadruple the speed of large DELETEs.
+**
+** When this routine is called, set the bit corresponding to pDbPage in
+** the Pager.pAlwaysRollback bitvec.  Subsequent calls to
+** sqlite3PagerDontRollback() for the same page will thereafter be ignored.
+** This is necessary to avoid a problem where a page with data is added to
+** the freelist during one part of a transaction then removed from the
+** freelist during a later part of the same transaction and reused for some
+** other purpose.  When it is first added to the freelist, this routine is
+** called.  When reused, the sqlite3PagerDontRollback() routine is called.
+** But because the page contains critical data, we still need to be sure it
+** gets rolled back in spite of the sqlite3PagerDontRollback() call.
+*/
+SQLITE_PRIVATE int sqlite3PagerDontWrite(DbPage *pDbPage){
+  PgHdr *pPg = pDbPage;
   Pager *pPager = pPg-&gt;pPager;
-  if( (pPg-&gt;flags&amp;PGHDR_DIRTY) &amp;&amp; pPager-&gt;nSavepoint==0 ){
-    PAGERTRACE((&quot;DONT_WRITE page %d of %d\n&quot;, pPg-&gt;pgno, PAGERID(pPager)));
-    IOTRACE((&quot;CLEAN %p %d\n&quot;, pPager, pPg-&gt;pgno))
-    pPg-&gt;flags |= PGHDR_DONT_WRITE;
+  int rc;
+
+  if( pPg-&gt;pgno&gt;pPager-&gt;dbOrigSize ){
+    return SQLITE_OK;
+  }
+  if( pPager-&gt;pAlwaysRollback==0 ){
+    assert( pPager-&gt;pInJournal );
+    pPager-&gt;pAlwaysRollback = sqlite3BitvecCreate(pPager-&gt;dbOrigSize);
+    if( !pPager-&gt;pAlwaysRollback ){
+      return SQLITE_NOMEM;
+    }
+  }
+  rc = sqlite3BitvecSet(pPager-&gt;pAlwaysRollback, pPg-&gt;pgno);
+
+  if( rc==SQLITE_OK &amp;&amp; (pPg-&gt;flags&amp;PGHDR_DIRTY) &amp;&amp; pPager-&gt;nSavepoint==0 ){
+    assert( pPager-&gt;state&gt;=PAGER_SHARED );
+    if( pPager-&gt;dbSize==pPg-&gt;pgno &amp;&amp; pPager-&gt;dbOrigSize&lt;pPager-&gt;dbSize ){
+      /* If this pages is the last page in the file and the file has grown
+      ** during the current transaction, then do NOT mark the page as clean.
+      ** When the database file grows, we must make sure that the last page
+      ** gets written at least once so that the disk file will be the correct
+      ** size. If you do not write this page and the size of the file
+      ** on the disk ends up being too small, that can lead to database
+      ** corruption during the next transaction.
+      */
+    }else{
+      PAGERTRACE((&quot;DONT_WRITE page %d of %d\n&quot;, pPg-&gt;pgno, PAGERID(pPager)));
+      IOTRACE((&quot;CLEAN %p %d\n&quot;, pPager, pPg-&gt;pgno))
+      pPg-&gt;flags |= PGHDR_DONT_WRITE;
 #ifdef SQLITE_CHECK_PAGES
-    pPg-&gt;pageHash = pager_pagehash(pPg);
+      pPg-&gt;pageHash = pager_pagehash(pPg);
 #endif
+    }
   }
+  return rc;
 }
 
 /*
-** This routine is called to increment the value of the database file 
-** change-counter, stored as a 4-byte big-endian integer starting at 
-** byte offset 24 of the pager file.
-**
-** If the isDirect flag is zero, then this is done by calling 
-** sqlite3PagerWrite() on page 1, then modifying the contents of the
-** page data. In this case the file will be updated when the current
-** transaction is committed.
+** A call to this routine tells the pager that if a rollback occurs,
+** it is not necessary to restore the data on the given page.  This
+** means that the pager does not have to record the given page in the
+** rollback journal.
 **
-** The isDirect flag may only be non-zero if the library was compiled
-** with the SQLITE_ENABLE_ATOMIC_WRITE macro defined. In this case,
-** if isDirect is non-zero, then the database file is updated directly
-** by writing an updated version of page 1 using a call to the 
-** sqlite3OsWrite() function.
+** If we have not yet actually read the content of this page (if
+** the PgHdr.needRead flag is set) then this routine acts as a promise
+** that we will never need to read the page content in the future.
+** so the needRead flag can be cleared at this point.
 */
-static int pager_incr_changecounter(Pager *pPager, int isDirectMode){
-  int rc = SQLITE_OK;
+SQLITE_PRIVATE void sqlite3PagerDontRollback(DbPage *pPg){
+  Pager *pPager = pPg-&gt;pPager;
+  TESTONLY( int rc; )  /* Return value from sqlite3BitvecSet() */
 
-  /* Declare and initialize constant integer 'isDirect'. If the
-  ** atomic-write optimization is enabled in this build, then isDirect
-  ** is initialized to the value passed as the isDirectMode parameter
-  ** to this function. Otherwise, it is always set to zero.
-  **
-  ** The idea is that if the atomic-write optimization is not
-  ** enabled at compile time, the compiler can omit the tests of
-  ** 'isDirect' below, as well as the block enclosed in the
-  ** &quot;if( isDirect )&quot; condition.
+  assert( pPager-&gt;state&gt;=PAGER_RESERVED );
+
+  /* If the journal file is not open, or DontWrite() has been called on
+  ** this page (DontWrite() sets the Pager.pAlwaysRollback bit), then this
+  ** function is a no-op.
   */
-#ifndef SQLITE_ENABLE_ATOMIC_WRITE
-  const int isDirect = 0;
-  assert( isDirectMode==0 );
-  UNUSED_PARAMETER(isDirectMode);
-#else
-  const int isDirect = isDirectMode;
+  if( pPager-&gt;journalOpen==0 
+   || sqlite3BitvecTest(pPager-&gt;pAlwaysRollback, pPg-&gt;pgno)
+   || pPg-&gt;pgno&gt;pPager-&gt;dbOrigSize
+  ){
+    return;
+  }
+
+#ifdef SQLITE_SECURE_DELETE
+  if( sqlite3BitvecTest(pPager-&gt;pInJournal, pPg-&gt;pgno)!=0
+   || pPg-&gt;pgno&gt;pPager-&gt;dbOrigSize ){
+    return;
+  }
 #endif
 
-  assert( pPager-&gt;state&gt;=PAGER_RESERVED );
-  if( !pPager-&gt;changeCountDone &amp;&amp; pPager-&gt;dbSize&gt;0 ){
-    PgHdr *pPgHdr;                /* Reference to page 1 */
-    u32 change_counter;           /* Initial value of change-counter field */
+  /* If SECURE_DELETE is disabled, then there is no way that this
+  ** routine can be called on a page for which sqlite3PagerDontWrite()
+  ** has not been previously called during the same transaction.
+  ** And if DontWrite() has previously been called, the following
+  ** conditions must be met.
+  **
+  ** (Later:)  Not true.  If the database is corrupted by having duplicate
+  ** pages on the freelist (ex: corrupt9.test) then the following is not
+  ** necessarily true:
+  */
+  /* assert( !pPg-&gt;inJournal &amp;&amp; (int)pPg-&gt;pgno &lt;= pPager-&gt;dbOrigSize ); */
+
+  assert( pPager-&gt;pInJournal!=0 );
+  pPg-&gt;flags &amp;= ~PGHDR_NEED_READ;
+
+  /* Failure to set the bits in the InJournal bit-vectors is benign.
+  ** It merely means that we might do some extra work to journal a page
+  ** that does not need to be journaled.  Nevertheless, be sure to test the
+  ** case where a malloc error occurs while trying to set a bit in a 
+  ** bit vector.
+  */
+  sqlite3BeginBenignMalloc();
+  TESTONLY( rc = ) sqlite3BitvecSet(pPager-&gt;pInJournal, pPg-&gt;pgno);
+  testcase( rc==SQLITE_NOMEM );
+  TESTONLY( rc = ) addToSavepointBitvecs(pPager, pPg-&gt;pgno);
+  testcase( rc==SQLITE_NOMEM );
+  sqlite3EndBenignMalloc();
+
+
+  PAGERTRACE((&quot;DONT_ROLLBACK page %d of %d\n&quot;, pPg-&gt;pgno, PAGERID(pPager)));
+  IOTRACE((&quot;GARBAGE %p %d\n&quot;, pPager, pPg-&gt;pgno))
+}
 
-    assert( !pPager-&gt;tempFile &amp;&amp; isOpen(pPager-&gt;fd) );
 
+/*
+** This routine is called to increment the database file change-counter,
+** stored at byte 24 of the pager file.
+*/
+static int pager_incr_changecounter(Pager *pPager, int isDirect){
+  PgHdr *pPgHdr;
+  u32 change_counter;
+  int rc = SQLITE_OK;
+
+#ifndef SQLITE_ENABLE_ATOMIC_WRITE
+  assert( isDirect==0 );  /* isDirect is only true for atomic writes */
+#endif
+  if( !pPager-&gt;changeCountDone &amp;&amp; pPager-&gt;dbSize&gt;0 ){
     /* Open page 1 of the file for writing. */
     rc = sqlite3PagerGet(pPager, 1, &amp;pPgHdr);
-    assert( pPgHdr==0 || rc==SQLITE_OK );
+    if( rc!=SQLITE_OK ) return rc;
 
-    /* If page one was fetched successfully, and this function is not
-    ** operating in direct-mode, make page 1 writable.
-    */
-    if( rc==SQLITE_OK &amp;&amp; !isDirect ){
+    if( !isDirect ){
       rc = sqlite3PagerWrite(pPgHdr);
+      if( rc!=SQLITE_OK ){
+        sqlite3PagerUnref(pPgHdr);
+        return rc;
+      }
     }
 
-    if( rc==SQLITE_OK ){
-      /* Increment the value just read and write it back to byte 24. */
-      change_counter = sqlite3Get4byte((u8*)pPager-&gt;dbFileVers);
-      change_counter++;
-      put32bits(((char*)pPgHdr-&gt;pData)+24, change_counter);
-
-      /* If running in direct mode, write the contents of page 1 to the file. */
-      if( isDirect ){
-        const void *zBuf = pPgHdr-&gt;pData;
-        assert( pPager-&gt;dbFileSize&gt;0 );
-        rc = sqlite3OsWrite(pPager-&gt;fd, zBuf, pPager-&gt;pageSize, 0);
-      }
+    /* Increment the value just read and write it back to byte 24. */
+    change_counter = sqlite3Get4byte((u8*)pPager-&gt;dbFileVers);
+    change_counter++;
+    put32bits(((char*)pPgHdr-&gt;pData)+24, change_counter);
 
-      /* If everything worked, set the changeCountDone flag. */
-      if( rc==SQLITE_OK ){
-        pPager-&gt;changeCountDone = 1;
-      }
+#ifdef SQLITE_ENABLE_ATOMIC_WRITE
+    if( isDirect &amp;&amp; pPager-&gt;fd-&gt;pMethods ){
+      const void *zBuf = pPgHdr-&gt;pData;
+      assert( pPager-&gt;dbFileSize&gt;0 );
+      rc = sqlite3OsWrite(pPager-&gt;fd, zBuf, pPager-&gt;pageSize, 0);
     }
+#endif
 
     /* Release the page reference. */
     sqlite3PagerUnref(pPgHdr);
+    pPager-&gt;changeCountDone = 1;
   }
   return rc;
 }
 
 /*
-** Sync the pager file to disk. This is a no-op for in-memory files
-** or pages with the Pager.noSync flag set.
-**
-** If successful, or called on a pager for which it is a no-op, this
-** function returns SQLITE_OK. Otherwise, an IO error code is returned.
+** Sync the pager file to disk.
 */
 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager){
-  int rc;                              /* Return code */
-  if( MEMDB || pPager-&gt;noSync ){
+  int rc;
+  if( MEMDB ){
     rc = SQLITE_OK;
   }else{
     rc = sqlite3OsSync(pPager-&gt;fd, pPager-&gt;sync_flags);
@@ -35642,17 +34632,10 @@ SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager){
 ** journal file. zMaster may be NULL, which is interpreted as no master
 ** journal (a single database transaction).
 **
-** This routine ensures that:
-**
-**   * The database file change-counter is updated,
-**   * the journal is synced (unless the atomic-write optimization is used),
-**   * all dirty pages are written to the database file, 
-**   * the database file is truncated (if required), and
-**   * the database file synced. 
-**
-** The only thing that remains to commit the transaction is to finalize 
-** (delete, truncate or zero the first part of) the journal file (or 
-** delete the master journal file if specified).
+** This routine ensures that the journal is synced, all dirty pages written
+** to the database file and the database file synced. The only thing that
+** remains to commit the transaction is to delete the journal file (or
+** master journal file if specified).
 **
 ** Note that if zMaster==NULL, this does not overwrite a previous value
 ** passed to an sqlite3PagerCommitPhaseOne() call.
@@ -35663,140 +34646,140 @@ SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager){
 ** journal file in this case.
 */
 SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(
-  Pager *pPager,                  /* Pager object */
-  const char *zMaster,            /* If not NULL, the master journal name */
-  int noSync                      /* True to omit the xSync on the db file */
+  Pager *pPager, 
+  const char *zMaster, 
+  int noSync
 ){
-  int rc = SQLITE_OK;             /* Return code */
+  int rc = SQLITE_OK;
 
   if( pPager-&gt;errCode ){
     return pPager-&gt;errCode;
   }
 
+  /* If no changes have been made, we can leave the transaction early.
+  */
+  if( pPager-&gt;dbModified==0 &amp;&amp;
+        (pPager-&gt;journalMode!=PAGER_JOURNALMODE_DELETE ||
+          pPager-&gt;exclusiveMode!=0) ){
+    assert( pPager-&gt;dirtyCache==0 || pPager-&gt;journalOpen==0 );
+    return SQLITE_OK;
+  }
+
   PAGERTRACE((&quot;DATABASE SYNC: File=%s zMaster=%s nSize=%d\n&quot;, 
       pPager-&gt;zFilename, zMaster, pPager-&gt;dbSize));
 
   /* If this is an in-memory db, or no pages have been written to, or this
   ** function has already been called, it is a no-op.
   */
-  if( MEMDB &amp;&amp; pPager-&gt;dbModified ){
-    sqlite3BackupRestart(pPager-&gt;pBackup);
-  }else if( pPager-&gt;state!=PAGER_SYNCED &amp;&amp; pPager-&gt;dbModified ){
+  if( pPager-&gt;state!=PAGER_SYNCED &amp;&amp; !MEMDB &amp;&amp; pPager-&gt;dirtyCache ){
+    PgHdr *pPg;
 
-    /* The following block updates the change-counter. Exactly how it
-    ** does this depends on whether or not the atomic-update optimization
-    ** was enabled at compile time, and if this transaction meets the 
-    ** runtime criteria to use the operation: 
-    **
-    **    * The file-system supports the atomic-write property for
-    **      blocks of size page-size, and 
-    **    * This commit is not part of a multi-file transaction, and
-    **    * Exactly one page has been modified and store in the journal file.
+#ifdef SQLITE_ENABLE_ATOMIC_WRITE
+    /* The atomic-write optimization can be used if all of the
+    ** following are true:
     **
-    ** If the optimization was not enabled at compile time, then the
-    ** pager_incr_changecounter() function is called to update the change
-    ** counter in 'indirect-mode'. If the optimization is compiled in but
-    ** is not applicable to this transaction, call sqlite3JournalCreate()
-    ** to make sure the journal file has actually been created, then call
-    ** pager_incr_changecounter() to update the change-counter in indirect
-    ** mode. 
+    **    + The file-system supports the atomic-write property for
+    **      blocks of size page-size, and
+    **    + This commit is not part of a multi-file transaction, and
+    **    + Exactly one page has been modified and store in the journal file.
     **
-    ** Otherwise, if the optimization is both enabled and applicable,
-    ** then call pager_incr_changecounter() to update the change-counter
-    ** in 'direct' mode. In this case the journal file will never be
-    ** created for this transaction.
+    ** If the optimization can be used, then the journal file will never
+    ** be created for this transaction.
     */
-#ifdef SQLITE_ENABLE_ATOMIC_WRITE
-    PgHdr *pPg;
-    assert( isOpen(pPager-&gt;jfd) || pPager-&gt;journalMode==PAGER_JOURNALMODE_OFF );
-    if( !zMaster &amp;&amp; isOpen(pPager-&gt;jfd) 
-     &amp;&amp; pPager-&gt;journalOff==jrnlBufferSize(pPager) 
-     &amp;&amp; pPager-&gt;dbSize&gt;=pPager-&gt;dbFileSize
-     &amp;&amp; (0==(pPg = sqlite3PcacheDirtyList(pPager-&gt;pPCache)) || 0==pPg-&gt;pDirty)
-    ){
-      /* Update the db file change counter via the direct-write method. The 
-      ** following call will modify the in-memory representation of page 1 
-      ** to include the updated change counter and then write page 1 
-      ** directly to the database file. Because of the atomic-write 
-      ** property of the host file-system, this is safe.
+    int useAtomicWrite;
+    pPg = sqlite3PcacheDirtyList(pPager-&gt;pPCache);
+    useAtomicWrite = (
+        !zMaster &amp;&amp; 
+        pPager-&gt;journalOpen &amp;&amp;
+        pPager-&gt;journalOff==jrnlBufferSize(pPager) &amp;&amp; 
+        pPager-&gt;dbSize&gt;=pPager-&gt;dbFileSize &amp;&amp; 
+        (pPg==0 || pPg-&gt;pDirty==0)
+    );
+    assert( pPager-&gt;journalOpen || pPager-&gt;journalMode==PAGER_JOURNALMODE_OFF );
+    if( useAtomicWrite ){
+      /* Update the nRec field in the journal file. */
+      int offset = pPager-&gt;journalHdr + sizeof(aJournalMagic);
+      assert(pPager-&gt;nRec==1);
+      rc = write32bits(pPager-&gt;jfd, offset, pPager-&gt;nRec);
+
+      /* Update the db file change counter. The following call will modify
+      ** the in-memory representation of page 1 to include the updated
+      ** change counter and then write page 1 directly to the database
+      ** file. Because of the atomic-write property of the host file-system, 
+      ** this is safe.
       */
-      rc = pager_incr_changecounter(pPager, 1);
-    }else{
-      rc = sqlite3JournalCreate(pPager-&gt;jfd);
       if( rc==SQLITE_OK ){
-        rc = pager_incr_changecounter(pPager, 0);
+        rc = pager_incr_changecounter(pPager, 1);
       }
+    }else{
+      rc = sqlite3JournalCreate(pPager-&gt;jfd);
     }
-#else
-    rc = pager_incr_changecounter(pPager, 0);
+
+    if( !useAtomicWrite &amp;&amp; rc==SQLITE_OK )
 #endif
-    if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
 
-    /* If this transaction has made the database smaller, then all pages
-    ** being discarded by the truncation must be written to the journal
-    ** file. This can only happen in auto-vacuum mode.
-    **
-    ** Before reading the pages with page numbers larger than the 
-    ** current value of Pager.dbSize, set dbSize back to the value
-    ** that it took at the start of the transaction. Otherwise, the
-    ** calls to sqlite3PagerGet() return zeroed pages instead of 
-    ** reading data from the database file.
+    /* If a master journal file name has already been written to the
+    ** journal file, then no sync is required. This happens when it is
+    ** written, then the process fails to upgrade from a RESERVED to an
+    ** EXCLUSIVE lock. The next time the process tries to commit the
+    ** transaction the m-j name will have already been written.
     */
+    if( !pPager-&gt;setMaster ){
+      rc = pager_incr_changecounter(pPager, 0);
+      if( rc!=SQLITE_OK ) goto sync_exit;
+      if( pPager-&gt;journalMode!=PAGER_JOURNALMODE_OFF ){
 #ifndef SQLITE_OMIT_AUTOVACUUM
-    if( pPager-&gt;dbSize&lt;pPager-&gt;dbOrigSize
-     &amp;&amp; pPager-&gt;journalMode!=PAGER_JOURNALMODE_OFF 
-    ){
-      Pgno i;                                   /* Iterator variable */
-      const Pgno iSkip = PAGER_MJ_PGNO(pPager); /* Pending lock page */
-      const Pgno dbSize = pPager-&gt;dbSize;       /* Database image size */ 
-      pPager-&gt;dbSize = pPager-&gt;dbOrigSize;
-      for( i=dbSize+1; i&lt;=pPager-&gt;dbOrigSize; i++ ){
-        if( !sqlite3BitvecTest(pPager-&gt;pInJournal, i) &amp;&amp; i!=iSkip ){
-          PgHdr *pPage;             /* Page to journal */
-          rc = sqlite3PagerGet(pPager, i, &amp;pPage);
-          if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
-          rc = sqlite3PagerWrite(pPage);
-          sqlite3PagerUnref(pPage);
-          if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
+        if( pPager-&gt;dbSize&lt;pPager-&gt;dbOrigSize ){
+          /* If this transaction has made the database smaller, then all pages
+          ** being discarded by the truncation must be written to the journal
+          ** file.
+          */
+          Pgno i;
+          Pgno iSkip = PAGER_MJ_PGNO(pPager);
+          Pgno dbSize = pPager-&gt;dbSize;
+          pPager-&gt;dbSize = pPager-&gt;dbOrigSize;
+          for( i=dbSize+1; i&lt;=pPager-&gt;dbOrigSize; i++ ){
+            if( !sqlite3BitvecTest(pPager-&gt;pInJournal, i) &amp;&amp; i!=iSkip ){
+              rc = sqlite3PagerGet(pPager, i, &amp;pPg);
+              if( rc!=SQLITE_OK ) goto sync_exit;
+              rc = sqlite3PagerWrite(pPg);
+              sqlite3PagerUnref(pPg);
+              if( rc!=SQLITE_OK ) goto sync_exit;
+            }
+          } 
+          pPager-&gt;dbSize = dbSize;
         }
-      } 
-      pPager-&gt;dbSize = dbSize;
-    }
 #endif
+        rc = writeMasterJournal(pPager, zMaster);
+        if( rc!=SQLITE_OK ) goto sync_exit;
+        rc = syncJournal(pPager);
+      }
+    }
+    if( rc!=SQLITE_OK ) goto sync_exit;
 
-    /* Write the master journal name into the journal file. If a master 
-    ** journal file name has already been written to the journal file, 
-    ** or if zMaster is NULL (no master journal), then this call is a no-op.
-    */
-    rc = writeMasterJournal(pPager, zMaster);
-    if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
-
-    /* Sync the journal file. If the atomic-update optimization is being
-    ** used, this call will not create the journal file or perform any
-    ** real IO.
-    */
-    rc = syncJournal(pPager);
-    if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
-
-    /* Write all dirty pages to the database file. */
-    rc = pager_write_pagelist(sqlite3PcacheDirtyList(pPager-&gt;pPCache));
+    /* Write all dirty pages to the database file */
+    pPg = sqlite3PcacheDirtyList(pPager-&gt;pPCache);
+    rc = pager_write_pagelist(pPg);
     if( rc!=SQLITE_OK ){
       assert( rc!=SQLITE_IOERR_BLOCKED );
-      goto commit_phase_one_exit;
+      /* The error might have left the dirty list all fouled up here,
+      ** but that does not matter because if the if the dirty list did
+      ** get corrupted, then the transaction will roll back and
+      ** discard the dirty list.  There is an assert in
+      ** pager_get_all_dirty_pages() that verifies that no attempt
+      ** is made to use an invalid dirty list.
+      */
+      goto sync_exit;
     }
     sqlite3PcacheCleanAll(pPager-&gt;pPCache);
 
-    /* If the file on disk is not the same size as the database image,
-    ** then use pager_truncate to grow or shrink the file here.
-    */
-    if( pPager-&gt;dbSize!=pPager-&gt;dbFileSize ){
-      Pgno nNew = pPager-&gt;dbSize - (pPager-&gt;dbSize==PAGER_MJ_PGNO(pPager));
+    if( pPager-&gt;dbSize&lt;pPager-&gt;dbFileSize ){
       assert( pPager-&gt;state&gt;=PAGER_EXCLUSIVE );
-      rc = pager_truncate(pPager, nNew);
-      if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
+      rc = pager_truncate(pPager, pPager-&gt;dbSize);
+      if( rc!=SQLITE_OK ) goto sync_exit;
     }
 
-    /* Finally, sync the database file. */
+    /* Sync the database file. */
     if( !pPager-&gt;noSync &amp;&amp; !noSync ){
       rc = sqlite3OsSync(pPager-&gt;fd, pPager-&gt;sync_flags);
     }
@@ -35805,13 +34788,13 @@ SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(
     pPager-&gt;state = PAGER_SYNCED;
   }
 
-commit_phase_one_exit:
+sync_exit:
   if( rc==SQLITE_IOERR_BLOCKED ){
     /* pager_incr_changecounter() may attempt to obtain an exclusive
-    ** lock to spill the cache and return IOERR_BLOCKED. But since 
-    ** there is no chance the cache is inconsistent, it is
-    ** better to return SQLITE_BUSY.
-    **/
+     * lock to spill the cache and return IOERR_BLOCKED. But since 
+     * there is no chance the cache is inconsistent, it is
+     * better to return SQLITE_BUSY.
+     */
     rc = SQLITE_BUSY;
   }
   return rc;
@@ -35819,107 +34802,50 @@ commit_phase_one_exit:
 
 
 /*
-** When this function is called, the database file has been completely
-** updated to reflect the changes made by the current transaction and
-** synced to disk. The journal file still exists in the file-system 
-** though, and if a failure occurs at this point it will eventually
-** be used as a hot-journal and the current transaction rolled back.
-**
-** This function finalizes the journal file, either by deleting, 
-** truncating or partially zeroing it, so that it cannot be used 
-** for hot-journal rollback. Once this is done the transaction is
-** irrevocably committed.
+** Commit all changes to the database and release the write lock.
 **
-** If an error occurs, an IO error code is returned and the pager
-** moves into the error state. Otherwise, SQLITE_OK is returned.
+** If the commit fails for any reason, a rollback attempt is made
+** and an error code is returned.  If the commit worked, SQLITE_OK
+** is returned.
 */
 SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager *pPager){
-  int rc = SQLITE_OK;                  /* Return code */
+  int rc = SQLITE_OK;
 
-  /* Do not proceed if the pager is already in the error state. */
   if( pPager-&gt;errCode ){
     return pPager-&gt;errCode;
   }
-
-  /* This function should not be called if the pager is not in at least
-  ** PAGER_RESERVED state. And indeed SQLite never does this. But it is
-  ** nice to have this defensive block here anyway.
-  */
-  if( NEVER(pPager-&gt;state&lt;PAGER_RESERVED) ){
+  if( pPager-&gt;state&lt;PAGER_RESERVED ){
     return SQLITE_ERROR;
   }
-
-  /* An optimization. If the database was not actually modified during
-  ** this transaction, the pager is running in exclusive-mode and is
-  ** using persistent journals, then this function is a no-op.
-  **
-  ** The start of the journal file currently contains a single journal 
-  ** header with the nRec field set to 0. If such a journal is used as
-  ** a hot-journal during hot-journal rollback, 0 changes will be made
-  ** to the database file. So there is no need to zero the journal 
-  ** header. Since the pager is in exclusive mode, there is no need
-  ** to drop any locks either.
-  */
-  if( pPager-&gt;dbModified==0 &amp;&amp; pPager-&gt;exclusiveMode 
-   &amp;&amp; pPager-&gt;journalMode==PAGER_JOURNALMODE_PERSIST
-  ){
-    assert( pPager-&gt;journalOff==JOURNAL_HDR_SZ(pPager) );
+  if( pPager-&gt;dbModified==0 &amp;&amp;
+        (pPager-&gt;journalMode!=PAGER_JOURNALMODE_DELETE ||
+          pPager-&gt;exclusiveMode!=0) ){
+    assert( pPager-&gt;dirtyCache==0 || pPager-&gt;journalOpen==0 );
     return SQLITE_OK;
   }
-
   PAGERTRACE((&quot;COMMIT %d\n&quot;, PAGERID(pPager)));
-  assert( pPager-&gt;state==PAGER_SYNCED || MEMDB || !pPager-&gt;dbModified );
+  assert( pPager-&gt;state==PAGER_SYNCED || MEMDB || !pPager-&gt;dirtyCache );
   rc = pager_end_transaction(pPager, pPager-&gt;setMaster);
-  return pager_error(pPager, rc);
+  rc = pager_error(pPager, rc);
+  return rc;
 }
 
 /*
-** Rollback all changes. The database falls back to PAGER_SHARED mode.
-**
-** This function performs two tasks:
-**
-**   1) It rolls back the journal file, restoring all database file and 
-**      in-memory cache pages to the state they were in when the transaction
-**      was opened, and
-**   2) It finalizes the journal file, so that it is not used for hot
-**      rollback at any point in the future.
-**
-** subject to the following qualifications:
-**
-** * If the journal file is not yet open when this function is called,
-**   then only (2) is performed. In this case there is no journal file
-**   to roll back.
-**
-** * If in an error state other than SQLITE_FULL, then task (1) is 
-**   performed. If successful, task (2). Regardless of the outcome
-**   of either, the error state error code is returned to the caller
-**   (i.e. either SQLITE_IOERR or SQLITE_CORRUPT).
+** Rollback all changes.  The database falls back to PAGER_SHARED mode.
+** All in-memory cache pages revert to their original data contents.
+** The journal is deleted.
 **
-** * If the pager is in PAGER_RESERVED state, then attempt (1). Whether
-**   or not (1) is succussful, also attempt (2). If successful, return
-**   SQLITE_OK. Otherwise, enter the error state and return the first 
-**   error code encountered. 
-**
-**   In this case there is no chance that the database was written to. 
-**   So is safe to finalize the journal file even if the playback 
-**   (operation 1) failed. However the pager must enter the error state
-**   as the contents of the in-memory cache are now suspect.
-**
-** * Finally, if in PAGER_EXCLUSIVE state, then attempt (1). Only
-**   attempt (2) if (1) is successful. Return SQLITE_OK if successful,
-**   otherwise enter the error state and return the error code from the 
-**   failing operation.
-**
-**   In this case the database file may have been written to. So if the
-**   playback operation did not succeed it would not be safe to finalize
-**   the journal file. It needs to be left in the file-system so that
-**   some other process can use it to restore the database state (by
-**   hot-journal rollback).
+** This routine cannot fail unless some other process is not following
+** the correct locking protocol or unless some other
+** process is writing trash into the journal file (SQLITE_CORRUPT) or
+** unless a prior malloc() failed (SQLITE_NOMEM).  Appropriate error
+** codes are returned for all these occasions.  Otherwise,
+** SQLITE_OK is returned.
 */
 SQLITE_PRIVATE int sqlite3PagerRollback(Pager *pPager){
-  int rc = SQLITE_OK;                  /* Return code */
+  int rc = SQLITE_OK;
   PAGERTRACE((&quot;ROLLBACK %d\n&quot;, PAGERID(pPager)));
-  if( !pPager-&gt;dbModified || !isOpen(pPager-&gt;jfd) ){
+  if( !pPager-&gt;dirtyCache || !pPager-&gt;journalOpen ){
     rc = pager_end_transaction(pPager, pPager-&gt;setMaster);
   }else if( pPager-&gt;errCode &amp;&amp; pPager-&gt;errCode!=SQLITE_FULL ){
     if( pPager-&gt;state&gt;=PAGER_EXCLUSIVE ){
@@ -35992,36 +34918,24 @@ SQLITE_PRIVATE int *sqlite3PagerStats(Pager *pPager){
   a[10] = pPager-&gt;nWrite;
   return a;
 }
-#endif
-
-/*
-** Return true if this is an in-memory pager.
-*/
 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager *pPager){
   return MEMDB;
 }
+#endif
 
 /*
-** Check that there are at least nSavepoint savepoints open. If there are
-** currently less than nSavepoints open, then open one or more savepoints
-** to make up the difference. If the number of savepoints is already
-** equal to nSavepoint, then this function is a no-op.
-**
-** If a memory allocation fails, SQLITE_NOMEM is returned. If an error 
-** occurs while opening the sub-journal file, then an IO error code is
-** returned. Otherwise, SQLITE_OK.
+** Ensure that there are at least nSavepoint savepoints open.
 */
 SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int nSavepoint){
-  int rc = SQLITE_OK;                       /* Return code */
-  int nCurrent = pPager-&gt;nSavepoint;        /* Current number of savepoints */
+  int rc = SQLITE_OK;
 
-  if( nSavepoint&gt;nCurrent &amp;&amp; pPager-&gt;useJournal ){
-    int ii;                                 /* Iterator variable */
-    PagerSavepoint *aNew;                   /* New Pager.aSavepoint array */
+  if( nSavepoint&gt;pPager-&gt;nSavepoint &amp;&amp; pPager-&gt;useJournal ){
+    int ii;
+    PagerSavepoint *aNew;
 
     /* Either there is no active journal or the sub-journal is open or 
     ** the journal is always stored in memory */
-    assert( pPager-&gt;nSavepoint==0 || isOpen(pPager-&gt;sjfd) ||
+    assert( pPager-&gt;nSavepoint==0 || pPager-&gt;sjfd-&gt;pMethods ||
             pPager-&gt;journalMode==PAGER_JOURNALMODE_MEMORY );
 
     /* Grow the Pager.aSavepoint array using realloc(). Return SQLITE_NOMEM
@@ -36034,20 +34948,23 @@ SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int nSavepoint){
     if( !aNew ){
       return SQLITE_NOMEM;
     }
-    memset(&amp;aNew[nCurrent], 0, (nSavepoint-nCurrent) * sizeof(PagerSavepoint));
+    memset(&amp;aNew[pPager-&gt;nSavepoint], 0,
+        (nSavepoint - pPager-&gt;nSavepoint) * sizeof(PagerSavepoint)
+    );
     pPager-&gt;aSavepoint = aNew;
+    ii = pPager-&gt;nSavepoint;
     pPager-&gt;nSavepoint = nSavepoint;
 
     /* Populate the PagerSavepoint structures just allocated. */
-    for(ii=nCurrent; ii&lt;nSavepoint; ii++){
+    for(/* no-op */; ii&lt;nSavepoint; ii++){
       assert( pPager-&gt;dbSizeValid );
       aNew[ii].nOrig = pPager-&gt;dbSize;
-      if( isOpen(pPager-&gt;jfd) &amp;&amp; pPager-&gt;journalOff&gt;0 ){
+      if( pPager-&gt;journalOpen &amp;&amp; pPager-&gt;journalOff&gt;0 ){
         aNew[ii].iOffset = pPager-&gt;journalOff;
       }else{
         aNew[ii].iOffset = JOURNAL_HDR_SZ(pPager);
       }
-      aNew[ii].iSubRec = pPager-&gt;nSubRec;
+      aNew[ii].iSubRec = pPager-&gt;stmtNRec;
       aNew[ii].pInSavepoint = sqlite3BitvecCreate(pPager-&gt;dbSize);
       if( !aNew[ii].pInSavepoint ){
         return SQLITE_NOMEM;
@@ -36062,72 +34979,42 @@ SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int nSavepoint){
 }
 
 /*
-** This function is called to rollback or release (commit) a savepoint.
-** The savepoint to release or rollback need not be the most recently 
-** created savepoint.
-**
 ** Parameter op is always either SAVEPOINT_ROLLBACK or SAVEPOINT_RELEASE.
 ** If it is SAVEPOINT_RELEASE, then release and destroy the savepoint with
 ** index iSavepoint. If it is SAVEPOINT_ROLLBACK, then rollback all changes
-** that have occured since the specified savepoint was created.
-**
-** The savepoint to rollback or release is identified by parameter 
-** iSavepoint. A value of 0 means to operate on the outermost savepoint
-** (the first created). A value of (Pager.nSavepoint-1) means operate
-** on the most recently created savepoint. If iSavepoint is greater than
-** (Pager.nSavepoint-1), then this function is a no-op.
-**
-** If a negative value is passed to this function, then the current
-** transaction is rolled back. This is different to calling 
-** sqlite3PagerRollback() because this function does not terminate
-** the transaction or unlock the database, it just restores the 
-** contents of the database to its original state. 
-**
-** In any case, all savepoints with an index greater than iSavepoint 
-** are destroyed. If this is a release operation (op==SAVEPOINT_RELEASE),
-** then savepoint iSavepoint is also destroyed.
-**
-** This function may return SQLITE_NOMEM if a memory allocation fails,
-** or an IO error code if an IO error occurs while rolling back a 
-** savepoint. If no errors occur, SQLITE_OK is returned.
+** that have occured since savepoint iSavepoint was created.
+**
+** In either case, all savepoints with an index greater than iSavepoint 
+** are destroyed.
+**
+** If there are less than (iSavepoint+1) active savepoints when this 
+** function is called it is a no-op.
 */ 
 SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint){
   int rc = SQLITE_OK;
 
   assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK );
-  assert( iSavepoint&gt;=0 || op==SAVEPOINT_ROLLBACK );
 
   if( iSavepoint&lt;pPager-&gt;nSavepoint ){
-    int ii;            /* Iterator variable */
-    int nNew;          /* Number of remaining savepoints after this op. */
-
-    /* Figure out how many savepoints will still be active after this
-    ** operation. Store this value in nNew. Then free resources associated 
-    ** with any savepoints that are destroyed by this operation.
-    */
-    nNew = iSavepoint + (op==SAVEPOINT_ROLLBACK);
+    int ii;
+    int nNew = iSavepoint + (op==SAVEPOINT_ROLLBACK);
     for(ii=nNew; ii&lt;pPager-&gt;nSavepoint; ii++){
       sqlite3BitvecDestroy(pPager-&gt;aSavepoint[ii].pInSavepoint);
     }
     pPager-&gt;nSavepoint = nNew;
 
-    /* If this is a rollback operation, playback the specified savepoint.
-    ** If this is a temp-file, it is possible that the journal file has
-    ** not yet been opened. In this case there have been no changes to
-    ** the database file, so the playback operation can be skipped.
-    */
-    if( op==SAVEPOINT_ROLLBACK &amp;&amp; isOpen(pPager-&gt;jfd) ){
+    if( op==SAVEPOINT_ROLLBACK &amp;&amp; pPager-&gt;jfd-&gt;pMethods ){
       PagerSavepoint *pSavepoint = (nNew==0)?0:&amp;pPager-&gt;aSavepoint[nNew-1];
       rc = pagerPlaybackSavepoint(pPager, pSavepoint);
       assert(rc!=SQLITE_DONE);
     }
   
     /* If this is a release of the outermost savepoint, truncate 
-    ** the sub-journal to zero bytes in size. */
-    if( nNew==0 &amp;&amp; op==SAVEPOINT_RELEASE &amp;&amp; isOpen(pPager-&gt;sjfd) ){
+    ** the sub-journal. */
+    if( nNew==0 &amp;&amp; op==SAVEPOINT_RELEASE &amp;&amp; pPager-&gt;sjfd-&gt;pMethods ){
       assert( rc==SQLITE_OK );
       rc = sqlite3OsTruncate(pPager-&gt;sjfd, 0);
-      pPager-&gt;nSubRec = 0;
+      pPager-&gt;stmtNRec = 0;
     }
   }
   return rc;
@@ -36157,6 +35044,13 @@ SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager *pPager){
 }
 
 /*
+** Return the directory of the database file.
+*/
+SQLITE_PRIVATE const char *sqlite3PagerDirname(Pager *pPager){
+  return pPager-&gt;zDirectory;
+}
+
+/*
 ** Return the full pathname of the journal file.
 */
 SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager *pPager){
@@ -36207,14 +35101,11 @@ SQLITE_PRIVATE void sqlite3PagerSetCodec(
 ** moved as part of a database reorganization just before the transaction 
 ** is being committed. In this case, it is guaranteed that the database page 
 ** pPg refers to will not be written to again within this transaction.
-**
-** This function may return SQLITE_NOMEM or an IO error code if an error
-** occurs. Otherwise, it returns SQLITE_OK.
 */
 SQLITE_PRIVATE int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, int isCommit){
-  PgHdr *pPgOld;               /* The page being overwritten. */
-  Pgno needSyncPgno = 0;       /* Old value of pPg-&gt;pgno, if sync is required */
-  int rc;                      /* Return code */
+  PgHdr *pPgOld;  /* The page being overwritten. */
+  Pgno needSyncPgno = 0;
+  int rc;
 
   assert( pPg-&gt;nRef&gt;0 );
 
@@ -36230,11 +35121,7 @@ SQLITE_PRIVATE int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, i
   **
   ** If page X were not written to the sub-journal here, it would not
   ** be possible to restore its contents when the &quot;ROLLBACK TO one&quot;
-  ** statement were is processed.
-  **
-  ** subjournalPage() may need to allocate space to store pPg-&gt;pgno into
-  ** one or more savepoint bitvecs. This is the reason this function
-  ** may return SQLITE_NOMEM.
+  ** statement were processed.
   */
   if( pPg-&gt;flags&amp;PGHDR_DIRTY 
    &amp;&amp; subjRequiresPage(pPg)
@@ -36247,6 +35134,8 @@ SQLITE_PRIVATE int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, i
       PAGERID(pPager), pPg-&gt;pgno, (pPg-&gt;flags&amp;PGHDR_NEED_SYNC)?1:0, pgno));
   IOTRACE((&quot;MOVE %p %d %d\n&quot;, pPager, pPg-&gt;pgno, pgno))
 
+  pager_get_content(pPg);
+
   /* If the journal needs to be sync()ed before page pPg-&gt;pgno can
   ** be written to, store pPg-&gt;pgno in local variable needSyncPgno.
   **
@@ -36279,6 +35168,7 @@ SQLITE_PRIVATE int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, i
   }
 
   sqlite3PcacheMakeDirty(pPg);
+  pPager-&gt;dirtyCache = 1;
   pPager-&gt;dbModified = 1;
 
   if( needSyncPgno ){
@@ -36366,12 +35256,12 @@ SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *pPager, int eMode){
 **    PAGER_JOURNALMODE_TRUNCATE
 **    PAGER_JOURNALMODE_PERSIST
 **    PAGER_JOURNALMODE_OFF
-**    PAGER_JOURNALMODE_MEMORY
 **
 ** If the parameter is not _QUERY, then the journal-mode is set to the
 ** value specified.
 **
-** The returned indicate the current (possibly updated) journal-mode.
+** The returned indicate the current (possibly updated)
+** journal-mode.
 */
 SQLITE_PRIVATE int sqlite3PagerJournalMode(Pager *pPager, int eMode){
   if( !MEMDB ){
@@ -36401,16 +35291,6 @@ SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *pPager, i64 iLimit){
   return pPager-&gt;journalSizeLimit;
 }
 
-/*
-** Return a pointer to the pPager-&gt;pBackup variable. The backup module
-** in backup.c maintains the content of this variable. This module
-** uses it opaquely as an argument to sqlite3BackupRestart() and
-** sqlite3BackupUpdate() only.
-*/
-sqlite3_backup **sqlite3PagerBackupPtr(Pager *pPager){
-  return &amp;pPager-&gt;pBackup;
-}
-
 #endif /* SQLITE_OMIT_DISKIO */
 
 /************** End of pager.c ***********************************************/
@@ -36447,7 +35327,7 @@ sqlite3_backup **sqlite3PagerBackupPtr(Pager *pPager){
 **    May you share freely, never taking more than you give.
 **
 *************************************************************************
-** $Id: btreeInt.h,v 1.42 2009/02/03 16:51:25 danielk1977 Exp $
+** $Id: btreeInt.h,v 1.38 2008/12/27 15:23:13 danielk1977 Exp $
 **
 ** This file implements a external (disk-based) database using BTrees.
 ** For a detailed discussion of BTrees, refer to
@@ -36761,7 +35641,6 @@ struct Btree {
   u8 sharable;       /* True if we can share pBt with another db */
   u8 locked;         /* True if db currently has pBt locked */
   int wantToLock;    /* Number of nested calls to sqlite3BtreeEnter() */
-  int nBackup;       /* Number of backup operations reading this btree */
   Btree *pNext;      /* List of other sharable Btrees from the same db */
   Btree *pPrev;      /* Back pointer of the same list */
 };
@@ -36817,7 +35696,6 @@ struct BtShared {
   void *pSchema;        /* Pointer to space allocated by sqlite3BtreeSchema() */
   void (*xFreeSchema)(void*);  /* Destructor for BtShared.pSchema */
   sqlite3_mutex *mutex; /* Non-recursive mutex required to access this struct */
-  Bitvec *pHasContent;  /* Set of pages moved to free-list this transaction */
 #ifndef SQLITE_OMIT_SHARED_CACHE
   int nRef;             /* Number of references to this structure */
   BtShared *pNext;      /* Next on a list of sharable BtShared structs */
@@ -36925,10 +35803,18 @@ struct BtCursor {
 #define CURSOR_REQUIRESEEK       2
 #define CURSOR_FAULT             3
 
-/* 
-** The database page the PENDING_BYTE occupies. This page is never used.
+/* The database page the PENDING_BYTE occupies. This page is never used.
+** TODO: This macro is very similary to PAGER_MJ_PGNO() in pager.c. They
+** should possibly be consolidated (presumably in pager.h).
+**
+** If disk I/O is omitted (meaning that the database is stored purely
+** in memory) then there is no pending byte.
 */
-# define PENDING_BYTE_PAGE(pBt) PAGER_MJ_PGNO(pBt)
+#ifdef SQLITE_OMIT_DISKIO
+# define PENDING_BYTE_PAGE(pBt)  0x7fffffff
+#else
+# define PENDING_BYTE_PAGE(pBt) ((Pgno)((PENDING_BYTE/(pBt)-&gt;pageSize)+1))
+#endif
 
 /*
 ** A linked list of the following structures is stored at BtShared.pLock.
@@ -37373,7 +36259,7 @@ SQLITE_PRIVATE void sqlite3BtreeMutexArrayLeave(BtreeMutexArray *pArray){
 **    May you share freely, never taking more than you give.
 **
 *************************************************************************
-** $Id: btree.c,v 1.565 2009/02/04 01:49:30 shane Exp $
+** $Id: btree.c,v 1.558 2009/01/10 16:15:21 drh Exp $
 **
 ** This file implements a external (disk-based) database using BTrees.
 ** See the header comment on &quot;btreeInt.h&quot; for additional information.
@@ -37646,80 +36532,6 @@ static void invalidateAllOverflowCache(BtShared *pBt){
 #endif
 
 /*
-** Set bit pgno of the BtShared.pHasContent bitvec. This is called 
-** when a page that previously contained data becomes a free-list leaf 
-** page.
-**
-** The BtShared.pHasContent bitvec exists to work around an obscure
-** bug caused by the interaction of two useful IO optimizations surrounding
-** free-list leaf pages:
-**
-**   1) When all data is deleted from a page and the page becomes
-**      a free-list leaf page, the page is not written to the database
-**      (as free-list leaf pages contain no meaningful data). Sometimes
-**      such a page is not even journalled (as it will not be modified,
-**      why bother journalling it?).
-**
-**   2) When a free-list leaf page is reused, its content is not read
-**      from the database or written to the journal file (why should it
-**      be, if it is not at all meaningful?).
-**
-** By themselves, these optimizations work fine and provide a handy
-** performance boost to bulk delete or insert operations. However, if
-** a page is moved to the free-list and then reused within the same
-** transaction, a problem comes up. If the page is not journalled when
-** it is moved to the free-list and it is also not journalled when it
-** is extracted from the free-list and reused, then the original data
-** may be lost. In the event of a rollback, it may not be possible
-** to restore the database to its original configuration.
-**
-** The solution is the BtShared.pHasContent bitvec. Whenever a page is 
-** moved to become a free-list leaf page, the corresponding bit is
-** set in the bitvec. Whenever a leaf page is extracted from the free-list,
-** optimization 2 above is ommitted if the corresponding bit is already
-** set in BtShared.pHasContent. The contents of the bitvec are cleared
-** at the end of every transaction.
-*/
-static int btreeSetHasContent(BtShared *pBt, Pgno pgno){
-  int rc = SQLITE_OK;
-  if( !pBt-&gt;pHasContent ){
-    int nPage;
-    rc = sqlite3PagerPagecount(pBt-&gt;pPager, &amp;nPage);
-    if( rc==SQLITE_OK ){
-      pBt-&gt;pHasContent = sqlite3BitvecCreate((u32)nPage);
-      if( !pBt-&gt;pHasContent ){
-        rc = SQLITE_NOMEM;
-      }
-    }
-  }
-  if( rc==SQLITE_OK &amp;&amp; pgno&lt;=sqlite3BitvecSize(pBt-&gt;pHasContent) ){
-    rc = sqlite3BitvecSet(pBt-&gt;pHasContent, pgno);
-  }
-  return rc;
-}
-
-/*
-** Query the BtShared.pHasContent vector.
-**
-** This function is called when a free-list leaf page is removed from the
-** free-list for reuse. It returns false if it is safe to retrieve the
-** page from the pager layer with the 'no-content' flag set. True otherwise.
-*/
-static int btreeGetHasContent(BtShared *pBt, Pgno pgno){
-  Bitvec *p = pBt-&gt;pHasContent;
-  return (p &amp;&amp; (pgno&gt;sqlite3BitvecSize(p) || sqlite3BitvecTest(p, pgno)));
-}
-
-/*
-** Clear (destroy) the BtShared.pHasContent bitvec. This should be
-** invoked at the conclusion of each write-transaction.
-*/
-static void btreeClearHasContent(BtShared *pBt){
-  sqlite3BitvecDestroy(pBt-&gt;pHasContent);
-  pBt-&gt;pHasContent = 0;
-}
-
-/*
 ** Save the current cursor position in the variables BtCursor.nKey 
 ** and BtCursor.pKey. The cursor's state is set to CURSOR_REQUIRESEEK.
 */
@@ -38538,21 +37350,6 @@ SQLITE_PRIVATE int sqlite3BtreeGetPage(
 }
 
 /*
-** Retrieve a page from the pager cache. If the requested page is not
-** already in the pager cache return NULL. Initialize the MemPage.pBt and
-** MemPage.aData elements if needed.
-*/
-static MemPage *btreePageLookup(BtShared *pBt, Pgno pgno){
-  DbPage *pDbPage;
-  assert( sqlite3_mutex_held(pBt-&gt;mutex) );
-  pDbPage = sqlite3PagerLookup(pBt-&gt;pPager, pgno);
-  if( pDbPage ){
-    return btreePageFromDbPage(pDbPage, pgno, pBt);
-  }
-  return 0;
-}
-
-/*
 ** Return the size of the database file in pages. If there is any kind of
 ** error, return ((unsigned int)-1).
 */
@@ -38576,6 +37373,7 @@ static int getAndInitPage(
   MemPage **ppPage     /* Write the page pointer here */
 ){
   int rc;
+  DbPage *pDbPage;
   MemPage *pPage;
 
   assert( sqlite3_mutex_held(pBt-&gt;mutex) );
@@ -38588,9 +37386,10 @@ static int getAndInitPage(
   ** pagerPagecount() to make sure pgno is within limits, which results
   ** in a measureable performance improvements.
   */
-  *ppPage = pPage = btreePageLookup(pBt, pgno);
-  if( pPage ){
+  pDbPage = sqlite3PagerLookup(pBt-&gt;pPager, pgno);
+  if( pDbPage ){
     /* Page is already in cache */
+    *ppPage = pPage = btreePageFromDbPage(pDbPage, pgno, pBt);
     rc = SQLITE_OK;
   }else{
     /* Page not in cache.  Acquire it. */
@@ -39463,7 +38262,7 @@ SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree *p, int wrflag){
       if( pBt-&gt;readOnly ){
         rc = SQLITE_READONLY;
       }else{
-        rc = sqlite3PagerBegin(pBt-&gt;pPager, wrflag&gt;1);
+        rc = sqlite3PagerBegin(pBt-&gt;pPage1-&gt;pDbPage, wrflag&gt;1);
         if( rc==SQLITE_OK ){
           rc = newDatabase(pBt);
         }
@@ -39822,7 +38621,7 @@ SQLITE_PRIVATE int sqlite3BtreeIncrVacuum(Btree *p){
     rc = SQLITE_DONE;
   }else{
     invalidateAllOverflowCache(pBt);
-    rc = incrVacuumStep(pBt, 0, pagerPagecount(pBt));
+    rc = incrVacuumStep(pBt, 0, sqlite3PagerImageSize(pBt-&gt;pPager));
   }
   sqlite3BtreeLeave(p);
   return rc;
@@ -39990,7 +38789,6 @@ SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree *p){
   /* Set the handles current transaction state to TRANS_NONE and unlock
   ** the pager if this call closed the only read or write transaction.
   */
-  btreeClearHasContent(pBt);
   p-&gt;inTrans = TRANS_NONE;
   unlockBtreeIfUnused(pBt);
 
@@ -40126,7 +38924,6 @@ SQLITE_PRIVATE int sqlite3BtreeRollback(Btree *p){
     }
   }
 
-  btreeClearHasContent(pBt);
   p-&gt;inTrans = TRANS_NONE;
   pBt-&gt;inStmt = 0;
   unlockBtreeIfUnused(pBt);
@@ -40534,29 +39331,34 @@ SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor *pCur, u32 *pSize){
 **
 ** If an error occurs an SQLite error code is returned. Otherwise:
 **
-** The page number of the next overflow page in the linked list is 
-** written to *pPgnoNext. If page ovfl is the last page in its linked 
-** list, *pPgnoNext is set to zero. 
+** Unless pPgnoNext is NULL, the page number of the next overflow 
+** page in the linked list is written to *pPgnoNext. If page ovfl
+** is the last page in its linked list, *pPgnoNext is set to zero. 
 **
-** If ppPage is not NULL, and a reference to the MemPage object corresponding
-** to page number pOvfl was obtained, then *ppPage is set to point to that
-** reference. It is the responsibility of the caller to call releasePage()
-** on *ppPage to free the reference. In no reference was obtained (because
-** the pointer-map was used to obtain the value for *pPgnoNext), then
-** *ppPage is set to zero.
+** If ppPage is not NULL, *ppPage is set to the MemPage* handle
+** for page ovfl. The underlying pager page may have been requested
+** with the noContent flag set, so the page data accessable via
+** this handle may not be trusted.
 */
 static int getOverflowPage(
   BtShared *pBt, 
   Pgno ovfl,                   /* Overflow page */
-  MemPage **ppPage,            /* OUT: MemPage handle (may be NULL) */
+  MemPage **ppPage,            /* OUT: MemPage handle */
   Pgno *pPgnoNext              /* OUT: Next overflow page number */
 ){
   Pgno next = 0;
-  MemPage *pPage = 0;
   int rc = SQLITE_OK;
 
   assert( sqlite3_mutex_held(pBt-&gt;mutex) );
-  assert(pPgnoNext);
+  /* One of these must not be NULL. Otherwise, why call this function? */
+  assert(ppPage || pPgnoNext);
+
+  /* If pPgnoNext is NULL, then this function is being called to obtain
+  ** a MemPage* reference only. No page-data is required in this case.
+  */
+  if( !pPgnoNext ){
+    return sqlite3BtreeGetPage(pBt, ovfl, ppPage, 1);
+  }
 
 #ifndef SQLITE_OMIT_AUTOVACUUM
   /* Try to find the next page in the overflow list using the
@@ -40576,29 +39378,34 @@ static int getOverflowPage(
 
     if( iGuess&lt;=pagerPagecount(pBt) ){
       rc = ptrmapGet(pBt, iGuess, &amp;eType, &amp;pgno);
-      if( rc==SQLITE_OK &amp;&amp; eType==PTRMAP_OVERFLOW2 &amp;&amp; pgno==ovfl ){
+      if( rc!=SQLITE_OK ){
+        return rc;
+      }
+      if( eType==PTRMAP_OVERFLOW2 &amp;&amp; pgno==ovfl ){
         next = iGuess;
-        rc = SQLITE_DONE;
       }
     }
   }
 #endif
 
-  if( rc==SQLITE_OK ){
-    rc = sqlite3BtreeGetPage(pBt, ovfl, &amp;pPage, 0);
+  if( next==0 || ppPage ){
+    MemPage *pPage = 0;
+
+    rc = sqlite3BtreeGetPage(pBt, ovfl, &amp;pPage, next!=0);
     assert(rc==SQLITE_OK || pPage==0);
     if( next==0 &amp;&amp; rc==SQLITE_OK ){
       next = get4byte(pPage-&gt;aData);
     }
-  }
 
-  *pPgnoNext = next;
-  if( ppPage ){
-    *ppPage = pPage;
-  }else{
-    releasePage(pPage);
+    if( ppPage ){
+      *ppPage = pPage;
+    }else{
+      releasePage(pPage);
+    }
   }
-  return (rc==SQLITE_DONE ? SQLITE_OK : rc);
+  *pPgnoNext = next;
+
+  return rc;
 }
 
 /*
@@ -41707,7 +40514,6 @@ static int allocateBtreePage(
 
         iPage = get4byte(&amp;aData[8+closest*4]);
         if( !searchList || iPage==nearby ){
-          int noContent;
           Pgno nPage;
           *pPgno = iPage;
           nPage = pagerPagecount(pBt);
@@ -41724,9 +40530,9 @@ static int allocateBtreePage(
           }
           put4byte(&amp;aData[4], k-1);
           assert( sqlite3PagerIswriteable(pTrunk-&gt;pDbPage) );
-          noContent = !btreeGetHasContent(pBt, *pPgno);
-          rc = sqlite3BtreeGetPage(pBt, *pPgno, ppPage, noContent);
+          rc = sqlite3BtreeGetPage(pBt, *pPgno, ppPage, 1);
           if( rc==SQLITE_OK ){
+            sqlite3PagerDontRollback((*ppPage)-&gt;pDbPage);
             rc = sqlite3PagerWrite((*ppPage)-&gt;pDbPage);
             if( rc!=SQLITE_OK ){
               releasePage(*ppPage);
@@ -41744,10 +40550,6 @@ static int allocateBtreePage(
     int nPage = pagerPagecount(pBt);
     *pPgno = nPage + 1;
 
-    if( *pPgno==PENDING_BYTE_PAGE(pBt) ){
-      (*pPgno)++;
-    }
-
 #ifndef SQLITE_OMIT_AUTOVACUUM
     if( pBt-&gt;autoVacuum &amp;&amp; PTRMAP_ISPAGE(pBt, *pPgno) ){
       /* If *pPgno refers to a pointer-map page, allocate two new pages
@@ -41787,51 +40589,32 @@ end_allocate_page:
 }
 
 /*
-** This function is used to add page iPage to the database file free-list. 
-** It is assumed that the page is not already a part of the free-list.
+** Add a page of the database file to the freelist.
 **
-** The value passed as the second argument to this function is optional.
-** If the caller happens to have a pointer to the MemPage object 
-** corresponding to page iPage handy, it may pass it as the second value. 
-** Otherwise, it may pass NULL.
-**
-** If a pointer to a MemPage object is passed as the second argument,
-** its reference count is not altered by this function.
+** sqlite3PagerUnref() is NOT called for pPage.
 */
-static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){
-  MemPage *pTrunk = 0;                /* Free-list trunk page */
-  Pgno iTrunk = 0;                    /* Page number of free-list trunk page */ 
-  MemPage *pPage1 = pBt-&gt;pPage1;      /* Local reference to page 1 */
-  MemPage *pPage;                     /* Page being freed. May be NULL. */
-  int rc;                             /* Return Code */
-  int nFree;                          /* Initial number of pages on free-list */
-
-  assert( sqlite3_mutex_held(pBt-&gt;mutex) );
-  assert( iPage&gt;1 );
-  assert( !pMemPage || pMemPage-&gt;pgno==iPage );
+static int freePage(MemPage *pPage){
+  BtShared *pBt = pPage-&gt;pBt;
+  MemPage *pPage1 = pBt-&gt;pPage1;
+  int rc, n, k;
 
-  if( pMemPage ){
-    pPage = pMemPage;
-    sqlite3PagerRef(pPage-&gt;pDbPage);
-  }else{
-    pPage = btreePageLookup(pBt, iPage);
-  }
+  /* Prepare the page for freeing */
+  assert( sqlite3_mutex_held(pPage-&gt;pBt-&gt;mutex) );
+  assert( pPage-&gt;pgno&gt;1 );
+  pPage-&gt;isInit = 0;
 
   /* Increment the free page count on pPage1 */
   rc = sqlite3PagerWrite(pPage1-&gt;pDbPage);
-  if( rc ) goto freepage_out;
-  nFree = get4byte(&amp;pPage1-&gt;aData[36]);
-  put4byte(&amp;pPage1-&gt;aData[36], nFree+1);
+  if( rc ) return rc;
+  n = get4byte(&amp;pPage1-&gt;aData[36]);
+  put4byte(&amp;pPage1-&gt;aData[36], n+1);
 
 #ifdef SQLITE_SECURE_DELETE
   /* If the SQLITE_SECURE_DELETE compile-time option is enabled, then
   ** always fully overwrite deleted information with zeros.
   */
-  if( (!pPage &amp;&amp; (rc = sqlite3BtreeGetPage(pBt, iPage, &amp;pPage, 0)))
-   ||            (rc = sqlite3PagerWrite(pPage-&gt;pDbPage))
-  ){
-    goto freepage_out;
-  }
+  rc = sqlite3PagerWrite(pPage-&gt;pDbPage);
+  if( rc ) return rc;
   memset(pPage-&gt;aData, 0, pPage-&gt;pBt-&gt;pageSize);
 #endif
 
@@ -41839,34 +40622,27 @@ static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){
   ** to indicate that the page is free.
   */
   if( ISAUTOVACUUM ){
-    rc = ptrmapPut(pBt, iPage, PTRMAP_FREEPAGE, 0);
-    if( rc ) goto freepage_out;
+    rc = ptrmapPut(pBt, pPage-&gt;pgno, PTRMAP_FREEPAGE, 0);
+    if( rc ) return rc;
   }
 
-  /* Now manipulate the actual database free-list structure. There are two
-  ** possibilities. If the free-list is currently empty, or if the first
-  ** trunk page in the free-list is full, then this page will become a
-  ** new free-list trunk page. Otherwise, it will become a leaf of the
-  ** first trunk page in the current free-list. This block tests if it
-  ** is possible to add the page as a new free-list leaf.
-  */
-  if( nFree!=0 ){
-    int nLeaf;                /* Initial number of leaf cells on trunk page */
-
-    iTrunk = get4byte(&amp;pPage1-&gt;aData[32]);
-    rc = sqlite3BtreeGetPage(pBt, iTrunk, &amp;pTrunk, 0);
-    if( rc!=SQLITE_OK ){
-      goto freepage_out;
-    }
-
-    nLeaf = get4byte(&amp;pTrunk-&gt;aData[4]);
-    if( nLeaf&lt;0 ){
-      rc = SQLITE_CORRUPT_BKPT;
-      goto freepage_out;
-    }
-    if( nLeaf&lt;pBt-&gt;usableSize/4 - 8 ){
-      /* In this case there is room on the trunk page to insert the page
-      ** being freed as a new leaf.
+  if( n==0 ){
+    /* This is the first free page */
+    rc = sqlite3PagerWrite(pPage-&gt;pDbPage);
+    if( rc ) return rc;
+    memset(pPage-&gt;aData, 0, 8);
+    put4byte(&amp;pPage1-&gt;aData[32], pPage-&gt;pgno);
+    TRACE((&quot;FREE-PAGE: %d first\n&quot;, pPage-&gt;pgno));
+  }else{
+    /* Other free pages already exist.  Retrive the first trunk page
+    ** of the freelist and find out how many leaves it has. */
+    MemPage *pTrunk;
+    rc = sqlite3BtreeGetPage(pBt, get4byte(&amp;pPage1-&gt;aData[32]), &amp;pTrunk, 0);
+    if( rc ) return rc;
+    k = get4byte(&amp;pTrunk-&gt;aData[4]);
+    if( k&gt;=pBt-&gt;usableSize/4 - 8 ){
+      /* The trunk is full.  Turn the page being freed into a new
+      ** trunk page with no leaves.
       **
       ** Note that the trunk page is not really full until it contains
       ** usableSize/4 - 2 entries, not usableSize/4 - 8 entries as we have
@@ -41879,49 +40655,32 @@ static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){
       ** to 3.6.0 or later) we should consider fixing the conditional above
       ** to read &quot;usableSize/4-2&quot; instead of &quot;usableSize/4-8&quot;.
       */
+      rc = sqlite3PagerWrite(pPage-&gt;pDbPage);
+      if( rc==SQLITE_OK ){
+        put4byte(pPage-&gt;aData, pTrunk-&gt;pgno);
+        put4byte(&amp;pPage-&gt;aData[4], 0);
+        put4byte(&amp;pPage1-&gt;aData[32], pPage-&gt;pgno);
+        TRACE((&quot;FREE-PAGE: %d new trunk page replacing %d\n&quot;,
+                pPage-&gt;pgno, pTrunk-&gt;pgno));
+      }
+    }else if( k&lt;0 ){
+      rc = SQLITE_CORRUPT;
+    }else{
+      /* Add the newly freed page as a leaf on the current trunk */
       rc = sqlite3PagerWrite(pTrunk-&gt;pDbPage);
       if( rc==SQLITE_OK ){
-        put4byte(&amp;pTrunk-&gt;aData[4], nLeaf+1);
-        put4byte(&amp;pTrunk-&gt;aData[8+nLeaf*4], iPage);
+        put4byte(&amp;pTrunk-&gt;aData[4], k+1);
+        put4byte(&amp;pTrunk-&gt;aData[8+k*4], pPage-&gt;pgno);
 #ifndef SQLITE_SECURE_DELETE
-        if( pPage ){
-          sqlite3PagerDontWrite(pPage-&gt;pDbPage);
-        }
+        rc = sqlite3PagerDontWrite(pPage-&gt;pDbPage);
 #endif
-        rc = btreeSetHasContent(pBt, iPage);
       }
       TRACE((&quot;FREE-PAGE: %d leaf on trunk page %d\n&quot;,pPage-&gt;pgno,pTrunk-&gt;pgno));
-      goto freepage_out;
     }
+    releasePage(pTrunk);
   }
-
-  /* If control flows to this point, then it was not possible to add the
-  ** the page being freed as a leaf page of the first trunk in the free-list.
-  ** Possibly because the free-list is empty, or possibly because the 
-  ** first trunk in the free-list is full. Either way, the page being freed
-  ** will become the new first trunk page in the free-list.
-  */
-  if(   ((!pPage) &amp;&amp; (0 != (rc = sqlite3BtreeGetPage(pBt, iPage, &amp;pPage, 0))))
-     || (0 != (rc = sqlite3PagerWrite(pPage-&gt;pDbPage)))
-  ){
-    goto freepage_out;
-  }
-  put4byte(pPage-&gt;aData, iTrunk);
-  put4byte(&amp;pPage-&gt;aData[4], 0);
-  put4byte(&amp;pPage1-&gt;aData[32], iPage);
-  TRACE((&quot;FREE-PAGE: %d new trunk page replacing %d\n&quot;, pPage-&gt;pgno, iTrunk));
-
-freepage_out:
-  if( pPage ){
-    pPage-&gt;isInit = 0;
-  }
-  releasePage(pPage);
-  releasePage(pTrunk);
   return rc;
 }
-static int freePage(MemPage *pPage){
-  return freePage2(pPage-&gt;pBt, pPage, pPage-&gt;pgno);
-}
 
 /*
 ** Free any overflow pages associated with the given Cell.
@@ -41932,7 +40691,7 @@ static int clearCell(MemPage *pPage, unsigned char *pCell){
   Pgno ovflPgno;
   int rc;
   int nOvfl;
-  u16 ovflPageSize;
+  int ovflPageSize;
 
   assert( sqlite3_mutex_held(pPage-&gt;pBt-&gt;mutex) );
   sqlite3BtreeParseCellPtr(pPage, pCell, &amp;info);
@@ -41940,26 +40699,20 @@ static int clearCell(MemPage *pPage, unsigned char *pCell){
     return SQLITE_OK;  /* No overflow pages. Return without doing anything */
   }
   ovflPgno = get4byte(&amp;pCell[info.iOverflow]);
-  assert( pBt-&gt;usableSize &gt; 4 );
   ovflPageSize = pBt-&gt;usableSize - 4;
   nOvfl = (info.nPayload - info.nLocal + ovflPageSize - 1)/ovflPageSize;
   assert( ovflPgno==0 || nOvfl&gt;0 );
   while( nOvfl-- ){
-    Pgno iNext = 0;
-    MemPage *pOvfl = 0;
+    MemPage *pOvfl;
     if( ovflPgno==0 || ovflPgno&gt;pagerPagecount(pBt) ){
       return SQLITE_CORRUPT_BKPT;
     }
-    if( nOvfl ){
-      rc = getOverflowPage(pBt, ovflPgno, &amp;pOvfl, &amp;iNext);
-      if( rc ) return rc;
-    }
-    rc = freePage2(pBt, pOvfl, ovflPgno);
-    if( pOvfl ){
-      sqlite3PagerUnref(pOvfl-&gt;pDbPage);
-    }
+
+    rc = getOverflowPage(pBt, ovflPgno, &amp;pOvfl, (nOvfl==0)?0:&amp;ovflPgno);
+    if( rc ) return rc;
+    rc = freePage(pOvfl);
+    sqlite3PagerUnref(pOvfl-&gt;pDbPage);
     if( rc ) return rc;
-    ovflPgno = iNext;
   }
   return SQLITE_OK;
 }
@@ -42027,9 +40780,7 @@ static int fillInCell(
     nSrc = nData;
     nData = 0;
   }else{ 
-    if( nKey&gt;0x7fffffff || pKey==0 ){
-      return SQLITE_CORRUPT;
-    }
+    /* TBD:  Perhaps raise SQLITE_CORRUPT if nKey is larger than 31 bits? */
     nPayload += (int)nKey;
     pSrc = pKey;
     nSrc = (int)nKey;
@@ -42951,10 +41702,7 @@ static int balance_nonroot(BtCursor *pCur){
         j--;
         sqlite3BtreeParseCellPtr(pNew, apCell[j], &amp;info);
         pCell = pTemp;
-        rc = fillInCell(pParent, pCell, 0, info.nKey, 0, 0, 0, &amp;sz);
-        if( rc!=SQLITE_OK ){
-          goto balance_cleanup;
-        }
+        fillInCell(pParent, pCell, 0, info.nKey, 0, 0, 0, &amp;sz);
         pTemp = 0;
       }else{
         pCell -= 4;
@@ -43730,6 +42478,11 @@ static int btreeCreateTable(Btree *p, int *piTable, int flags){
       }
       assert( eType!=PTRMAP_ROOTPAGE );
       assert( eType!=PTRMAP_FREEPAGE );
+      rc = sqlite3PagerWrite(pRoot-&gt;pDbPage);
+      if( rc!=SQLITE_OK ){
+        releasePage(pRoot);
+        return rc;
+      }
       rc = relocatePage(pBt, pRoot, eType, iPtrPage, pgnoMove, 0);
       releasePage(pRoot);
 
@@ -44591,6 +43344,17 @@ SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *p){
 }
 
 /*
+** Return the pathname of the directory that contains the database file.
+**
+** The pager directory name is invariant as long as the pager is
+** open so it is safe to access without the BtShared mutex.
+*/
+SQLITE_PRIVATE const char *sqlite3BtreeGetDirname(Btree *p){
+  assert( p-&gt;pBt-&gt;pPager!=0 );
+  return sqlite3PagerDirname(p-&gt;pBt-&gt;pPager);
+}
+
+/*
 ** Return the pathname of the journal file for this database. The return
 ** value of this routine is the same regardless of whether the journal file
 ** has been created or not.
@@ -44603,6 +43367,221 @@ SQLITE_PRIVATE const char *sqlite3BtreeGetJournalname(Btree *p){
   return sqlite3PagerJournalname(p-&gt;pBt-&gt;pPager);
 }
 
+#ifndef SQLITE_OMIT_VACUUM
+/*
+** Copy the complete content of pBtFrom into pBtTo.  A transaction
+** must be active for both files.
+**
+** The size of file pTo may be reduced by this operation.
+** If anything goes wrong, the transaction on pTo is rolled back. 
+**
+** If successful, CommitPhaseOne() may be called on pTo before returning. 
+** The caller should finish committing the transaction on pTo by calling
+** sqlite3BtreeCommit().
+*/
+static int btreeCopyFile(Btree *pTo, Btree *pFrom){
+  int rc = SQLITE_OK;
+  Pgno i;
+
+  Pgno nFromPage;     /* Number of pages in pFrom */
+  Pgno nToPage;       /* Number of pages in pTo */
+  Pgno nNewPage;      /* Number of pages in pTo after the copy */
+
+  Pgno iSkip;         /* Pending byte page in pTo */
+  int nToPageSize;    /* Page size of pTo in bytes */
+  int nFromPageSize;  /* Page size of pFrom in bytes */
+
+  BtShared *pBtTo = pTo-&gt;pBt;
+  BtShared *pBtFrom = pFrom-&gt;pBt;
+  pBtTo-&gt;db = pTo-&gt;db;
+  pBtFrom-&gt;db = pFrom-&gt;db;
+
+  nToPageSize = pBtTo-&gt;pageSize;
+  nFromPageSize = pBtFrom-&gt;pageSize;
+
+  assert( pTo-&gt;inTrans==TRANS_WRITE );
+  assert( pFrom-&gt;inTrans==TRANS_WRITE );
+  if( NEVER(pBtTo-&gt;pCursor) ){
+    return SQLITE_BUSY;
+  }
+
+  nToPage = pagerPagecount(pBtTo);
+  nFromPage = pagerPagecount(pBtFrom);
+  iSkip = PENDING_BYTE_PAGE(pBtTo);
+
+  /* Variable nNewPage is the number of pages required to store the
+  ** contents of pFrom using the current page-size of pTo.
+  */
+  nNewPage = (Pgno)
+     (((i64)nFromPage*(i64)nFromPageSize+(i64)nToPageSize-1)/(i64)nToPageSize);
+
+  for(i=1; rc==SQLITE_OK &amp;&amp; (i&lt;=nToPage || i&lt;=nNewPage); i++){
+
+    /* Journal the original page.
+    **
+    ** iSkip is the page number of the locking page (PENDING_BYTE_PAGE)
+    ** in database *pTo (before the copy). This page is never written 
+    ** into the journal file. Unless i==iSkip or the page was not
+    ** present in pTo before the copy operation, journal page i from pTo.
+    */
+    if( i!=iSkip &amp;&amp; i&lt;=nToPage ){
+      DbPage *pDbPage = 0;
+      rc = sqlite3PagerGet(pBtTo-&gt;pPager, i, &amp;pDbPage);
+      if( rc==SQLITE_OK ){
+        rc = sqlite3PagerWrite(pDbPage);
+        if( rc==SQLITE_OK &amp;&amp; i&gt;nFromPage ){
+          /* Yeah.  It seems wierd to call DontWrite() right after Write(). But
+          ** that is because the names of those procedures do not exactly 
+          ** represent what they do.  Write() really means &quot;put this page in the
+          ** rollback journal and mark it as dirty so that it will be written
+          ** to the database file later.&quot;  DontWrite() undoes the second part of
+          ** that and prevents the page from being written to the database. The
+          ** page is still on the rollback journal, though.  And that is the 
+          ** whole point of this block: to put pages on the rollback journal. 
+          */
+          rc = sqlite3PagerDontWrite(pDbPage);
+        }
+        sqlite3PagerUnref(pDbPage);
+      }
+    }
+
+    /* Overwrite the data in page i of the target database */
+    if( rc==SQLITE_OK &amp;&amp; i!=iSkip &amp;&amp; i&lt;=nNewPage ){
+
+      DbPage *pToPage = 0;
+      sqlite3_int64 iOff;
+
+      rc = sqlite3PagerGet(pBtTo-&gt;pPager, i, &amp;pToPage);
+      if( rc==SQLITE_OK ){
+        rc = sqlite3PagerWrite(pToPage);
+      }
+
+      for(
+        iOff=(i-1)*nToPageSize; 
+        rc==SQLITE_OK &amp;&amp; iOff&lt;i*nToPageSize; 
+        iOff += nFromPageSize
+      ){
+        DbPage *pFromPage = 0;
+        Pgno iFrom = (Pgno)(iOff/nFromPageSize)+1;
+
+        if( iFrom==PENDING_BYTE_PAGE(pBtFrom) ){
+          continue;
+        }
+
+        rc = sqlite3PagerGet(pBtFrom-&gt;pPager, iFrom, &amp;pFromPage);
+        if( rc==SQLITE_OK ){
+          char *zTo = sqlite3PagerGetData(pToPage);
+          char *zFrom = sqlite3PagerGetData(pFromPage);
+          int nCopy;
+
+          if( nFromPageSize&gt;=nToPageSize ){
+            zFrom += ((i-1)*nToPageSize - ((iFrom-1)*nFromPageSize));
+            nCopy = nToPageSize;
+          }else{
+            zTo += (((iFrom-1)*nFromPageSize) - (i-1)*nToPageSize);
+            nCopy = nFromPageSize;
+          }
+
+          memcpy(zTo, zFrom, nCopy);
+          sqlite3PagerUnref(pFromPage);
+        }
+      }
+
+      if( pToPage ){
+        MemPage *p = (MemPage *)sqlite3PagerGetExtra(pToPage);
+        p-&gt;isInit = 0;
+        sqlite3PagerUnref(pToPage);
+      }
+    }
+  }
+
+  /* If things have worked so far, the database file may need to be 
+  ** truncated. The complex part is that it may need to be truncated to
+  ** a size that is not an integer multiple of nToPageSize - the current
+  ** page size used by the pager associated with B-Tree pTo.
+  **
+  ** For example, say the page-size of pTo is 2048 bytes and the original 
+  ** number of pages is 5 (10 KB file). If pFrom has a page size of 1024 
+  ** bytes and 9 pages, then the file needs to be truncated to 9KB.
+  */
+  if( rc==SQLITE_OK ){
+    sqlite3_file *pFile = sqlite3PagerFile(pBtTo-&gt;pPager);
+    i64 iSize = (i64)nFromPageSize * (i64)nFromPage;
+    i64 iNow = (i64)((nToPage&gt;nNewPage)?nToPage:nNewPage) * (i64)nToPageSize; 
+    i64 iPending = ((i64)PENDING_BYTE_PAGE(pBtTo)-1) *(i64)nToPageSize;
+
+    assert( iSize&lt;=iNow );
+
+    /* Commit phase one syncs the journal file associated with pTo 
+    ** containing the original data. It does not sync the database file
+    ** itself. After doing this it is safe to use OsTruncate() and other
+    ** file APIs on the database file directly.
+    */
+    pBtTo-&gt;db = pTo-&gt;db;
+    rc = sqlite3PagerCommitPhaseOne(pBtTo-&gt;pPager, 0, 1);
+    if( iSize&lt;iNow &amp;&amp; rc==SQLITE_OK ){
+      rc = sqlite3OsTruncate(pFile, iSize);
+    }
+
+    /* The loop that copied data from database pFrom to pTo did not
+    ** populate the locking page of database pTo. If the page-size of
+    ** pFrom is smaller than that of pTo, this means some data will
+    ** not have been copied. 
+    **
+    ** This block copies the missing data from database pFrom to pTo 
+    ** using file APIs. This is safe because at this point we know that
+    ** all of the original data from pTo has been synced into the 
+    ** journal file. At this point it would be safe to do anything at
+    ** all to the database file except truncate it to zero bytes.
+    */
+    if( rc==SQLITE_OK &amp;&amp; nFromPageSize&lt;nToPageSize &amp;&amp; iSize&gt;iPending){
+      i64 iOff;
+      for(
+        iOff=iPending; 
+        rc==SQLITE_OK &amp;&amp; iOff&lt;(iPending+nToPageSize); 
+        iOff += nFromPageSize
+      ){
+        DbPage *pFromPage = 0;
+        Pgno iFrom = (Pgno)(iOff/nFromPageSize)+1;
+
+        if( iFrom==PENDING_BYTE_PAGE(pBtFrom) || iFrom&gt;nFromPage ){
+          continue;
+        }
+
+        rc = sqlite3PagerGet(pBtFrom-&gt;pPager, iFrom, &amp;pFromPage);
+        if( rc==SQLITE_OK ){
+          char *zFrom = sqlite3PagerGetData(pFromPage);
+          rc = sqlite3OsWrite(pFile, zFrom, nFromPageSize, iOff);
+          sqlite3PagerUnref(pFromPage);
+        }
+      }
+    }
+  }
+
+  /* Sync the database file */
+  if( rc==SQLITE_OK ){
+    rc = sqlite3PagerSync(pBtTo-&gt;pPager);
+  }
+  if( rc==SQLITE_OK ){
+    pBtTo-&gt;pageSizeFixed = 0;
+  }else{
+    sqlite3BtreeRollback(pTo);
+  }
+
+  return rc;
+}
+SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
+  int rc;
+  sqlite3BtreeEnter(pTo);
+  sqlite3BtreeEnter(pFrom);
+  rc = btreeCopyFile(pTo, pFrom);
+  sqlite3BtreeLeave(pFrom);
+  sqlite3BtreeLeave(pTo);
+  return rc;
+}
+
+#endif /* SQLITE_OMIT_VACUUM */
+
 /*
 ** Return non-zero if a transaction is active.
 */
@@ -44628,12 +43607,6 @@ SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree *p){
   return p-&gt;inTrans!=TRANS_NONE;
 }
 
-SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree *p){
-  assert( p );
-  assert( sqlite3_mutex_held(p-&gt;db-&gt;mutex) );
-  return p-&gt;nBackup!=0;
-}
-
 /*
 ** This function returns a pointer to a blob of memory associated with
 ** a single shared-btree. The memory is used by client code for its own
@@ -44761,618 +43734,6 @@ SQLITE_PRIVATE void sqlite3BtreeCacheOverflow(BtCursor *pCur){
 #endif
 
 /************** End of btree.c ***********************************************/
-/************** Begin file backup.c ******************************************/
-/*
-** 2009 January 28
-**
-** 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_backup_XXX() 
-** API functions and the related features.
-**
-** $Id: backup.c,v 1.12 2009/02/16 17:55:47 shane Exp $
-*/
-
-/* Macro to find the minimum of two numeric values.
-*/
-#ifndef MIN
-# define MIN(x,y) ((x)&lt;(y)?(x):(y))
-#endif
-
-/*
-** Structure allocated for each backup operation.
-*/
-struct sqlite3_backup {
-  sqlite3* pDestDb;        /* Destination database handle */
-  Btree *pDest;            /* Destination b-tree file */
-  u32 iDestSchema;         /* Original schema cookie in destination */
-  int bDestLocked;         /* True once a write-transaction is open on pDest */
-
-  Pgno iNext;              /* Page number of the next source page to copy */
-  sqlite3* pSrcDb;         /* Source database handle */
-  Btree *pSrc;             /* Source b-tree file */
-
-  int rc;                  /* Backup process error code */
-
-  /* These two variables are set by every call to backup_step(). They are
-  ** read by calls to backup_remaining() and backup_pagecount().
-  */
-  Pgno nRemaining;         /* Number of pages left to copy */
-  Pgno nPagecount;         /* Total number of pages to copy */
-
-  sqlite3_backup *pNext;   /* Next backup associated with source pager */
-};
-
-/*
-** THREAD SAFETY NOTES:
-**
-**   Once it has been created using backup_init(), a single sqlite3_backup
-**   structure may be accessed via two groups of thread-safe entry points:
-**
-**     * Via the sqlite3_backup_XXX() API function backup_step() and 
-**       backup_finish(). Both these functions obtain the source database
-**       handle mutex and the mutex associated with the source BtShared 
-**       structure, in that order.
-**
-**     * Via the BackupUpdate() and BackupRestart() functions, which are
-**       invoked by the pager layer to report various state changes in
-**       the page cache associated with the source database. The mutex
-**       associated with the source database BtShared structure will always 
-**       be held when either of these functions are invoked.
-**
-**   The other sqlite3_backup_XXX() API functions, backup_remaining() and
-**   backup_pagecount() are not thread-safe functions. If they are called
-**   while some other thread is calling backup_step() or backup_finish(),
-**   the values returned may be invalid. There is no way for a call to
-**   BackupUpdate() or BackupRestart() to interfere with backup_remaining()
-**   or backup_pagecount().
-**
-**   Depending on the SQLite configuration, the database handles and/or
-**   the Btree objects may have their own mutexes that require locking.
-**   Non-sharable Btrees (in-memory databases for example), do not have
-**   associated mutexes.
-*/
-
-/*
-** Return a pointer corresponding to database zDb (i.e. &quot;main&quot;, &quot;temp&quot;)
-** in connection handle pDb. If such a database cannot be found, return
-** a NULL pointer and write an error message to pErrorDb.
-**
-** If the &quot;temp&quot; database is requested, it may need to be opened by this 
-** function. If an error occurs while doing so, return 0 and write an 
-** error message to pErrorDb.
-*/
-static Btree *findBtree(sqlite3 *pErrorDb, sqlite3 *pDb, const char *zDb){
-  int i = sqlite3FindDbName(pDb, zDb);
-
-  if( i==1 ){
-    Parse sParse;
-    memset(&amp;sParse, 0, sizeof(sParse));
-    sParse.db = pDb;
-    if( sqlite3OpenTempDatabase(&amp;sParse) ){
-      sqlite3ErrorClear(&amp;sParse);
-      sqlite3Error(pErrorDb, sParse.rc, &quot;%s&quot;, sParse.zErrMsg);
-      return 0;
-    }
-    assert( sParse.zErrMsg==0 );
-  }
-
-  if( i&lt;0 ){
-    sqlite3Error(pErrorDb, SQLITE_ERROR, &quot;unknown database %s&quot;, zDb);
-    return 0;
-  }
-
-  return pDb-&gt;aDb[i].pBt;
-}
-
-/*
-** Create an sqlite3_backup process to copy the contents of zSrcDb from
-** connection handle pSrcDb to zDestDb in pDestDb. If successful, return
-** a pointer to the new sqlite3_backup object.
-**
-** If an error occurs, NULL is returned and an error code and error message
-** stored in database handle pDestDb.
-*/
-SQLITE_API sqlite3_backup *sqlite3_backup_init(
-  sqlite3* pDestDb,                     /* Database to write to */
-  const char *zDestDb,                  /* Name of database within pDestDb */
-  sqlite3* pSrcDb,                      /* Database connection to read from */
-  const char *zSrcDb                    /* Name of database within pSrcDb */
-){
-  sqlite3_backup *p;                    /* Value to return */
-
-  /* Lock the source database handle. The destination database
-  ** handle is not locked in this routine, but it is locked in
-  ** sqlite3_backup_step(). The user is required to ensure that no
-  ** other thread accesses the destination handle for the duration
-  ** of the backup operation.  Any attempt to use the destination
-  ** database connection while a backup is in progress may cause
-  ** a malfunction or a deadlock.
-  */
-  sqlite3_mutex_enter(pSrcDb-&gt;mutex);
-  sqlite3_mutex_enter(pDestDb-&gt;mutex);
-
-  if( pSrcDb==pDestDb ){
-    sqlite3Error(
-        pDestDb, SQLITE_ERROR, &quot;source and destination must be distinct&quot;
-    );
-    p = 0;
-  }else {
-    /* Allocate space for a new sqlite3_backup object */
-    p = (sqlite3_backup *)sqlite3_malloc(sizeof(sqlite3_backup));
-    if( !p ){
-      sqlite3Error(pDestDb, SQLITE_NOMEM, 0);
-    }
-  }
-
-  /* If the allocation succeeded, populate the new object. */
-  if( p ){
-    memset(p, 0, sizeof(sqlite3_backup));
-    p-&gt;pSrc = findBtree(pDestDb, pSrcDb, zSrcDb);
-    p-&gt;pDest = findBtree(pDestDb, pDestDb, zDestDb);
-    p-&gt;pDestDb = pDestDb;
-    p-&gt;pSrcDb = pSrcDb;
-    p-&gt;iNext = 1;
-
-    if( 0==p-&gt;pSrc || 0==p-&gt;pDest ){
-      /* One (or both) of the named databases did not exist. An error has
-      ** already been written into the pDestDb handle. All that is left
-      ** to do here is free the sqlite3_backup structure.
-      */
-      sqlite3_free(p);
-      p = 0;
-    }
-  }
-
-  /* If everything has gone as planned, attach the backup object to the
-  ** source pager. The source pager calls BackupUpdate() and BackupRestart()
-  ** to notify this module if the source file is modified mid-backup.
-  */
-  if( p ){
-    sqlite3_backup **pp;             /* Pointer to head of pagers backup list */
-    sqlite3BtreeEnter(p-&gt;pSrc);
-    pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p-&gt;pSrc));
-    p-&gt;pNext = *pp;
-    *pp = p;
-    sqlite3BtreeLeave(p-&gt;pSrc);
-    p-&gt;pSrc-&gt;nBackup++;
-  }
-
-  sqlite3_mutex_leave(pDestDb-&gt;mutex);
-  sqlite3_mutex_leave(pSrcDb-&gt;mutex);
-  return p;
-}
-
-/*
-** Argument rc is an SQLite error code. Return true if this error is 
-** considered fatal if encountered during a backup operation. All errors
-** are considered fatal except for SQLITE_BUSY and SQLITE_LOCKED.
-*/
-static int isFatalError(int rc){
-  return (rc!=SQLITE_OK &amp;&amp; rc!=SQLITE_BUSY &amp;&amp; rc!=SQLITE_LOCKED);
-}
-
-/*
-** Parameter zSrcData points to a buffer containing the data for 
-** page iSrcPg from the source database. Copy this data into the 
-** destination database.
-*/
-static int backupOnePage(sqlite3_backup *p, Pgno iSrcPg, const u8 *zSrcData){
-  Pager * const pDestPager = sqlite3BtreePager(p-&gt;pDest);
-  const int nSrcPgsz = sqlite3BtreeGetPageSize(p-&gt;pSrc);
-  int nDestPgsz = sqlite3BtreeGetPageSize(p-&gt;pDest);
-  const int nCopy = MIN(nSrcPgsz, nDestPgsz);
-  const i64 iEnd = (i64)iSrcPg*(i64)nSrcPgsz;
-
-  int rc = SQLITE_OK;
-  i64 iOff;
-
-  assert( p-&gt;bDestLocked );
-  assert( !isFatalError(p-&gt;rc) );
-  assert( iSrcPg!=PENDING_BYTE_PAGE(p-&gt;pSrc-&gt;pBt) );
-  assert( zSrcData );
-
-  /* Catch the case where the destination is an in-memory database and the
-  ** page sizes of the source and destination differ. 
-  */
-  if( nSrcPgsz!=nDestPgsz &amp;&amp; sqlite3PagerIsMemdb(sqlite3BtreePager(p-&gt;pDest)) ){
-    rc = SQLITE_READONLY;
-  }
-
-  /* This loop runs once for each destination page spanned by the source 
-  ** page. For each iteration, variable iOff is set to the byte offset
-  ** of the destination page.
-  */
-  for(iOff=iEnd-(i64)nSrcPgsz; rc==SQLITE_OK &amp;&amp; iOff&lt;iEnd; iOff+=nDestPgsz){
-    DbPage *pDestPg = 0;
-    Pgno iDest = (Pgno)(iOff/nDestPgsz)+1;
-    if( iDest==PENDING_BYTE_PAGE(p-&gt;pDest-&gt;pBt) ) continue;
-    if( SQLITE_OK==(rc = sqlite3PagerGet(pDestPager, iDest, &amp;pDestPg))
-     &amp;&amp; SQLITE_OK==(rc = sqlite3PagerWrite(pDestPg))
-    ){
-      const u8 *zIn = &amp;zSrcData[iOff%nSrcPgsz];
-      u8 *zDestData = sqlite3PagerGetData(pDestPg);
-      u8 *zOut = &amp;zDestData[iOff%nDestPgsz];
-
-      /* Copy the data from the source page into the destination page.
-      ** Then clear the Btree layer MemPage.isInit flag. Both this module
-      ** and the pager code use this trick (clearing the first byte
-      ** of the page 'extra' space to invalidate the Btree layers
-      ** cached parse of the page). MemPage.isInit is marked 
-      ** &quot;MUST BE FIRST&quot; for this purpose.
-      */
-      memcpy(zOut, zIn, nCopy);
-      ((u8 *)sqlite3PagerGetExtra(pDestPg))[0] = 0;
-    }
-    sqlite3PagerUnref(pDestPg);
-  }
-
-  return rc;
-}
-
-/*
-** If pFile is currently larger than iSize bytes, then truncate it to
-** exactly iSize bytes. If pFile is not larger than iSize bytes, then
-** this function is a no-op.
-**
-** Return SQLITE_OK if everything is successful, or an SQLite error 
-** code if an error occurs.
-*/
-static int backupTruncateFile(sqlite3_file *pFile, i64 iSize){
-  i64 iCurrent;
-  int rc = sqlite3OsFileSize(pFile, &amp;iCurrent);
-  if( rc==SQLITE_OK &amp;&amp; iCurrent&gt;iSize ){
-    rc = sqlite3OsTruncate(pFile, iSize);
-  }
-  return rc;
-}
-
-/*
-** Copy nPage pages from the source b-tree to the destination.
-*/
-SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage){
-  int rc;
-
-  sqlite3_mutex_enter(p-&gt;pSrcDb-&gt;mutex);
-  sqlite3BtreeEnter(p-&gt;pSrc);
-  if( p-&gt;pDestDb ){
-    sqlite3_mutex_enter(p-&gt;pDestDb-&gt;mutex);
-  }
-
-  rc = p-&gt;rc;
-  if( !isFatalError(rc) ){
-    Pager * const pSrcPager = sqlite3BtreePager(p-&gt;pSrc);     /* Source pager */
-    Pager * const pDestPager = sqlite3BtreePager(p-&gt;pDest);   /* Dest pager */
-    int ii;                            /* Iterator variable */
-    int nSrcPage = -1;                 /* Size of source db in pages */
-    int bCloseTrans = 0;               /* True if src db requires unlocking */
-
-    /* If the source pager is currently in a write-transaction, return
-    ** SQLITE_LOCKED immediately.
-    */
-    if( p-&gt;pDestDb &amp;&amp; p-&gt;pSrc-&gt;pBt-&gt;inTransaction==TRANS_WRITE ){
-      rc = SQLITE_LOCKED;
-    }else{
-      rc = SQLITE_OK;
-    }
-
-    /* Lock the destination database, if it is not locked already. */
-    if( SQLITE_OK==rc &amp;&amp; p-&gt;bDestLocked==0
-     &amp;&amp; SQLITE_OK==(rc = sqlite3BtreeBeginTrans(p-&gt;pDest, 2)) 
-    ){
-      p-&gt;bDestLocked = 1;
-      rc = sqlite3BtreeGetMeta(p-&gt;pDest, 1, &amp;p-&gt;iDestSchema);
-    }
-
-    /* If there is no open read-transaction on the source database, open
-    ** one now. If a transaction is opened here, then it will be closed
-    ** before this function exits.
-    */
-    if( rc==SQLITE_OK &amp;&amp; 0==sqlite3BtreeIsInReadTrans(p-&gt;pSrc) ){
-      rc = sqlite3BtreeBeginTrans(p-&gt;pSrc, 0);
-      bCloseTrans = 1;
-    }
-  
-    /* Now that there is a read-lock on the source database, query the
-    ** source pager for the number of pages in the database.
-    */
-    if( rc==SQLITE_OK ){
-      rc = sqlite3PagerPagecount(pSrcPager, &amp;nSrcPage);
-    }
-    for(ii=0; (nPage&lt;0 || ii&lt;nPage) &amp;&amp; p-&gt;iNext&lt;=(Pgno)nSrcPage &amp;&amp; !rc; ii++){
-      const Pgno iSrcPg = p-&gt;iNext;                 /* Source page number */
-      if( iSrcPg!=PENDING_BYTE_PAGE(p-&gt;pSrc-&gt;pBt) ){
-        DbPage *pSrcPg;                             /* Source page object */
-        rc = sqlite3PagerGet(pSrcPager, iSrcPg, &amp;pSrcPg);
-        if( rc==SQLITE_OK ){
-          rc = backupOnePage(p, iSrcPg, sqlite3PagerGetData(pSrcPg));
-          sqlite3PagerUnref(pSrcPg);
-        }
-      }
-      p-&gt;iNext++;
-    }
-    if( rc==SQLITE_OK ){
-      p-&gt;nPagecount = nSrcPage;
-      p-&gt;nRemaining = nSrcPage+1-p-&gt;iNext;
-      if( p-&gt;iNext&gt;(Pgno)nSrcPage ){
-        rc = SQLITE_DONE;
-      }
-    }
-  
-    if( rc==SQLITE_DONE ){
-      const int nSrcPagesize = sqlite3BtreeGetPageSize(p-&gt;pSrc);
-      const int nDestPagesize = sqlite3BtreeGetPageSize(p-&gt;pDest);
-      int nDestTruncate;
-  
-      /* Update the schema version field in the destination database. This
-      ** is to make sure that the schema-version really does change in
-      ** the case where the source and destination databases have the
-      ** same schema version.
-      */
-      sqlite3BtreeUpdateMeta(p-&gt;pDest, 1, p-&gt;iDestSchema+1);
-      if( p-&gt;pDestDb ){
-        sqlite3ResetInternalSchema(p-&gt;pDestDb, 0);
-      }
-
-      /* Set nDestTruncate to the final number of pages in the destination
-      ** database. The complication here is that the destination page
-      ** size may be different to the source page size. 
-      **
-      ** If the source page size is smaller than the destination page size, 
-      ** round up. In this case the call to sqlite3OsTruncate() below will
-      ** fix the size of the file. However it is important to call
-      ** sqlite3PagerTruncateImage() here so that any pages in the 
-      ** destination file that lie beyond the nDestTruncate page mark are
-      ** journalled by PagerCommitPhaseOne() before they are destroyed
-      ** by the file truncation.
-      */
-      if( nSrcPagesize&lt;nDestPagesize ){
-        int ratio = nDestPagesize/nSrcPagesize;
-        nDestTruncate = (nSrcPage+ratio-1)/ratio;
-        if( nDestTruncate==(int)PENDING_BYTE_PAGE(p-&gt;pDest-&gt;pBt) ){
-          nDestTruncate--;
-        }
-      }else{
-        nDestTruncate = nSrcPage * (nSrcPagesize/nDestPagesize);
-      }
-      sqlite3PagerTruncateImage(pDestPager, nDestTruncate);
-
-      if( nSrcPagesize&lt;nDestPagesize ){
-        /* If the source page-size is smaller than the destination page-size,
-        ** two extra things may need to happen:
-        **
-        **   * The destination may need to be truncated, and
-        **
-        **   * Data stored on the pages immediately following the 
-        **     pending-byte page in the source database may need to be
-        **     copied into the destination database.
-        */
-        const i64 iSize = (i64)nSrcPagesize * (i64)nSrcPage;
-        sqlite3_file * const pFile = sqlite3PagerFile(pDestPager);
-
-        assert( pFile );
-        assert( (i64)nDestTruncate*(i64)nDestPagesize &gt;= iSize || (
-              nDestTruncate==(int)(PENDING_BYTE_PAGE(p-&gt;pDest-&gt;pBt)-1)
-           &amp;&amp; iSize&gt;=PENDING_BYTE &amp;&amp; iSize&lt;=PENDING_BYTE+nDestPagesize
-        ));
-        if( SQLITE_OK==(rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 1))
-         &amp;&amp; SQLITE_OK==(rc = backupTruncateFile(pFile, iSize))
-         &amp;&amp; SQLITE_OK==(rc = sqlite3PagerSync(pDestPager))
-        ){
-          i64 iOff;
-          i64 iEnd = MIN(PENDING_BYTE + nDestPagesize, iSize);
-          for(
-            iOff=PENDING_BYTE+nSrcPagesize; 
-            rc==SQLITE_OK &amp;&amp; iOff&lt;iEnd; 
-            iOff+=nSrcPagesize
-          ){
-            PgHdr *pSrcPg = 0;
-            const Pgno iSrcPg = (Pgno)((iOff/nSrcPagesize)+1);
-            rc = sqlite3PagerGet(pSrcPager, iSrcPg, &amp;pSrcPg);
-            if( rc==SQLITE_OK ){
-              u8 *zData = sqlite3PagerGetData(pSrcPg);
-              rc = sqlite3OsWrite(pFile, zData, nSrcPagesize, iOff);
-            }
-            sqlite3PagerUnref(pSrcPg);
-          }
-        }
-      }else{
-        rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
-      }
-  
-      /* Finish committing the transaction to the destination database. */
-      if( SQLITE_OK==rc
-       &amp;&amp; SQLITE_OK==(rc = sqlite3BtreeCommitPhaseTwo(p-&gt;pDest))
-      ){
-        rc = SQLITE_DONE;
-      }
-    }
-  
-    /* If bCloseTrans is true, then this function opened a read transaction
-    ** on the source database. Close the read transaction here. There is
-    ** no need to check the return values of the btree methods here, as
-    ** &quot;committing&quot; a read-only transaction cannot fail.
-    */
-    if( bCloseTrans ){
-      TESTONLY( int rc2 );
-      TESTONLY( rc2  = ) sqlite3BtreeCommitPhaseOne(p-&gt;pSrc, 0);
-      TESTONLY( rc2 |= ) sqlite3BtreeCommitPhaseTwo(p-&gt;pSrc);
-      assert( rc2==SQLITE_OK );
-    }
-  
-    p-&gt;rc = rc;
-  }
-  if( p-&gt;pDestDb ){
-    sqlite3_mutex_leave(p-&gt;pDestDb-&gt;mutex);
-  }
-  sqlite3BtreeLeave(p-&gt;pSrc);
-  sqlite3_mutex_leave(p-&gt;pSrcDb-&gt;mutex);
-  return rc;
-}
-
-/*
-** Release all resources associated with an sqlite3_backup* handle.
-*/
-SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p){
-  sqlite3_backup **pp;                 /* Ptr to head of pagers backup list */
-  sqlite3_mutex *mutex;                /* Mutex to protect source database */
-  int rc;                              /* Value to return */
-
-  /* Enter the mutexes */
-  sqlite3_mutex_enter(p-&gt;pSrcDb-&gt;mutex);
-  sqlite3BtreeEnter(p-&gt;pSrc);
-  mutex = p-&gt;pSrcDb-&gt;mutex;
-  if( p-&gt;pDestDb ){
-    sqlite3_mutex_enter(p-&gt;pDestDb-&gt;mutex);
-  }
-
-  /* Detach this backup from the source pager. */
-  if( p-&gt;pDestDb ){
-    pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p-&gt;pSrc));
-    while( *pp!=p ){
-      pp = &amp;(*pp)-&gt;pNext;
-    }
-    *pp = p-&gt;pNext;
-    p-&gt;pSrc-&gt;nBackup--;
-  }
-
-  /* If a transaction is still open on the Btree, roll it back. */
-  sqlite3BtreeRollback(p-&gt;pDest);
-
-  /* Set the error code of the destination database handle. */
-  rc = (p-&gt;rc==SQLITE_DONE) ? SQLITE_OK : p-&gt;rc;
-  sqlite3Error(p-&gt;pDestDb, rc, 0);
-
-  /* Exit the mutexes and free the backup context structure. */
-  if( p-&gt;pDestDb ){
-    sqlite3_mutex_leave(p-&gt;pDestDb-&gt;mutex);
-  }
-  sqlite3BtreeLeave(p-&gt;pSrc);
-  if( p-&gt;pDestDb ){
-    sqlite3_free(p);
-  }
-  sqlite3_mutex_leave(mutex);
-  return rc;
-}
-
-/*
-** Return the number of pages still to be backed up as of the most recent
-** call to sqlite3_backup_step().
-*/
-SQLITE_API int sqlite3_backup_remaining(sqlite3_backup *p){
-  return p-&gt;nRemaining;
-}
-
-/*
-** Return the total number of pages in the source database as of the most 
-** recent call to sqlite3_backup_step().
-*/
-SQLITE_API int sqlite3_backup_pagecount(sqlite3_backup *p){
-  return p-&gt;nPagecount;
-}
-
-/*
-** This function is called after the contents of page iPage of the
-** source database have been modified. If page iPage has already been 
-** copied into the destination database, then the data written to the
-** destination is now invalidated. The destination copy of iPage needs
-** to be updated with the new data before the backup operation is
-** complete.
-**
-** It is assumed that the mutex associated with the BtShared object
-** corresponding to the source database is held when this function is
-** called.
-*/
-SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *pBackup, Pgno iPage, const u8 *aData){
-  sqlite3_backup *p;                   /* Iterator variable */
-  for(p=pBackup; p; p=p-&gt;pNext){
-    assert( sqlite3_mutex_held(p-&gt;pSrc-&gt;pBt-&gt;mutex) );
-    if( !isFatalError(p-&gt;rc) &amp;&amp; iPage&lt;p-&gt;iNext ){
-      /* The backup process p has already copied page iPage. But now it
-      ** has been modified by a transaction on the source pager. Copy
-      ** the new data into the backup.
-      */
-      int rc = backupOnePage(p, iPage, aData);
-      assert( rc!=SQLITE_BUSY &amp;&amp; rc!=SQLITE_LOCKED );
-      if( rc!=SQLITE_OK ){
-        p-&gt;rc = rc;
-      }
-    }
-  }
-}
-
-/*
-** Restart the backup process. This is called when the pager layer
-** detects that the database has been modified by an external database
-** connection. In this case there is no way of knowing which of the
-** pages that have been copied into the destination database are still 
-** valid and which are not, so the entire process needs to be restarted.
-**
-** It is assumed that the mutex associated with the BtShared object
-** corresponding to the source database is held when this function is
-** called.
-*/
-SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *pBackup){
-  sqlite3_backup *p;                   /* Iterator variable */
-  for(p=pBackup; p; p=p-&gt;pNext){
-    assert( sqlite3_mutex_held(p-&gt;pSrc-&gt;pBt-&gt;mutex) );
-    p-&gt;iNext = 1;
-  }
-}
-
-#ifndef SQLITE_OMIT_VACUUM
-/*
-** Copy the complete content of pBtFrom into pBtTo.  A transaction
-** must be active for both files.
-**
-** The size of file pTo may be reduced by this operation. If anything 
-** goes wrong, the transaction on pTo is rolled back. If successful, the 
-** transaction is committed before returning.
-*/
-SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
-  int rc;
-  sqlite3_backup b;
-  sqlite3BtreeEnter(pTo);
-  sqlite3BtreeEnter(pFrom);
-
-  /* Set up an sqlite3_backup object. sqlite3_backup.pDestDb must be set
-  ** to 0. This is used by the implementations of sqlite3_backup_step()
-  ** and sqlite3_backup_finish() to detect that they are being called
-  ** from this function, not directly by the user.
-  */
-  memset(&amp;b, 0, sizeof(b));
-  b.pSrcDb = pFrom-&gt;db;
-  b.pSrc = pFrom;
-  b.pDest = pTo;
-  b.iNext = 1;
-
-  /* 0x7FFFFFFF is the hard limit for the number of pages in a database
-  ** file. By passing this as the number of pages to copy to
-  ** sqlite3_backup_step(), we can guarantee that the copy finishes 
-  ** within a single call (unless an error occurs). The assert() statement
-  ** checks this assumption - (p-&gt;rc) should be set to either SQLITE_DONE 
-  ** or an error code.
-  */
-  sqlite3_backup_step(&amp;b, 0x7FFFFFFF);
-  assert( b.rc!=SQLITE_OK );
-  rc = sqlite3_backup_finish(&amp;b);
-  if( rc==SQLITE_OK ){
-    pTo-&gt;pBt-&gt;pageSizeFixed = 0;
-  }
-
-  sqlite3BtreeLeave(pFrom);
-  sqlite3BtreeLeave(pTo);
-  return rc;
-}
-#endif /* SQLITE_OMIT_VACUUM */
-
-/************** End of backup.c **********************************************/
 /************** Begin file vdbemem.c *****************************************/
 /*
 ** 2004 May 26
@@ -45391,7 +43752,7 @@ SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
 ** only within the VDBE.  Interface routines refer to a Mem using the
 ** name sqlite_value
 **
-** $Id: vdbemem.c,v 1.137 2009/02/04 03:59:25 shane Exp $
+** $Id: vdbemem.c,v 1.134 2009/01/05 22:30:39 drh Exp $
 */
 
 /*
@@ -45747,20 +44108,17 @@ SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){
   }else if( pMem-&gt;flags &amp; MEM_Int ){
     return (double)pMem-&gt;u.i;
   }else if( pMem-&gt;flags &amp; (MEM_Str|MEM_Blob) ){
-    /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
-    double val = (double)0;
+    double val = 0.0;
     pMem-&gt;flags |= MEM_Str;
     if( sqlite3VdbeChangeEncoding(pMem, SQLITE_UTF8)
        || sqlite3VdbeMemNulTerminate(pMem) ){
-      /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
-      return (double)0;
+      return 0.0;
     }
     assert( pMem-&gt;z );
     sqlite3AtoF(pMem-&gt;z, &amp;val);
     return val;
   }else{
-    /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
-    return (double)0;
+    return 0.0;
   }
 }
 
@@ -46246,6 +44604,55 @@ SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(
   return rc;
 }
 
+#if 0
+/*
+** Perform various checks on the memory cell pMem. An assert() will
+** fail if pMem is internally inconsistent.
+*/
+SQLITE_PRIVATE void sqlite3VdbeMemSanity(Mem *pMem){
+  int flags = pMem-&gt;flags;
+  assert( flags!=0 );  /* Must define some type */
+  if( flags &amp; (MEM_Str|MEM_Blob) ){
+    int x = flags &amp; (MEM_Static|MEM_Dyn|MEM_Ephem|MEM_Short);
+    assert( x!=0 );            /* Strings must define a string subtype */
+    assert( (x &amp; (x-1))==0 );  /* Only one string subtype can be defined */
+    assert( pMem-&gt;z!=0 );      /* Strings must have a value */
+    /* Mem.z points to Mem.zShort iff the subtype is MEM_Short */
+    assert( (x &amp; MEM_Short)==0 || pMem-&gt;z==pMem-&gt;zShort );
+    assert( (x &amp; MEM_Short)!=0 || pMem-&gt;z!=pMem-&gt;zShort );
+    /* No destructor unless there is MEM_Dyn */
+    assert( pMem-&gt;xDel==0 || (pMem-&gt;flags &amp; MEM_Dyn)!=0 );
+
+    if( (flags &amp; MEM_Str) ){
+      assert( pMem-&gt;enc==SQLITE_UTF8 || 
+              pMem-&gt;enc==SQLITE_UTF16BE ||
+              pMem-&gt;enc==SQLITE_UTF16LE 
+      );
+      /* If the string is UTF-8 encoded and nul terminated, then pMem-&gt;n
+      ** must be the length of the string.  (Later:)  If the database file
+      ** has been corrupted, '\000' characters might have been inserted
+      ** into the middle of the string.  In that case, the sqlite3Strlen30()
+      ** might be less.
+      */
+      if( pMem-&gt;enc==SQLITE_UTF8 &amp;&amp; (flags &amp; MEM_Term) ){ 
+        assert( sqlite3Strlen30(pMem-&gt;z)&lt;=pMem-&gt;n );
+        assert( pMem-&gt;z[pMem-&gt;n]==0 );
+      }
+    }
+  }else{
+    /* Cannot define a string subtype for non-string objects */
+    assert( (pMem-&gt;flags &amp; (MEM_Static|MEM_Dyn|MEM_Ephem|MEM_Short))==0 );
+    assert( pMem-&gt;xDel==0 );
+  }
+  /* MEM_Null excludes all other types */
+  assert( (pMem-&gt;flags&amp;(MEM_Str|MEM_Int|MEM_Real|MEM_Blob))==0
+          || (pMem-&gt;flags&amp;MEM_Null)==0 );
+  /* If the MEM is both real and integer, the values are equal */
+  assert( (pMem-&gt;flags &amp; (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) 
+          || pMem-&gt;r==pMem-&gt;u.i );
+}
+#endif
+
 /* This function is only available internally, it is not part of the
 ** external API. It works in a similar way to sqlite3_value_text(),
 ** except the data returned is in the encoding specified by the second
@@ -46346,8 +44753,7 @@ SQLITE_PRIVATE int sqlite3ValueFromExpr(
   }else if( op==TK_UMINUS ) {
     if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr-&gt;pLeft,enc,affinity,&amp;pVal) ){
       pVal-&gt;u.i = -1 * pVal-&gt;u.i;
-      /* (double)-1 In case of SQLITE_OMIT_FLOATING_POINT... */
-      pVal-&gt;r = (double)-1 * pVal-&gt;r;
+      pVal-&gt;r = -1.0 * pVal-&gt;r;
     }
   }
 #ifndef SQLITE_OMIT_BLOB_LITERAL
@@ -46433,7 +44839,7 @@ SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value *pVal, u8 enc){
 ** to version 2.8.7, all this code was combined into the vdbe.c source file.
 ** But that file was getting too big so this subroutines were split out.
 **
-** $Id: vdbeaux.c,v 1.435 2009/02/03 16:51:25 danielk1977 Exp $
+** $Id: vdbeaux.c,v 1.430 2009/01/07 08:12:16 danielk1977 Exp $
 */
 
 
@@ -47379,7 +45785,7 @@ SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe *p){
   pOp = &amp;p-&gt;aOp[0];
   if( pOp-&gt;opcode==OP_Trace &amp;&amp; pOp-&gt;p4.z!=0 ){
     const char *z = pOp-&gt;p4.z;
-    while( sqlite3Isspace(*z) ) z++;
+    while( isspace(*(u8*)z) ) z++;
     printf(&quot;SQL: [%s]\n&quot;, z);
   }
 }
@@ -47399,9 +45805,9 @@ SQLITE_PRIVATE void sqlite3VdbeIOTraceSql(Vdbe *p){
     int i, j;
     char z[1000];
     sqlite3_snprintf(sizeof(z), z, &quot;%s&quot;, pOp-&gt;p4.z);
-    for(i=0; sqlite3Isspace(z[i]); i++){}
+    for(i=0; isspace((unsigned char)z[i]); i++){}
     for(j=0; z[i]; i++){
-      if( sqlite3Isspace(z[i]) ){
+      if( isspace((unsigned char)z[i]) ){
         if( z[i-1]!=' ' ){
           z[j++] = ' ';
         }
@@ -47715,7 +46121,7 @@ static int vdbeCommit(sqlite3 *db, Vdbe *p){
   if( 0==sqlite3Strlen30(sqlite3BtreeGetFilename(db-&gt;aDb[0].pBt))
    || nTrans&lt;=1
   ){
-    for(i=0; rc==SQLITE_OK &amp;&amp; i&lt;db-&gt;nDb; i++){
+    for(i=0; rc==SQLITE_OK &amp;&amp; i&lt;db-&gt;nDb; i++){ 
       Btree *pBt = db-&gt;aDb[i].pBt;
       if( pBt ){
         rc = sqlite3BtreeCommitPhaseOne(pBt, 0);
@@ -47804,10 +46210,10 @@ static int vdbeCommit(sqlite3 *db, Vdbe *p){
     /* Sync the master journal file. If the IOCAP_SEQUENTIAL device
     ** flag is set this is not required.
     */
-    if( needSync 
-     &amp;&amp; 0==(sqlite3OsDeviceCharacteristics(pMaster)&amp;SQLITE_IOCAP_SEQUENTIAL)
-     &amp;&amp; SQLITE_OK!=(rc = sqlite3OsSync(pMaster, SQLITE_SYNC_NORMAL))
-    ){
+    zMainFile = sqlite3BtreeGetDirname(db-&gt;aDb[0].pBt);
+    if( (needSync 
+     &amp;&amp; (0==(sqlite3OsDeviceCharacteristics(pMaster)&amp;SQLITE_IOCAP_SEQUENTIAL))
+     &amp;&amp; (rc=sqlite3OsSync(pMaster, SQLITE_SYNC_NORMAL))!=SQLITE_OK) ){
       sqlite3OsCloseFree(pMaster);
       sqlite3OsDelete(pVfs, zMaster, 0);
       sqlite3DbFree(db, zMaster);
@@ -48977,7 +47383,7 @@ SQLITE_PRIVATE sqlite3 *sqlite3VdbeDb(Vdbe *v){
 ** This file contains code use to implement APIs that are part of the
 ** VDBE.
 **
-** $Id: vdbeapi.c,v 1.151 2009/02/04 03:59:25 shane Exp $
+** $Id: vdbeapi.c,v 1.150 2008/12/10 18:03:47 drh Exp $
 */
 
 #if 0 &amp;&amp; defined(SQLITE_ENABLE_MEMORY_MANAGEMENT)
@@ -49714,8 +48120,7 @@ static Mem *columnMem(sqlite3_stmt *pStmt, int i){
     vals = sqlite3_data_count(pStmt);
     pOut = &amp;pVm-&gt;pResultSet[i];
   }else{
-    /* ((double)0) In case of SQLITE_OMIT_FLOATING_POINT... */
-    static const Mem nullMem = {{0}, (double)0, 0, &quot;&quot;, 0, MEM_Null, SQLITE_NULL, 0, 0, 0 };
+    static const Mem nullMem = {{0}, 0.0, 0, &quot;&quot;, 0, MEM_Null, SQLITE_NULL, 0, 0, 0 };
     if( pVm-&gt;db ){
       sqlite3_mutex_enter(pVm-&gt;db-&gt;mutex);
       sqlite3Error(pVm-&gt;db, SQLITE_RANGE, 0);
@@ -50319,7 +48724,7 @@ SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){
 ** in this file for details.  If in doubt, do not deviate from existing
 ** commenting and indentation practices when changing or adding code.
 **
-** $Id: vdbe.c,v 1.817 2009/02/16 17:55:47 shane Exp $
+** $Id: vdbe.c,v 1.811 2009/01/14 00:55:10 drh Exp $
 */
 
 /*
@@ -51593,8 +49998,7 @@ case OP_Remainder: {           /* same as TK_REM, in1, in2, out3 */
       case OP_Subtract:    b -= a;       break;
       case OP_Multiply:    b *= a;       break;
       case OP_Divide: {
-        /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
-        if( a==(double)0 ) goto arithmetic_result_is_null;
+        if( a==0.0 ) goto arithmetic_result_is_null;
         b /= a;
         break;
       }
@@ -52239,7 +50643,7 @@ case OP_IfNot: {            /* jump, in1 */
     c = pOp-&gt;p3;
   }else{
 #ifdef SQLITE_OMIT_FLOATING_POINT
-    c = sqlite3VdbeIntValue(pIn1)!=0;
+    c = sqlite3VdbeIntValue(pIn1);
 #else
     c = sqlite3VdbeRealValue(pIn1)!=0.0;
 #endif
@@ -53855,7 +52259,7 @@ case OP_NewRowid: {           /* out2-prerelease */
     ** larger than the previous rowid.  This has been shown experimentally
     ** to double the speed of the COPY operation.
     */
-    int res=0, rx=SQLITE_OK, cnt;
+    int res, rx=SQLITE_OK, cnt;
     i64 x;
     cnt = 0;
     if( (sqlite3BtreeFlags(pC-&gt;pCursor)&amp;(BTREE_INTKEY|BTREE_ZERODATA)) !=
@@ -54079,7 +52483,7 @@ case OP_Insert: {
 */
 case OP_Delete: {
   int i = pOp-&gt;p1;
-  i64 iKey = 0;
+  i64 iKey;
   VdbeCursor *pC;
 
   assert( i&gt;=0 &amp;&amp; i&lt;p-&gt;nCursor );
@@ -54390,7 +52794,7 @@ case OP_Next: {        /* jump */
 /* Opcode: IdxInsert P1 P2 P3 * *
 **
 ** Register P2 holds a SQL index key made using the
-** MakeRecord instructions.  This opcode writes that key
+** MakeIdxRec instructions.  This opcode writes that key
 ** into the index P1.  Data for the entry is nil.
 **
 ** P3 is a flag that provides a hint to the b-tree layer that this
@@ -54457,7 +52861,7 @@ case OP_IdxDelete: {
 ** 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: Rowid, MakeRecord.
+** See also: Rowid, MakeIdxRec.
 */
 case OP_IdxRowid: {              /* out2-prerelease */
   int i = pOp-&gt;p1;
@@ -56065,7 +54469,7 @@ SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *pBlob){
 **
 *************************************************************************
 **
-** @(#) $Id: journal.c,v 1.9 2009/01/20 17:06:27 danielk1977 Exp $
+** @(#) $Id: journal.c,v 1.8 2008/05/01 18:01:47 drh Exp $
 */
 
 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
@@ -56083,7 +54487,7 @@ SQLITE_API int sqlite3_blob_bytes(sqlite3_blob *pBlob){
 **
 **   1) The in-memory representation grows too large for the allocated 
 **      buffer, or
-**   2) The sqlite3JournalCreate() function is called.
+**   2) The xSync() method is called.
 */
 
 
@@ -56149,9 +54553,8 @@ static int jrnlRead(
   JournalFile *p = (JournalFile *)pJfd;
   if( p-&gt;pReal ){
     rc = sqlite3OsRead(p-&gt;pReal, zBuf, iAmt, iOfst);
-  }else if( (iAmt+iOfst)&gt;p-&gt;iSize ){
-    rc = SQLITE_IOERR_SHORT_READ;
   }else{
+    assert( iAmt+iOfst&lt;=p-&gt;iSize );
     memcpy(zBuf, &amp;p-&gt;zBuf[iOfst], iAmt);
   }
   return rc;
@@ -57859,7 +56262,7 @@ SQLITE_PRIVATE void sqlite3ResolveSelectNames(
 ** This file contains routines used for analyzing expressions and
 ** for generating VDBE code that evaluates expressions in SQLite.
 **
-** $Id: expr.c,v 1.411 2009/02/04 03:59:25 shane Exp $
+** $Id: expr.c,v 1.409 2009/01/10 13:24:51 drh Exp $
 */
 
 /*
@@ -59297,7 +57700,7 @@ static char *dup8bytes(Vdbe *v, const char *in){
 */
 static void codeReal(Vdbe *v, const char *z, int n, int negateFlag, int iMem){
   assert( z || v==0 || sqlite3VdbeDb(v)-&gt;mallocFailed );
-  assert( !z || !sqlite3Isdigit(z[n]) );
+  assert( !z || !isdigit(z[n]) );
   UNUSED_PARAMETER(n);
   if( z ){
     double value;
@@ -59331,7 +57734,7 @@ static void codeInteger(Vdbe *v, Expr *pExpr, int negFlag, int iMem){
   }else if( (z = (char*)pExpr-&gt;token.z)!=0 ){
     int i;
     int n = pExpr-&gt;token.n;
-    assert( !sqlite3Isdigit(z[n]) );
+    assert( !isdigit(z[n]) );
     if( sqlite3GetInt32(z, &amp;i) ){
       if( negFlag ) i = -i;
       sqlite3VdbeAddOp2(v, OP_Integer, i, iMem);
@@ -59778,10 +58181,12 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target)
     case TK_UMINUS: {
       Expr *pLeft = pExpr-&gt;pLeft;
       assert( pLeft );
-      if( pLeft-&gt;op==TK_FLOAT ){
-        codeReal(v, (char*)pLeft-&gt;token.z, pLeft-&gt;token.n, 1, target);
-      }else if( pLeft-&gt;op==TK_INTEGER ){
-        codeInteger(v, pLeft, 1, target);
+      if( pLeft-&gt;op==TK_FLOAT || pLeft-&gt;op==TK_INTEGER ){
+        if( pLeft-&gt;op==TK_FLOAT ){
+          codeReal(v, (char*)pLeft-&gt;token.z, pLeft-&gt;token.n, 1, target);
+        }else{
+          codeInteger(v, pLeft, 1, target);
+        }
       }else{
         regFree1 = r1 = sqlite3GetTempReg(pParse);
         sqlite3VdbeAddOp2(v, OP_Integer, 0, r1);
@@ -60944,7 +59349,7 @@ SQLITE_PRIVATE void sqlite3ReleaseTempRange(Parse *pParse, int iReg, int nReg){
 ** This file contains C code routines that used to generate VDBE code
 ** that implements the ALTER TABLE command.
 **
-** $Id: alter.c,v 1.53 2009/02/13 03:43:32 drh Exp $
+** $Id: alter.c,v 1.51 2008/12/10 19:26:22 drh Exp $
 */
 
 /*
@@ -61384,7 +59789,7 @@ SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
   assert( sqlite3BtreeHoldsAllMutexes(db) );
   iDb = sqlite3SchemaToIndex(db, pNew-&gt;pSchema);
   zDb = db-&gt;aDb[iDb].zName;
-  zTab = &amp;pNew-&gt;zName[16];  /* Skip the &quot;sqlite_altertab_&quot; prefix on the name */
+  zTab = pNew-&gt;zName;
   pCol = &amp;pNew-&gt;aCol[pNew-&gt;nCol-1];
   pDflt = pCol-&gt;pDflt;
   pTab = sqlite3FindTable(db, zTab, zDb);
@@ -61443,7 +59848,7 @@ SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
   zCol = sqlite3DbStrNDup(db, (char*)pColDef-&gt;z, pColDef-&gt;n);
   if( zCol ){
     char *zEnd = &amp;zCol[pColDef-&gt;n-1];
-    while( (zEnd&gt;zCol &amp;&amp; *zEnd==';') || sqlite3Isspace(*zEnd) ){
+    while( (zEnd&gt;zCol &amp;&amp; *zEnd==';') || isspace(*(unsigned char *)zEnd) ){
       *zEnd-- = '\0';
     }
     sqlite3NestedParse(pParse, 
@@ -61514,11 +59919,7 @@ SQLITE_PRIVATE void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){
   iDb = sqlite3SchemaToIndex(db, pTab-&gt;pSchema);
 
   /* Put a copy of the Table struct in Parse.pNewTable for the
-  ** sqlite3AddColumn() function and friends to modify.  But modify
-  ** the name by adding an &quot;sqlite_altertab_&quot; prefix.  By adding this
-  ** prefix, we insure that the name will not collide with an existing
-  ** table because user table are not allowed to have the &quot;sqlite_&quot;
-  ** prefix on their name.
+  ** sqlite3AddColumn() function and friends to modify.
   */
   pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
   if( !pNew ) goto exit_begin_add_column;
@@ -61530,7 +59931,7 @@ SQLITE_PRIVATE void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){
   nAlloc = (((pNew-&gt;nCol-1)/8)*8)+8;
   assert( nAlloc&gt;=pNew-&gt;nCol &amp;&amp; nAlloc%8==0 &amp;&amp; nAlloc-pNew-&gt;nCol&lt;8 );
   pNew-&gt;aCol = (Column*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc);
-  pNew-&gt;zName = sqlite3MPrintf(db, &quot;sqlite_altertab_%s&quot;, pTab-&gt;zName);
+  pNew-&gt;zName = sqlite3DbStrDup(db, pTab-&gt;zName);
   if( !pNew-&gt;aCol || !pNew-&gt;zName ){
     db-&gt;mallocFailed = 1;
     goto exit_begin_add_column;
@@ -61574,7 +59975,7 @@ exit_begin_add_column:
 *************************************************************************
 ** This file contains code associated with the ANALYZE command.
 **
-** @(#) $Id: analyze.c,v 1.48 2009/02/13 16:59:53 drh Exp $
+** @(#) $Id: analyze.c,v 1.47 2008/12/10 16:45:51 drh Exp $
 */
 #ifndef SQLITE_OMIT_ANALYZE
 
@@ -61978,15 +60379,10 @@ SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
   /* Load new statistics out of the sqlite_stat1 table */
   zSql = sqlite3MPrintf(db, &quot;SELECT idx, stat FROM %Q.sqlite_stat1&quot;,
                         sInfo.zDatabase);
-  if( zSql==0 ){
-    rc = SQLITE_NOMEM;
-  }else{
-    (void)sqlite3SafetyOff(db);
-    rc = sqlite3_exec(db, zSql, analysisLoader, &amp;sInfo, 0);
-    (void)sqlite3SafetyOn(db);
-    sqlite3DbFree(db, zSql);
-    if( rc==SQLITE_NOMEM ) db-&gt;mallocFailed = 1;
-  }
+  (void)sqlite3SafetyOff(db);
+  rc = sqlite3_exec(db, zSql, analysisLoader, &amp;sInfo, 0);
+  (void)sqlite3SafetyOn(db);
+  sqlite3DbFree(db, zSql);
   return rc;
 }
 
@@ -62008,7 +60404,7 @@ SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
 *************************************************************************
 ** This file contains code used to implement the ATTACH and DETACH commands.
 **
-** $Id: attach.c,v 1.82 2009/02/03 16:51:25 danielk1977 Exp $
+** $Id: attach.c,v 1.81 2008/12/10 16:45:51 drh Exp $
 */
 
 #ifndef SQLITE_OMIT_ATTACH
@@ -62261,7 +60657,7 @@ static void detachFunc(
                      &quot;cannot DETACH database within transaction&quot;);
     goto detach_error;
   }
-  if( sqlite3BtreeIsInReadTrans(pDb-&gt;pBt) || sqlite3BtreeIsInBackup(pDb-&gt;pBt) ){
+  if( sqlite3BtreeIsInReadTrans(pDb-&gt;pBt) ){
     sqlite3_snprintf(sizeof(zErr),zErr, &quot;database %s is locked&quot;, zName);
     goto detach_error;
   }
@@ -62796,7 +61192,7 @@ SQLITE_PRIVATE void sqlite3AuthContextPop(AuthContext *pContext){
 **     COMMIT
 **     ROLLBACK
 **
-** $Id: build.c,v 1.518 2009/02/13 03:43:32 drh Exp $
+** $Id: build.c,v 1.511 2008/12/30 06:24:58 danielk1977 Exp $
 */
 
 /*
@@ -63138,7 +61534,7 @@ static void freeIndex(Index *p){
 ** it is not unlinked from the Table that it indexes.
 ** Unlinking from the Table must be done by the calling function.
 */
-static void sqlite3DeleteIndex(Index *p){
+static void sqliteDeleteIndex(Index *p){
   Index *pOld;
   const char *zName = p-&gt;zName;
 
@@ -63183,8 +61579,8 @@ SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char
 ** if there were schema changes during the transaction or if a
 ** schema-cookie mismatch occurs.
 **
-** If iDb==0 then reset the internal schema tables for all database
-** files.  If iDb&gt;=1 then reset the internal schema for only the
+** If iDb&lt;=0 then reset the internal schema tables for all database
+** files.  If iDb&gt;=2 then reset the internal schema for only the
 ** single file indicated.
 */
 SQLITE_PRIVATE void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){
@@ -63298,7 +61694,7 @@ SQLITE_PRIVATE void sqlite3DeleteTable(Table *pTable){
   for(pIndex = pTable-&gt;pIndex; pIndex; pIndex=pNext){
     pNext = pIndex-&gt;pNext;
     assert( pIndex-&gt;pSchema==pTable-&gt;pSchema );
-    sqlite3DeleteIndex(pIndex);
+    sqliteDeleteIndex(pIndex);
   }
 
 #ifndef SQLITE_OMIT_FOREIGN_KEY
@@ -63394,41 +61790,31 @@ SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *p, int iDb){
 }
 
 /*
-** Parameter zName points to a nul-terminated buffer containing the name
-** of a database (&quot;main&quot;, &quot;temp&quot; or the name of an attached db). This
-** function returns the index of the named database in db-&gt;aDb[], or
-** -1 if the named db cannot be found.
+** The token *pName contains the name of a database (either &quot;main&quot; or
+** &quot;temp&quot; or the name of an attached db). This routine returns the
+** index of the named database in db-&gt;aDb[], or -1 if the named db 
+** does not exist.
 */
-SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *db, const char *zName){
-  int i = -1;         /* Database number */
+SQLITE_PRIVATE int sqlite3FindDb(sqlite3 *db, Token *pName){
+  int i = -1;    /* Database number */
+  int n;         /* Number of characters in the name */
+  Db *pDb;       /* A database whose name space is being searched */
+  char *zName;   /* Name we are searching for */
+
+  zName = sqlite3NameFromToken(db, pName);
   if( zName ){
-    Db *pDb;
-    int n = sqlite3Strlen30(zName);
+    n = sqlite3Strlen30(zName);
     for(i=(db-&gt;nDb-1), pDb=&amp;db-&gt;aDb[i]; i&gt;=0; i--, pDb--){
       if( (!OMIT_TEMPDB || i!=1 ) &amp;&amp; n==sqlite3Strlen30(pDb-&gt;zName) &amp;&amp; 
           0==sqlite3StrICmp(pDb-&gt;zName, zName) ){
         break;
       }
     }
+    sqlite3DbFree(db, zName);
   }
   return i;
 }
 
-/*
-** The token *pName contains the name of a database (either &quot;main&quot; or
-** &quot;temp&quot; or the name of an attached db). This routine returns the
-** index of the named database in db-&gt;aDb[], or -1 if the named db 
-** does not exist.
-*/
-SQLITE_PRIVATE int sqlite3FindDb(sqlite3 *db, Token *pName){
-  int i;                               /* Database number */
-  char *zName;                         /* Name we are searching for */
-  zName = sqlite3NameFromToken(db, pName);
-  i = sqlite3FindDbName(db, zName);
-  sqlite3DbFree(db, zName);
-  return i;
-}
-
 /* The table or view or trigger name is passed to this routine via tokens
 ** pName1 and pName2. If the table name was fully qualified, for example:
 **
@@ -64121,9 +62507,9 @@ static void identPut(char *z, int *pIdx, char *zSignedIdent){
   int i, j, needQuote;
   i = *pIdx;
   for(j=0; zIdent[j]; j++){
-    if( !sqlite3Isalnum(zIdent[j]) &amp;&amp; zIdent[j]!='_' ) break;
+    if( !isalnum(zIdent[j]) &amp;&amp; zIdent[j]!='_' ) break;
   }
-  needQuote =  zIdent[j]!=0 || sqlite3Isdigit(zIdent[0])
+  needQuote =  zIdent[j]!=0 || isdigit(zIdent[0])
                   || sqlite3KeywordCode(zIdent, j)!=TK_ID;
   if( needQuote ) z[i++] = '&quot;';
   for(j=0; zIdent[j]; j++){
@@ -64140,7 +62526,7 @@ static void identPut(char *z, int *pIdx, char *zSignedIdent){
 ** table.  Memory to hold the text of the statement is obtained
 ** from sqliteMalloc() and must be freed by the calling function.
 */
-static char *createTableStmt(sqlite3 *db, Table *p){
+static char *createTableStmt(sqlite3 *db, Table *p, int isTemp){
   int i, k, n;
   char *zStmt;
   char *zSep, *zSep2, *zEnd, *z;
@@ -64169,7 +62555,8 @@ static char *createTableStmt(sqlite3 *db, Table *p){
     db-&gt;mallocFailed = 1;
     return 0;
   }
-  sqlite3_snprintf(n, zStmt, &quot;CREATE TABLE &quot;);
+  sqlite3_snprintf(n, zStmt,
+                  !OMIT_TEMPDB&amp;&amp;isTemp ? &quot;CREATE TEMP TABLE &quot;:&quot;CREATE TABLE &quot;);
   k = sqlite3Strlen30(zStmt);
   identPut(zStmt, &amp;k, p-&gt;zName);
   zStmt[k++] = '(';
@@ -64334,7 +62721,7 @@ SQLITE_PRIVATE void sqlite3EndTable(
 
     /* Compute the complete text of the CREATE statement */
     if( pSelect ){
-      zStmt = createTableStmt(db, p);
+      zStmt = createTableStmt(db, p, p-&gt;pSchema==db-&gt;aDb[1].pSchema);
     }else{
       n = (int)(pEnd-&gt;z - pParse-&gt;sNameToken.z) + 1;
       zStmt = sqlite3MPrintf(db, 
@@ -64493,7 +62880,7 @@ SQLITE_PRIVATE void sqlite3CreateView(
   sEnd.n = 0;
   n = (int)(sEnd.z - pBegin-&gt;z);
   z = (const unsigned char*)pBegin-&gt;z;
-  while( n&gt;0 &amp;&amp; (z[n-1]==';' || sqlite3Isspace(z[n-1])) ){ n--; }
+  while( n&gt;0 &amp;&amp; (z[n-1]==';' || isspace(z[n-1])) ){ n--; }
   sEnd.z = &amp;z[n-1];
   sEnd.n = 1;
 
@@ -65201,8 +63588,7 @@ SQLITE_PRIVATE void sqlite3CreateIndex(
   pDb = &amp;db-&gt;aDb[iDb];
 
   if( pTab==0 || pParse-&gt;nErr ) goto exit_create_index;
-  if( sqlite3StrNICmp(pTab-&gt;zName, &quot;sqlite_&quot;, 7)==0 
-       &amp;&amp; memcmp(&amp;pTab-&gt;zName[7],&quot;altertab_&quot;,9)!=0 ){
+  if( sqlite3StrNICmp(pTab-&gt;zName, &quot;sqlite_&quot;, 7)==0 ){
     sqlite3ErrorMsg(pParse, &quot;table %s may not be indexed&quot;, pTab-&gt;zName);
     goto exit_create_index;
   }
@@ -66204,6 +64590,11 @@ SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *pParse, int iDb){
 ** rollback the whole transaction.  For operations where all constraints
 ** can be checked before any changes are made to the database, it is never
 ** necessary to undo a write and the checkpoint should not be set.
+**
+** Only database iDb and the temp database are made writable by this call.
+** If iDb==0, then the main and temp databases are made writable.   If
+** iDb==1 then only the temp database is made writable.  If iDb&gt;1 then the
+** specified auxiliary database and the temp database are made writable.
 */
 SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse *pParse, int setStatement, int iDb){
   Vdbe *v = sqlite3GetVdbe(pParse);
@@ -66213,6 +64604,9 @@ SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse *pParse, int setStatement,
   if( setStatement &amp;&amp; pParse-&gt;nested==0 ){
     sqlite3VdbeAddOp1(v, OP_Statement, iDb);
   }
+  if( (OMIT_TEMPDB || iDb!=1) &amp;&amp; pParse-&gt;db-&gt;aDb[1].pBt!=0 ){
+    sqlite3BeginWriteOperation(pParse, setStatement, 1);
+  }
 }
 
 /*
@@ -66397,7 +64791,7 @@ SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *pParse, Index *pIdx){
 ** This file contains functions used to access the internal hash tables
 ** of user defined functions and collation sequences.
 **
-** $Id: callback.c,v 1.35 2009/01/31 22:28:49 drh Exp $
+** $Id: callback.c,v 1.34 2008/12/10 21:19:57 drh Exp $
 */
 
 
@@ -66611,9 +65005,8 @@ SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(
 ** that uses encoding enc. The value returned indicates how well the
 ** request is matched. A higher value indicates a better match.
 **
-** The returned value is always between 0 and 6, as follows:
+** The returned value is always between 1 and 6, as follows:
 **
-** 0: Not a match, or if nArg&lt;0 and the function is has no implementation.
 ** 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
@@ -66628,9 +65021,7 @@ SQLITE_PRIVATE CollSeq *sqlite3FindCollSeq(
 */
 static int matchQuality(FuncDef *p, int nArg, u8 enc){
   int match = 0;
-  if( p-&gt;nArg==-1 || p-&gt;nArg==nArg 
-   || (nArg==-1 &amp;&amp; (p-&gt;xFunc!=0 || p-&gt;xStep!=0))
-  ){
+  if( p-&gt;nArg==-1 || p-&gt;nArg==nArg || nArg==-1 ){
     match = 1;
     if( p-&gt;nArg==nArg || nArg==-1 ){
       match = 4;
@@ -67488,7 +65879,7 @@ SQLITE_PRIVATE int sqlite3GenerateIndexKey(
 ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
 ** All other code has file scope.
 **
-** $Id: func.c,v 1.222 2009/02/04 03:59:25 shane Exp $
+** $Id: func.c,v 1.209 2008/12/10 23:04:13 drh Exp $
 */
 
 /*
@@ -67511,7 +65902,7 @@ static void minmaxFunc(
   int iBest;
   CollSeq *pColl;
 
-  assert( argc&gt;1 );
+  if( argc==0 ) return;
   mask = sqlite3_user_data(context)==0 ? 0 : -1;
   pColl = sqlite3GetFuncCollSeq(context);
   assert( pColl );
@@ -67521,7 +65912,6 @@ static void minmaxFunc(
   for(i=1; i&lt;argc; i++){
     if( sqlite3_value_type(argv[i])==SQLITE_NULL ) return;
     if( (sqlite3MemCompare(argv[iBest], argv[i], pColl)^mask)&gt;=0 ){
-      testcase( mask==0 );
       iBest = i;
     }
   }
@@ -67539,11 +65929,11 @@ static void typeofFunc(
   const char *z = 0;
   UNUSED_PARAMETER(NotUsed);
   switch( sqlite3_value_type(argv[0]) ){
+    case SQLITE_NULL:    z = &quot;null&quot;;    break;
     case SQLITE_INTEGER: z = &quot;integer&quot;; break;
     case SQLITE_TEXT:    z = &quot;text&quot;;    break;
     case SQLITE_FLOAT:   z = &quot;real&quot;;    break;
     case SQLITE_BLOB:    z = &quot;blob&quot;;    break;
-    default:             z = &quot;null&quot;;    break;
   }
   sqlite3_result_text(context, z, -1, SQLITE_STATIC);
 }
@@ -67638,14 +66028,8 @@ static void substrFunc(
   int len;
   int p0type;
   i64 p1, p2;
-  int negP2 = 0;
 
   assert( argc==3 || argc==2 );
-  if( sqlite3_value_type(argv[1])==SQLITE_NULL
-   || (argc==3 &amp;&amp; sqlite3_value_type(argv[2])==SQLITE_NULL)
-  ){
-    return;
-  }
   p0type = sqlite3_value_type(argv[0]);
   if( p0type==SQLITE_BLOB ){
     len = sqlite3_value_bytes(argv[0]);
@@ -67663,10 +66047,6 @@ static void substrFunc(
   p1 = sqlite3_value_int(argv[1]);
   if( argc==3 ){
     p2 = sqlite3_value_int(argv[2]);
-    if( p2&lt;0 ){
-      p2 = -p2;
-      negP2 = 1;
-    }
   }else{
     p2 = sqlite3_context_db_handle(context)-&gt;aLimit[SQLITE_LIMIT_LENGTH];
   }
@@ -67674,25 +66054,13 @@ static void substrFunc(
     p1 += len;
     if( p1&lt;0 ){
       p2 += p1;
-      if( p2&lt;0 ) p2 = 0;
       p1 = 0;
     }
   }else if( p1&gt;0 ){
     p1--;
-  }else if( p2&gt;0 ){
-    p2--;
   }
-  if( negP2 ){
-    p1 -= p2;
-    if( p1&lt;0 ){
-      p2 += p1;
-      p1 = 0;
-    }
-  }
-  assert( p1&gt;=0 &amp;&amp; p2&gt;=0 );
   if( p1+p2&gt;len ){
     p2 = len-p1;
-    if( p2&lt;0 ) p2 = 0;
   }
   if( p0type!=SQLITE_BLOB ){
     while( *z &amp;&amp; p1 ){
@@ -67704,6 +66072,7 @@ static void substrFunc(
     }
     sqlite3_result_text(context, (char*)z, (int)(z2-z), SQLITE_TRANSIENT);
   }else{
+    if( p2&lt;0 ) p2 = 0;
     sqlite3_result_blob(context, (char*)&amp;z[p1], (int)p2, SQLITE_TRANSIENT);
   }
 }
@@ -67711,7 +66080,6 @@ static void substrFunc(
 /*
 ** Implementation of the round() function
 */
-#ifndef SQLITE_OMIT_FLOATING_POINT
 static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
   int n = 0;
   double r;
@@ -67729,7 +66097,6 @@ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
   sqlite3AtoF(zBuf, &amp;r);
   sqlite3_result_double(context, r);
 }
-#endif
 
 /*
 ** Allocate nByte bytes of space using sqlite3_malloc(). If the
@@ -67757,7 +66124,7 @@ static void upperFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
   char *z1;
   const char *z2;
   int i, n;
-  UNUSED_PARAMETER(argc);
+  if( argc&lt;1 || SQLITE_NULL==sqlite3_value_type(argv[0]) ) return;
   z2 = (char*)sqlite3_value_text(argv[0]);
   n = sqlite3_value_bytes(argv[0]);
   /* Verify that the call to _bytes() does not invalidate the _text() pointer */
@@ -67767,17 +66134,17 @@ static void upperFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
     if( z1 ){
       memcpy(z1, z2, n+1);
       for(i=0; z1[i]; i++){
-        z1[i] = (char)sqlite3Toupper(z1[i]);
+        z1[i] = (char)toupper(z1[i]);
       }
       sqlite3_result_text(context, z1, -1, sqlite3_free);
     }
   }
 }
 static void lowerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
-  u8 *z1;
+  char *z1;
   const char *z2;
   int i, n;
-  UNUSED_PARAMETER(argc);
+  if( argc&lt;1 || SQLITE_NULL==sqlite3_value_type(argv[0]) ) return;
   z2 = (char*)sqlite3_value_text(argv[0]);
   n = sqlite3_value_bytes(argv[0]);
   /* Verify that the call to _bytes() does not invalidate the _text() pointer */
@@ -67787,9 +66154,9 @@ static void lowerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
     if( z1 ){
       memcpy(z1, z2, n+1);
       for(i=0; z1[i]; i++){
-        z1[i] = sqlite3Tolower(z1[i]);
+        z1[i] = (char)tolower(z1[i]);
       }
-      sqlite3_result_text(context, (char *)z1, -1, sqlite3_free);
+      sqlite3_result_text(context, z1, -1, sqlite3_free);
     }
   }
 }
@@ -68178,9 +66545,12 @@ static const char hexdigits[] = {
 ** single-quote escapes.
 */
 static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
-  assert( argc==1 );
-  UNUSED_PARAMETER(argc);
+  if( argc&lt;1 ) return;
   switch( sqlite3_value_type(argv[0]) ){
+    case SQLITE_NULL: {
+      sqlite3_result_text(context, &quot;NULL&quot;, 4, SQLITE_STATIC);
+      break;
+    }
     case SQLITE_INTEGER:
     case SQLITE_FLOAT: {
       sqlite3_result_value(context, argv[0]);
@@ -68228,12 +66598,6 @@ static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
         z[j] = 0;
         sqlite3_result_text(context, z, j, sqlite3_free);
       }
-      break;
-    }
-    default: {
-      assert( sqlite3_value_type(argv[0])==SQLITE_NULL );
-      sqlite3_result_text(context, &quot;NULL&quot;, 4, SQLITE_STATIC);
-      break;
     }
   }
 }
@@ -68315,16 +66679,7 @@ static void replaceFunc(
   nStr = sqlite3_value_bytes(argv[0]);
   assert( zStr==sqlite3_value_text(argv[0]) );  /* No encoding change */
   zPattern = sqlite3_value_text(argv[1]);
-  if( zPattern==0 ){
-    assert( sqlite3_value_type(argv[1])==SQLITE_NULL
-            || sqlite3_context_db_handle(context)-&gt;mallocFailed );
-    return;
-  }
-  if( zPattern[0]==0 ){
-    assert( sqlite3_value_type(argv[1])!=SQLITE_NULL );
-    sqlite3_result_value(context, argv[0]);
-    return;
-  }
+  if( zPattern==0 || zPattern[0]==0 ) return;
   nPattern = sqlite3_value_bytes(argv[1]);
   assert( zPattern==sqlite3_value_text(argv[1]) );  /* No encoding change */
   zRep = sqlite3_value_text(argv[2]);
@@ -68480,10 +66835,10 @@ static void soundexFunc(
   assert( argc==1 );
   zIn = (u8*)sqlite3_value_text(argv[0]);
   if( zIn==0 ) zIn = (u8*)&quot;&quot;;
-  for(i=0; zIn[i] &amp;&amp; !sqlite3Isalpha(zIn[i]); i++){}
+  for(i=0; zIn[i] &amp;&amp; !isalpha(zIn[i]); i++){}
   if( zIn[i] ){
     u8 prevcode = iCode[zIn[i]&amp;0x7f];
-    zResult[0] = sqlite3Toupper(zIn[i]);
+    zResult[0] = toupper(zIn[i]);
     for(j=1; j&lt;4 &amp;&amp; zIn[i]; i++){
       int code = iCode[zIn[i]&amp;0x7f];
       if( code&gt;0 ){
@@ -68601,8 +66956,7 @@ static void avgFinalize(sqlite3_context *context){
 static void totalFinalize(sqlite3_context *context){
   SumCtx *p;
   p = sqlite3_aggregate_context(context, 0);
-  /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
-  sqlite3_result_double(context, p ? p-&gt;rSum : (double)0);
+  sqlite3_result_double(context, p ? p-&gt;rSum : 0.0);
 }
 
 /*
@@ -68689,9 +67043,8 @@ static void groupConcatStep(
   const char *zVal;
   StrAccum *pAccum;
   const char *zSep;
-  int nVal, nSep;
-  assert( argc==1 || argc==2 );
-  if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
+  int nVal, nSep, i;
+  if( argc==0 || sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
   pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum));
 
   if( pAccum ){
@@ -68699,18 +67052,22 @@ static void groupConcatStep(
     pAccum-&gt;useMalloc = 1;
     pAccum-&gt;mxAlloc = db-&gt;aLimit[SQLITE_LIMIT_LENGTH];
     if( pAccum-&gt;nChar ){
-      if( argc==2 ){
-        zSep = (char*)sqlite3_value_text(argv[1]);
-        nSep = sqlite3_value_bytes(argv[1]);
+      if( argc&gt;1 ){
+        zSep = (char*)sqlite3_value_text(argv[argc-1]);
+        nSep = sqlite3_value_bytes(argv[argc-1]);
       }else{
         zSep = &quot;,&quot;;
         nSep = 1;
       }
       sqlite3StrAccumAppend(pAccum, zSep, nSep);
     }
-    zVal = (char*)sqlite3_value_text(argv[0]);
-    nVal = sqlite3_value_bytes(argv[0]);
-    sqlite3StrAccumAppend(pAccum, zVal, nVal);
+    i = 0;
+    do{
+      zVal = (char*)sqlite3_value_text(argv[i]);
+      nVal = sqlite3_value_bytes(argv[i]);
+      sqlite3StrAccumAppend(pAccum, zVal, nVal);
+      i++;
+    }while( i&lt;argc-1 );
   }
 }
 static void groupConcatFinalize(sqlite3_context *context){
@@ -68849,10 +67206,8 @@ SQLITE_PRIVATE void sqlite3RegisterGlobalFunctions(void){
     FUNCTION(substr,             2, 0, 0, substrFunc       ),
     FUNCTION(substr,             3, 0, 0, substrFunc       ),
     FUNCTION(abs,                1, 0, 0, absFunc          ),
-#ifndef SQLITE_OMIT_FLOATING_POINT
     FUNCTION(round,              1, 0, 0, roundFunc        ),
     FUNCTION(round,              2, 0, 0, roundFunc        ),
-#endif
     FUNCTION(upper,              1, 0, 0, upperFunc        ),
     FUNCTION(lower,              1, 0, 0, lowerFunc        ),
     FUNCTION(coalesce,           1, 0, 0, 0                ),
@@ -68860,7 +67215,7 @@ SQLITE_PRIVATE void sqlite3RegisterGlobalFunctions(void){
     FUNCTION(coalesce,           0, 0, 0, 0                ),
     FUNCTION(hex,                1, 0, 0, hexFunc          ),
     FUNCTION(ifnull,             2, 0, 1, ifnullFunc       ),
-    FUNCTION(random,             0, 0, 0, randomFunc       ),
+    FUNCTION(random,            -1, 0, 0, randomFunc       ),
     FUNCTION(randomblob,         1, 0, 0, randomBlob       ),
     FUNCTION(nullif,             2, 0, 1, nullifFunc       ),
     FUNCTION(sqlite_version,     0, 0, 0, versionFunc      ),
@@ -68882,8 +67237,7 @@ SQLITE_PRIVATE void sqlite3RegisterGlobalFunctions(void){
     AGGREGATE(avg,               1, 0, 0, sumStep,         avgFinalize    ),
     AGGREGATE(count,             0, 0, 0, countStep,       countFinalize  ),
     AGGREGATE(count,             1, 0, 0, countStep,       countFinalize  ),
-    AGGREGATE(group_concat,      1, 0, 0, groupConcatStep, groupConcatFinalize),
-    AGGREGATE(group_concat,      2, 0, 0, groupConcatStep, groupConcatFinalize),
+    AGGREGATE(group_concat,     -1, 0, 0, groupConcatStep, groupConcatFinalize),
   
     LIKEFUNC(glob, 2, &amp;globInfo, SQLITE_FUNC_LIKE|SQLITE_FUNC_CASE),
   #ifdef SQLITE_CASE_SENSITIVE_LIKE
@@ -70662,7 +69016,7 @@ static int xferOptimization(
 ** other files are for internal use by SQLite and should not be
 ** accessed by users of the library.
 **
-** $Id: legacy.c,v 1.31 2009/01/20 16:53:40 danielk1977 Exp $
+** $Id: legacy.c,v 1.30 2008/12/10 19:26:24 drh Exp $
 */
 
 
@@ -70761,7 +69115,7 @@ SQLITE_API int sqlite3_exec(
         if( rc!=SQLITE_SCHEMA ){
           nRetry = 0;
           zSql = zLeftover;
-          while( sqlite3Isspace(zSql[0]) ) zSql++;
+          while( isspace((unsigned char)zSql[0]) ) zSql++;
         }
         break;
       }
@@ -70807,7 +69161,7 @@ exec_out:
 ** This file contains code used to dynamically load extensions into
 ** the SQLite library.
 **
-** $Id: loadext.c,v 1.58 2009/01/20 16:53:40 danielk1977 Exp $
+** $Id: loadext.c,v 1.57 2008/12/08 18:19:18 drh Exp $
 */
 
 #ifndef SQLITE_CORE
@@ -71793,7 +70147,7 @@ SQLITE_PRIVATE int sqlite3AutoLoadExtensions(sqlite3 *db){
 *************************************************************************
 ** This file contains code used to implement the PRAGMA command.
 **
-** $Id: pragma.c,v 1.202 2009/01/20 16:53:41 danielk1977 Exp $
+** $Id: pragma.c,v 1.201 2009/01/13 20:14:16 drh Exp $
 */
 
 /* Ignore this whole file if pragmas are disabled
@@ -71817,7 +70171,7 @@ static u8 getSafetyLevel(const char *z){
   static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4};
   static const u8 iValue[] =  {1, 0, 0, 0, 1, 1, 2};
   int i, n;
-  if( sqlite3Isdigit(*z) ){
+  if( isdigit(*z) ){
     return (u8)atoi(z);
   }
   n = sqlite3Strlen30(z);
@@ -73230,7 +71584,7 @@ pragma_out:
 ** interface, and routines that contribute to loading the database schema
 ** from disk.
 **
-** $Id: prepare.c,v 1.105 2009/01/20 16:53:41 danielk1977 Exp $
+** $Id: prepare.c,v 1.104 2009/01/09 02:49:32 drh Exp $
 */
 
 /*
@@ -74041,7 +72395,7 @@ SQLITE_API int sqlite3_prepare16_v2(
 ** This file contains C code routines that are called by the parser
 ** to handle SELECT statements in SQLite.
 **
-** $Id: select.c,v 1.499 2009/02/09 13:19:28 drh Exp $
+** $Id: select.c,v 1.498 2009/01/09 02:49:32 drh Exp $
 */
 
 
@@ -77393,8 +75747,8 @@ static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){
     if( pFunc-&gt;iDistinct&gt;=0 ){
       Expr *pE = pFunc-&gt;pExpr;
       if( pE-&gt;pList==0 || pE-&gt;pList-&gt;nExpr!=1 ){
-        sqlite3ErrorMsg(pParse, &quot;DISTINCT aggregates must have exactly one &quot;
-           &quot;argument&quot;);
+        sqlite3ErrorMsg(pParse, &quot;DISTINCT in aggregate must be followed &quot;
+           &quot;by an expression&quot;);
         pFunc-&gt;iDistinct = -1;
       }else{
         KeyInfo *pKeyInfo = keyInfoFromExprList(pParse, pE-&gt;pList);
@@ -78231,7 +76585,7 @@ SQLITE_PRIVATE void sqlite3PrintSelect(Select *p, int indent){
 ** These routines are in a separate files so that they will not be linked
 ** if they are not used.
 **
-** $Id: table.c,v 1.39 2009/01/19 20:49:10 drh Exp $
+** $Id: table.c,v 1.38 2008/12/10 19:26:24 drh Exp $
 */
 
 #ifndef SQLITE_OMIT_GET_TABLE
@@ -78344,7 +76698,6 @@ SQLITE_API int sqlite3_get_table(
   *pazResult = 0;
   if( pnColumn ) *pnColumn = 0;
   if( pnRow ) *pnRow = 0;
-  if( pzErrMsg ) *pzErrMsg = 0;
   res.zErrMsg = 0;
   res.nResult = 0;
   res.nRow = 0;
@@ -79975,7 +78328,7 @@ static void updateVirtualTable(
 ** Most of the code in this file may be omitted by defining the
 ** SQLITE_OMIT_VACUUM macro.
 **
-** $Id: vacuum.c,v 1.86 2009/02/03 16:51:25 danielk1977 Exp $
+** $Id: vacuum.c,v 1.84 2008/11/17 19:18:55 danielk1977 Exp $
 */
 
 #if !defined(SQLITE_OMIT_VACUUM) &amp;&amp; !defined(SQLITE_OMIT_ATTACH)
@@ -80050,17 +78403,17 @@ SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
   int isMemDb;            /* True is vacuuming a :memory: database */
   int nRes;
 
-  if( !db-&gt;autoCommit ){
-    sqlite3SetString(pzErrMsg, db, &quot;cannot VACUUM from within a transaction&quot;);
-    return SQLITE_ERROR;
-  }
-
   /* Save the current value of the write-schema flag before setting it. */
   saved_flags = db-&gt;flags;
   saved_nChange = db-&gt;nChange;
   saved_nTotalChange = db-&gt;nTotalChange;
   db-&gt;flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks;
 
+  if( !db-&gt;autoCommit ){
+    sqlite3SetString(pzErrMsg, db, &quot;cannot VACUUM from within a transaction&quot;);
+    rc = SQLITE_ERROR;
+    goto end_of_vacuum;
+  }
   pMain = db-&gt;aDb[0].pBt;
   pMainPager = sqlite3BtreePager(pMain);
   isMemDb = sqlite3PagerFile(pMainPager)-&gt;pMethods==0;
@@ -80224,6 +78577,7 @@ SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
 #ifndef SQLITE_OMIT_AUTOVACUUM
     sqlite3BtreeSetAutoVacuum(pMain, sqlite3BtreeGetAutoVacuum(pTemp));
 #endif
+    rc = sqlite3BtreeCommit(pMain);
   }
 
   if( rc==SQLITE_OK ){
@@ -81122,7 +79476,7 @@ SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse *pParse, Table *pTab){
 ** so is applicable.  Because this module is responsible for selecting
 ** indices, you might also think of this module as the &quot;query optimizer&quot;.
 **
-** $Id: where.c,v 1.368 2009/02/04 03:59:25 shane Exp $
+** $Id: where.c,v 1.364 2009/01/14 00:55:10 drh Exp $
 */
 
 /*
@@ -81993,7 +80347,7 @@ static void exprAnalyzeOrTerm(
   if( chngToIN ){
     int okToChngToIN = 0;     /* True if the conversion to IN is valid */
     int iColumn = -1;         /* Column index on lhs of IN operator */
-    int iCursor = -1;         /* Table cursor common to all terms */
+    int iCursor;              /* Table cursor common to all terms */
     int j = 0;                /* Loop counter */
 
     /* Search for a table and column that appears on one side or the
@@ -82652,8 +81006,7 @@ static double bestVirtualIndex(
                              + sizeof(*pIdxOrderBy)*nOrderBy );
     if( pIdxInfo==0 ){
       sqlite3ErrorMsg(pParse, &quot;out of memory&quot;);
-      /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
-      return (double)0;
+      return 0.0;
     }
     *ppIdxInfo = pIdxInfo;
 
@@ -82756,8 +81109,7 @@ static double bestVirtualIndex(
   pIdxInfo-&gt;idxNum = 0;
   pIdxInfo-&gt;needToFreeIdxStr = 0;
   pIdxInfo-&gt;orderByConsumed = 0;
-  /* ((double)2) In case of SQLITE_OMIT_FLOATING_POINT... */
-  pIdxInfo-&gt;estimatedCost = SQLITE_BIG_DBL / ((double)2);
+  pIdxInfo-&gt;estimatedCost = SQLITE_BIG_DBL / 2.0;
   nOrderBy = pIdxInfo-&gt;nOrderBy;
   if( pIdxInfo-&gt;nOrderBy &amp;&amp; !orderByUsable ){
     *(int*)&amp;pIdxInfo-&gt;nOrderBy = 0;
@@ -82786,8 +81138,7 @@ static double bestVirtualIndex(
     if( !pIdxInfo-&gt;aConstraint[i].usable &amp;&amp; pUsage[i].argvIndex&gt;0 ){
       sqlite3ErrorMsg(pParse, 
           &quot;table %s: xBestIndex returned an invalid plan&quot;, pTab-&gt;zName);
-      /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
-      return (double)0;
+      return 0.0;
     }
   }
 
@@ -83032,7 +81383,7 @@ static void bestIndex(
         wsFlags |= WHERE_COLUMN_IN;
         if( pExpr-&gt;pSelect!=0 ){
           inMultiplier *= 25;
-        }else if( pExpr-&gt;pList ){
+        }else if( ALWAYS(pExpr-&gt;pList) ){
           inMultiplier *= pExpr-&gt;pList-&gt;nExpr + 1;
         }
       }
@@ -84200,14 +82551,12 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
           sCost.plan.wsFlags = WHERE_VIRTUALTABLE | WHERE_ORDERBY;
         }
         sCost.plan.nEq = 0;
-        /* (double)2 In case of SQLITE_OMIT_FLOATING_POINT... */
-        if( (SQLITE_BIG_DBL/((double)2))&lt;sCost.rCost ){
+        if( (SQLITE_BIG_DBL/2.0)&lt;sCost.rCost ){
           /* The cost is not allowed to be larger than SQLITE_BIG_DBL (the
           ** inital value of lowestCost in this loop. If it is, then
           ** the (cost&lt;lowestCost) test below will never be true.
           */ 
-          /* (double)2 In case of SQLITE_OMIT_FLOATING_POINT... */
-          sCost.rCost = (SQLITE_BIG_DBL/((double)2));
+          sCost.rCost = (SQLITE_BIG_DBL/2.0);
         }
       }else 
 #endif
@@ -84237,7 +82586,7 @@ SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
       pLevel-&gt;iIdxCur = -1;
     }
     notReady &amp;= ~getMask(pMaskSet, pTabList-&gt;a[bestJ].iCursor);
-    pLevel-&gt;iFrom = (u8)bestJ;
+    pLevel-&gt;iFrom = bestJ;
 
     /* Check that if the table scanned by this loop iteration had an
     ** INDEXED BY clause attached to it, that the named index is being
@@ -84639,7 +82988,7 @@ struct AttachKey { int type;  Token key; };
 #define YYCODETYPE unsigned char
 #define YYNOCODE 251
 #define YYACTIONTYPE unsigned short int
-#define YYWILDCARD 64
+#define YYWILDCARD 62
 #define sqlite3ParserTOKENTYPE Token
 typedef union {
   int yyinit;
@@ -84723,364 +83072,364 @@ static const YYMINORTYPE yyzerominor = { 0 };
 **  yy_default[]       Default action for each state.
 */
 static const YYACTIONTYPE yy_action[] = {
- /*     0 */   304,  930,  120,  609,    1,  178,  264,  436,   62,   62,
- /*    10 */    62,   62,  214,   64,   64,   64,   64,   65,   65,   66,
- /*    20 */    66,   66,   67,  216,  593,  467,  336,  174,  443,  449,
- /*    30 */    69,   64,   64,   64,   64,   65,   65,   66,   66,   66,
- /*    40 */    67,  216,  315,  592,  591,  355,   61,   60,  309,  453,
- /*    50 */   454,  450,  450,   63,   63,   62,   62,   62,   62,  216,
- /*    60 */    64,   64,   64,   64,   65,   65,   66,   66,   66,   67,
- /*    70 */   216,  304,  431,  312,  436,  509,  430,   83,   64,   64,
- /*    80 */    64,   64,   65,   65,   66,   66,   66,   67,  216,  406,
- /*    90 */   403,  411,   65,   65,   66,   66,   66,   67,  216,  443,
- /*   100 */   449,  551,  526,   59,  588,  217,  171,   57,  550,  411,
- /*   110 */    68,  428,   70,  155,  610,  406,  403,   61,   60,  309,
- /*   120 */   453,  454,  450,  450,   63,   63,   62,   62,   62,   62,
- /*   130 */   595,   64,   64,   64,   64,   65,   65,   66,   66,   66,
- /*   140 */    67,  216,  304,  228,  414,  415,  416,  312,  469,  170,
- /*   150 */   114,  256,  357,  261,  358,  181,  330,  562,  412,  413,
- /*   160 */   187,  561,  265,  359,  362,  363,  465,  218,  150,  151,
- /*   170 */   443,  449,   95,  153,  364,  376,  412,  413,  510,  432,
- /*   180 */    36,  492,  438,  411,  465,  218,  589,  590,   61,   60,
- /*   190 */   309,  453,  454,  450,  450,   63,   63,   62,   62,   62,
- /*   200 */    62,  649,   64,   64,   64,   64,   65,   65,   66,   66,
- /*   210 */    66,   67,  216,  304,  440,  440,  440,  228,  109,  264,
- /*   220 */   501,  330,  469,  511,  114,  256,  357,  261,  358,  181,
- /*   230 */   330,  247,   68,  480,   70,  155,  265,   68,  552,   70,
- /*   240 */   155,  443,  449,  187,  432,   35,  359,  362,  363,  569,
- /*   250 */   412,  413,  510,  432,   42,  229,  438,  364,  207,   61,
- /*   260 */    60,  309,  453,  454,  450,  450,   63,   63,   62,   62,
- /*   270 */    62,   62,  264,   64,   64,   64,   64,   65,   65,   66,
- /*   280 */    66,   66,   67,  216,  304,  570,  344,  427,  440,  440,
- /*   290 */   440,  354,  433,  346,  221,  539,  325,  408,  411,  387,
- /*   300 */   282,  281,  213,   66,   66,   66,   67,  216,  316,  206,
- /*   310 */   214,  187,  443,  449,  359,  362,  363,  299,  545,    2,
- /*   320 */   467,  543,  174,  411,   68,  364,   70,  155,  569,  384,
- /*   330 */    61,   60,  309,  453,  454,  450,  450,   63,   63,   62,
- /*   340 */    62,   62,   62,  433,   64,   64,   64,   64,   65,   65,
- /*   350 */    66,   66,   66,   67,  216,  465,  304,   68,  544,   70,
- /*   360 */   155,  426,  542,  593,  330,  412,  413,  394,  425,   20,
- /*   370 */   539,  436,  178,  330,  436,  330,  514,  515,  387,  282,
- /*   380 */   281,  198,  592,  241,  443,  449,  248,  432,   50,  214,
- /*   390 */   412,  413,  152,  553,  402,  230,  432,   42,  432,   35,
- /*   400 */   162,   78,   61,   60,  309,  453,  454,  450,  450,   63,
- /*   410 */    63,   62,   62,   62,   62,  433,   64,   64,   64,   64,
- /*   420 */    65,   65,   66,   66,   66,   67,  216,  330,  304,  198,
- /*   430 */   474,  330,  505,  320,  433,  367,  154,  220,  436,  385,
- /*   440 */   348,  436,  544,  397,  217,  475,  163,  161,  411,  240,
- /*   450 */   432,   28,  554,   20,  432,   50,  443,  449,  307,  341,
- /*   460 */   476,  381,  516,  433,  182,  485,  310,  460,  461,   19,
- /*   470 */   433,  145,  517,   81,   61,   60,  309,  453,  454,  450,
- /*   480 */   450,   63,   63,   62,   62,   62,   62,  385,   64,   64,
- /*   490 */    64,   64,   65,   65,   66,   66,   66,   67,  216,  304,
- /*   500 */   321,  504,  353,  508,   17,  457,   77,  330,   79,  388,
- /*   510 */   335,  460,  461,  470,  512,  412,  413,  411,  123,  306,
- /*   520 */   160,  444,  445,  429,  265,  432,    3,  443,  449,  217,
- /*   530 */   432,   29,  377,  564,  349,  607,  921,  380,  921,   67,
- /*   540 */   216,  488,  447,  448,  492,   61,   60,  309,  453,  454,
- /*   550 */   450,  450,   63,   63,   62,   62,   62,   62,  148,   64,
- /*   560 */    64,   64,   64,   65,   65,   66,   66,   66,   67,  216,
- /*   570 */   304,  446,  389,  217,  525,   23,  492,  604,  124,  411,
- /*   580 */   487,  396,  474,  222,  412,  413,  531,  607,  920,  333,
- /*   590 */   920,  456,  456,  333,  411,  456,  456,  475,  443,  449,
- /*   600 */   214,  333,  286,  456,  456,  249,  333,  532,  456,  456,
- /*   610 */   489,  566,  476,  395,  340,  252,   61,   60,  309,  453,
- /*   620 */   454,  450,  450,   63,   63,   62,   62,   62,   62,  604,
- /*   630 */    64,   64,   64,   64,   65,   65,   66,   66,   66,   67,
- /*   640 */   216,  304,  289,  330,  287,  268,  412,  413,  330,  159,
- /*   650 */   853,   21,  330,  503,  330,  436,  330,  257,  330,  314,
- /*   660 */   330,  412,  413,  182,  567,  515,  432,   24,  258,  443,
- /*   670 */   449,  432,   33,  214,  487,  432,   54,  432,   53,  432,
- /*   680 */    99,  432,   97,  432,  102,  270,  386,   61,   60,  309,
- /*   690 */   453,  454,  450,  450,   63,   63,   62,   62,   62,   62,
- /*   700 */   331,   64,   64,   64,   64,   65,   65,   66,   66,   66,
- /*   710 */    67,  216,  304,  330,  560,  374,  560,   94,  306,  330,
- /*   720 */   234,  330,  436,  288,  330,  274,  330,  272,  330,  333,
- /*   730 */   330,  456,  456,  330,  603,  303,  432,  103,  405,    1,
- /*   740 */   443,  449,  432,  108,  432,  110,  492,  432,   16,  432,
- /*   750 */   100,  432,   34,  432,   98,  496,  432,   25,   61,   60,
- /*   760 */   309,  453,  454,  450,  450,   63,   63,   62,   62,   62,
- /*   770 */    62,  330,   64,   64,   64,   64,   65,   65,   66,   66,
- /*   780 */    66,   67,  216,  304,  330,  254,  330,  183,  184,  185,
- /*   790 */   330,  544,  330,  486,  432,   55,  330,  496,  330,  215,
- /*   800 */   330,  600,   20,  330,  410,  384,   56,  432,  111,  432,
- /*   810 */   112,  443,  449,  432,  113,  432,   26,  311,    5,  432,
- /*   820 */    37,  432,   38,  432,   27,  276,  432,   39,  264,   61,
- /*   830 */    60,  309,  453,  454,  450,  450,   63,   63,   62,   62,
- /*   840 */    62,   62,  330,   64,   64,   64,   64,   65,   65,   66,
- /*   850 */    66,   66,   67,  216,  304,  330,  202,  330,  431,  375,
- /*   860 */   420,  330,  430,  330,  317,  432,   40,  277,  330,  487,
- /*   870 */   330,  233,  330,  421,  330,  177,  161,  496,  432,   41,
- /*   880 */   432,   43,  443,  449,  432,   44,  432,   45,  276,  276,
- /*   890 */   433,  432,   30,  432,   31,  432,   46,  432,   47,  264,
- /*   900 */    61,   71,  309,  453,  454,  450,  450,   63,   63,   62,
- /*   910 */    62,   62,   62,  330,   64,   64,   64,   64,   65,   65,
- /*   920 */    66,   66,   66,   67,  216,  304,  330,  276,  330,  276,
- /*   930 */   578,  580,  330,  157,  330,  318,  432,   48,  159,  319,
- /*   940 */   352,  330,  276,  323,  119,  463,  463,  422,  332,  432,
- /*   950 */    49,  432,   32,  443,  449,  432,   10,  432,   51,  276,
- /*   960 */   276,  276,  186,  487,  432,   52,  466,  433,  200,  399,
- /*   970 */   115,  581,   60,  309,  453,  454,  450,  450,   63,   63,
- /*   980 */    62,   62,   62,   62,  582,   64,   64,   64,   64,   65,
- /*   990 */    65,   66,   66,   66,   67,  216,  304,  189,  192,  605,
- /*  1000 */   482,  231,  232,  292,  458,  494,   22,  179,  439,  483,
- /*  1010 */   520,  521,  530,  529,  535,  267,  186,  186,  366,  401,
- /*  1020 */   186,  565,  342,  186,  443,  449,  451,  573,  574,  179,
- /*  1030 */    92,  433,  433,  585,   18,   92,  602,  478,  302,  523,
- /*  1040 */   606,  351,  491,  495,  309,  453,  454,  450,  450,   63,
- /*  1050 */    63,   62,   62,   62,   62,  497,   64,   64,   64,   64,
- /*  1060 */    65,   65,   66,   66,   66,   67,  216,  165,  262,   85,
- /*  1070 */   527,  528,  235,  236,  237,  168,  239,  533,  105,  534,
- /*  1080 */   263,  546,  269,   73,  337,    8,    4,  195,  271,  273,
- /*  1090 */   308,  211,  275,  294,  280,  371,  379,  382,  383,  334,
- /*  1100 */   283,  284,  295,  285,  577,  587,  293,  296,  297,  599,
- /*  1110 */   147,  242,  462,  423,  209,  464,  569,  339,  338,  250,
- /*  1120 */   208,  481,  526,  210,  572,  484,  437,  469,  259,  537,
- /*  1130 */   540,  290,  393,  584,  166,  409,  417,  418,  536,  538,
- /*  1140 */   330,    7,  326,  361,  419,  167,   85,   76,   75,  156,
- /*  1150 */   169,  347,  345,   84,  327,  176,   74,  328,  329,   58,
- /*  1160 */   434,  438,   80,  432,   35,  479,  392,  291,  281,  243,
- /*  1170 */   246,  244,  305,  245,  121,   86,  435,  214,  350,  214,
- /*  1180 */   356,  513,  518,  433,  251,  313,  260,  523,  125,  493,
- /*  1190 */   499,  519,  253,  440,  440,  440,  441,  442,   11,   73,
- /*  1200 */   337,  398,    4,  522,  219,  344,  308,  500,  524,  255,
- /*  1210 */   343,  226,  368,  300,  225,  334,   73,  337,  227,    4,
- /*  1220 */   541,  547,  548,  308,  549,  190,  301,  555,  191,  372,
- /*  1230 */   370,  193,  334,  339,  194,  557,   89,  196,  278,  378,
- /*  1240 */   558,  117,  568,  469,  199,  133,  390,  391,  575,  143,
- /*  1250 */   339,  134,  135,  583,  136,  139,  137,  142,  322,  596,
- /*  1260 */   469,   93,   96,   76,   75,  502,  597,  598,  601,  101,
- /*  1270 */   224,  104,   74,  328,  329,  107,  407,  438,  238,  424,
- /*  1280 */    76,   75,  118,  455,  650,  651,  172,  173,  452,   74,
- /*  1290 */   328,  329,  324,   72,  438,  459,  468,  471,  144,  158,
- /*  1300 */     6,  472,   13,  473,  175,  477,   82,  490,   12,  440,
- /*  1310 */   440,  440,  441,  442,   11,  122,  498,  180,  164,  506,
- /*  1320 */   507,   87,  116,  223,  126,  127,  440,  440,  440,  441,
- /*  1330 */   442,   11,  266,   88,  128,  188,  360,  365,  258,  369,
- /*  1340 */   146,  556,  129,  179,  130,  373,  559,  279,  563,  197,
- /*  1350 */   131,    9,  571,  201,  132,   14,  203,  576,  204,  579,
- /*  1360 */   138,  205,   90,  141,   91,  140,   15,  106,  594,  586,
- /*  1370 */   400,  298,  212,  404,  149,  608,
+ /*     0 */   304,  930,  120,  609,    1,  178,  214,  436,   62,   62,
+ /*    10 */    62,   62,  216,   64,   64,   64,   64,   65,   65,   66,
+ /*    20 */    66,   66,   67,  216,  406,  403,  443,  449,   69,   64,
+ /*    30 */    64,   64,   64,   65,   65,   66,   66,   66,   67,  216,
+ /*    40 */   469,  467,  336,  174,   61,   60,  309,  453,  454,  450,
+ /*    50 */   450,   63,   63,   62,   62,   62,   62,  200,   64,   64,
+ /*    60 */    64,   64,   65,   65,   66,   66,   66,   67,  216,  304,
+ /*    70 */   510,  312,  436,  509,  438,   83,   64,   64,   64,   64,
+ /*    80 */    65,   65,   66,   66,   66,   67,  216,   65,   65,   66,
+ /*    90 */    66,   66,   67,  216,  511,  443,  449,  325,  408,   59,
+ /*   100 */   465,  218,   57,  213,  411,  496,  428,  440,  440,  440,
+ /*   110 */   206,   67,  216,   61,   60,  309,  453,  454,  450,  450,
+ /*   120 */    63,   63,   62,   62,   62,   62,  552,   64,   64,   64,
+ /*   130 */    64,   65,   65,   66,   66,   66,   67,  216,  304,  228,
+ /*   140 */   186,  469,  544,  312,  433,  170,  114,  256,  357,  261,
+ /*   150 */   358,  181,  425,   20,  426,  542,  153,   85,  265,  465,
+ /*   160 */   218,  150,  151,  539,  443,  449,   95,  311,  394,  412,
+ /*   170 */   413,  510,  276,  427,  436,  438,  152,  553,  545,  589,
+ /*   180 */   590,  539,   61,   60,  309,  453,  454,  450,  450,   63,
+ /*   190 */    63,   62,   62,   62,   62,  402,   64,   64,   64,   64,
+ /*   200 */    65,   65,   66,   66,   66,   67,  216,  304,  440,  440,
+ /*   210 */   440,  228,  109,  411,  399,  523,  593,  330,  114,  256,
+ /*   220 */   357,  261,  358,  181,  187,  330,  485,  359,  362,  363,
+ /*   230 */   265,  593,  241,  443,  449,  592,  591,  248,  364,  436,
+ /*   240 */   432,   35,  492,   66,   66,   66,   67,  216,  432,   42,
+ /*   250 */   592,   61,   60,  309,  453,  454,  450,  450,   63,   63,
+ /*   260 */    62,   62,   62,   62,  401,   64,   64,   64,   64,   65,
+ /*   270 */    65,   66,   66,   66,   67,  216,  304,  570,  412,  413,
+ /*   280 */   187,  501,  344,  359,  362,  363,  215,  354,  346,  221,
+ /*   290 */   330,  341,  330,   56,  364,  569,  588,  217,   68,  156,
+ /*   300 */    70,  155,  443,  449,   68,  187,   70,  155,  359,  362,
+ /*   310 */   363,  397,  217,  432,   35,  432,   36,  148,  569,  364,
+ /*   320 */    61,   60,  309,  453,  454,  450,  450,   63,   63,   62,
+ /*   330 */    62,   62,   62,  433,   64,   64,   64,   64,   65,   65,
+ /*   340 */    66,   66,   66,   67,  216,  387,  282,  281,  330,  304,
+ /*   350 */   474,   68,  480,   70,  155,  344,  214,  154,  299,  330,
+ /*   360 */   343,  467,  543,  174,  384,  475,  257,  247,  387,  282,
+ /*   370 */   281,  432,   28,  411,  160,  443,  449,  258,  476,  214,
+ /*   380 */   516,  496,  432,   42,  198,  492,   68,  162,   70,  155,
+ /*   390 */   517,  433,   78,   61,   60,  309,  453,  454,  450,  450,
+ /*   400 */    63,   63,   62,   62,   62,   62,  595,   64,   64,   64,
+ /*   410 */    64,   65,   65,   66,   66,   66,   67,  216,  433,  367,
+ /*   420 */   349,  433,  304,  220,  222,  544,  505,  330,  465,  330,
+ /*   430 */   230,  330,  240,  163,  161,  554,   20,  431,  412,  413,
+ /*   440 */     2,  430,  385,  375,  411,  198,  182,  249,  443,  449,
+ /*   450 */   432,   35,  432,   50,  432,   50,  310,  460,  461,   17,
+ /*   460 */   207,  335,  460,  461,  388,   81,   61,   60,  309,  453,
+ /*   470 */   454,  450,  450,   63,   63,   62,   62,   62,   62,  433,
+ /*   480 */    64,   64,   64,   64,   65,   65,   66,   66,   66,   67,
+ /*   490 */   216,  304,  348,  504,  433,  508,  531,  486,  320,  353,
+ /*   500 */   321,  306,  457,  385,   23,  331,  265,  470,  411,  412,
+ /*   510 */   413,  444,  445,  551,  526,  307,  532,  443,  449,  217,
+ /*   520 */   550,  496,  432,    3,  217,  381,  607,  921,  333,  921,
+ /*   530 */   456,  456,  447,  448,  276,   61,   60,  309,  453,  454,
+ /*   540 */   450,  450,   63,   63,   62,   62,   62,   62,  410,   64,
+ /*   550 */    64,   64,   64,   65,   65,   66,   66,   66,   67,  216,
+ /*   560 */   304,  446,  607,  920,  525,  920,  604,  264,  314,  474,
+ /*   570 */   411,  123,  411,  412,  413,  124,  277,  487,  234,  333,
+ /*   580 */   411,  456,  456,  319,  475,  411,  443,  449,  333,  377,
+ /*   590 */   456,  456,  286,  333,  380,  456,  456,  476,  178,  340,
+ /*   600 */   436,  420,  604,  315,   61,   60,  309,  453,  454,  450,
+ /*   610 */   450,   63,   63,   62,   62,   62,   62,  330,   64,   64,
+ /*   620 */    64,   64,   65,   65,   66,   66,   66,   67,  216,  304,
+ /*   630 */   289,    5,  287,  268,  466,  412,  413,  412,  413,  396,
+ /*   640 */   432,   29,  503,  330,  159,  412,  413,  610,  406,  403,
+ /*   650 */   412,  413,  414,  415,  416,  443,  449,  333,  214,  456,
+ /*   660 */   456,  488,  276,  489,   21,  436,  432,   24,  436,  487,
+ /*   670 */   514,  515,  395,   61,   60,  309,  453,  454,  450,  450,
+ /*   680 */    63,   63,   62,   62,   62,   62,  330,   64,   64,   64,
+ /*   690 */    64,   65,   65,   66,   66,   66,   67,  216,  304,  560,
+ /*   700 */   374,  560,  352,   94,  578,  330,  567,  515,  330,  432,
+ /*   710 */    33,  330,  288,  330,  562,  330,  544,  330,  561,  183,
+ /*   720 */   184,  185,  603,  303,  443,  449,  600,   20,  432,   54,
+ /*   730 */   376,  432,   53,  436,  432,   99,  432,   97,  432,  102,
+ /*   740 */   432,  103,   61,   60,  309,  453,  454,  450,  450,   63,
+ /*   750 */    63,   62,   62,   62,   62,  330,   64,   64,   64,   64,
+ /*   760 */    65,   65,   66,   66,   66,   67,  216,  304,  330,  405,
+ /*   770 */     1,  202,  330,  512,  330,  214,  330,  171,  432,  108,
+ /*   780 */   330,  421,  429,  330,  487,  342,  330,  384,   19,  386,
+ /*   790 */   145,  432,  110,  443,  449,  432,   16,  432,  100,  432,
+ /*   800 */    34,  351,  270,  432,   98,  433,  432,   25,  276,  432,
+ /*   810 */    55,   61,   60,  309,  453,  454,  450,  450,   63,   63,
+ /*   820 */    62,   62,   62,   62,  330,   64,   64,   64,   64,   65,
+ /*   830 */    65,   66,   66,   66,   67,  216,  304,  330,  323,  119,
+ /*   840 */   274,  330,  272,  330,  355,  330,  422,  432,  111,  330,
+ /*   850 */   580,  159,  115,  233,  330,  177,  161,  439,  463,  463,
+ /*   860 */   432,  112,  443,  449,  432,  113,  432,   26,  432,   37,
+ /*   870 */   649,  431,  432,   38,  492,  430,  487,  432,   27,  264,
+ /*   880 */    61,   71,  309,  453,  454,  450,  450,   63,   63,   62,
+ /*   890 */    62,   62,   62,  330,   64,   64,   64,   64,   65,   65,
+ /*   900 */    66,   66,   66,   67,  216,  304,  330,  264,  264,  528,
+ /*   910 */   330,  157,  330,  252,  330,  229,  432,   39,  330,  482,
+ /*   920 */   332,  478,   77,  330,   79,  330,  483,  520,  521,  432,
+ /*   930 */    40,  443,  449,  432,   41,  432,   43,  432,   44,  492,
+ /*   940 */   491,  432,   45,  316,  317,  433,  432,   30,  432,   31,
+ /*   950 */    60,  309,  453,  454,  450,  450,   63,   63,   62,   62,
+ /*   960 */    62,   62,  330,   64,   64,   64,   64,   65,   65,   66,
+ /*   970 */    66,   66,   67,  216,  304,  330,  264,  564,  254,  330,
+ /*   980 */   458,  330,   22,  330,  495,  432,   46,  330,  494,  535,
+ /*   990 */   179,  186,  330,  267,  330,  186,  451,  497,  432,   47,
+ /*  1000 */   443,  449,  432,   48,  432,   49,  432,   32,  182,  262,
+ /*  1010 */   432,   10,  318,  276,  389,  432,   51,  432,   52,  276,
+ /*  1020 */   309,  453,  454,  450,  450,   63,   63,   62,   62,   62,
+ /*  1030 */    62,  276,   64,   64,   64,   64,   65,   65,   66,   66,
+ /*  1040 */    66,   67,  216,  165,  276,  276,  189,  192,  235,  236,
+ /*  1050 */   237,  168,  239,  566,  105,  581,   18,  530,  529,   73,
+ /*  1060 */   337,  582,    4,  306,  605,  527,  308,  211,  366,  294,
+ /*  1070 */   186,  263,  533,  231,  334,  565,  295,  186,  534,  546,
+ /*  1080 */   433,  433,  573,  574,  179,   92,  232,  292,  209,  269,
+ /*  1090 */   569,  339,  271,  853,  208,  273,  275,  210,  585,  195,
+ /*  1100 */    92,  469,  371,  606,  602,    8,  302,  423,  280,  379,
+ /*  1110 */   382,  383,  147,  242,  283,  437,  462,  284,  285,  577,
+ /*  1120 */   338,   76,   75,  587,  293,  296,  297,  599,  481,  464,
+ /*  1130 */    74,  328,  329,  250,  526,  438,  572,  166,  290,  393,
+ /*  1140 */   392,  291,  281,  409,  537,  584,  305,  484,  259,  540,
+ /*  1150 */   417,  214,  418,  214,  536,  326,  538,  419,  361,  167,
+ /*  1160 */    73,  337,  169,    4,    7,  327,  347,  308,  440,  440,
+ /*  1170 */   440,  441,  442,   11,   85,  334,  398,   84,  434,  345,
+ /*  1180 */   243,   58,  244,   73,  337,   80,    4,  245,  435,  246,
+ /*  1190 */   308,  176,  339,  479,   86,  121,  356,  350,  334,  493,
+ /*  1200 */   251,  253,  469,  499,  255,  513,  500,  518,  313,  519,
+ /*  1210 */   260,  523,  125,  522,  226,  339,  219,  524,  368,  190,
+ /*  1220 */   191,  300,   76,   75,  502,  469,  225,  227,  547,  541,
+ /*  1230 */   548,   74,  328,  329,  301,  555,  438,  549,  370,  193,
+ /*  1240 */   372,  194,  557,   89,  196,   76,   75,  278,  378,  117,
+ /*  1250 */   558,  568,  133,  390,   74,  328,  329,  199,  391,  438,
+ /*  1260 */   322,  134,  135,  136,  575,  143,  583,  596,  139,  440,
+ /*  1270 */   440,  440,  441,  442,   11,  597,  598,  601,  137,  142,
+ /*  1280 */   101,  224,  104,  407,  238,  424,  650,  651,   93,  172,
+ /*  1290 */    96,  173,  440,  440,  440,  441,  442,   11,  452,  455,
+ /*  1300 */    72,  471,  459,  468,  472,  144,  158,    6,  473,  490,
+ /*  1310 */   107,  175,  477,   82,   13,  122,   12,  180,  506,  118,
+ /*  1320 */   498,  164,  507,  324,  223,   87,  126,  116,  266,  127,
+ /*  1330 */    88,  128,  188,  258,  360,  369,  146,  556,  129,  373,
+ /*  1340 */   179,  365,  279,  197,  131,  130,  563,    9,  571,  132,
+ /*  1350 */   559,  201,   14,  576,  203,  204,  205,  579,  140,  138,
+ /*  1360 */   141,   15,  586,  594,  212,  106,  400,  298,  149,  404,
+ /*  1370 */   931,  608,   90,   91,
 };
 static const YYCODETYPE yy_lookahead[] = {
- /*     0 */    19,  142,  143,  144,  145,   24,  150,   26,   74,   75,
- /*    10 */    76,   77,  115,   79,   80,   81,   82,   83,   84,   85,
- /*    20 */    86,   87,   88,   89,  150,  165,  166,  167,   47,   48,
+ /*     0 */    19,  142,  143,  144,  145,   24,  113,   26,   72,   73,
+ /*    10 */    74,   75,   87,   77,   78,   79,   80,   81,   82,   83,
+ /*    20 */    84,   85,   86,   87,    1,    2,   45,   46,   76,   77,
  /*    30 */    78,   79,   80,   81,   82,   83,   84,   85,   86,   87,
- /*    40 */    88,   89,  186,  169,  170,   85,   65,   66,   67,   68,
- /*    50 */    69,   70,   71,   72,   73,   74,   75,   76,   77,   89,
- /*    60 */    79,   80,   81,   82,   83,   84,   85,   86,   87,   88,
- /*    70 */    89,   19,  112,   19,   93,  173,  116,   25,   79,   80,
- /*    80 */    81,   82,   83,   84,   85,   86,   87,   88,   89,    1,
- /*    90 */     2,   26,   83,   84,   85,   86,   87,   88,   89,   47,
- /*   100 */    48,  180,  181,   51,  230,  231,   22,   22,  187,   26,
- /*   110 */   221,   26,  223,  224,    0,    1,    2,   65,   66,   67,
- /*   120 */    68,   69,   70,   71,   72,   73,   74,   75,   76,   77,
- /*   130 */   241,   79,   80,   81,   82,   83,   84,   85,   86,   87,
- /*   140 */    88,   89,   19,   89,    7,    8,    9,   19,   63,   95,
- /*   150 */    96,   97,   98,   99,  100,  101,  150,   28,   93,   94,
- /*   160 */    95,   32,  108,   98,   99,  100,   83,   84,   83,   84,
- /*   170 */    47,   48,   49,   25,  109,   46,   93,   94,   93,  173,
- /*   180 */   174,  165,   97,   26,   83,   84,  103,  104,   65,   66,
- /*   190 */    67,   68,   69,   70,   71,   72,   73,   74,   75,   76,
- /*   200 */    77,  117,   79,   80,   81,   82,   83,   84,   85,   86,
- /*   210 */    87,   88,   89,   19,  129,  130,  131,   89,   24,  150,
- /*   220 */   204,  150,   63,  173,   96,   97,   98,   99,  100,  101,
- /*   230 */   150,  225,  221,  222,  223,  224,  108,  221,  185,  223,
- /*   240 */   224,   47,   48,   95,  173,  174,   98,   99,  100,   54,
- /*   250 */    93,   94,   93,  173,  174,  186,   97,  109,  159,   65,
- /*   260 */    66,   67,   68,   69,   70,   71,   72,   73,   74,   75,
- /*   270 */    76,   77,  150,   79,   80,   81,   82,   83,   84,   85,
- /*   280 */    86,   87,   88,   89,   19,   11,  215,  172,  129,  130,
- /*   290 */   131,  220,  193,  213,  214,  180,  146,  147,   26,  104,
- /*   300 */   105,  106,  152,   85,   86,   87,   88,   89,  186,  159,
- /*   310 */   115,   95,   47,   48,   98,   99,  100,  162,  185,   22,
- /*   320 */   165,  166,  167,   26,  221,  109,  223,  224,   54,  150,
- /*   330 */    65,   66,   67,   68,   69,   70,   71,   72,   73,   74,
- /*   340 */    75,   76,   77,  193,   79,   80,   81,   82,   83,   84,
- /*   350 */    85,   86,   87,   88,   89,   83,   19,  221,  150,  223,
- /*   360 */   224,  171,  172,  150,  150,   93,   94,  217,  160,  161,
- /*   370 */   180,   26,   24,  150,   26,  150,  189,  190,  104,  105,
- /*   380 */   106,  159,  169,  194,   47,   48,  150,  173,  174,  115,
- /*   390 */    93,   94,  184,  185,  244,  216,  173,  174,  173,  174,
- /*   400 */   159,  136,   65,   66,   67,   68,   69,   70,   71,   72,
- /*   410 */    73,   74,   75,   76,   77,  193,   79,   80,   81,   82,
- /*   420 */    83,   84,   85,   86,   87,   88,   89,  150,   19,  159,
- /*   430 */    12,  150,   23,  219,  193,   19,  159,  214,   93,  217,
- /*   440 */   215,   93,  150,  230,  231,   27,  205,  206,   26,  157,
- /*   450 */   173,  174,  160,  161,  173,  174,   47,   48,  154,  190,
- /*   460 */    42,  239,   44,  193,   48,   25,  168,  169,  170,   22,
- /*   470 */   193,   24,   54,  136,   65,   66,   67,   68,   69,   70,
- /*   480 */    71,   72,   73,   74,   75,   76,   77,  217,   79,   80,
- /*   490 */    81,   82,   83,   84,   85,   86,   87,   88,   89,   19,
- /*   500 */   219,   23,  150,   23,  234,   23,  135,  150,  137,  239,
- /*   510 */   168,  169,  170,   23,  164,   93,   94,   26,   23,  103,
- /*   520 */   150,   47,   48,  173,  108,  173,  174,   47,   48,  231,
- /*   530 */   173,  174,  228,   21,  150,   22,   23,  233,   25,   88,
- /*   540 */    89,  119,   68,   69,  165,   65,   66,   67,   68,   69,
- /*   550 */    70,   71,   72,   73,   74,   75,   76,   77,  118,   79,
- /*   560 */    80,   81,   82,   83,   84,   85,   86,   87,   88,   89,
- /*   570 */    19,   97,   60,  231,   23,   22,  165,   64,   23,   26,
- /*   580 */    25,   96,   12,  204,   93,   94,   34,   22,   23,  111,
- /*   590 */    25,  113,  114,  111,   26,  113,  114,   27,   47,   48,
- /*   600 */   115,  111,   17,  113,  114,  150,  111,   55,  113,  114,
- /*   610 */   119,   99,   42,  128,   44,  204,   65,   66,   67,   68,
- /*   620 */    69,   70,   71,   72,   73,   74,   75,   76,   77,   64,
- /*   630 */    79,   80,   81,   82,   83,   84,   85,   86,   87,   88,
- /*   640 */    89,   19,   57,  150,   59,   23,   93,   94,  150,   94,
- /*   650 */   138,   22,  150,   85,  150,   26,  150,   97,  150,  107,
- /*   660 */   150,   93,   94,   48,  189,  190,  173,  174,  108,   47,
- /*   670 */    48,  173,  174,  115,  119,  173,  174,  173,  174,  173,
- /*   680 */   174,  173,  174,  173,  174,   17,  128,   65,   66,   67,
- /*   690 */    68,   69,   70,   71,   72,   73,   74,   75,   76,   77,
- /*   700 */   150,   79,   80,   81,   82,   83,   84,   85,   86,   87,
- /*   710 */    88,   89,   19,  150,  104,  105,  106,   24,  103,  150,
- /*   720 */   148,  150,   93,  138,  150,   57,  150,   59,  150,  111,
- /*   730 */   150,  113,  114,  150,  247,  248,  173,  174,  144,  145,
- /*   740 */    47,   48,  173,  174,  173,  174,  165,  173,  174,  173,
- /*   750 */   174,  173,  174,  173,  174,  150,  173,  174,   65,   66,
- /*   760 */    67,   68,   69,   70,   71,   72,   73,   74,   75,   76,
- /*   770 */    77,  150,   79,   80,   81,   82,   83,   84,   85,   86,
- /*   780 */    87,   88,   89,   19,  150,  204,  150,  104,  105,  106,
- /*   790 */   150,  150,  150,  207,  173,  174,  150,  150,  150,  196,
- /*   800 */   150,  160,  161,  150,  150,  150,  203,  173,  174,  173,
- /*   810 */   174,   47,   48,  173,  174,  173,  174,  212,  195,  173,
- /*   820 */   174,  173,  174,  173,  174,  150,  173,  174,  150,   65,
- /*   830 */    66,   67,   68,   69,   70,   71,   72,   73,   74,   75,
- /*   840 */    76,   77,  150,   79,   80,   81,   82,   83,   84,   85,
- /*   850 */    86,   87,   88,   89,   19,  150,  159,  150,  112,  212,
- /*   860 */   150,  150,  116,  150,  186,  173,  174,  192,  150,   25,
- /*   870 */   150,  216,  150,  150,  150,  205,  206,  150,  173,  174,
- /*   880 */   173,  174,   47,   48,  173,  174,  173,  174,  150,  150,
- /*   890 */   193,  173,  174,  173,  174,  173,  174,  173,  174,  150,
- /*   900 */    65,   66,   67,   68,   69,   70,   71,   72,   73,   74,
- /*   910 */    75,   76,   77,  150,   79,   80,   81,   82,   83,   84,
- /*   920 */    85,   86,   87,   88,   89,   19,  150,  150,  150,  150,
- /*   930 */   192,  192,  150,  159,  150,  186,  173,  174,   94,  212,
- /*   940 */    19,  150,  150,  245,  246,  129,  130,  150,   19,  173,
- /*   950 */   174,  173,  174,   47,   48,  173,  174,  173,  174,  150,
- /*   960 */   150,  150,   25,  119,  173,  174,  165,  193,   25,  192,
- /*   970 */   150,  192,   66,   67,   68,   69,   70,   71,   72,   73,
- /*   980 */    74,   75,   76,   77,  192,   79,   80,   81,   82,   83,
- /*   990 */    84,   85,   86,   87,   88,   89,   19,  159,  159,   23,
- /*  1000 */    30,  192,  192,  192,   23,   23,   25,   25,  150,   39,
- /*  1010 */     7,    8,   96,   97,   23,   23,   25,   25,   23,  242,
- /*  1020 */    25,   23,  150,   25,   47,   48,   97,   23,   23,   25,
- /*  1030 */    25,  193,  193,   23,   22,   25,   23,  150,   25,  102,
- /*  1040 */    64,  120,  150,  150,   67,   68,   69,   70,   71,   72,
- /*  1050 */    73,   74,   75,   76,   77,  150,   79,   80,   81,   82,
- /*  1060 */    83,   84,   85,   86,   87,   88,   89,    5,  150,  126,
- /*  1070 */   150,  182,   10,   11,   12,   13,   14,  182,   16,  182,
- /*  1080 */   150,  150,  150,   19,   20,   73,   22,  235,  150,  150,
- /*  1090 */    26,   29,  150,   31,  150,  236,  150,  150,  150,   35,
- /*  1100 */   150,  150,   40,  150,  150,  150,  150,  150,  150,  150,
- /*  1110 */   195,  197,  232,  153,   52,  232,   54,   53,  227,  208,
- /*  1120 */    58,  176,  181,   61,  198,  176,  165,   63,  176,  165,
- /*  1130 */   165,  208,  208,  198,    6,  149,  149,  149,  176,  176,
- /*  1140 */   150,   25,  149,  177,   13,  151,  126,   83,   84,  159,
- /*  1150 */   151,  123,  122,  124,  158,  117,   92,   93,   94,  125,
- /*  1160 */   193,   97,  135,  173,  174,  156,  104,  105,  106,  198,
- /*  1170 */   201,  199,  110,  200,  156,  103,  202,  115,  121,  115,
- /*  1180 */   103,  175,  175,  193,  209,   45,  175,  102,   22,  210,
- /*  1190 */   210,  183,  209,  129,  130,  131,  132,  133,  134,   19,
- /*  1200 */    20,  139,   22,  177,  226,  215,   26,  210,  175,  209,
- /*  1210 */   220,   89,   18,  178,  229,   35,   19,   20,  229,   22,
- /*  1220 */   183,  175,  175,   26,  175,  155,  178,  156,  155,   43,
- /*  1230 */   156,  155,   35,   53,  156,  156,  135,  155,  237,  156,
- /*  1240 */   238,   65,  188,   63,  188,   22,  156,   18,  198,  218,
- /*  1250 */    53,  191,  191,  198,  191,  188,  191,  218,  156,   38,
- /*  1260 */    63,  240,  240,   83,   84,   85,  156,  156,   36,  163,
- /*  1270 */   179,  179,   92,   93,   94,  243,    1,   97,   15,   23,
- /*  1280 */    83,   84,  246,  112,  117,  117,  117,  117,   97,   92,
- /*  1290 */    93,   94,  249,   22,   97,   23,   23,   11,   22,   22,
- /*  1300 */    33,   23,   33,   23,   25,   23,   25,  119,   25,  129,
- /*  1310 */   130,  131,  132,  133,  134,   22,  120,   33,  117,   23,
- /*  1320 */    23,   22,   37,   49,   22,   22,  129,  130,  131,  132,
- /*  1330 */   133,  134,   23,   22,   22,  101,   49,   49,  108,   19,
- /*  1340 */    24,   20,  103,   25,   50,   41,   56,  138,   50,  103,
- /*  1350 */    22,    5,    1,  127,  107,   22,  118,    1,   17,   20,
- /*  1360 */   118,  121,   73,  127,   73,  107,   22,   17,   23,  128,
- /*  1370 */    62,  140,   15,    3,   22,    4,
+ /*    40 */    61,  165,  166,  167,   63,   64,   65,   66,   67,   68,
+ /*    50 */    69,   70,   71,   72,   73,   74,   75,   25,   77,   78,
+ /*    60 */    79,   80,   81,   82,   83,   84,   85,   86,   87,   19,
+ /*    70 */    91,   19,   91,  173,   95,   25,   77,   78,   79,   80,
+ /*    80 */    81,   82,   83,   84,   85,   86,   87,   81,   82,   83,
+ /*    90 */    84,   85,   86,   87,  173,   45,   46,  146,  147,   49,
+ /*   100 */    81,   82,   22,  152,   26,  150,   26,  128,  129,  130,
+ /*   110 */   159,   86,   87,   63,   64,   65,   66,   67,   68,   69,
+ /*   120 */    70,   71,   72,   73,   74,   75,  185,   77,   78,   79,
+ /*   130 */    80,   81,   82,   83,   84,   85,   86,   87,   19,   87,
+ /*   140 */    25,   61,  150,   19,  193,   93,   94,   95,   96,   97,
+ /*   150 */    98,   99,  160,  161,  171,  172,   25,  125,  106,   81,
+ /*   160 */    82,   81,   82,  180,   45,   46,   47,  212,  217,   91,
+ /*   170 */    92,   91,  150,  172,   26,   95,  184,  185,  185,  101,
+ /*   180 */   102,  180,   63,   64,   65,   66,   67,   68,   69,   70,
+ /*   190 */    71,   72,   73,   74,   75,  244,   77,   78,   79,   80,
+ /*   200 */    81,   82,   83,   84,   85,   86,   87,   19,  128,  129,
+ /*   210 */   130,   87,   24,   26,  192,  100,  150,  150,   94,   95,
+ /*   220 */    96,   97,   98,   99,   93,  150,   25,   96,   97,   98,
+ /*   230 */   106,  150,  194,   45,   46,  169,  170,  150,  107,   91,
+ /*   240 */   173,  174,  165,   83,   84,   85,   86,   87,  173,  174,
+ /*   250 */   169,   63,   64,   65,   66,   67,   68,   69,   70,   71,
+ /*   260 */    72,   73,   74,   75,  242,   77,   78,   79,   80,   81,
+ /*   270 */    82,   83,   84,   85,   86,   87,   19,   11,   91,   92,
+ /*   280 */    93,  204,  215,   96,   97,   98,  196,  220,  213,  214,
+ /*   290 */   150,  190,  150,  203,  107,   52,  230,  231,  221,  159,
+ /*   300 */   223,  224,   45,   46,  221,   93,  223,  224,   96,   97,
+ /*   310 */    98,  230,  231,  173,  174,  173,  174,  116,   52,  107,
+ /*   320 */    63,   64,   65,   66,   67,   68,   69,   70,   71,   72,
+ /*   330 */    73,   74,   75,  193,   77,   78,   79,   80,   81,   82,
+ /*   340 */    83,   84,   85,   86,   87,  102,  103,  104,  150,   19,
+ /*   350 */    12,  221,  222,  223,  224,  215,  113,  159,  162,  150,
+ /*   360 */   220,  165,  166,  167,  150,   27,   95,  225,  102,  103,
+ /*   370 */   104,  173,  174,   26,  150,   45,   46,  106,   40,  113,
+ /*   380 */    42,  150,  173,  174,  159,  165,  221,  159,  223,  224,
+ /*   390 */    52,  193,  135,   63,   64,   65,   66,   67,   68,   69,
+ /*   400 */    70,   71,   72,   73,   74,   75,  241,   77,   78,   79,
+ /*   410 */    80,   81,   82,   83,   84,   85,   86,   87,  193,   19,
+ /*   420 */   150,  193,   19,  214,  204,  150,   23,  150,   81,  150,
+ /*   430 */   216,  150,  157,  205,  206,  160,  161,  110,   91,   92,
+ /*   440 */    22,  114,  217,  212,   26,  159,   46,  150,   45,   46,
+ /*   450 */   173,  174,  173,  174,  173,  174,  168,  169,  170,  234,
+ /*   460 */   159,  168,  169,  170,  239,  135,   63,   64,   65,   66,
+ /*   470 */    67,   68,   69,   70,   71,   72,   73,   74,   75,  193,
+ /*   480 */    77,   78,   79,   80,   81,   82,   83,   84,   85,   86,
+ /*   490 */    87,   19,  215,   23,  193,   23,   33,  207,  219,  150,
+ /*   500 */   219,  101,   23,  217,   22,  150,  106,   23,   26,   91,
+ /*   510 */    92,   45,   46,  180,  181,  154,   53,   45,   46,  231,
+ /*   520 */   187,  150,  173,  174,  231,  239,   22,   23,  109,   25,
+ /*   530 */   111,  112,   66,   67,  150,   63,   64,   65,   66,   67,
+ /*   540 */    68,   69,   70,   71,   72,   73,   74,   75,  150,   77,
+ /*   550 */    78,   79,   80,   81,   82,   83,   84,   85,   86,   87,
+ /*   560 */    19,   95,   22,   23,   23,   25,   62,  150,  105,   12,
+ /*   570 */    26,   23,   26,   91,   92,   23,  192,   25,  148,  109,
+ /*   580 */    26,  111,  112,  212,   27,   26,   45,   46,  109,  228,
+ /*   590 */   111,  112,   17,  109,  233,  111,  112,   40,   24,   42,
+ /*   600 */    26,  150,   62,  186,   63,   64,   65,   66,   67,   68,
+ /*   610 */    69,   70,   71,   72,   73,   74,   75,  150,   77,   78,
+ /*   620 */    79,   80,   81,   82,   83,   84,   85,   86,   87,   19,
+ /*   630 */    55,  195,   57,   23,  165,   91,   92,   91,   92,   94,
+ /*   640 */   173,  174,   83,  150,   92,   91,   92,    0,    1,    2,
+ /*   650 */    91,   92,    7,    8,    9,   45,   46,  109,  113,  111,
+ /*   660 */   112,  117,  150,  117,   22,   91,  173,  174,   26,  117,
+ /*   670 */   189,  190,  127,   63,   64,   65,   66,   67,   68,   69,
+ /*   680 */    70,   71,   72,   73,   74,   75,  150,   77,   78,   79,
+ /*   690 */    80,   81,   82,   83,   84,   85,   86,   87,   19,  102,
+ /*   700 */   103,  104,   19,   24,  192,  150,  189,  190,  150,  173,
+ /*   710 */   174,  150,  137,  150,   28,  150,  150,  150,   32,  102,
+ /*   720 */   103,  104,  247,  248,   45,   46,  160,  161,  173,  174,
+ /*   730 */    44,  173,  174,   91,  173,  174,  173,  174,  173,  174,
+ /*   740 */   173,  174,   63,   64,   65,   66,   67,   68,   69,   70,
+ /*   750 */    71,   72,   73,   74,   75,  150,   77,   78,   79,   80,
+ /*   760 */    81,   82,   83,   84,   85,   86,   87,   19,  150,  144,
+ /*   770 */   145,  159,  150,  164,  150,  113,  150,   22,  173,  174,
+ /*   780 */   150,  150,  173,  150,   25,  150,  150,  150,   22,  127,
+ /*   790 */    24,  173,  174,   45,   46,  173,  174,  173,  174,  173,
+ /*   800 */   174,  118,   17,  173,  174,  193,  173,  174,  150,  173,
+ /*   810 */   174,   63,   64,   65,   66,   67,   68,   69,   70,   71,
+ /*   820 */    72,   73,   74,   75,  150,   77,   78,   79,   80,   81,
+ /*   830 */    82,   83,   84,   85,   86,   87,   19,  150,  245,  246,
+ /*   840 */    55,  150,   57,  150,   83,  150,  150,  173,  174,  150,
+ /*   850 */   192,   92,  150,  216,  150,  205,  206,  150,  128,  129,
+ /*   860 */   173,  174,   45,   46,  173,  174,  173,  174,  173,  174,
+ /*   870 */   115,  110,  173,  174,  165,  114,  117,  173,  174,  150,
+ /*   880 */    63,   64,   65,   66,   67,   68,   69,   70,   71,   72,
+ /*   890 */    73,   74,   75,  150,   77,   78,   79,   80,   81,   82,
+ /*   900 */    83,   84,   85,   86,   87,   19,  150,  150,  150,  182,
+ /*   910 */   150,  159,  150,  204,  150,  186,  173,  174,  150,   30,
+ /*   920 */    19,  150,  134,  150,  136,  150,   37,    7,    8,  173,
+ /*   930 */   174,   45,   46,  173,  174,  173,  174,  173,  174,  165,
+ /*   940 */   150,  173,  174,  186,  186,  193,  173,  174,  173,  174,
+ /*   950 */    64,   65,   66,   67,   68,   69,   70,   71,   72,   73,
+ /*   960 */    74,   75,  150,   77,   78,   79,   80,   81,   82,   83,
+ /*   970 */    84,   85,   86,   87,   19,  150,  150,   21,  204,  150,
+ /*   980 */    23,  150,   25,  150,  150,  173,  174,  150,   23,   23,
+ /*   990 */    25,   25,  150,   23,  150,   25,   95,  150,  173,  174,
+ /*  1000 */    45,   46,  173,  174,  173,  174,  173,  174,   46,  150,
+ /*  1010 */   173,  174,  186,  150,   58,  173,  174,  173,  174,  150,
+ /*  1020 */    65,   66,   67,   68,   69,   70,   71,   72,   73,   74,
+ /*  1030 */    75,  150,   77,   78,   79,   80,   81,   82,   83,   84,
+ /*  1040 */    85,   86,   87,    5,  150,  150,  159,  159,   10,   11,
+ /*  1050 */    12,   13,   14,   97,   16,  192,   22,   94,   95,   19,
+ /*  1060 */    20,  192,   22,  101,   23,  150,   26,   29,   23,   31,
+ /*  1070 */    25,  150,  182,  192,   34,   23,   38,   25,  182,  150,
+ /*  1080 */   193,  193,   23,   23,   25,   25,  192,  192,   50,  150,
+ /*  1090 */    52,   51,  150,  137,   56,  150,  150,   59,   23,  235,
+ /*  1100 */    25,   61,  236,   62,   23,   71,   25,  153,  150,  150,
+ /*  1110 */   150,  150,  195,  197,  150,  165,  232,  150,  150,  150,
+ /*  1120 */   227,   81,   82,  150,  150,  150,  150,  150,  176,  232,
+ /*  1130 */    90,   91,   92,  208,  181,   95,  198,    6,  208,  208,
+ /*  1140 */   102,  103,  104,  149,  165,  198,  108,  176,  176,  165,
+ /*  1150 */   149,  113,  149,  113,  176,  149,  176,   13,  177,  151,
+ /*  1160 */    19,   20,  151,   22,   25,  158,  122,   26,  128,  129,
+ /*  1170 */   130,  131,  132,  133,  125,   34,  138,  123,  193,  121,
+ /*  1180 */   198,  124,  199,   19,   20,  134,   22,  200,  202,  201,
+ /*  1190 */    26,  115,   51,  156,  101,  156,  101,  120,   34,  210,
+ /*  1200 */   209,  209,   61,  210,  209,  175,  210,  175,   43,  183,
+ /*  1210 */   175,  100,   22,  177,   87,   51,  226,  175,   18,  155,
+ /*  1220 */   155,  178,   81,   82,   83,   61,  229,  229,  175,  183,
+ /*  1230 */   175,   90,   91,   92,  178,  156,   95,  175,  156,  155,
+ /*  1240 */    41,  156,  156,  134,  155,   81,   82,  237,  156,   63,
+ /*  1250 */   238,  188,   22,  156,   90,   91,   92,  188,   18,   95,
+ /*  1260 */   156,  191,  191,  191,  198,  218,  198,   36,  188,  128,
+ /*  1270 */   129,  130,  131,  132,  133,  156,  156,  140,  191,  218,
+ /*  1280 */   163,  179,  179,    1,   15,   23,  115,  115,  240,  115,
+ /*  1290 */   240,  115,  128,  129,  130,  131,  132,  133,   95,  110,
+ /*  1300 */    22,   11,   23,   23,   23,   22,   22,  119,   23,  117,
+ /*  1310 */   243,   25,   23,   25,  119,   22,   25,  119,   23,  246,
+ /*  1320 */   118,  115,   23,  249,   47,   22,   22,   35,   23,   22,
+ /*  1330 */    22,   22,   99,  106,   47,   19,   24,   20,  101,   39,
+ /*  1340 */    25,   47,  137,  101,   22,   48,   48,    5,    1,  105,
+ /*  1350 */    54,  126,   22,    1,  116,   17,  120,   20,  105,  116,
+ /*  1360 */   126,   22,  127,   23,   15,   17,   60,  139,   22,    3,
+ /*  1370 */   250,    4,   71,   71,
 };
-#define YY_SHIFT_USE_DFLT (-104)
+#define YY_SHIFT_USE_DFLT (-108)
 #define YY_SHIFT_MAX 404
 static const short yy_shift_ofst[] = {
- /*     0 */    88, 1062, 1064,  -19, 1064, 1197, 1197,   65,   83,  195,
- /*    10 */   123, 1197, 1197, 1197, 1197, 1197,  -48,  274,  272,  157,
- /*    20 */   345,  101,  101, -103,   52,  194,  265,  337,  409,  480,
- /*    30 */   551,  622,  693,  764,  835,  764,  764,  764,  764,  764,
- /*    40 */   764,  764,  764,  764,  764,  764,  764,  764,  764,  764,
- /*    50 */   764,  764,  764,  906,  977,  977, 1180, 1197, 1197, 1197,
- /*    60 */  1197, 1197, 1197, 1197, 1197, 1197, 1197, 1197, 1197, 1197,
- /*    70 */  1197, 1197, 1197, 1197, 1197, 1197, 1197, 1197, 1197, 1197,
- /*    80 */  1197, 1197, 1197, 1197, 1197, 1197, 1197, 1197, 1197, 1197,
- /*    90 */  1197, 1197, 1197, 1197, 1197, 1197, 1197,  -66,  -66,   -1,
- /*   100 */    -1,   54,    9,  218,  416,  512,  157,  157,  451,  345,
- /*   110 */   -30, -104, -104, -104,   85,  128,  418,  418,  513,  565,
- /*   120 */   114,  348,  157,  348,  348,  157,  157,  157,  157,  157,
- /*   130 */   157,  157,  157,  157,  157,  157,  157,  157,  157,  157,
- /*   140 */   157,  157,  485,  558, -103, -103, -103, -104, -104, -104,
- /*   150 */   159,  159,  148,  216,  478,  297,  482,  490,  570,  422,
- /*   160 */   491,  553,  495,  555,  568,  137,  157,  157,  157,  157,
- /*   170 */   157,  -40,  157,  157,  629,  157,  157,  844,  157,  157,
- /*   180 */   157,  157,  157,  552,  552,  552,  157,  157,  157,  618,
- /*   190 */   157,  157,  618,  157,  129,  610,  157,  157,  618,  157,
- /*   200 */   157,  157,  618,  157,  157,  157,  618,  618,  157,  157,
- /*   210 */   157,  157,  157,  447,  746,  440,  345,  816,  816,  371,
- /*   220 */   970,  970,  921,  970,  615,  970,  345,  970,  345,  937,
- /*   230 */   943,  921,  921,  943, 1128, 1128, 1128, 1128, 1131, 1131,
- /*   240 */  1116, -103, 1020, 1028, 1029, 1030, 1034, 1027, 1038, 1038,
- /*   250 */  1072, 1057, 1072, 1057, 1072, 1057, 1077, 1077, 1140, 1077,
- /*   260 */  1085, 1077, 1166, 1122, 1122, 1140, 1077, 1077, 1077, 1166,
- /*   270 */  1194, 1038, 1194, 1038, 1194, 1038, 1038, 1186, 1101, 1194,
- /*   280 */  1038, 1176, 1176, 1223, 1020, 1038, 1229, 1229, 1229, 1229,
- /*   290 */  1020, 1176, 1223, 1038, 1221, 1221, 1038, 1038, 1232, -104,
- /*   300 */  -104, -104, -104, -104,  474,  585,  683,  668,   84,  929,
- /*   310 */   981,  982,  560, 1003,  916,  991,  992,  995,  998, 1004,
- /*   320 */  1005, 1010, 1012, 1013,  976, 1275, 1263, 1256, 1167, 1168,
- /*   330 */  1169, 1170, 1191, 1171, 1271, 1272, 1273, 1276, 1286, 1277,
- /*   340 */  1278, 1279, 1280, 1282, 1281, 1267, 1283, 1269, 1281, 1188,
- /*   350 */  1293, 1284, 1196, 1201, 1296, 1297, 1285, 1274, 1299, 1287,
- /*   360 */  1302, 1309, 1303, 1311, 1288, 1312, 1234, 1230, 1320, 1321,
- /*   370 */  1316, 1239, 1304, 1290, 1294, 1318, 1298, 1209, 1246, 1328,
- /*   380 */  1346, 1351, 1247, 1289, 1291, 1226, 1333, 1238, 1356, 1341,
- /*   390 */  1240, 1339, 1242, 1258, 1236, 1344, 1241, 1345, 1350, 1308,
- /*   400 */  1357, 1231, 1352, 1370, 1371,
+ /*     0 */    23, 1038, 1040,  -19, 1040, 1164, 1164,  187,   78,  243,
+ /*    10 */   119, 1164, 1164, 1164, 1164, 1164,  -48,  266,  347,  554,
+ /*    20 */   148,   19,   19, -107,   50,  188,  257,  330,  403,  472,
+ /*    30 */   541,  610,  679,  748,  817,  748,  748,  748,  748,  748,
+ /*    40 */   748,  748,  748,  748,  748,  748,  748,  748,  748,  748,
+ /*    50 */   748,  748,  748,  886,  955,  955, 1141, 1164, 1164, 1164,
+ /*    60 */  1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164,
+ /*    70 */  1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164,
+ /*    80 */  1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164, 1164,
+ /*    90 */  1164, 1164, 1164, 1164, 1164, 1164, 1164,  -64,  -64,   -1,
+ /*   100 */    -1,   52,    6,  160,  400,  956,  554,  554,   25,  148,
+ /*   110 */   -75, -108, -108, -108,   80,  124,  338,  338,  504,  540,
+ /*   120 */   647,  574,  554,  574,  574,  554,  554,  554,  554,  554,
+ /*   130 */   554,  554,  554,  554,  554,  554,  554,  554,  554,  554,
+ /*   140 */   554,  554,  545,  662, -107, -107, -107, -108, -108, -108,
+ /*   150 */   -21,  -21,  131,  212,  470,  418,  479,  484,  557,  544,
+ /*   160 */   546,  482,  548,  552,  559,  645,  554,  554,  554,  554,
+ /*   170 */   554,  761,  554,  554,  642,  554,  554,  759,  554,  554,
+ /*   180 */   554,  554,  554,  463,  463,  463,  554,  554,  554,  419,
+ /*   190 */   554,  554,  419,  554,  686,  597,  554,  554,  419,  554,
+ /*   200 */   554,  554,  419,  554,  554,  554,  419,  419,  554,  554,
+ /*   210 */   554,  554,  554,  766,  327,  201,  148,  730,  730,  788,
+ /*   220 */   889,  889,  683,  889,  962,  889,  148,  889,  148,  115,
+ /*   230 */    32,  683,  683,   32, 1131, 1131, 1131, 1131, 1144, 1144,
+ /*   240 */  1139, -107, 1049, 1044, 1054, 1058, 1057, 1051, 1076, 1076,
+ /*   250 */  1093, 1077, 1093, 1077, 1093, 1077, 1095, 1095, 1165, 1095,
+ /*   260 */  1111, 1095, 1190, 1127, 1127, 1165, 1095, 1095, 1095, 1190,
+ /*   270 */  1200, 1076, 1200, 1076, 1200, 1076, 1076, 1199, 1109, 1200,
+ /*   280 */  1076, 1186, 1186, 1230, 1049, 1076, 1240, 1240, 1240, 1240,
+ /*   290 */  1049, 1186, 1230, 1076, 1231, 1231, 1076, 1076, 1137, -108,
+ /*   300 */  -108, -108, -108, -108,  466,  575,  617,  785,  755,  901,
+ /*   310 */   957,  965,  271,  920,  963,  966,  970, 1045, 1052, 1059,
+ /*   320 */  1060, 1075, 1034, 1081, 1041, 1282, 1269, 1262, 1171, 1172,
+ /*   330 */  1174, 1176, 1203, 1189, 1278, 1279, 1280, 1283, 1290, 1284,
+ /*   340 */  1281, 1286, 1285, 1289, 1288, 1188, 1291, 1195, 1288, 1192,
+ /*   350 */  1293, 1198, 1202, 1206, 1295, 1299, 1292, 1277, 1303, 1287,
+ /*   360 */  1304, 1305, 1307, 1308, 1294, 1309, 1233, 1227, 1316, 1317,
+ /*   370 */  1312, 1237, 1300, 1296, 1297, 1315, 1298, 1205, 1242, 1322,
+ /*   380 */  1342, 1347, 1244, 1301, 1302, 1225, 1330, 1238, 1352, 1338,
+ /*   390 */  1236, 1337, 1243, 1253, 1234, 1339, 1235, 1340, 1348, 1306,
+ /*   400 */  1349, 1228, 1346, 1366, 1367,
 };
-#define YY_REDUCE_USE_DFLT (-145)
+#define YY_REDUCE_USE_DFLT (-142)
 #define YY_REDUCE_MAX 303
 static const short yy_reduce_ofst[] = {
- /*     0 */  -141,  150,  990,   16,  277,   71,   80,  208, -126,  270,
- /*    10 */  -111,    6,  223,  225,  214,  281,   11,  222,  213,  292,
- /*    20 */   155,  298,  342,  241,  136,  136,  136,  136,  136,  136,
- /*    30 */   136,  136,  136,  136,  136,  136,  136,  136,  136,  136,
- /*    40 */   136,  136,  136,  136,  136,  136,  136,  136,  136,  136,
- /*    50 */   136,  136,  136,  136,  136,  136,  352,  357,  493,  498,
- /*    60 */   502,  504,  506,  508,  510,  563,  569,  571,  574,  576,
- /*    70 */   578,  580,  583,  621,  634,  636,  640,  642,  646,  648,
- /*    80 */   650,  653,  692,  705,  707,  711,  713,  718,  720,  722,
- /*    90 */   724,  763,  776,  778,  782,  784,  791,  136,  136,  136,
- /*   100 */   136,  190,  136,  136,  -79,  304,  777,  641,  103, -140,
- /*   110 */   103,  103,  103,  103,  350,  115,  187,  475,  487,  487,
- /*   120 */   594,  379,  605,  411,  581, -144,   69,  122,  678,  675,
- /*   130 */   647,  749,  179,  727,  738,  739,  779,  792,  809,  810,
- /*   140 */   655,  811,   99,  697,  774,  838,  839,  603,  670,  698,
- /*   150 */   -98,   50,   53,  133,  189,  236,  189,  189,  269,  370,
- /*   160 */   384,  455,  189,  586,  550,  572,  654,  710,  723,  797,
- /*   170 */   820,  623,  550,  858,  801,  872,  887,  586,  892,  893,
- /*   180 */   905,  918,  920,  889,  895,  897,  930,  931,  932,  189,
- /*   190 */   938,  939,  189,  942,  852,  859,  944,  946,  189,  947,
- /*   200 */   948,  950,  189,  951,  953,  954,  189,  189,  955,  956,
- /*   210 */   957,  958,  959,  960,  915,  914,  961,  880,  883,  891,
- /*   220 */   945,  949,  911,  952,  941,  962,  964,  963,  965,  966,
- /*   230 */   926,  923,  924,  935,  986,  987,  988,  993,  994,  999,
- /*   240 */   996,  967,  971,  972,  973,  969,  974,  978, 1009, 1018,
- /*   250 */   975,  979,  983,  980, 1000,  997, 1006, 1007, 1008, 1011,
- /*   260 */  1026, 1033, 1035,  985,  989, 1037, 1046, 1047, 1049, 1048,
- /*   270 */  1070, 1071, 1073, 1074, 1076, 1078, 1079, 1001, 1002, 1082,
- /*   280 */  1083, 1054, 1056, 1031, 1050, 1090, 1060, 1061, 1063, 1065,
- /*   290 */  1055, 1067, 1039, 1102, 1021, 1022, 1110, 1111, 1032, 1106,
- /*   300 */  1091, 1092, 1036, 1043,
+ /*     0 */  -141,  -49,  140,   77,  198,   67,   75,   -8,   66,  225,
+ /*    10 */   165,  142,  209,  277,  279,  281,  130,  286,   81,  275,
+ /*    20 */   196,  288,  293,  228,   83,   83,   83,   83,   83,   83,
+ /*    30 */    83,   83,   83,   83,   83,   83,   83,   83,   83,   83,
+ /*    40 */    83,   83,   83,   83,   83,   83,   83,   83,   83,   83,
+ /*    50 */    83,   83,   83,   83,   83,   83,  349,  467,  493,  536,
+ /*    60 */   555,  558,  561,  563,  565,  567,  605,  618,  622,  624,
+ /*    70 */   626,  630,  633,  636,  674,  687,  691,  693,  695,  699,
+ /*    80 */   704,  743,  756,  760,  762,  764,  768,  773,  775,  812,
+ /*    90 */   825,  829,  831,  833,  837,  842,  844,   83,   83,   83,
+ /*   100 */    83,  -17,   83,   83,  333,  361,   22,  566,   83, -124,
+ /*   110 */    83,   83,   83,   83,  609,    1,  481,  517,  475,  475,
+ /*   120 */   625,  220,  -45,  709,  774,  417,  729,  757,  758,  384,
+ /*   130 */   231,  826,  214,  371,  512,  658,  863,  869,  881,  894,
+ /*   140 */   637,  895,  301,  612,  752,  887,  888,   90,  650,  593,
+ /*   150 */  -100,  -79,  -59,   -7,   38,   87,   38,   38,  101,  224,
+ /*   160 */   270,  297,   38,  290,  355,  430,  398,  451,  631,  696,
+ /*   170 */   702,  436,  355,  707,  469,  635,  771,  290,  790,  834,
+ /*   180 */   847,  859,  915,  727,  890,  896,  921,  929,  939,   38,
+ /*   190 */   942,  945,   38,  946,  864,  866,  958,  959,   38,  960,
+ /*   200 */   961,  964,   38,  967,  968,  969,   38,   38,  973,  974,
+ /*   210 */   975,  976,  977,  954,  917,  916,  950,  884,  897,  893,
+ /*   220 */   952,  971,  925,  972,  953,  978,  979,  980,  984,  981,
+ /*   230 */   938,  930,  931,  947,  994, 1001, 1003, 1006, 1008, 1011,
+ /*   240 */  1007,  985,  982,  983,  987,  988,  986,  990, 1037, 1039,
+ /*   250 */   991,  989,  992,  993,  995,  996, 1030, 1032, 1026, 1035,
+ /*   260 */  1036, 1042, 1043,  997,  998, 1046, 1053, 1055, 1062, 1056,
+ /*   270 */  1064, 1079, 1065, 1082, 1084, 1085, 1086, 1010, 1012, 1089,
+ /*   280 */  1092, 1063, 1069, 1047, 1066, 1097, 1070, 1071, 1072, 1087,
+ /*   290 */  1068, 1080, 1061, 1104, 1048, 1050, 1119, 1120, 1067, 1117,
+ /*   300 */  1102, 1103, 1073, 1074,
 };
 static const YYACTIONTYPE yy_default[] = {
  /*     0 */   615,  929,  848,  736,  929,  848,  929,  929,  875,  929,
@@ -85171,9 +83520,9 @@ static const YYCODETYPE yyFallback[] = {
    26,  /*  EXCLUSIVE =&gt; ID */
     0,  /*     COMMIT =&gt; nothing */
    26,  /*        END =&gt; ID */
-   26,  /*   ROLLBACK =&gt; ID */
-   26,  /*  SAVEPOINT =&gt; ID */
-   26,  /*    RELEASE =&gt; ID */
+    0,  /*   ROLLBACK =&gt; nothing */
+    0,  /*  SAVEPOINT =&gt; nothing */
+    0,  /*    RELEASE =&gt; nothing */
     0,  /*         TO =&gt; nothing */
     0,  /*     CREATE =&gt; nothing */
     0,  /*      TABLE =&gt; nothing */
@@ -85192,10 +83541,8 @@ static const YYCODETYPE yyFallback[] = {
    26,  /*        ASC =&gt; ID */
    26,  /*     ATTACH =&gt; ID */
    26,  /*     BEFORE =&gt; ID */
-   26,  /*         BY =&gt; ID */
    26,  /*    CASCADE =&gt; ID */
    26,  /*       CAST =&gt; ID */
-   26,  /*   COLUMNKW =&gt; ID */
    26,  /*   CONFLICT =&gt; ID */
    26,  /*   DATABASE =&gt; ID */
    26,  /*       DESC =&gt; ID */
@@ -85280,6 +83627,7 @@ static const YYCODETYPE yyFallback[] = {
     0,  /*       FROM =&gt; nothing */
     0,  /*       JOIN =&gt; nothing */
     0,  /*    INDEXED =&gt; nothing */
+    0,  /*         BY =&gt; nothing */
     0,  /*      USING =&gt; nothing */
     0,  /*      ORDER =&gt; nothing */
     0,  /*      GROUP =&gt; nothing */
@@ -85300,6 +83648,7 @@ static const YYCODETYPE yyFallback[] = {
     0,  /*      INDEX =&gt; nothing */
     0,  /*      ALTER =&gt; nothing */
     0,  /*        ADD =&gt; nothing */
+    0,  /*   COLUMNKW =&gt; nothing */
 };
 #endif /* YYFALLBACK */
 
@@ -85385,34 +83734,34 @@ static const char *const yyTokenName[] = {
   &quot;EXISTS&quot;,        &quot;TEMP&quot;,          &quot;LP&quot;,            &quot;RP&quot;,          
   &quot;AS&quot;,            &quot;COMMA&quot;,         &quot;ID&quot;,            &quot;ABORT&quot;,       
   &quot;AFTER&quot;,         &quot;ANALYZE&quot;,       &quot;ASC&quot;,           &quot;ATTACH&quot;,      
-  &quot;BEFORE&quot;,        &quot;BY&quot;,            &quot;CASCADE&quot;,       &quot;CAST&quot;,        
-  &quot;COLUMNKW&quot;,      &quot;CONFLICT&quot;,      &quot;DATABASE&quot;,      &quot;DESC&quot;,        
-  &quot;DETACH&quot;,        &quot;EACH&quot;,          &quot;FAIL&quot;,          &quot;FOR&quot;,         
-  &quot;IGNORE&quot;,        &quot;INITIALLY&quot;,     &quot;INSTEAD&quot;,       &quot;LIKE_KW&quot;,     
-  &quot;MATCH&quot;,         &quot;KEY&quot;,           &quot;OF&quot;,            &quot;OFFSET&quot;,      
-  &quot;PRAGMA&quot;,        &quot;RAISE&quot;,         &quot;REPLACE&quot;,       &quot;RESTRICT&quot;,    
-  &quot;ROW&quot;,           &quot;TRIGGER&quot;,       &quot;VACUUM&quot;,        &quot;VIEW&quot;,        
-  &quot;VIRTUAL&quot;,       &quot;REINDEX&quot;,       &quot;RENAME&quot;,        &quot;CTIME_KW&quot;,    
-  &quot;ANY&quot;,           &quot;OR&quot;,            &quot;AND&quot;,           &quot;IS&quot;,          
-  &quot;BETWEEN&quot;,       &quot;IN&quot;,            &quot;ISNULL&quot;,        &quot;NOTNULL&quot;,     
-  &quot;NE&quot;,            &quot;EQ&quot;,            &quot;GT&quot;,            &quot;LE&quot;,          
-  &quot;LT&quot;,            &quot;GE&quot;,            &quot;ESCAPE&quot;,        &quot;BITAND&quot;,      
-  &quot;BITOR&quot;,         &quot;LSHIFT&quot;,        &quot;RSHIFT&quot;,        &quot;PLUS&quot;,        
-  &quot;MINUS&quot;,         &quot;STAR&quot;,          &quot;SLASH&quot;,         &quot;REM&quot;,         
-  &quot;CONCAT&quot;,        &quot;COLLATE&quot;,       &quot;UMINUS&quot;,        &quot;UPLUS&quot;,       
-  &quot;BITNOT&quot;,        &quot;STRING&quot;,        &quot;JOIN_KW&quot;,       &quot;CONSTRAINT&quot;,  
-  &quot;DEFAULT&quot;,       &quot;NULL&quot;,          &quot;PRIMARY&quot;,       &quot;UNIQUE&quot;,      
-  &quot;CHECK&quot;,         &quot;REFERENCES&quot;,    &quot;AUTOINCR&quot;,      &quot;ON&quot;,          
-  &quot;DELETE&quot;,        &quot;UPDATE&quot;,        &quot;INSERT&quot;,        &quot;SET&quot;,         
-  &quot;DEFERRABLE&quot;,    &quot;FOREIGN&quot;,       &quot;DROP&quot;,          &quot;UNION&quot;,       
-  &quot;ALL&quot;,           &quot;EXCEPT&quot;,        &quot;INTERSECT&quot;,     &quot;SELECT&quot;,      
-  &quot;DISTINCT&quot;,      &quot;DOT&quot;,           &quot;FROM&quot;,          &quot;JOIN&quot;,        
-  &quot;INDEXED&quot;,       &quot;USING&quot;,         &quot;ORDER&quot;,         &quot;GROUP&quot;,       
-  &quot;HAVING&quot;,        &quot;LIMIT&quot;,         &quot;WHERE&quot;,         &quot;INTO&quot;,        
-  &quot;VALUES&quot;,        &quot;INTEGER&quot;,       &quot;FLOAT&quot;,         &quot;BLOB&quot;,        
-  &quot;REGISTER&quot;,      &quot;VARIABLE&quot;,      &quot;CASE&quot;,          &quot;WHEN&quot;,        
-  &quot;THEN&quot;,          &quot;ELSE&quot;,          &quot;INDEX&quot;,         &quot;ALTER&quot;,       
-  &quot;ADD&quot;,           &quot;error&quot;,         &quot;input&quot;,         &quot;cmdlist&quot;,     
+  &quot;BEFORE&quot;,        &quot;CASCADE&quot;,       &quot;CAST&quot;,          &quot;CONFLICT&quot;,    
+  &quot;DATABASE&quot;,      &quot;DESC&quot;,          &quot;DETACH&quot;,        &quot;EACH&quot;,        
+  &quot;FAIL&quot;,          &quot;FOR&quot;,           &quot;IGNORE&quot;,        &quot;INITIALLY&quot;,   
+  &quot;INSTEAD&quot;,       &quot;LIKE_KW&quot;,       &quot;MATCH&quot;,         &quot;KEY&quot;,         
+  &quot;OF&quot;,            &quot;OFFSET&quot;,        &quot;PRAGMA&quot;,        &quot;RAISE&quot;,       
+  &quot;REPLACE&quot;,       &quot;RESTRICT&quot;,      &quot;ROW&quot;,           &quot;TRIGGER&quot;,     
+  &quot;VACUUM&quot;,        &quot;VIEW&quot;,          &quot;VIRTUAL&quot;,       &quot;REINDEX&quot;,     
+  &quot;RENAME&quot;,        &quot;CTIME_KW&quot;,      &quot;ANY&quot;,           &quot;OR&quot;,          
+  &quot;AND&quot;,           &quot;IS&quot;,            &quot;BETWEEN&quot;,       &quot;IN&quot;,          
+  &quot;ISNULL&quot;,        &quot;NOTNULL&quot;,       &quot;NE&quot;,            &quot;EQ&quot;,          
+  &quot;GT&quot;,            &quot;LE&quot;,            &quot;LT&quot;,            &quot;GE&quot;,          
+  &quot;ESCAPE&quot;,        &quot;BITAND&quot;,        &quot;BITOR&quot;,         &quot;LSHIFT&quot;,      
+  &quot;RSHIFT&quot;,        &quot;PLUS&quot;,          &quot;MINUS&quot;,         &quot;STAR&quot;,        
+  &quot;SLASH&quot;,         &quot;REM&quot;,           &quot;CONCAT&quot;,        &quot;COLLATE&quot;,     
+  &quot;UMINUS&quot;,        &quot;UPLUS&quot;,         &quot;BITNOT&quot;,        &quot;STRING&quot;,      
+  &quot;JOIN_KW&quot;,       &quot;CONSTRAINT&quot;,    &quot;DEFAULT&quot;,       &quot;NULL&quot;,        
+  &quot;PRIMARY&quot;,       &quot;UNIQUE&quot;,        &quot;CHECK&quot;,         &quot;REFERENCES&quot;,  
+  &quot;AUTOINCR&quot;,      &quot;ON&quot;,            &quot;DELETE&quot;,        &quot;UPDATE&quot;,      
+  &quot;INSERT&quot;,        &quot;SET&quot;,           &quot;DEFERRABLE&quot;,    &quot;FOREIGN&quot;,     
+  &quot;DROP&quot;,          &quot;UNION&quot;,         &quot;ALL&quot;,           &quot;EXCEPT&quot;,      
+  &quot;INTERSECT&quot;,     &quot;SELECT&quot;,        &quot;DISTINCT&quot;,      &quot;DOT&quot;,         
+  &quot;FROM&quot;,          &quot;JOIN&quot;,          &quot;INDEXED&quot;,       &quot;BY&quot;,          
+  &quot;USING&quot;,         &quot;ORDER&quot;,         &quot;GROUP&quot;,         &quot;HAVING&quot;,      
+  &quot;LIMIT&quot;,         &quot;WHERE&quot;,         &quot;INTO&quot;,          &quot;VALUES&quot;,      
+  &quot;INTEGER&quot;,       &quot;FLOAT&quot;,         &quot;BLOB&quot;,          &quot;REGISTER&quot;,    
+  &quot;VARIABLE&quot;,      &quot;CASE&quot;,          &quot;WHEN&quot;,          &quot;THEN&quot;,        
+  &quot;ELSE&quot;,          &quot;INDEX&quot;,         &quot;ALTER&quot;,         &quot;ADD&quot;,         
+  &quot;COLUMNKW&quot;,      &quot;error&quot;,         &quot;input&quot;,         &quot;cmdlist&quot;,     
   &quot;ecmd&quot;,          &quot;explain&quot;,       &quot;cmdx&quot;,          &quot;cmd&quot;,         
   &quot;transtype&quot;,     &quot;trans_opt&quot;,     &quot;nm&quot;,            &quot;savepoint_opt&quot;,
   &quot;create_table&quot;,  &quot;create_table_args&quot;,  &quot;temp&quot;,          &quot;ifnotexists&quot;, 
@@ -87537,8 +85886,8 @@ static void yy_reduce(
     if( yysize ){
       yypParser-&gt;yyidx++;
       yymsp -= yysize-1;
-      yymsp-&gt;stateno = (YYACTIONTYPE)yyact;
-      yymsp-&gt;major = (YYCODETYPE)yygoto;
+      yymsp-&gt;stateno = yyact;
+      yymsp-&gt;major = yygoto;
       yymsp-&gt;minor = yygotominor;
     }else
 #endif
@@ -87782,7 +86131,7 @@ SQLITE_PRIVATE void sqlite3Parser(
 ** individual tokens and sends those tokens one-by-one over to the
 ** parser for analysis.
 **
-** $Id: tokenize.c,v 1.153 2009/01/20 16:53:41 danielk1977 Exp $
+** $Id: tokenize.c,v 1.152 2008/09/01 15:52:11 drh Exp $
 */
 
 /*
@@ -87835,7 +86184,7 @@ const unsigned char ebcdicToAscii[] = {
 **
 ** The code in this file has been automatically generated by
 **
-**     $Header: /sqlite/sqlite/tool/mkkeywordhash.c,v 1.37 2009/02/01 00:00:46 drh Exp $
+**     $Header: /sqlite/sqlite/tool/mkkeywordhash.c,v 1.36 2008/12/31 21:52:41 drh Exp $
 **
 ** The code in this file implements a function that determines whether
 ** or not a given identifier is really an SQL keyword.  The same thing
@@ -88158,7 +86507,7 @@ SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *z, int *tokenType){
   int i, c;
   switch( *z ){
     case ' ': case '\t': case '\n': case '\f': case '\r': {
-      for(i=1; sqlite3Isspace(z[i]); i++){}
+      for(i=1; isspace(z[i]); i++){}
       *tokenType = TK_SPACE;
       return i;
     }
@@ -88292,7 +86641,7 @@ SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *z, int *tokenType){
     }
     case '.': {
 #ifndef SQLITE_OMIT_FLOATING_POINT
-      if( !sqlite3Isdigit(z[1]) )
+      if( !isdigit(z[1]) )
 #endif
       {
         *tokenType = TK_DOT;
@@ -88304,20 +86653,20 @@ SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *z, int *tokenType){
     case '0': case '1': case '2': case '3': case '4':
     case '5': case '6': case '7': case '8': case '9': {
       *tokenType = TK_INTEGER;
-      for(i=0; sqlite3Isdigit(z[i]); i++){}
+      for(i=0; isdigit(z[i]); i++){}
 #ifndef SQLITE_OMIT_FLOATING_POINT
       if( z[i]=='.' ){
         i++;
-        while( sqlite3Isdigit(z[i]) ){ i++; }
+        while( isdigit(z[i]) ){ i++; }
         *tokenType = TK_FLOAT;
       }
       if( (z[i]=='e' || z[i]=='E') &amp;&amp;
-           ( sqlite3Isdigit(z[i+1]) 
-            || ((z[i+1]=='+' || z[i+1]=='-') &amp;&amp; sqlite3Isdigit(z[i+2]))
+           ( isdigit(z[i+1]) 
+            || ((z[i+1]=='+' || z[i+1]=='-') &amp;&amp; isdigit(z[i+2]))
            )
       ){
         i += 2;
-        while( sqlite3Isdigit(z[i]) ){ i++; }
+        while( isdigit(z[i]) ){ i++; }
         *tokenType = TK_FLOAT;
       }
 #endif
@@ -88334,11 +86683,11 @@ SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *z, int *tokenType){
     }
     case '?': {
       *tokenType = TK_VARIABLE;
-      for(i=1; sqlite3Isdigit(z[i]); i++){}
+      for(i=1; isdigit(z[i]); i++){}
       return i;
     }
     case '#': {
-      for(i=1; sqlite3Isdigit(z[i]); i++){}
+      for(i=1; isdigit(z[i]); i++){}
       if( i&gt;1 ){
         /* Parameters of the form #NNN (where NNN is a number) are used
         ** internally by sqlite3NestedParse.  */
@@ -88362,7 +86711,7 @@ SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *z, int *tokenType){
         }else if( c=='(' &amp;&amp; n&gt;0 ){
           do{
             i++;
-          }while( (c=z[i])!=0 &amp;&amp; !sqlite3Isspace(c) &amp;&amp; c!=')' );
+          }while( (c=z[i])!=0 &amp;&amp; !isspace(c) &amp;&amp; c!=')' );
           if( c==')' ){
             i++;
           }else{
@@ -88384,7 +86733,7 @@ SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *z, int *tokenType){
       if( z[1]=='\'' ){
         *tokenType = TK_BLOB;
         for(i=2; (c=z[i])!=0 &amp;&amp; c!='\''; i++){
-          if( !sqlite3Isxdigit(c) ){
+          if( !isxdigit(c) ){
             *tokenType = TK_ILLEGAL;
           }
         }
@@ -88846,7 +87195,7 @@ SQLITE_API int sqlite3_complete16(const void *zSql){
 ** other files are for internal use by SQLite and should not be
 ** accessed by users of the library.
 **
-** $Id: main.c,v 1.528 2009/02/05 16:31:46 drh Exp $
+** $Id: main.c,v 1.521 2009/01/10 16:15:22 drh Exp $
 */
 
 #ifdef SQLITE_ENABLE_FTS3
@@ -89110,7 +87459,6 @@ SQLITE_API int sqlite3_initialize(void){
   ** reason.  So we run it once during initialization.
   */
 #ifndef NDEBUG
-#ifndef SQLITE_OMIT_FLOATING_POINT
   /* This section of code's only &quot;output&quot; is via assert() statements. */
   if ( rc==SQLITE_OK ){
     u64 x = (((u64)1)&lt;&lt;63)-1;
@@ -89121,7 +87469,6 @@ SQLITE_API int sqlite3_initialize(void){
     assert( sqlite3IsNaN(y) );
   }
 #endif
-#endif
 
   return rc;
 }
@@ -89307,22 +87654,9 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
   if( db-&gt;lookaside.nOut ){
     return SQLITE_BUSY;
   }
-  /* Free any existing lookaside buffer for this handle before
-  ** allocating a new one so we don't have to have space for 
-  ** both at the same time.
-  */
-  if( db-&gt;lookaside.bMalloced ){
-    sqlite3_free(db-&gt;lookaside.pStart);
-  }
-  /* The size of a lookaside slot needs to be larger than a pointer
-  ** to be useful.
-  */
-  if( sz&lt;=(int)sizeof(LookasideSlot*) ) sz = 0;
+  if( sz&lt;0 ) sz = 0;
   if( cnt&lt;0 ) cnt = 0;
-  if( sz==0 || cnt==0 ){
-    sz = 0;
-    pStart = 0;
-  }else if( pBuf==0 ){
+  if( pBuf==0 ){
     sz = (sz + 7)&amp;~7;
     sqlite3BeginBenignMalloc();
     pStart = sqlite3Malloc( sz*cnt );
@@ -89331,13 +87665,16 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
     sz = sz&amp;~7;
     pStart = pBuf;
   }
+  if( db-&gt;lookaside.bMalloced ){
+    sqlite3_free(db-&gt;lookaside.pStart);
+  }
   db-&gt;lookaside.pStart = pStart;
   db-&gt;lookaside.pFree = 0;
   db-&gt;lookaside.sz = (u16)sz;
+  db-&gt;lookaside.bMalloced = pBuf==0 ?1:0;
   if( pStart ){
     int i;
     LookasideSlot *p;
-    assert( sz &gt; sizeof(LookasideSlot*) );
     p = (LookasideSlot*)pStart;
     for(i=cnt-1; i&gt;=0; i--){
       p-&gt;pNext = db-&gt;lookaside.pFree;
@@ -89346,11 +87683,9 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
     }
     db-&gt;lookaside.pEnd = p;
     db-&gt;lookaside.bEnabled = 1;
-    db-&gt;lookaside.bMalloced = pBuf==0 ?1:0;
   }else{
     db-&gt;lookaside.pEnd = 0;
     db-&gt;lookaside.bEnabled = 0;
-    db-&gt;lookaside.bMalloced = 0;
   }
   return SQLITE_OK;
 }
@@ -89518,22 +87853,12 @@ SQLITE_API int sqlite3_close(sqlite3 *db){
   /* If there are any outstanding VMs, return SQLITE_BUSY. */
   if( db-&gt;pVdbe ){
     sqlite3Error(db, SQLITE_BUSY, 
-        &quot;unable to close due to unfinalised statements&quot;);
+        &quot;Unable to close due to unfinalised statements&quot;);
     sqlite3_mutex_leave(db-&gt;mutex);
     return SQLITE_BUSY;
   }
   assert( sqlite3SafetyCheckSickOrOk(db) );
 
-  for(j=0; j&lt;db-&gt;nDb; j++){
-    Btree *pBt = db-&gt;aDb[j].pBt;
-    if( pBt &amp;&amp; sqlite3BtreeIsInBackup(pBt) ){
-      sqlite3Error(db, SQLITE_BUSY, 
-          &quot;unable to close due to unfinished backup operation&quot;);
-      sqlite3_mutex_leave(db-&gt;mutex);
-      return SQLITE_BUSY;
-    }
-  }
-
   /* Free any outstanding Savepoint structures. */
   sqlite3CloseSavepoints(db);
 
@@ -89874,7 +88199,7 @@ SQLITE_PRIVATE int sqlite3CreateFunc(
   if( p &amp;&amp; p-&gt;iPrefEnc==enc &amp;&amp; p-&gt;nArg==nArg ){
     if( db-&gt;activeVdbeCnt ){
       sqlite3Error(db, SQLITE_BUSY, 
-        &quot;unable to delete/modify user-function due to active statements&quot;);
+        &quot;Unable to delete/modify user-function due to active statements&quot;);
       assert( !db-&gt;mallocFailed );
       return SQLITE_BUSY;
     }else{
@@ -90284,7 +88609,7 @@ static int createCollation(
   if( pColl &amp;&amp; pColl-&gt;xCmp ){
     if( db-&gt;activeVdbeCnt ){
       sqlite3Error(db, SQLITE_BUSY, 
-        &quot;unable to delete/modify collation sequence due to active statements&quot;);
+        &quot;Unable to delete/modify collation sequence due to active statements&quot;);
       return SQLITE_BUSY;
     }
     sqlite3ExpirePreparedStatements(db);
@@ -91069,25 +89394,6 @@ SQLITE_API int sqlite3_test_control(int op, ...){
       sqlite3BenignMallocHooks(xBenignBegin, xBenignEnd);
       break;
     }
-
-    /*
-    **  sqlite3_test_control(PENDING_BYTE, unsigned int X)
-    **
-    ** Set the PENDING byte to the value in the argument, if X&gt;0.
-    ** Make no changes if X==0.  Return the value of the pending byte
-    ** as it existing before this routine was called.
-    **
-    ** IMPORTANT:  Changing the PENDING byte from 0x40000000 results in
-    ** an incompatible database file format.  Changing the PENDING byte
-    ** while any database connection is open results in undefined and
-    ** dileterious behavior.
-    */
-    case SQLITE_TESTCTRL_PENDING_BYTE: {
-      unsigned int newVal = va_arg(ap, unsigned int);
-      rc = sqlite3PendingByte;
-      if( newVal ) sqlite3PendingByte = newVal;
-      break;
-    }
   }
   va_end(ap);
 #endif /* SQLITE_OMIT_BUILTIN_TEST */
@@ -91509,10 +89815,7 @@ struct sqlite3_tokenizer_module {
   ** stemming has been performed). *pnBytes should be set to the length
   ** of this buffer in bytes. The input text that generated the token is
   ** identified by the byte offsets returned in *piStartOffset and
-  ** *piEndOffset. *piStartOffset should be set to the index of the first
-  ** byte of the token in the input buffer. *piEndOffset should be set
-  ** to the index of the first byte just past the end of the token in
-  ** the input buffer.
+  ** *piEndOffset.
   **
   ** The buffer *ppToken is set to point at is managed by the tokenizer
   ** implementation. It is only required to be valid until the next call
@@ -98621,8 +96924,8 @@ static int getNextToken(
           pRet-&gt;pPhrase-&gt;isNot = 1;
         }
       }
-      nConsumed = iEnd;
     }
+    nConsumed = iEnd;
 
     pModule-&gt;xClose(pCursor);
   }</diff>
      <filename>ext/sqlite3.c</filename>
    </modified>
    <modified>
      <diff>@@ -30,7 +30,7 @@
 ** the version number) and changes its name to &quot;sqlite3.h&quot; as
 ** part of the build process.
 **
-** @(#) $Id: sqlite.h.in,v 1.432 2009/02/12 17:07:35 drh Exp $
+** @(#) $Id: sqlite.h.in,v 1.421 2008/12/30 06:24:58 danielk1977 Exp $
 */
 #ifndef _SQLITE3_H_
 #define _SQLITE3_H_
@@ -107,8 +107,8 @@ extern &quot;C&quot; {
 **          with the value (X*1000000 + Y*1000 + Z) where X, Y, and Z
 **          are the major version, minor version, and release number.
 */
-#define SQLITE_VERSION         &quot;3.6.11&quot;
-#define SQLITE_VERSION_NUMBER  3006011
+#define SQLITE_VERSION         &quot;3.6.10&quot;
+#define SQLITE_VERSION_NUMBER  3006010
 
 /*
 ** CAPI3REF: Run-Time Library Version Numbers {H10020} &lt;S60100&gt;
@@ -2789,10 +2789,8 @@ typedef struct sqlite3_stmt sqlite3_stmt;
 ** new limit for that construct.  The function returns the old limit.
 **
 ** If the new limit is a negative number, the limit is unchanged.
-** For the limit category of SQLITE_LIMIT_XYZ there is a 
-** [limits | hard upper bound]
-** set by a compile-time C preprocessor macro named 
-** [limits | SQLITE_MAX_XYZ].
+** For the limit category of SQLITE_LIMIT_XYZ there is a hard upper
+** bound set by a compile-time C preprocessor macro named SQLITE_MAX_XYZ.
 ** (The &quot;_LIMIT_&quot; in the name is changed to &quot;_MAX_&quot;.)
 ** Attempts to increase a limit above its hard upper bound are
 ** silently truncated to the hard upper limit.
@@ -2800,7 +2798,7 @@ typedef struct sqlite3_stmt sqlite3_stmt;
 ** Run time limits are intended for use in applications that manage
 ** both their own internal database and also databases that are controlled
 ** by untrusted external sources.  An example application might be a
-** web browser that has its own databases for storing history and
+** webbrowser that has its own databases for storing history and
 ** separate databases controlled by JavaScript applications downloaded
 ** off the Internet.  The internal databases can be given the
 ** large, default limits.  Databases managed by external sources can
@@ -2832,10 +2830,9 @@ int sqlite3_limit(sqlite3*, int id, int newVal);
 ** CAPI3REF: Run-Time Limit Categories {H12790} &lt;H12760&gt;
 ** KEYWORDS: {limit category} {limit categories}
 **
-** These constants define various performance limits
-** that can be lowered at run-time using [sqlite3_limit()].
-** The synopsis of the meanings of the various limits is shown below.
-** Additional information is available at [limits | Limits in SQLite].
+** These constants define various aspects of a [database connection]
+** that can be limited in size by calls to [sqlite3_limit()].
+** The meanings of the various limits are as follows:
 **
 ** &lt;dl&gt;
 ** &lt;dt&gt;SQLITE_LIMIT_LENGTH&lt;/dt&gt;
@@ -2846,7 +2843,7 @@ int sqlite3_limit(sqlite3*, int id, int newVal);
 **
 ** &lt;dt&gt;SQLITE_LIMIT_COLUMN&lt;/dt&gt;
 ** &lt;dd&gt;The maximum number of columns in a table definition or in the
-** result set of a [SELECT] or the maximum number of columns in an index
+** result set of a SELECT or the maximum number of columns in an index
 ** or in an ORDER BY or GROUP BY clause.&lt;/dd&gt;
 **
 ** &lt;dt&gt;SQLITE_LIMIT_EXPR_DEPTH&lt;/dt&gt;
@@ -2863,11 +2860,11 @@ int sqlite3_limit(sqlite3*, int id, int newVal);
 ** &lt;dd&gt;The maximum number of arguments on a function.&lt;/dd&gt;
 **
 ** &lt;dt&gt;SQLITE_LIMIT_ATTACHED&lt;/dt&gt;
-** &lt;dd&gt;The maximum number of [ATTACH | attached databases].&lt;/dd&gt;
+** &lt;dd&gt;The maximum number of attached databases.&lt;/dd&gt;
 **
 ** &lt;dt&gt;SQLITE_LIMIT_LIKE_PATTERN_LENGTH&lt;/dt&gt;
-** &lt;dd&gt;The maximum length of the pattern argument to the [LIKE] or
-** [GLOB] operators.&lt;/dd&gt;
+** &lt;dd&gt;The maximum length of the pattern argument to the LIKE or
+** GLOB operators.&lt;/dd&gt;
 **
 ** &lt;dt&gt;SQLITE_LIMIT_VARIABLE_NUMBER&lt;/dt&gt;
 ** &lt;dd&gt;The maximum number of variables in an SQL statement that can
@@ -3102,7 +3099,7 @@ typedef struct sqlite3_context sqlite3_context;
 ** KEYWORDS: {SQL parameter} {SQL parameters} {parameter binding}
 **
 ** In the SQL strings input to [sqlite3_prepare_v2()] and its variants,
-** literals may be replaced by a [parameter] in one of these forms:
+** literals may be replaced by a parameter in one of these forms:
 **
 ** &lt;ul&gt;
 ** &lt;li&gt;  ?
@@ -4980,8 +4977,8 @@ int sqlite3_get_autocommit(sqlite3*);
 ** CAPI3REF: Find The Database Handle Of A Prepared Statement {H13120} &lt;S60600&gt;
 **
 ** The sqlite3_db_handle interface returns the [database connection] handle
-** to which a [prepared statement] belongs.  The [database connection]
-** returned by sqlite3_db_handle is the same [database connection] that was the first argument
+** to which a [prepared statement] belongs.  The database handle returned by
+** sqlite3_db_handle is the same database handle that was the first argument
 ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
 ** create the statement in the first place.
 **
@@ -5186,7 +5183,7 @@ void *sqlite3_update_hook(
 ** to the same database. Sharing is enabled if the argument is true
 ** and disabled if the argument is false.
 **
-** Cache sharing is enabled and disabled for an entire process.
+** Cache sharing is enabled and disabled for an entire process. {END}
 ** This is a change as of SQLite version 3.5.0. In prior versions of SQLite,
 ** sharing was enabled or disabled for each thread separately.
 **
@@ -5206,8 +5203,6 @@ void *sqlite3_update_hook(
 ** future releases of SQLite.  Applications that care about shared
 ** cache setting should set it explicitly.
 **
-** See Also:  [SQLite Shared-Cache Mode]
-**
 ** INVARIANTS:
 **
 ** {H10331} A successful invocation of [sqlite3_enable_shared_cache(B)]
@@ -6377,7 +6372,6 @@ int sqlite3_test_control(int op, ...);
 #define SQLITE_TESTCTRL_BITVEC_TEST              8
 #define SQLITE_TESTCTRL_FAULT_INSTALL            9
 #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS     10
-#define SQLITE_TESTCTRL_PENDING_BYTE            11
 
 /*
 ** CAPI3REF: SQLite Runtime Status {H17200} &lt;S60200&gt;
@@ -6667,17 +6661,17 @@ typedef struct sqlite3_pcache sqlite3_pcache;
 **                in which case SQLite will attempt to unpin one or more 
 **                pages before re-requesting the same page, or it can
 **                allocate a new page and return a pointer to it. If a new
-**                page is allocated, then the first sizeof(void*) bytes of
-**                it (at least) must be zeroed before it is returned.
+**                page is allocated, then it must be completely zeroed before 
+**                it is returned.
 **   &lt;tr&gt;&lt;td&gt;2&lt;td&gt;If createFlag is set to 2, then SQLite is not holding any
 **                pinned pages associated with the specific cache passed
 **                as the first argument to xFetch() that can be unpinned. The
 **                cache implementation should attempt to allocate a new
-**                cache entry and return a pointer to it. Again, the first
-**                sizeof(void*) bytes of the page should be zeroed before 
-**                it is returned. If the xFetch() method returns NULL when 
-**                createFlag==2, SQLite assumes that a memory allocation 
-**                failed and returns SQLITE_NOMEM to the user.
+**                cache entry and return a pointer to it. Again, the new
+**                page should be zeroed before it is returned. If the xFetch()
+**                method returns NULL when createFlag==2, SQLite assumes that
+**                a memory allocation failed and returns SQLITE_NOMEM to the
+**                user.
 ** &lt;/table&gt;
 **
 ** xUnpin() is called by SQLite with a pointer to a currently pinned page
@@ -6729,202 +6723,6 @@ struct sqlite3_pcache_methods {
 };
 
 /*
-** CAPI3REF: Online Backup Object
-** EXPERIMENTAL
-**
-** The sqlite3_backup object records state information about an ongoing
-** online backup operation.  The sqlite3_backup object is created by
-** a call to [sqlite3_backup_init()] and is destroyed by a call to
-** [sqlite3_backup_finish()].
-**
-** See Also: [Using the SQLite Online Backup API]
-*/
-typedef struct sqlite3_backup sqlite3_backup;
-
-/*
-** CAPI3REF: Online Backup API.
-** EXPERIMENTAL
-**
-** This API is used to overwrite the contents of one database with that
-** of another. It is useful either for creating backups of databases or
-** for copying in-memory databases to or from persistent files. 
-**
-** See Also: [Using the SQLite Online Backup API]
-**
-** Exclusive access is required to the destination database for the 
-** duration of the operation. However the source database is only
-** read-locked while it is actually being read, it is not locked
-** continuously for the entire operation. Thus, the backup may be
-** performed on a live database without preventing other users from
-** writing to the database for an extended period of time.
-** 
-** To perform a backup operation: 
-**   &lt;ol&gt;
-**     &lt;li&gt;&lt;b&gt;sqlite3_backup_init()&lt;/b&gt; is called once to initialize the
-**         backup, 
-**     &lt;li&gt;&lt;b&gt;sqlite3_backup_step()&lt;/b&gt; is called one or more times to transfer 
-**         the data between the two databases, and finally
-**     &lt;li&gt;&lt;b&gt;sqlite3_backup_finish()&lt;/b&gt; is called to release all resources 
-**         associated with the backup operation. 
-**   &lt;/ol&gt;
-** There should be exactly one call to sqlite3_backup_finish() for each
-** successful call to sqlite3_backup_init().
-**
-** &lt;b&gt;sqlite3_backup_init()&lt;/b&gt;
-**
-** The first two arguments passed to [sqlite3_backup_init()] are the database
-** handle associated with the destination database and the database name 
-** used to attach the destination database to the handle. The database name
-** is &quot;main&quot; for the main database, &quot;temp&quot; for the temporary database, or
-** the name specified as part of the [ATTACH] statement if the destination is
-** an attached database. The third and fourth arguments passed to 
-** sqlite3_backup_init() identify the [database connection]
-** and database name used
-** to access the source database. The values passed for the source and 
-** destination [database connection] parameters must not be the same.
-**
-** If an error occurs within sqlite3_backup_init(), then NULL is returned
-** and an error code and error message written into the [database connection] 
-** passed as the first argument. They may be retrieved using the
-** [sqlite3_errcode()], [sqlite3_errmsg()], and [sqlite3_errmsg16()] functions.
-** Otherwise, if successful, a pointer to an [sqlite3_backup] object is
-** returned. This pointer may be used with the sqlite3_backup_step() and
-** sqlite3_backup_finish() functions to perform the specified backup 
-** operation.
-**
-** &lt;b&gt;sqlite3_backup_step()&lt;/b&gt;
-**
-** Function [sqlite3_backup_step()] is used to copy up to nPage pages between 
-** the source and destination databases, where nPage is the value of the 
-** second parameter passed to sqlite3_backup_step(). If nPage is a negative
-** value, all remaining source pages are copied. If the required pages are 
-** succesfully copied, but there are still more pages to copy before the 
-** backup is complete, it returns [SQLITE_OK]. If no error occured and there 
-** are no more pages to copy, then [SQLITE_DONE] is returned. If an error 
-** occurs, then an SQLite error code is returned. As well as [SQLITE_OK] and
-** [SQLITE_DONE], a call to sqlite3_backup_step() may return [SQLITE_READONLY],
-** [SQLITE_NOMEM], [SQLITE_BUSY], [SQLITE_LOCKED], or an
-** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] extended error code.
-**
-** As well as the case where the destination database file was opened for
-** read-only access, sqlite3_backup_step() may return [SQLITE_READONLY] if
-** the destination is an in-memory database with a different page size
-** from the source database.
-**
-** If sqlite3_backup_step() cannot obtain a required file-system lock, then
-** the [sqlite3_busy_handler | busy-handler function]
-** is invoked (if one is specified). If the 
-** busy-handler returns non-zero before the lock is available, then 
-** [SQLITE_BUSY] is returned to the caller. In this case the call to
-** sqlite3_backup_step() can be retried later. If the source
-** [database connection]
-** is being used to write to the source database when sqlite3_backup_step()
-** is called, then [SQLITE_LOCKED] is returned immediately. Again, in this
-** case the call to sqlite3_backup_step() can be retried later on. If
-** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX], [SQLITE_NOMEM], or
-** [SQLITE_READONLY] is returned, then 
-** there is no point in retrying the call to sqlite3_backup_step(). These 
-** errors are considered fatal. At this point the application must accept 
-** that the backup operation has failed and pass the backup operation handle 
-** to the sqlite3_backup_finish() to release associated resources.
-**
-** Following the first call to sqlite3_backup_step(), an exclusive lock is
-** obtained on the destination file. It is not released until either 
-** sqlite3_backup_finish() is called or the backup operation is complete 
-** and sqlite3_backup_step() returns [SQLITE_DONE]. Additionally, each time 
-** a call to sqlite3_backup_step() is made a [shared lock] is obtained on
-** the source database file. This lock is released before the
-** sqlite3_backup_step() call returns. Because the source database is not
-** locked between calls to sqlite3_backup_step(), it may be modified mid-way
-** through the backup procedure. If the source database is modified by an
-** external process or via a database connection other than the one being
-** used by the backup operation, then the backup will be transparently
-** restarted by the next call to sqlite3_backup_step(). If the source 
-** database is modified by the using the same database connection as is used
-** by the backup operation, then the backup database is transparently 
-** updated at the same time.
-**
-** &lt;b&gt;sqlite3_backup_finish()&lt;/b&gt;
-**
-** Once sqlite3_backup_step() has returned [SQLITE_DONE], or when the 
-** application wishes to abandon the backup operation, the [sqlite3_backup]
-** object should be passed to sqlite3_backup_finish(). This releases all
-** resources associated with the backup operation. If sqlite3_backup_step()
-** has not yet returned [SQLITE_DONE], then any active write-transaction on the
-** destination database is rolled back. The [sqlite3_backup] object is invalid
-** and may not be used following a call to sqlite3_backup_finish().
-**
-** The value returned by sqlite3_backup_finish is [SQLITE_OK] if no error
-** occurred, regardless or whether or not sqlite3_backup_step() was called
-** a sufficient number of times to complete the backup operation. Or, if
-** an out-of-memory condition or IO error occured during a call to
-** sqlite3_backup_step() then [SQLITE_NOMEM] or an
-** [SQLITE_IOERR_ACCESS | SQLITE_IOERR_XXX] error code
-** is returned. In this case the error code and an error message are
-** written to the destination [database connection].
-**
-** A return of [SQLITE_BUSY] or [SQLITE_LOCKED] from sqlite3_backup_step() is
-** not a permanent error and does not affect the return value of
-** sqlite3_backup_finish().
-**
-** &lt;b&gt;sqlite3_backup_remaining(), sqlite3_backup_pagecount()&lt;/b&gt;
-**
-** Each call to sqlite3_backup_step() sets two values stored internally
-** by an [sqlite3_backup] object. The number of pages still to be backed
-** up, which may be queried by sqlite3_backup_remaining(), and the total
-** number of pages in the source database file, which may be queried by
-** sqlite3_backup_pagecount().
-**
-** The values returned by these functions are only updated by
-** sqlite3_backup_step(). If the source database is modified during a backup
-** operation, then the values are not updated to account for any extra
-** pages that need to be updated or the size of the source database file
-** changing.
-**
-** &lt;b&gt;Concurrent Usage of Database Handles&lt;/b&gt;
-**
-** The source [database connection] may be used by the application for other
-** purposes while a backup operation is underway or being initialized.
-** If SQLite is compiled and configured to support threadsafe database
-** connections, then the source database connection may be used concurrently
-** from within other threads.
-**
-** However, the application must guarantee that the destination database
-** connection handle is not passed to any other API (by any thread) after 
-** sqlite3_backup_init() is called and before the corresponding call to
-** sqlite3_backup_finish(). Unfortunately SQLite does not currently check
-** for this, if the application does use the destination [database connection]
-** for some other purpose during a backup operation, things may appear to
-** work correctly but in fact be subtly malfunctioning.  Use of the
-** destination database connection while a backup is in progress might
-** also cause a mutex deadlock.
-**
-** Furthermore, if running in [shared cache mode], the application must
-** guarantee that the shared cache used by the destination database
-** is not accessed while the backup is running. In practice this means
-** that the application must guarantee that the file-system file being 
-** backed up to is not accessed by any connection within the process,
-** not just the specific connection that was passed to sqlite3_backup_init().
-**
-** The [sqlite3_backup] object itself is partially threadsafe. Multiple 
-** threads may safely make multiple concurrent calls to sqlite3_backup_step().
-** However, the sqlite3_backup_remaining() and sqlite3_backup_pagecount()
-** APIs are not strictly speaking threadsafe. If they are invoked at the
-** same time as another thread is invoking sqlite3_backup_step() it is
-** possible that they return invalid values.
-*/
-sqlite3_backup *sqlite3_backup_init(
-  sqlite3 *pDest,                        /* Destination database handle */
-  const char *zDestName,                 /* Destination database name */
-  sqlite3 *pSource,                      /* Source database handle */
-  const char *zSourceName                /* Source database name */
-);
-int sqlite3_backup_step(sqlite3_backup *p, int nPage);
-int sqlite3_backup_finish(sqlite3_backup *p);
-int sqlite3_backup_remaining(sqlite3_backup *p);
-int sqlite3_backup_pagecount(sqlite3_backup *p);
-
-/*
 ** Undo the hack that converts floating point types to integer for
 ** builds on processors without floating point support.
 */</diff>
      <filename>ext/sqlite3.h</filename>
    </modified>
    <modified>
      <diff>@@ -9,7 +9,7 @@ module Amalgalite
 
     MAJOR   = 0
     MINOR   = 7
-    BUILD   = 6
+    BUILD   = 7
 
     #
     # return the Version as an array of MAJOR, MINOR, BUILD</diff>
      <filename>lib/amalgalite/version.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,10 +5,10 @@ describe &quot;Amalgalite::SQLite3::Version&quot; do
   it &quot;should have the sqlite3 version&quot; do
     Amalgalite::SQLite3::VERSION.should =~ /\d\.\d\.\d/
     Amalgalite::SQLite3::Version.to_s.should =~ /\d\.\d\.\d/
-    Amalgalite::SQLite3::Version.to_i.should eql(3006011)
+    Amalgalite::SQLite3::Version.to_i.should eql(3006010)
     Amalgalite::SQLite3::Version::MAJOR.should eql(3)
     Amalgalite::SQLite3::Version::MINOR.should eql(6)
-    Amalgalite::SQLite3::Version::RELEASE.should eql(11)
+    Amalgalite::SQLite3::Version::RELEASE.should eql(10)
     Amalgalite::SQLite3::Version.to_a.should have(3).items
   end
 end</diff>
      <filename>spec/sqlite3/version_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>e4eeda66bbf77e71413070ee5ef0a5a56fd17294</id>
    </parent>
  </parents>
  <author>
    <name>Jeremy Hinegardner</name>
    <email>jeremy@hinegardner.org</email>
  </author>
  <url>http://github.com/copiousfreetime/amalgalite/commit/c0a087c1d9503371b4f2a1755fee03628ac24bde</url>
  <id>c0a087c1d9503371b4f2a1755fee03628ac24bde</id>
  <committed-date>2009-03-04T21:33:46-08:00</committed-date>
  <authored-date>2009-03-04T21:33:46-08:00</authored-date>
  <message>Roll back to SQLite 3.6.10

SQLite 3.6.11 introduced a bug in the substr() sql function.

    http://www.sqlite.org/cvstrac/chngview?cn=6234</message>
  <tree>927381e294f0c61b4db66779d923a255d34b7720</tree>
  <committer>
    <name>Jeremy Hinegardner</name>
    <email>jeremy@hinegardner.org</email>
  </committer>
</commit>
