Fossil SCM
Update to the latest prerelease version fo SQLite 3.7.5.
Commit
464775a520c71127b353ae721a9eea7fab219722
Parent
35aed076214bb05…
2 files changed
+231
-160
+22
-10
+231
-160
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | /****************************************************************************** |
| 2 | 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 | |
| 3 | +** version 3.7.5. By combining all the individual C code files into this | |
| 4 | 4 | ** single large file, the entire code can be compiled as a one translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| @@ -648,13 +648,13 @@ | ||
| 648 | 648 | ** |
| 649 | 649 | ** See also: [sqlite3_libversion()], |
| 650 | 650 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 651 | 651 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 652 | 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" | |
| 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 | 656 | |
| 657 | 657 | /* |
| 658 | 658 | ** CAPI3REF: Run-Time Library Version Numbers |
| 659 | 659 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 660 | 660 | ** |
| @@ -1261,18 +1261,25 @@ | ||
| 1261 | 1261 | ** |
| 1262 | 1262 | ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer |
| 1263 | 1263 | ** to the [sqlite3_file] object associated with a particular database |
| 1264 | 1264 | ** connection. See the [sqlite3_file_control()] documentation for |
| 1265 | 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. | |
| 1266 | 1272 | */ |
| 1267 | 1273 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 1268 | 1274 | #define SQLITE_GET_LOCKPROXYFILE 2 |
| 1269 | 1275 | #define SQLITE_SET_LOCKPROXYFILE 3 |
| 1270 | 1276 | #define SQLITE_LAST_ERRNO 4 |
| 1271 | 1277 | #define SQLITE_FCNTL_SIZE_HINT 5 |
| 1272 | 1278 | #define SQLITE_FCNTL_CHUNK_SIZE 6 |
| 1273 | 1279 | #define SQLITE_FCNTL_FILE_POINTER 7 |
| 1280 | +#define SQLITE_FCNTL_SYNC 8 | |
| 1274 | 1281 | |
| 1275 | 1282 | |
| 1276 | 1283 | /* |
| 1277 | 1284 | ** CAPI3REF: Mutex Handle |
| 1278 | 1285 | ** |
| @@ -2407,10 +2414,12 @@ | ||
| 2407 | 2414 | ** guarantees that the buffer is always zero-terminated. ^The first |
| 2408 | 2415 | ** parameter "n" is the total size of the buffer, including space for |
| 2409 | 2416 | ** the zero terminator. So the longest string that can be completely |
| 2410 | 2417 | ** written will be n-1 characters. |
| 2411 | 2418 | ** |
| 2419 | +** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf(). | |
| 2420 | +** | |
| 2412 | 2421 | ** These routines all implement some additional formatting |
| 2413 | 2422 | ** options that are useful for constructing SQL statements. |
| 2414 | 2423 | ** All of the usual printf() formatting options apply. In addition, there |
| 2415 | 2424 | ** is are "%q", "%Q", and "%z" options. |
| 2416 | 2425 | ** |
| @@ -2470,10 +2479,11 @@ | ||
| 2470 | 2479 | ** the result, [sqlite3_free()] is called on the input string.)^ |
| 2471 | 2480 | */ |
| 2472 | 2481 | SQLITE_API char *sqlite3_mprintf(const char*,...); |
| 2473 | 2482 | SQLITE_API char *sqlite3_vmprintf(const char*, va_list); |
| 2474 | 2483 | SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...); |
| 2484 | +SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list); | |
| 2475 | 2485 | |
| 2476 | 2486 | /* |
| 2477 | 2487 | ** CAPI3REF: Memory Allocation Subsystem |
| 2478 | 2488 | ** |
| 2479 | 2489 | ** The SQLite core uses these three routines for all of its own |
| @@ -2847,11 +2857,11 @@ | ||
| 2847 | 2857 | ** <dd>The database is opened for reading and writing if possible, or reading |
| 2848 | 2858 | ** only if the file is write protected by the operating system. In either |
| 2849 | 2859 | ** case the database must already exist, otherwise an error is returned.</dd>)^ |
| 2850 | 2860 | ** |
| 2851 | 2861 | ** ^(<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 | |
| 2853 | 2863 | ** it does not already exist. This is the behavior that is always used for |
| 2854 | 2864 | ** sqlite3_open() and sqlite3_open16().</dd>)^ |
| 2855 | 2865 | ** </dl> |
| 2856 | 2866 | ** |
| 2857 | 2867 | ** If the 3rd parameter to sqlite3_open_v2() is not one of the |
| @@ -3957,20 +3967,20 @@ | ||
| 3957 | 3967 | ** encoding is used, then the fourth argument should be [SQLITE_ANY]. |
| 3958 | 3968 | ** |
| 3959 | 3969 | ** ^(The fifth parameter is an arbitrary pointer. The implementation of the |
| 3960 | 3970 | ** function can gain access to this pointer using [sqlite3_user_data()].)^ |
| 3961 | 3971 | ** |
| 3962 | -** ^The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are | |
| 3972 | +** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are | |
| 3963 | 3973 | ** pointers to C-language functions that implement the SQL function or |
| 3964 | 3974 | ** aggregate. ^A scalar SQL function requires an implementation of the xFunc |
| 3965 | 3975 | ** callback only; NULL pointers must be passed as the xStep and xFinal |
| 3966 | 3976 | ** parameters. ^An aggregate SQL function requires an implementation of xStep |
| 3967 | 3977 | ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing |
| 3968 | 3978 | ** SQL function or aggregate, pass NULL poiners for all three function |
| 3969 | 3979 | ** callbacks. |
| 3970 | 3980 | ** |
| 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, | |
| 3972 | 3982 | ** then it is destructor for the application data pointer. |
| 3973 | 3983 | ** The destructor is invoked when the function is deleted, either by being |
| 3974 | 3984 | ** overloaded or when the database connection closes.)^ |
| 3975 | 3985 | ** ^The destructor is also invoked if the call to |
| 3976 | 3986 | ** sqlite3_create_function_v2() fails. |
| @@ -4070,11 +4080,11 @@ | ||
| 4070 | 4080 | ** the function or aggregate. |
| 4071 | 4081 | ** |
| 4072 | 4082 | ** The xFunc (for scalar functions) or xStep (for aggregates) parameters |
| 4073 | 4083 | ** to [sqlite3_create_function()] and [sqlite3_create_function16()] |
| 4074 | 4084 | ** 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 | |
| 4076 | 4086 | ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for |
| 4077 | 4087 | ** each parameter to the SQL function. These routines are used to |
| 4078 | 4088 | ** extract values from the [sqlite3_value] objects. |
| 4079 | 4089 | ** |
| 4080 | 4090 | ** These routines work only with [protected sqlite3_value] objects. |
| @@ -6235,15 +6245,17 @@ | ||
| 6235 | 6245 | ** SQLite will typically create one cache instance for each open database file, |
| 6236 | 6246 | ** though this is not guaranteed. ^The |
| 6237 | 6247 | ** first parameter, szPage, is the size in bytes of the pages that must |
| 6238 | 6248 | ** be allocated by the cache. ^szPage will not be a power of two. ^szPage |
| 6239 | 6249 | ** 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 | |
| 6241 | 6251 | ** extra R bytes on each page to store metadata about the underlying |
| 6242 | 6252 | ** database page on disk. The value of R depends |
| 6243 | 6253 | ** 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 | |
| 6245 | 6257 | ** xCreate(), bPurgeable, is true if the cache being created will |
| 6246 | 6258 | ** be used to cache database pages of a file stored on disk, or |
| 6247 | 6259 | ** false if it is used for an in-memory database. The cache implementation |
| 6248 | 6260 | ** does not have to do anything special based with the value of bPurgeable; |
| 6249 | 6261 | ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will |
| @@ -6271,11 +6283,11 @@ | ||
| 6271 | 6283 | ** is considered to be "pinned". |
| 6272 | 6284 | ** |
| 6273 | 6285 | ** If the requested page is already in the page cache, then the page cache |
| 6274 | 6286 | ** implementation must return a pointer to the page buffer with its content |
| 6275 | 6287 | ** 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 | |
| 6277 | 6289 | ** parameter to help it determined what action to take: |
| 6278 | 6290 | ** |
| 6279 | 6291 | ** <table border=1 width=85% align=center> |
| 6280 | 6292 | ** <tr><th> createFlag <th> Behaviour when page is not already in cache |
| 6281 | 6293 | ** <tr><td> 0 <td> Do not allocate a new page. Return NULL. |
| @@ -12051,37 +12063,32 @@ | ||
| 12051 | 12063 | ** entries or retrieve the key or data from the entry that the cursor |
| 12052 | 12064 | ** is currently pointing to. |
| 12053 | 12065 | ** |
| 12054 | 12066 | ** Every cursor that the virtual machine has open is represented by an |
| 12055 | 12067 | ** 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 | 12068 | */ |
| 12062 | 12069 | struct VdbeCursor { |
| 12063 | 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 */ | |
| 12064 | 12073 | 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 */ | |
| 12066 | 12076 | Bool zeroed; /* True if zeroed out and ready for reuse */ |
| 12067 | 12077 | Bool rowidIsValid; /* True if lastRowid is valid */ |
| 12068 | 12078 | Bool atFirst; /* True if pointing to first entry */ |
| 12069 | 12079 | Bool useRandomRowid; /* Generate new record numbers semi-randomly */ |
| 12070 | 12080 | Bool nullRow; /* True if pointing to a row with no data */ |
| 12071 | 12081 | Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */ |
| 12072 | 12082 | Bool isTable; /* True if a table requiring integer keys */ |
| 12073 | 12083 | Bool isIndex; /* True if an index containing keys only - no data */ |
| 12074 | 12084 | 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 | 12085 | sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */ |
| 12082 | 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 */ | |
| 12083 | 12090 | |
| 12084 | 12091 | /* Result of last sqlite3BtreeMoveto() done by an OP_NotExists or |
| 12085 | 12092 | ** OP_IsUnique opcode on this cursor. */ |
| 12086 | 12093 | int seekResult; |
| 12087 | 12094 | |
| @@ -12149,29 +12156,23 @@ | ||
| 12149 | 12156 | #define CACHE_STALE 0 |
| 12150 | 12157 | |
| 12151 | 12158 | /* |
| 12152 | 12159 | ** Internally, the vdbe manipulates nearly all SQL values as Mem |
| 12153 | 12160 | ** 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. | |
| 12161 | 12162 | */ |
| 12162 | 12163 | struct Mem { |
| 12164 | + sqlite3 *db; /* The associated database connection */ | |
| 12165 | + char *z; /* String or BLOB value */ | |
| 12166 | + double r; /* Real value */ | |
| 12163 | 12167 | union { |
| 12164 | - i64 i; /* Integer value. */ | |
| 12168 | + i64 i; /* Integer value used when MEM_Int is set in flags */ | |
| 12165 | 12169 | int nZero; /* Used when bit MEM_Zero is set in flags */ |
| 12166 | 12170 | FuncDef *pDef; /* Used only when flags==MEM_Agg */ |
| 12167 | 12171 | RowSet *pRowSet; /* Used only when flags==MEM_RowSet */ |
| 12168 | 12172 | VdbeFrame *pFrame; /* Used when flags==MEM_Frame */ |
| 12169 | 12173 | } u; |
| 12170 | - double r; /* Real value */ | |
| 12171 | - sqlite3 *db; /* The associated database connection */ | |
| 12172 | - char *z; /* String or BLOB value */ | |
| 12173 | 12174 | int n; /* Number of characters in string value, excluding '\0' */ |
| 12174 | 12175 | u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */ |
| 12175 | 12176 | u8 type; /* One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc */ |
| 12176 | 12177 | u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */ |
| 12177 | 12178 | #ifdef SQLITE_DEBUG |
| @@ -12191,13 +12192,10 @@ | ||
| 12191 | 12192 | ** If the MEM_Str flag is set then Mem.z points at a string representation. |
| 12192 | 12193 | ** Usually this is encoded in the same unicode encoding as the main |
| 12193 | 12194 | ** database (see below for exceptions). If the MEM_Term flag is also |
| 12194 | 12195 | ** set, then the string is nul terminated. The MEM_Int and MEM_Real |
| 12195 | 12196 | ** 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 | 12197 | */ |
| 12200 | 12198 | #define MEM_Null 0x0001 /* Value is NULL */ |
| 12201 | 12199 | #define MEM_Str 0x0002 /* Value is a string */ |
| 12202 | 12200 | #define MEM_Int 0x0004 /* Value is an integer */ |
| 12203 | 12201 | #define MEM_Real 0x0008 /* Value is a real number */ |
| @@ -12276,27 +12274,15 @@ | ||
| 12276 | 12274 | Mem *pMem; /* Memory cell used to store aggregate context */ |
| 12277 | 12275 | int isError; /* Error code returned by the function. */ |
| 12278 | 12276 | CollSeq *pColl; /* Collating sequence */ |
| 12279 | 12277 | }; |
| 12280 | 12278 | |
| 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 | 12279 | /* |
| 12294 | 12280 | ** An instance of the virtual machine. This structure contains the complete |
| 12295 | 12281 | ** state of the virtual machine. |
| 12296 | 12282 | ** |
| 12297 | -** The "sqlite3_stmt" structure pointer that is returned by sqlite3_compile() | |
| 12283 | +** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare() | |
| 12298 | 12284 | ** is really a pointer to an instance of this structure. |
| 12299 | 12285 | ** |
| 12300 | 12286 | ** The Vdbe.inVtabMethod variable is set to non-zero for the duration of |
| 12301 | 12287 | ** any virtual table method invocations made by the vdbe program. It is |
| 12302 | 12288 | ** set to 2 for xDestroy method calls and 1 for all other methods. This |
| @@ -12305,35 +12291,35 @@ | ||
| 12305 | 12291 | ** malloc failure when SQLite is invoked recursively by a virtual table |
| 12306 | 12292 | ** method function. |
| 12307 | 12293 | */ |
| 12308 | 12294 | struct Vdbe { |
| 12309 | 12295 | 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 | 12296 | 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 */ | |
| 12317 | 12298 | Mem **apArg; /* Arguments to currently executing user function */ |
| 12318 | 12299 | Mem *aColName; /* Column names to return */ |
| 12319 | 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 */ | |
| 12320 | 12307 | u16 nResColumn; /* Number of columns in one row of the result set */ |
| 12321 | 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 */ | |
| 12322 | 12312 | 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 | 12313 | Mem *aVar; /* Values for the OP_Variable opcode. */ |
| 12327 | 12314 | 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[] */ | |
| 12331 | 12316 | u32 cacheCtr; /* VdbeCursor row cache generation counter */ |
| 12332 | 12317 | int pc; /* The program counter */ |
| 12333 | 12318 | 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 */ | |
| 12335 | 12321 | u8 explain; /* True if EXPLAIN present on SQL command */ |
| 12336 | 12322 | u8 changeCntOn; /* True to update the change-counter */ |
| 12337 | 12323 | u8 expired; /* True if the VM needs to be recompiled */ |
| 12338 | 12324 | u8 runOnlyOnce; /* Automatically expire on reset */ |
| 12339 | 12325 | u8 minWriteFileFormat; /* Minimum file format for writable database files */ |
| @@ -12341,18 +12327,20 @@ | ||
| 12341 | 12327 | u8 usesStmtJournal; /* True if uses a statement journal */ |
| 12342 | 12328 | u8 readOnly; /* True for read-only statements */ |
| 12343 | 12329 | u8 isPrepareV2; /* True if prepared with prepare_v2() */ |
| 12344 | 12330 | int nChange; /* Number of db changes made since last reset */ |
| 12345 | 12331 | 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() */ | |
| 12347 | 12334 | 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 | |
| 12351 | 12338 | i64 nFkConstraint; /* Number of imm. FK constraints this VM */ |
| 12352 | 12339 | 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 */ | |
| 12354 | 12342 | #ifdef SQLITE_DEBUG |
| 12355 | 12343 | FILE *trace; /* Write an execution trace here, if not NULL */ |
| 12356 | 12344 | #endif |
| 12357 | 12345 | VdbeFrame *pFrame; /* Parent frame */ |
| 12358 | 12346 | VdbeFrame *pDelFrame; /* List of frame objects to free on VM reset */ |
| @@ -19231,25 +19219,32 @@ | ||
| 19231 | 19219 | /* |
| 19232 | 19220 | ** sqlite3_snprintf() works like snprintf() except that it ignores the |
| 19233 | 19221 | ** current locale settings. This is important for SQLite because we |
| 19234 | 19222 | ** are not able to use a "," as the decimal point in place of "." as |
| 19235 | 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. | |
| 19236 | 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 | +} | |
| 19237 | 19240 | SQLITE_API char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){ |
| 19238 | 19241 | char *z; |
| 19239 | 19242 | 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 | 19243 | va_start(ap,zFormat); |
| 19248 | - sqlite3VXPrintf(&acc, 0, zFormat, ap); | |
| 19244 | + z = sqlite3_vsnprintf(n, zBuf, zFormat, ap); | |
| 19249 | 19245 | va_end(ap); |
| 19250 | - z = sqlite3StrAccumFinish(&acc); | |
| 19251 | 19246 | return z; |
| 19252 | 19247 | } |
| 19253 | 19248 | |
| 19254 | 19249 | /* |
| 19255 | 19250 | ** This is the routine that actually formats the sqlite3_log() message. |
| @@ -22976,11 +22971,13 @@ | ||
| 22976 | 22971 | #include <sys/stat.h> |
| 22977 | 22972 | #include <fcntl.h> |
| 22978 | 22973 | #include <unistd.h> |
| 22979 | 22974 | #include <sys/time.h> |
| 22980 | 22975 | #include <errno.h> |
| 22976 | +#ifndef SQLITE_OMIT_WAL | |
| 22981 | 22977 | #include <sys/mman.h> |
| 22978 | +#endif | |
| 22982 | 22979 | |
| 22983 | 22980 | #if SQLITE_ENABLE_LOCKING_STYLE |
| 22984 | 22981 | # include <sys/ioctl.h> |
| 22985 | 22982 | # if OS_VXWORKS |
| 22986 | 22983 | # include <semaphore.h> |
| @@ -34069,15 +34066,11 @@ | ||
| 34069 | 34066 | |
| 34070 | 34067 | if( reuseUnlikely || pcache1.nCurrentPage>pcache1.nMaxPage ){ |
| 34071 | 34068 | pcache1RemoveFromHash(pPage); |
| 34072 | 34069 | pcache1FreePage(pPage); |
| 34073 | 34070 | }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. */ | |
| 34079 | 34072 | if( pcache1.pLruHead ){ |
| 34080 | 34073 | pcache1.pLruHead->pLruPrev = pPage; |
| 34081 | 34074 | pPage->pLruNext = pcache1.pLruHead; |
| 34082 | 34075 | pcache1.pLruHead = pPage; |
| 34083 | 34076 | }else{ |
| @@ -37523,14 +37516,14 @@ | ||
| 37523 | 37516 | if( rc==SQLITE_OK ){ |
| 37524 | 37517 | zMaster = pPager->pTmpSpace; |
| 37525 | 37518 | rc = readMasterJournal(pPager->jfd, zMaster, pPager->pVfs->mxPathname+1); |
| 37526 | 37519 | testcase( rc!=SQLITE_OK ); |
| 37527 | 37520 | } |
| 37528 | - if( rc==SQLITE_OK && !pPager->noSync | |
| 37521 | + if( rc==SQLITE_OK | |
| 37529 | 37522 | && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN) |
| 37530 | 37523 | ){ |
| 37531 | - rc = sqlite3OsSync(pPager->fd, pPager->syncFlags); | |
| 37524 | + rc = sqlite3PagerSync(pPager); | |
| 37532 | 37525 | } |
| 37533 | 37526 | if( rc==SQLITE_OK ){ |
| 37534 | 37527 | rc = pager_end_transaction(pPager, zMaster[0]!='\0'); |
| 37535 | 37528 | testcase( rc!=SQLITE_OK ); |
| 37536 | 37529 | } |
| @@ -37689,26 +37682,63 @@ | ||
| 37689 | 37682 | } |
| 37690 | 37683 | |
| 37691 | 37684 | return rc; |
| 37692 | 37685 | } |
| 37693 | 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 | + | |
| 37694 | 37710 | /* |
| 37695 | 37711 | ** This function is a wrapper around sqlite3WalFrames(). As well as logging |
| 37696 | 37712 | ** the contents of the list of pages headed by pList (connected by pDirty), |
| 37697 | 37713 | ** 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. | |
| 37699 | 37718 | */ |
| 37700 | 37719 | static int pagerWalFrames( |
| 37701 | 37720 | Pager *pPager, /* Pager object */ |
| 37702 | 37721 | PgHdr *pList, /* List of frames to log */ |
| 37703 | 37722 | Pgno nTruncate, /* Database size after this commit */ |
| 37704 | 37723 | int isCommit, /* True if this is a commit */ |
| 37705 | 37724 | int syncFlags /* Flags to pass to OsSync() (or 0) */ |
| 37706 | 37725 | ){ |
| 37707 | 37726 | int rc; /* Return code */ |
| 37727 | +#if defined(SQLITE_DEBUG) || defined(SQLITE_CHECK_PAGES) | |
| 37728 | + PgHdr *p; /* For looping over pages */ | |
| 37729 | +#endif | |
| 37708 | 37730 | |
| 37709 | 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); | |
| 37710 | 37740 | rc = sqlite3WalFrames(pPager->pWal, |
| 37711 | 37741 | pPager->pageSize, pList, nTruncate, isCommit, syncFlags |
| 37712 | 37742 | ); |
| 37713 | 37743 | if( rc==SQLITE_OK && pPager->pBackup ){ |
| 37714 | 37744 | PgHdr *p; |
| @@ -37716,13 +37746,12 @@ | ||
| 37716 | 37746 | sqlite3BackupUpdate(pPager->pBackup, p->pgno, (u8 *)p->pData); |
| 37717 | 37747 | } |
| 37718 | 37748 | } |
| 37719 | 37749 | |
| 37720 | 37750 | #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); | |
| 37724 | 37753 | } |
| 37725 | 37754 | #endif |
| 37726 | 37755 | |
| 37727 | 37756 | return rc; |
| 37728 | 37757 | } |
| @@ -38743,10 +38772,11 @@ | ||
| 38743 | 38772 | if( pgno<=pPager->dbSize && 0==(pList->flags&PGHDR_DONT_WRITE) ){ |
| 38744 | 38773 | i64 offset = (pgno-1)*(i64)pPager->pageSize; /* Offset to write */ |
| 38745 | 38774 | char *pData; /* Data to write */ |
| 38746 | 38775 | |
| 38747 | 38776 | assert( (pList->flags&PGHDR_NEED_SYNC)==0 ); |
| 38777 | + if( pList->pgno==1 ) pager_write_changecounter(pList); | |
| 38748 | 38778 | |
| 38749 | 38779 | /* Encode the database */ |
| 38750 | 38780 | CODEC2(pPager, pList->pData, pgno, 6, return SQLITE_NOMEM, pData); |
| 38751 | 38781 | |
| 38752 | 38782 | /* Write out the page data. */ |
| @@ -40263,11 +40293,17 @@ | ||
| 40263 | 40293 | } |
| 40264 | 40294 | |
| 40265 | 40295 | /* |
| 40266 | 40296 | ** This routine is called to increment the value of the database file |
| 40267 | 40297 | ** 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. | |
| 40269 | 40305 | ** |
| 40270 | 40306 | ** If the isDirectMode flag is zero, then this is done by calling |
| 40271 | 40307 | ** sqlite3PagerWrite() on page 1, then modifying the contents of the |
| 40272 | 40308 | ** page data. In this case the file will be updated when the current |
| 40273 | 40309 | ** transaction is committed. |
| @@ -40304,11 +40340,10 @@ | ||
| 40304 | 40340 | # define DIRECT_MODE isDirectMode |
| 40305 | 40341 | #endif |
| 40306 | 40342 | |
| 40307 | 40343 | if( !pPager->changeCountDone && pPager->dbSize>0 ){ |
| 40308 | 40344 | PgHdr *pPgHdr; /* Reference to page 1 */ |
| 40309 | - u32 change_counter; /* Initial value of change-counter field */ | |
| 40310 | 40345 | |
| 40311 | 40346 | assert( !pPager->tempFile && isOpen(pPager->fd) ); |
| 40312 | 40347 | |
| 40313 | 40348 | /* Open page 1 of the file for writing. */ |
| 40314 | 40349 | rc = sqlite3PagerGet(pPager, 1, &pPgHdr); |
| @@ -40322,20 +40357,12 @@ | ||
| 40322 | 40357 | if( !DIRECT_MODE && ALWAYS(rc==SQLITE_OK) ){ |
| 40323 | 40358 | rc = sqlite3PagerWrite(pPgHdr); |
| 40324 | 40359 | } |
| 40325 | 40360 | |
| 40326 | 40361 | 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); | |
| 40337 | 40364 | |
| 40338 | 40365 | /* If running in direct mode, write the contents of page 1 to the file. */ |
| 40339 | 40366 | if( DIRECT_MODE ){ |
| 40340 | 40367 | const void *zBuf; |
| 40341 | 40368 | assert( pPager->dbFileSize>0 ); |
| @@ -40370,10 +40397,13 @@ | ||
| 40370 | 40397 | if( pPager->noSync ){ |
| 40371 | 40398 | rc = SQLITE_OK; |
| 40372 | 40399 | }else{ |
| 40373 | 40400 | rc = sqlite3OsSync(pPager->fd, pPager->syncFlags); |
| 40374 | 40401 | } |
| 40402 | + if( isOpen(pPager->fd) ){ | |
| 40403 | + sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC, (void *)&rc); | |
| 40404 | + } | |
| 40375 | 40405 | return rc; |
| 40376 | 40406 | } |
| 40377 | 40407 | |
| 40378 | 40408 | /* |
| 40379 | 40409 | ** This function may only be called while a write-transaction is active in |
| @@ -40587,12 +40617,12 @@ | ||
| 40587 | 40617 | rc = pager_truncate(pPager, nNew); |
| 40588 | 40618 | if( rc!=SQLITE_OK ) goto commit_phase_one_exit; |
| 40589 | 40619 | } |
| 40590 | 40620 | |
| 40591 | 40621 | /* Finally, sync the database file. */ |
| 40592 | - if( !pPager->noSync && !noSync ){ | |
| 40593 | - rc = sqlite3OsSync(pPager->fd, pPager->syncFlags); | |
| 40622 | + if( !noSync ){ | |
| 40623 | + rc = sqlite3PagerSync(pPager); | |
| 40594 | 40624 | } |
| 40595 | 40625 | IOTRACE(("DBSYNC %p\n", pPager)) |
| 40596 | 40626 | } |
| 40597 | 40627 | } |
| 40598 | 40628 | |
| @@ -40700,11 +40730,21 @@ | ||
| 40700 | 40730 | int rc2; |
| 40701 | 40731 | rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_ROLLBACK, -1); |
| 40702 | 40732 | rc2 = pager_end_transaction(pPager, pPager->setMaster); |
| 40703 | 40733 | if( rc==SQLITE_OK ) rc = rc2; |
| 40704 | 40734 | }else if( !isOpen(pPager->jfd) || pPager->eState==PAGER_WRITER_LOCKED ){ |
| 40735 | + int eState = pPager->eState; | |
| 40705 | 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 | + } | |
| 40706 | 40746 | }else{ |
| 40707 | 40747 | rc = pager_playback(pPager, 0); |
| 40708 | 40748 | } |
| 40709 | 40749 | |
| 40710 | 40750 | assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK ); |
| @@ -44732,16 +44772,16 @@ | ||
| 44732 | 44772 | u8 openFlags; /* Flags to sqlite3BtreeOpen() */ |
| 44733 | 44773 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 44734 | 44774 | u8 autoVacuum; /* True if auto-vacuum is enabled */ |
| 44735 | 44775 | u8 incrVacuum; /* True if incr-vacuum is enabled */ |
| 44736 | 44776 | #endif |
| 44777 | + u8 inTransaction; /* Transaction state */ | |
| 44778 | + u8 doNotUseWAL; /* If true, do not open write-ahead-log file */ | |
| 44737 | 44779 | u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */ |
| 44738 | 44780 | u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */ |
| 44739 | 44781 | u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */ |
| 44740 | 44782 | 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 | 44783 | u32 pageSize; /* Total number of bytes on a page */ |
| 44744 | 44784 | u32 usableSize; /* Number of usable bytes on each page */ |
| 44745 | 44785 | int nTransaction; /* Number of open transactions (read + write) */ |
| 44746 | 44786 | u32 nPage; /* Number of pages in the database */ |
| 44747 | 44787 | void *pSchema; /* Pointer to space allocated by sqlite3BtreeSchema() */ |
| @@ -44764,12 +44804,12 @@ | ||
| 44764 | 44804 | ** about a cell. The parseCellPtr() function fills in this structure |
| 44765 | 44805 | ** based on information extract from the raw disk page. |
| 44766 | 44806 | */ |
| 44767 | 44807 | typedef struct CellInfo CellInfo; |
| 44768 | 44808 | struct CellInfo { |
| 44769 | - u8 *pCell; /* Pointer to the start of cell content */ | |
| 44770 | 44809 | i64 nKey; /* The key for INTKEY tables, or number of bytes in key */ |
| 44810 | + u8 *pCell; /* Pointer to the start of cell content */ | |
| 44771 | 44811 | u32 nData; /* Number of bytes of data */ |
| 44772 | 44812 | u32 nPayload; /* Total amount of payload */ |
| 44773 | 44813 | u16 nHeader; /* Size of the cell content header in bytes */ |
| 44774 | 44814 | u16 nLocal; /* Amount of payload held locally */ |
| 44775 | 44815 | u16 iOverflow; /* Offset to overflow page number. Zero if no overflow */ |
| @@ -44807,24 +44847,24 @@ | ||
| 44807 | 44847 | BtCursor *pNext, *pPrev; /* Forms a linked list of all cursors */ |
| 44808 | 44848 | struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */ |
| 44809 | 44849 | Pgno pgnoRoot; /* The root page of this tree */ |
| 44810 | 44850 | sqlite3_int64 cachedRowid; /* Next rowid cache. 0 means not valid */ |
| 44811 | 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 */ | |
| 44812 | 44855 | u8 wrFlag; /* True if writable */ |
| 44813 | 44856 | u8 atLast; /* Cursor pointing to the last entry */ |
| 44814 | 44857 | u8 validNKey; /* True if info.nKey is valid */ |
| 44815 | 44858 | 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 | 44859 | #ifndef SQLITE_OMIT_INCRBLOB |
| 44820 | - u8 isIncrblobHandle; /* True if this cursor is an incr. io handle */ | |
| 44821 | 44860 | Pgno *aOverflow; /* Cache of overflow page locations */ |
| 44861 | + u8 isIncrblobHandle; /* True if this cursor is an incr. io handle */ | |
| 44822 | 44862 | #endif |
| 44823 | 44863 | i16 iPage; /* Index of current page in apPage */ |
| 44824 | - MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */ | |
| 44825 | 44864 | u16 aiIdx[BTCURSOR_MAX_DEPTH]; /* Current index in apPage[i] */ |
| 44865 | + MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */ | |
| 44826 | 44866 | }; |
| 44827 | 44867 | |
| 44828 | 44868 | /* |
| 44829 | 44869 | ** Potential values for BtCursor.eState. |
| 44830 | 44870 | ** |
| @@ -47692,11 +47732,11 @@ | ||
| 47692 | 47732 | freeTempSpace(pBt); |
| 47693 | 47733 | rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, |
| 47694 | 47734 | pageSize-usableSize); |
| 47695 | 47735 | return rc; |
| 47696 | 47736 | } |
| 47697 | - if( nPageHeader>nPageFile ){ | |
| 47737 | + if( (pBt->db->flags & SQLITE_RecoveryMode)==0 && nPageHeader>nPageFile ){ | |
| 47698 | 47738 | rc = SQLITE_CORRUPT_BKPT; |
| 47699 | 47739 | goto page1_init_failed; |
| 47700 | 47740 | } |
| 47701 | 47741 | if( usableSize<480 ){ |
| 47702 | 47742 | goto page1_init_failed; |
| @@ -53563,10 +53603,20 @@ | ||
| 53563 | 53603 | return 0; |
| 53564 | 53604 | } |
| 53565 | 53605 | |
| 53566 | 53606 | return pDb->aDb[i].pBt; |
| 53567 | 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 | +} | |
| 53568 | 53618 | |
| 53569 | 53619 | /* |
| 53570 | 53620 | ** Create an sqlite3_backup process to copy the contents of zSrcDb from |
| 53571 | 53621 | ** connection handle pSrcDb to zDestDb in pDestDb. If successful, return |
| 53572 | 53622 | ** a pointer to the new sqlite3_backup object. |
| @@ -53617,14 +53667,15 @@ | ||
| 53617 | 53667 | p->pDestDb = pDestDb; |
| 53618 | 53668 | p->pSrcDb = pSrcDb; |
| 53619 | 53669 | p->iNext = 1; |
| 53620 | 53670 | p->isAttached = 0; |
| 53621 | 53671 | |
| 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. | |
| 53626 | 53677 | */ |
| 53627 | 53678 | sqlite3_free(p); |
| 53628 | 53679 | p = 0; |
| 53629 | 53680 | } |
| 53630 | 53681 | } |
| @@ -53877,35 +53928,37 @@ | ||
| 53877 | 53928 | ** pending-byte page in the source database may need to be |
| 53878 | 53929 | ** copied into the destination database. |
| 53879 | 53930 | */ |
| 53880 | 53931 | const i64 iSize = (i64)pgszSrc * (i64)nSrcPage; |
| 53881 | 53932 | sqlite3_file * const pFile = sqlite3PagerFile(pDestPager); |
| 53933 | + i64 iOff; | |
| 53934 | + i64 iEnd; | |
| 53882 | 53935 | |
| 53883 | 53936 | assert( pFile ); |
| 53884 | 53937 | assert( (i64)nDestTruncate*(i64)pgszDest >= iSize || ( |
| 53885 | 53938 | nDestTruncate==(int)(PENDING_BYTE_PAGE(p->pDest->pBt)-1) |
| 53886 | 53939 | && iSize>=PENDING_BYTE && iSize<=PENDING_BYTE+pgszDest |
| 53887 | 53940 | )); |
| 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); | |
| 53907 | 53960 | } |
| 53908 | 53961 | } |
| 53909 | 53962 | }else{ |
| 53910 | 53963 | rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0); |
| 53911 | 53964 | } |
| @@ -59102,11 +59155,11 @@ | ||
| 59102 | 59155 | ** __attribute__((aligned(8))) macro. */ |
| 59103 | 59156 | static const Mem nullMem |
| 59104 | 59157 | #if defined(SQLITE_DEBUG) && defined(__GNUC__) |
| 59105 | 59158 | __attribute__((aligned(8))) |
| 59106 | 59159 | #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 }; | |
| 59108 | 59161 | |
| 59109 | 59162 | if( pVm && ALWAYS(pVm->db) ){ |
| 59110 | 59163 | sqlite3_mutex_enter(pVm->db->mutex); |
| 59111 | 59164 | sqlite3Error(pVm->db, SQLITE_RANGE, 0); |
| 59112 | 59165 | } |
| @@ -73549,13 +73602,14 @@ | ||
| 73549 | 73602 | sqlite3VdbeAddOp2(v, OP_Rewind, iIdxCur, endOfLoop); |
| 73550 | 73603 | topOfLoop = sqlite3VdbeCurrentAddr(v); |
| 73551 | 73604 | sqlite3VdbeAddOp2(v, OP_AddImm, iMem, 1); |
| 73552 | 73605 | |
| 73553 | 73606 | for(i=0; i<nCol; i++){ |
| 73607 | + CollSeq *pColl; | |
| 73554 | 73608 | sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regCol); |
| 73555 | -#ifdef SQLITE_ENABLE_STAT2 | |
| 73556 | 73609 | if( i==0 ){ |
| 73610 | +#ifdef SQLITE_ENABLE_STAT2 | |
| 73557 | 73611 | /* Check if the record that cursor iIdxCur points to contains a |
| 73558 | 73612 | ** value that should be stored in the sqlite_stat2 table. If so, |
| 73559 | 73613 | ** store it. */ |
| 73560 | 73614 | int ne = sqlite3VdbeAddOp3(v, OP_Ne, regRecno, 0, regSamplerecno); |
| 73561 | 73615 | assert( regTabname+1==regIdxname |
| @@ -73580,16 +73634,21 @@ | ||
| 73580 | 73634 | sqlite3VdbeAddOp3(v, OP_Divide, regTemp2, regTemp, regTemp); |
| 73581 | 73635 | sqlite3VdbeAddOp3(v, OP_Add, regSamplerecno, regTemp, regSamplerecno); |
| 73582 | 73636 | |
| 73583 | 73637 | sqlite3VdbeJumpHere(v, ne); |
| 73584 | 73638 | sqlite3VdbeAddOp2(v, OP_AddImm, regRecno, 1); |
| 73585 | - } | |
| 73586 | 73639 | #endif |
| 73587 | 73640 | |
| 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); | |
| 73591 | 73650 | } |
| 73592 | 73651 | if( db->mallocFailed ){ |
| 73593 | 73652 | /* If a malloc failure has occurred, then the result of the expression |
| 73594 | 73653 | ** passed as the second argument to the call to sqlite3VdbeJumpHere() |
| 73595 | 73654 | ** below may be negative. Which causes an assert() to fail (or an |
| @@ -73596,11 +73655,15 @@ | ||
| 73596 | 73655 | ** out-of-bounds write if SQLITE_DEBUG is not defined). */ |
| 73597 | 73656 | return; |
| 73598 | 73657 | } |
| 73599 | 73658 | sqlite3VdbeAddOp2(v, OP_Goto, 0, endOfLoop); |
| 73600 | 73659 | 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 */ | |
| 73602 | 73665 | sqlite3VdbeAddOp2(v, OP_AddImm, iMem+i+1, 1); |
| 73603 | 73666 | sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, iMem+nCol+i+1); |
| 73604 | 73667 | } |
| 73605 | 73668 | |
| 73606 | 73669 | /* End of the analysis loop. */ |
| @@ -73942,12 +74005,15 @@ | ||
| 73942 | 74005 | sqlite3DbFree(db, zSql); |
| 73943 | 74006 | } |
| 73944 | 74007 | |
| 73945 | 74008 | if( rc==SQLITE_OK ){ |
| 73946 | 74009 | 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; | |
| 73949 | 74015 | if( pIdx ){ |
| 73950 | 74016 | int iSample = sqlite3_column_int(pStmt, 1); |
| 73951 | 74017 | if( iSample<SQLITE_INDEX_SAMPLES && iSample>=0 ){ |
| 73952 | 74018 | int eType = sqlite3_column_type(pStmt, 2); |
| 73953 | 74019 | |
| @@ -115616,28 +115682,32 @@ | ||
| 115616 | 115682 | ** the table. The following nCol varints contain the total amount of |
| 115617 | 115683 | ** data stored in all rows of each column of the table, from left |
| 115618 | 115684 | ** to right. |
| 115619 | 115685 | */ |
| 115620 | 115686 | 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); | |
| 115622 | 115691 | 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 ); | |
| 115637 | 115707 | rc = sqlite3_reset(pStmt); |
| 115638 | - if( rc!=SQLITE_OK || pCsr->nRowAvg==0 ) return rc; | |
| 115708 | + if( rc!=SQLITE_OK ) return rc; | |
| 115639 | 115709 | } |
| 115640 | 115710 | |
| 115641 | 115711 | /* Assume that a blob flows over onto overflow pages if it is larger |
| 115642 | 115712 | ** than (pgsz-35) bytes in size (the file-format documentation |
| 115643 | 115713 | ** confirms this). |
| @@ -116754,11 +116824,11 @@ | ||
| 116754 | 116824 | |
| 116755 | 116825 | if( !isIgnoreEmpty || nList>0 ){ |
| 116756 | 116826 | nByte = sqlite3Fts3VarintLen(iDocid-iPrev) + (isRequirePos?nList+1:0); |
| 116757 | 116827 | if( nDoclist+nByte>nAlloc ){ |
| 116758 | 116828 | char *aNew; |
| 116759 | - nAlloc = nDoclist+nByte*2; | |
| 116829 | + nAlloc = (nDoclist+nByte)*2; | |
| 116760 | 116830 | aNew = sqlite3_realloc(aBuffer, nAlloc); |
| 116761 | 116831 | if( !aNew ){ |
| 116762 | 116832 | rc = SQLITE_NOMEM; |
| 116763 | 116833 | goto finished; |
| 116764 | 116834 | } |
| @@ -118361,10 +118431,11 @@ | ||
| 118361 | 118431 | if( !*ppStmt ){ |
| 118362 | 118432 | int rc = sqlite3Fts3SelectDoctotal(pTab, ppStmt); |
| 118363 | 118433 | if( rc!=SQLITE_OK ) return rc; |
| 118364 | 118434 | } |
| 118365 | 118435 | pStmt = *ppStmt; |
| 118436 | + assert( sqlite3_data_count(pStmt)==1 ); | |
| 118366 | 118437 | |
| 118367 | 118438 | a = sqlite3_column_blob(pStmt, 0); |
| 118368 | 118439 | a += sqlite3Fts3GetVarint(a, &nDoc); |
| 118369 | 118440 | *pnDoc = (u32)nDoc; |
| 118370 | 118441 | |
| 118371 | 118442 |
| --- 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 @@ | ||
| 105 | 105 | ** |
| 106 | 106 | ** See also: [sqlite3_libversion()], |
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 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" | |
| 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 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| @@ -718,18 +718,25 @@ | ||
| 718 | 718 | ** |
| 719 | 719 | ** The [SQLITE_FCNTL_FILE_POINTER] opcode is used to obtain a pointer |
| 720 | 720 | ** to the [sqlite3_file] object associated with a particular database |
| 721 | 721 | ** connection. See the [sqlite3_file_control()] documentation for |
| 722 | 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. | |
| 723 | 729 | */ |
| 724 | 730 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 725 | 731 | #define SQLITE_GET_LOCKPROXYFILE 2 |
| 726 | 732 | #define SQLITE_SET_LOCKPROXYFILE 3 |
| 727 | 733 | #define SQLITE_LAST_ERRNO 4 |
| 728 | 734 | #define SQLITE_FCNTL_SIZE_HINT 5 |
| 729 | 735 | #define SQLITE_FCNTL_CHUNK_SIZE 6 |
| 730 | 736 | #define SQLITE_FCNTL_FILE_POINTER 7 |
| 737 | +#define SQLITE_FCNTL_SYNC 8 | |
| 731 | 738 | |
| 732 | 739 | |
| 733 | 740 | /* |
| 734 | 741 | ** CAPI3REF: Mutex Handle |
| 735 | 742 | ** |
| @@ -1864,10 +1871,12 @@ | ||
| 1864 | 1871 | ** guarantees that the buffer is always zero-terminated. ^The first |
| 1865 | 1872 | ** parameter "n" is the total size of the buffer, including space for |
| 1866 | 1873 | ** the zero terminator. So the longest string that can be completely |
| 1867 | 1874 | ** written will be n-1 characters. |
| 1868 | 1875 | ** |
| 1876 | +** ^The sqlite3_vsnprintf() routine is a varargs version of sqlite3_snprintf(). | |
| 1877 | +** | |
| 1869 | 1878 | ** These routines all implement some additional formatting |
| 1870 | 1879 | ** options that are useful for constructing SQL statements. |
| 1871 | 1880 | ** All of the usual printf() formatting options apply. In addition, there |
| 1872 | 1881 | ** is are "%q", "%Q", and "%z" options. |
| 1873 | 1882 | ** |
| @@ -1927,10 +1936,11 @@ | ||
| 1927 | 1936 | ** the result, [sqlite3_free()] is called on the input string.)^ |
| 1928 | 1937 | */ |
| 1929 | 1938 | SQLITE_API char *sqlite3_mprintf(const char*,...); |
| 1930 | 1939 | SQLITE_API char *sqlite3_vmprintf(const char*, va_list); |
| 1931 | 1940 | SQLITE_API char *sqlite3_snprintf(int,char*,const char*, ...); |
| 1941 | +SQLITE_API char *sqlite3_vsnprintf(int,char*,const char*, va_list); | |
| 1932 | 1942 | |
| 1933 | 1943 | /* |
| 1934 | 1944 | ** CAPI3REF: Memory Allocation Subsystem |
| 1935 | 1945 | ** |
| 1936 | 1946 | ** The SQLite core uses these three routines for all of its own |
| @@ -2304,11 +2314,11 @@ | ||
| 2304 | 2314 | ** <dd>The database is opened for reading and writing if possible, or reading |
| 2305 | 2315 | ** only if the file is write protected by the operating system. In either |
| 2306 | 2316 | ** case the database must already exist, otherwise an error is returned.</dd>)^ |
| 2307 | 2317 | ** |
| 2308 | 2318 | ** ^(<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 | |
| 2310 | 2320 | ** it does not already exist. This is the behavior that is always used for |
| 2311 | 2321 | ** sqlite3_open() and sqlite3_open16().</dd>)^ |
| 2312 | 2322 | ** </dl> |
| 2313 | 2323 | ** |
| 2314 | 2324 | ** If the 3rd parameter to sqlite3_open_v2() is not one of the |
| @@ -3414,20 +3424,20 @@ | ||
| 3414 | 3424 | ** encoding is used, then the fourth argument should be [SQLITE_ANY]. |
| 3415 | 3425 | ** |
| 3416 | 3426 | ** ^(The fifth parameter is an arbitrary pointer. The implementation of the |
| 3417 | 3427 | ** function can gain access to this pointer using [sqlite3_user_data()].)^ |
| 3418 | 3428 | ** |
| 3419 | -** ^The seventh, eighth and ninth parameters, xFunc, xStep and xFinal, are | |
| 3429 | +** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are | |
| 3420 | 3430 | ** pointers to C-language functions that implement the SQL function or |
| 3421 | 3431 | ** aggregate. ^A scalar SQL function requires an implementation of the xFunc |
| 3422 | 3432 | ** callback only; NULL pointers must be passed as the xStep and xFinal |
| 3423 | 3433 | ** parameters. ^An aggregate SQL function requires an implementation of xStep |
| 3424 | 3434 | ** and xFinal and NULL pointer must be passed for xFunc. ^To delete an existing |
| 3425 | 3435 | ** SQL function or aggregate, pass NULL poiners for all three function |
| 3426 | 3436 | ** callbacks. |
| 3427 | 3437 | ** |
| 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, | |
| 3429 | 3439 | ** then it is destructor for the application data pointer. |
| 3430 | 3440 | ** The destructor is invoked when the function is deleted, either by being |
| 3431 | 3441 | ** overloaded or when the database connection closes.)^ |
| 3432 | 3442 | ** ^The destructor is also invoked if the call to |
| 3433 | 3443 | ** sqlite3_create_function_v2() fails. |
| @@ -3527,11 +3537,11 @@ | ||
| 3527 | 3537 | ** the function or aggregate. |
| 3528 | 3538 | ** |
| 3529 | 3539 | ** The xFunc (for scalar functions) or xStep (for aggregates) parameters |
| 3530 | 3540 | ** to [sqlite3_create_function()] and [sqlite3_create_function16()] |
| 3531 | 3541 | ** 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 | |
| 3533 | 3543 | ** [protected sqlite3_value] objects. There is one [sqlite3_value] object for |
| 3534 | 3544 | ** each parameter to the SQL function. These routines are used to |
| 3535 | 3545 | ** extract values from the [sqlite3_value] objects. |
| 3536 | 3546 | ** |
| 3537 | 3547 | ** These routines work only with [protected sqlite3_value] objects. |
| @@ -5692,15 +5702,17 @@ | ||
| 5692 | 5702 | ** SQLite will typically create one cache instance for each open database file, |
| 5693 | 5703 | ** though this is not guaranteed. ^The |
| 5694 | 5704 | ** first parameter, szPage, is the size in bytes of the pages that must |
| 5695 | 5705 | ** be allocated by the cache. ^szPage will not be a power of two. ^szPage |
| 5696 | 5706 | ** 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 | |
| 5698 | 5708 | ** extra R bytes on each page to store metadata about the underlying |
| 5699 | 5709 | ** database page on disk. The value of R depends |
| 5700 | 5710 | ** 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 | |
| 5702 | 5714 | ** xCreate(), bPurgeable, is true if the cache being created will |
| 5703 | 5715 | ** be used to cache database pages of a file stored on disk, or |
| 5704 | 5716 | ** false if it is used for an in-memory database. The cache implementation |
| 5705 | 5717 | ** does not have to do anything special based with the value of bPurgeable; |
| 5706 | 5718 | ** it is purely advisory. ^On a cache where bPurgeable is false, SQLite will |
| @@ -5728,11 +5740,11 @@ | ||
| 5728 | 5740 | ** is considered to be "pinned". |
| 5729 | 5741 | ** |
| 5730 | 5742 | ** If the requested page is already in the page cache, then the page cache |
| 5731 | 5743 | ** implementation must return a pointer to the page buffer with its content |
| 5732 | 5744 | ** 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 | |
| 5734 | 5746 | ** parameter to help it determined what action to take: |
| 5735 | 5747 | ** |
| 5736 | 5748 | ** <table border=1 width=85% align=center> |
| 5737 | 5749 | ** <tr><th> createFlag <th> Behaviour when page is not already in cache |
| 5738 | 5750 | ** <tr><td> 0 <td> Do not allocate a new page. Return NULL. |
| 5739 | 5751 |
| --- 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 |