Fossil SCM

Update to the latest prerelease version fo SQLite 3.7.5.

drh 2011-01-17 02:39 trunk
Commit 464775a520c71127b353ae721a9eea7fab219722
2 files changed +231 -160 +22 -10
+231 -160
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.7.4. By combining all the individual C code files into this
3
+** version 3.7.5. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a one translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -648,13 +648,13 @@
648648
**
649649
** See also: [sqlite3_libversion()],
650650
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651651
** [sqlite_version()] and [sqlite_source_id()].
652652
*/
653
-#define SQLITE_VERSION "3.7.4"
654
-#define SQLITE_VERSION_NUMBER 3007004
655
-#define SQLITE_SOURCE_ID "2010-12-21 21:28:38 b0888047bb6d9ac55e29b9224df2ff650728bb78"
653
+#define SQLITE_VERSION "3.7.5"
654
+#define SQLITE_VERSION_NUMBER 3007005
655
+#define SQLITE_SOURCE_ID "2011-01-17 02:24:12 b93f6f3e679c7710f42580a8dd9ce43136376c1d"
656656
657657
/*
658658
** CAPI3REF: Run-Time Library Version Numbers
659659
** KEYWORDS: sqlite3_version, sqlite3_sourceid
660660
**
@@ -1261,18 +1261,25 @@
12611261
**
12621262
** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
12631263
** to the [sqlite3_file] object associated with a particular database
12641264
** connection. See the [sqlite3_file_control()] documentation for
12651265
** additional information.
1266
+**
1267
+** The [SQLITE_FCNTL_SYNC] opcode is used internally. SQLite calls
1268
+** the file-control method with this opcode immediately after the database
1269
+** file is synced, or if the database is running in synchronous=off mode
1270
+** immediately after it would have been synced otherwise. This makes it
1271
+** easier to write special VFS modules that depend on the xSync call.
12661272
*/
12671273
#define SQLITE_FCNTL_LOCKSTATE 1
12681274
#define SQLITE_GET_LOCKPROXYFILE 2
12691275
#define SQLITE_SET_LOCKPROXYFILE 3
12701276
#define SQLITE_LAST_ERRNO 4
12711277
#define SQLITE_FCNTL_SIZE_HINT 5
12721278
#define SQLITE_FCNTL_CHUNK_SIZE 6
12731279
#define SQLITE_FCNTL_FILE_POINTER 7
1280
+#define SQLITE_FCNTL_SYNC 8
12741281
12751282
12761283
/*
12771284
** CAPI3REF: Mutex Handle
12781285
**
@@ -2407,10 +2414,12 @@
24072414
** guarantees that the buffer is always zero-terminated. ^The first
24082415
** parameter "n" is the total size of the buffer, including space for
24092416
** the zero terminator. So the longest string that can be completely
24102417
** written will be n-1 characters.
24112418
**
2419
+** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
2420
+**
24122421
** These routines all implement some additional formatting
24132422
** options that are useful for constructing SQL statements.
24142423
** All of the usual printf() formatting options apply. In addition, there
24152424
** is are "%q", "%Q", and "%z" options.
24162425
**
@@ -2470,10 +2479,11 @@
24702479
** the result, [sqlite3_free()] is called on the input string.)^
24712480
*/
24722481
SQLITE_API char *sqlite3_mprintf(const char*,...);
24732482
SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
24742483
SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
2484
+SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
24752485
24762486
/*
24772487
** CAPI3REF: Memory Allocation Subsystem
24782488
**
24792489
** The SQLite core uses these three routines for all of its own
@@ -2847,11 +2857,11 @@
28472857
** <dd>The database is opened for reading and writing if possible, or reading
28482858
** only if the file is write protected by the operating system. In either
28492859
** case the database must already exist, otherwise an error is returned.</dd>)^
28502860
**
28512861
** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
2852
-** <dd>The database is opened for reading and writing, and is creates it if
2862
+** <dd>The database is opened for reading and writing, and is created if
28532863
** it does not already exist. This is the behavior that is always used for
28542864
** sqlite3_open() and sqlite3_open16().</dd>)^
28552865
** </dl>
28562866
**
28572867
** If the 3rd parameter to sqlite3_open_v2() is not one of the
@@ -3957,20 +3967,20 @@
39573967
** encoding is used, then the fourth argument should be [SQLITE_ANY].
39583968
**
39593969
** ^(The fifth parameter is an arbitrary pointer. The implementation of the
39603970
** function can gain access to this pointer using [sqlite3_user_data()].)^
39613971
**
3962
-** ^The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
3972
+** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
39633973
** pointers to C-language functions that implement the SQL function or
39643974
** aggregate. ^A scalar SQL function requires an implementation of the xFunc
39653975
** callback only; NULL pointers must be passed as the xStep and xFinal
39663976
** parameters. ^An aggregate SQL function requires an implementation of xStep
39673977
** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
39683978
** SQL function or aggregate, pass NULL poiners for all three function
39693979
** callbacks.
39703980
**
3971
-** ^(If the tenth parameter to sqlite3_create_function_v2() is not NULL,
3981
+** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL,
39723982
** then it is destructor for the application data pointer.
39733983
** The destructor is invoked when the function is deleted, either by being
39743984
** overloaded or when the database connection closes.)^
39753985
** ^The destructor is also invoked if the call to
39763986
** sqlite3_create_function_v2() fails.
@@ -4070,11 +4080,11 @@
40704080
** the function or aggregate.
40714081
**
40724082
** The xFunc (for scalar functions) or xStep (for aggregates) parameters
40734083
** to [sqlite3_create_function()] and [sqlite3_create_function16()]
40744084
** define callbacks that implement the SQL functions and aggregates.
4075
-** The 4th parameter to these callbacks is an array of pointers to
4085
+** The 3rd parameter to these callbacks is an array of pointers to
40764086
** [protected sqlite3_value] objects. There is one [sqlite3_value] object for
40774087
** each parameter to the SQL function. These routines are used to
40784088
** extract values from the [sqlite3_value] objects.
40794089
**
40804090
** These routines work only with [protected sqlite3_value] objects.
@@ -6235,15 +6245,17 @@
62356245
** SQLite will typically create one cache instance for each open database file,
62366246
** though this is not guaranteed. ^The
62376247
** first parameter, szPage, is the size in bytes of the pages that must
62386248
** be allocated by the cache. ^szPage will not be a power of two. ^szPage
62396249
** will the page size of the database file that is to be cached plus an
6240
-** increment (here called "R") of about 100 or 200. SQLite will use the
6250
+** increment (here called "R") of less than 250. SQLite will use the
62416251
** extra R bytes on each page to store metadata about the underlying
62426252
** database page on disk. The value of R depends
62436253
** on the SQLite version, the target platform, and how SQLite was compiled.
6244
-** ^R is constant for a particular build of SQLite. ^The second argument to
6254
+** ^(R is constant for a particular build of SQLite. Except, there are two
6255
+** distinct values of R when SQLite is compiled with the proprietary
6256
+** ZIPVFS extension.)^ ^The second argument to
62456257
** xCreate(), bPurgeable, is true if the cache being created will
62466258
** be used to cache database pages of a file stored on disk, or
62476259
** false if it is used for an in-memory database. The cache implementation
62486260
** does not have to do anything special based with the value of bPurgeable;
62496261
** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
@@ -6271,11 +6283,11 @@
62716283
** is considered to be "pinned".
62726284
**
62736285
** If the requested page is already in the page cache, then the page cache
62746286
** implementation must return a pointer to the page buffer with its content
62756287
** intact. If the requested page is not already in the cache, then the
6276
-** behavior of the cache implementation should use the value of the createFlag
6288
+** cache implementation should use the value of the createFlag
62776289
** parameter to help it determined what action to take:
62786290
**
62796291
** <table border=1 width=85% align=center>
62806292
** <tr><th> createFlag <th> Behaviour when page is not already in cache
62816293
** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
@@ -12051,37 +12063,32 @@
1205112063
** entries or retrieve the key or data from the entry that the cursor
1205212064
** is currently pointing to.
1205312065
**
1205412066
** Every cursor that the virtual machine has open is represented by an
1205512067
** instance of the following structure.
12056
-**
12057
-** If the VdbeCursor.isTriggerRow flag is set it means that this cursor is
12058
-** really a single row that represents the NEW or OLD pseudo-table of
12059
-** a row trigger. The data for the row is stored in VdbeCursor.pData and
12060
-** the rowid is in VdbeCursor.iKey.
1206112068
*/
1206212069
struct VdbeCursor {
1206312070
BtCursor *pCursor; /* The cursor structure of the backend */
12071
+ Btree *pBt; /* Separate file holding temporary table */
12072
+ KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
1206412073
int iDb; /* Index of cursor database in db->aDb[] (or -1) */
12065
- i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
12074
+ int pseudoTableReg; /* Register holding pseudotable content. */
12075
+ int nField; /* Number of fields in the header */
1206612076
Bool zeroed; /* True if zeroed out and ready for reuse */
1206712077
Bool rowidIsValid; /* True if lastRowid is valid */
1206812078
Bool atFirst; /* True if pointing to first entry */
1206912079
Bool useRandomRowid; /* Generate new record numbers semi-randomly */
1207012080
Bool nullRow; /* True if pointing to a row with no data */
1207112081
Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
1207212082
Bool isTable; /* True if a table requiring integer keys */
1207312083
Bool isIndex; /* True if an index containing keys only - no data */
1207412084
Bool isOrdered; /* True if the underlying table is BTREE_UNORDERED */
12075
- i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
12076
- Btree *pBt; /* Separate file holding temporary table */
12077
- int pseudoTableReg; /* Register holding pseudotable content. */
12078
- KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
12079
- int nField; /* Number of fields in the header */
12080
- i64 seqCount; /* Sequence counter */
1208112085
sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
1208212086
const sqlite3_module *pModule; /* Module for cursor pVtabCursor */
12087
+ i64 seqCount; /* Sequence counter */
12088
+ i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
12089
+ i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
1208312090
1208412091
/* Result of last sqlite3BtreeMoveto() done by an OP_NotExists or
1208512092
** OP_IsUnique opcode on this cursor. */
1208612093
int seekResult;
1208712094
@@ -12149,29 +12156,23 @@
1214912156
#define CACHE_STALE 0
1215012157
1215112158
/*
1215212159
** Internally, the vdbe manipulates nearly all SQL values as Mem
1215312160
** structures. Each Mem struct may cache multiple representations (string,
12154
-** integer etc.) of the same value. A value (and therefore Mem structure)
12155
-** has the following properties:
12156
-**
12157
-** Each value has a manifest type. The manifest type of the value stored
12158
-** in a Mem struct is returned by the MemType(Mem*) macro. The type is
12159
-** one of SQLITE_NULL, SQLITE_INTEGER, SQLITE_REAL, SQLITE_TEXT or
12160
-** SQLITE_BLOB.
12161
+** integer etc.) of the same value.
1216112162
*/
1216212163
struct Mem {
12164
+ sqlite3 *db; /* The associated database connection */
12165
+ char *z; /* String or BLOB value */
12166
+ double r; /* Real value */
1216312167
union {
12164
- i64 i; /* Integer value. */
12168
+ i64 i; /* Integer value used when MEM_Int is set in flags */
1216512169
int nZero; /* Used when bit MEM_Zero is set in flags */
1216612170
FuncDef *pDef; /* Used only when flags==MEM_Agg */
1216712171
RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
1216812172
VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
1216912173
} u;
12170
- double r; /* Real value */
12171
- sqlite3 *db; /* The associated database connection */
12172
- char *z; /* String or BLOB value */
1217312174
int n; /* Number of characters in string value, excluding '\0' */
1217412175
u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
1217512176
u8 type; /* One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc */
1217612177
u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
1217712178
#ifdef SQLITE_DEBUG
@@ -12191,13 +12192,10 @@
1219112192
** If the MEM_Str flag is set then Mem.z points at a string representation.
1219212193
** Usually this is encoded in the same unicode encoding as the main
1219312194
** database (see below for exceptions). If the MEM_Term flag is also
1219412195
** set, then the string is nul terminated. The MEM_Int and MEM_Real
1219512196
** flags may coexist with the MEM_Str flag.
12196
-**
12197
-** Multiple of these values can appear in Mem.flags. But only one
12198
-** at a time can appear in Mem.type.
1219912197
*/
1220012198
#define MEM_Null 0x0001 /* Value is NULL */
1220112199
#define MEM_Str 0x0002 /* Value is a string */
1220212200
#define MEM_Int 0x0004 /* Value is an integer */
1220312201
#define MEM_Real 0x0008 /* Value is a real number */
@@ -12276,27 +12274,15 @@
1227612274
Mem *pMem; /* Memory cell used to store aggregate context */
1227712275
int isError; /* Error code returned by the function. */
1227812276
CollSeq *pColl; /* Collating sequence */
1227912277
};
1228012278
12281
-/*
12282
-** A Set structure is used for quick testing to see if a value
12283
-** is part of a small set. Sets are used to implement code like
12284
-** this:
12285
-** x.y IN ('hi','hoo','hum')
12286
-*/
12287
-typedef struct Set Set;
12288
-struct Set {
12289
- Hash hash; /* A set is just a hash table */
12290
- HashElem *prev; /* Previously accessed hash elemen */
12291
-};
12292
-
1229312279
/*
1229412280
** An instance of the virtual machine. This structure contains the complete
1229512281
** state of the virtual machine.
1229612282
**
12297
-** The "sqlite3_stmt" structure pointer that is returned by sqlite3_compile()
12283
+** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
1229812284
** is really a pointer to an instance of this structure.
1229912285
**
1230012286
** The Vdbe.inVtabMethod variable is set to non-zero for the duration of
1230112287
** any virtual table method invocations made by the vdbe program. It is
1230212288
** set to 2 for xDestroy method calls and 1 for all other methods. This
@@ -12305,35 +12291,35 @@
1230512291
** malloc failure when SQLite is invoked recursively by a virtual table
1230612292
** method function.
1230712293
*/
1230812294
struct Vdbe {
1230912295
sqlite3 *db; /* The database connection that owns this statement */
12310
- Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
12311
- int nOp; /* Number of instructions in the program */
12312
- int nOpAlloc; /* Number of slots allocated for aOp[] */
1231312296
Op *aOp; /* Space to hold the virtual machine's program */
12314
- int nLabel; /* Number of labels used */
12315
- int nLabelAlloc; /* Number of slots allocated in aLabel[] */
12316
- int *aLabel; /* Space to hold the labels */
12297
+ Mem *aMem; /* The memory locations */
1231712298
Mem **apArg; /* Arguments to currently executing user function */
1231812299
Mem *aColName; /* Column names to return */
1231912300
Mem *pResultSet; /* Pointer to an array of results */
12301
+ int nMem; /* Number of memory locations currently allocated */
12302
+ int nOp; /* Number of instructions in the program */
12303
+ int nOpAlloc; /* Number of slots allocated for aOp[] */
12304
+ int nLabel; /* Number of labels used */
12305
+ int nLabelAlloc; /* Number of slots allocated in aLabel[] */
12306
+ int *aLabel; /* Space to hold the labels */
1232012307
u16 nResColumn; /* Number of columns in one row of the result set */
1232112308
u16 nCursor; /* Number of slots in apCsr[] */
12309
+ u32 magic; /* Magic number for sanity checking */
12310
+ char *zErrMsg; /* Error message written here */
12311
+ Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
1232212312
VdbeCursor **apCsr; /* One element of this array for each open cursor */
12323
- u8 errorAction; /* Recovery action to do in case of an error */
12324
- u8 okVar; /* True if azVar[] has been initialized */
12325
- ynVar nVar; /* Number of entries in aVar[] */
1232612313
Mem *aVar; /* Values for the OP_Variable opcode. */
1232712314
char **azVar; /* Name of variables */
12328
- u32 magic; /* Magic number for sanity checking */
12329
- int nMem; /* Number of memory locations currently allocated */
12330
- Mem *aMem; /* The memory locations */
12315
+ ynVar nVar; /* Number of entries in aVar[] */
1233112316
u32 cacheCtr; /* VdbeCursor row cache generation counter */
1233212317
int pc; /* The program counter */
1233312318
int rc; /* Value to return */
12334
- char *zErrMsg; /* Error message written here */
12319
+ u8 errorAction; /* Recovery action to do in case of an error */
12320
+ u8 okVar; /* True if azVar[] has been initialized */
1233512321
u8 explain; /* True if EXPLAIN present on SQL command */
1233612322
u8 changeCntOn; /* True to update the change-counter */
1233712323
u8 expired; /* True if the VM needs to be recompiled */
1233812324
u8 runOnlyOnce; /* Automatically expire on reset */
1233912325
u8 minWriteFileFormat; /* Minimum file format for writable database files */
@@ -12341,18 +12327,20 @@
1234112327
u8 usesStmtJournal; /* True if uses a statement journal */
1234212328
u8 readOnly; /* True for read-only statements */
1234312329
u8 isPrepareV2; /* True if prepared with prepare_v2() */
1234412330
int nChange; /* Number of db changes made since last reset */
1234512331
int btreeMask; /* Bitmask of db->aDb[] entries referenced */
12346
- i64 startTime; /* Time when query started - used for profiling */
12332
+ int iStatement; /* Statement number (or 0 if has not opened stmt) */
12333
+ int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
1234712334
BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
12348
- int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
12349
- char *zSql; /* Text of the SQL statement that generated this */
12350
- void *pFree; /* Free this when deleting the vdbe */
12335
+#ifndef SQLITE_OMIT_TRACE
12336
+ i64 startTime; /* Time when query started - used for profiling */
12337
+#endif
1235112338
i64 nFkConstraint; /* Number of imm. FK constraints this VM */
1235212339
i64 nStmtDefCons; /* Number of def. constraints when stmt started */
12353
- int iStatement; /* Statement number (or 0 if has not opened stmt) */
12340
+ char *zSql; /* Text of the SQL statement that generated this */
12341
+ void *pFree; /* Free this when deleting the vdbe */
1235412342
#ifdef SQLITE_DEBUG
1235512343
FILE *trace; /* Write an execution trace here, if not NULL */
1235612344
#endif
1235712345
VdbeFrame *pFrame; /* Parent frame */
1235812346
VdbeFrame *pDelFrame; /* List of frame objects to free on VM reset */
@@ -19231,25 +19219,32 @@
1923119219
/*
1923219220
** sqlite3_snprintf() works like snprintf() except that it ignores the
1923319221
** current locale settings. This is important for SQLite because we
1923419222
** are not able to use a "," as the decimal point in place of "." as
1923519223
** specified by some locales.
19224
+**
19225
+** Oops: The first two arguments of sqlite3_snprintf() are backwards
19226
+** from the snprintf() standard. Unfortunately, it is too late to change
19227
+** this without breaking compatibility, so we just have to live with the
19228
+** mistake.
19229
+**
19230
+** sqlite3_vsnprintf() is the varargs version.
1923619231
*/
19232
+SQLITE_API char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){
19233
+ StrAccum acc;
19234
+ if( n<=0 ) return zBuf;
19235
+ sqlite3StrAccumInit(&acc, zBuf, n, 0);
19236
+ acc.useMalloc = 0;
19237
+ sqlite3VXPrintf(&acc, 0, zFormat, ap);
19238
+ return sqlite3StrAccumFinish(&acc);
19239
+}
1923719240
SQLITE_API char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
1923819241
char *z;
1923919242
va_list ap;
19240
- StrAccum acc;
19241
-
19242
- if( n<=0 ){
19243
- return zBuf;
19244
- }
19245
- sqlite3StrAccumInit(&acc, zBuf, n, 0);
19246
- acc.useMalloc = 0;
1924719243
va_start(ap,zFormat);
19248
- sqlite3VXPrintf(&acc, 0, zFormat, ap);
19244
+ z = sqlite3_vsnprintf(n, zBuf, zFormat, ap);
1924919245
va_end(ap);
19250
- z = sqlite3StrAccumFinish(&acc);
1925119246
return z;
1925219247
}
1925319248
1925419249
/*
1925519250
** This is the routine that actually formats the sqlite3_log() message.
@@ -22976,11 +22971,13 @@
2297622971
#include <sys/stat.h>
2297722972
#include <fcntl.h>
2297822973
#include <unistd.h>
2297922974
#include <sys/time.h>
2298022975
#include <errno.h>
22976
+#ifndef SQLITE_OMIT_WAL
2298122977
#include <sys/mman.h>
22978
+#endif
2298222979
2298322980
#if SQLITE_ENABLE_LOCKING_STYLE
2298422981
# include <sys/ioctl.h>
2298522982
# if OS_VXWORKS
2298622983
# include <semaphore.h>
@@ -34069,15 +34066,11 @@
3406934066
3407034067
if( reuseUnlikely || pcache1.nCurrentPage>pcache1.nMaxPage ){
3407134068
pcache1RemoveFromHash(pPage);
3407234069
pcache1FreePage(pPage);
3407334070
}else{
34074
- /* Add the page to the global LRU list. Normally, the page is added to
34075
- ** the head of the list (last page to be recycled). However, if the
34076
- ** reuseUnlikely flag passed to this function is true, the page is added
34077
- ** to the tail of the list (first page to be recycled).
34078
- */
34071
+ /* Add the page to the global LRU list. */
3407934072
if( pcache1.pLruHead ){
3408034073
pcache1.pLruHead->pLruPrev = pPage;
3408134074
pPage->pLruNext = pcache1.pLruHead;
3408234075
pcache1.pLruHead = pPage;
3408334076
}else{
@@ -37523,14 +37516,14 @@
3752337516
if( rc==SQLITE_OK ){
3752437517
zMaster = pPager->pTmpSpace;
3752537518
rc = readMasterJournal(pPager->jfd, zMaster, pPager->pVfs->mxPathname+1);
3752637519
testcase( rc!=SQLITE_OK );
3752737520
}
37528
- if( rc==SQLITE_OK && !pPager->noSync
37521
+ if( rc==SQLITE_OK
3752937522
&& (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
3753037523
){
37531
- rc = sqlite3OsSync(pPager->fd, pPager->syncFlags);
37524
+ rc = sqlite3PagerSync(pPager);
3753237525
}
3753337526
if( rc==SQLITE_OK ){
3753437527
rc = pager_end_transaction(pPager, zMaster[0]!='\0');
3753537528
testcase( rc!=SQLITE_OK );
3753637529
}
@@ -37689,26 +37682,63 @@
3768937682
}
3769037683
3769137684
return rc;
3769237685
}
3769337686
37687
+
37688
+/*
37689
+** Update the value of the change-counter at offsets 24 and 92 in
37690
+** the header and the sqlite version number at offset 96.
37691
+**
37692
+** This is an unconditional update. See also the pager_incr_changecounter()
37693
+** routine which only updates the change-counter if the update is actually
37694
+** needed, as determined by the pPager->changeCountDone state variable.
37695
+*/
37696
+static void pager_write_changecounter(PgHdr *pPg){
37697
+ u32 change_counter;
37698
+
37699
+ /* Increment the value just read and write it back to byte 24. */
37700
+ change_counter = sqlite3Get4byte((u8*)pPg->pPager->dbFileVers)+1;
37701
+ put32bits(((char*)pPg->pData)+24, change_counter);
37702
+
37703
+ /* Also store the SQLite version number in bytes 96..99 and in
37704
+ ** bytes 92..95 store the change counter for which the version number
37705
+ ** is valid. */
37706
+ put32bits(((char*)pPg->pData)+92, change_counter);
37707
+ put32bits(((char*)pPg->pData)+96, SQLITE_VERSION_NUMBER);
37708
+}
37709
+
3769437710
/*
3769537711
** This function is a wrapper around sqlite3WalFrames(). As well as logging
3769637712
** the contents of the list of pages headed by pList (connected by pDirty),
3769737713
** this function notifies any active backup processes that the pages have
37698
-** changed.
37714
+** changed.
37715
+**
37716
+** The list of pages passed into this routine is always sorted by page number.
37717
+** Hence, if page 1 appears anywhere on the list, it will be the first page.
3769937718
*/
3770037719
static int pagerWalFrames(
3770137720
Pager *pPager, /* Pager object */
3770237721
PgHdr *pList, /* List of frames to log */
3770337722
Pgno nTruncate, /* Database size after this commit */
3770437723
int isCommit, /* True if this is a commit */
3770537724
int syncFlags /* Flags to pass to OsSync() (or 0) */
3770637725
){
3770737726
int rc; /* Return code */
37727
+#if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES)
37728
+ PgHdr *p; /* For looping over pages */
37729
+#endif
3770837730
3770937731
assert( pPager->pWal );
37732
+#ifdef SQLITE_DEBUG
37733
+ /* Verify that the page list is in accending order */
37734
+ for(p=pList; p && p->pDirty; p=p->pDirty){
37735
+ assert( p->pgno < p->pDirty->pgno );
37736
+ }
37737
+#endif
37738
+
37739
+ if( pList->pgno==1 ) pager_write_changecounter(pList);
3771037740
rc = sqlite3WalFrames(pPager->pWal,
3771137741
pPager->pageSize, pList, nTruncate, isCommit, syncFlags
3771237742
);
3771337743
if( rc==SQLITE_OK && pPager->pBackup ){
3771437744
PgHdr *p;
@@ -37716,13 +37746,12 @@
3771637746
sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData);
3771737747
}
3771837748
}
3771937749
3772037750
#ifdef SQLITE_CHECK_PAGES
37721
- {
37722
- PgHdr *p;
37723
- for(p=pList; p; p=p->pDirty) pager_set_pagehash(p);
37751
+ for(p=pList; p; p=p->pDirty){
37752
+ pager_set_pagehash(p);
3772437753
}
3772537754
#endif
3772637755
3772737756
return rc;
3772837757
}
@@ -38743,10 +38772,11 @@
3874338772
if( pgno<=pPager->dbSize && 0==(pList->flags&PGHDR_DONT_WRITE) ){
3874438773
i64 offset = (pgno-1)*(i64)pPager->pageSize; /* Offset to write */
3874538774
char *pData; /* Data to write */
3874638775
3874738776
assert( (pList->flags&PGHDR_NEED_SYNC)==0 );
38777
+ if( pList->pgno==1 ) pager_write_changecounter(pList);
3874838778
3874938779
/* Encode the database */
3875038780
CODEC2(pPager, pList->pData, pgno, 6, return SQLITE_NOMEM, pData);
3875138781
3875238782
/* Write out the page data. */
@@ -40263,11 +40293,17 @@
4026340293
}
4026440294
4026540295
/*
4026640296
** This routine is called to increment the value of the database file
4026740297
** change-counter, stored as a 4-byte big-endian integer starting at
40268
-** byte offset 24 of the pager file.
40298
+** byte offset 24 of the pager file. The secondary change counter at
40299
+** 92 is also updated, as is the SQLite version number at offset 96.
40300
+**
40301
+** But this only happens if the pPager->changeCountDone flag is false.
40302
+** To avoid excess churning of page 1, the update only happens once.
40303
+** See also the pager_write_changecounter() routine that does an
40304
+** unconditional update of the change counters.
4026940305
**
4027040306
** If the isDirectMode flag is zero, then this is done by calling
4027140307
** sqlite3PagerWrite() on page 1, then modifying the contents of the
4027240308
** page data. In this case the file will be updated when the current
4027340309
** transaction is committed.
@@ -40304,11 +40340,10 @@
4030440340
# define DIRECT_MODE isDirectMode
4030540341
#endif
4030640342
4030740343
if( !pPager->changeCountDone && pPager->dbSize>0 ){
4030840344
PgHdr *pPgHdr; /* Reference to page 1 */
40309
- u32 change_counter; /* Initial value of change-counter field */
4031040345
4031140346
assert( !pPager->tempFile && isOpen(pPager->fd) );
4031240347
4031340348
/* Open page 1 of the file for writing. */
4031440349
rc = sqlite3PagerGet(pPager, 1, &pPgHdr);
@@ -40322,20 +40357,12 @@
4032240357
if( !DIRECT_MODE && ALWAYS(rc==SQLITE_OK) ){
4032340358
rc = sqlite3PagerWrite(pPgHdr);
4032440359
}
4032540360
4032640361
if( rc==SQLITE_OK ){
40327
- /* Increment the value just read and write it back to byte 24. */
40328
- change_counter = sqlite3Get4byte((u8*)pPager->dbFileVers);
40329
- change_counter++;
40330
- put32bits(((char*)pPgHdr->pData)+24, change_counter);
40331
-
40332
- /* Also store the SQLite version number in bytes 96..99 and in
40333
- ** bytes 92..95 store the change counter for which the version number
40334
- ** is valid. */
40335
- put32bits(((char*)pPgHdr->pData)+92, change_counter);
40336
- put32bits(((char*)pPgHdr->pData)+96, SQLITE_VERSION_NUMBER);
40362
+ /* Actually do the update of the change counter */
40363
+ pager_write_changecounter(pPgHdr);
4033740364
4033840365
/* If running in direct mode, write the contents of page 1 to the file. */
4033940366
if( DIRECT_MODE ){
4034040367
const void *zBuf;
4034140368
assert( pPager->dbFileSize>0 );
@@ -40370,10 +40397,13 @@
4037040397
if( pPager->noSync ){
4037140398
rc = SQLITE_OK;
4037240399
}else{
4037340400
rc = sqlite3OsSync(pPager->fd, pPager->syncFlags);
4037440401
}
40402
+ if( isOpen(pPager->fd) ){
40403
+ sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC, (void *)&rc);
40404
+ }
4037540405
return rc;
4037640406
}
4037740407
4037840408
/*
4037940409
** This function may only be called while a write-transaction is active in
@@ -40587,12 +40617,12 @@
4058740617
rc = pager_truncate(pPager, nNew);
4058840618
if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
4058940619
}
4059040620
4059140621
/* Finally, sync the database file. */
40592
- if( !pPager->noSync && !noSync ){
40593
- rc = sqlite3OsSync(pPager->fd, pPager->syncFlags);
40622
+ if( !noSync ){
40623
+ rc = sqlite3PagerSync(pPager);
4059440624
}
4059540625
IOTRACE(("DBSYNC %p\n", pPager))
4059640626
}
4059740627
}
4059840628
@@ -40700,11 +40730,21 @@
4070040730
int rc2;
4070140731
rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_ROLLBACK, -1);
4070240732
rc2 = pager_end_transaction(pPager, pPager->setMaster);
4070340733
if( rc==SQLITE_OK ) rc = rc2;
4070440734
}else if( !isOpen(pPager->jfd) || pPager->eState==PAGER_WRITER_LOCKED ){
40735
+ int eState = pPager->eState;
4070540736
rc = pager_end_transaction(pPager, 0);
40737
+ if( !MEMDB && eState>PAGER_WRITER_LOCKED ){
40738
+ /* This can happen using journal_mode=off. Move the pager to the error
40739
+ ** state to indicate that the contents of the cache may not be trusted.
40740
+ ** Any active readers will get SQLITE_ABORT.
40741
+ */
40742
+ pPager->errCode = SQLITE_ABORT;
40743
+ pPager->eState = PAGER_ERROR;
40744
+ return rc;
40745
+ }
4070640746
}else{
4070740747
rc = pager_playback(pPager, 0);
4070840748
}
4070940749
4071040750
assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK );
@@ -44732,16 +44772,16 @@
4473244772
u8 openFlags; /* Flags to sqlite3BtreeOpen() */
4473344773
#ifndef SQLITE_OMIT_AUTOVACUUM
4473444774
u8 autoVacuum; /* True if auto-vacuum is enabled */
4473544775
u8 incrVacuum; /* True if incr-vacuum is enabled */
4473644776
#endif
44777
+ u8 inTransaction; /* Transaction state */
44778
+ u8 doNotUseWAL; /* If true, do not open write-ahead-log file */
4473744779
u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */
4473844780
u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
4473944781
u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
4474044782
u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
44741
- u8 inTransaction; /* Transaction state */
44742
- u8 doNotUseWAL; /* If true, do not open write-ahead-log file */
4474344783
u32 pageSize; /* Total number of bytes on a page */
4474444784
u32 usableSize; /* Number of usable bytes on each page */
4474544785
int nTransaction; /* Number of open transactions (read + write) */
4474644786
u32 nPage; /* Number of pages in the database */
4474744787
void *pSchema; /* Pointer to space allocated by sqlite3BtreeSchema() */
@@ -44764,12 +44804,12 @@
4476444804
** about a cell. The parseCellPtr() function fills in this structure
4476544805
** based on information extract from the raw disk page.
4476644806
*/
4476744807
typedef struct CellInfo CellInfo;
4476844808
struct CellInfo {
44769
- u8 *pCell; /* Pointer to the start of cell content */
4477044809
i64 nKey; /* The key for INTKEY tables, or number of bytes in key */
44810
+ u8 *pCell; /* Pointer to the start of cell content */
4477144811
u32 nData; /* Number of bytes of data */
4477244812
u32 nPayload; /* Total amount of payload */
4477344813
u16 nHeader; /* Size of the cell content header in bytes */
4477444814
u16 nLocal; /* Amount of payload held locally */
4477544815
u16 iOverflow; /* Offset to overflow page number. Zero if no overflow */
@@ -44807,24 +44847,24 @@
4480744847
BtCursor *pNext, *pPrev; /* Forms a linked list of all cursors */
4480844848
struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */
4480944849
Pgno pgnoRoot; /* The root page of this tree */
4481044850
sqlite3_int64 cachedRowid; /* Next rowid cache. 0 means not valid */
4481144851
CellInfo info; /* A parse of the cell we are pointing at */
44852
+ i64 nKey; /* Size of pKey, or last integer key */
44853
+ void *pKey; /* Saved key that was cursor's last known position */
44854
+ int skipNext; /* Prev() is noop if negative. Next() is noop if positive */
4481244855
u8 wrFlag; /* True if writable */
4481344856
u8 atLast; /* Cursor pointing to the last entry */
4481444857
u8 validNKey; /* True if info.nKey is valid */
4481544858
u8 eState; /* One of the CURSOR_XXX constants (see below) */
44816
- void *pKey; /* Saved key that was cursor's last known position */
44817
- i64 nKey; /* Size of pKey, or last integer key */
44818
- int skipNext; /* Prev() is noop if negative. Next() is noop if positive */
4481944859
#ifndef SQLITE_OMIT_INCRBLOB
44820
- u8 isIncrblobHandle; /* True if this cursor is an incr. io handle */
4482144860
Pgno *aOverflow; /* Cache of overflow page locations */
44861
+ u8 isIncrblobHandle; /* True if this cursor is an incr. io handle */
4482244862
#endif
4482344863
i16 iPage; /* Index of current page in apPage */
44824
- MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */
4482544864
u16 aiIdx[BTCURSOR_MAX_DEPTH]; /* Current index in apPage[i] */
44865
+ MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */
4482644866
};
4482744867
4482844868
/*
4482944869
** Potential values for BtCursor.eState.
4483044870
**
@@ -47692,11 +47732,11 @@
4769247732
freeTempSpace(pBt);
4769347733
rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
4769447734
pageSize-usableSize);
4769547735
return rc;
4769647736
}
47697
- if( nPageHeader>nPageFile ){
47737
+ if( (pBt->db->flags & SQLITE_RecoveryMode)==0 && nPageHeader>nPageFile ){
4769847738
rc = SQLITE_CORRUPT_BKPT;
4769947739
goto page1_init_failed;
4770047740
}
4770147741
if( usableSize<480 ){
4770247742
goto page1_init_failed;
@@ -53563,10 +53603,20 @@
5356353603
return 0;
5356453604
}
5356553605
5356653606
return pDb->aDb[i].pBt;
5356753607
}
53608
+
53609
+/*
53610
+** Attempt to set the page size of the destination to match the page size
53611
+** of the source.
53612
+*/
53613
+static int setDestPgsz(sqlite3_backup *p){
53614
+ int rc;
53615
+ rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),-1,0);
53616
+ return rc;
53617
+}
5356853618
5356953619
/*
5357053620
** Create an sqlite3_backup process to copy the contents of zSrcDb from
5357153621
** connection handle pSrcDb to zDestDb in pDestDb. If successful, return
5357253622
** a pointer to the new sqlite3_backup object.
@@ -53617,14 +53667,15 @@
5361753667
p->pDestDb = pDestDb;
5361853668
p->pSrcDb = pSrcDb;
5361953669
p->iNext = 1;
5362053670
p->isAttached = 0;
5362153671
53622
- if( 0==p->pSrc || 0==p->pDest ){
53623
- /* One (or both) of the named databases did not exist. An error has
53624
- ** already been written into the pDestDb handle. All that is left
53625
- ** to do here is free the sqlite3_backup structure.
53672
+ if( 0==p->pSrc || 0==p->pDest || setDestPgsz(p)==SQLITE_NOMEM ){
53673
+ /* One (or both) of the named databases did not exist or an OOM
53674
+ ** error was hit. The error has already been written into the
53675
+ ** pDestDb handle. All that is left to do here is free the
53676
+ ** sqlite3_backup structure.
5362653677
*/
5362753678
sqlite3_free(p);
5362853679
p = 0;
5362953680
}
5363053681
}
@@ -53877,35 +53928,37 @@
5387753928
** pending-byte page in the source database may need to be
5387853929
** copied into the destination database.
5387953930
*/
5388053931
const i64 iSize = (i64)pgszSrc * (i64)nSrcPage;
5388153932
sqlite3_file * const pFile = sqlite3PagerFile(pDestPager);
53933
+ i64 iOff;
53934
+ i64 iEnd;
5388253935
5388353936
assert( pFile );
5388453937
assert( (i64)nDestTruncate*(i64)pgszDest >= iSize || (
5388553938
nDestTruncate==(int)(PENDING_BYTE_PAGE(p->pDest->pBt)-1)
5388653939
&& iSize>=PENDING_BYTE && iSize<=PENDING_BYTE+pgszDest
5388753940
));
53888
- if( SQLITE_OK==(rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 1))
53889
- && SQLITE_OK==(rc = backupTruncateFile(pFile, iSize))
53890
- && SQLITE_OK==(rc = sqlite3PagerSync(pDestPager))
53891
- ){
53892
- i64 iOff;
53893
- i64 iEnd = MIN(PENDING_BYTE + pgszDest, iSize);
53894
- for(
53895
- iOff=PENDING_BYTE+pgszSrc;
53896
- rc==SQLITE_OK && iOff<iEnd;
53897
- iOff+=pgszSrc
53898
- ){
53899
- PgHdr *pSrcPg = 0;
53900
- const Pgno iSrcPg = (Pgno)((iOff/pgszSrc)+1);
53901
- rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg);
53902
- if( rc==SQLITE_OK ){
53903
- u8 *zData = sqlite3PagerGetData(pSrcPg);
53904
- rc = sqlite3OsWrite(pFile, zData, pgszSrc, iOff);
53905
- }
53906
- sqlite3PagerUnref(pSrcPg);
53941
+ iEnd = MIN(PENDING_BYTE + pgszDest, iSize);
53942
+ for(
53943
+ iOff=PENDING_BYTE+pgszSrc;
53944
+ rc==SQLITE_OK && iOff<iEnd;
53945
+ iOff+=pgszSrc
53946
+ ){
53947
+ PgHdr *pSrcPg = 0;
53948
+ const Pgno iSrcPg = (Pgno)((iOff/pgszSrc)+1);
53949
+ rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg);
53950
+ if( rc==SQLITE_OK ){
53951
+ u8 *zData = sqlite3PagerGetData(pSrcPg);
53952
+ rc = sqlite3OsWrite(pFile, zData, pgszSrc, iOff);
53953
+ }
53954
+ sqlite3PagerUnref(pSrcPg);
53955
+ }
53956
+ if( rc==SQLITE_OK ){
53957
+ rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 1);
53958
+ if( rc==SQLITE_OK ){
53959
+ rc = backupTruncateFile(pFile, iSize);
5390753960
}
5390853961
}
5390953962
}else{
5391053963
rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
5391153964
}
@@ -59102,11 +59155,11 @@
5910259155
** __attribute__((aligned(8))) macro. */
5910359156
static const Mem nullMem
5910459157
#if defined(SQLITE_DEBUG) && defined(__GNUC__)
5910559158
__attribute__((aligned(8)))
5910659159
#endif
59107
- = {{0}, (double)0, 0, "", 0, MEM_Null, SQLITE_NULL, 0, 0, 0 };
59160
+ = {0, "", (double)0, {0}, 0, MEM_Null, SQLITE_NULL, 0, 0, 0 };
5910859161
5910959162
if( pVm && ALWAYS(pVm->db) ){
5911059163
sqlite3_mutex_enter(pVm->db->mutex);
5911159164
sqlite3Error(pVm->db, SQLITE_RANGE, 0);
5911259165
}
@@ -73549,13 +73602,14 @@
7354973602
sqlite3VdbeAddOp2(v, OP_Rewind, iIdxCur, endOfLoop);
7355073603
topOfLoop = sqlite3VdbeCurrentAddr(v);
7355173604
sqlite3VdbeAddOp2(v, OP_AddImm, iMem, 1);
7355273605
7355373606
for(i=0; i<nCol; i++){
73607
+ CollSeq *pColl;
7355473608
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regCol);
73555
-#ifdef SQLITE_ENABLE_STAT2
7355673609
if( i==0 ){
73610
+#ifdef SQLITE_ENABLE_STAT2
7355773611
/* Check if the record that cursor iIdxCur points to contains a
7355873612
** value that should be stored in the sqlite_stat2 table. If so,
7355973613
** store it. */
7356073614
int ne = sqlite3VdbeAddOp3(v, OP_Ne, regRecno, 0, regSamplerecno);
7356173615
assert( regTabname+1==regIdxname
@@ -73580,16 +73634,21 @@
7358073634
sqlite3VdbeAddOp3(v, OP_Divide, regTemp2, regTemp, regTemp);
7358173635
sqlite3VdbeAddOp3(v, OP_Add, regSamplerecno, regTemp, regSamplerecno);
7358273636
7358373637
sqlite3VdbeJumpHere(v, ne);
7358473638
sqlite3VdbeAddOp2(v, OP_AddImm, regRecno, 1);
73585
- }
7358673639
#endif
7358773640
73588
- sqlite3VdbeAddOp3(v, OP_Ne, regCol, 0, iMem+nCol+i+1);
73589
- /**** TODO: add collating sequence *****/
73590
- sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
73641
+ /* Always record the very first row */
73642
+ sqlite3VdbeAddOp1(v, OP_IfNot, iMem+1);
73643
+ }
73644
+ assert( pIdx->azColl!=0 );
73645
+ assert( pIdx->azColl[i]!=0 );
73646
+ pColl = sqlite3LocateCollSeq(pParse, pIdx->azColl[i]);
73647
+ sqlite3VdbeAddOp4(v, OP_Ne, regCol, 0, iMem+nCol+i+1,
73648
+ (char*)pColl, P4_COLLSEQ);
73649
+ sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
7359173650
}
7359273651
if( db->mallocFailed ){
7359373652
/* If a malloc failure has occurred, then the result of the expression
7359473653
** passed as the second argument to the call to sqlite3VdbeJumpHere()
7359573654
** below may be negative. Which causes an assert() to fail (or an
@@ -73596,11 +73655,15 @@
7359673655
** out-of-bounds write if SQLITE_DEBUG is not defined). */
7359773656
return;
7359873657
}
7359973658
sqlite3VdbeAddOp2(v, OP_Goto, 0, endOfLoop);
7360073659
for(i=0; i<nCol; i++){
73601
- sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-(nCol*2));
73660
+ int addr = sqlite3VdbeCurrentAddr(v) - (nCol*2);
73661
+ if( i==0 ){
73662
+ sqlite3VdbeJumpHere(v, addr-1); /* Set jump dest for the OP_IfNot */
73663
+ }
73664
+ sqlite3VdbeJumpHere(v, addr); /* Set jump dest for the OP_Ne */
7360273665
sqlite3VdbeAddOp2(v, OP_AddImm, iMem+i+1, 1);
7360373666
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, iMem+nCol+i+1);
7360473667
}
7360573668
7360673669
/* End of the analysis loop. */
@@ -73942,12 +74005,15 @@
7394274005
sqlite3DbFree(db, zSql);
7394374006
}
7394474007
7394574008
if( rc==SQLITE_OK ){
7394674009
while( sqlite3_step(pStmt)==SQLITE_ROW ){
73947
- char *zIndex = (char *)sqlite3_column_text(pStmt, 0);
73948
- Index *pIdx = sqlite3FindIndex(db, zIndex, sInfo.zDatabase);
74010
+ char *zIndex; /* Index name */
74011
+ Index *pIdx; /* Pointer to the index object */
74012
+
74013
+ zIndex = (char *)sqlite3_column_text(pStmt, 0);
74014
+ pIdx = zIndex ? sqlite3FindIndex(db, zIndex, sInfo.zDatabase) : 0;
7394974015
if( pIdx ){
7395074016
int iSample = sqlite3_column_int(pStmt, 1);
7395174017
if( iSample<SQLITE_INDEX_SAMPLES && iSample>=0 ){
7395274018
int eType = sqlite3_column_type(pStmt, 2);
7395374019
@@ -115616,28 +115682,32 @@
115616115682
** the table. The following nCol varints contain the total amount of
115617115683
** data stored in all rows of each column of the table, from left
115618115684
** to right.
115619115685
*/
115620115686
sqlite3_stmt *pStmt;
115621
- rc = fts3SqlStmt(p, SQL_SELECT_DOCTOTAL, &pStmt, 0);
115687
+ sqlite3_int64 nDoc = 0;
115688
+ sqlite3_int64 nByte = 0;
115689
+ const char *a;
115690
+ rc = sqlite3Fts3SelectDoctotal(p, &pStmt);
115622115691
if( rc ) return rc;
115623
- if( sqlite3_step(pStmt)==SQLITE_ROW ){
115624
- sqlite3_int64 nDoc = 0;
115625
- sqlite3_int64 nByte = 0;
115626
- const char *a = sqlite3_column_blob(pStmt, 0);
115627
- if( a ){
115628
- const char *pEnd = &a[sqlite3_column_bytes(pStmt, 0)];
115629
- a += sqlite3Fts3GetVarint(a, &nDoc);
115630
- while( a<pEnd ){
115631
- a += sqlite3Fts3GetVarint(a, &nByte);
115632
- }
115633
- }
115634
-
115635
- pCsr->nRowAvg = (int)(((nByte / nDoc) + pgsz - 1) / pgsz);
115636
- }
115692
+ a = sqlite3_column_blob(pStmt, 0);
115693
+ if( a ){
115694
+ const char *pEnd = &a[sqlite3_column_bytes(pStmt, 0)];
115695
+ a += sqlite3Fts3GetVarint(a, &nDoc);
115696
+ while( a<pEnd ){
115697
+ a += sqlite3Fts3GetVarint(a, &nByte);
115698
+ }
115699
+ }
115700
+ if( nDoc==0 || nByte==0 ){
115701
+ sqlite3_reset(pStmt);
115702
+ return SQLITE_CORRUPT;
115703
+ }
115704
+
115705
+ pCsr->nRowAvg = (int)(((nByte / nDoc) + pgsz) / pgsz);
115706
+ assert( pCsr->nRowAvg>0 );
115637115707
rc = sqlite3_reset(pStmt);
115638
- if( rc!=SQLITE_OK || pCsr->nRowAvg==0 ) return rc;
115708
+ if( rc!=SQLITE_OK ) return rc;
115639115709
}
115640115710
115641115711
/* Assume that a blob flows over onto overflow pages if it is larger
115642115712
** than (pgsz-35) bytes in size (the file-format documentation
115643115713
** confirms this).
@@ -116754,11 +116824,11 @@
116754116824
116755116825
if( !isIgnoreEmpty || nList>0 ){
116756116826
nByte = sqlite3Fts3VarintLen(iDocid-iPrev) + (isRequirePos?nList+1:0);
116757116827
if( nDoclist+nByte>nAlloc ){
116758116828
char *aNew;
116759
- nAlloc = nDoclist+nByte*2;
116829
+ nAlloc = (nDoclist+nByte)*2;
116760116830
aNew = sqlite3_realloc(aBuffer, nAlloc);
116761116831
if( !aNew ){
116762116832
rc = SQLITE_NOMEM;
116763116833
goto finished;
116764116834
}
@@ -118361,10 +118431,11 @@
118361118431
if( !*ppStmt ){
118362118432
int rc = sqlite3Fts3SelectDoctotal(pTab, ppStmt);
118363118433
if( rc!=SQLITE_OK ) return rc;
118364118434
}
118365118435
pStmt = *ppStmt;
118436
+ assert( sqlite3_data_count(pStmt)==1 );
118366118437
118367118438
a = sqlite3_column_blob(pStmt, 0);
118368118439
a += sqlite3Fts3GetVarint(a, &nDoc);
118369118440
*pnDoc = (u32)nDoc;
118370118441
118371118442
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.7.4. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a one translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -648,13 +648,13 @@
648 **
649 ** See also: [sqlite3_libversion()],
650 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651 ** [sqlite_version()] and [sqlite_source_id()].
652 */
653 #define SQLITE_VERSION "3.7.4"
654 #define SQLITE_VERSION_NUMBER 3007004
655 #define SQLITE_SOURCE_ID "2010-12-21 21:28:38 b0888047bb6d9ac55e29b9224df2ff650728bb78"
656
657 /*
658 ** CAPI3REF: Run-Time Library Version Numbers
659 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
660 **
@@ -1261,18 +1261,25 @@
1261 **
1262 ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
1263 ** to the [sqlite3_file] object associated with a particular database
1264 ** connection. See the [sqlite3_file_control()] documentation for
1265 ** additional information.
 
 
 
 
 
 
1266 */
1267 #define SQLITE_FCNTL_LOCKSTATE 1
1268 #define SQLITE_GET_LOCKPROXYFILE 2
1269 #define SQLITE_SET_LOCKPROXYFILE 3
1270 #define SQLITE_LAST_ERRNO 4
1271 #define SQLITE_FCNTL_SIZE_HINT 5
1272 #define SQLITE_FCNTL_CHUNK_SIZE 6
1273 #define SQLITE_FCNTL_FILE_POINTER 7
 
1274
1275
1276 /*
1277 ** CAPI3REF: Mutex Handle
1278 **
@@ -2407,10 +2414,12 @@
2407 ** guarantees that the buffer is always zero-terminated. ^The first
2408 ** parameter "n" is the total size of the buffer, including space for
2409 ** the zero terminator. So the longest string that can be completely
2410 ** written will be n-1 characters.
2411 **
 
 
2412 ** These routines all implement some additional formatting
2413 ** options that are useful for constructing SQL statements.
2414 ** All of the usual printf() formatting options apply. In addition, there
2415 ** is are "%q", "%Q", and "%z" options.
2416 **
@@ -2470,10 +2479,11 @@
2470 ** the result, [sqlite3_free()] is called on the input string.)^
2471 */
2472 SQLITE_API char *sqlite3_mprintf(const char*,...);
2473 SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
2474 SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
 
2475
2476 /*
2477 ** CAPI3REF: Memory Allocation Subsystem
2478 **
2479 ** The SQLite core uses these three routines for all of its own
@@ -2847,11 +2857,11 @@
2847 ** <dd>The database is opened for reading and writing if possible, or reading
2848 ** only if the file is write protected by the operating system. In either
2849 ** case the database must already exist, otherwise an error is returned.</dd>)^
2850 **
2851 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
2852 ** <dd>The database is opened for reading and writing, and is creates it if
2853 ** it does not already exist. This is the behavior that is always used for
2854 ** sqlite3_open() and sqlite3_open16().</dd>)^
2855 ** </dl>
2856 **
2857 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
@@ -3957,20 +3967,20 @@
3957 ** encoding is used, then the fourth argument should be [SQLITE_ANY].
3958 **
3959 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
3960 ** function can gain access to this pointer using [sqlite3_user_data()].)^
3961 **
3962 ** ^The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
3963 ** pointers to C-language functions that implement the SQL function or
3964 ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
3965 ** callback only; NULL pointers must be passed as the xStep and xFinal
3966 ** parameters. ^An aggregate SQL function requires an implementation of xStep
3967 ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
3968 ** SQL function or aggregate, pass NULL poiners for all three function
3969 ** callbacks.
3970 **
3971 ** ^(If the tenth parameter to sqlite3_create_function_v2() is not NULL,
3972 ** then it is destructor for the application data pointer.
3973 ** The destructor is invoked when the function is deleted, either by being
3974 ** overloaded or when the database connection closes.)^
3975 ** ^The destructor is also invoked if the call to
3976 ** sqlite3_create_function_v2() fails.
@@ -4070,11 +4080,11 @@
4070 ** the function or aggregate.
4071 **
4072 ** The xFunc (for scalar functions) or xStep (for aggregates) parameters
4073 ** to [sqlite3_create_function()] and [sqlite3_create_function16()]
4074 ** define callbacks that implement the SQL functions and aggregates.
4075 ** The 4th parameter to these callbacks is an array of pointers to
4076 ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for
4077 ** each parameter to the SQL function. These routines are used to
4078 ** extract values from the [sqlite3_value] objects.
4079 **
4080 ** These routines work only with [protected sqlite3_value] objects.
@@ -6235,15 +6245,17 @@
6235 ** SQLite will typically create one cache instance for each open database file,
6236 ** though this is not guaranteed. ^The
6237 ** first parameter, szPage, is the size in bytes of the pages that must
6238 ** be allocated by the cache. ^szPage will not be a power of two. ^szPage
6239 ** will the page size of the database file that is to be cached plus an
6240 ** increment (here called "R") of about 100 or 200. SQLite will use the
6241 ** extra R bytes on each page to store metadata about the underlying
6242 ** database page on disk. The value of R depends
6243 ** on the SQLite version, the target platform, and how SQLite was compiled.
6244 ** ^R is constant for a particular build of SQLite. ^The second argument to
 
 
6245 ** xCreate(), bPurgeable, is true if the cache being created will
6246 ** be used to cache database pages of a file stored on disk, or
6247 ** false if it is used for an in-memory database. The cache implementation
6248 ** does not have to do anything special based with the value of bPurgeable;
6249 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
@@ -6271,11 +6283,11 @@
6271 ** is considered to be "pinned".
6272 **
6273 ** If the requested page is already in the page cache, then the page cache
6274 ** implementation must return a pointer to the page buffer with its content
6275 ** intact. If the requested page is not already in the cache, then the
6276 ** behavior of the cache implementation should use the value of the createFlag
6277 ** parameter to help it determined what action to take:
6278 **
6279 ** <table border=1 width=85% align=center>
6280 ** <tr><th> createFlag <th> Behaviour when page is not already in cache
6281 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
@@ -12051,37 +12063,32 @@
12051 ** entries or retrieve the key or data from the entry that the cursor
12052 ** is currently pointing to.
12053 **
12054 ** Every cursor that the virtual machine has open is represented by an
12055 ** instance of the following structure.
12056 **
12057 ** If the VdbeCursor.isTriggerRow flag is set it means that this cursor is
12058 ** really a single row that represents the NEW or OLD pseudo-table of
12059 ** a row trigger. The data for the row is stored in VdbeCursor.pData and
12060 ** the rowid is in VdbeCursor.iKey.
12061 */
12062 struct VdbeCursor {
12063 BtCursor *pCursor; /* The cursor structure of the backend */
 
 
12064 int iDb; /* Index of cursor database in db->aDb[] (or -1) */
12065 i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
 
12066 Bool zeroed; /* True if zeroed out and ready for reuse */
12067 Bool rowidIsValid; /* True if lastRowid is valid */
12068 Bool atFirst; /* True if pointing to first entry */
12069 Bool useRandomRowid; /* Generate new record numbers semi-randomly */
12070 Bool nullRow; /* True if pointing to a row with no data */
12071 Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
12072 Bool isTable; /* True if a table requiring integer keys */
12073 Bool isIndex; /* True if an index containing keys only - no data */
12074 Bool isOrdered; /* True if the underlying table is BTREE_UNORDERED */
12075 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
12076 Btree *pBt; /* Separate file holding temporary table */
12077 int pseudoTableReg; /* Register holding pseudotable content. */
12078 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
12079 int nField; /* Number of fields in the header */
12080 i64 seqCount; /* Sequence counter */
12081 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
12082 const sqlite3_module *pModule; /* Module for cursor pVtabCursor */
 
 
 
12083
12084 /* Result of last sqlite3BtreeMoveto() done by an OP_NotExists or
12085 ** OP_IsUnique opcode on this cursor. */
12086 int seekResult;
12087
@@ -12149,29 +12156,23 @@
12149 #define CACHE_STALE 0
12150
12151 /*
12152 ** Internally, the vdbe manipulates nearly all SQL values as Mem
12153 ** structures. Each Mem struct may cache multiple representations (string,
12154 ** integer etc.) of the same value. A value (and therefore Mem structure)
12155 ** has the following properties:
12156 **
12157 ** Each value has a manifest type. The manifest type of the value stored
12158 ** in a Mem struct is returned by the MemType(Mem*) macro. The type is
12159 ** one of SQLITE_NULL, SQLITE_INTEGER, SQLITE_REAL, SQLITE_TEXT or
12160 ** SQLITE_BLOB.
12161 */
12162 struct Mem {
 
 
 
12163 union {
12164 i64 i; /* Integer value. */
12165 int nZero; /* Used when bit MEM_Zero is set in flags */
12166 FuncDef *pDef; /* Used only when flags==MEM_Agg */
12167 RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
12168 VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
12169 } u;
12170 double r; /* Real value */
12171 sqlite3 *db; /* The associated database connection */
12172 char *z; /* String or BLOB value */
12173 int n; /* Number of characters in string value, excluding '\0' */
12174 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
12175 u8 type; /* One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc */
12176 u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
12177 #ifdef SQLITE_DEBUG
@@ -12191,13 +12192,10 @@
12191 ** If the MEM_Str flag is set then Mem.z points at a string representation.
12192 ** Usually this is encoded in the same unicode encoding as the main
12193 ** database (see below for exceptions). If the MEM_Term flag is also
12194 ** set, then the string is nul terminated. The MEM_Int and MEM_Real
12195 ** flags may coexist with the MEM_Str flag.
12196 **
12197 ** Multiple of these values can appear in Mem.flags. But only one
12198 ** at a time can appear in Mem.type.
12199 */
12200 #define MEM_Null 0x0001 /* Value is NULL */
12201 #define MEM_Str 0x0002 /* Value is a string */
12202 #define MEM_Int 0x0004 /* Value is an integer */
12203 #define MEM_Real 0x0008 /* Value is a real number */
@@ -12276,27 +12274,15 @@
12276 Mem *pMem; /* Memory cell used to store aggregate context */
12277 int isError; /* Error code returned by the function. */
12278 CollSeq *pColl; /* Collating sequence */
12279 };
12280
12281 /*
12282 ** A Set structure is used for quick testing to see if a value
12283 ** is part of a small set. Sets are used to implement code like
12284 ** this:
12285 ** x.y IN ('hi','hoo','hum')
12286 */
12287 typedef struct Set Set;
12288 struct Set {
12289 Hash hash; /* A set is just a hash table */
12290 HashElem *prev; /* Previously accessed hash elemen */
12291 };
12292
12293 /*
12294 ** An instance of the virtual machine. This structure contains the complete
12295 ** state of the virtual machine.
12296 **
12297 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_compile()
12298 ** is really a pointer to an instance of this structure.
12299 **
12300 ** The Vdbe.inVtabMethod variable is set to non-zero for the duration of
12301 ** any virtual table method invocations made by the vdbe program. It is
12302 ** set to 2 for xDestroy method calls and 1 for all other methods. This
@@ -12305,35 +12291,35 @@
12305 ** malloc failure when SQLite is invoked recursively by a virtual table
12306 ** method function.
12307 */
12308 struct Vdbe {
12309 sqlite3 *db; /* The database connection that owns this statement */
12310 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
12311 int nOp; /* Number of instructions in the program */
12312 int nOpAlloc; /* Number of slots allocated for aOp[] */
12313 Op *aOp; /* Space to hold the virtual machine's program */
12314 int nLabel; /* Number of labels used */
12315 int nLabelAlloc; /* Number of slots allocated in aLabel[] */
12316 int *aLabel; /* Space to hold the labels */
12317 Mem **apArg; /* Arguments to currently executing user function */
12318 Mem *aColName; /* Column names to return */
12319 Mem *pResultSet; /* Pointer to an array of results */
 
 
 
 
 
 
12320 u16 nResColumn; /* Number of columns in one row of the result set */
12321 u16 nCursor; /* Number of slots in apCsr[] */
 
 
 
12322 VdbeCursor **apCsr; /* One element of this array for each open cursor */
12323 u8 errorAction; /* Recovery action to do in case of an error */
12324 u8 okVar; /* True if azVar[] has been initialized */
12325 ynVar nVar; /* Number of entries in aVar[] */
12326 Mem *aVar; /* Values for the OP_Variable opcode. */
12327 char **azVar; /* Name of variables */
12328 u32 magic; /* Magic number for sanity checking */
12329 int nMem; /* Number of memory locations currently allocated */
12330 Mem *aMem; /* The memory locations */
12331 u32 cacheCtr; /* VdbeCursor row cache generation counter */
12332 int pc; /* The program counter */
12333 int rc; /* Value to return */
12334 char *zErrMsg; /* Error message written here */
 
12335 u8 explain; /* True if EXPLAIN present on SQL command */
12336 u8 changeCntOn; /* True to update the change-counter */
12337 u8 expired; /* True if the VM needs to be recompiled */
12338 u8 runOnlyOnce; /* Automatically expire on reset */
12339 u8 minWriteFileFormat; /* Minimum file format for writable database files */
@@ -12341,18 +12327,20 @@
12341 u8 usesStmtJournal; /* True if uses a statement journal */
12342 u8 readOnly; /* True for read-only statements */
12343 u8 isPrepareV2; /* True if prepared with prepare_v2() */
12344 int nChange; /* Number of db changes made since last reset */
12345 int btreeMask; /* Bitmask of db->aDb[] entries referenced */
12346 i64 startTime; /* Time when query started - used for profiling */
 
12347 BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
12348 int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
12349 char *zSql; /* Text of the SQL statement that generated this */
12350 void *pFree; /* Free this when deleting the vdbe */
12351 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
12352 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
12353 int iStatement; /* Statement number (or 0 if has not opened stmt) */
 
12354 #ifdef SQLITE_DEBUG
12355 FILE *trace; /* Write an execution trace here, if not NULL */
12356 #endif
12357 VdbeFrame *pFrame; /* Parent frame */
12358 VdbeFrame *pDelFrame; /* List of frame objects to free on VM reset */
@@ -19231,25 +19219,32 @@
19231 /*
19232 ** sqlite3_snprintf() works like snprintf() except that it ignores the
19233 ** current locale settings. This is important for SQLite because we
19234 ** are not able to use a "," as the decimal point in place of "." as
19235 ** specified by some locales.
 
 
 
 
 
 
 
19236 */
 
 
 
 
 
 
 
 
19237 SQLITE_API char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
19238 char *z;
19239 va_list ap;
19240 StrAccum acc;
19241
19242 if( n<=0 ){
19243 return zBuf;
19244 }
19245 sqlite3StrAccumInit(&acc, zBuf, n, 0);
19246 acc.useMalloc = 0;
19247 va_start(ap,zFormat);
19248 sqlite3VXPrintf(&acc, 0, zFormat, ap);
19249 va_end(ap);
19250 z = sqlite3StrAccumFinish(&acc);
19251 return z;
19252 }
19253
19254 /*
19255 ** This is the routine that actually formats the sqlite3_log() message.
@@ -22976,11 +22971,13 @@
22976 #include <sys/stat.h>
22977 #include <fcntl.h>
22978 #include <unistd.h>
22979 #include <sys/time.h>
22980 #include <errno.h>
 
22981 #include <sys/mman.h>
 
22982
22983 #if SQLITE_ENABLE_LOCKING_STYLE
22984 # include <sys/ioctl.h>
22985 # if OS_VXWORKS
22986 # include <semaphore.h>
@@ -34069,15 +34066,11 @@
34069
34070 if( reuseUnlikely || pcache1.nCurrentPage>pcache1.nMaxPage ){
34071 pcache1RemoveFromHash(pPage);
34072 pcache1FreePage(pPage);
34073 }else{
34074 /* Add the page to the global LRU list. Normally, the page is added to
34075 ** the head of the list (last page to be recycled). However, if the
34076 ** reuseUnlikely flag passed to this function is true, the page is added
34077 ** to the tail of the list (first page to be recycled).
34078 */
34079 if( pcache1.pLruHead ){
34080 pcache1.pLruHead->pLruPrev = pPage;
34081 pPage->pLruNext = pcache1.pLruHead;
34082 pcache1.pLruHead = pPage;
34083 }else{
@@ -37523,14 +37516,14 @@
37523 if( rc==SQLITE_OK ){
37524 zMaster = pPager->pTmpSpace;
37525 rc = readMasterJournal(pPager->jfd, zMaster, pPager->pVfs->mxPathname+1);
37526 testcase( rc!=SQLITE_OK );
37527 }
37528 if( rc==SQLITE_OK && !pPager->noSync
37529 && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
37530 ){
37531 rc = sqlite3OsSync(pPager->fd, pPager->syncFlags);
37532 }
37533 if( rc==SQLITE_OK ){
37534 rc = pager_end_transaction(pPager, zMaster[0]!='\0');
37535 testcase( rc!=SQLITE_OK );
37536 }
@@ -37689,26 +37682,63 @@
37689 }
37690
37691 return rc;
37692 }
37693
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37694 /*
37695 ** This function is a wrapper around sqlite3WalFrames(). As well as logging
37696 ** the contents of the list of pages headed by pList (connected by pDirty),
37697 ** this function notifies any active backup processes that the pages have
37698 ** changed.
 
 
 
37699 */
37700 static int pagerWalFrames(
37701 Pager *pPager, /* Pager object */
37702 PgHdr *pList, /* List of frames to log */
37703 Pgno nTruncate, /* Database size after this commit */
37704 int isCommit, /* True if this is a commit */
37705 int syncFlags /* Flags to pass to OsSync() (or 0) */
37706 ){
37707 int rc; /* Return code */
 
 
 
37708
37709 assert( pPager->pWal );
 
 
 
 
 
 
 
 
37710 rc = sqlite3WalFrames(pPager->pWal,
37711 pPager->pageSize, pList, nTruncate, isCommit, syncFlags
37712 );
37713 if( rc==SQLITE_OK && pPager->pBackup ){
37714 PgHdr *p;
@@ -37716,13 +37746,12 @@
37716 sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData);
37717 }
37718 }
37719
37720 #ifdef SQLITE_CHECK_PAGES
37721 {
37722 PgHdr *p;
37723 for(p=pList; p; p=p->pDirty) pager_set_pagehash(p);
37724 }
37725 #endif
37726
37727 return rc;
37728 }
@@ -38743,10 +38772,11 @@
38743 if( pgno<=pPager->dbSize && 0==(pList->flags&PGHDR_DONT_WRITE) ){
38744 i64 offset = (pgno-1)*(i64)pPager->pageSize; /* Offset to write */
38745 char *pData; /* Data to write */
38746
38747 assert( (pList->flags&PGHDR_NEED_SYNC)==0 );
 
38748
38749 /* Encode the database */
38750 CODEC2(pPager, pList->pData, pgno, 6, return SQLITE_NOMEM, pData);
38751
38752 /* Write out the page data. */
@@ -40263,11 +40293,17 @@
40263 }
40264
40265 /*
40266 ** This routine is called to increment the value of the database file
40267 ** change-counter, stored as a 4-byte big-endian integer starting at
40268 ** byte offset 24 of the pager file.
 
 
 
 
 
 
40269 **
40270 ** If the isDirectMode flag is zero, then this is done by calling
40271 ** sqlite3PagerWrite() on page 1, then modifying the contents of the
40272 ** page data. In this case the file will be updated when the current
40273 ** transaction is committed.
@@ -40304,11 +40340,10 @@
40304 # define DIRECT_MODE isDirectMode
40305 #endif
40306
40307 if( !pPager->changeCountDone && pPager->dbSize>0 ){
40308 PgHdr *pPgHdr; /* Reference to page 1 */
40309 u32 change_counter; /* Initial value of change-counter field */
40310
40311 assert( !pPager->tempFile && isOpen(pPager->fd) );
40312
40313 /* Open page 1 of the file for writing. */
40314 rc = sqlite3PagerGet(pPager, 1, &pPgHdr);
@@ -40322,20 +40357,12 @@
40322 if( !DIRECT_MODE && ALWAYS(rc==SQLITE_OK) ){
40323 rc = sqlite3PagerWrite(pPgHdr);
40324 }
40325
40326 if( rc==SQLITE_OK ){
40327 /* Increment the value just read and write it back to byte 24. */
40328 change_counter = sqlite3Get4byte((u8*)pPager->dbFileVers);
40329 change_counter++;
40330 put32bits(((char*)pPgHdr->pData)+24, change_counter);
40331
40332 /* Also store the SQLite version number in bytes 96..99 and in
40333 ** bytes 92..95 store the change counter for which the version number
40334 ** is valid. */
40335 put32bits(((char*)pPgHdr->pData)+92, change_counter);
40336 put32bits(((char*)pPgHdr->pData)+96, SQLITE_VERSION_NUMBER);
40337
40338 /* If running in direct mode, write the contents of page 1 to the file. */
40339 if( DIRECT_MODE ){
40340 const void *zBuf;
40341 assert( pPager->dbFileSize>0 );
@@ -40370,10 +40397,13 @@
40370 if( pPager->noSync ){
40371 rc = SQLITE_OK;
40372 }else{
40373 rc = sqlite3OsSync(pPager->fd, pPager->syncFlags);
40374 }
 
 
 
40375 return rc;
40376 }
40377
40378 /*
40379 ** This function may only be called while a write-transaction is active in
@@ -40587,12 +40617,12 @@
40587 rc = pager_truncate(pPager, nNew);
40588 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
40589 }
40590
40591 /* Finally, sync the database file. */
40592 if( !pPager->noSync && !noSync ){
40593 rc = sqlite3OsSync(pPager->fd, pPager->syncFlags);
40594 }
40595 IOTRACE(("DBSYNC %p\n", pPager))
40596 }
40597 }
40598
@@ -40700,11 +40730,21 @@
40700 int rc2;
40701 rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_ROLLBACK, -1);
40702 rc2 = pager_end_transaction(pPager, pPager->setMaster);
40703 if( rc==SQLITE_OK ) rc = rc2;
40704 }else if( !isOpen(pPager->jfd) || pPager->eState==PAGER_WRITER_LOCKED ){
 
40705 rc = pager_end_transaction(pPager, 0);
 
 
 
 
 
 
 
 
 
40706 }else{
40707 rc = pager_playback(pPager, 0);
40708 }
40709
40710 assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK );
@@ -44732,16 +44772,16 @@
44732 u8 openFlags; /* Flags to sqlite3BtreeOpen() */
44733 #ifndef SQLITE_OMIT_AUTOVACUUM
44734 u8 autoVacuum; /* True if auto-vacuum is enabled */
44735 u8 incrVacuum; /* True if incr-vacuum is enabled */
44736 #endif
 
 
44737 u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */
44738 u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
44739 u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
44740 u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
44741 u8 inTransaction; /* Transaction state */
44742 u8 doNotUseWAL; /* If true, do not open write-ahead-log file */
44743 u32 pageSize; /* Total number of bytes on a page */
44744 u32 usableSize; /* Number of usable bytes on each page */
44745 int nTransaction; /* Number of open transactions (read + write) */
44746 u32 nPage; /* Number of pages in the database */
44747 void *pSchema; /* Pointer to space allocated by sqlite3BtreeSchema() */
@@ -44764,12 +44804,12 @@
44764 ** about a cell. The parseCellPtr() function fills in this structure
44765 ** based on information extract from the raw disk page.
44766 */
44767 typedef struct CellInfo CellInfo;
44768 struct CellInfo {
44769 u8 *pCell; /* Pointer to the start of cell content */
44770 i64 nKey; /* The key for INTKEY tables, or number of bytes in key */
 
44771 u32 nData; /* Number of bytes of data */
44772 u32 nPayload; /* Total amount of payload */
44773 u16 nHeader; /* Size of the cell content header in bytes */
44774 u16 nLocal; /* Amount of payload held locally */
44775 u16 iOverflow; /* Offset to overflow page number. Zero if no overflow */
@@ -44807,24 +44847,24 @@
44807 BtCursor *pNext, *pPrev; /* Forms a linked list of all cursors */
44808 struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */
44809 Pgno pgnoRoot; /* The root page of this tree */
44810 sqlite3_int64 cachedRowid; /* Next rowid cache. 0 means not valid */
44811 CellInfo info; /* A parse of the cell we are pointing at */
 
 
 
44812 u8 wrFlag; /* True if writable */
44813 u8 atLast; /* Cursor pointing to the last entry */
44814 u8 validNKey; /* True if info.nKey is valid */
44815 u8 eState; /* One of the CURSOR_XXX constants (see below) */
44816 void *pKey; /* Saved key that was cursor's last known position */
44817 i64 nKey; /* Size of pKey, or last integer key */
44818 int skipNext; /* Prev() is noop if negative. Next() is noop if positive */
44819 #ifndef SQLITE_OMIT_INCRBLOB
44820 u8 isIncrblobHandle; /* True if this cursor is an incr. io handle */
44821 Pgno *aOverflow; /* Cache of overflow page locations */
 
44822 #endif
44823 i16 iPage; /* Index of current page in apPage */
44824 MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */
44825 u16 aiIdx[BTCURSOR_MAX_DEPTH]; /* Current index in apPage[i] */
 
44826 };
44827
44828 /*
44829 ** Potential values for BtCursor.eState.
44830 **
@@ -47692,11 +47732,11 @@
47692 freeTempSpace(pBt);
47693 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
47694 pageSize-usableSize);
47695 return rc;
47696 }
47697 if( nPageHeader>nPageFile ){
47698 rc = SQLITE_CORRUPT_BKPT;
47699 goto page1_init_failed;
47700 }
47701 if( usableSize<480 ){
47702 goto page1_init_failed;
@@ -53563,10 +53603,20 @@
53563 return 0;
53564 }
53565
53566 return pDb->aDb[i].pBt;
53567 }
 
 
 
 
 
 
 
 
 
 
53568
53569 /*
53570 ** Create an sqlite3_backup process to copy the contents of zSrcDb from
53571 ** connection handle pSrcDb to zDestDb in pDestDb. If successful, return
53572 ** a pointer to the new sqlite3_backup object.
@@ -53617,14 +53667,15 @@
53617 p->pDestDb = pDestDb;
53618 p->pSrcDb = pSrcDb;
53619 p->iNext = 1;
53620 p->isAttached = 0;
53621
53622 if( 0==p->pSrc || 0==p->pDest ){
53623 /* One (or both) of the named databases did not exist. An error has
53624 ** already been written into the pDestDb handle. All that is left
53625 ** to do here is free the sqlite3_backup structure.
 
53626 */
53627 sqlite3_free(p);
53628 p = 0;
53629 }
53630 }
@@ -53877,35 +53928,37 @@
53877 ** pending-byte page in the source database may need to be
53878 ** copied into the destination database.
53879 */
53880 const i64 iSize = (i64)pgszSrc * (i64)nSrcPage;
53881 sqlite3_file * const pFile = sqlite3PagerFile(pDestPager);
 
 
53882
53883 assert( pFile );
53884 assert( (i64)nDestTruncate*(i64)pgszDest >= iSize || (
53885 nDestTruncate==(int)(PENDING_BYTE_PAGE(p->pDest->pBt)-1)
53886 && iSize>=PENDING_BYTE && iSize<=PENDING_BYTE+pgszDest
53887 ));
53888 if( SQLITE_OK==(rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 1))
53889 && SQLITE_OK==(rc = backupTruncateFile(pFile, iSize))
53890 && SQLITE_OK==(rc = sqlite3PagerSync(pDestPager))
53891 ){
53892 i64 iOff;
53893 i64 iEnd = MIN(PENDING_BYTE + pgszDest, iSize);
53894 for(
53895 iOff=PENDING_BYTE+pgszSrc;
53896 rc==SQLITE_OK && iOff<iEnd;
53897 iOff+=pgszSrc
53898 ){
53899 PgHdr *pSrcPg = 0;
53900 const Pgno iSrcPg = (Pgno)((iOff/pgszSrc)+1);
53901 rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg);
53902 if( rc==SQLITE_OK ){
53903 u8 *zData = sqlite3PagerGetData(pSrcPg);
53904 rc = sqlite3OsWrite(pFile, zData, pgszSrc, iOff);
53905 }
53906 sqlite3PagerUnref(pSrcPg);
53907 }
53908 }
53909 }else{
53910 rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
53911 }
@@ -59102,11 +59155,11 @@
59102 ** __attribute__((aligned(8))) macro. */
59103 static const Mem nullMem
59104 #if defined(SQLITE_DEBUG) && defined(__GNUC__)
59105 __attribute__((aligned(8)))
59106 #endif
59107 = {{0}, (double)0, 0, "", 0, MEM_Null, SQLITE_NULL, 0, 0, 0 };
59108
59109 if( pVm && ALWAYS(pVm->db) ){
59110 sqlite3_mutex_enter(pVm->db->mutex);
59111 sqlite3Error(pVm->db, SQLITE_RANGE, 0);
59112 }
@@ -73549,13 +73602,14 @@
73549 sqlite3VdbeAddOp2(v, OP_Rewind, iIdxCur, endOfLoop);
73550 topOfLoop = sqlite3VdbeCurrentAddr(v);
73551 sqlite3VdbeAddOp2(v, OP_AddImm, iMem, 1);
73552
73553 for(i=0; i<nCol; i++){
 
73554 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regCol);
73555 #ifdef SQLITE_ENABLE_STAT2
73556 if( i==0 ){
 
73557 /* Check if the record that cursor iIdxCur points to contains a
73558 ** value that should be stored in the sqlite_stat2 table. If so,
73559 ** store it. */
73560 int ne = sqlite3VdbeAddOp3(v, OP_Ne, regRecno, 0, regSamplerecno);
73561 assert( regTabname+1==regIdxname
@@ -73580,16 +73634,21 @@
73580 sqlite3VdbeAddOp3(v, OP_Divide, regTemp2, regTemp, regTemp);
73581 sqlite3VdbeAddOp3(v, OP_Add, regSamplerecno, regTemp, regSamplerecno);
73582
73583 sqlite3VdbeJumpHere(v, ne);
73584 sqlite3VdbeAddOp2(v, OP_AddImm, regRecno, 1);
73585 }
73586 #endif
73587
73588 sqlite3VdbeAddOp3(v, OP_Ne, regCol, 0, iMem+nCol+i+1);
73589 /**** TODO: add collating sequence *****/
73590 sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
 
 
 
 
 
 
73591 }
73592 if( db->mallocFailed ){
73593 /* If a malloc failure has occurred, then the result of the expression
73594 ** passed as the second argument to the call to sqlite3VdbeJumpHere()
73595 ** below may be negative. Which causes an assert() to fail (or an
@@ -73596,11 +73655,15 @@
73596 ** out-of-bounds write if SQLITE_DEBUG is not defined). */
73597 return;
73598 }
73599 sqlite3VdbeAddOp2(v, OP_Goto, 0, endOfLoop);
73600 for(i=0; i<nCol; i++){
73601 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-(nCol*2));
 
 
 
 
73602 sqlite3VdbeAddOp2(v, OP_AddImm, iMem+i+1, 1);
73603 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, iMem+nCol+i+1);
73604 }
73605
73606 /* End of the analysis loop. */
@@ -73942,12 +74005,15 @@
73942 sqlite3DbFree(db, zSql);
73943 }
73944
73945 if( rc==SQLITE_OK ){
73946 while( sqlite3_step(pStmt)==SQLITE_ROW ){
73947 char *zIndex = (char *)sqlite3_column_text(pStmt, 0);
73948 Index *pIdx = sqlite3FindIndex(db, zIndex, sInfo.zDatabase);
 
 
 
73949 if( pIdx ){
73950 int iSample = sqlite3_column_int(pStmt, 1);
73951 if( iSample<SQLITE_INDEX_SAMPLES && iSample>=0 ){
73952 int eType = sqlite3_column_type(pStmt, 2);
73953
@@ -115616,28 +115682,32 @@
115616 ** the table. The following nCol varints contain the total amount of
115617 ** data stored in all rows of each column of the table, from left
115618 ** to right.
115619 */
115620 sqlite3_stmt *pStmt;
115621 rc = fts3SqlStmt(p, SQL_SELECT_DOCTOTAL, &pStmt, 0);
 
 
 
115622 if( rc ) return rc;
115623 if( sqlite3_step(pStmt)==SQLITE_ROW ){
115624 sqlite3_int64 nDoc = 0;
115625 sqlite3_int64 nByte = 0;
115626 const char *a = sqlite3_column_blob(pStmt, 0);
115627 if( a ){
115628 const char *pEnd = &a[sqlite3_column_bytes(pStmt, 0)];
115629 a += sqlite3Fts3GetVarint(a, &nDoc);
115630 while( a<pEnd ){
115631 a += sqlite3Fts3GetVarint(a, &nByte);
115632 }
115633 }
115634
115635 pCsr->nRowAvg = (int)(((nByte / nDoc) + pgsz - 1) / pgsz);
115636 }
 
115637 rc = sqlite3_reset(pStmt);
115638 if( rc!=SQLITE_OK || pCsr->nRowAvg==0 ) return rc;
115639 }
115640
115641 /* Assume that a blob flows over onto overflow pages if it is larger
115642 ** than (pgsz-35) bytes in size (the file-format documentation
115643 ** confirms this).
@@ -116754,11 +116824,11 @@
116754
116755 if( !isIgnoreEmpty || nList>0 ){
116756 nByte = sqlite3Fts3VarintLen(iDocid-iPrev) + (isRequirePos?nList+1:0);
116757 if( nDoclist+nByte>nAlloc ){
116758 char *aNew;
116759 nAlloc = nDoclist+nByte*2;
116760 aNew = sqlite3_realloc(aBuffer, nAlloc);
116761 if( !aNew ){
116762 rc = SQLITE_NOMEM;
116763 goto finished;
116764 }
@@ -118361,10 +118431,11 @@
118361 if( !*ppStmt ){
118362 int rc = sqlite3Fts3SelectDoctotal(pTab, ppStmt);
118363 if( rc!=SQLITE_OK ) return rc;
118364 }
118365 pStmt = *ppStmt;
 
118366
118367 a = sqlite3_column_blob(pStmt, 0);
118368 a += sqlite3Fts3GetVarint(a, &nDoc);
118369 *pnDoc = (u32)nDoc;
118370
118371
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.7.5. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a one translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -648,13 +648,13 @@
648 **
649 ** See also: [sqlite3_libversion()],
650 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
651 ** [sqlite_version()] and [sqlite_source_id()].
652 */
653 #define SQLITE_VERSION "3.7.5"
654 #define SQLITE_VERSION_NUMBER 3007005
655 #define SQLITE_SOURCE_ID "2011-01-17 02:24:12 b93f6f3e679c7710f42580a8dd9ce43136376c1d"
656
657 /*
658 ** CAPI3REF: Run-Time Library Version Numbers
659 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
660 **
@@ -1261,18 +1261,25 @@
1261 **
1262 ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
1263 ** to the [sqlite3_file] object associated with a particular database
1264 ** connection. See the [sqlite3_file_control()] documentation for
1265 ** additional information.
1266 **
1267 ** The [SQLITE_FCNTL_SYNC] opcode is used internally. SQLite calls
1268 ** the file-control method with this opcode immediately after the database
1269 ** file is synced, or if the database is running in synchronous=off mode
1270 ** immediately after it would have been synced otherwise. This makes it
1271 ** easier to write special VFS modules that depend on the xSync call.
1272 */
1273 #define SQLITE_FCNTL_LOCKSTATE 1
1274 #define SQLITE_GET_LOCKPROXYFILE 2
1275 #define SQLITE_SET_LOCKPROXYFILE 3
1276 #define SQLITE_LAST_ERRNO 4
1277 #define SQLITE_FCNTL_SIZE_HINT 5
1278 #define SQLITE_FCNTL_CHUNK_SIZE 6
1279 #define SQLITE_FCNTL_FILE_POINTER 7
1280 #define SQLITE_FCNTL_SYNC 8
1281
1282
1283 /*
1284 ** CAPI3REF: Mutex Handle
1285 **
@@ -2407,10 +2414,12 @@
2414 ** guarantees that the buffer is always zero-terminated. ^The first
2415 ** parameter "n" is the total size of the buffer, including space for
2416 ** the zero terminator. So the longest string that can be completely
2417 ** written will be n-1 characters.
2418 **
2419 ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
2420 **
2421 ** These routines all implement some additional formatting
2422 ** options that are useful for constructing SQL statements.
2423 ** All of the usual printf() formatting options apply. In addition, there
2424 ** is are "%q", "%Q", and "%z" options.
2425 **
@@ -2470,10 +2479,11 @@
2479 ** the result, [sqlite3_free()] is called on the input string.)^
2480 */
2481 SQLITE_API char *sqlite3_mprintf(const char*,...);
2482 SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
2483 SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
2484 SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
2485
2486 /*
2487 ** CAPI3REF: Memory Allocation Subsystem
2488 **
2489 ** The SQLite core uses these three routines for all of its own
@@ -2847,11 +2857,11 @@
2857 ** <dd>The database is opened for reading and writing if possible, or reading
2858 ** only if the file is write protected by the operating system. In either
2859 ** case the database must already exist, otherwise an error is returned.</dd>)^
2860 **
2861 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
2862 ** <dd>The database is opened for reading and writing, and is created if
2863 ** it does not already exist. This is the behavior that is always used for
2864 ** sqlite3_open() and sqlite3_open16().</dd>)^
2865 ** </dl>
2866 **
2867 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
@@ -3957,20 +3967,20 @@
3967 ** encoding is used, then the fourth argument should be [SQLITE_ANY].
3968 **
3969 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
3970 ** function can gain access to this pointer using [sqlite3_user_data()].)^
3971 **
3972 ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
3973 ** pointers to C-language functions that implement the SQL function or
3974 ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
3975 ** callback only; NULL pointers must be passed as the xStep and xFinal
3976 ** parameters. ^An aggregate SQL function requires an implementation of xStep
3977 ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
3978 ** SQL function or aggregate, pass NULL poiners for all three function
3979 ** callbacks.
3980 **
3981 ** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL,
3982 ** then it is destructor for the application data pointer.
3983 ** The destructor is invoked when the function is deleted, either by being
3984 ** overloaded or when the database connection closes.)^
3985 ** ^The destructor is also invoked if the call to
3986 ** sqlite3_create_function_v2() fails.
@@ -4070,11 +4080,11 @@
4080 ** the function or aggregate.
4081 **
4082 ** The xFunc (for scalar functions) or xStep (for aggregates) parameters
4083 ** to [sqlite3_create_function()] and [sqlite3_create_function16()]
4084 ** define callbacks that implement the SQL functions and aggregates.
4085 ** The 3rd parameter to these callbacks is an array of pointers to
4086 ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for
4087 ** each parameter to the SQL function. These routines are used to
4088 ** extract values from the [sqlite3_value] objects.
4089 **
4090 ** These routines work only with [protected sqlite3_value] objects.
@@ -6235,15 +6245,17 @@
6245 ** SQLite will typically create one cache instance for each open database file,
6246 ** though this is not guaranteed. ^The
6247 ** first parameter, szPage, is the size in bytes of the pages that must
6248 ** be allocated by the cache. ^szPage will not be a power of two. ^szPage
6249 ** will the page size of the database file that is to be cached plus an
6250 ** increment (here called "R") of less than 250. SQLite will use the
6251 ** extra R bytes on each page to store metadata about the underlying
6252 ** database page on disk. The value of R depends
6253 ** on the SQLite version, the target platform, and how SQLite was compiled.
6254 ** ^(R is constant for a particular build of SQLite. Except, there are two
6255 ** distinct values of R when SQLite is compiled with the proprietary
6256 ** ZIPVFS extension.)^ ^The second argument to
6257 ** xCreate(), bPurgeable, is true if the cache being created will
6258 ** be used to cache database pages of a file stored on disk, or
6259 ** false if it is used for an in-memory database. The cache implementation
6260 ** does not have to do anything special based with the value of bPurgeable;
6261 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
@@ -6271,11 +6283,11 @@
6283 ** is considered to be "pinned".
6284 **
6285 ** If the requested page is already in the page cache, then the page cache
6286 ** implementation must return a pointer to the page buffer with its content
6287 ** intact. If the requested page is not already in the cache, then the
6288 ** cache implementation should use the value of the createFlag
6289 ** parameter to help it determined what action to take:
6290 **
6291 ** <table border=1 width=85% align=center>
6292 ** <tr><th> createFlag <th> Behaviour when page is not already in cache
6293 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
@@ -12051,37 +12063,32 @@
12063 ** entries or retrieve the key or data from the entry that the cursor
12064 ** is currently pointing to.
12065 **
12066 ** Every cursor that the virtual machine has open is represented by an
12067 ** instance of the following structure.
 
 
 
 
 
12068 */
12069 struct VdbeCursor {
12070 BtCursor *pCursor; /* The cursor structure of the backend */
12071 Btree *pBt; /* Separate file holding temporary table */
12072 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
12073 int iDb; /* Index of cursor database in db->aDb[] (or -1) */
12074 int pseudoTableReg; /* Register holding pseudotable content. */
12075 int nField; /* Number of fields in the header */
12076 Bool zeroed; /* True if zeroed out and ready for reuse */
12077 Bool rowidIsValid; /* True if lastRowid is valid */
12078 Bool atFirst; /* True if pointing to first entry */
12079 Bool useRandomRowid; /* Generate new record numbers semi-randomly */
12080 Bool nullRow; /* True if pointing to a row with no data */
12081 Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
12082 Bool isTable; /* True if a table requiring integer keys */
12083 Bool isIndex; /* True if an index containing keys only - no data */
12084 Bool isOrdered; /* True if the underlying table is BTREE_UNORDERED */
 
 
 
 
 
 
12085 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
12086 const sqlite3_module *pModule; /* Module for cursor pVtabCursor */
12087 i64 seqCount; /* Sequence counter */
12088 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
12089 i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
12090
12091 /* Result of last sqlite3BtreeMoveto() done by an OP_NotExists or
12092 ** OP_IsUnique opcode on this cursor. */
12093 int seekResult;
12094
@@ -12149,29 +12156,23 @@
12156 #define CACHE_STALE 0
12157
12158 /*
12159 ** Internally, the vdbe manipulates nearly all SQL values as Mem
12160 ** structures. Each Mem struct may cache multiple representations (string,
12161 ** integer etc.) of the same value.
 
 
 
 
 
 
12162 */
12163 struct Mem {
12164 sqlite3 *db; /* The associated database connection */
12165 char *z; /* String or BLOB value */
12166 double r; /* Real value */
12167 union {
12168 i64 i; /* Integer value used when MEM_Int is set in flags */
12169 int nZero; /* Used when bit MEM_Zero is set in flags */
12170 FuncDef *pDef; /* Used only when flags==MEM_Agg */
12171 RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
12172 VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
12173 } u;
 
 
 
12174 int n; /* Number of characters in string value, excluding '\0' */
12175 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
12176 u8 type; /* One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc */
12177 u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
12178 #ifdef SQLITE_DEBUG
@@ -12191,13 +12192,10 @@
12192 ** If the MEM_Str flag is set then Mem.z points at a string representation.
12193 ** Usually this is encoded in the same unicode encoding as the main
12194 ** database (see below for exceptions). If the MEM_Term flag is also
12195 ** set, then the string is nul terminated. The MEM_Int and MEM_Real
12196 ** flags may coexist with the MEM_Str flag.
 
 
 
12197 */
12198 #define MEM_Null 0x0001 /* Value is NULL */
12199 #define MEM_Str 0x0002 /* Value is a string */
12200 #define MEM_Int 0x0004 /* Value is an integer */
12201 #define MEM_Real 0x0008 /* Value is a real number */
@@ -12276,27 +12274,15 @@
12274 Mem *pMem; /* Memory cell used to store aggregate context */
12275 int isError; /* Error code returned by the function. */
12276 CollSeq *pColl; /* Collating sequence */
12277 };
12278
 
 
 
 
 
 
 
 
 
 
 
 
12279 /*
12280 ** An instance of the virtual machine. This structure contains the complete
12281 ** state of the virtual machine.
12282 **
12283 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
12284 ** is really a pointer to an instance of this structure.
12285 **
12286 ** The Vdbe.inVtabMethod variable is set to non-zero for the duration of
12287 ** any virtual table method invocations made by the vdbe program. It is
12288 ** set to 2 for xDestroy method calls and 1 for all other methods. This
@@ -12305,35 +12291,35 @@
12291 ** malloc failure when SQLite is invoked recursively by a virtual table
12292 ** method function.
12293 */
12294 struct Vdbe {
12295 sqlite3 *db; /* The database connection that owns this statement */
 
 
 
12296 Op *aOp; /* Space to hold the virtual machine's program */
12297 Mem *aMem; /* The memory locations */
 
 
12298 Mem **apArg; /* Arguments to currently executing user function */
12299 Mem *aColName; /* Column names to return */
12300 Mem *pResultSet; /* Pointer to an array of results */
12301 int nMem; /* Number of memory locations currently allocated */
12302 int nOp; /* Number of instructions in the program */
12303 int nOpAlloc; /* Number of slots allocated for aOp[] */
12304 int nLabel; /* Number of labels used */
12305 int nLabelAlloc; /* Number of slots allocated in aLabel[] */
12306 int *aLabel; /* Space to hold the labels */
12307 u16 nResColumn; /* Number of columns in one row of the result set */
12308 u16 nCursor; /* Number of slots in apCsr[] */
12309 u32 magic; /* Magic number for sanity checking */
12310 char *zErrMsg; /* Error message written here */
12311 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
12312 VdbeCursor **apCsr; /* One element of this array for each open cursor */
 
 
 
12313 Mem *aVar; /* Values for the OP_Variable opcode. */
12314 char **azVar; /* Name of variables */
12315 ynVar nVar; /* Number of entries in aVar[] */
 
 
12316 u32 cacheCtr; /* VdbeCursor row cache generation counter */
12317 int pc; /* The program counter */
12318 int rc; /* Value to return */
12319 u8 errorAction; /* Recovery action to do in case of an error */
12320 u8 okVar; /* True if azVar[] has been initialized */
12321 u8 explain; /* True if EXPLAIN present on SQL command */
12322 u8 changeCntOn; /* True to update the change-counter */
12323 u8 expired; /* True if the VM needs to be recompiled */
12324 u8 runOnlyOnce; /* Automatically expire on reset */
12325 u8 minWriteFileFormat; /* Minimum file format for writable database files */
@@ -12341,18 +12327,20 @@
12327 u8 usesStmtJournal; /* True if uses a statement journal */
12328 u8 readOnly; /* True for read-only statements */
12329 u8 isPrepareV2; /* True if prepared with prepare_v2() */
12330 int nChange; /* Number of db changes made since last reset */
12331 int btreeMask; /* Bitmask of db->aDb[] entries referenced */
12332 int iStatement; /* Statement number (or 0 if has not opened stmt) */
12333 int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
12334 BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
12335 #ifndef SQLITE_OMIT_TRACE
12336 i64 startTime; /* Time when query started - used for profiling */
12337 #endif
12338 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
12339 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
12340 char *zSql; /* Text of the SQL statement that generated this */
12341 void *pFree; /* Free this when deleting the vdbe */
12342 #ifdef SQLITE_DEBUG
12343 FILE *trace; /* Write an execution trace here, if not NULL */
12344 #endif
12345 VdbeFrame *pFrame; /* Parent frame */
12346 VdbeFrame *pDelFrame; /* List of frame objects to free on VM reset */
@@ -19231,25 +19219,32 @@
19219 /*
19220 ** sqlite3_snprintf() works like snprintf() except that it ignores the
19221 ** current locale settings. This is important for SQLite because we
19222 ** are not able to use a "," as the decimal point in place of "." as
19223 ** specified by some locales.
19224 **
19225 ** Oops: The first two arguments of sqlite3_snprintf() are backwards
19226 ** from the snprintf() standard. Unfortunately, it is too late to change
19227 ** this without breaking compatibility, so we just have to live with the
19228 ** mistake.
19229 **
19230 ** sqlite3_vsnprintf() is the varargs version.
19231 */
19232 SQLITE_API char *sqlite3_vsnprintf(int n, char *zBuf, const char *zFormat, va_list ap){
19233 StrAccum acc;
19234 if( n<=0 ) return zBuf;
19235 sqlite3StrAccumInit(&acc, zBuf, n, 0);
19236 acc.useMalloc = 0;
19237 sqlite3VXPrintf(&acc, 0, zFormat, ap);
19238 return sqlite3StrAccumFinish(&acc);
19239 }
19240 SQLITE_API char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
19241 char *z;
19242 va_list ap;
 
 
 
 
 
 
 
19243 va_start(ap,zFormat);
19244 z = sqlite3_vsnprintf(n, zBuf, zFormat, ap);
19245 va_end(ap);
 
19246 return z;
19247 }
19248
19249 /*
19250 ** This is the routine that actually formats the sqlite3_log() message.
@@ -22976,11 +22971,13 @@
22971 #include <sys/stat.h>
22972 #include <fcntl.h>
22973 #include <unistd.h>
22974 #include <sys/time.h>
22975 #include <errno.h>
22976 #ifndef SQLITE_OMIT_WAL
22977 #include <sys/mman.h>
22978 #endif
22979
22980 #if SQLITE_ENABLE_LOCKING_STYLE
22981 # include <sys/ioctl.h>
22982 # if OS_VXWORKS
22983 # include <semaphore.h>
@@ -34069,15 +34066,11 @@
34066
34067 if( reuseUnlikely || pcache1.nCurrentPage>pcache1.nMaxPage ){
34068 pcache1RemoveFromHash(pPage);
34069 pcache1FreePage(pPage);
34070 }else{
34071 /* Add the page to the global LRU list. */
 
 
 
 
34072 if( pcache1.pLruHead ){
34073 pcache1.pLruHead->pLruPrev = pPage;
34074 pPage->pLruNext = pcache1.pLruHead;
34075 pcache1.pLruHead = pPage;
34076 }else{
@@ -37523,14 +37516,14 @@
37516 if( rc==SQLITE_OK ){
37517 zMaster = pPager->pTmpSpace;
37518 rc = readMasterJournal(pPager->jfd, zMaster, pPager->pVfs->mxPathname+1);
37519 testcase( rc!=SQLITE_OK );
37520 }
37521 if( rc==SQLITE_OK
37522 && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
37523 ){
37524 rc = sqlite3PagerSync(pPager);
37525 }
37526 if( rc==SQLITE_OK ){
37527 rc = pager_end_transaction(pPager, zMaster[0]!='\0');
37528 testcase( rc!=SQLITE_OK );
37529 }
@@ -37689,26 +37682,63 @@
37682 }
37683
37684 return rc;
37685 }
37686
37687
37688 /*
37689 ** Update the value of the change-counter at offsets 24 and 92 in
37690 ** the header and the sqlite version number at offset 96.
37691 **
37692 ** This is an unconditional update. See also the pager_incr_changecounter()
37693 ** routine which only updates the change-counter if the update is actually
37694 ** needed, as determined by the pPager->changeCountDone state variable.
37695 */
37696 static void pager_write_changecounter(PgHdr *pPg){
37697 u32 change_counter;
37698
37699 /* Increment the value just read and write it back to byte 24. */
37700 change_counter = sqlite3Get4byte((u8*)pPg->pPager->dbFileVers)+1;
37701 put32bits(((char*)pPg->pData)+24, change_counter);
37702
37703 /* Also store the SQLite version number in bytes 96..99 and in
37704 ** bytes 92..95 store the change counter for which the version number
37705 ** is valid. */
37706 put32bits(((char*)pPg->pData)+92, change_counter);
37707 put32bits(((char*)pPg->pData)+96, SQLITE_VERSION_NUMBER);
37708 }
37709
37710 /*
37711 ** This function is a wrapper around sqlite3WalFrames(). As well as logging
37712 ** the contents of the list of pages headed by pList (connected by pDirty),
37713 ** this function notifies any active backup processes that the pages have
37714 ** changed.
37715 **
37716 ** The list of pages passed into this routine is always sorted by page number.
37717 ** Hence, if page 1 appears anywhere on the list, it will be the first page.
37718 */
37719 static int pagerWalFrames(
37720 Pager *pPager, /* Pager object */
37721 PgHdr *pList, /* List of frames to log */
37722 Pgno nTruncate, /* Database size after this commit */
37723 int isCommit, /* True if this is a commit */
37724 int syncFlags /* Flags to pass to OsSync() (or 0) */
37725 ){
37726 int rc; /* Return code */
37727 #if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES)
37728 PgHdr *p; /* For looping over pages */
37729 #endif
37730
37731 assert( pPager->pWal );
37732 #ifdef SQLITE_DEBUG
37733 /* Verify that the page list is in accending order */
37734 for(p=pList; p && p->pDirty; p=p->pDirty){
37735 assert( p->pgno < p->pDirty->pgno );
37736 }
37737 #endif
37738
37739 if( pList->pgno==1 ) pager_write_changecounter(pList);
37740 rc = sqlite3WalFrames(pPager->pWal,
37741 pPager->pageSize, pList, nTruncate, isCommit, syncFlags
37742 );
37743 if( rc==SQLITE_OK && pPager->pBackup ){
37744 PgHdr *p;
@@ -37716,13 +37746,12 @@
37746 sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData);
37747 }
37748 }
37749
37750 #ifdef SQLITE_CHECK_PAGES
37751 for(p=pList; p; p=p->pDirty){
37752 pager_set_pagehash(p);
 
37753 }
37754 #endif
37755
37756 return rc;
37757 }
@@ -38743,10 +38772,11 @@
38772 if( pgno<=pPager->dbSize && 0==(pList->flags&PGHDR_DONT_WRITE) ){
38773 i64 offset = (pgno-1)*(i64)pPager->pageSize; /* Offset to write */
38774 char *pData; /* Data to write */
38775
38776 assert( (pList->flags&PGHDR_NEED_SYNC)==0 );
38777 if( pList->pgno==1 ) pager_write_changecounter(pList);
38778
38779 /* Encode the database */
38780 CODEC2(pPager, pList->pData, pgno, 6, return SQLITE_NOMEM, pData);
38781
38782 /* Write out the page data. */
@@ -40263,11 +40293,17 @@
40293 }
40294
40295 /*
40296 ** This routine is called to increment the value of the database file
40297 ** change-counter, stored as a 4-byte big-endian integer starting at
40298 ** byte offset 24 of the pager file. The secondary change counter at
40299 ** 92 is also updated, as is the SQLite version number at offset 96.
40300 **
40301 ** But this only happens if the pPager->changeCountDone flag is false.
40302 ** To avoid excess churning of page 1, the update only happens once.
40303 ** See also the pager_write_changecounter() routine that does an
40304 ** unconditional update of the change counters.
40305 **
40306 ** If the isDirectMode flag is zero, then this is done by calling
40307 ** sqlite3PagerWrite() on page 1, then modifying the contents of the
40308 ** page data. In this case the file will be updated when the current
40309 ** transaction is committed.
@@ -40304,11 +40340,10 @@
40340 # define DIRECT_MODE isDirectMode
40341 #endif
40342
40343 if( !pPager->changeCountDone && pPager->dbSize>0 ){
40344 PgHdr *pPgHdr; /* Reference to page 1 */
 
40345
40346 assert( !pPager->tempFile && isOpen(pPager->fd) );
40347
40348 /* Open page 1 of the file for writing. */
40349 rc = sqlite3PagerGet(pPager, 1, &pPgHdr);
@@ -40322,20 +40357,12 @@
40357 if( !DIRECT_MODE && ALWAYS(rc==SQLITE_OK) ){
40358 rc = sqlite3PagerWrite(pPgHdr);
40359 }
40360
40361 if( rc==SQLITE_OK ){
40362 /* Actually do the update of the change counter */
40363 pager_write_changecounter(pPgHdr);
 
 
 
 
 
 
 
 
40364
40365 /* If running in direct mode, write the contents of page 1 to the file. */
40366 if( DIRECT_MODE ){
40367 const void *zBuf;
40368 assert( pPager->dbFileSize>0 );
@@ -40370,10 +40397,13 @@
40397 if( pPager->noSync ){
40398 rc = SQLITE_OK;
40399 }else{
40400 rc = sqlite3OsSync(pPager->fd, pPager->syncFlags);
40401 }
40402 if( isOpen(pPager->fd) ){
40403 sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC, (void *)&rc);
40404 }
40405 return rc;
40406 }
40407
40408 /*
40409 ** This function may only be called while a write-transaction is active in
@@ -40587,12 +40617,12 @@
40617 rc = pager_truncate(pPager, nNew);
40618 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
40619 }
40620
40621 /* Finally, sync the database file. */
40622 if( !noSync ){
40623 rc = sqlite3PagerSync(pPager);
40624 }
40625 IOTRACE(("DBSYNC %p\n", pPager))
40626 }
40627 }
40628
@@ -40700,11 +40730,21 @@
40730 int rc2;
40731 rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_ROLLBACK, -1);
40732 rc2 = pager_end_transaction(pPager, pPager->setMaster);
40733 if( rc==SQLITE_OK ) rc = rc2;
40734 }else if( !isOpen(pPager->jfd) || pPager->eState==PAGER_WRITER_LOCKED ){
40735 int eState = pPager->eState;
40736 rc = pager_end_transaction(pPager, 0);
40737 if( !MEMDB && eState>PAGER_WRITER_LOCKED ){
40738 /* This can happen using journal_mode=off. Move the pager to the error
40739 ** state to indicate that the contents of the cache may not be trusted.
40740 ** Any active readers will get SQLITE_ABORT.
40741 */
40742 pPager->errCode = SQLITE_ABORT;
40743 pPager->eState = PAGER_ERROR;
40744 return rc;
40745 }
40746 }else{
40747 rc = pager_playback(pPager, 0);
40748 }
40749
40750 assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK );
@@ -44732,16 +44772,16 @@
44772 u8 openFlags; /* Flags to sqlite3BtreeOpen() */
44773 #ifndef SQLITE_OMIT_AUTOVACUUM
44774 u8 autoVacuum; /* True if auto-vacuum is enabled */
44775 u8 incrVacuum; /* True if incr-vacuum is enabled */
44776 #endif
44777 u8 inTransaction; /* Transaction state */
44778 u8 doNotUseWAL; /* If true, do not open write-ahead-log file */
44779 u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */
44780 u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */
44781 u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */
44782 u16 minLeaf; /* Minimum local payload in a LEAFDATA table */
 
 
44783 u32 pageSize; /* Total number of bytes on a page */
44784 u32 usableSize; /* Number of usable bytes on each page */
44785 int nTransaction; /* Number of open transactions (read + write) */
44786 u32 nPage; /* Number of pages in the database */
44787 void *pSchema; /* Pointer to space allocated by sqlite3BtreeSchema() */
@@ -44764,12 +44804,12 @@
44804 ** about a cell. The parseCellPtr() function fills in this structure
44805 ** based on information extract from the raw disk page.
44806 */
44807 typedef struct CellInfo CellInfo;
44808 struct CellInfo {
 
44809 i64 nKey; /* The key for INTKEY tables, or number of bytes in key */
44810 u8 *pCell; /* Pointer to the start of cell content */
44811 u32 nData; /* Number of bytes of data */
44812 u32 nPayload; /* Total amount of payload */
44813 u16 nHeader; /* Size of the cell content header in bytes */
44814 u16 nLocal; /* Amount of payload held locally */
44815 u16 iOverflow; /* Offset to overflow page number. Zero if no overflow */
@@ -44807,24 +44847,24 @@
44847 BtCursor *pNext, *pPrev; /* Forms a linked list of all cursors */
44848 struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */
44849 Pgno pgnoRoot; /* The root page of this tree */
44850 sqlite3_int64 cachedRowid; /* Next rowid cache. 0 means not valid */
44851 CellInfo info; /* A parse of the cell we are pointing at */
44852 i64 nKey; /* Size of pKey, or last integer key */
44853 void *pKey; /* Saved key that was cursor's last known position */
44854 int skipNext; /* Prev() is noop if negative. Next() is noop if positive */
44855 u8 wrFlag; /* True if writable */
44856 u8 atLast; /* Cursor pointing to the last entry */
44857 u8 validNKey; /* True if info.nKey is valid */
44858 u8 eState; /* One of the CURSOR_XXX constants (see below) */
 
 
 
44859 #ifndef SQLITE_OMIT_INCRBLOB
 
44860 Pgno *aOverflow; /* Cache of overflow page locations */
44861 u8 isIncrblobHandle; /* True if this cursor is an incr. io handle */
44862 #endif
44863 i16 iPage; /* Index of current page in apPage */
 
44864 u16 aiIdx[BTCURSOR_MAX_DEPTH]; /* Current index in apPage[i] */
44865 MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */
44866 };
44867
44868 /*
44869 ** Potential values for BtCursor.eState.
44870 **
@@ -47692,11 +47732,11 @@
47732 freeTempSpace(pBt);
47733 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
47734 pageSize-usableSize);
47735 return rc;
47736 }
47737 if( (pBt->db->flags & SQLITE_RecoveryMode)==0 && nPageHeader>nPageFile ){
47738 rc = SQLITE_CORRUPT_BKPT;
47739 goto page1_init_failed;
47740 }
47741 if( usableSize<480 ){
47742 goto page1_init_failed;
@@ -53563,10 +53603,20 @@
53603 return 0;
53604 }
53605
53606 return pDb->aDb[i].pBt;
53607 }
53608
53609 /*
53610 ** Attempt to set the page size of the destination to match the page size
53611 ** of the source.
53612 */
53613 static int setDestPgsz(sqlite3_backup *p){
53614 int rc;
53615 rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),-1,0);
53616 return rc;
53617 }
53618
53619 /*
53620 ** Create an sqlite3_backup process to copy the contents of zSrcDb from
53621 ** connection handle pSrcDb to zDestDb in pDestDb. If successful, return
53622 ** a pointer to the new sqlite3_backup object.
@@ -53617,14 +53667,15 @@
53667 p->pDestDb = pDestDb;
53668 p->pSrcDb = pSrcDb;
53669 p->iNext = 1;
53670 p->isAttached = 0;
53671
53672 if( 0==p->pSrc || 0==p->pDest || setDestPgsz(p)==SQLITE_NOMEM ){
53673 /* One (or both) of the named databases did not exist or an OOM
53674 ** error was hit. The error has already been written into the
53675 ** pDestDb handle. All that is left to do here is free the
53676 ** sqlite3_backup structure.
53677 */
53678 sqlite3_free(p);
53679 p = 0;
53680 }
53681 }
@@ -53877,35 +53928,37 @@
53928 ** pending-byte page in the source database may need to be
53929 ** copied into the destination database.
53930 */
53931 const i64 iSize = (i64)pgszSrc * (i64)nSrcPage;
53932 sqlite3_file * const pFile = sqlite3PagerFile(pDestPager);
53933 i64 iOff;
53934 i64 iEnd;
53935
53936 assert( pFile );
53937 assert( (i64)nDestTruncate*(i64)pgszDest >= iSize || (
53938 nDestTruncate==(int)(PENDING_BYTE_PAGE(p->pDest->pBt)-1)
53939 && iSize>=PENDING_BYTE && iSize<=PENDING_BYTE+pgszDest
53940 ));
53941 iEnd = MIN(PENDING_BYTE + pgszDest, iSize);
53942 for(
53943 iOff=PENDING_BYTE+pgszSrc;
53944 rc==SQLITE_OK && iOff<iEnd;
53945 iOff+=pgszSrc
53946 ){
53947 PgHdr *pSrcPg = 0;
53948 const Pgno iSrcPg = (Pgno)((iOff/pgszSrc)+1);
53949 rc = sqlite3PagerGet(pSrcPager, iSrcPg, &pSrcPg);
53950 if( rc==SQLITE_OK ){
53951 u8 *zData = sqlite3PagerGetData(pSrcPg);
53952 rc = sqlite3OsWrite(pFile, zData, pgszSrc, iOff);
53953 }
53954 sqlite3PagerUnref(pSrcPg);
53955 }
53956 if( rc==SQLITE_OK ){
53957 rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 1);
53958 if( rc==SQLITE_OK ){
53959 rc = backupTruncateFile(pFile, iSize);
53960 }
53961 }
53962 }else{
53963 rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0);
53964 }
@@ -59102,11 +59155,11 @@
59155 ** __attribute__((aligned(8))) macro. */
59156 static const Mem nullMem
59157 #if defined(SQLITE_DEBUG) && defined(__GNUC__)
59158 __attribute__((aligned(8)))
59159 #endif
59160 = {0, "", (double)0, {0}, 0, MEM_Null, SQLITE_NULL, 0, 0, 0 };
59161
59162 if( pVm && ALWAYS(pVm->db) ){
59163 sqlite3_mutex_enter(pVm->db->mutex);
59164 sqlite3Error(pVm->db, SQLITE_RANGE, 0);
59165 }
@@ -73549,13 +73602,14 @@
73602 sqlite3VdbeAddOp2(v, OP_Rewind, iIdxCur, endOfLoop);
73603 topOfLoop = sqlite3VdbeCurrentAddr(v);
73604 sqlite3VdbeAddOp2(v, OP_AddImm, iMem, 1);
73605
73606 for(i=0; i<nCol; i++){
73607 CollSeq *pColl;
73608 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regCol);
 
73609 if( i==0 ){
73610 #ifdef SQLITE_ENABLE_STAT2
73611 /* Check if the record that cursor iIdxCur points to contains a
73612 ** value that should be stored in the sqlite_stat2 table. If so,
73613 ** store it. */
73614 int ne = sqlite3VdbeAddOp3(v, OP_Ne, regRecno, 0, regSamplerecno);
73615 assert( regTabname+1==regIdxname
@@ -73580,16 +73634,21 @@
73634 sqlite3VdbeAddOp3(v, OP_Divide, regTemp2, regTemp, regTemp);
73635 sqlite3VdbeAddOp3(v, OP_Add, regSamplerecno, regTemp, regSamplerecno);
73636
73637 sqlite3VdbeJumpHere(v, ne);
73638 sqlite3VdbeAddOp2(v, OP_AddImm, regRecno, 1);
 
73639 #endif
73640
73641 /* Always record the very first row */
73642 sqlite3VdbeAddOp1(v, OP_IfNot, iMem+1);
73643 }
73644 assert( pIdx->azColl!=0 );
73645 assert( pIdx->azColl[i]!=0 );
73646 pColl = sqlite3LocateCollSeq(pParse, pIdx->azColl[i]);
73647 sqlite3VdbeAddOp4(v, OP_Ne, regCol, 0, iMem+nCol+i+1,
73648 (char*)pColl, P4_COLLSEQ);
73649 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
73650 }
73651 if( db->mallocFailed ){
73652 /* If a malloc failure has occurred, then the result of the expression
73653 ** passed as the second argument to the call to sqlite3VdbeJumpHere()
73654 ** below may be negative. Which causes an assert() to fail (or an
@@ -73596,11 +73655,15 @@
73655 ** out-of-bounds write if SQLITE_DEBUG is not defined). */
73656 return;
73657 }
73658 sqlite3VdbeAddOp2(v, OP_Goto, 0, endOfLoop);
73659 for(i=0; i<nCol; i++){
73660 int addr = sqlite3VdbeCurrentAddr(v) - (nCol*2);
73661 if( i==0 ){
73662 sqlite3VdbeJumpHere(v, addr-1); /* Set jump dest for the OP_IfNot */
73663 }
73664 sqlite3VdbeJumpHere(v, addr); /* Set jump dest for the OP_Ne */
73665 sqlite3VdbeAddOp2(v, OP_AddImm, iMem+i+1, 1);
73666 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, iMem+nCol+i+1);
73667 }
73668
73669 /* End of the analysis loop. */
@@ -73942,12 +74005,15 @@
74005 sqlite3DbFree(db, zSql);
74006 }
74007
74008 if( rc==SQLITE_OK ){
74009 while( sqlite3_step(pStmt)==SQLITE_ROW ){
74010 char *zIndex; /* Index name */
74011 Index *pIdx; /* Pointer to the index object */
74012
74013 zIndex = (char *)sqlite3_column_text(pStmt, 0);
74014 pIdx = zIndex ? sqlite3FindIndex(db, zIndex, sInfo.zDatabase) : 0;
74015 if( pIdx ){
74016 int iSample = sqlite3_column_int(pStmt, 1);
74017 if( iSample<SQLITE_INDEX_SAMPLES && iSample>=0 ){
74018 int eType = sqlite3_column_type(pStmt, 2);
74019
@@ -115616,28 +115682,32 @@
115682 ** the table. The following nCol varints contain the total amount of
115683 ** data stored in all rows of each column of the table, from left
115684 ** to right.
115685 */
115686 sqlite3_stmt *pStmt;
115687 sqlite3_int64 nDoc = 0;
115688 sqlite3_int64 nByte = 0;
115689 const char *a;
115690 rc = sqlite3Fts3SelectDoctotal(p, &pStmt);
115691 if( rc ) return rc;
115692 a = sqlite3_column_blob(pStmt, 0);
115693 if( a ){
115694 const char *pEnd = &a[sqlite3_column_bytes(pStmt, 0)];
115695 a += sqlite3Fts3GetVarint(a, &nDoc);
115696 while( a<pEnd ){
115697 a += sqlite3Fts3GetVarint(a, &nByte);
115698 }
115699 }
115700 if( nDoc==0 || nByte==0 ){
115701 sqlite3_reset(pStmt);
115702 return SQLITE_CORRUPT;
115703 }
115704
115705 pCsr->nRowAvg = (int)(((nByte / nDoc) + pgsz) / pgsz);
115706 assert( pCsr->nRowAvg>0 );
115707 rc = sqlite3_reset(pStmt);
115708 if( rc!=SQLITE_OK ) return rc;
115709 }
115710
115711 /* Assume that a blob flows over onto overflow pages if it is larger
115712 ** than (pgsz-35) bytes in size (the file-format documentation
115713 ** confirms this).
@@ -116754,11 +116824,11 @@
116824
116825 if( !isIgnoreEmpty || nList>0 ){
116826 nByte = sqlite3Fts3VarintLen(iDocid-iPrev) + (isRequirePos?nList+1:0);
116827 if( nDoclist+nByte>nAlloc ){
116828 char *aNew;
116829 nAlloc = (nDoclist+nByte)*2;
116830 aNew = sqlite3_realloc(aBuffer, nAlloc);
116831 if( !aNew ){
116832 rc = SQLITE_NOMEM;
116833 goto finished;
116834 }
@@ -118361,10 +118431,11 @@
118431 if( !*ppStmt ){
118432 int rc = sqlite3Fts3SelectDoctotal(pTab, ppStmt);
118433 if( rc!=SQLITE_OK ) return rc;
118434 }
118435 pStmt = *ppStmt;
118436 assert( sqlite3_data_count(pStmt)==1 );
118437
118438 a = sqlite3_column_blob(pStmt, 0);
118439 a += sqlite3Fts3GetVarint(a, &nDoc);
118440 *pnDoc = (u32)nDoc;
118441
118442
+22 -10
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105105
**
106106
** See also: [sqlite3_libversion()],
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110
-#define SQLITE_VERSION "3.7.4"
111
-#define SQLITE_VERSION_NUMBER 3007004
112
-#define SQLITE_SOURCE_ID "2010-12-21 21:28:38 b0888047bb6d9ac55e29b9224df2ff650728bb78"
110
+#define SQLITE_VERSION "3.7.5"
111
+#define SQLITE_VERSION_NUMBER 3007005
112
+#define SQLITE_SOURCE_ID "2011-01-17 02:24:12 b93f6f3e679c7710f42580a8dd9ce43136376c1d"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -718,18 +718,25 @@
718718
**
719719
** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
720720
** to the [sqlite3_file] object associated with a particular database
721721
** connection. See the [sqlite3_file_control()] documentation for
722722
** additional information.
723
+**
724
+** The [SQLITE_FCNTL_SYNC] opcode is used internally. SQLite calls
725
+** the file-control method with this opcode immediately after the database
726
+** file is synced, or if the database is running in synchronous=off mode
727
+** immediately after it would have been synced otherwise. This makes it
728
+** easier to write special VFS modules that depend on the xSync call.
723729
*/
724730
#define SQLITE_FCNTL_LOCKSTATE 1
725731
#define SQLITE_GET_LOCKPROXYFILE 2
726732
#define SQLITE_SET_LOCKPROXYFILE 3
727733
#define SQLITE_LAST_ERRNO 4
728734
#define SQLITE_FCNTL_SIZE_HINT 5
729735
#define SQLITE_FCNTL_CHUNK_SIZE 6
730736
#define SQLITE_FCNTL_FILE_POINTER 7
737
+#define SQLITE_FCNTL_SYNC 8
731738
732739
733740
/*
734741
** CAPI3REF: Mutex Handle
735742
**
@@ -1864,10 +1871,12 @@
18641871
** guarantees that the buffer is always zero-terminated. ^The first
18651872
** parameter "n" is the total size of the buffer, including space for
18661873
** the zero terminator. So the longest string that can be completely
18671874
** written will be n-1 characters.
18681875
**
1876
+** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
1877
+**
18691878
** These routines all implement some additional formatting
18701879
** options that are useful for constructing SQL statements.
18711880
** All of the usual printf() formatting options apply. In addition, there
18721881
** is are "%q", "%Q", and "%z" options.
18731882
**
@@ -1927,10 +1936,11 @@
19271936
** the result, [sqlite3_free()] is called on the input string.)^
19281937
*/
19291938
SQLITE_API char *sqlite3_mprintf(const char*,...);
19301939
SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
19311940
SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
1941
+SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
19321942
19331943
/*
19341944
** CAPI3REF: Memory Allocation Subsystem
19351945
**
19361946
** The SQLite core uses these three routines for all of its own
@@ -2304,11 +2314,11 @@
23042314
** <dd>The database is opened for reading and writing if possible, or reading
23052315
** only if the file is write protected by the operating system. In either
23062316
** case the database must already exist, otherwise an error is returned.</dd>)^
23072317
**
23082318
** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
2309
-** <dd>The database is opened for reading and writing, and is creates it if
2319
+** <dd>The database is opened for reading and writing, and is created if
23102320
** it does not already exist. This is the behavior that is always used for
23112321
** sqlite3_open() and sqlite3_open16().</dd>)^
23122322
** </dl>
23132323
**
23142324
** If the 3rd parameter to sqlite3_open_v2() is not one of the
@@ -3414,20 +3424,20 @@
34143424
** encoding is used, then the fourth argument should be [SQLITE_ANY].
34153425
**
34163426
** ^(The fifth parameter is an arbitrary pointer. The implementation of the
34173427
** function can gain access to this pointer using [sqlite3_user_data()].)^
34183428
**
3419
-** ^The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
3429
+** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
34203430
** pointers to C-language functions that implement the SQL function or
34213431
** aggregate. ^A scalar SQL function requires an implementation of the xFunc
34223432
** callback only; NULL pointers must be passed as the xStep and xFinal
34233433
** parameters. ^An aggregate SQL function requires an implementation of xStep
34243434
** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
34253435
** SQL function or aggregate, pass NULL poiners for all three function
34263436
** callbacks.
34273437
**
3428
-** ^(If the tenth parameter to sqlite3_create_function_v2() is not NULL,
3438
+** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL,
34293439
** then it is destructor for the application data pointer.
34303440
** The destructor is invoked when the function is deleted, either by being
34313441
** overloaded or when the database connection closes.)^
34323442
** ^The destructor is also invoked if the call to
34333443
** sqlite3_create_function_v2() fails.
@@ -3527,11 +3537,11 @@
35273537
** the function or aggregate.
35283538
**
35293539
** The xFunc (for scalar functions) or xStep (for aggregates) parameters
35303540
** to [sqlite3_create_function()] and [sqlite3_create_function16()]
35313541
** define callbacks that implement the SQL functions and aggregates.
3532
-** The 4th parameter to these callbacks is an array of pointers to
3542
+** The 3rd parameter to these callbacks is an array of pointers to
35333543
** [protected sqlite3_value] objects. There is one [sqlite3_value] object for
35343544
** each parameter to the SQL function. These routines are used to
35353545
** extract values from the [sqlite3_value] objects.
35363546
**
35373547
** These routines work only with [protected sqlite3_value] objects.
@@ -5692,15 +5702,17 @@
56925702
** SQLite will typically create one cache instance for each open database file,
56935703
** though this is not guaranteed. ^The
56945704
** first parameter, szPage, is the size in bytes of the pages that must
56955705
** be allocated by the cache. ^szPage will not be a power of two. ^szPage
56965706
** will the page size of the database file that is to be cached plus an
5697
-** increment (here called "R") of about 100 or 200. SQLite will use the
5707
+** increment (here called "R") of less than 250. SQLite will use the
56985708
** extra R bytes on each page to store metadata about the underlying
56995709
** database page on disk. The value of R depends
57005710
** on the SQLite version, the target platform, and how SQLite was compiled.
5701
-** ^R is constant for a particular build of SQLite. ^The second argument to
5711
+** ^(R is constant for a particular build of SQLite. Except, there are two
5712
+** distinct values of R when SQLite is compiled with the proprietary
5713
+** ZIPVFS extension.)^ ^The second argument to
57025714
** xCreate(), bPurgeable, is true if the cache being created will
57035715
** be used to cache database pages of a file stored on disk, or
57045716
** false if it is used for an in-memory database. The cache implementation
57055717
** does not have to do anything special based with the value of bPurgeable;
57065718
** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
@@ -5728,11 +5740,11 @@
57285740
** is considered to be "pinned".
57295741
**
57305742
** If the requested page is already in the page cache, then the page cache
57315743
** implementation must return a pointer to the page buffer with its content
57325744
** intact. If the requested page is not already in the cache, then the
5733
-** behavior of the cache implementation should use the value of the createFlag
5745
+** cache implementation should use the value of the createFlag
57345746
** parameter to help it determined what action to take:
57355747
**
57365748
** <table border=1 width=85% align=center>
57375749
** <tr><th> createFlag <th> Behaviour when page is not already in cache
57385750
** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
57395751
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.4"
111 #define SQLITE_VERSION_NUMBER 3007004
112 #define SQLITE_SOURCE_ID "2010-12-21 21:28:38 b0888047bb6d9ac55e29b9224df2ff650728bb78"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -718,18 +718,25 @@
718 **
719 ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
720 ** to the [sqlite3_file] object associated with a particular database
721 ** connection. See the [sqlite3_file_control()] documentation for
722 ** additional information.
 
 
 
 
 
 
723 */
724 #define SQLITE_FCNTL_LOCKSTATE 1
725 #define SQLITE_GET_LOCKPROXYFILE 2
726 #define SQLITE_SET_LOCKPROXYFILE 3
727 #define SQLITE_LAST_ERRNO 4
728 #define SQLITE_FCNTL_SIZE_HINT 5
729 #define SQLITE_FCNTL_CHUNK_SIZE 6
730 #define SQLITE_FCNTL_FILE_POINTER 7
 
731
732
733 /*
734 ** CAPI3REF: Mutex Handle
735 **
@@ -1864,10 +1871,12 @@
1864 ** guarantees that the buffer is always zero-terminated. ^The first
1865 ** parameter "n" is the total size of the buffer, including space for
1866 ** the zero terminator. So the longest string that can be completely
1867 ** written will be n-1 characters.
1868 **
 
 
1869 ** These routines all implement some additional formatting
1870 ** options that are useful for constructing SQL statements.
1871 ** All of the usual printf() formatting options apply. In addition, there
1872 ** is are "%q", "%Q", and "%z" options.
1873 **
@@ -1927,10 +1936,11 @@
1927 ** the result, [sqlite3_free()] is called on the input string.)^
1928 */
1929 SQLITE_API char *sqlite3_mprintf(const char*,...);
1930 SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
1931 SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
 
1932
1933 /*
1934 ** CAPI3REF: Memory Allocation Subsystem
1935 **
1936 ** The SQLite core uses these three routines for all of its own
@@ -2304,11 +2314,11 @@
2304 ** <dd>The database is opened for reading and writing if possible, or reading
2305 ** only if the file is write protected by the operating system. In either
2306 ** case the database must already exist, otherwise an error is returned.</dd>)^
2307 **
2308 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
2309 ** <dd>The database is opened for reading and writing, and is creates it if
2310 ** it does not already exist. This is the behavior that is always used for
2311 ** sqlite3_open() and sqlite3_open16().</dd>)^
2312 ** </dl>
2313 **
2314 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
@@ -3414,20 +3424,20 @@
3414 ** encoding is used, then the fourth argument should be [SQLITE_ANY].
3415 **
3416 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
3417 ** function can gain access to this pointer using [sqlite3_user_data()].)^
3418 **
3419 ** ^The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are
3420 ** pointers to C-language functions that implement the SQL function or
3421 ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
3422 ** callback only; NULL pointers must be passed as the xStep and xFinal
3423 ** parameters. ^An aggregate SQL function requires an implementation of xStep
3424 ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
3425 ** SQL function or aggregate, pass NULL poiners for all three function
3426 ** callbacks.
3427 **
3428 ** ^(If the tenth parameter to sqlite3_create_function_v2() is not NULL,
3429 ** then it is destructor for the application data pointer.
3430 ** The destructor is invoked when the function is deleted, either by being
3431 ** overloaded or when the database connection closes.)^
3432 ** ^The destructor is also invoked if the call to
3433 ** sqlite3_create_function_v2() fails.
@@ -3527,11 +3537,11 @@
3527 ** the function or aggregate.
3528 **
3529 ** The xFunc (for scalar functions) or xStep (for aggregates) parameters
3530 ** to [sqlite3_create_function()] and [sqlite3_create_function16()]
3531 ** define callbacks that implement the SQL functions and aggregates.
3532 ** The 4th parameter to these callbacks is an array of pointers to
3533 ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for
3534 ** each parameter to the SQL function. These routines are used to
3535 ** extract values from the [sqlite3_value] objects.
3536 **
3537 ** These routines work only with [protected sqlite3_value] objects.
@@ -5692,15 +5702,17 @@
5692 ** SQLite will typically create one cache instance for each open database file,
5693 ** though this is not guaranteed. ^The
5694 ** first parameter, szPage, is the size in bytes of the pages that must
5695 ** be allocated by the cache. ^szPage will not be a power of two. ^szPage
5696 ** will the page size of the database file that is to be cached plus an
5697 ** increment (here called "R") of about 100 or 200. SQLite will use the
5698 ** extra R bytes on each page to store metadata about the underlying
5699 ** database page on disk. The value of R depends
5700 ** on the SQLite version, the target platform, and how SQLite was compiled.
5701 ** ^R is constant for a particular build of SQLite. ^The second argument to
 
 
5702 ** xCreate(), bPurgeable, is true if the cache being created will
5703 ** be used to cache database pages of a file stored on disk, or
5704 ** false if it is used for an in-memory database. The cache implementation
5705 ** does not have to do anything special based with the value of bPurgeable;
5706 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
@@ -5728,11 +5740,11 @@
5728 ** is considered to be "pinned".
5729 **
5730 ** If the requested page is already in the page cache, then the page cache
5731 ** implementation must return a pointer to the page buffer with its content
5732 ** intact. If the requested page is not already in the cache, then the
5733 ** behavior of the cache implementation should use the value of the createFlag
5734 ** parameter to help it determined what action to take:
5735 **
5736 ** <table border=1 width=85% align=center>
5737 ** <tr><th> createFlag <th> Behaviour when page is not already in cache
5738 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
5739
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.5"
111 #define SQLITE_VERSION_NUMBER 3007005
112 #define SQLITE_SOURCE_ID "2011-01-17 02:24:12 b93f6f3e679c7710f42580a8dd9ce43136376c1d"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -718,18 +718,25 @@
718 **
719 ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer
720 ** to the [sqlite3_file] object associated with a particular database
721 ** connection. See the [sqlite3_file_control()] documentation for
722 ** additional information.
723 **
724 ** The [SQLITE_FCNTL_SYNC] opcode is used internally. SQLite calls
725 ** the file-control method with this opcode immediately after the database
726 ** file is synced, or if the database is running in synchronous=off mode
727 ** immediately after it would have been synced otherwise. This makes it
728 ** easier to write special VFS modules that depend on the xSync call.
729 */
730 #define SQLITE_FCNTL_LOCKSTATE 1
731 #define SQLITE_GET_LOCKPROXYFILE 2
732 #define SQLITE_SET_LOCKPROXYFILE 3
733 #define SQLITE_LAST_ERRNO 4
734 #define SQLITE_FCNTL_SIZE_HINT 5
735 #define SQLITE_FCNTL_CHUNK_SIZE 6
736 #define SQLITE_FCNTL_FILE_POINTER 7
737 #define SQLITE_FCNTL_SYNC 8
738
739
740 /*
741 ** CAPI3REF: Mutex Handle
742 **
@@ -1864,10 +1871,12 @@
1871 ** guarantees that the buffer is always zero-terminated. ^The first
1872 ** parameter "n" is the total size of the buffer, including space for
1873 ** the zero terminator. So the longest string that can be completely
1874 ** written will be n-1 characters.
1875 **
1876 ** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf().
1877 **
1878 ** These routines all implement some additional formatting
1879 ** options that are useful for constructing SQL statements.
1880 ** All of the usual printf() formatting options apply. In addition, there
1881 ** is are "%q", "%Q", and "%z" options.
1882 **
@@ -1927,10 +1936,11 @@
1936 ** the result, [sqlite3_free()] is called on the input string.)^
1937 */
1938 SQLITE_API char *sqlite3_mprintf(const char*,...);
1939 SQLITE_API char *sqlite3_vmprintf(const char*, va_list);
1940 SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...);
1941 SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list);
1942
1943 /*
1944 ** CAPI3REF: Memory Allocation Subsystem
1945 **
1946 ** The SQLite core uses these three routines for all of its own
@@ -2304,11 +2314,11 @@
2314 ** <dd>The database is opened for reading and writing if possible, or reading
2315 ** only if the file is write protected by the operating system. In either
2316 ** case the database must already exist, otherwise an error is returned.</dd>)^
2317 **
2318 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
2319 ** <dd>The database is opened for reading and writing, and is created if
2320 ** it does not already exist. This is the behavior that is always used for
2321 ** sqlite3_open() and sqlite3_open16().</dd>)^
2322 ** </dl>
2323 **
2324 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
@@ -3414,20 +3424,20 @@
3424 ** encoding is used, then the fourth argument should be [SQLITE_ANY].
3425 **
3426 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
3427 ** function can gain access to this pointer using [sqlite3_user_data()].)^
3428 **
3429 ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are
3430 ** pointers to C-language functions that implement the SQL function or
3431 ** aggregate. ^A scalar SQL function requires an implementation of the xFunc
3432 ** callback only; NULL pointers must be passed as the xStep and xFinal
3433 ** parameters. ^An aggregate SQL function requires an implementation of xStep
3434 ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing
3435 ** SQL function or aggregate, pass NULL poiners for all three function
3436 ** callbacks.
3437 **
3438 ** ^(If the ninth parameter to sqlite3_create_function_v2() is not NULL,
3439 ** then it is destructor for the application data pointer.
3440 ** The destructor is invoked when the function is deleted, either by being
3441 ** overloaded or when the database connection closes.)^
3442 ** ^The destructor is also invoked if the call to
3443 ** sqlite3_create_function_v2() fails.
@@ -3527,11 +3537,11 @@
3537 ** the function or aggregate.
3538 **
3539 ** The xFunc (for scalar functions) or xStep (for aggregates) parameters
3540 ** to [sqlite3_create_function()] and [sqlite3_create_function16()]
3541 ** define callbacks that implement the SQL functions and aggregates.
3542 ** The 3rd parameter to these callbacks is an array of pointers to
3543 ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for
3544 ** each parameter to the SQL function. These routines are used to
3545 ** extract values from the [sqlite3_value] objects.
3546 **
3547 ** These routines work only with [protected sqlite3_value] objects.
@@ -5692,15 +5702,17 @@
5702 ** SQLite will typically create one cache instance for each open database file,
5703 ** though this is not guaranteed. ^The
5704 ** first parameter, szPage, is the size in bytes of the pages that must
5705 ** be allocated by the cache. ^szPage will not be a power of two. ^szPage
5706 ** will the page size of the database file that is to be cached plus an
5707 ** increment (here called "R") of less than 250. SQLite will use the
5708 ** extra R bytes on each page to store metadata about the underlying
5709 ** database page on disk. The value of R depends
5710 ** on the SQLite version, the target platform, and how SQLite was compiled.
5711 ** ^(R is constant for a particular build of SQLite. Except, there are two
5712 ** distinct values of R when SQLite is compiled with the proprietary
5713 ** ZIPVFS extension.)^ ^The second argument to
5714 ** xCreate(), bPurgeable, is true if the cache being created will
5715 ** be used to cache database pages of a file stored on disk, or
5716 ** false if it is used for an in-memory database. The cache implementation
5717 ** does not have to do anything special based with the value of bPurgeable;
5718 ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will
@@ -5728,11 +5740,11 @@
5740 ** is considered to be "pinned".
5741 **
5742 ** If the requested page is already in the page cache, then the page cache
5743 ** implementation must return a pointer to the page buffer with its content
5744 ** intact. If the requested page is not already in the cache, then the
5745 ** cache implementation should use the value of the createFlag
5746 ** parameter to help it determined what action to take:
5747 **
5748 ** <table border=1 width=85% align=center>
5749 ** <tr><th> createFlag <th> Behaviour when page is not already in cache
5750 ** <tr><td> 0 <td> Do not allocate a new page. Return NULL.
5751

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button