| | @@ -1,8 +1,8 @@ |
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | | -** version 3.15.0. By combining all the individual C code files into this |
| 3 | +** version 3.16.0. By combining all the individual C code files into this |
| 4 | 4 | ** single large file, the entire code can be compiled as a single 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. |
| | @@ -379,13 +379,13 @@ |
| 379 | 379 | ** |
| 380 | 380 | ** See also: [sqlite3_libversion()], |
| 381 | 381 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 382 | 382 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 383 | 383 | */ |
| 384 | | -#define SQLITE_VERSION "3.15.0" |
| 385 | | -#define SQLITE_VERSION_NUMBER 3015000 |
| 386 | | -#define SQLITE_SOURCE_ID "2016-10-14 10:20:30 707875582fcba352b4906a595ad89198d84711d8" |
| 384 | +#define SQLITE_VERSION "3.16.0" |
| 385 | +#define SQLITE_VERSION_NUMBER 3016000 |
| 386 | +#define SQLITE_SOURCE_ID "2016-11-02 14:50:19 3028845329c9b7acdec2ec8b01d00d782347454c" |
| 387 | 387 | |
| 388 | 388 | /* |
| 389 | 389 | ** CAPI3REF: Run-Time Library Version Numbers |
| 390 | 390 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 391 | 391 | ** |
| | @@ -1235,10 +1235,16 @@ |
| 1235 | 1235 | ** <li>[[SQLITE_FCNTL_HAS_MOVED]] |
| 1236 | 1236 | ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a |
| 1237 | 1237 | ** pointer to an integer and it writes a boolean into that integer depending |
| 1238 | 1238 | ** on whether or not the file has been renamed, moved, or deleted since it |
| 1239 | 1239 | ** was first opened. |
| 1240 | +** |
| 1241 | +** <li>[[SQLITE_FCNTL_WIN32_GET_HANDLE]] |
| 1242 | +** The [SQLITE_FCNTL_WIN32_GET_HANDLE] opcode can be used to obtain the |
| 1243 | +** underlying native file handle associated with a file handle. This file |
| 1244 | +** control interprets its argument as a pointer to a native file handle and |
| 1245 | +** writes the resulting value there. |
| 1240 | 1246 | ** |
| 1241 | 1247 | ** <li>[[SQLITE_FCNTL_WIN32_SET_HANDLE]] |
| 1242 | 1248 | ** The [SQLITE_FCNTL_WIN32_SET_HANDLE] opcode is used for debugging. This |
| 1243 | 1249 | ** opcode causes the xFileControl method to swap the file handle with the one |
| 1244 | 1250 | ** pointed to by the pArg argument. This capability is used during testing |
| | @@ -1286,10 +1292,12 @@ |
| 1286 | 1292 | #define SQLITE_FCNTL_WAL_BLOCK 24 |
| 1287 | 1293 | #define SQLITE_FCNTL_ZIPVFS 25 |
| 1288 | 1294 | #define SQLITE_FCNTL_RBU 26 |
| 1289 | 1295 | #define SQLITE_FCNTL_VFS_POINTER 27 |
| 1290 | 1296 | #define SQLITE_FCNTL_JOURNAL_POINTER 28 |
| 1297 | +#define SQLITE_FCNTL_WIN32_GET_HANDLE 29 |
| 1298 | +#define SQLITE_FCNTL_PDB 30 |
| 1291 | 1299 | |
| 1292 | 1300 | /* deprecated names */ |
| 1293 | 1301 | #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE |
| 1294 | 1302 | #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE |
| 1295 | 1303 | #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO |
| | @@ -2238,18 +2246,31 @@ |
| 2238 | 2246 | ** does not make a copy of the new main schema name string, so the application |
| 2239 | 2247 | ** must ensure that the argument passed into this DBCONFIG option is unchanged |
| 2240 | 2248 | ** until after the database connection closes. |
| 2241 | 2249 | ** </dd> |
| 2242 | 2250 | ** |
| 2251 | +** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt> |
| 2252 | +** <dd> Usually, when a database in wal mode is closed or detached from a |
| 2253 | +** database handle, SQLite checks if this will mean that there are now no |
| 2254 | +** connections at all to the database. If so, it performs a checkpoint |
| 2255 | +** operation before closing the connection. This option may be used to |
| 2256 | +** override this behaviour. The first parameter passed to this operation |
| 2257 | +** is an integer - non-zero to disable checkpoints-on-close, or zero (the |
| 2258 | +** default) to enable them. The second parameter is a pointer to an integer |
| 2259 | +** into which is written 0 or 1 to indicate whether checkpoints-on-close |
| 2260 | +** have been disabled - 0 if they are not disabled, 1 if they are. |
| 2261 | +** </dd> |
| 2262 | +** |
| 2243 | 2263 | ** </dl> |
| 2244 | 2264 | */ |
| 2245 | 2265 | #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */ |
| 2246 | 2266 | #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */ |
| 2247 | 2267 | #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */ |
| 2248 | 2268 | #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */ |
| 2249 | 2269 | #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */ |
| 2250 | 2270 | #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */ |
| 2271 | +#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */ |
| 2251 | 2272 | |
| 2252 | 2273 | |
| 2253 | 2274 | /* |
| 2254 | 2275 | ** CAPI3REF: Enable Or Disable Extended Result Codes |
| 2255 | 2276 | ** METHOD: sqlite3 |
| | @@ -12675,11 +12696,11 @@ |
| 12675 | 12696 | #define OP_SorterData 120 /* synopsis: r[P2]=data */ |
| 12676 | 12697 | #define OP_RowKey 121 /* synopsis: r[P2]=key */ |
| 12677 | 12698 | #define OP_RowData 122 /* synopsis: r[P2]=data */ |
| 12678 | 12699 | #define OP_Rowid 123 /* synopsis: r[P2]=rowid */ |
| 12679 | 12700 | #define OP_NullRow 124 |
| 12680 | | -#define OP_SorterInsert 125 |
| 12701 | +#define OP_SorterInsert 125 /* synopsis: key=r[P2] */ |
| 12681 | 12702 | #define OP_IdxInsert 126 /* synopsis: key=r[P2] */ |
| 12682 | 12703 | #define OP_IdxDelete 127 /* synopsis: key=r[P2@P3] */ |
| 12683 | 12704 | #define OP_Seek 128 /* synopsis: Move P3 to P1.rowid */ |
| 12684 | 12705 | #define OP_IdxRowid 129 /* synopsis: r[P2]=rowid */ |
| 12685 | 12706 | #define OP_Destroy 130 |
| | @@ -13030,11 +13051,11 @@ |
| 13030 | 13051 | int, |
| 13031 | 13052 | int, |
| 13032 | 13053 | int, |
| 13033 | 13054 | void(*)(DbPage*) |
| 13034 | 13055 | ); |
| 13035 | | -SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager); |
| 13056 | +SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager, sqlite3*); |
| 13036 | 13057 | SQLITE_PRIVATE int sqlite3PagerReadFileheader(Pager*, int, unsigned char*); |
| 13037 | 13058 | |
| 13038 | 13059 | /* Functions used to configure a Pager object. */ |
| 13039 | 13060 | SQLITE_PRIVATE void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *); |
| 13040 | 13061 | SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int); |
| | @@ -13081,19 +13102,22 @@ |
| 13081 | 13102 | SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n); |
| 13082 | 13103 | SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint); |
| 13083 | 13104 | SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager); |
| 13084 | 13105 | |
| 13085 | 13106 | #ifndef SQLITE_OMIT_WAL |
| 13086 | | -SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, int, int*, int*); |
| 13107 | +SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, sqlite3*, int, int*, int*); |
| 13087 | 13108 | SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager); |
| 13088 | 13109 | SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager); |
| 13089 | 13110 | SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen); |
| 13090 | | -SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager); |
| 13111 | +SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3*); |
| 13112 | +SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager); |
| 13091 | 13113 | # ifdef SQLITE_ENABLE_SNAPSHOT |
| 13092 | 13114 | SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot); |
| 13093 | 13115 | SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot); |
| 13094 | 13116 | # endif |
| 13117 | +#else |
| 13118 | +# define sqlite3PagerUseWal(x) 0 |
| 13095 | 13119 | #endif |
| 13096 | 13120 | |
| 13097 | 13121 | #ifdef SQLITE_ENABLE_ZIPVFS |
| 13098 | 13122 | SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager); |
| 13099 | 13123 | #endif |
| | @@ -14060,10 +14084,11 @@ |
| 14060 | 14084 | #define SQLITE_QueryOnly 0x04000000 /* Disable database changes */ |
| 14061 | 14085 | #define SQLITE_VdbeEQP 0x08000000 /* Debug EXPLAIN QUERY PLAN */ |
| 14062 | 14086 | #define SQLITE_Vacuum 0x10000000 /* Currently in a VACUUM */ |
| 14063 | 14087 | #define SQLITE_CellSizeCk 0x20000000 /* Check btree cell sizes on load */ |
| 14064 | 14088 | #define SQLITE_Fts3Tokenizer 0x40000000 /* Enable fts3_tokenizer(2) */ |
| 14089 | +#define SQLITE_NoCkptOnClose 0x80000000 /* No checkpoint on close()/DETACH */ |
| 14065 | 14090 | |
| 14066 | 14091 | |
| 14067 | 14092 | /* |
| 14068 | 14093 | ** Bits of the sqlite3.dbOptFlags field that are used by the |
| 14069 | 14094 | ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to |
| | @@ -17268,10 +17293,13 @@ |
| 17268 | 17293 | #if SQLITE_DEFAULT_LOCKING_MODE |
| 17269 | 17294 | "DEFAULT_LOCKING_MODE=" CTIMEOPT_VAL(SQLITE_DEFAULT_LOCKING_MODE), |
| 17270 | 17295 | #endif |
| 17271 | 17296 | #if defined(SQLITE_DEFAULT_MMAP_SIZE) && !defined(SQLITE_DEFAULT_MMAP_SIZE_xc) |
| 17272 | 17297 | "DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE), |
| 17298 | +#endif |
| 17299 | +#if SQLITE_DIRECT_OVERFLOW_READ |
| 17300 | + "DIRECT_OVERFLOW_READ", |
| 17273 | 17301 | #endif |
| 17274 | 17302 | #if SQLITE_DISABLE_DIRSYNC |
| 17275 | 17303 | "DISABLE_DIRSYNC", |
| 17276 | 17304 | #endif |
| 17277 | 17305 | #if SQLITE_DISABLE_LFS |
| | @@ -17354,10 +17382,13 @@ |
| 17354 | 17382 | #if SQLITE_ENABLE_UNLOCK_NOTIFY |
| 17355 | 17383 | "ENABLE_UNLOCK_NOTIFY", |
| 17356 | 17384 | #endif |
| 17357 | 17385 | #if SQLITE_ENABLE_UPDATE_DELETE_LIMIT |
| 17358 | 17386 | "ENABLE_UPDATE_DELETE_LIMIT", |
| 17387 | +#endif |
| 17388 | +#if defined(SQLITE_ENABLE_URI_00_ERROR) |
| 17389 | + "ENABLE_URI_00_ERROR", |
| 17359 | 17390 | #endif |
| 17360 | 17391 | #if SQLITE_HAS_CODEC |
| 17361 | 17392 | "HAS_CODEC", |
| 17362 | 17393 | #endif |
| 17363 | 17394 | #if HAVE_ISNAN || SQLITE_HAVE_ISNAN |
| | @@ -18105,12 +18136,12 @@ |
| 18105 | 18136 | UnpackedRecord *pUnpacked; /* Unpacked version of aRecord[] */ |
| 18106 | 18137 | UnpackedRecord *pNewUnpacked; /* Unpacked version of new.* record */ |
| 18107 | 18138 | int iNewReg; /* Register for new.* values */ |
| 18108 | 18139 | i64 iKey1; /* First key value passed to hook */ |
| 18109 | 18140 | i64 iKey2; /* Second key value passed to hook */ |
| 18110 | | - int iPKey; /* If not negative index of IPK column */ |
| 18111 | 18141 | Mem *aNew; /* Array of new.* values */ |
| 18142 | + Table *pTab; /* Schema object being upated */ |
| 18112 | 18143 | }; |
| 18113 | 18144 | |
| 18114 | 18145 | /* |
| 18115 | 18146 | ** Function prototypes |
| 18116 | 18147 | */ |
| | @@ -24598,13 +24629,12 @@ |
| 24598 | 24629 | char *zNew; |
| 24599 | 24630 | size_t n; |
| 24600 | 24631 | if( z==0 ){ |
| 24601 | 24632 | return 0; |
| 24602 | 24633 | } |
| 24603 | | - n = sqlite3Strlen30(z) + 1; |
| 24604 | | - assert( (n&0x7fffffff)==n ); |
| 24605 | | - zNew = sqlite3DbMallocRaw(db, (int)n); |
| 24634 | + n = strlen(z) + 1; |
| 24635 | + zNew = sqlite3DbMallocRaw(db, n); |
| 24606 | 24636 | if( zNew ){ |
| 24607 | 24637 | memcpy(zNew, z, n); |
| 24608 | 24638 | } |
| 24609 | 24639 | return zNew; |
| 24610 | 24640 | } |
| | @@ -29127,11 +29157,11 @@ |
| 29127 | 29157 | /* 120 */ "SorterData" OpHelp("r[P2]=data"), |
| 29128 | 29158 | /* 121 */ "RowKey" OpHelp("r[P2]=key"), |
| 29129 | 29159 | /* 122 */ "RowData" OpHelp("r[P2]=data"), |
| 29130 | 29160 | /* 123 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 29131 | 29161 | /* 124 */ "NullRow" OpHelp(""), |
| 29132 | | - /* 125 */ "SorterInsert" OpHelp(""), |
| 29162 | + /* 125 */ "SorterInsert" OpHelp("key=r[P2]"), |
| 29133 | 29163 | /* 126 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 29134 | 29164 | /* 127 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 29135 | 29165 | /* 128 */ "Seek" OpHelp("Move P3 to P1.rowid"), |
| 29136 | 29166 | /* 129 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 29137 | 29167 | /* 130 */ "Destroy" OpHelp(""), |
| | @@ -40674,10 +40704,16 @@ |
| 40674 | 40704 | a[1] = winIoerrRetryDelay; |
| 40675 | 40705 | } |
| 40676 | 40706 | OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); |
| 40677 | 40707 | return SQLITE_OK; |
| 40678 | 40708 | } |
| 40709 | + case SQLITE_FCNTL_WIN32_GET_HANDLE: { |
| 40710 | + LPHANDLE phFile = (LPHANDLE)pArg; |
| 40711 | + *phFile = pFile->h; |
| 40712 | + OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); |
| 40713 | + return SQLITE_OK; |
| 40714 | + } |
| 40679 | 40715 | #ifdef SQLITE_TEST |
| 40680 | 40716 | case SQLITE_FCNTL_WIN32_SET_HANDLE: { |
| 40681 | 40717 | LPHANDLE phFile = (LPHANDLE)pArg; |
| 40682 | 40718 | HANDLE hOldFile = pFile->h; |
| 40683 | 40719 | pFile->h = *phFile; |
| | @@ -46249,21 +46285,21 @@ |
| 46249 | 46285 | #define SQLITE_SYNC_MASK 0x13 /* Mask off the SQLITE_SYNC_* values */ |
| 46250 | 46286 | |
| 46251 | 46287 | #ifdef SQLITE_OMIT_WAL |
| 46252 | 46288 | # define sqlite3WalOpen(x,y,z) 0 |
| 46253 | 46289 | # define sqlite3WalLimit(x,y) |
| 46254 | | -# define sqlite3WalClose(w,x,y,z) 0 |
| 46290 | +# define sqlite3WalClose(v,w,x,y,z) 0 |
| 46255 | 46291 | # define sqlite3WalBeginReadTransaction(y,z) 0 |
| 46256 | 46292 | # define sqlite3WalEndReadTransaction(z) |
| 46257 | 46293 | # define sqlite3WalDbsize(y) 0 |
| 46258 | 46294 | # define sqlite3WalBeginWriteTransaction(y) 0 |
| 46259 | 46295 | # define sqlite3WalEndWriteTransaction(x) 0 |
| 46260 | 46296 | # define sqlite3WalUndo(x,y,z) 0 |
| 46261 | 46297 | # define sqlite3WalSavepoint(y,z) |
| 46262 | 46298 | # define sqlite3WalSavepointUndo(y,z) 0 |
| 46263 | 46299 | # define sqlite3WalFrames(u,v,w,x,y,z) 0 |
| 46264 | | -# define sqlite3WalCheckpoint(r,s,t,u,v,w,x,y,z) 0 |
| 46300 | +# define sqlite3WalCheckpoint(q,r,s,t,u,v,w,x,y,z) 0 |
| 46265 | 46301 | # define sqlite3WalCallback(z) 0 |
| 46266 | 46302 | # define sqlite3WalExclusiveMode(y,z) 0 |
| 46267 | 46303 | # define sqlite3WalHeapMemory(z) 0 |
| 46268 | 46304 | # define sqlite3WalFramesize(z) 0 |
| 46269 | 46305 | # define sqlite3WalFindFrame(x,y,z) 0 |
| | @@ -46277,11 +46313,11 @@ |
| 46277 | 46313 | */ |
| 46278 | 46314 | typedef struct Wal Wal; |
| 46279 | 46315 | |
| 46280 | 46316 | /* Open and close a connection to a write-ahead log. */ |
| 46281 | 46317 | SQLITE_PRIVATE int sqlite3WalOpen(sqlite3_vfs*, sqlite3_file*, const char *, int, i64, Wal**); |
| 46282 | | -SQLITE_PRIVATE int sqlite3WalClose(Wal *pWal, int sync_flags, int, u8 *); |
| 46318 | +SQLITE_PRIVATE int sqlite3WalClose(Wal *pWal, sqlite3*, int sync_flags, int, u8 *); |
| 46283 | 46319 | |
| 46284 | 46320 | /* Set the limiting size of a WAL file. */ |
| 46285 | 46321 | SQLITE_PRIVATE void sqlite3WalLimit(Wal*, i64); |
| 46286 | 46322 | |
| 46287 | 46323 | /* Used by readers to open (lock) and close (unlock) a snapshot. A |
| | @@ -46320,10 +46356,11 @@ |
| 46320 | 46356 | SQLITE_PRIVATE int sqlite3WalFrames(Wal *pWal, int, PgHdr *, Pgno, int, int); |
| 46321 | 46357 | |
| 46322 | 46358 | /* Copy pages from the log to the database file */ |
| 46323 | 46359 | SQLITE_PRIVATE int sqlite3WalCheckpoint( |
| 46324 | 46360 | Wal *pWal, /* Write-ahead log connection */ |
| 46361 | + sqlite3 *db, /* Check this handle's interrupt flag */ |
| 46325 | 46362 | int eMode, /* One of PASSIVE, FULL and RESTART */ |
| 46326 | 46363 | int (*xBusy)(void*), /* Function to call when busy */ |
| 46327 | 46364 | void *pBusyArg, /* Context argument for xBusyHandler */ |
| 46328 | 46365 | int sync_flags, /* Flags to sync db file with (or 0) */ |
| 46329 | 46366 | int nBuf, /* Size of buffer nBuf */ |
| | @@ -47164,13 +47201,14 @@ |
| 47164 | 47201 | /* |
| 47165 | 47202 | ** Return true if this pager uses a write-ahead log instead of the usual |
| 47166 | 47203 | ** rollback journal. Otherwise false. |
| 47167 | 47204 | */ |
| 47168 | 47205 | #ifndef SQLITE_OMIT_WAL |
| 47169 | | -static int pagerUseWal(Pager *pPager){ |
| 47206 | +SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager){ |
| 47170 | 47207 | return (pPager->pWal!=0); |
| 47171 | 47208 | } |
| 47209 | +# define pagerUseWal(x) sqlite3PagerUseWal(x) |
| 47172 | 47210 | #else |
| 47173 | 47211 | # define pagerUseWal(x) 0 |
| 47174 | 47212 | # define pagerRollbackWal(x) 0 |
| 47175 | 47213 | # define pagerWalFrames(v,w,x,y) 0 |
| 47176 | 47214 | # define pagerOpenWalIfPresent(z) SQLITE_OK |
| | @@ -50368,21 +50406,22 @@ |
| 50368 | 50406 | ** This function always succeeds. If a transaction is active an attempt |
| 50369 | 50407 | ** is made to roll it back. If an error occurs during the rollback |
| 50370 | 50408 | ** a hot journal may be left in the filesystem but no error is returned |
| 50371 | 50409 | ** to the caller. |
| 50372 | 50410 | */ |
| 50373 | | -SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager){ |
| 50411 | +SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager, sqlite3 *db){ |
| 50374 | 50412 | u8 *pTmp = (u8 *)pPager->pTmpSpace; |
| 50375 | 50413 | |
| 50414 | + assert( db || pagerUseWal(pPager)==0 ); |
| 50376 | 50415 | assert( assert_pager_state(pPager) ); |
| 50377 | 50416 | disable_simulated_io_errors(); |
| 50378 | 50417 | sqlite3BeginBenignMalloc(); |
| 50379 | 50418 | pagerFreeMapHdrs(pPager); |
| 50380 | 50419 | /* pPager->errCode = 0; */ |
| 50381 | 50420 | pPager->exclusiveMode = 0; |
| 50382 | 50421 | #ifndef SQLITE_OMIT_WAL |
| 50383 | | - sqlite3WalClose(pPager->pWal, pPager->ckptSyncFlags, pPager->pageSize, pTmp); |
| 50422 | + sqlite3WalClose(pPager->pWal,db,pPager->ckptSyncFlags,pPager->pageSize,pTmp); |
| 50384 | 50423 | pPager->pWal = 0; |
| 50385 | 50424 | #endif |
| 50386 | 50425 | pager_reset(pPager); |
| 50387 | 50426 | if( MEMDB ){ |
| 50388 | 50427 | pager_unlock(pPager); |
| | @@ -53541,14 +53580,20 @@ |
| 53541 | 53580 | ** "PRAGMA wal_blocking_checkpoint" or calls the sqlite3_wal_checkpoint() |
| 53542 | 53581 | ** or wal_blocking_checkpoint() API functions. |
| 53543 | 53582 | ** |
| 53544 | 53583 | ** Parameter eMode is one of SQLITE_CHECKPOINT_PASSIVE, FULL or RESTART. |
| 53545 | 53584 | */ |
| 53546 | | -SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, int eMode, int *pnLog, int *pnCkpt){ |
| 53585 | +SQLITE_PRIVATE int sqlite3PagerCheckpoint( |
| 53586 | + Pager *pPager, /* Checkpoint on this pager */ |
| 53587 | + sqlite3 *db, /* Db handle used to check for interrupts */ |
| 53588 | + int eMode, /* Type of checkpoint */ |
| 53589 | + int *pnLog, /* OUT: Final number of frames in log */ |
| 53590 | + int *pnCkpt /* OUT: Final number of checkpointed frames */ |
| 53591 | +){ |
| 53547 | 53592 | int rc = SQLITE_OK; |
| 53548 | 53593 | if( pPager->pWal ){ |
| 53549 | | - rc = sqlite3WalCheckpoint(pPager->pWal, eMode, |
| 53594 | + rc = sqlite3WalCheckpoint(pPager->pWal, db, eMode, |
| 53550 | 53595 | (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler), |
| 53551 | 53596 | pPager->pBusyHandlerArg, |
| 53552 | 53597 | pPager->ckptSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace, |
| 53553 | 53598 | pnLog, pnCkpt |
| 53554 | 53599 | ); |
| | @@ -53676,11 +53721,11 @@ |
| 53676 | 53721 | ** Before closing the log file, this function attempts to take an |
| 53677 | 53722 | ** EXCLUSIVE lock on the database file. If this cannot be obtained, an |
| 53678 | 53723 | ** error (SQLITE_BUSY) is returned and the log connection is not closed. |
| 53679 | 53724 | ** If successful, the EXCLUSIVE lock is not released before returning. |
| 53680 | 53725 | */ |
| 53681 | | -SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager){ |
| 53726 | +SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3 *db){ |
| 53682 | 53727 | int rc = SQLITE_OK; |
| 53683 | 53728 | |
| 53684 | 53729 | assert( pPager->journalMode==PAGER_JOURNALMODE_WAL ); |
| 53685 | 53730 | |
| 53686 | 53731 | /* If the log file is not already open, but does exist in the file-system, |
| | @@ -53704,11 +53749,11 @@ |
| 53704 | 53749 | ** the database file, the log and log-summary files will be deleted. |
| 53705 | 53750 | */ |
| 53706 | 53751 | if( rc==SQLITE_OK && pPager->pWal ){ |
| 53707 | 53752 | rc = pagerExclusiveLock(pPager); |
| 53708 | 53753 | if( rc==SQLITE_OK ){ |
| 53709 | | - rc = sqlite3WalClose(pPager->pWal, pPager->ckptSyncFlags, |
| 53754 | + rc = sqlite3WalClose(pPager->pWal, db, pPager->ckptSyncFlags, |
| 53710 | 53755 | pPager->pageSize, (u8*)pPager->pTmpSpace); |
| 53711 | 53756 | pPager->pWal = 0; |
| 53712 | 53757 | pagerFixMaplimit(pPager); |
| 53713 | 53758 | if( rc && !pPager->exclusiveMode ) pagerUnlockDb(pPager, SHARED_LOCK); |
| 53714 | 53759 | } |
| | @@ -55487,10 +55532,11 @@ |
| 55487 | 55532 | ** checkpoint is running (in any other thread or process) at the same |
| 55488 | 55533 | ** time. |
| 55489 | 55534 | */ |
| 55490 | 55535 | static int walCheckpoint( |
| 55491 | 55536 | Wal *pWal, /* Wal connection */ |
| 55537 | + sqlite3 *db, /* Check for interrupts on this handle */ |
| 55492 | 55538 | int eMode, /* One of PASSIVE, FULL or RESTART */ |
| 55493 | 55539 | int (*xBusy)(void*), /* Function to call when busy */ |
| 55494 | 55540 | void *pBusyArg, /* Context argument for xBusyHandler */ |
| 55495 | 55541 | int sync_flags, /* Flags for OsSync() (or 0) */ |
| 55496 | 55542 | u8 *zBuf /* Temporary buffer to use */ |
| | @@ -55581,10 +55627,14 @@ |
| 55581 | 55627 | |
| 55582 | 55628 | /* Iterate through the contents of the WAL, copying data to the db file */ |
| 55583 | 55629 | while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){ |
| 55584 | 55630 | i64 iOffset; |
| 55585 | 55631 | assert( walFramePgno(pWal, iFrame)==iDbpage ); |
| 55632 | + if( db->u1.isInterrupted ){ |
| 55633 | + rc = db->mallocFailed ? SQLITE_NOMEM_BKPT : SQLITE_INTERRUPT; |
| 55634 | + break; |
| 55635 | + } |
| 55586 | 55636 | if( iFrame<=nBackfill || iFrame>mxSafeFrame || iDbpage>mxPage ){ |
| 55587 | 55637 | continue; |
| 55588 | 55638 | } |
| 55589 | 55639 | iOffset = walFrameOffset(iFrame, szPage) + WAL_FRAME_HDRSIZE; |
| 55590 | 55640 | /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL file */ |
| | @@ -55685,10 +55735,11 @@ |
| 55685 | 55735 | /* |
| 55686 | 55736 | ** Close a connection to a log file. |
| 55687 | 55737 | */ |
| 55688 | 55738 | SQLITE_PRIVATE int sqlite3WalClose( |
| 55689 | 55739 | Wal *pWal, /* Wal to close */ |
| 55740 | + sqlite3 *db, /* For interrupt flag */ |
| 55690 | 55741 | int sync_flags, /* Flags to pass to OsSync() (or 0) */ |
| 55691 | 55742 | int nBuf, |
| 55692 | 55743 | u8 *zBuf /* Buffer of at least nBuf bytes */ |
| 55693 | 55744 | ){ |
| 55694 | 55745 | int rc = SQLITE_OK; |
| | @@ -55701,17 +55752,18 @@ |
| 55701 | 55752 | ** the database. In this case checkpoint the database and unlink both |
| 55702 | 55753 | ** the wal and wal-index files. |
| 55703 | 55754 | ** |
| 55704 | 55755 | ** The EXCLUSIVE lock is not released before returning. |
| 55705 | 55756 | */ |
| 55706 | | - rc = sqlite3OsLock(pWal->pDbFd, SQLITE_LOCK_EXCLUSIVE); |
| 55707 | | - if( rc==SQLITE_OK ){ |
| 55757 | + if( (db->flags & SQLITE_NoCkptOnClose)==0 |
| 55758 | + && SQLITE_OK==(rc = sqlite3OsLock(pWal->pDbFd, SQLITE_LOCK_EXCLUSIVE)) |
| 55759 | + ){ |
| 55708 | 55760 | if( pWal->exclusiveMode==WAL_NORMAL_MODE ){ |
| 55709 | 55761 | pWal->exclusiveMode = WAL_EXCLUSIVE_MODE; |
| 55710 | 55762 | } |
| 55711 | | - rc = sqlite3WalCheckpoint( |
| 55712 | | - pWal, SQLITE_CHECKPOINT_PASSIVE, 0, 0, sync_flags, nBuf, zBuf, 0, 0 |
| 55763 | + rc = sqlite3WalCheckpoint(pWal, db, |
| 55764 | + SQLITE_CHECKPOINT_PASSIVE, 0, 0, sync_flags, nBuf, zBuf, 0, 0 |
| 55713 | 55765 | ); |
| 55714 | 55766 | if( rc==SQLITE_OK ){ |
| 55715 | 55767 | int bPersist = -1; |
| 55716 | 55768 | sqlite3OsFileControlHint( |
| 55717 | 55769 | pWal->pDbFd, SQLITE_FCNTL_PERSIST_WAL, &bPersist |
| | @@ -56955,10 +57007,11 @@ |
| 56955 | 57007 | ** If parameter xBusy is not NULL, it is a pointer to a busy-handler |
| 56956 | 57008 | ** callback. In this case this function runs a blocking checkpoint. |
| 56957 | 57009 | */ |
| 56958 | 57010 | SQLITE_PRIVATE int sqlite3WalCheckpoint( |
| 56959 | 57011 | Wal *pWal, /* Wal connection */ |
| 57012 | + sqlite3 *db, /* Check this handle's interrupt flag */ |
| 56960 | 57013 | int eMode, /* PASSIVE, FULL, RESTART, or TRUNCATE */ |
| 56961 | 57014 | int (*xBusy)(void*), /* Function to call when busy */ |
| 56962 | 57015 | void *pBusyArg, /* Context argument for xBusyHandler */ |
| 56963 | 57016 | int sync_flags, /* Flags to sync db file with (or 0) */ |
| 56964 | 57017 | int nBuf, /* Size of temporary buffer */ |
| | @@ -57029,11 +57082,11 @@ |
| 57029 | 57082 | if( rc==SQLITE_OK ){ |
| 57030 | 57083 | |
| 57031 | 57084 | if( pWal->hdr.mxFrame && walPagesize(pWal)!=nBuf ){ |
| 57032 | 57085 | rc = SQLITE_CORRUPT_BKPT; |
| 57033 | 57086 | }else{ |
| 57034 | | - rc = walCheckpoint(pWal, eMode2, xBusy2, pBusyArg, sync_flags, zBuf); |
| 57087 | + rc = walCheckpoint(pWal, db, eMode2, xBusy2, pBusyArg, sync_flags, zBuf); |
| 57035 | 57088 | } |
| 57036 | 57089 | |
| 57037 | 57090 | /* If no error occurred, set the output variables. */ |
| 57038 | 57091 | if( rc==SQLITE_OK || rc==SQLITE_BUSY ){ |
| 57039 | 57092 | if( pnLog ) *pnLog = (int)pWal->hdr.mxFrame; |
| | @@ -60619,23 +60672,30 @@ |
| 60619 | 60672 | *ppBtree = p; |
| 60620 | 60673 | |
| 60621 | 60674 | btree_open_out: |
| 60622 | 60675 | if( rc!=SQLITE_OK ){ |
| 60623 | 60676 | if( pBt && pBt->pPager ){ |
| 60624 | | - sqlite3PagerClose(pBt->pPager); |
| 60677 | + sqlite3PagerClose(pBt->pPager, 0); |
| 60625 | 60678 | } |
| 60626 | 60679 | sqlite3_free(pBt); |
| 60627 | 60680 | sqlite3_free(p); |
| 60628 | 60681 | *ppBtree = 0; |
| 60629 | 60682 | }else{ |
| 60683 | + sqlite3_file *pFile; |
| 60684 | + |
| 60630 | 60685 | /* If the B-Tree was successfully opened, set the pager-cache size to the |
| 60631 | 60686 | ** default value. Except, when opening on an existing shared pager-cache, |
| 60632 | 60687 | ** do not change the pager-cache size. |
| 60633 | 60688 | */ |
| 60634 | 60689 | if( sqlite3BtreeSchema(p, 0, 0)==0 ){ |
| 60635 | 60690 | sqlite3PagerSetCachesize(p->pBt->pPager, SQLITE_DEFAULT_CACHE_SIZE); |
| 60636 | 60691 | } |
| 60692 | + |
| 60693 | + pFile = sqlite3PagerFile(pBt->pPager); |
| 60694 | + if( pFile->pMethods ){ |
| 60695 | + sqlite3OsFileControlHint(pFile, SQLITE_FCNTL_PDB, (void*)&pBt->db); |
| 60696 | + } |
| 60637 | 60697 | } |
| 60638 | 60698 | if( mutexOpen ){ |
| 60639 | 60699 | assert( sqlite3_mutex_held(mutexOpen) ); |
| 60640 | 60700 | sqlite3_mutex_leave(mutexOpen); |
| 60641 | 60701 | } |
| | @@ -60761,11 +60821,11 @@ |
| 60761 | 60821 | ** it without having to hold the mutex. |
| 60762 | 60822 | ** |
| 60763 | 60823 | ** Clean out and delete the BtShared object. |
| 60764 | 60824 | */ |
| 60765 | 60825 | assert( !pBt->pCursor ); |
| 60766 | | - sqlite3PagerClose(pBt->pPager); |
| 60826 | + sqlite3PagerClose(pBt->pPager, p->db); |
| 60767 | 60827 | if( pBt->xFreeSchema && pBt->pSchema ){ |
| 60768 | 60828 | pBt->xFreeSchema(pBt->pSchema); |
| 60769 | 60829 | } |
| 60770 | 60830 | sqlite3DbFree(0, pBt->pSchema); |
| 60771 | 60831 | freeTempSpace(pBt); |
| | @@ -62825,11 +62885,11 @@ |
| 62825 | 62885 | if( (eOp&0x01)==0 /* (1) */ |
| 62826 | 62886 | && offset==0 /* (2) */ |
| 62827 | 62887 | && (bEnd || a==ovflSize) /* (6) */ |
| 62828 | 62888 | && pBt->inTransaction==TRANS_READ /* (4) */ |
| 62829 | 62889 | && (fd = sqlite3PagerFile(pBt->pPager))->pMethods /* (3) */ |
| 62830 | | - && pBt->pPage1->aData[19]==0x01 /* (5) */ |
| 62890 | + && 0==sqlite3PagerUseWal(pBt->pPager) /* (5) */ |
| 62831 | 62891 | && &pBuf[-4]>=pBufStart /* (7) */ |
| 62832 | 62892 | ){ |
| 62833 | 62893 | u8 aSave[4]; |
| 62834 | 62894 | u8 *aWrite = &pBuf[-4]; |
| 62835 | 62895 | assert( aWrite>=pBufStart ); /* hence (7) */ |
| | @@ -63081,13 +63141,16 @@ |
| 63081 | 63141 | } |
| 63082 | 63142 | sqlite3BtreeClearCursor(pCur); |
| 63083 | 63143 | } |
| 63084 | 63144 | |
| 63085 | 63145 | if( pCur->iPage>=0 ){ |
| 63086 | | - while( pCur->iPage ){ |
| 63087 | | - assert( pCur->apPage[pCur->iPage]!=0 ); |
| 63088 | | - releasePageNotNull(pCur->apPage[pCur->iPage--]); |
| 63146 | + if( pCur->iPage ){ |
| 63147 | + do{ |
| 63148 | + assert( pCur->apPage[pCur->iPage]!=0 ); |
| 63149 | + releasePageNotNull(pCur->apPage[pCur->iPage--]); |
| 63150 | + }while( pCur->iPage); |
| 63151 | + goto skip_init; |
| 63089 | 63152 | } |
| 63090 | 63153 | }else if( pCur->pgnoRoot==0 ){ |
| 63091 | 63154 | pCur->eState = CURSOR_INVALID; |
| 63092 | 63155 | return SQLITE_OK; |
| 63093 | 63156 | }else{ |
| | @@ -63094,11 +63157,11 @@ |
| 63094 | 63157 | assert( pCur->iPage==(-1) ); |
| 63095 | 63158 | rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0], |
| 63096 | 63159 | 0, pCur->curPagerFlags); |
| 63097 | 63160 | if( rc!=SQLITE_OK ){ |
| 63098 | 63161 | pCur->eState = CURSOR_INVALID; |
| 63099 | | - return rc; |
| 63162 | + return rc; |
| 63100 | 63163 | } |
| 63101 | 63164 | pCur->iPage = 0; |
| 63102 | 63165 | pCur->curIntKey = pCur->apPage[0]->intKey; |
| 63103 | 63166 | } |
| 63104 | 63167 | pRoot = pCur->apPage[0]; |
| | @@ -63117,14 +63180,16 @@ |
| 63117 | 63180 | assert( pRoot->intKey==1 || pRoot->intKey==0 ); |
| 63118 | 63181 | if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){ |
| 63119 | 63182 | return SQLITE_CORRUPT_BKPT; |
| 63120 | 63183 | } |
| 63121 | 63184 | |
| 63185 | +skip_init: |
| 63122 | 63186 | pCur->aiIdx[0] = 0; |
| 63123 | 63187 | pCur->info.nSize = 0; |
| 63124 | 63188 | pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidNKey|BTCF_ValidOvfl); |
| 63125 | 63189 | |
| 63190 | + pRoot = pCur->apPage[0]; |
| 63126 | 63191 | if( pRoot->nCell>0 ){ |
| 63127 | 63192 | pCur->eState = CURSOR_VALID; |
| 63128 | 63193 | }else if( !pRoot->leaf ){ |
| 63129 | 63194 | Pgno subpage; |
| 63130 | 63195 | if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT; |
| | @@ -67701,11 +67766,11 @@ |
| 67701 | 67766 | BtShared *pBt = p->pBt; |
| 67702 | 67767 | sqlite3BtreeEnter(p); |
| 67703 | 67768 | if( pBt->inTransaction!=TRANS_NONE ){ |
| 67704 | 67769 | rc = SQLITE_LOCKED; |
| 67705 | 67770 | }else{ |
| 67706 | | - rc = sqlite3PagerCheckpoint(pBt->pPager, eMode, pnLog, pnCkpt); |
| 67771 | + rc = sqlite3PagerCheckpoint(pBt->pPager, p->db, eMode, pnLog, pnCkpt); |
| 67707 | 67772 | } |
| 67708 | 67773 | sqlite3BtreeLeave(p); |
| 67709 | 67774 | } |
| 67710 | 67775 | return rc; |
| 67711 | 67776 | } |
| | @@ -75076,11 +75141,11 @@ |
| 75076 | 75141 | preupdate.keyinfo.enc = ENC(db); |
| 75077 | 75142 | preupdate.keyinfo.nField = pTab->nCol; |
| 75078 | 75143 | preupdate.keyinfo.aSortOrder = (u8*)&fakeSortOrder; |
| 75079 | 75144 | preupdate.iKey1 = iKey1; |
| 75080 | 75145 | preupdate.iKey2 = iKey2; |
| 75081 | | - preupdate.iPKey = pTab->iPKey; |
| 75146 | + preupdate.pTab = pTab; |
| 75082 | 75147 | |
| 75083 | 75148 | db->pPreUpdate = &preupdate; |
| 75084 | 75149 | db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2); |
| 75085 | 75150 | db->pPreUpdate = 0; |
| 75086 | 75151 | sqlite3DbFree(db, preupdate.aRecord); |
| | @@ -76808,13 +76873,18 @@ |
| 76808 | 76873 | } |
| 76809 | 76874 | |
| 76810 | 76875 | if( iIdx>=p->pUnpacked->nField ){ |
| 76811 | 76876 | *ppValue = (sqlite3_value *)columnNullValue(); |
| 76812 | 76877 | }else{ |
| 76878 | + Mem *pMem = *ppValue = &p->pUnpacked->aMem[iIdx]; |
| 76813 | 76879 | *ppValue = &p->pUnpacked->aMem[iIdx]; |
| 76814 | | - if( iIdx==p->iPKey ){ |
| 76815 | | - sqlite3VdbeMemSetInt64(*ppValue, p->iKey1); |
| 76880 | + if( iIdx==p->pTab->iPKey ){ |
| 76881 | + sqlite3VdbeMemSetInt64(pMem, p->iKey1); |
| 76882 | + }else if( p->pTab->aCol[iIdx].affinity==SQLITE_AFF_REAL ){ |
| 76883 | + if( pMem->flags & MEM_Int ){ |
| 76884 | + sqlite3VdbeMemRealify(pMem); |
| 76885 | + } |
| 76816 | 76886 | } |
| 76817 | 76887 | } |
| 76818 | 76888 | |
| 76819 | 76889 | preupdate_old_out: |
| 76820 | 76890 | sqlite3Error(db, rc); |
| | @@ -76887,11 +76957,11 @@ |
| 76887 | 76957 | } |
| 76888 | 76958 | if( iIdx>=pUnpack->nField ){ |
| 76889 | 76959 | pMem = (sqlite3_value *)columnNullValue(); |
| 76890 | 76960 | }else{ |
| 76891 | 76961 | pMem = &pUnpack->aMem[iIdx]; |
| 76892 | | - if( iIdx==p->iPKey ){ |
| 76962 | + if( iIdx==p->pTab->iPKey ){ |
| 76893 | 76963 | sqlite3VdbeMemSetInt64(pMem, p->iKey2); |
| 76894 | 76964 | } |
| 76895 | 76965 | } |
| 76896 | 76966 | }else{ |
| 76897 | 76967 | /* For an UPDATE, memory cell (p->iNewReg+1+iIdx) contains the required |
| | @@ -76908,11 +76978,11 @@ |
| 76908 | 76978 | } |
| 76909 | 76979 | } |
| 76910 | 76980 | assert( iIdx>=0 && iIdx<p->pCsr->nField ); |
| 76911 | 76981 | pMem = &p->aNew[iIdx]; |
| 76912 | 76982 | if( pMem->flags==0 ){ |
| 76913 | | - if( iIdx==p->iPKey ){ |
| 76983 | + if( iIdx==p->pTab->iPKey ){ |
| 76914 | 76984 | sqlite3VdbeMemSetInt64(pMem, p->iKey2); |
| 76915 | 76985 | }else{ |
| 76916 | 76986 | rc = sqlite3VdbeMemCopy(pMem, &p->v->aMem[p->iNewReg+1+iIdx]); |
| 76917 | 76987 | if( rc!=SQLITE_OK ) goto preupdate_new_out; |
| 76918 | 76988 | } |
| | @@ -79286,12 +79356,11 @@ |
| 79286 | 79356 | ** or not both operands are null. |
| 79287 | 79357 | */ |
| 79288 | 79358 | assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne ); |
| 79289 | 79359 | assert( (flags1 & MEM_Cleared)==0 ); |
| 79290 | 79360 | assert( (pOp->p5 & SQLITE_JUMPIFNULL)==0 ); |
| 79291 | | - if( (flags1&MEM_Null)!=0 |
| 79292 | | - && (flags3&MEM_Null)!=0 |
| 79361 | + if( (flags1&flags3&MEM_Null)!=0 |
| 79293 | 79362 | && (flags3&MEM_Cleared)==0 |
| 79294 | 79363 | ){ |
| 79295 | 79364 | res = 0; /* Operands are equal */ |
| 79296 | 79365 | }else{ |
| 79297 | 79366 | res = 1; /* Operands are not equal */ |
| | @@ -81554,11 +81623,11 @@ |
| 81554 | 81623 | |
| 81555 | 81624 | REGISTER_TRACE(pOp->p3, pMem); |
| 81556 | 81625 | sqlite3VdbeMemIntegerify(pMem); |
| 81557 | 81626 | assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */ |
| 81558 | 81627 | if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){ |
| 81559 | | - rc = SQLITE_FULL; /* IMP: R-12275-61338 */ |
| 81628 | + rc = SQLITE_FULL; /* IMP: R-17817-00630 */ |
| 81560 | 81629 | goto abort_due_to_error; |
| 81561 | 81630 | } |
| 81562 | 81631 | if( v<pMem->u.i+1 ){ |
| 81563 | 81632 | v = pMem->u.i + 1; |
| 81564 | 81633 | } |
| | @@ -82321,10 +82390,17 @@ |
| 82321 | 82390 | ** This flag avoids doing an extra seek. |
| 82322 | 82391 | ** |
| 82323 | 82392 | ** This instruction only works for indices. The equivalent instruction |
| 82324 | 82393 | ** for tables is OP_Insert. |
| 82325 | 82394 | */ |
| 82395 | +/* Opcode: SorterInsert P1 P2 * * * |
| 82396 | +** Synopsis: key=r[P2] |
| 82397 | +** |
| 82398 | +** Register P2 holds an SQL index key made using the |
| 82399 | +** MakeRecord instructions. This opcode writes that key |
| 82400 | +** into the sorter P1. Data for the entry is nil. |
| 82401 | +*/ |
| 82326 | 82402 | case OP_SorterInsert: /* in2 */ |
| 82327 | 82403 | case OP_IdxInsert: { /* in2 */ |
| 82328 | 82404 | VdbeCursor *pC; |
| 82329 | 82405 | BtreePayload x; |
| 82330 | 82406 | |
| | @@ -83549,11 +83625,11 @@ |
| 83549 | 83625 | /* If leaving WAL mode, close the log file. If successful, the call |
| 83550 | 83626 | ** to PagerCloseWal() checkpoints and deletes the write-ahead-log |
| 83551 | 83627 | ** file. An EXCLUSIVE lock may still be held on the database file |
| 83552 | 83628 | ** after a successful return. |
| 83553 | 83629 | */ |
| 83554 | | - rc = sqlite3PagerCloseWal(pPager); |
| 83630 | + rc = sqlite3PagerCloseWal(pPager, db); |
| 83555 | 83631 | if( rc==SQLITE_OK ){ |
| 83556 | 83632 | sqlite3PagerSetJournalMode(pPager, eNew); |
| 83557 | 83633 | } |
| 83558 | 83634 | }else if( eOld==PAGER_JOURNALMODE_MEMORY ){ |
| 83559 | 83635 | /* Cannot transition directly from MEMORY to WAL. Use mode OFF |
| | @@ -94292,15 +94368,14 @@ |
| 94292 | 94368 | && (sqlite3ExprImpliesExpr(pE1, pE2->pLeft, iTab) |
| 94293 | 94369 | || sqlite3ExprImpliesExpr(pE1, pE2->pRight, iTab) ) |
| 94294 | 94370 | ){ |
| 94295 | 94371 | return 1; |
| 94296 | 94372 | } |
| 94297 | | - if( pE2->op==TK_NOTNULL |
| 94298 | | - && sqlite3ExprCompare(pE1->pLeft, pE2->pLeft, iTab)==0 |
| 94299 | | - && (pE1->op!=TK_ISNULL && pE1->op!=TK_IS) |
| 94300 | | - ){ |
| 94301 | | - return 1; |
| 94373 | + if( pE2->op==TK_NOTNULL && pE1->op!=TK_ISNULL && pE1->op!=TK_IS ){ |
| 94374 | + Expr *pX = sqlite3ExprSkipCollate(pE1->pLeft); |
| 94375 | + testcase( pX!=pE1->pLeft ); |
| 94376 | + if( sqlite3ExprCompare(pX, pE2->pLeft, iTab)==0 ) return 1; |
| 94302 | 94377 | } |
| 94303 | 94378 | return 0; |
| 94304 | 94379 | } |
| 94305 | 94380 | |
| 94306 | 94381 | /* |
| | @@ -122354,11 +122429,11 @@ |
| 122354 | 122429 | } |
| 122355 | 122430 | #endif |
| 122356 | 122431 | |
| 122357 | 122432 | sqlite3BtreeSetCacheSize(pTemp, db->aDb[iDb].pSchema->cache_size); |
| 122358 | 122433 | sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0)); |
| 122359 | | - sqlite3BtreeSetPagerFlags(pTemp, PAGER_SYNCHRONOUS_OFF); |
| 122434 | + sqlite3BtreeSetPagerFlags(pTemp, PAGER_SYNCHRONOUS_OFF|PAGER_CACHESPILL); |
| 122360 | 122435 | |
| 122361 | 122436 | /* Begin a transaction and take an exclusive lock on the main database |
| 122362 | 122437 | ** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below, |
| 122363 | 122438 | ** to ensure that we do not try to change the page-size on a WAL database. |
| 122364 | 122439 | */ |
| | @@ -127537,10 +127612,11 @@ |
| 127537 | 127612 | Expr *pNew; |
| 127538 | 127613 | Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i); |
| 127539 | 127614 | Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i); |
| 127540 | 127615 | |
| 127541 | 127616 | pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight, 0); |
| 127617 | + transferJoinMarkings(pNew, pExpr); |
| 127542 | 127618 | idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC); |
| 127543 | 127619 | exprAnalyze(pSrc, pWC, idxNew); |
| 127544 | 127620 | } |
| 127545 | 127621 | pTerm = &pWC->a[idxTerm]; |
| 127546 | 127622 | pTerm->wtFlags = TERM_CODED|TERM_VIRTUAL; /* Disable the original */ |
| | @@ -127978,15 +128054,17 @@ |
| 127978 | 128054 | Expr *pX; /* An expression being tested */ |
| 127979 | 128055 | WhereClause *pWC; /* Shorthand for pScan->pWC */ |
| 127980 | 128056 | WhereTerm *pTerm; /* The term being tested */ |
| 127981 | 128057 | int k = pScan->k; /* Where to start scanning */ |
| 127982 | 128058 | |
| 127983 | | - while( pScan->iEquiv<=pScan->nEquiv ){ |
| 127984 | | - iCur = pScan->aiCur[pScan->iEquiv-1]; |
| 128059 | + assert( pScan->iEquiv<=pScan->nEquiv ); |
| 128060 | + pWC = pScan->pWC; |
| 128061 | + while(1){ |
| 127985 | 128062 | iColumn = pScan->aiColumn[pScan->iEquiv-1]; |
| 127986 | | - if( iColumn==XN_EXPR && pScan->pIdxExpr==0 ) return 0; |
| 127987 | | - while( (pWC = pScan->pWC)!=0 ){ |
| 128063 | + iCur = pScan->aiCur[pScan->iEquiv-1]; |
| 128064 | + assert( pWC!=0 ); |
| 128065 | + do{ |
| 127988 | 128066 | for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){ |
| 127989 | 128067 | if( pTerm->leftCursor==iCur |
| 127990 | 128068 | && pTerm->u.leftColumn==iColumn |
| 127991 | 128069 | && (iColumn!=XN_EXPR |
| 127992 | 128070 | || sqlite3ExprCompare(pTerm->pExpr->pLeft,pScan->pIdxExpr,iCur)==0) |
| | @@ -128032,19 +128110,21 @@ |
| 128032 | 128110 | && pX->iColumn==pScan->aiColumn[0] |
| 128033 | 128111 | ){ |
| 128034 | 128112 | testcase( pTerm->eOperator & WO_IS ); |
| 128035 | 128113 | continue; |
| 128036 | 128114 | } |
| 128115 | + pScan->pWC = pWC; |
| 128037 | 128116 | pScan->k = k+1; |
| 128038 | 128117 | return pTerm; |
| 128039 | 128118 | } |
| 128040 | 128119 | } |
| 128041 | 128120 | } |
| 128042 | | - pScan->pWC = pScan->pWC->pOuter; |
| 128121 | + pWC = pWC->pOuter; |
| 128043 | 128122 | k = 0; |
| 128044 | | - } |
| 128045 | | - pScan->pWC = pScan->pOrigWC; |
| 128123 | + }while( pWC!=0 ); |
| 128124 | + if( pScan->iEquiv>=pScan->nEquiv ) break; |
| 128125 | + pWC = pScan->pOrigWC; |
| 128046 | 128126 | k = 0; |
| 128047 | 128127 | pScan->iEquiv++; |
| 128048 | 128128 | } |
| 128049 | 128129 | return 0; |
| 128050 | 128130 | } |
| | @@ -128074,28 +128154,28 @@ |
| 128074 | 128154 | int iCur, /* Cursor to scan for */ |
| 128075 | 128155 | int iColumn, /* Column to scan for */ |
| 128076 | 128156 | u32 opMask, /* Operator(s) to scan for */ |
| 128077 | 128157 | Index *pIdx /* Must be compatible with this index */ |
| 128078 | 128158 | ){ |
| 128079 | | - int j = 0; |
| 128080 | | - |
| 128081 | | - /* memset(pScan, 0, sizeof(*pScan)); */ |
| 128082 | 128159 | pScan->pOrigWC = pWC; |
| 128083 | 128160 | pScan->pWC = pWC; |
| 128084 | 128161 | pScan->pIdxExpr = 0; |
| 128162 | + pScan->idxaff = 0; |
| 128163 | + pScan->zCollName = 0; |
| 128085 | 128164 | if( pIdx ){ |
| 128086 | | - j = iColumn; |
| 128165 | + int j = iColumn; |
| 128087 | 128166 | iColumn = pIdx->aiColumn[j]; |
| 128088 | | - if( iColumn==XN_EXPR ) pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr; |
| 128089 | | - if( iColumn==pIdx->pTable->iPKey ) iColumn = XN_ROWID; |
| 128090 | | - } |
| 128091 | | - if( pIdx && iColumn>=0 ){ |
| 128092 | | - pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity; |
| 128093 | | - pScan->zCollName = pIdx->azColl[j]; |
| 128094 | | - }else{ |
| 128095 | | - pScan->idxaff = 0; |
| 128096 | | - pScan->zCollName = 0; |
| 128167 | + if( iColumn==XN_EXPR ){ |
| 128168 | + pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr; |
| 128169 | + }else if( iColumn==pIdx->pTable->iPKey ){ |
| 128170 | + iColumn = XN_ROWID; |
| 128171 | + }else if( iColumn>=0 ){ |
| 128172 | + pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity; |
| 128173 | + pScan->zCollName = pIdx->azColl[j]; |
| 128174 | + } |
| 128175 | + }else if( iColumn==XN_EXPR ){ |
| 128176 | + return 0; |
| 128097 | 128177 | } |
| 128098 | 128178 | pScan->opMask = opMask; |
| 128099 | 128179 | pScan->k = 0; |
| 128100 | 128180 | pScan->aiCur[0] = iCur; |
| 128101 | 128181 | pScan->aiColumn[0] = iColumn; |
| | @@ -132640,17 +132720,19 @@ |
| 132640 | 132720 | pLevel->addrLikeRep); |
| 132641 | 132721 | VdbeCoverage(v); |
| 132642 | 132722 | } |
| 132643 | 132723 | #endif |
| 132644 | 132724 | if( pLevel->iLeftJoin ){ |
| 132725 | + int ws = pLoop->wsFlags; |
| 132645 | 132726 | addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v); |
| 132646 | | - assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 |
| 132647 | | - || (pLoop->wsFlags & WHERE_INDEXED)!=0 ); |
| 132648 | | - if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 ){ |
| 132727 | + assert( (ws & WHERE_IDX_ONLY)==0 || (ws & WHERE_INDEXED)!=0 ); |
| 132728 | + if( (ws & WHERE_IDX_ONLY)==0 ){ |
| 132649 | 132729 | sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor); |
| 132650 | 132730 | } |
| 132651 | | - if( pLoop->wsFlags & WHERE_INDEXED ){ |
| 132731 | + if( (ws & WHERE_INDEXED) |
| 132732 | + || ((ws & WHERE_MULTI_OR) && pLevel->u.pCovidx) |
| 132733 | + ){ |
| 132652 | 132734 | sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur); |
| 132653 | 132735 | } |
| 132654 | 132736 | if( pLevel->op==OP_Return ){ |
| 132655 | 132737 | sqlite3VdbeAddOp2(v, OP_Gosub, pLevel->p1, pLevel->addrFirst); |
| 132656 | 132738 | }else{ |
| | @@ -138612,10 +138694,11 @@ |
| 138612 | 138694 | } aFlagOp[] = { |
| 138613 | 138695 | { SQLITE_DBCONFIG_ENABLE_FKEY, SQLITE_ForeignKeys }, |
| 138614 | 138696 | { SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger }, |
| 138615 | 138697 | { SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_Fts3Tokenizer }, |
| 138616 | 138698 | { SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_LoadExtension }, |
| 138699 | + { SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE, SQLITE_NoCkptOnClose }, |
| 138617 | 138700 | }; |
| 138618 | 138701 | unsigned int i; |
| 138619 | 138702 | rc = SQLITE_ERROR; /* IMP: R-42790-23372 */ |
| 138620 | 138703 | for(i=0; i<ArraySize(aFlagOp); i++){ |
| 138621 | 138704 | if( aFlagOp[i].op==op ){ |
| | @@ -139908,10 +139991,17 @@ |
| 139908 | 139991 | db->busyHandler.nBusy = 0; |
| 139909 | 139992 | rc = sqlite3Checkpoint(db, iDb, eMode, pnLog, pnCkpt); |
| 139910 | 139993 | sqlite3Error(db, rc); |
| 139911 | 139994 | } |
| 139912 | 139995 | rc = sqlite3ApiExit(db, rc); |
| 139996 | + |
| 139997 | + /* If there are no active statements, clear the interrupt flag at this |
| 139998 | + ** point. */ |
| 139999 | + if( db->nVdbeActive==0 ){ |
| 140000 | + db->u1.isInterrupted = 0; |
| 140001 | + } |
| 140002 | + |
| 139913 | 140003 | sqlite3_mutex_leave(db->mutex); |
| 139914 | 140004 | return rc; |
| 139915 | 140005 | #endif |
| 139916 | 140006 | } |
| 139917 | 140007 | |
| | @@ -140410,10 +140500,11 @@ |
| 140410 | 140500 | int octet = (sqlite3HexToInt(zUri[iIn++]) << 4); |
| 140411 | 140501 | octet += sqlite3HexToInt(zUri[iIn++]); |
| 140412 | 140502 | |
| 140413 | 140503 | assert( octet>=0 && octet<256 ); |
| 140414 | 140504 | if( octet==0 ){ |
| 140505 | +#ifndef SQLITE_ENABLE_URI_00_ERROR |
| 140415 | 140506 | /* This branch is taken when "%00" appears within the URI. In this |
| 140416 | 140507 | ** case we ignore all text in the remainder of the path, name or |
| 140417 | 140508 | ** value currently being parsed. So ignore the current character |
| 140418 | 140509 | ** and skip to the next "?", "=" or "&", as appropriate. */ |
| 140419 | 140510 | while( (c = zUri[iIn])!=0 && c!='#' |
| | @@ -140422,10 +140513,16 @@ |
| 140422 | 140513 | && (eState!=2 || c!='&') |
| 140423 | 140514 | ){ |
| 140424 | 140515 | iIn++; |
| 140425 | 140516 | } |
| 140426 | 140517 | continue; |
| 140518 | +#else |
| 140519 | + /* If ENABLE_URI_00_ERROR is defined, "%00" in a URI is an error. */ |
| 140520 | + *pzErrMsg = sqlite3_mprintf("unexpected %%00 in uri"); |
| 140521 | + rc = SQLITE_ERROR; |
| 140522 | + goto parse_uri_out; |
| 140523 | +#endif |
| 140427 | 140524 | } |
| 140428 | 140525 | c = octet; |
| 140429 | 140526 | }else if( eState==1 && (c=='&' || c=='=') ){ |
| 140430 | 140527 | if( zFile[iOut-1]==0 ){ |
| 140431 | 140528 | /* An empty option name. Ignore this option altogether. */ |
| | @@ -165207,11 +165304,11 @@ |
| 165207 | 165304 | ** of the locale to use. Passing an empty string ("") or SQL NULL value |
| 165208 | 165305 | ** as the second argument is the same as invoking the 1 argument version |
| 165209 | 165306 | ** of upper() or lower(). |
| 165210 | 165307 | ** |
| 165211 | 165308 | ** lower('I', 'en_us') -> 'i' |
| 165212 | | -** lower('I', 'tr_tr') -> 'ı' (small dotless i) |
| 165309 | +** lower('I', 'tr_tr') -> '\u131' (small dotless i) |
| 165213 | 165310 | ** |
| 165214 | 165311 | ** http://www.icu-project.org/userguide/posix.html#case_mappings |
| 165215 | 165312 | */ |
| 165216 | 165313 | static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){ |
| 165217 | 165314 | const UChar *zInput; /* Pointer to input string */ |
| | @@ -195596,11 +195693,11 @@ |
| 195596 | 195693 | int nArg, /* Number of args */ |
| 195597 | 195694 | sqlite3_value **apUnused /* Function arguments */ |
| 195598 | 195695 | ){ |
| 195599 | 195696 | assert( nArg==0 ); |
| 195600 | 195697 | UNUSED_PARAM2(nArg, apUnused); |
| 195601 | | - sqlite3_result_text(pCtx, "fts5: 2016-10-14 10:20:30 707875582fcba352b4906a595ad89198d84711d8", -1, SQLITE_TRANSIENT); |
| 195698 | + sqlite3_result_text(pCtx, "fts5: 2016-10-26 16:05:10 ec9dab8054c71d112c68f58a45821b38c2a45677", -1, SQLITE_TRANSIENT); |
| 195602 | 195699 | } |
| 195603 | 195700 | |
| 195604 | 195701 | static int fts5Init(sqlite3 *db){ |
| 195605 | 195702 | static const sqlite3_module fts5Mod = { |
| 195606 | 195703 | /* iVersion */ 2, |
| 195607 | 195704 | |