Fossil SCM
Update the built-in SQLite to the first 3.32.0 beta.
Commit
17610f8d7307b361dc0afd98ab8c2467792bd50b630e825e00cc766b7453dcd0
Parent
ccf6a361f3f4bbd…
2 files changed
+402
-243
+3
-1
+402
-243
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -1162,11 +1162,11 @@ | ||
| 1162 | 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1163 | 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1164 | 1164 | */ |
| 1165 | 1165 | #define SQLITE_VERSION "3.32.0" |
| 1166 | 1166 | #define SQLITE_VERSION_NUMBER 3032000 |
| 1167 | -#define SQLITE_SOURCE_ID "2020-05-04 19:52:00 8eee591d3cb9fadfd5cac5543bd66ef9cb371a72d3ad3241fb3bfd67fb216eda" | |
| 1167 | +#define SQLITE_SOURCE_ID "2020-05-08 19:02:21 3a16c0ce4d8851f79f670d94786032c8007619154ece44647dc9cc5b1f9654ff" | |
| 1168 | 1168 | |
| 1169 | 1169 | /* |
| 1170 | 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1171 | 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1172 | 1172 | ** |
| @@ -1545,18 +1545,20 @@ | ||
| 1545 | 1545 | #define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8)) |
| 1546 | 1546 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 1547 | 1547 | #define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8)) |
| 1548 | 1548 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 1549 | 1549 | #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8)) |
| 1550 | +#define SQLITE_BUSY_TIMEOUT (SQLITE_BUSY | (3<<8)) | |
| 1550 | 1551 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 1551 | 1552 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 1552 | 1553 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 1553 | 1554 | #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) |
| 1554 | 1555 | #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */ |
| 1555 | 1556 | #define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8)) |
| 1556 | 1557 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 1557 | 1558 | #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8)) |
| 1559 | +#define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8)) | |
| 1558 | 1560 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 1559 | 1561 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 1560 | 1562 | #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) |
| 1561 | 1563 | #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) |
| 1562 | 1564 | #define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8)) |
| @@ -14535,11 +14537,10 @@ | ||
| 14535 | 14537 | typedef struct BusyHandler BusyHandler; |
| 14536 | 14538 | struct BusyHandler { |
| 14537 | 14539 | int (*xBusyHandler)(void *,int); /* The busy callback */ |
| 14538 | 14540 | void *pBusyArg; /* First arg to busy callback */ |
| 14539 | 14541 | int nBusy; /* Incremented with each busy call */ |
| 14540 | - u8 bExtraFileArg; /* Include sqlite3_file as callback arg */ | |
| 14541 | 14542 | }; |
| 14542 | 14543 | |
| 14543 | 14544 | /* |
| 14544 | 14545 | ** Name of the master database table. The master database table |
| 14545 | 14546 | ** is a special table that holds the names and attributes of all |
| @@ -15918,17 +15919,25 @@ | ||
| 15918 | 15919 | SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager); |
| 15919 | 15920 | SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager); |
| 15920 | 15921 | SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen); |
| 15921 | 15922 | SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3*); |
| 15922 | 15923 | # ifdef SQLITE_ENABLE_SNAPSHOT |
| 15923 | -SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot); | |
| 15924 | -SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot); | |
| 15924 | +SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager*, sqlite3_snapshot **ppSnapshot); | |
| 15925 | +SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager*, sqlite3_snapshot *pSnapshot); | |
| 15925 | 15926 | SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager); |
| 15926 | 15927 | SQLITE_PRIVATE int sqlite3PagerSnapshotCheck(Pager *pPager, sqlite3_snapshot *pSnapshot); |
| 15927 | 15928 | SQLITE_PRIVATE void sqlite3PagerSnapshotUnlock(Pager *pPager); |
| 15928 | 15929 | # endif |
| 15929 | 15930 | #endif |
| 15931 | + | |
| 15932 | +#if !defined(SQLITE_OMIT_WAL) && defined(SQLITE_ENABLE_SETLK_TIMEOUT) | |
| 15933 | +SQLITE_PRIVATE int sqlite3PagerWalWriteLock(Pager*, int); | |
| 15934 | +SQLITE_PRIVATE void sqlite3PagerWalDb(Pager*, sqlite3*); | |
| 15935 | +#else | |
| 15936 | +# define sqlite3PagerWalWriteLock(y,z) SQLITE_OK | |
| 15937 | +# define sqlite3PagerWalDb(x,y) | |
| 15938 | +#endif | |
| 15930 | 15939 | |
| 15931 | 15940 | #ifdef SQLITE_DIRECT_OVERFLOW_READ |
| 15932 | 15941 | SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno); |
| 15933 | 15942 | #endif |
| 15934 | 15943 | |
| @@ -15951,15 +15960,10 @@ | ||
| 15951 | 15960 | SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*); |
| 15952 | 15961 | SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*); |
| 15953 | 15962 | SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *); |
| 15954 | 15963 | SQLITE_PRIVATE void sqlite3PagerClearCache(Pager*); |
| 15955 | 15964 | SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *); |
| 15956 | -#ifdef SQLITE_ENABLE_SETLK_TIMEOUT | |
| 15957 | -SQLITE_PRIVATE void sqlite3PagerResetLockTimeout(Pager *pPager); | |
| 15958 | -#else | |
| 15959 | -# define sqlite3PagerResetLockTimeout(X) | |
| 15960 | -#endif | |
| 15961 | 15965 | |
| 15962 | 15966 | /* Functions used to truncate the database file. */ |
| 15963 | 15967 | SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno); |
| 15964 | 15968 | |
| 15965 | 15969 | SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16); |
| @@ -19935,11 +19939,11 @@ | ||
| 19935 | 19939 | SQLITE_PRIVATE void sqlite3RenameExprUnmap(Parse*, Expr*); |
| 19936 | 19940 | SQLITE_PRIVATE void sqlite3RenameExprlistUnmap(Parse*, ExprList*); |
| 19937 | 19941 | SQLITE_PRIVATE CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*); |
| 19938 | 19942 | SQLITE_PRIVATE char sqlite3AffinityType(const char*, Column*); |
| 19939 | 19943 | SQLITE_PRIVATE void sqlite3Analyze(Parse*, Token*, Token*); |
| 19940 | -SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler*, sqlite3_file*); | |
| 19944 | +SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler*); | |
| 19941 | 19945 | SQLITE_PRIVATE int sqlite3FindDb(sqlite3*, Token*); |
| 19942 | 19946 | SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *, const char *); |
| 19943 | 19947 | SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3*,int iDB); |
| 19944 | 19948 | SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3*,Index*); |
| 19945 | 19949 | SQLITE_PRIVATE void sqlite3DefaultRowEst(Index*); |
| @@ -27730,14 +27734,16 @@ | ||
| 27730 | 27734 | if( nDiff>0 && sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= |
| 27731 | 27735 | mem0.alarmThreshold-nDiff ){ |
| 27732 | 27736 | sqlite3MallocAlarm(nDiff); |
| 27733 | 27737 | } |
| 27734 | 27738 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 27739 | +#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT | |
| 27735 | 27740 | if( pNew==0 && mem0.alarmThreshold>0 ){ |
| 27736 | 27741 | sqlite3MallocAlarm((int)nBytes); |
| 27737 | 27742 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 27738 | 27743 | } |
| 27744 | +#endif | |
| 27739 | 27745 | if( pNew ){ |
| 27740 | 27746 | nNew = sqlite3MallocSize(pNew); |
| 27741 | 27747 | sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nNew-nOld); |
| 27742 | 27748 | } |
| 27743 | 27749 | sqlite3_mutex_leave(mem0.mutex); |
| @@ -34971,20 +34977,21 @@ | ||
| 34971 | 34977 | static int osSetPosixAdvisoryLock( |
| 34972 | 34978 | int h, /* The file descriptor on which to take the lock */ |
| 34973 | 34979 | struct flock *pLock, /* The description of the lock */ |
| 34974 | 34980 | unixFile *pFile /* Structure holding timeout value */ |
| 34975 | 34981 | ){ |
| 34982 | + int tm = pFile->iBusyTimeout; | |
| 34976 | 34983 | int rc = osFcntl(h,F_SETLK,pLock); |
| 34977 | - while( rc<0 && pFile->iBusyTimeout>0 ){ | |
| 34984 | + while( rc<0 && tm>0 ){ | |
| 34978 | 34985 | /* On systems that support some kind of blocking file lock with a timeout, |
| 34979 | 34986 | ** make appropriate changes here to invoke that blocking file lock. On |
| 34980 | 34987 | ** generic posix, however, there is no such API. So we simply try the |
| 34981 | 34988 | ** lock once every millisecond until either the timeout expires, or until |
| 34982 | 34989 | ** the lock is obtained. */ |
| 34983 | 34990 | usleep(1000); |
| 34984 | 34991 | rc = osFcntl(h,F_SETLK,pLock); |
| 34985 | - pFile->iBusyTimeout--; | |
| 34992 | + tm--; | |
| 34986 | 34993 | } |
| 34987 | 34994 | return rc; |
| 34988 | 34995 | } |
| 34989 | 34996 | #endif /* SQLITE_ENABLE_SETLK_TIMEOUT */ |
| 34990 | 34997 | |
| @@ -37722,17 +37729,24 @@ | ||
| 37722 | 37729 | |
| 37723 | 37730 | /* Locks are within range */ |
| 37724 | 37731 | assert( n>=1 && n<=SQLITE_SHM_NLOCK ); |
| 37725 | 37732 | |
| 37726 | 37733 | if( pShmNode->hShm>=0 ){ |
| 37734 | + int res; | |
| 37727 | 37735 | /* Initialize the locking parameters */ |
| 37728 | 37736 | f.l_type = lockType; |
| 37729 | 37737 | f.l_whence = SEEK_SET; |
| 37730 | 37738 | f.l_start = ofst; |
| 37731 | 37739 | f.l_len = n; |
| 37732 | - rc = osSetPosixAdvisoryLock(pShmNode->hShm, &f, pFile); | |
| 37733 | - rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY; | |
| 37740 | + res = osSetPosixAdvisoryLock(pShmNode->hShm, &f, pFile); | |
| 37741 | + if( res==-1 ){ | |
| 37742 | +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT | |
| 37743 | + rc = (pFile->iBusyTimeout ? SQLITE_BUSY_TIMEOUT : SQLITE_BUSY); | |
| 37744 | +#else | |
| 37745 | + rc = SQLITE_BUSY; | |
| 37746 | +#endif | |
| 37747 | + } | |
| 37734 | 37748 | } |
| 37735 | 37749 | |
| 37736 | 37750 | /* Update the global lock state and do debug tracing */ |
| 37737 | 37751 | #ifdef SQLITE_DEBUG |
| 37738 | 37752 | { u16 mask; |
| @@ -38225,26 +38239,27 @@ | ||
| 38225 | 38239 | || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE) ); |
| 38226 | 38240 | assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 ); |
| 38227 | 38241 | assert( pShmNode->hShm>=0 || pDbFd->pInode->bProcessLock==1 ); |
| 38228 | 38242 | assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 ); |
| 38229 | 38243 | |
| 38230 | - /* Check that, if this to be a blocking lock, that locks have been | |
| 38231 | - ** obtained in the following order. | |
| 38244 | + /* Check that, if this to be a blocking lock, no locks that occur later | |
| 38245 | + ** in the following list than the lock being obtained are already held: | |
| 38232 | 38246 | ** |
| 38233 | 38247 | ** 1. Checkpointer lock (ofst==1). |
| 38234 | - ** 2. Recover lock (ofst==2). | |
| 38248 | + ** 2. Write lock (ofst==0). | |
| 38235 | 38249 | ** 3. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK). |
| 38236 | - ** 4. Write lock (ofst==0). | |
| 38237 | 38250 | ** |
| 38238 | 38251 | ** In other words, if this is a blocking lock, none of the locks that |
| 38239 | 38252 | ** occur later in the above list than the lock being obtained may be |
| 38240 | 38253 | ** held. */ |
| 38241 | 38254 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 38242 | - assert( pDbFd->iBusyTimeout==0 | |
| 38243 | - || (flags & SQLITE_SHM_UNLOCK) || ofst==0 | |
| 38244 | - || ((p->exclMask|p->sharedMask)&~((1<<ofst)-2))==0 | |
| 38245 | - ); | |
| 38255 | + assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || ( | |
| 38256 | + (ofst!=2) /* not RECOVER */ | |
| 38257 | + && (ofst!=1 || (p->exclMask|p->sharedMask)==0) | |
| 38258 | + && (ofst!=0 || (p->exclMask|p->sharedMask)<3) | |
| 38259 | + && (ofst<3 || (p->exclMask|p->sharedMask)<(1<<ofst)) | |
| 38260 | + )); | |
| 38246 | 38261 | #endif |
| 38247 | 38262 | |
| 38248 | 38263 | mask = (1<<(ofst+n)) - (1<<ofst); |
| 38249 | 38264 | assert( n>1 || mask==(1<<ofst) ); |
| 38250 | 38265 | sqlite3_mutex_enter(pShmNode->pShmMutex); |
| @@ -51548,10 +51563,15 @@ | ||
| 51548 | 51563 | SQLITE_PRIVATE int sqlite3WalFramesize(Wal *pWal); |
| 51549 | 51564 | #endif |
| 51550 | 51565 | |
| 51551 | 51566 | /* Return the sqlite3_file object for the WAL file */ |
| 51552 | 51567 | SQLITE_PRIVATE sqlite3_file *sqlite3WalFile(Wal *pWal); |
| 51568 | + | |
| 51569 | +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT | |
| 51570 | +SQLITE_PRIVATE int sqlite3WalWriteLock(Wal *pWal, int bLock); | |
| 51571 | +SQLITE_PRIVATE void sqlite3WalDb(Wal *pWal, sqlite3 *db); | |
| 51572 | +#endif | |
| 51553 | 51573 | |
| 51554 | 51574 | #endif /* ifndef SQLITE_OMIT_WAL */ |
| 51555 | 51575 | #endif /* SQLITE_WAL_H */ |
| 51556 | 51576 | |
| 51557 | 51577 | /************** End of wal.h *************************************************/ |
| @@ -57238,11 +57258,10 @@ | ||
| 57238 | 57258 | Pager *pPager; |
| 57239 | 57259 | assert( pPg!=0 ); |
| 57240 | 57260 | assert( pPg->pgno==1 ); |
| 57241 | 57261 | assert( (pPg->flags & PGHDR_MMAP)==0 ); /* Page1 is never memory mapped */ |
| 57242 | 57262 | pPager = pPg->pPager; |
| 57243 | - sqlite3PagerResetLockTimeout(pPager); | |
| 57244 | 57263 | sqlite3PcacheRelease(pPg); |
| 57245 | 57264 | pagerUnlockIfUnused(pPager); |
| 57246 | 57265 | } |
| 57247 | 57266 | |
| 57248 | 57267 | /* |
| @@ -58531,20 +58550,10 @@ | ||
| 58531 | 58550 | */ |
| 58532 | 58551 | SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager *pPager){ |
| 58533 | 58552 | return pPager->fd; |
| 58534 | 58553 | } |
| 58535 | 58554 | |
| 58536 | -#ifdef SQLITE_ENABLE_SETLK_TIMEOUT | |
| 58537 | -/* | |
| 58538 | -** Reset the lock timeout for pager. | |
| 58539 | -*/ | |
| 58540 | -SQLITE_PRIVATE void sqlite3PagerResetLockTimeout(Pager *pPager){ | |
| 58541 | - int x = 0; | |
| 58542 | - sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_LOCK_TIMEOUT, &x); | |
| 58543 | -} | |
| 58544 | -#endif | |
| 58545 | - | |
| 58546 | 58555 | /* |
| 58547 | 58556 | ** Return the file handle for the journal file (if it exists). |
| 58548 | 58557 | ** This will be either the rollback journal or the WAL file. |
| 58549 | 58558 | */ |
| 58550 | 58559 | SQLITE_PRIVATE sqlite3_file *sqlite3PagerJrnlFile(Pager *pPager){ |
| @@ -58954,11 +58963,10 @@ | ||
| 58954 | 58963 | (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler), |
| 58955 | 58964 | pPager->pBusyHandlerArg, |
| 58956 | 58965 | pPager->walSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace, |
| 58957 | 58966 | pnLog, pnCkpt |
| 58958 | 58967 | ); |
| 58959 | - sqlite3PagerResetLockTimeout(pPager); | |
| 58960 | 58968 | } |
| 58961 | 58969 | return rc; |
| 58962 | 58970 | } |
| 58963 | 58971 | |
| 58964 | 58972 | SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager){ |
| @@ -59119,11 +59127,35 @@ | ||
| 59119 | 59127 | } |
| 59120 | 59128 | } |
| 59121 | 59129 | return rc; |
| 59122 | 59130 | } |
| 59123 | 59131 | |
| 59132 | +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT | |
| 59133 | +/* | |
| 59134 | +** If pager pPager is a wal-mode database not in exclusive locking mode, | |
| 59135 | +** invoke the sqlite3WalWriteLock() function on the associated Wal object | |
| 59136 | +** with the same db and bLock parameters as were passed to this function. | |
| 59137 | +** Return an SQLite error code if an error occurs, or SQLITE_OK otherwise. | |
| 59138 | +*/ | |
| 59139 | +SQLITE_PRIVATE int sqlite3PagerWalWriteLock(Pager *pPager, int bLock){ | |
| 59140 | + int rc = SQLITE_OK; | |
| 59141 | + if( pagerUseWal(pPager) && pPager->exclusiveMode==0 ){ | |
| 59142 | + rc = sqlite3WalWriteLock(pPager->pWal, bLock); | |
| 59143 | + } | |
| 59144 | + return rc; | |
| 59145 | +} | |
| 59124 | 59146 | |
| 59147 | +/* | |
| 59148 | +** Set the database handle used by the wal layer to determine if | |
| 59149 | +** blocking locks are required. | |
| 59150 | +*/ | |
| 59151 | +SQLITE_PRIVATE void sqlite3PagerWalDb(Pager *pPager, sqlite3 *db){ | |
| 59152 | + if( pagerUseWal(pPager) ){ | |
| 59153 | + sqlite3WalDb(pPager->pWal, db); | |
| 59154 | + } | |
| 59155 | +} | |
| 59156 | +#endif | |
| 59125 | 59157 | |
| 59126 | 59158 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 59127 | 59159 | /* |
| 59128 | 59160 | ** If this is a WAL database, obtain a snapshot handle for the snapshot |
| 59129 | 59161 | ** currently open. Otherwise, return an error. |
| @@ -59139,11 +59171,14 @@ | ||
| 59139 | 59171 | /* |
| 59140 | 59172 | ** If this is a WAL database, store a pointer to pSnapshot. Next time a |
| 59141 | 59173 | ** read transaction is opened, attempt to read from the snapshot it |
| 59142 | 59174 | ** identifies. If this is not a WAL database, return an error. |
| 59143 | 59175 | */ |
| 59144 | -SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot){ | |
| 59176 | +SQLITE_PRIVATE int sqlite3PagerSnapshotOpen( | |
| 59177 | + Pager *pPager, | |
| 59178 | + sqlite3_snapshot *pSnapshot | |
| 59179 | +){ | |
| 59145 | 59180 | int rc = SQLITE_OK; |
| 59146 | 59181 | if( pPager->pWal ){ |
| 59147 | 59182 | sqlite3WalSnapshotOpen(pPager->pWal, pSnapshot); |
| 59148 | 59183 | }else{ |
| 59149 | 59184 | rc = SQLITE_ERROR; |
| @@ -59684,10 +59719,13 @@ | ||
| 59684 | 59719 | u8 lockError; /* True if a locking error has occurred */ |
| 59685 | 59720 | #endif |
| 59686 | 59721 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 59687 | 59722 | WalIndexHdr *pSnapshot; /* Start transaction here if not NULL */ |
| 59688 | 59723 | #endif |
| 59724 | +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT | |
| 59725 | + sqlite3 *db; | |
| 59726 | +#endif | |
| 59689 | 59727 | }; |
| 59690 | 59728 | |
| 59691 | 59729 | /* |
| 59692 | 59730 | ** Candidate values for Wal.exclusiveMode. |
| 59693 | 59731 | */ |
| @@ -60057,11 +60095,11 @@ | ||
| 60057 | 60095 | if( pWal->exclusiveMode ) return SQLITE_OK; |
| 60058 | 60096 | rc = sqlite3OsShmLock(pWal->pDbFd, lockIdx, 1, |
| 60059 | 60097 | SQLITE_SHM_LOCK | SQLITE_SHM_SHARED); |
| 60060 | 60098 | WALTRACE(("WAL%p: acquire SHARED-%s %s\n", pWal, |
| 60061 | 60099 | walLockName(lockIdx), rc ? "failed" : "ok")); |
| 60062 | - VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && rc!=SQLITE_BUSY); ) | |
| 60100 | + VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && (rc&0xFF)!=SQLITE_BUSY); ) | |
| 60063 | 60101 | return rc; |
| 60064 | 60102 | } |
| 60065 | 60103 | static void walUnlockShared(Wal *pWal, int lockIdx){ |
| 60066 | 60104 | if( pWal->exclusiveMode ) return; |
| 60067 | 60105 | (void)sqlite3OsShmLock(pWal->pDbFd, lockIdx, 1, |
| @@ -60073,11 +60111,11 @@ | ||
| 60073 | 60111 | if( pWal->exclusiveMode ) return SQLITE_OK; |
| 60074 | 60112 | rc = sqlite3OsShmLock(pWal->pDbFd, lockIdx, n, |
| 60075 | 60113 | SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE); |
| 60076 | 60114 | WALTRACE(("WAL%p: acquire EXCLUSIVE-%s cnt=%d %s\n", pWal, |
| 60077 | 60115 | walLockName(lockIdx), n, rc ? "failed" : "ok")); |
| 60078 | - VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && rc!=SQLITE_BUSY); ) | |
| 60116 | + VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && (rc&0xFF)!=SQLITE_BUSY); ) | |
| 60079 | 60117 | return rc; |
| 60080 | 60118 | } |
| 60081 | 60119 | static void walUnlockExclusive(Wal *pWal, int lockIdx, int n){ |
| 60082 | 60120 | if( pWal->exclusiveMode ) return; |
| 60083 | 60121 | (void)sqlite3OsShmLock(pWal->pDbFd, lockIdx, n, |
| @@ -60345,15 +60383,10 @@ | ||
| 60345 | 60383 | int rc; /* Return Code */ |
| 60346 | 60384 | i64 nSize; /* Size of log file */ |
| 60347 | 60385 | u32 aFrameCksum[2] = {0, 0}; |
| 60348 | 60386 | int iLock; /* Lock offset to lock for checkpoint */ |
| 60349 | 60387 | |
| 60350 | -#ifdef SQLITE_ENABLE_SETLK_TIMEOUT | |
| 60351 | - int tmout = 0; | |
| 60352 | - sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout); | |
| 60353 | -#endif | |
| 60354 | - | |
| 60355 | 60388 | /* Obtain an exclusive lock on all byte in the locking range not already |
| 60356 | 60389 | ** locked by the caller. The caller is guaranteed to have locked the |
| 60357 | 60390 | ** WAL_WRITE_LOCK byte, and may have also locked the WAL_CKPT_LOCK byte. |
| 60358 | 60391 | ** If successful, the same bytes that are locked here are unlocked before |
| 60359 | 60392 | ** this function returns. |
| @@ -60897,10 +60930,93 @@ | ||
| 60897 | 60930 | p = 0; |
| 60898 | 60931 | } |
| 60899 | 60932 | *pp = p; |
| 60900 | 60933 | return rc; |
| 60901 | 60934 | } |
| 60935 | + | |
| 60936 | +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT | |
| 60937 | +/* | |
| 60938 | +** Attempt to enable blocking locks. Blocking locks are enabled only if (a) | |
| 60939 | +** they are supported by the VFS, and (b) the database handle is configured | |
| 60940 | +** with a busy-timeout. Return 1 if blocking locks are successfully enabled, | |
| 60941 | +** or 0 otherwise. | |
| 60942 | +*/ | |
| 60943 | +static int walEnableBlocking(Wal *pWal){ | |
| 60944 | + int res = 0; | |
| 60945 | + if( pWal->db ){ | |
| 60946 | + int tmout = pWal->db->busyTimeout; | |
| 60947 | + if( tmout ){ | |
| 60948 | + int rc; | |
| 60949 | + rc = sqlite3OsFileControl( | |
| 60950 | + pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout | |
| 60951 | + ); | |
| 60952 | + res = (rc==SQLITE_OK); | |
| 60953 | + } | |
| 60954 | + } | |
| 60955 | + return res; | |
| 60956 | +} | |
| 60957 | + | |
| 60958 | +/* | |
| 60959 | +** Disable blocking locks. | |
| 60960 | +*/ | |
| 60961 | +static void walDisableBlocking(Wal *pWal){ | |
| 60962 | + int tmout = 0; | |
| 60963 | + sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout); | |
| 60964 | +} | |
| 60965 | + | |
| 60966 | +/* | |
| 60967 | +** If parameter bLock is true, attempt to enable blocking locks, take | |
| 60968 | +** the WRITER lock, and then disable blocking locks. If blocking locks | |
| 60969 | +** cannot be enabled, no attempt to obtain the WRITER lock is made. Return | |
| 60970 | +** an SQLite error code if an error occurs, or SQLITE_OK otherwise. It is not | |
| 60971 | +** an error if blocking locks can not be enabled. | |
| 60972 | +** | |
| 60973 | +** If the bLock parameter is false and the WRITER lock is held, release it. | |
| 60974 | +*/ | |
| 60975 | +SQLITE_PRIVATE int sqlite3WalWriteLock(Wal *pWal, int bLock){ | |
| 60976 | + int rc = SQLITE_OK; | |
| 60977 | + assert( pWal->readLock<0 || bLock==0 ); | |
| 60978 | + if( bLock ){ | |
| 60979 | + assert( pWal->db ); | |
| 60980 | + if( walEnableBlocking(pWal) ){ | |
| 60981 | + rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1); | |
| 60982 | + if( rc==SQLITE_OK ){ | |
| 60983 | + pWal->writeLock = 1; | |
| 60984 | + } | |
| 60985 | + walDisableBlocking(pWal); | |
| 60986 | + } | |
| 60987 | + }else if( pWal->writeLock ){ | |
| 60988 | + walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1); | |
| 60989 | + pWal->writeLock = 0; | |
| 60990 | + } | |
| 60991 | + return rc; | |
| 60992 | +} | |
| 60993 | + | |
| 60994 | +/* | |
| 60995 | +** Set the database handle used to determine if blocking locks are required. | |
| 60996 | +*/ | |
| 60997 | +SQLITE_PRIVATE void sqlite3WalDb(Wal *pWal, sqlite3 *db){ | |
| 60998 | + pWal->db = db; | |
| 60999 | +} | |
| 61000 | + | |
| 61001 | +/* | |
| 61002 | +** Take an exclusive WRITE lock. Blocking if so configured. | |
| 61003 | +*/ | |
| 61004 | +static int walLockWriter(Wal *pWal){ | |
| 61005 | + int rc; | |
| 61006 | + walEnableBlocking(pWal); | |
| 61007 | + rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1); | |
| 61008 | + walDisableBlocking(pWal); | |
| 61009 | + return rc; | |
| 61010 | +} | |
| 61011 | +#else | |
| 61012 | +# define walEnableBlocking(x) 0 | |
| 61013 | +# define walDisableBlocking(x) | |
| 61014 | +# define walLockWriter(pWal) walLockExclusive((pWal), WAL_WRITE_LOCK, 1) | |
| 61015 | +# define sqlite3WalDb(pWal, db) | |
| 61016 | +#endif /* ifdef SQLITE_ENABLE_SETLK_TIMEOUT */ | |
| 61017 | + | |
| 60902 | 61018 | |
| 60903 | 61019 | /* |
| 60904 | 61020 | ** Attempt to obtain the exclusive WAL lock defined by parameters lockIdx and |
| 60905 | 61021 | ** n. If the attempt fails and parameter xBusy is not NULL, then it is a |
| 60906 | 61022 | ** busy-handler function. Invoke it and retry the lock until either the |
| @@ -60915,10 +61031,16 @@ | ||
| 60915 | 61031 | ){ |
| 60916 | 61032 | int rc; |
| 60917 | 61033 | do { |
| 60918 | 61034 | rc = walLockExclusive(pWal, lockIdx, n); |
| 60919 | 61035 | }while( xBusy && rc==SQLITE_BUSY && xBusy(pBusyArg) ); |
| 61036 | +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT | |
| 61037 | + if( rc==SQLITE_BUSY_TIMEOUT ){ | |
| 61038 | + walDisableBlocking(pWal); | |
| 61039 | + rc = SQLITE_BUSY; | |
| 61040 | + } | |
| 61041 | +#endif | |
| 60920 | 61042 | return rc; |
| 60921 | 61043 | } |
| 60922 | 61044 | |
| 60923 | 61045 | /* |
| 60924 | 61046 | ** The cache of the wal-index header must be valid to call this function. |
| @@ -61394,32 +61516,36 @@ | ||
| 61394 | 61516 | badHdr = (page0 ? walIndexTryHdr(pWal, pChanged) : 1); |
| 61395 | 61517 | |
| 61396 | 61518 | /* If the first attempt failed, it might have been due to a race |
| 61397 | 61519 | ** with a writer. So get a WRITE lock and try again. |
| 61398 | 61520 | */ |
| 61399 | - assert( badHdr==0 || pWal->writeLock==0 ); | |
| 61400 | 61521 | if( badHdr ){ |
| 61401 | 61522 | if( pWal->bShmUnreliable==0 && (pWal->readOnly & WAL_SHM_RDONLY) ){ |
| 61402 | 61523 | if( SQLITE_OK==(rc = walLockShared(pWal, WAL_WRITE_LOCK)) ){ |
| 61403 | 61524 | walUnlockShared(pWal, WAL_WRITE_LOCK); |
| 61404 | 61525 | rc = SQLITE_READONLY_RECOVERY; |
| 61405 | 61526 | } |
| 61406 | - }else if( SQLITE_OK==(rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1)) ){ | |
| 61407 | - pWal->writeLock = 1; | |
| 61408 | - if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){ | |
| 61409 | - badHdr = walIndexTryHdr(pWal, pChanged); | |
| 61410 | - if( badHdr ){ | |
| 61411 | - /* If the wal-index header is still malformed even while holding | |
| 61412 | - ** a WRITE lock, it can only mean that the header is corrupted and | |
| 61413 | - ** needs to be reconstructed. So run recovery to do exactly that. | |
| 61414 | - */ | |
| 61415 | - rc = walIndexRecover(pWal); | |
| 61416 | - *pChanged = 1; | |
| 61417 | - } | |
| 61418 | - } | |
| 61419 | - pWal->writeLock = 0; | |
| 61420 | - walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1); | |
| 61527 | + }else{ | |
| 61528 | + int bWriteLock = pWal->writeLock; | |
| 61529 | + if( bWriteLock || SQLITE_OK==(rc = walLockWriter(pWal)) ){ | |
| 61530 | + pWal->writeLock = 1; | |
| 61531 | + if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){ | |
| 61532 | + badHdr = walIndexTryHdr(pWal, pChanged); | |
| 61533 | + if( badHdr ){ | |
| 61534 | + /* If the wal-index header is still malformed even while holding | |
| 61535 | + ** a WRITE lock, it can only mean that the header is corrupted and | |
| 61536 | + ** needs to be reconstructed. So run recovery to do exactly that. | |
| 61537 | + */ | |
| 61538 | + rc = walIndexRecover(pWal); | |
| 61539 | + *pChanged = 1; | |
| 61540 | + } | |
| 61541 | + } | |
| 61542 | + if( bWriteLock==0 ){ | |
| 61543 | + pWal->writeLock = 0; | |
| 61544 | + walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1); | |
| 61545 | + } | |
| 61546 | + } | |
| 61421 | 61547 | } |
| 61422 | 61548 | } |
| 61423 | 61549 | |
| 61424 | 61550 | /* If the header is read successfully, check the version number to make |
| 61425 | 61551 | ** sure the wal-index was not constructed with some future format that |
| @@ -61967,26 +62093,38 @@ | ||
| 61967 | 62093 | ** needs to be flushed. |
| 61968 | 62094 | */ |
| 61969 | 62095 | SQLITE_PRIVATE int sqlite3WalBeginReadTransaction(Wal *pWal, int *pChanged){ |
| 61970 | 62096 | int rc; /* Return code */ |
| 61971 | 62097 | int cnt = 0; /* Number of TryBeginRead attempts */ |
| 61972 | -#ifdef SQLITE_ENABLE_SETLK_TIMEOUT | |
| 61973 | - int tmout = 0; | |
| 61974 | -#endif | |
| 62098 | + | |
| 62099 | + assert( pWal->ckptLock==0 ); | |
| 61975 | 62100 | |
| 61976 | 62101 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 61977 | 62102 | int bChanged = 0; |
| 61978 | 62103 | WalIndexHdr *pSnapshot = pWal->pSnapshot; |
| 61979 | - if( pSnapshot && memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){ | |
| 61980 | - bChanged = 1; | |
| 61981 | - } | |
| 61982 | -#endif | |
| 61983 | - | |
| 61984 | -#ifdef SQLITE_ENABLE_SETLK_TIMEOUT | |
| 61985 | - /* Disable blocking locks. They are not useful when trying to open a | |
| 61986 | - ** read-transaction, and blocking may cause deadlock anyway. */ | |
| 61987 | - sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout); | |
| 62104 | + if( pSnapshot ){ | |
| 62105 | + if( memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){ | |
| 62106 | + bChanged = 1; | |
| 62107 | + } | |
| 62108 | + | |
| 62109 | + /* It is possible that there is a checkpointer thread running | |
| 62110 | + ** concurrent with this code. If this is the case, it may be that the | |
| 62111 | + ** checkpointer has already determined that it will checkpoint | |
| 62112 | + ** snapshot X, where X is later in the wal file than pSnapshot, but | |
| 62113 | + ** has not yet set the pInfo->nBackfillAttempted variable to indicate | |
| 62114 | + ** its intent. To avoid the race condition this leads to, ensure that | |
| 62115 | + ** there is no checkpointer process by taking a shared CKPT lock | |
| 62116 | + ** before checking pInfo->nBackfillAttempted. */ | |
| 62117 | + (void)walEnableBlocking(pWal); | |
| 62118 | + rc = walLockShared(pWal, WAL_CKPT_LOCK); | |
| 62119 | + walDisableBlocking(pWal); | |
| 62120 | + | |
| 62121 | + if( rc!=SQLITE_OK ){ | |
| 62122 | + return rc; | |
| 62123 | + } | |
| 62124 | + pWal->ckptLock = 1; | |
| 62125 | + } | |
| 61988 | 62126 | #endif |
| 61989 | 62127 | |
| 61990 | 62128 | do{ |
| 61991 | 62129 | rc = walTryBeginRead(pWal, pChanged, 0, ++cnt); |
| 61992 | 62130 | }while( rc==WAL_RETRY ); |
| @@ -61993,20 +62131,10 @@ | ||
| 61993 | 62131 | testcase( (rc&0xff)==SQLITE_BUSY ); |
| 61994 | 62132 | testcase( (rc&0xff)==SQLITE_IOERR ); |
| 61995 | 62133 | testcase( rc==SQLITE_PROTOCOL ); |
| 61996 | 62134 | testcase( rc==SQLITE_OK ); |
| 61997 | 62135 | |
| 61998 | -#ifdef SQLITE_ENABLE_SETLK_TIMEOUT | |
| 61999 | - /* If they were disabled earlier and the read-transaction has been | |
| 62000 | - ** successfully opened, re-enable blocking locks. This is because the | |
| 62001 | - ** connection may attempt to upgrade to a write-transaction, which does | |
| 62002 | - ** benefit from using blocking locks. */ | |
| 62003 | - if( rc==SQLITE_OK ){ | |
| 62004 | - sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout); | |
| 62005 | - } | |
| 62006 | -#endif | |
| 62007 | - | |
| 62008 | 62136 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 62009 | 62137 | if( rc==SQLITE_OK ){ |
| 62010 | 62138 | if( pSnapshot && memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){ |
| 62011 | 62139 | /* At this point the client has a lock on an aReadMark[] slot holding |
| 62012 | 62140 | ** a value equal to or smaller than pSnapshot->mxFrame, but pWal->hdr |
| @@ -62024,52 +62152,46 @@ | ||
| 62024 | 62152 | volatile WalCkptInfo *pInfo = walCkptInfo(pWal); |
| 62025 | 62153 | |
| 62026 | 62154 | assert( pWal->readLock>0 || pWal->hdr.mxFrame==0 ); |
| 62027 | 62155 | assert( pInfo->aReadMark[pWal->readLock]<=pSnapshot->mxFrame ); |
| 62028 | 62156 | |
| 62029 | - /* It is possible that there is a checkpointer thread running | |
| 62030 | - ** concurrent with this code. If this is the case, it may be that the | |
| 62031 | - ** checkpointer has already determined that it will checkpoint | |
| 62032 | - ** snapshot X, where X is later in the wal file than pSnapshot, but | |
| 62033 | - ** has not yet set the pInfo->nBackfillAttempted variable to indicate | |
| 62034 | - ** its intent. To avoid the race condition this leads to, ensure that | |
| 62035 | - ** there is no checkpointer process by taking a shared CKPT lock | |
| 62036 | - ** before checking pInfo->nBackfillAttempted. | |
| 62037 | - ** | |
| 62038 | - ** TODO: Does the aReadMark[] lock prevent a checkpointer from doing | |
| 62039 | - ** this already? | |
| 62040 | - */ | |
| 62041 | - rc = walLockShared(pWal, WAL_CKPT_LOCK); | |
| 62042 | - | |
| 62043 | - if( rc==SQLITE_OK ){ | |
| 62044 | - /* Check that the wal file has not been wrapped. Assuming that it has | |
| 62045 | - ** not, also check that no checkpointer has attempted to checkpoint any | |
| 62046 | - ** frames beyond pSnapshot->mxFrame. If either of these conditions are | |
| 62047 | - ** true, return SQLITE_ERROR_SNAPSHOT. Otherwise, overwrite pWal->hdr | |
| 62048 | - ** with *pSnapshot and set *pChanged as appropriate for opening the | |
| 62049 | - ** snapshot. */ | |
| 62050 | - if( !memcmp(pSnapshot->aSalt, pWal->hdr.aSalt, sizeof(pWal->hdr.aSalt)) | |
| 62051 | - && pSnapshot->mxFrame>=pInfo->nBackfillAttempted | |
| 62052 | - ){ | |
| 62053 | - assert( pWal->readLock>0 ); | |
| 62054 | - memcpy(&pWal->hdr, pSnapshot, sizeof(WalIndexHdr)); | |
| 62055 | - *pChanged = bChanged; | |
| 62056 | - }else{ | |
| 62057 | - rc = SQLITE_ERROR_SNAPSHOT; | |
| 62058 | - } | |
| 62059 | - | |
| 62060 | - /* Release the shared CKPT lock obtained above. */ | |
| 62061 | - walUnlockShared(pWal, WAL_CKPT_LOCK); | |
| 62062 | - pWal->minFrame = 1; | |
| 62063 | - } | |
| 62064 | - | |
| 62157 | + /* Check that the wal file has not been wrapped. Assuming that it has | |
| 62158 | + ** not, also check that no checkpointer has attempted to checkpoint any | |
| 62159 | + ** frames beyond pSnapshot->mxFrame. If either of these conditions are | |
| 62160 | + ** true, return SQLITE_ERROR_SNAPSHOT. Otherwise, overwrite pWal->hdr | |
| 62161 | + ** with *pSnapshot and set *pChanged as appropriate for opening the | |
| 62162 | + ** snapshot. */ | |
| 62163 | + if( !memcmp(pSnapshot->aSalt, pWal->hdr.aSalt, sizeof(pWal->hdr.aSalt)) | |
| 62164 | + && pSnapshot->mxFrame>=pInfo->nBackfillAttempted | |
| 62165 | + ){ | |
| 62166 | + assert( pWal->readLock>0 ); | |
| 62167 | + memcpy(&pWal->hdr, pSnapshot, sizeof(WalIndexHdr)); | |
| 62168 | + *pChanged = bChanged; | |
| 62169 | + }else{ | |
| 62170 | + rc = SQLITE_ERROR_SNAPSHOT; | |
| 62171 | + } | |
| 62172 | + | |
| 62173 | + /* A client using a non-current snapshot may not ignore any frames | |
| 62174 | + ** from the start of the wal file. This is because, for a system | |
| 62175 | + ** where (minFrame < iSnapshot < maxFrame), a checkpointer may | |
| 62176 | + ** have omitted to checkpoint a frame earlier than minFrame in | |
| 62177 | + ** the file because there exists a frame after iSnapshot that | |
| 62178 | + ** is the same database page. */ | |
| 62179 | + pWal->minFrame = 1; | |
| 62065 | 62180 | |
| 62066 | 62181 | if( rc!=SQLITE_OK ){ |
| 62067 | 62182 | sqlite3WalEndReadTransaction(pWal); |
| 62068 | 62183 | } |
| 62069 | 62184 | } |
| 62070 | 62185 | } |
| 62186 | + | |
| 62187 | + /* Release the shared CKPT lock obtained above. */ | |
| 62188 | + if( pWal->ckptLock ){ | |
| 62189 | + assert( pSnapshot ); | |
| 62190 | + walUnlockShared(pWal, WAL_CKPT_LOCK); | |
| 62191 | + pWal->ckptLock = 0; | |
| 62192 | + } | |
| 62071 | 62193 | #endif |
| 62072 | 62194 | return rc; |
| 62073 | 62195 | } |
| 62074 | 62196 | |
| 62075 | 62197 | /* |
| @@ -62235,10 +62357,20 @@ | ||
| 62235 | 62357 | ** |
| 62236 | 62358 | ** There can only be a single writer active at a time. |
| 62237 | 62359 | */ |
| 62238 | 62360 | SQLITE_PRIVATE int sqlite3WalBeginWriteTransaction(Wal *pWal){ |
| 62239 | 62361 | int rc; |
| 62362 | + | |
| 62363 | +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT | |
| 62364 | + /* If the write-lock is already held, then it was obtained before the | |
| 62365 | + ** read-transaction was even opened, making this call a no-op. | |
| 62366 | + ** Return early. */ | |
| 62367 | + if( pWal->writeLock ){ | |
| 62368 | + assert( !memcmp(&pWal->hdr,(void *)walIndexHdr(pWal),sizeof(WalIndexHdr)) ); | |
| 62369 | + return SQLITE_OK; | |
| 62370 | + } | |
| 62371 | +#endif | |
| 62240 | 62372 | |
| 62241 | 62373 | /* Cannot start a write transaction without first holding a read |
| 62242 | 62374 | ** transaction. */ |
| 62243 | 62375 | assert( pWal->readLock>=0 ); |
| 62244 | 62376 | assert( pWal->writeLock==0 && pWal->iReCksum==0 ); |
| @@ -62811,50 +62943,57 @@ | ||
| 62811 | 62943 | ** in the SQLITE_CHECKPOINT_PASSIVE mode. */ |
| 62812 | 62944 | assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 ); |
| 62813 | 62945 | |
| 62814 | 62946 | if( pWal->readOnly ) return SQLITE_READONLY; |
| 62815 | 62947 | WALTRACE(("WAL%p: checkpoint begins\n", pWal)); |
| 62948 | + | |
| 62949 | + /* Enable blocking locks, if possible. If blocking locks are successfully | |
| 62950 | + ** enabled, set xBusy2=0 so that the busy-handler is never invoked. */ | |
| 62951 | + sqlite3WalDb(pWal, db); | |
| 62952 | + (void)walEnableBlocking(pWal); | |
| 62816 | 62953 | |
| 62817 | 62954 | /* IMPLEMENTATION-OF: R-62028-47212 All calls obtain an exclusive |
| 62818 | - ** "checkpoint" lock on the database file. */ | |
| 62955 | + ** "checkpoint" lock on the database file. | |
| 62956 | + ** EVIDENCE-OF: R-10421-19736 If any other process is running a | |
| 62957 | + ** checkpoint operation at the same time, the lock cannot be obtained and | |
| 62958 | + ** SQLITE_BUSY is returned. | |
| 62959 | + ** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured, | |
| 62960 | + ** it will not be invoked in this case. | |
| 62961 | + */ | |
| 62819 | 62962 | rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1); |
| 62820 | - if( rc ){ | |
| 62821 | - /* EVIDENCE-OF: R-10421-19736 If any other process is running a | |
| 62822 | - ** checkpoint operation at the same time, the lock cannot be obtained and | |
| 62823 | - ** SQLITE_BUSY is returned. | |
| 62824 | - ** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured, | |
| 62825 | - ** it will not be invoked in this case. | |
| 62826 | - */ | |
| 62827 | - testcase( rc==SQLITE_BUSY ); | |
| 62828 | - testcase( xBusy!=0 ); | |
| 62829 | - return rc; | |
| 62830 | - } | |
| 62831 | - pWal->ckptLock = 1; | |
| 62832 | - | |
| 62833 | - /* IMPLEMENTATION-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART and | |
| 62834 | - ** TRUNCATE modes also obtain the exclusive "writer" lock on the database | |
| 62835 | - ** file. | |
| 62836 | - ** | |
| 62837 | - ** EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained | |
| 62838 | - ** immediately, and a busy-handler is configured, it is invoked and the | |
| 62839 | - ** writer lock retried until either the busy-handler returns 0 or the | |
| 62840 | - ** lock is successfully obtained. | |
| 62841 | - */ | |
| 62842 | - if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){ | |
| 62843 | - rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_WRITE_LOCK, 1); | |
| 62844 | - if( rc==SQLITE_OK ){ | |
| 62845 | - pWal->writeLock = 1; | |
| 62846 | - }else if( rc==SQLITE_BUSY ){ | |
| 62847 | - eMode2 = SQLITE_CHECKPOINT_PASSIVE; | |
| 62848 | - xBusy2 = 0; | |
| 62849 | - rc = SQLITE_OK; | |
| 62850 | - } | |
| 62851 | - } | |
| 62963 | + testcase( rc==SQLITE_BUSY ); | |
| 62964 | + testcase( rc!=SQLITE_OK && xBusy2!=0 ); | |
| 62965 | + if( rc==SQLITE_OK ){ | |
| 62966 | + pWal->ckptLock = 1; | |
| 62967 | + | |
| 62968 | + /* IMPLEMENTATION-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART and | |
| 62969 | + ** TRUNCATE modes also obtain the exclusive "writer" lock on the database | |
| 62970 | + ** file. | |
| 62971 | + ** | |
| 62972 | + ** EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained | |
| 62973 | + ** immediately, and a busy-handler is configured, it is invoked and the | |
| 62974 | + ** writer lock retried until either the busy-handler returns 0 or the | |
| 62975 | + ** lock is successfully obtained. | |
| 62976 | + */ | |
| 62977 | + if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){ | |
| 62978 | + rc = walBusyLock(pWal, xBusy2, pBusyArg, WAL_WRITE_LOCK, 1); | |
| 62979 | + if( rc==SQLITE_OK ){ | |
| 62980 | + pWal->writeLock = 1; | |
| 62981 | + }else if( rc==SQLITE_BUSY ){ | |
| 62982 | + eMode2 = SQLITE_CHECKPOINT_PASSIVE; | |
| 62983 | + xBusy2 = 0; | |
| 62984 | + rc = SQLITE_OK; | |
| 62985 | + } | |
| 62986 | + } | |
| 62987 | + } | |
| 62988 | + | |
| 62852 | 62989 | |
| 62853 | 62990 | /* Read the wal-index header. */ |
| 62854 | 62991 | if( rc==SQLITE_OK ){ |
| 62992 | + walDisableBlocking(pWal); | |
| 62855 | 62993 | rc = walIndexReadHdr(pWal, &isChanged); |
| 62994 | + (void)walEnableBlocking(pWal); | |
| 62856 | 62995 | if( isChanged && pWal->pDbFd->pMethods->iVersion>=3 ){ |
| 62857 | 62996 | sqlite3OsUnfetch(pWal->pDbFd, 0, 0); |
| 62858 | 62997 | } |
| 62859 | 62998 | } |
| 62860 | 62999 | |
| @@ -62881,16 +63020,24 @@ | ||
| 62881 | 63020 | ** next time the pager opens a snapshot on this database it knows that |
| 62882 | 63021 | ** the cache needs to be reset. |
| 62883 | 63022 | */ |
| 62884 | 63023 | memset(&pWal->hdr, 0, sizeof(WalIndexHdr)); |
| 62885 | 63024 | } |
| 63025 | + | |
| 63026 | + walDisableBlocking(pWal); | |
| 63027 | + sqlite3WalDb(pWal, 0); | |
| 62886 | 63028 | |
| 62887 | 63029 | /* Release the locks. */ |
| 62888 | 63030 | sqlite3WalEndWriteTransaction(pWal); |
| 62889 | - walUnlockExclusive(pWal, WAL_CKPT_LOCK, 1); | |
| 62890 | - pWal->ckptLock = 0; | |
| 63031 | + if( pWal->ckptLock ){ | |
| 63032 | + walUnlockExclusive(pWal, WAL_CKPT_LOCK, 1); | |
| 63033 | + pWal->ckptLock = 0; | |
| 63034 | + } | |
| 62891 | 63035 | WALTRACE(("WAL%p: checkpoint %s\n", pWal, rc ? "failed" : "ok")); |
| 63036 | +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT | |
| 63037 | + if( rc==SQLITE_BUSY_TIMEOUT ) rc = SQLITE_BUSY; | |
| 63038 | +#endif | |
| 62892 | 63039 | return (rc==SQLITE_OK && eMode!=eMode2 ? SQLITE_BUSY : rc); |
| 62893 | 63040 | } |
| 62894 | 63041 | |
| 62895 | 63042 | /* Return the value to pass to a sqlite3_wal_hook callback, the |
| 62896 | 63043 | ** number of frames in the WAL at the point of the last commit since |
| @@ -63003,11 +63150,14 @@ | ||
| 63003 | 63150 | return rc; |
| 63004 | 63151 | } |
| 63005 | 63152 | |
| 63006 | 63153 | /* Try to open on pSnapshot when the next read-transaction starts |
| 63007 | 63154 | */ |
| 63008 | -SQLITE_PRIVATE void sqlite3WalSnapshotOpen(Wal *pWal, sqlite3_snapshot *pSnapshot){ | |
| 63155 | +SQLITE_PRIVATE void sqlite3WalSnapshotOpen( | |
| 63156 | + Wal *pWal, | |
| 63157 | + sqlite3_snapshot *pSnapshot | |
| 63158 | +){ | |
| 63009 | 63159 | pWal->pSnapshot = (WalIndexHdr*)pSnapshot; |
| 63010 | 63160 | } |
| 63011 | 63161 | |
| 63012 | 63162 | /* |
| 63013 | 63163 | ** Return a +ve value if snapshot p1 is newer than p2. A -ve value if |
| @@ -63522,11 +63672,11 @@ | ||
| 63522 | 63672 | u8 incrVacuum; /* True if incr-vacuum is enabled */ |
| 63523 | 63673 | u8 bDoTruncate; /* True to truncate db on commit */ |
| 63524 | 63674 | #endif |
| 63525 | 63675 | u8 inTransaction; /* Transaction state */ |
| 63526 | 63676 | u8 max1bytePayload; /* Maximum first byte of cell for a 1-byte payload */ |
| 63527 | - u8 nReserveWanted; /* 1 more than desired number of extra bytes per page */ | |
| 63677 | + u8 nReserveWanted; /* Desired number of extra bytes per page */ | |
| 63528 | 63678 | u16 btsFlags; /* Boolean parameters. See BTS_* macros below */ |
| 63529 | 63679 | u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */ |
| 63530 | 63680 | u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */ |
| 63531 | 63681 | u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */ |
| 63532 | 63682 | u16 minLeaf; /* Minimum local payload in a LEAFDATA table */ |
| @@ -66416,12 +66566,11 @@ | ||
| 66416 | 66566 | */ |
| 66417 | 66567 | static int btreeInvokeBusyHandler(void *pArg){ |
| 66418 | 66568 | BtShared *pBt = (BtShared*)pArg; |
| 66419 | 66569 | assert( pBt->db ); |
| 66420 | 66570 | assert( sqlite3_mutex_held(pBt->db->mutex) ); |
| 66421 | - return sqlite3InvokeBusyHandler(&pBt->db->busyHandler, | |
| 66422 | - sqlite3PagerFile(pBt->pPager)); | |
| 66571 | + return sqlite3InvokeBusyHandler(&pBt->db->busyHandler); | |
| 66423 | 66572 | } |
| 66424 | 66573 | |
| 66425 | 66574 | /* |
| 66426 | 66575 | ** Open a database file. |
| 66427 | 66576 | ** |
| @@ -66968,23 +67117,21 @@ | ||
| 66968 | 67117 | ** If the iFix!=0 then the BTS_PAGESIZE_FIXED flag is set so that the page size |
| 66969 | 67118 | ** and autovacuum mode can no longer be changed. |
| 66970 | 67119 | */ |
| 66971 | 67120 | SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve, int iFix){ |
| 66972 | 67121 | int rc = SQLITE_OK; |
| 67122 | + int x; | |
| 66973 | 67123 | BtShared *pBt = p->pBt; |
| 66974 | - assert( nReserve>=-1 && nReserve<=254 ); | |
| 67124 | + assert( nReserve>=0 && nReserve<=255 ); | |
| 66975 | 67125 | sqlite3BtreeEnter(p); |
| 66976 | - if( nReserve>=0 ){ | |
| 66977 | - pBt->nReserveWanted = nReserve + 1; | |
| 66978 | - } | |
| 67126 | + pBt->nReserveWanted = nReserve; | |
| 67127 | + x = pBt->pageSize - pBt->usableSize; | |
| 67128 | + if( nReserve<x ) nReserve = x; | |
| 66979 | 67129 | if( pBt->btsFlags & BTS_PAGESIZE_FIXED ){ |
| 66980 | 67130 | sqlite3BtreeLeave(p); |
| 66981 | 67131 | return SQLITE_READONLY; |
| 66982 | 67132 | } |
| 66983 | - if( nReserve<0 ){ | |
| 66984 | - nReserve = pBt->pageSize - pBt->usableSize; | |
| 66985 | - } | |
| 66986 | 67133 | assert( nReserve>=0 && nReserve<=255 ); |
| 66987 | 67134 | if( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE && |
| 66988 | 67135 | ((pageSize-1)&pageSize)==0 ){ |
| 66989 | 67136 | assert( (pageSize & 7)==0 ); |
| 66990 | 67137 | assert( !pBt->pCursor ); |
| @@ -67031,16 +67178,16 @@ | ||
| 67031 | 67178 | ** The value returned is the larger of the current reserve size and |
| 67032 | 67179 | ** the latest reserve size requested by SQLITE_FILECTRL_RESERVE_BYTES. |
| 67033 | 67180 | ** The amount of reserve can only grow - never shrink. |
| 67034 | 67181 | */ |
| 67035 | 67182 | SQLITE_PRIVATE int sqlite3BtreeGetRequestedReserve(Btree *p){ |
| 67036 | - int n; | |
| 67183 | + int n1, n2; | |
| 67037 | 67184 | sqlite3BtreeEnter(p); |
| 67038 | - n = ((int)p->pBt->nReserveWanted) - 1; | |
| 67039 | - if( n<0 ) n = sqlite3BtreeGetReserveNoMutex(p); | |
| 67185 | + n1 = (int)p->pBt->nReserveWanted; | |
| 67186 | + n2 = sqlite3BtreeGetReserveNoMutex(p); | |
| 67040 | 67187 | sqlite3BtreeLeave(p); |
| 67041 | - return n; | |
| 67188 | + return n1>n2 ? n1 : n2; | |
| 67042 | 67189 | } |
| 67043 | 67190 | |
| 67044 | 67191 | |
| 67045 | 67192 | /* |
| 67046 | 67193 | ** Set the maximum page count for a database if mxPage is positive. |
| @@ -67486,10 +67633,11 @@ | ||
| 67486 | 67633 | ** when A already has a read lock, we encourage A to give up and let B |
| 67487 | 67634 | ** proceed. |
| 67488 | 67635 | */ |
| 67489 | 67636 | SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){ |
| 67490 | 67637 | BtShared *pBt = p->pBt; |
| 67638 | + Pager *pPager = pBt->pPager; | |
| 67491 | 67639 | int rc = SQLITE_OK; |
| 67492 | 67640 | |
| 67493 | 67641 | sqlite3BtreeEnter(p); |
| 67494 | 67642 | btreeIntegrity(p); |
| 67495 | 67643 | |
| @@ -67501,11 +67649,11 @@ | ||
| 67501 | 67649 | goto trans_begun; |
| 67502 | 67650 | } |
| 67503 | 67651 | assert( pBt->inTransaction==TRANS_WRITE || IfNotOmitAV(pBt->bDoTruncate)==0 ); |
| 67504 | 67652 | |
| 67505 | 67653 | if( (p->db->flags & SQLITE_ResetDatabase) |
| 67506 | - && sqlite3PagerIsreadonly(pBt->pPager)==0 | |
| 67654 | + && sqlite3PagerIsreadonly(pPager)==0 | |
| 67507 | 67655 | ){ |
| 67508 | 67656 | pBt->btsFlags &= ~BTS_READ_ONLY; |
| 67509 | 67657 | } |
| 67510 | 67658 | |
| 67511 | 67659 | /* Write transactions are not possible on a read-only database */ |
| @@ -67549,10 +67697,22 @@ | ||
| 67549 | 67697 | if( SQLITE_OK!=rc ) goto trans_begun; |
| 67550 | 67698 | |
| 67551 | 67699 | pBt->btsFlags &= ~BTS_INITIALLY_EMPTY; |
| 67552 | 67700 | if( pBt->nPage==0 ) pBt->btsFlags |= BTS_INITIALLY_EMPTY; |
| 67553 | 67701 | do { |
| 67702 | + sqlite3PagerWalDb(pPager, p->db); | |
| 67703 | + | |
| 67704 | +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT | |
| 67705 | + /* If transitioning from no transaction directly to a write transaction, | |
| 67706 | + ** block for the WRITER lock first if possible. */ | |
| 67707 | + if( pBt->pPage1==0 && wrflag ){ | |
| 67708 | + assert( pBt->inTransaction==TRANS_NONE ); | |
| 67709 | + rc = sqlite3PagerWalWriteLock(pPager, 1); | |
| 67710 | + if( rc!=SQLITE_BUSY && rc!=SQLITE_OK ) break; | |
| 67711 | + } | |
| 67712 | +#endif | |
| 67713 | + | |
| 67554 | 67714 | /* Call lockBtree() until either pBt->pPage1 is populated or |
| 67555 | 67715 | ** lockBtree() returns something other than SQLITE_OK. lockBtree() |
| 67556 | 67716 | ** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after |
| 67557 | 67717 | ** reading page 1 it discovers that the page-size of the database |
| 67558 | 67718 | ** file is not pBt->pageSize. In this case lockBtree() will update |
| @@ -67562,11 +67722,11 @@ | ||
| 67562 | 67722 | |
| 67563 | 67723 | if( rc==SQLITE_OK && wrflag ){ |
| 67564 | 67724 | if( (pBt->btsFlags & BTS_READ_ONLY)!=0 ){ |
| 67565 | 67725 | rc = SQLITE_READONLY; |
| 67566 | 67726 | }else{ |
| 67567 | - rc = sqlite3PagerBegin(pBt->pPager,wrflag>1,sqlite3TempInMemory(p->db)); | |
| 67727 | + rc = sqlite3PagerBegin(pPager, wrflag>1, sqlite3TempInMemory(p->db)); | |
| 67568 | 67728 | if( rc==SQLITE_OK ){ |
| 67569 | 67729 | rc = newDatabase(pBt); |
| 67570 | 67730 | }else if( rc==SQLITE_BUSY_SNAPSHOT && pBt->inTransaction==TRANS_NONE ){ |
| 67571 | 67731 | /* if there was no transaction opened when this function was |
| 67572 | 67732 | ** called and SQLITE_BUSY_SNAPSHOT is returned, change the error |
| @@ -67575,15 +67735,19 @@ | ||
| 67575 | 67735 | } |
| 67576 | 67736 | } |
| 67577 | 67737 | } |
| 67578 | 67738 | |
| 67579 | 67739 | if( rc!=SQLITE_OK ){ |
| 67740 | + (void)sqlite3PagerWalWriteLock(pPager, 0); | |
| 67580 | 67741 | unlockBtreeIfUnused(pBt); |
| 67581 | 67742 | } |
| 67582 | 67743 | }while( (rc&0xFF)==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE && |
| 67583 | 67744 | btreeInvokeBusyHandler(pBt) ); |
| 67584 | - sqlite3PagerResetLockTimeout(pBt->pPager); | |
| 67745 | + sqlite3PagerWalDb(pPager, 0); | |
| 67746 | +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT | |
| 67747 | + if( rc==SQLITE_BUSY_TIMEOUT ) rc = SQLITE_BUSY; | |
| 67748 | +#endif | |
| 67585 | 67749 | |
| 67586 | 67750 | if( rc==SQLITE_OK ){ |
| 67587 | 67751 | if( p->inTrans==TRANS_NONE ){ |
| 67588 | 67752 | pBt->nTransaction++; |
| 67589 | 67753 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| @@ -67631,11 +67795,11 @@ | ||
| 67631 | 67795 | if( wrflag ){ |
| 67632 | 67796 | /* This call makes sure that the pager has the correct number of |
| 67633 | 67797 | ** open savepoints. If the second parameter is greater than 0 and |
| 67634 | 67798 | ** the sub-journal is not already open, then it will be opened here. |
| 67635 | 67799 | */ |
| 67636 | - rc = sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint); | |
| 67800 | + rc = sqlite3PagerOpenSavepoint(pPager, p->db->nSavepoint); | |
| 67637 | 67801 | } |
| 67638 | 67802 | } |
| 67639 | 67803 | |
| 67640 | 67804 | btreeIntegrity(p); |
| 67641 | 67805 | sqlite3BtreeLeave(p); |
| @@ -71267,11 +71431,11 @@ | ||
| 71267 | 71431 | |
| 71268 | 71432 | /* Remove cells from the start and end of the page */ |
| 71269 | 71433 | assert( nCell>=0 ); |
| 71270 | 71434 | if( iOld<iNew ){ |
| 71271 | 71435 | int nShift = pageFreeArray(pPg, iOld, iNew-iOld, pCArray); |
| 71272 | - if( nShift>nCell ) return SQLITE_CORRUPT_BKPT; | |
| 71436 | + if( NEVER(nShift>nCell) ) return SQLITE_CORRUPT_BKPT; | |
| 71273 | 71437 | memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2); |
| 71274 | 71438 | nCell -= nShift; |
| 71275 | 71439 | } |
| 71276 | 71440 | if( iNewEnd < iOldEnd ){ |
| 71277 | 71441 | int nTail = pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray); |
| @@ -74746,11 +74910,11 @@ | ||
| 74746 | 74910 | ** Attempt to set the page size of the destination to match the page size |
| 74747 | 74911 | ** of the source. |
| 74748 | 74912 | */ |
| 74749 | 74913 | static int setDestPgsz(sqlite3_backup *p){ |
| 74750 | 74914 | int rc; |
| 74751 | - rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),-1,0); | |
| 74915 | + rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),0,0); | |
| 74752 | 74916 | return rc; |
| 74753 | 74917 | } |
| 74754 | 74918 | |
| 74755 | 74919 | /* |
| 74756 | 74920 | ** Check that there is no open read-transaction on the b-tree passed as the |
| @@ -90540,16 +90704,23 @@ | ||
| 90540 | 90704 | rc = sqlite3VdbeSorterWrite(pC, pIn2); |
| 90541 | 90705 | if( rc) goto abort_due_to_error; |
| 90542 | 90706 | break; |
| 90543 | 90707 | } |
| 90544 | 90708 | |
| 90545 | -/* Opcode: IdxDelete P1 P2 P3 * * | |
| 90709 | +/* Opcode: IdxDelete P1 P2 P3 * P5 | |
| 90546 | 90710 | ** Synopsis: key=r[P2@P3] |
| 90547 | 90711 | ** |
| 90548 | 90712 | ** The content of P3 registers starting at register P2 form |
| 90549 | 90713 | ** an unpacked index key. This opcode removes that entry from the |
| 90550 | 90714 | ** index opened by cursor P1. |
| 90715 | +** | |
| 90716 | +** If P5 is not zero, then raise an SQLITE_CORRUPT_INDEX error | |
| 90717 | +** if no matching index entry is found. This happens when running | |
| 90718 | +** an UPDATE or DELETE statement and the index entry to be updated | |
| 90719 | +** or deleted is not found. For some uses of IdxDelete | |
| 90720 | +** (example: the EXCEPT operator) it does not matter that no matching | |
| 90721 | +** entry is found. For those cases, P5 is zero. | |
| 90551 | 90722 | */ |
| 90552 | 90723 | case OP_IdxDelete: { |
| 90553 | 90724 | VdbeCursor *pC; |
| 90554 | 90725 | BtCursor *pCrsr; |
| 90555 | 90726 | int res; |
| @@ -90562,20 +90733,22 @@ | ||
| 90562 | 90733 | assert( pC!=0 ); |
| 90563 | 90734 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 90564 | 90735 | sqlite3VdbeIncrWriteCounter(p, pC); |
| 90565 | 90736 | pCrsr = pC->uc.pCursor; |
| 90566 | 90737 | assert( pCrsr!=0 ); |
| 90567 | - assert( pOp->p5==0 ); | |
| 90568 | 90738 | r.pKeyInfo = pC->pKeyInfo; |
| 90569 | 90739 | r.nField = (u16)pOp->p3; |
| 90570 | 90740 | r.default_rc = 0; |
| 90571 | 90741 | r.aMem = &aMem[pOp->p2]; |
| 90572 | 90742 | rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res); |
| 90573 | 90743 | if( rc ) goto abort_due_to_error; |
| 90574 | 90744 | if( res==0 ){ |
| 90575 | 90745 | rc = sqlite3BtreeDelete(pCrsr, BTREE_AUXDELETE); |
| 90576 | 90746 | if( rc ) goto abort_due_to_error; |
| 90747 | + }else if( pOp->p5 ){ | |
| 90748 | + rc = SQLITE_CORRUPT_INDEX; | |
| 90749 | + goto abort_due_to_error; | |
| 90577 | 90750 | } |
| 90578 | 90751 | assert( pC->deferredMoveto==0 ); |
| 90579 | 90752 | pC->cacheStatus = CACHE_STALE; |
| 90580 | 90753 | pC->seekResult = 0; |
| 90581 | 90754 | break; |
| @@ -103684,11 +103857,11 @@ | ||
| 103684 | 103857 | assert( pExpr->affExpr==OE_Rollback |
| 103685 | 103858 | || pExpr->affExpr==OE_Abort |
| 103686 | 103859 | || pExpr->affExpr==OE_Fail |
| 103687 | 103860 | || pExpr->affExpr==OE_Ignore |
| 103688 | 103861 | ); |
| 103689 | - if( !pParse->pTriggerTab ){ | |
| 103862 | + if( !pParse->pTriggerTab && !pParse->nested ){ | |
| 103690 | 103863 | sqlite3ErrorMsg(pParse, |
| 103691 | 103864 | "RAISE() may only be used within a trigger-program"); |
| 103692 | 103865 | return 0; |
| 103693 | 103866 | } |
| 103694 | 103867 | if( pExpr->affExpr==OE_Abort ){ |
| @@ -103698,12 +103871,13 @@ | ||
| 103698 | 103871 | if( pExpr->affExpr==OE_Ignore ){ |
| 103699 | 103872 | sqlite3VdbeAddOp4( |
| 103700 | 103873 | v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0); |
| 103701 | 103874 | VdbeCoverage(v); |
| 103702 | 103875 | }else{ |
| 103703 | - sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_TRIGGER, | |
| 103704 | - pExpr->affExpr, pExpr->u.zToken, 0, 0); | |
| 103876 | + sqlite3HaltConstraint(pParse, | |
| 103877 | + pParse->pTriggerTab ? SQLITE_CONSTRAINT_TRIGGER : SQLITE_ERROR, | |
| 103878 | + pExpr->affExpr, pExpr->u.zToken, 0, 0); | |
| 103705 | 103879 | } |
| 103706 | 103880 | |
| 103707 | 103881 | break; |
| 103708 | 103882 | } |
| 103709 | 103883 | #endif |
| @@ -105454,10 +105628,26 @@ | ||
| 105454 | 105628 | exit_rename_table: |
| 105455 | 105629 | sqlite3SrcListDelete(db, pSrc); |
| 105456 | 105630 | sqlite3DbFree(db, zName); |
| 105457 | 105631 | db->mDbFlags = savedDbFlags; |
| 105458 | 105632 | } |
| 105633 | + | |
| 105634 | +/* | |
| 105635 | +** Write code that will raise an error if the table described by | |
| 105636 | +** zDb and zTab is not empty. | |
| 105637 | +*/ | |
| 105638 | +static void sqlite3ErrorIfNotEmpty( | |
| 105639 | + Parse *pParse, /* Parsing context */ | |
| 105640 | + const char *zDb, /* Schema holding the table */ | |
| 105641 | + const char *zTab, /* Table to check for empty */ | |
| 105642 | + const char *zErr /* Error message text */ | |
| 105643 | +){ | |
| 105644 | + sqlite3NestedParse(pParse, | |
| 105645 | + "SELECT raise(ABORT,%Q) FROM \"%w\".\"%w\"", | |
| 105646 | + zErr, zDb, zTab | |
| 105647 | + ); | |
| 105648 | +} | |
| 105459 | 105649 | |
| 105460 | 105650 | /* |
| 105461 | 105651 | ** This function is called after an "ALTER TABLE ... ADD" statement |
| 105462 | 105652 | ** has been parsed. Argument pColDef contains the text of the new |
| 105463 | 105653 | ** column definition. |
| @@ -105507,11 +105697,12 @@ | ||
| 105507 | 105697 | if( pCol->colFlags & COLFLAG_PRIMKEY ){ |
| 105508 | 105698 | sqlite3ErrorMsg(pParse, "Cannot add a PRIMARY KEY column"); |
| 105509 | 105699 | return; |
| 105510 | 105700 | } |
| 105511 | 105701 | if( pNew->pIndex ){ |
| 105512 | - sqlite3ErrorMsg(pParse, "Cannot add a UNIQUE column"); | |
| 105702 | + sqlite3ErrorMsg(pParse, | |
| 105703 | + "Cannot add a UNIQUE column"); | |
| 105513 | 105704 | return; |
| 105514 | 105705 | } |
| 105515 | 105706 | if( (pCol->colFlags & COLFLAG_GENERATED)==0 ){ |
| 105516 | 105707 | /* If the default value for the new column was specified with a |
| 105517 | 105708 | ** literal NULL, then set pDflt to 0. This simplifies checking |
| @@ -105520,19 +105711,18 @@ | ||
| 105520 | 105711 | assert( pDflt==0 || pDflt->op==TK_SPAN ); |
| 105521 | 105712 | if( pDflt && pDflt->pLeft->op==TK_NULL ){ |
| 105522 | 105713 | pDflt = 0; |
| 105523 | 105714 | } |
| 105524 | 105715 | if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){ |
| 105525 | - sqlite3ErrorMsg(pParse, | |
| 105716 | + sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, | |
| 105526 | 105717 | "Cannot add a REFERENCES column with non-NULL default value"); |
| 105527 | - return; | |
| 105528 | 105718 | } |
| 105529 | 105719 | if( pCol->notNull && !pDflt ){ |
| 105530 | - sqlite3ErrorMsg(pParse, | |
| 105720 | + sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, | |
| 105531 | 105721 | "Cannot add a NOT NULL column with default value NULL"); |
| 105532 | - return; | |
| 105533 | 105722 | } |
| 105723 | + | |
| 105534 | 105724 | |
| 105535 | 105725 | /* Ensure the default expression is something that sqlite3ValueFromExpr() |
| 105536 | 105726 | ** can handle (i.e. not CURRENT_TIME etc.) |
| 105537 | 105727 | */ |
| 105538 | 105728 | if( pDflt ){ |
| @@ -105543,18 +105733,17 @@ | ||
| 105543 | 105733 | if( rc!=SQLITE_OK ){ |
| 105544 | 105734 | assert( db->mallocFailed == 1 ); |
| 105545 | 105735 | return; |
| 105546 | 105736 | } |
| 105547 | 105737 | if( !pVal ){ |
| 105548 | - sqlite3ErrorMsg(pParse,"Cannot add a column with non-constant default"); | |
| 105549 | - return; | |
| 105738 | + sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, | |
| 105739 | + "Cannot add a column with non-constant default"); | |
| 105550 | 105740 | } |
| 105551 | 105741 | sqlite3ValueFree(pVal); |
| 105552 | 105742 | } |
| 105553 | 105743 | }else if( pCol->colFlags & COLFLAG_STORED ){ |
| 105554 | - sqlite3ErrorMsg(pParse, "cannot add a STORED column"); | |
| 105555 | - return; | |
| 105744 | + sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, "cannot add a STORED column"); | |
| 105556 | 105745 | } |
| 105557 | 105746 | |
| 105558 | 105747 | |
| 105559 | 105748 | /* Modify the CREATE TABLE statement. */ |
| 105560 | 105749 | zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n); |
| @@ -114373,11 +114562,11 @@ | ||
| 114373 | 114562 | pParse->rc = rc; |
| 114374 | 114563 | return 1; |
| 114375 | 114564 | } |
| 114376 | 114565 | db->aDb[1].pBt = pBt; |
| 114377 | 114566 | assert( db->aDb[1].pSchema ); |
| 114378 | - if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){ | |
| 114567 | + if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, 0, 0) ){ | |
| 114379 | 114568 | sqlite3OomFault(db); |
| 114380 | 114569 | return 1; |
| 114381 | 114570 | } |
| 114382 | 114571 | } |
| 114383 | 114572 | return 0; |
| @@ -114484,11 +114673,11 @@ | ||
| 114484 | 114673 | char *p4, /* Error message */ |
| 114485 | 114674 | i8 p4type, /* P4_STATIC or P4_TRANSIENT */ |
| 114486 | 114675 | u8 p5Errmsg /* P5_ErrMsg type */ |
| 114487 | 114676 | ){ |
| 114488 | 114677 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 114489 | - assert( (errCode&0xff)==SQLITE_CONSTRAINT ); | |
| 114678 | + assert( (errCode&0xff)==SQLITE_CONSTRAINT || pParse->nested ); | |
| 114490 | 114679 | if( onError==OE_Abort ){ |
| 114491 | 114680 | sqlite3MayAbort(pParse); |
| 114492 | 114681 | } |
| 114493 | 114682 | sqlite3VdbeAddOp4(v, OP_Halt, errCode, onError, 0, p4, p4type); |
| 114494 | 114683 | sqlite3VdbeChangeP5(v, p5Errmsg); |
| @@ -116197,10 +116386,11 @@ | ||
| 116197 | 116386 | VdbeModuleComment((v, "GenRowIdxDel for %s", pIdx->zName)); |
| 116198 | 116387 | r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 1, |
| 116199 | 116388 | &iPartIdxLabel, pPrior, r1); |
| 116200 | 116389 | sqlite3VdbeAddOp3(v, OP_IdxDelete, iIdxCur+i, r1, |
| 116201 | 116390 | pIdx->uniqNotNull ? pIdx->nKeyCol : pIdx->nColumn); |
| 116391 | + sqlite3VdbeChangeP5(v, 1); /* Cause IdxDelete to error if no entry found */ | |
| 116202 | 116392 | sqlite3ResolvePartIdxLabel(pParse, iPartIdxLabel); |
| 116203 | 116393 | pPrior = pIdx; |
| 116204 | 116394 | } |
| 116205 | 116395 | } |
| 116206 | 116396 | |
| @@ -125555,11 +125745,11 @@ | ||
| 125555 | 125745 | }else{ |
| 125556 | 125746 | /* Malloc may fail when setting the page-size, as there is an internal |
| 125557 | 125747 | ** buffer that the pager module resizes using sqlite3_realloc(). |
| 125558 | 125748 | */ |
| 125559 | 125749 | db->nextPagesize = sqlite3Atoi(zRight); |
| 125560 | - if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){ | |
| 125750 | + if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,0,0) ){ | |
| 125561 | 125751 | sqlite3OomFault(db); |
| 125562 | 125752 | } |
| 125563 | 125753 | } |
| 125564 | 125754 | break; |
| 125565 | 125755 | } |
| @@ -135193,17 +135383,19 @@ | ||
| 135193 | 135383 | ** |
| 135194 | 135384 | ** In practice the KeyInfo structure will not be used. It is only |
| 135195 | 135385 | ** passed to keep OP_OpenRead happy. |
| 135196 | 135386 | */ |
| 135197 | 135387 | if( !HasRowid(pTab) ) pBest = sqlite3PrimaryKeyIndex(pTab); |
| 135198 | - for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ | |
| 135199 | - if( pIdx->bUnordered==0 | |
| 135200 | - && pIdx->szIdxRow<pTab->szTabRow | |
| 135201 | - && pIdx->pPartIdxWhere==0 | |
| 135202 | - && (!pBest || pIdx->szIdxRow<pBest->szIdxRow) | |
| 135203 | - ){ | |
| 135204 | - pBest = pIdx; | |
| 135388 | + if( !p->pSrc->a[0].fg.notIndexed ){ | |
| 135389 | + for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ | |
| 135390 | + if( pIdx->bUnordered==0 | |
| 135391 | + && pIdx->szIdxRow<pTab->szTabRow | |
| 135392 | + && pIdx->pPartIdxWhere==0 | |
| 135393 | + && (!pBest || pIdx->szIdxRow<pBest->szIdxRow) | |
| 135394 | + ){ | |
| 135395 | + pBest = pIdx; | |
| 135396 | + } | |
| 135205 | 135397 | } |
| 135206 | 135398 | } |
| 135207 | 135399 | if( pBest ){ |
| 135208 | 135400 | iRoot = pBest->tnum; |
| 135209 | 135401 | pKeyInfo = sqlite3KeyInfoOfIndex(pParse, pBest); |
| @@ -138439,11 +138631,11 @@ | ||
| 138439 | 138631 | db->mDbFlags = saved_mDbFlags; |
| 138440 | 138632 | db->flags = saved_flags; |
| 138441 | 138633 | db->nChange = saved_nChange; |
| 138442 | 138634 | db->nTotalChange = saved_nTotalChange; |
| 138443 | 138635 | db->mTrace = saved_mTrace; |
| 138444 | - sqlite3BtreeSetPageSize(pMain, -1, -1, 1); | |
| 138636 | + sqlite3BtreeSetPageSize(pMain, -1, 0, 1); | |
| 138445 | 138637 | |
| 138446 | 138638 | /* Currently there is an SQL level transaction open on the vacuum |
| 138447 | 138639 | ** database. No locks are held on any other files (since the main file |
| 138448 | 138640 | ** was committed at the btree level). So it safe to end the transaction |
| 138449 | 138641 | ** by manually setting the autoCommit flag to true and detaching the |
| @@ -161431,12 +161623,11 @@ | ||
| 161431 | 161623 | ** Return non-zero to retry the lock. Return zero to stop trying |
| 161432 | 161624 | ** and cause SQLite to return SQLITE_BUSY. |
| 161433 | 161625 | */ |
| 161434 | 161626 | static int sqliteDefaultBusyCallback( |
| 161435 | 161627 | void *ptr, /* Database connection */ |
| 161436 | - int count, /* Number of times table has been busy */ | |
| 161437 | - sqlite3_file *pFile /* The file on which the lock occurred */ | |
| 161628 | + int count /* Number of times table has been busy */ | |
| 161438 | 161629 | ){ |
| 161439 | 161630 | #if SQLITE_OS_WIN || HAVE_USLEEP |
| 161440 | 161631 | /* This case is for systems that have support for sleeping for fractions of |
| 161441 | 161632 | ** a second. Examples: All windows systems, unix systems with usleep() */ |
| 161442 | 161633 | static const u8 delays[] = |
| @@ -161446,35 +161637,10 @@ | ||
| 161446 | 161637 | # define NDELAY ArraySize(delays) |
| 161447 | 161638 | sqlite3 *db = (sqlite3 *)ptr; |
| 161448 | 161639 | int tmout = db->busyTimeout; |
| 161449 | 161640 | int delay, prior; |
| 161450 | 161641 | |
| 161451 | -#ifdef SQLITE_ENABLE_SETLK_TIMEOUT | |
| 161452 | - if( sqlite3OsFileControl(pFile,SQLITE_FCNTL_LOCK_TIMEOUT,&tmout)==SQLITE_OK ){ | |
| 161453 | - if( count ){ | |
| 161454 | - /* If this is the second or later invocation of the busy-handler, | |
| 161455 | - ** but tmout==0, then code in wal.c must have disabled the blocking | |
| 161456 | - ** lock before the SQLITE_BUSY error was hit. In this case, no delay | |
| 161457 | - ** occurred while waiting for the lock, so fall through to the xSleep() | |
| 161458 | - ** code below to delay a while before retrying the lock. | |
| 161459 | - ** | |
| 161460 | - ** Alternatively, if tmout!=0, then SQLite has already waited | |
| 161461 | - ** sqlite3.busyTimeout ms for a lock. In this case, return 0 to | |
| 161462 | - ** indicate that the lock should not be retried and the SQLITE_BUSY | |
| 161463 | - ** error returned to the application. */ | |
| 161464 | - if( tmout ){ | |
| 161465 | - tmout = 0; | |
| 161466 | - sqlite3OsFileControl(pFile, SQLITE_FCNTL_LOCK_TIMEOUT, &tmout); | |
| 161467 | - return 0; | |
| 161468 | - } | |
| 161469 | - }else{ | |
| 161470 | - return 1; | |
| 161471 | - } | |
| 161472 | - } | |
| 161473 | -#else | |
| 161474 | - UNUSED_PARAMETER(pFile); | |
| 161475 | -#endif | |
| 161476 | 161642 | assert( count>=0 ); |
| 161477 | 161643 | if( count < NDELAY ){ |
| 161478 | 161644 | delay = delays[count]; |
| 161479 | 161645 | prior = totals[count]; |
| 161480 | 161646 | }else{ |
| @@ -161490,11 +161656,10 @@ | ||
| 161490 | 161656 | #else |
| 161491 | 161657 | /* This case for unix systems that lack usleep() support. Sleeping |
| 161492 | 161658 | ** must be done in increments of whole seconds */ |
| 161493 | 161659 | sqlite3 *db = (sqlite3 *)ptr; |
| 161494 | 161660 | int tmout = ((sqlite3 *)ptr)->busyTimeout; |
| 161495 | - UNUSED_PARAMETER(pFile); | |
| 161496 | 161661 | if( (count+1)*1000 > tmout ){ |
| 161497 | 161662 | return 0; |
| 161498 | 161663 | } |
| 161499 | 161664 | sqlite3OsSleep(db->pVfs, 1000000); |
| 161500 | 161665 | return 1; |
| @@ -161508,23 +161673,14 @@ | ||
| 161508 | 161673 | ** lock on VFS file pFile. |
| 161509 | 161674 | ** |
| 161510 | 161675 | ** If this routine returns non-zero, the lock is retried. If it |
| 161511 | 161676 | ** returns 0, the operation aborts with an SQLITE_BUSY error. |
| 161512 | 161677 | */ |
| 161513 | -SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler *p, sqlite3_file *pFile){ | |
| 161678 | +SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler *p){ | |
| 161514 | 161679 | int rc; |
| 161515 | 161680 | if( p->xBusyHandler==0 || p->nBusy<0 ) return 0; |
| 161516 | - if( p->bExtraFileArg ){ | |
| 161517 | - /* Add an extra parameter with the pFile pointer to the end of the | |
| 161518 | - ** callback argument list */ | |
| 161519 | - int (*xTra)(void*,int,sqlite3_file*); | |
| 161520 | - xTra = (int(*)(void*,int,sqlite3_file*))p->xBusyHandler; | |
| 161521 | - rc = xTra(p->pBusyArg, p->nBusy, pFile); | |
| 161522 | - }else{ | |
| 161523 | - /* Legacy style busy handler callback */ | |
| 161524 | - rc = p->xBusyHandler(p->pBusyArg, p->nBusy); | |
| 161525 | - } | |
| 161681 | + rc = p->xBusyHandler(p->pBusyArg, p->nBusy); | |
| 161526 | 161682 | if( rc==0 ){ |
| 161527 | 161683 | p->nBusy = -1; |
| 161528 | 161684 | }else{ |
| 161529 | 161685 | p->nBusy++; |
| 161530 | 161686 | } |
| @@ -161545,11 +161701,10 @@ | ||
| 161545 | 161701 | #endif |
| 161546 | 161702 | sqlite3_mutex_enter(db->mutex); |
| 161547 | 161703 | db->busyHandler.xBusyHandler = xBusy; |
| 161548 | 161704 | db->busyHandler.pBusyArg = pArg; |
| 161549 | 161705 | db->busyHandler.nBusy = 0; |
| 161550 | - db->busyHandler.bExtraFileArg = 0; | |
| 161551 | 161706 | db->busyTimeout = 0; |
| 161552 | 161707 | sqlite3_mutex_leave(db->mutex); |
| 161553 | 161708 | return SQLITE_OK; |
| 161554 | 161709 | } |
| 161555 | 161710 | |
| @@ -161596,11 +161751,10 @@ | ||
| 161596 | 161751 | #endif |
| 161597 | 161752 | if( ms>0 ){ |
| 161598 | 161753 | sqlite3_busy_handler(db, (int(*)(void*,int))sqliteDefaultBusyCallback, |
| 161599 | 161754 | (void*)db); |
| 161600 | 161755 | db->busyTimeout = ms; |
| 161601 | - db->busyHandler.bExtraFileArg = 1; | |
| 161602 | 161756 | }else{ |
| 161603 | 161757 | sqlite3_busy_handler(db, 0, 0); |
| 161604 | 161758 | } |
| 161605 | 161759 | return SQLITE_OK; |
| 161606 | 161760 | } |
| @@ -163071,10 +163225,13 @@ | ||
| 163071 | 163225 | | SQLITE_EnableQPSG |
| 163072 | 163226 | #endif |
| 163073 | 163227 | #if defined(SQLITE_DEFAULT_DEFENSIVE) |
| 163074 | 163228 | | SQLITE_Defensive |
| 163075 | 163229 | #endif |
| 163230 | +#if defined(SQLITE_DEFAULT_LEGACY_ALTER_TABLE) | |
| 163231 | + | SQLITE_LegacyAlter | |
| 163232 | +#endif | |
| 163076 | 163233 | ; |
| 163077 | 163234 | sqlite3HashInit(&db->aCollSeq); |
| 163078 | 163235 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 163079 | 163236 | sqlite3HashInit(&db->aModule); |
| 163080 | 163237 | #endif |
| @@ -163668,11 +163825,11 @@ | ||
| 163668 | 163825 | *(unsigned int*)pArg = sqlite3PagerDataVersion(pPager); |
| 163669 | 163826 | rc = SQLITE_OK; |
| 163670 | 163827 | }else if( op==SQLITE_FCNTL_RESERVE_BYTES ){ |
| 163671 | 163828 | int iNew = *(int*)pArg; |
| 163672 | 163829 | *(int*)pArg = sqlite3BtreeGetRequestedReserve(pBtree); |
| 163673 | - if( iNew>=0 && iNew<=254 ){ | |
| 163830 | + if( iNew>=0 && iNew<=255 ){ | |
| 163674 | 163831 | sqlite3BtreeSetPageSize(pBtree, 0, iNew, 0); |
| 163675 | 163832 | } |
| 163676 | 163833 | rc = SQLITE_OK; |
| 163677 | 163834 | }else{ |
| 163678 | 163835 | rc = sqlite3OsFileControl(fd, op, pArg); |
| @@ -167905,11 +168062,13 @@ | ||
| 167905 | 168062 | static void fts3ReadNextPos( |
| 167906 | 168063 | char **pp, /* IN/OUT: Pointer into position-list buffer */ |
| 167907 | 168064 | sqlite3_int64 *pi /* IN/OUT: Value read from position-list */ |
| 167908 | 168065 | ){ |
| 167909 | 168066 | if( (**pp)&0xFE ){ |
| 167910 | - fts3GetDeltaVarint(pp, pi); | |
| 168067 | + int iVal; | |
| 168068 | + *pp += fts3GetVarint32((*pp), &iVal); | |
| 168069 | + *pi += iVal; | |
| 167911 | 168070 | *pi -= 2; |
| 167912 | 168071 | }else{ |
| 167913 | 168072 | *pi = POSITION_LIST_END; |
| 167914 | 168073 | } |
| 167915 | 168074 | } |
| @@ -224505,11 +224664,11 @@ | ||
| 224505 | 224664 | int nArg, /* Number of args */ |
| 224506 | 224665 | sqlite3_value **apUnused /* Function arguments */ |
| 224507 | 224666 | ){ |
| 224508 | 224667 | assert( nArg==0 ); |
| 224509 | 224668 | UNUSED_PARAM2(nArg, apUnused); |
| 224510 | - sqlite3_result_text(pCtx, "fts5: 2020-05-04 19:52:00 8eee591d3cb9fadfd5cac5543bd66ef9cb371a72d3ad3241fb3bfd67fb216eda", -1, SQLITE_TRANSIENT); | |
| 224669 | + sqlite3_result_text(pCtx, "fts5: 2020-05-08 19:02:21 3a16c0ce4d8851f79f670d94786032c8007619154ece44647dc9cc5b1f9654ff", -1, SQLITE_TRANSIENT); | |
| 224511 | 224670 | } |
| 224512 | 224671 | |
| 224513 | 224672 | /* |
| 224514 | 224673 | ** Return true if zName is the extension on one of the shadow tables used |
| 224515 | 224674 | ** by this module. |
| @@ -229288,12 +229447,12 @@ | ||
| 229288 | 229447 | } |
| 229289 | 229448 | #endif /* SQLITE_CORE */ |
| 229290 | 229449 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 229291 | 229450 | |
| 229292 | 229451 | /************** End of stmt.c ************************************************/ |
| 229293 | -#if __LINE__!=229293 | |
| 229452 | +#if __LINE__!=229452 | |
| 229294 | 229453 | #undef SQLITE_SOURCE_ID |
| 229295 | -#define SQLITE_SOURCE_ID "2020-05-04 19:52:00 8eee591d3cb9fadfd5cac5543bd66ef9cb371a72d3ad3241fb3bfd67fb21alt2" | |
| 229454 | +#define SQLITE_SOURCE_ID "2020-05-08 19:02:21 3a16c0ce4d8851f79f670d94786032c8007619154ece44647dc9cc5b1f96alt2" | |
| 229296 | 229455 | #endif |
| 229297 | 229456 | /* Return the source-id for this library */ |
| 229298 | 229457 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 229299 | 229458 | /************************** End of sqlite3.c ******************************/ |
| 229300 | 229459 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1162,11 +1162,11 @@ | |
| 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1164 | */ |
| 1165 | #define SQLITE_VERSION "3.32.0" |
| 1166 | #define SQLITE_VERSION_NUMBER 3032000 |
| 1167 | #define SQLITE_SOURCE_ID "2020-05-04 19:52:00 8eee591d3cb9fadfd5cac5543bd66ef9cb371a72d3ad3241fb3bfd67fb216eda" |
| 1168 | |
| 1169 | /* |
| 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1172 | ** |
| @@ -1545,18 +1545,20 @@ | |
| 1545 | #define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8)) |
| 1546 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 1547 | #define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8)) |
| 1548 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 1549 | #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8)) |
| 1550 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 1551 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 1552 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 1553 | #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) |
| 1554 | #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */ |
| 1555 | #define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8)) |
| 1556 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 1557 | #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8)) |
| 1558 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 1559 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 1560 | #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) |
| 1561 | #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) |
| 1562 | #define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8)) |
| @@ -14535,11 +14537,10 @@ | |
| 14535 | typedef struct BusyHandler BusyHandler; |
| 14536 | struct BusyHandler { |
| 14537 | int (*xBusyHandler)(void *,int); /* The busy callback */ |
| 14538 | void *pBusyArg; /* First arg to busy callback */ |
| 14539 | int nBusy; /* Incremented with each busy call */ |
| 14540 | u8 bExtraFileArg; /* Include sqlite3_file as callback arg */ |
| 14541 | }; |
| 14542 | |
| 14543 | /* |
| 14544 | ** Name of the master database table. The master database table |
| 14545 | ** is a special table that holds the names and attributes of all |
| @@ -15918,17 +15919,25 @@ | |
| 15918 | SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager); |
| 15919 | SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager); |
| 15920 | SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen); |
| 15921 | SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3*); |
| 15922 | # ifdef SQLITE_ENABLE_SNAPSHOT |
| 15923 | SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot); |
| 15924 | SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot); |
| 15925 | SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager); |
| 15926 | SQLITE_PRIVATE int sqlite3PagerSnapshotCheck(Pager *pPager, sqlite3_snapshot *pSnapshot); |
| 15927 | SQLITE_PRIVATE void sqlite3PagerSnapshotUnlock(Pager *pPager); |
| 15928 | # endif |
| 15929 | #endif |
| 15930 | |
| 15931 | #ifdef SQLITE_DIRECT_OVERFLOW_READ |
| 15932 | SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno); |
| 15933 | #endif |
| 15934 | |
| @@ -15951,15 +15960,10 @@ | |
| 15951 | SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*); |
| 15952 | SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*); |
| 15953 | SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *); |
| 15954 | SQLITE_PRIVATE void sqlite3PagerClearCache(Pager*); |
| 15955 | SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *); |
| 15956 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 15957 | SQLITE_PRIVATE void sqlite3PagerResetLockTimeout(Pager *pPager); |
| 15958 | #else |
| 15959 | # define sqlite3PagerResetLockTimeout(X) |
| 15960 | #endif |
| 15961 | |
| 15962 | /* Functions used to truncate the database file. */ |
| 15963 | SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno); |
| 15964 | |
| 15965 | SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16); |
| @@ -19935,11 +19939,11 @@ | |
| 19935 | SQLITE_PRIVATE void sqlite3RenameExprUnmap(Parse*, Expr*); |
| 19936 | SQLITE_PRIVATE void sqlite3RenameExprlistUnmap(Parse*, ExprList*); |
| 19937 | SQLITE_PRIVATE CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*); |
| 19938 | SQLITE_PRIVATE char sqlite3AffinityType(const char*, Column*); |
| 19939 | SQLITE_PRIVATE void sqlite3Analyze(Parse*, Token*, Token*); |
| 19940 | SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler*, sqlite3_file*); |
| 19941 | SQLITE_PRIVATE int sqlite3FindDb(sqlite3*, Token*); |
| 19942 | SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *, const char *); |
| 19943 | SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3*,int iDB); |
| 19944 | SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3*,Index*); |
| 19945 | SQLITE_PRIVATE void sqlite3DefaultRowEst(Index*); |
| @@ -27730,14 +27734,16 @@ | |
| 27730 | if( nDiff>0 && sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= |
| 27731 | mem0.alarmThreshold-nDiff ){ |
| 27732 | sqlite3MallocAlarm(nDiff); |
| 27733 | } |
| 27734 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 27735 | if( pNew==0 && mem0.alarmThreshold>0 ){ |
| 27736 | sqlite3MallocAlarm((int)nBytes); |
| 27737 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 27738 | } |
| 27739 | if( pNew ){ |
| 27740 | nNew = sqlite3MallocSize(pNew); |
| 27741 | sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nNew-nOld); |
| 27742 | } |
| 27743 | sqlite3_mutex_leave(mem0.mutex); |
| @@ -34971,20 +34977,21 @@ | |
| 34971 | static int osSetPosixAdvisoryLock( |
| 34972 | int h, /* The file descriptor on which to take the lock */ |
| 34973 | struct flock *pLock, /* The description of the lock */ |
| 34974 | unixFile *pFile /* Structure holding timeout value */ |
| 34975 | ){ |
| 34976 | int rc = osFcntl(h,F_SETLK,pLock); |
| 34977 | while( rc<0 && pFile->iBusyTimeout>0 ){ |
| 34978 | /* On systems that support some kind of blocking file lock with a timeout, |
| 34979 | ** make appropriate changes here to invoke that blocking file lock. On |
| 34980 | ** generic posix, however, there is no such API. So we simply try the |
| 34981 | ** lock once every millisecond until either the timeout expires, or until |
| 34982 | ** the lock is obtained. */ |
| 34983 | usleep(1000); |
| 34984 | rc = osFcntl(h,F_SETLK,pLock); |
| 34985 | pFile->iBusyTimeout--; |
| 34986 | } |
| 34987 | return rc; |
| 34988 | } |
| 34989 | #endif /* SQLITE_ENABLE_SETLK_TIMEOUT */ |
| 34990 | |
| @@ -37722,17 +37729,24 @@ | |
| 37722 | |
| 37723 | /* Locks are within range */ |
| 37724 | assert( n>=1 && n<=SQLITE_SHM_NLOCK ); |
| 37725 | |
| 37726 | if( pShmNode->hShm>=0 ){ |
| 37727 | /* Initialize the locking parameters */ |
| 37728 | f.l_type = lockType; |
| 37729 | f.l_whence = SEEK_SET; |
| 37730 | f.l_start = ofst; |
| 37731 | f.l_len = n; |
| 37732 | rc = osSetPosixAdvisoryLock(pShmNode->hShm, &f, pFile); |
| 37733 | rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY; |
| 37734 | } |
| 37735 | |
| 37736 | /* Update the global lock state and do debug tracing */ |
| 37737 | #ifdef SQLITE_DEBUG |
| 37738 | { u16 mask; |
| @@ -38225,26 +38239,27 @@ | |
| 38225 | || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE) ); |
| 38226 | assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 ); |
| 38227 | assert( pShmNode->hShm>=0 || pDbFd->pInode->bProcessLock==1 ); |
| 38228 | assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 ); |
| 38229 | |
| 38230 | /* Check that, if this to be a blocking lock, that locks have been |
| 38231 | ** obtained in the following order. |
| 38232 | ** |
| 38233 | ** 1. Checkpointer lock (ofst==1). |
| 38234 | ** 2. Recover lock (ofst==2). |
| 38235 | ** 3. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK). |
| 38236 | ** 4. Write lock (ofst==0). |
| 38237 | ** |
| 38238 | ** In other words, if this is a blocking lock, none of the locks that |
| 38239 | ** occur later in the above list than the lock being obtained may be |
| 38240 | ** held. */ |
| 38241 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 38242 | assert( pDbFd->iBusyTimeout==0 |
| 38243 | || (flags & SQLITE_SHM_UNLOCK) || ofst==0 |
| 38244 | || ((p->exclMask|p->sharedMask)&~((1<<ofst)-2))==0 |
| 38245 | ); |
| 38246 | #endif |
| 38247 | |
| 38248 | mask = (1<<(ofst+n)) - (1<<ofst); |
| 38249 | assert( n>1 || mask==(1<<ofst) ); |
| 38250 | sqlite3_mutex_enter(pShmNode->pShmMutex); |
| @@ -51548,10 +51563,15 @@ | |
| 51548 | SQLITE_PRIVATE int sqlite3WalFramesize(Wal *pWal); |
| 51549 | #endif |
| 51550 | |
| 51551 | /* Return the sqlite3_file object for the WAL file */ |
| 51552 | SQLITE_PRIVATE sqlite3_file *sqlite3WalFile(Wal *pWal); |
| 51553 | |
| 51554 | #endif /* ifndef SQLITE_OMIT_WAL */ |
| 51555 | #endif /* SQLITE_WAL_H */ |
| 51556 | |
| 51557 | /************** End of wal.h *************************************************/ |
| @@ -57238,11 +57258,10 @@ | |
| 57238 | Pager *pPager; |
| 57239 | assert( pPg!=0 ); |
| 57240 | assert( pPg->pgno==1 ); |
| 57241 | assert( (pPg->flags & PGHDR_MMAP)==0 ); /* Page1 is never memory mapped */ |
| 57242 | pPager = pPg->pPager; |
| 57243 | sqlite3PagerResetLockTimeout(pPager); |
| 57244 | sqlite3PcacheRelease(pPg); |
| 57245 | pagerUnlockIfUnused(pPager); |
| 57246 | } |
| 57247 | |
| 57248 | /* |
| @@ -58531,20 +58550,10 @@ | |
| 58531 | */ |
| 58532 | SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager *pPager){ |
| 58533 | return pPager->fd; |
| 58534 | } |
| 58535 | |
| 58536 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 58537 | /* |
| 58538 | ** Reset the lock timeout for pager. |
| 58539 | */ |
| 58540 | SQLITE_PRIVATE void sqlite3PagerResetLockTimeout(Pager *pPager){ |
| 58541 | int x = 0; |
| 58542 | sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_LOCK_TIMEOUT, &x); |
| 58543 | } |
| 58544 | #endif |
| 58545 | |
| 58546 | /* |
| 58547 | ** Return the file handle for the journal file (if it exists). |
| 58548 | ** This will be either the rollback journal or the WAL file. |
| 58549 | */ |
| 58550 | SQLITE_PRIVATE sqlite3_file *sqlite3PagerJrnlFile(Pager *pPager){ |
| @@ -58954,11 +58963,10 @@ | |
| 58954 | (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler), |
| 58955 | pPager->pBusyHandlerArg, |
| 58956 | pPager->walSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace, |
| 58957 | pnLog, pnCkpt |
| 58958 | ); |
| 58959 | sqlite3PagerResetLockTimeout(pPager); |
| 58960 | } |
| 58961 | return rc; |
| 58962 | } |
| 58963 | |
| 58964 | SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager){ |
| @@ -59119,11 +59127,35 @@ | |
| 59119 | } |
| 59120 | } |
| 59121 | return rc; |
| 59122 | } |
| 59123 | |
| 59124 | |
| 59125 | |
| 59126 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 59127 | /* |
| 59128 | ** If this is a WAL database, obtain a snapshot handle for the snapshot |
| 59129 | ** currently open. Otherwise, return an error. |
| @@ -59139,11 +59171,14 @@ | |
| 59139 | /* |
| 59140 | ** If this is a WAL database, store a pointer to pSnapshot. Next time a |
| 59141 | ** read transaction is opened, attempt to read from the snapshot it |
| 59142 | ** identifies. If this is not a WAL database, return an error. |
| 59143 | */ |
| 59144 | SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot){ |
| 59145 | int rc = SQLITE_OK; |
| 59146 | if( pPager->pWal ){ |
| 59147 | sqlite3WalSnapshotOpen(pPager->pWal, pSnapshot); |
| 59148 | }else{ |
| 59149 | rc = SQLITE_ERROR; |
| @@ -59684,10 +59719,13 @@ | |
| 59684 | u8 lockError; /* True if a locking error has occurred */ |
| 59685 | #endif |
| 59686 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 59687 | WalIndexHdr *pSnapshot; /* Start transaction here if not NULL */ |
| 59688 | #endif |
| 59689 | }; |
| 59690 | |
| 59691 | /* |
| 59692 | ** Candidate values for Wal.exclusiveMode. |
| 59693 | */ |
| @@ -60057,11 +60095,11 @@ | |
| 60057 | if( pWal->exclusiveMode ) return SQLITE_OK; |
| 60058 | rc = sqlite3OsShmLock(pWal->pDbFd, lockIdx, 1, |
| 60059 | SQLITE_SHM_LOCK | SQLITE_SHM_SHARED); |
| 60060 | WALTRACE(("WAL%p: acquire SHARED-%s %s\n", pWal, |
| 60061 | walLockName(lockIdx), rc ? "failed" : "ok")); |
| 60062 | VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && rc!=SQLITE_BUSY); ) |
| 60063 | return rc; |
| 60064 | } |
| 60065 | static void walUnlockShared(Wal *pWal, int lockIdx){ |
| 60066 | if( pWal->exclusiveMode ) return; |
| 60067 | (void)sqlite3OsShmLock(pWal->pDbFd, lockIdx, 1, |
| @@ -60073,11 +60111,11 @@ | |
| 60073 | if( pWal->exclusiveMode ) return SQLITE_OK; |
| 60074 | rc = sqlite3OsShmLock(pWal->pDbFd, lockIdx, n, |
| 60075 | SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE); |
| 60076 | WALTRACE(("WAL%p: acquire EXCLUSIVE-%s cnt=%d %s\n", pWal, |
| 60077 | walLockName(lockIdx), n, rc ? "failed" : "ok")); |
| 60078 | VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && rc!=SQLITE_BUSY); ) |
| 60079 | return rc; |
| 60080 | } |
| 60081 | static void walUnlockExclusive(Wal *pWal, int lockIdx, int n){ |
| 60082 | if( pWal->exclusiveMode ) return; |
| 60083 | (void)sqlite3OsShmLock(pWal->pDbFd, lockIdx, n, |
| @@ -60345,15 +60383,10 @@ | |
| 60345 | int rc; /* Return Code */ |
| 60346 | i64 nSize; /* Size of log file */ |
| 60347 | u32 aFrameCksum[2] = {0, 0}; |
| 60348 | int iLock; /* Lock offset to lock for checkpoint */ |
| 60349 | |
| 60350 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 60351 | int tmout = 0; |
| 60352 | sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout); |
| 60353 | #endif |
| 60354 | |
| 60355 | /* Obtain an exclusive lock on all byte in the locking range not already |
| 60356 | ** locked by the caller. The caller is guaranteed to have locked the |
| 60357 | ** WAL_WRITE_LOCK byte, and may have also locked the WAL_CKPT_LOCK byte. |
| 60358 | ** If successful, the same bytes that are locked here are unlocked before |
| 60359 | ** this function returns. |
| @@ -60897,10 +60930,93 @@ | |
| 60897 | p = 0; |
| 60898 | } |
| 60899 | *pp = p; |
| 60900 | return rc; |
| 60901 | } |
| 60902 | |
| 60903 | /* |
| 60904 | ** Attempt to obtain the exclusive WAL lock defined by parameters lockIdx and |
| 60905 | ** n. If the attempt fails and parameter xBusy is not NULL, then it is a |
| 60906 | ** busy-handler function. Invoke it and retry the lock until either the |
| @@ -60915,10 +61031,16 @@ | |
| 60915 | ){ |
| 60916 | int rc; |
| 60917 | do { |
| 60918 | rc = walLockExclusive(pWal, lockIdx, n); |
| 60919 | }while( xBusy && rc==SQLITE_BUSY && xBusy(pBusyArg) ); |
| 60920 | return rc; |
| 60921 | } |
| 60922 | |
| 60923 | /* |
| 60924 | ** The cache of the wal-index header must be valid to call this function. |
| @@ -61394,32 +61516,36 @@ | |
| 61394 | badHdr = (page0 ? walIndexTryHdr(pWal, pChanged) : 1); |
| 61395 | |
| 61396 | /* If the first attempt failed, it might have been due to a race |
| 61397 | ** with a writer. So get a WRITE lock and try again. |
| 61398 | */ |
| 61399 | assert( badHdr==0 || pWal->writeLock==0 ); |
| 61400 | if( badHdr ){ |
| 61401 | if( pWal->bShmUnreliable==0 && (pWal->readOnly & WAL_SHM_RDONLY) ){ |
| 61402 | if( SQLITE_OK==(rc = walLockShared(pWal, WAL_WRITE_LOCK)) ){ |
| 61403 | walUnlockShared(pWal, WAL_WRITE_LOCK); |
| 61404 | rc = SQLITE_READONLY_RECOVERY; |
| 61405 | } |
| 61406 | }else if( SQLITE_OK==(rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1)) ){ |
| 61407 | pWal->writeLock = 1; |
| 61408 | if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){ |
| 61409 | badHdr = walIndexTryHdr(pWal, pChanged); |
| 61410 | if( badHdr ){ |
| 61411 | /* If the wal-index header is still malformed even while holding |
| 61412 | ** a WRITE lock, it can only mean that the header is corrupted and |
| 61413 | ** needs to be reconstructed. So run recovery to do exactly that. |
| 61414 | */ |
| 61415 | rc = walIndexRecover(pWal); |
| 61416 | *pChanged = 1; |
| 61417 | } |
| 61418 | } |
| 61419 | pWal->writeLock = 0; |
| 61420 | walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1); |
| 61421 | } |
| 61422 | } |
| 61423 | |
| 61424 | /* If the header is read successfully, check the version number to make |
| 61425 | ** sure the wal-index was not constructed with some future format that |
| @@ -61967,26 +62093,38 @@ | |
| 61967 | ** needs to be flushed. |
| 61968 | */ |
| 61969 | SQLITE_PRIVATE int sqlite3WalBeginReadTransaction(Wal *pWal, int *pChanged){ |
| 61970 | int rc; /* Return code */ |
| 61971 | int cnt = 0; /* Number of TryBeginRead attempts */ |
| 61972 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 61973 | int tmout = 0; |
| 61974 | #endif |
| 61975 | |
| 61976 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 61977 | int bChanged = 0; |
| 61978 | WalIndexHdr *pSnapshot = pWal->pSnapshot; |
| 61979 | if( pSnapshot && memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){ |
| 61980 | bChanged = 1; |
| 61981 | } |
| 61982 | #endif |
| 61983 | |
| 61984 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 61985 | /* Disable blocking locks. They are not useful when trying to open a |
| 61986 | ** read-transaction, and blocking may cause deadlock anyway. */ |
| 61987 | sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout); |
| 61988 | #endif |
| 61989 | |
| 61990 | do{ |
| 61991 | rc = walTryBeginRead(pWal, pChanged, 0, ++cnt); |
| 61992 | }while( rc==WAL_RETRY ); |
| @@ -61993,20 +62131,10 @@ | |
| 61993 | testcase( (rc&0xff)==SQLITE_BUSY ); |
| 61994 | testcase( (rc&0xff)==SQLITE_IOERR ); |
| 61995 | testcase( rc==SQLITE_PROTOCOL ); |
| 61996 | testcase( rc==SQLITE_OK ); |
| 61997 | |
| 61998 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 61999 | /* If they were disabled earlier and the read-transaction has been |
| 62000 | ** successfully opened, re-enable blocking locks. This is because the |
| 62001 | ** connection may attempt to upgrade to a write-transaction, which does |
| 62002 | ** benefit from using blocking locks. */ |
| 62003 | if( rc==SQLITE_OK ){ |
| 62004 | sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout); |
| 62005 | } |
| 62006 | #endif |
| 62007 | |
| 62008 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 62009 | if( rc==SQLITE_OK ){ |
| 62010 | if( pSnapshot && memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){ |
| 62011 | /* At this point the client has a lock on an aReadMark[] slot holding |
| 62012 | ** a value equal to or smaller than pSnapshot->mxFrame, but pWal->hdr |
| @@ -62024,52 +62152,46 @@ | |
| 62024 | volatile WalCkptInfo *pInfo = walCkptInfo(pWal); |
| 62025 | |
| 62026 | assert( pWal->readLock>0 || pWal->hdr.mxFrame==0 ); |
| 62027 | assert( pInfo->aReadMark[pWal->readLock]<=pSnapshot->mxFrame ); |
| 62028 | |
| 62029 | /* It is possible that there is a checkpointer thread running |
| 62030 | ** concurrent with this code. If this is the case, it may be that the |
| 62031 | ** checkpointer has already determined that it will checkpoint |
| 62032 | ** snapshot X, where X is later in the wal file than pSnapshot, but |
| 62033 | ** has not yet set the pInfo->nBackfillAttempted variable to indicate |
| 62034 | ** its intent. To avoid the race condition this leads to, ensure that |
| 62035 | ** there is no checkpointer process by taking a shared CKPT lock |
| 62036 | ** before checking pInfo->nBackfillAttempted. |
| 62037 | ** |
| 62038 | ** TODO: Does the aReadMark[] lock prevent a checkpointer from doing |
| 62039 | ** this already? |
| 62040 | */ |
| 62041 | rc = walLockShared(pWal, WAL_CKPT_LOCK); |
| 62042 | |
| 62043 | if( rc==SQLITE_OK ){ |
| 62044 | /* Check that the wal file has not been wrapped. Assuming that it has |
| 62045 | ** not, also check that no checkpointer has attempted to checkpoint any |
| 62046 | ** frames beyond pSnapshot->mxFrame. If either of these conditions are |
| 62047 | ** true, return SQLITE_ERROR_SNAPSHOT. Otherwise, overwrite pWal->hdr |
| 62048 | ** with *pSnapshot and set *pChanged as appropriate for opening the |
| 62049 | ** snapshot. */ |
| 62050 | if( !memcmp(pSnapshot->aSalt, pWal->hdr.aSalt, sizeof(pWal->hdr.aSalt)) |
| 62051 | && pSnapshot->mxFrame>=pInfo->nBackfillAttempted |
| 62052 | ){ |
| 62053 | assert( pWal->readLock>0 ); |
| 62054 | memcpy(&pWal->hdr, pSnapshot, sizeof(WalIndexHdr)); |
| 62055 | *pChanged = bChanged; |
| 62056 | }else{ |
| 62057 | rc = SQLITE_ERROR_SNAPSHOT; |
| 62058 | } |
| 62059 | |
| 62060 | /* Release the shared CKPT lock obtained above. */ |
| 62061 | walUnlockShared(pWal, WAL_CKPT_LOCK); |
| 62062 | pWal->minFrame = 1; |
| 62063 | } |
| 62064 | |
| 62065 | |
| 62066 | if( rc!=SQLITE_OK ){ |
| 62067 | sqlite3WalEndReadTransaction(pWal); |
| 62068 | } |
| 62069 | } |
| 62070 | } |
| 62071 | #endif |
| 62072 | return rc; |
| 62073 | } |
| 62074 | |
| 62075 | /* |
| @@ -62235,10 +62357,20 @@ | |
| 62235 | ** |
| 62236 | ** There can only be a single writer active at a time. |
| 62237 | */ |
| 62238 | SQLITE_PRIVATE int sqlite3WalBeginWriteTransaction(Wal *pWal){ |
| 62239 | int rc; |
| 62240 | |
| 62241 | /* Cannot start a write transaction without first holding a read |
| 62242 | ** transaction. */ |
| 62243 | assert( pWal->readLock>=0 ); |
| 62244 | assert( pWal->writeLock==0 && pWal->iReCksum==0 ); |
| @@ -62811,50 +62943,57 @@ | |
| 62811 | ** in the SQLITE_CHECKPOINT_PASSIVE mode. */ |
| 62812 | assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 ); |
| 62813 | |
| 62814 | if( pWal->readOnly ) return SQLITE_READONLY; |
| 62815 | WALTRACE(("WAL%p: checkpoint begins\n", pWal)); |
| 62816 | |
| 62817 | /* IMPLEMENTATION-OF: R-62028-47212 All calls obtain an exclusive |
| 62818 | ** "checkpoint" lock on the database file. */ |
| 62819 | rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1); |
| 62820 | if( rc ){ |
| 62821 | /* EVIDENCE-OF: R-10421-19736 If any other process is running a |
| 62822 | ** checkpoint operation at the same time, the lock cannot be obtained and |
| 62823 | ** SQLITE_BUSY is returned. |
| 62824 | ** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured, |
| 62825 | ** it will not be invoked in this case. |
| 62826 | */ |
| 62827 | testcase( rc==SQLITE_BUSY ); |
| 62828 | testcase( xBusy!=0 ); |
| 62829 | return rc; |
| 62830 | } |
| 62831 | pWal->ckptLock = 1; |
| 62832 | |
| 62833 | /* IMPLEMENTATION-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART and |
| 62834 | ** TRUNCATE modes also obtain the exclusive "writer" lock on the database |
| 62835 | ** file. |
| 62836 | ** |
| 62837 | ** EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained |
| 62838 | ** immediately, and a busy-handler is configured, it is invoked and the |
| 62839 | ** writer lock retried until either the busy-handler returns 0 or the |
| 62840 | ** lock is successfully obtained. |
| 62841 | */ |
| 62842 | if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){ |
| 62843 | rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_WRITE_LOCK, 1); |
| 62844 | if( rc==SQLITE_OK ){ |
| 62845 | pWal->writeLock = 1; |
| 62846 | }else if( rc==SQLITE_BUSY ){ |
| 62847 | eMode2 = SQLITE_CHECKPOINT_PASSIVE; |
| 62848 | xBusy2 = 0; |
| 62849 | rc = SQLITE_OK; |
| 62850 | } |
| 62851 | } |
| 62852 | |
| 62853 | /* Read the wal-index header. */ |
| 62854 | if( rc==SQLITE_OK ){ |
| 62855 | rc = walIndexReadHdr(pWal, &isChanged); |
| 62856 | if( isChanged && pWal->pDbFd->pMethods->iVersion>=3 ){ |
| 62857 | sqlite3OsUnfetch(pWal->pDbFd, 0, 0); |
| 62858 | } |
| 62859 | } |
| 62860 | |
| @@ -62881,16 +63020,24 @@ | |
| 62881 | ** next time the pager opens a snapshot on this database it knows that |
| 62882 | ** the cache needs to be reset. |
| 62883 | */ |
| 62884 | memset(&pWal->hdr, 0, sizeof(WalIndexHdr)); |
| 62885 | } |
| 62886 | |
| 62887 | /* Release the locks. */ |
| 62888 | sqlite3WalEndWriteTransaction(pWal); |
| 62889 | walUnlockExclusive(pWal, WAL_CKPT_LOCK, 1); |
| 62890 | pWal->ckptLock = 0; |
| 62891 | WALTRACE(("WAL%p: checkpoint %s\n", pWal, rc ? "failed" : "ok")); |
| 62892 | return (rc==SQLITE_OK && eMode!=eMode2 ? SQLITE_BUSY : rc); |
| 62893 | } |
| 62894 | |
| 62895 | /* Return the value to pass to a sqlite3_wal_hook callback, the |
| 62896 | ** number of frames in the WAL at the point of the last commit since |
| @@ -63003,11 +63150,14 @@ | |
| 63003 | return rc; |
| 63004 | } |
| 63005 | |
| 63006 | /* Try to open on pSnapshot when the next read-transaction starts |
| 63007 | */ |
| 63008 | SQLITE_PRIVATE void sqlite3WalSnapshotOpen(Wal *pWal, sqlite3_snapshot *pSnapshot){ |
| 63009 | pWal->pSnapshot = (WalIndexHdr*)pSnapshot; |
| 63010 | } |
| 63011 | |
| 63012 | /* |
| 63013 | ** Return a +ve value if snapshot p1 is newer than p2. A -ve value if |
| @@ -63522,11 +63672,11 @@ | |
| 63522 | u8 incrVacuum; /* True if incr-vacuum is enabled */ |
| 63523 | u8 bDoTruncate; /* True to truncate db on commit */ |
| 63524 | #endif |
| 63525 | u8 inTransaction; /* Transaction state */ |
| 63526 | u8 max1bytePayload; /* Maximum first byte of cell for a 1-byte payload */ |
| 63527 | u8 nReserveWanted; /* 1 more than desired number of extra bytes per page */ |
| 63528 | u16 btsFlags; /* Boolean parameters. See BTS_* macros below */ |
| 63529 | u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */ |
| 63530 | u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */ |
| 63531 | u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */ |
| 63532 | u16 minLeaf; /* Minimum local payload in a LEAFDATA table */ |
| @@ -66416,12 +66566,11 @@ | |
| 66416 | */ |
| 66417 | static int btreeInvokeBusyHandler(void *pArg){ |
| 66418 | BtShared *pBt = (BtShared*)pArg; |
| 66419 | assert( pBt->db ); |
| 66420 | assert( sqlite3_mutex_held(pBt->db->mutex) ); |
| 66421 | return sqlite3InvokeBusyHandler(&pBt->db->busyHandler, |
| 66422 | sqlite3PagerFile(pBt->pPager)); |
| 66423 | } |
| 66424 | |
| 66425 | /* |
| 66426 | ** Open a database file. |
| 66427 | ** |
| @@ -66968,23 +67117,21 @@ | |
| 66968 | ** If the iFix!=0 then the BTS_PAGESIZE_FIXED flag is set so that the page size |
| 66969 | ** and autovacuum mode can no longer be changed. |
| 66970 | */ |
| 66971 | SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve, int iFix){ |
| 66972 | int rc = SQLITE_OK; |
| 66973 | BtShared *pBt = p->pBt; |
| 66974 | assert( nReserve>=-1 && nReserve<=254 ); |
| 66975 | sqlite3BtreeEnter(p); |
| 66976 | if( nReserve>=0 ){ |
| 66977 | pBt->nReserveWanted = nReserve + 1; |
| 66978 | } |
| 66979 | if( pBt->btsFlags & BTS_PAGESIZE_FIXED ){ |
| 66980 | sqlite3BtreeLeave(p); |
| 66981 | return SQLITE_READONLY; |
| 66982 | } |
| 66983 | if( nReserve<0 ){ |
| 66984 | nReserve = pBt->pageSize - pBt->usableSize; |
| 66985 | } |
| 66986 | assert( nReserve>=0 && nReserve<=255 ); |
| 66987 | if( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE && |
| 66988 | ((pageSize-1)&pageSize)==0 ){ |
| 66989 | assert( (pageSize & 7)==0 ); |
| 66990 | assert( !pBt->pCursor ); |
| @@ -67031,16 +67178,16 @@ | |
| 67031 | ** The value returned is the larger of the current reserve size and |
| 67032 | ** the latest reserve size requested by SQLITE_FILECTRL_RESERVE_BYTES. |
| 67033 | ** The amount of reserve can only grow - never shrink. |
| 67034 | */ |
| 67035 | SQLITE_PRIVATE int sqlite3BtreeGetRequestedReserve(Btree *p){ |
| 67036 | int n; |
| 67037 | sqlite3BtreeEnter(p); |
| 67038 | n = ((int)p->pBt->nReserveWanted) - 1; |
| 67039 | if( n<0 ) n = sqlite3BtreeGetReserveNoMutex(p); |
| 67040 | sqlite3BtreeLeave(p); |
| 67041 | return n; |
| 67042 | } |
| 67043 | |
| 67044 | |
| 67045 | /* |
| 67046 | ** Set the maximum page count for a database if mxPage is positive. |
| @@ -67486,10 +67633,11 @@ | |
| 67486 | ** when A already has a read lock, we encourage A to give up and let B |
| 67487 | ** proceed. |
| 67488 | */ |
| 67489 | SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){ |
| 67490 | BtShared *pBt = p->pBt; |
| 67491 | int rc = SQLITE_OK; |
| 67492 | |
| 67493 | sqlite3BtreeEnter(p); |
| 67494 | btreeIntegrity(p); |
| 67495 | |
| @@ -67501,11 +67649,11 @@ | |
| 67501 | goto trans_begun; |
| 67502 | } |
| 67503 | assert( pBt->inTransaction==TRANS_WRITE || IfNotOmitAV(pBt->bDoTruncate)==0 ); |
| 67504 | |
| 67505 | if( (p->db->flags & SQLITE_ResetDatabase) |
| 67506 | && sqlite3PagerIsreadonly(pBt->pPager)==0 |
| 67507 | ){ |
| 67508 | pBt->btsFlags &= ~BTS_READ_ONLY; |
| 67509 | } |
| 67510 | |
| 67511 | /* Write transactions are not possible on a read-only database */ |
| @@ -67549,10 +67697,22 @@ | |
| 67549 | if( SQLITE_OK!=rc ) goto trans_begun; |
| 67550 | |
| 67551 | pBt->btsFlags &= ~BTS_INITIALLY_EMPTY; |
| 67552 | if( pBt->nPage==0 ) pBt->btsFlags |= BTS_INITIALLY_EMPTY; |
| 67553 | do { |
| 67554 | /* Call lockBtree() until either pBt->pPage1 is populated or |
| 67555 | ** lockBtree() returns something other than SQLITE_OK. lockBtree() |
| 67556 | ** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after |
| 67557 | ** reading page 1 it discovers that the page-size of the database |
| 67558 | ** file is not pBt->pageSize. In this case lockBtree() will update |
| @@ -67562,11 +67722,11 @@ | |
| 67562 | |
| 67563 | if( rc==SQLITE_OK && wrflag ){ |
| 67564 | if( (pBt->btsFlags & BTS_READ_ONLY)!=0 ){ |
| 67565 | rc = SQLITE_READONLY; |
| 67566 | }else{ |
| 67567 | rc = sqlite3PagerBegin(pBt->pPager,wrflag>1,sqlite3TempInMemory(p->db)); |
| 67568 | if( rc==SQLITE_OK ){ |
| 67569 | rc = newDatabase(pBt); |
| 67570 | }else if( rc==SQLITE_BUSY_SNAPSHOT && pBt->inTransaction==TRANS_NONE ){ |
| 67571 | /* if there was no transaction opened when this function was |
| 67572 | ** called and SQLITE_BUSY_SNAPSHOT is returned, change the error |
| @@ -67575,15 +67735,19 @@ | |
| 67575 | } |
| 67576 | } |
| 67577 | } |
| 67578 | |
| 67579 | if( rc!=SQLITE_OK ){ |
| 67580 | unlockBtreeIfUnused(pBt); |
| 67581 | } |
| 67582 | }while( (rc&0xFF)==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE && |
| 67583 | btreeInvokeBusyHandler(pBt) ); |
| 67584 | sqlite3PagerResetLockTimeout(pBt->pPager); |
| 67585 | |
| 67586 | if( rc==SQLITE_OK ){ |
| 67587 | if( p->inTrans==TRANS_NONE ){ |
| 67588 | pBt->nTransaction++; |
| 67589 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| @@ -67631,11 +67795,11 @@ | |
| 67631 | if( wrflag ){ |
| 67632 | /* This call makes sure that the pager has the correct number of |
| 67633 | ** open savepoints. If the second parameter is greater than 0 and |
| 67634 | ** the sub-journal is not already open, then it will be opened here. |
| 67635 | */ |
| 67636 | rc = sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint); |
| 67637 | } |
| 67638 | } |
| 67639 | |
| 67640 | btreeIntegrity(p); |
| 67641 | sqlite3BtreeLeave(p); |
| @@ -71267,11 +71431,11 @@ | |
| 71267 | |
| 71268 | /* Remove cells from the start and end of the page */ |
| 71269 | assert( nCell>=0 ); |
| 71270 | if( iOld<iNew ){ |
| 71271 | int nShift = pageFreeArray(pPg, iOld, iNew-iOld, pCArray); |
| 71272 | if( nShift>nCell ) return SQLITE_CORRUPT_BKPT; |
| 71273 | memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2); |
| 71274 | nCell -= nShift; |
| 71275 | } |
| 71276 | if( iNewEnd < iOldEnd ){ |
| 71277 | int nTail = pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray); |
| @@ -74746,11 +74910,11 @@ | |
| 74746 | ** Attempt to set the page size of the destination to match the page size |
| 74747 | ** of the source. |
| 74748 | */ |
| 74749 | static int setDestPgsz(sqlite3_backup *p){ |
| 74750 | int rc; |
| 74751 | rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),-1,0); |
| 74752 | return rc; |
| 74753 | } |
| 74754 | |
| 74755 | /* |
| 74756 | ** Check that there is no open read-transaction on the b-tree passed as the |
| @@ -90540,16 +90704,23 @@ | |
| 90540 | rc = sqlite3VdbeSorterWrite(pC, pIn2); |
| 90541 | if( rc) goto abort_due_to_error; |
| 90542 | break; |
| 90543 | } |
| 90544 | |
| 90545 | /* Opcode: IdxDelete P1 P2 P3 * * |
| 90546 | ** Synopsis: key=r[P2@P3] |
| 90547 | ** |
| 90548 | ** The content of P3 registers starting at register P2 form |
| 90549 | ** an unpacked index key. This opcode removes that entry from the |
| 90550 | ** index opened by cursor P1. |
| 90551 | */ |
| 90552 | case OP_IdxDelete: { |
| 90553 | VdbeCursor *pC; |
| 90554 | BtCursor *pCrsr; |
| 90555 | int res; |
| @@ -90562,20 +90733,22 @@ | |
| 90562 | assert( pC!=0 ); |
| 90563 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 90564 | sqlite3VdbeIncrWriteCounter(p, pC); |
| 90565 | pCrsr = pC->uc.pCursor; |
| 90566 | assert( pCrsr!=0 ); |
| 90567 | assert( pOp->p5==0 ); |
| 90568 | r.pKeyInfo = pC->pKeyInfo; |
| 90569 | r.nField = (u16)pOp->p3; |
| 90570 | r.default_rc = 0; |
| 90571 | r.aMem = &aMem[pOp->p2]; |
| 90572 | rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res); |
| 90573 | if( rc ) goto abort_due_to_error; |
| 90574 | if( res==0 ){ |
| 90575 | rc = sqlite3BtreeDelete(pCrsr, BTREE_AUXDELETE); |
| 90576 | if( rc ) goto abort_due_to_error; |
| 90577 | } |
| 90578 | assert( pC->deferredMoveto==0 ); |
| 90579 | pC->cacheStatus = CACHE_STALE; |
| 90580 | pC->seekResult = 0; |
| 90581 | break; |
| @@ -103684,11 +103857,11 @@ | |
| 103684 | assert( pExpr->affExpr==OE_Rollback |
| 103685 | || pExpr->affExpr==OE_Abort |
| 103686 | || pExpr->affExpr==OE_Fail |
| 103687 | || pExpr->affExpr==OE_Ignore |
| 103688 | ); |
| 103689 | if( !pParse->pTriggerTab ){ |
| 103690 | sqlite3ErrorMsg(pParse, |
| 103691 | "RAISE() may only be used within a trigger-program"); |
| 103692 | return 0; |
| 103693 | } |
| 103694 | if( pExpr->affExpr==OE_Abort ){ |
| @@ -103698,12 +103871,13 @@ | |
| 103698 | if( pExpr->affExpr==OE_Ignore ){ |
| 103699 | sqlite3VdbeAddOp4( |
| 103700 | v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0); |
| 103701 | VdbeCoverage(v); |
| 103702 | }else{ |
| 103703 | sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_TRIGGER, |
| 103704 | pExpr->affExpr, pExpr->u.zToken, 0, 0); |
| 103705 | } |
| 103706 | |
| 103707 | break; |
| 103708 | } |
| 103709 | #endif |
| @@ -105454,10 +105628,26 @@ | |
| 105454 | exit_rename_table: |
| 105455 | sqlite3SrcListDelete(db, pSrc); |
| 105456 | sqlite3DbFree(db, zName); |
| 105457 | db->mDbFlags = savedDbFlags; |
| 105458 | } |
| 105459 | |
| 105460 | /* |
| 105461 | ** This function is called after an "ALTER TABLE ... ADD" statement |
| 105462 | ** has been parsed. Argument pColDef contains the text of the new |
| 105463 | ** column definition. |
| @@ -105507,11 +105697,12 @@ | |
| 105507 | if( pCol->colFlags & COLFLAG_PRIMKEY ){ |
| 105508 | sqlite3ErrorMsg(pParse, "Cannot add a PRIMARY KEY column"); |
| 105509 | return; |
| 105510 | } |
| 105511 | if( pNew->pIndex ){ |
| 105512 | sqlite3ErrorMsg(pParse, "Cannot add a UNIQUE column"); |
| 105513 | return; |
| 105514 | } |
| 105515 | if( (pCol->colFlags & COLFLAG_GENERATED)==0 ){ |
| 105516 | /* If the default value for the new column was specified with a |
| 105517 | ** literal NULL, then set pDflt to 0. This simplifies checking |
| @@ -105520,19 +105711,18 @@ | |
| 105520 | assert( pDflt==0 || pDflt->op==TK_SPAN ); |
| 105521 | if( pDflt && pDflt->pLeft->op==TK_NULL ){ |
| 105522 | pDflt = 0; |
| 105523 | } |
| 105524 | if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){ |
| 105525 | sqlite3ErrorMsg(pParse, |
| 105526 | "Cannot add a REFERENCES column with non-NULL default value"); |
| 105527 | return; |
| 105528 | } |
| 105529 | if( pCol->notNull && !pDflt ){ |
| 105530 | sqlite3ErrorMsg(pParse, |
| 105531 | "Cannot add a NOT NULL column with default value NULL"); |
| 105532 | return; |
| 105533 | } |
| 105534 | |
| 105535 | /* Ensure the default expression is something that sqlite3ValueFromExpr() |
| 105536 | ** can handle (i.e. not CURRENT_TIME etc.) |
| 105537 | */ |
| 105538 | if( pDflt ){ |
| @@ -105543,18 +105733,17 @@ | |
| 105543 | if( rc!=SQLITE_OK ){ |
| 105544 | assert( db->mallocFailed == 1 ); |
| 105545 | return; |
| 105546 | } |
| 105547 | if( !pVal ){ |
| 105548 | sqlite3ErrorMsg(pParse,"Cannot add a column with non-constant default"); |
| 105549 | return; |
| 105550 | } |
| 105551 | sqlite3ValueFree(pVal); |
| 105552 | } |
| 105553 | }else if( pCol->colFlags & COLFLAG_STORED ){ |
| 105554 | sqlite3ErrorMsg(pParse, "cannot add a STORED column"); |
| 105555 | return; |
| 105556 | } |
| 105557 | |
| 105558 | |
| 105559 | /* Modify the CREATE TABLE statement. */ |
| 105560 | zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n); |
| @@ -114373,11 +114562,11 @@ | |
| 114373 | pParse->rc = rc; |
| 114374 | return 1; |
| 114375 | } |
| 114376 | db->aDb[1].pBt = pBt; |
| 114377 | assert( db->aDb[1].pSchema ); |
| 114378 | if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){ |
| 114379 | sqlite3OomFault(db); |
| 114380 | return 1; |
| 114381 | } |
| 114382 | } |
| 114383 | return 0; |
| @@ -114484,11 +114673,11 @@ | |
| 114484 | char *p4, /* Error message */ |
| 114485 | i8 p4type, /* P4_STATIC or P4_TRANSIENT */ |
| 114486 | u8 p5Errmsg /* P5_ErrMsg type */ |
| 114487 | ){ |
| 114488 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 114489 | assert( (errCode&0xff)==SQLITE_CONSTRAINT ); |
| 114490 | if( onError==OE_Abort ){ |
| 114491 | sqlite3MayAbort(pParse); |
| 114492 | } |
| 114493 | sqlite3VdbeAddOp4(v, OP_Halt, errCode, onError, 0, p4, p4type); |
| 114494 | sqlite3VdbeChangeP5(v, p5Errmsg); |
| @@ -116197,10 +116386,11 @@ | |
| 116197 | VdbeModuleComment((v, "GenRowIdxDel for %s", pIdx->zName)); |
| 116198 | r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 1, |
| 116199 | &iPartIdxLabel, pPrior, r1); |
| 116200 | sqlite3VdbeAddOp3(v, OP_IdxDelete, iIdxCur+i, r1, |
| 116201 | pIdx->uniqNotNull ? pIdx->nKeyCol : pIdx->nColumn); |
| 116202 | sqlite3ResolvePartIdxLabel(pParse, iPartIdxLabel); |
| 116203 | pPrior = pIdx; |
| 116204 | } |
| 116205 | } |
| 116206 | |
| @@ -125555,11 +125745,11 @@ | |
| 125555 | }else{ |
| 125556 | /* Malloc may fail when setting the page-size, as there is an internal |
| 125557 | ** buffer that the pager module resizes using sqlite3_realloc(). |
| 125558 | */ |
| 125559 | db->nextPagesize = sqlite3Atoi(zRight); |
| 125560 | if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){ |
| 125561 | sqlite3OomFault(db); |
| 125562 | } |
| 125563 | } |
| 125564 | break; |
| 125565 | } |
| @@ -135193,17 +135383,19 @@ | |
| 135193 | ** |
| 135194 | ** In practice the KeyInfo structure will not be used. It is only |
| 135195 | ** passed to keep OP_OpenRead happy. |
| 135196 | */ |
| 135197 | if( !HasRowid(pTab) ) pBest = sqlite3PrimaryKeyIndex(pTab); |
| 135198 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 135199 | if( pIdx->bUnordered==0 |
| 135200 | && pIdx->szIdxRow<pTab->szTabRow |
| 135201 | && pIdx->pPartIdxWhere==0 |
| 135202 | && (!pBest || pIdx->szIdxRow<pBest->szIdxRow) |
| 135203 | ){ |
| 135204 | pBest = pIdx; |
| 135205 | } |
| 135206 | } |
| 135207 | if( pBest ){ |
| 135208 | iRoot = pBest->tnum; |
| 135209 | pKeyInfo = sqlite3KeyInfoOfIndex(pParse, pBest); |
| @@ -138439,11 +138631,11 @@ | |
| 138439 | db->mDbFlags = saved_mDbFlags; |
| 138440 | db->flags = saved_flags; |
| 138441 | db->nChange = saved_nChange; |
| 138442 | db->nTotalChange = saved_nTotalChange; |
| 138443 | db->mTrace = saved_mTrace; |
| 138444 | sqlite3BtreeSetPageSize(pMain, -1, -1, 1); |
| 138445 | |
| 138446 | /* Currently there is an SQL level transaction open on the vacuum |
| 138447 | ** database. No locks are held on any other files (since the main file |
| 138448 | ** was committed at the btree level). So it safe to end the transaction |
| 138449 | ** by manually setting the autoCommit flag to true and detaching the |
| @@ -161431,12 +161623,11 @@ | |
| 161431 | ** Return non-zero to retry the lock. Return zero to stop trying |
| 161432 | ** and cause SQLite to return SQLITE_BUSY. |
| 161433 | */ |
| 161434 | static int sqliteDefaultBusyCallback( |
| 161435 | void *ptr, /* Database connection */ |
| 161436 | int count, /* Number of times table has been busy */ |
| 161437 | sqlite3_file *pFile /* The file on which the lock occurred */ |
| 161438 | ){ |
| 161439 | #if SQLITE_OS_WIN || HAVE_USLEEP |
| 161440 | /* This case is for systems that have support for sleeping for fractions of |
| 161441 | ** a second. Examples: All windows systems, unix systems with usleep() */ |
| 161442 | static const u8 delays[] = |
| @@ -161446,35 +161637,10 @@ | |
| 161446 | # define NDELAY ArraySize(delays) |
| 161447 | sqlite3 *db = (sqlite3 *)ptr; |
| 161448 | int tmout = db->busyTimeout; |
| 161449 | int delay, prior; |
| 161450 | |
| 161451 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 161452 | if( sqlite3OsFileControl(pFile,SQLITE_FCNTL_LOCK_TIMEOUT,&tmout)==SQLITE_OK ){ |
| 161453 | if( count ){ |
| 161454 | /* If this is the second or later invocation of the busy-handler, |
| 161455 | ** but tmout==0, then code in wal.c must have disabled the blocking |
| 161456 | ** lock before the SQLITE_BUSY error was hit. In this case, no delay |
| 161457 | ** occurred while waiting for the lock, so fall through to the xSleep() |
| 161458 | ** code below to delay a while before retrying the lock. |
| 161459 | ** |
| 161460 | ** Alternatively, if tmout!=0, then SQLite has already waited |
| 161461 | ** sqlite3.busyTimeout ms for a lock. In this case, return 0 to |
| 161462 | ** indicate that the lock should not be retried and the SQLITE_BUSY |
| 161463 | ** error returned to the application. */ |
| 161464 | if( tmout ){ |
| 161465 | tmout = 0; |
| 161466 | sqlite3OsFileControl(pFile, SQLITE_FCNTL_LOCK_TIMEOUT, &tmout); |
| 161467 | return 0; |
| 161468 | } |
| 161469 | }else{ |
| 161470 | return 1; |
| 161471 | } |
| 161472 | } |
| 161473 | #else |
| 161474 | UNUSED_PARAMETER(pFile); |
| 161475 | #endif |
| 161476 | assert( count>=0 ); |
| 161477 | if( count < NDELAY ){ |
| 161478 | delay = delays[count]; |
| 161479 | prior = totals[count]; |
| 161480 | }else{ |
| @@ -161490,11 +161656,10 @@ | |
| 161490 | #else |
| 161491 | /* This case for unix systems that lack usleep() support. Sleeping |
| 161492 | ** must be done in increments of whole seconds */ |
| 161493 | sqlite3 *db = (sqlite3 *)ptr; |
| 161494 | int tmout = ((sqlite3 *)ptr)->busyTimeout; |
| 161495 | UNUSED_PARAMETER(pFile); |
| 161496 | if( (count+1)*1000 > tmout ){ |
| 161497 | return 0; |
| 161498 | } |
| 161499 | sqlite3OsSleep(db->pVfs, 1000000); |
| 161500 | return 1; |
| @@ -161508,23 +161673,14 @@ | |
| 161508 | ** lock on VFS file pFile. |
| 161509 | ** |
| 161510 | ** If this routine returns non-zero, the lock is retried. If it |
| 161511 | ** returns 0, the operation aborts with an SQLITE_BUSY error. |
| 161512 | */ |
| 161513 | SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler *p, sqlite3_file *pFile){ |
| 161514 | int rc; |
| 161515 | if( p->xBusyHandler==0 || p->nBusy<0 ) return 0; |
| 161516 | if( p->bExtraFileArg ){ |
| 161517 | /* Add an extra parameter with the pFile pointer to the end of the |
| 161518 | ** callback argument list */ |
| 161519 | int (*xTra)(void*,int,sqlite3_file*); |
| 161520 | xTra = (int(*)(void*,int,sqlite3_file*))p->xBusyHandler; |
| 161521 | rc = xTra(p->pBusyArg, p->nBusy, pFile); |
| 161522 | }else{ |
| 161523 | /* Legacy style busy handler callback */ |
| 161524 | rc = p->xBusyHandler(p->pBusyArg, p->nBusy); |
| 161525 | } |
| 161526 | if( rc==0 ){ |
| 161527 | p->nBusy = -1; |
| 161528 | }else{ |
| 161529 | p->nBusy++; |
| 161530 | } |
| @@ -161545,11 +161701,10 @@ | |
| 161545 | #endif |
| 161546 | sqlite3_mutex_enter(db->mutex); |
| 161547 | db->busyHandler.xBusyHandler = xBusy; |
| 161548 | db->busyHandler.pBusyArg = pArg; |
| 161549 | db->busyHandler.nBusy = 0; |
| 161550 | db->busyHandler.bExtraFileArg = 0; |
| 161551 | db->busyTimeout = 0; |
| 161552 | sqlite3_mutex_leave(db->mutex); |
| 161553 | return SQLITE_OK; |
| 161554 | } |
| 161555 | |
| @@ -161596,11 +161751,10 @@ | |
| 161596 | #endif |
| 161597 | if( ms>0 ){ |
| 161598 | sqlite3_busy_handler(db, (int(*)(void*,int))sqliteDefaultBusyCallback, |
| 161599 | (void*)db); |
| 161600 | db->busyTimeout = ms; |
| 161601 | db->busyHandler.bExtraFileArg = 1; |
| 161602 | }else{ |
| 161603 | sqlite3_busy_handler(db, 0, 0); |
| 161604 | } |
| 161605 | return SQLITE_OK; |
| 161606 | } |
| @@ -163071,10 +163225,13 @@ | |
| 163071 | | SQLITE_EnableQPSG |
| 163072 | #endif |
| 163073 | #if defined(SQLITE_DEFAULT_DEFENSIVE) |
| 163074 | | SQLITE_Defensive |
| 163075 | #endif |
| 163076 | ; |
| 163077 | sqlite3HashInit(&db->aCollSeq); |
| 163078 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 163079 | sqlite3HashInit(&db->aModule); |
| 163080 | #endif |
| @@ -163668,11 +163825,11 @@ | |
| 163668 | *(unsigned int*)pArg = sqlite3PagerDataVersion(pPager); |
| 163669 | rc = SQLITE_OK; |
| 163670 | }else if( op==SQLITE_FCNTL_RESERVE_BYTES ){ |
| 163671 | int iNew = *(int*)pArg; |
| 163672 | *(int*)pArg = sqlite3BtreeGetRequestedReserve(pBtree); |
| 163673 | if( iNew>=0 && iNew<=254 ){ |
| 163674 | sqlite3BtreeSetPageSize(pBtree, 0, iNew, 0); |
| 163675 | } |
| 163676 | rc = SQLITE_OK; |
| 163677 | }else{ |
| 163678 | rc = sqlite3OsFileControl(fd, op, pArg); |
| @@ -167905,11 +168062,13 @@ | |
| 167905 | static void fts3ReadNextPos( |
| 167906 | char **pp, /* IN/OUT: Pointer into position-list buffer */ |
| 167907 | sqlite3_int64 *pi /* IN/OUT: Value read from position-list */ |
| 167908 | ){ |
| 167909 | if( (**pp)&0xFE ){ |
| 167910 | fts3GetDeltaVarint(pp, pi); |
| 167911 | *pi -= 2; |
| 167912 | }else{ |
| 167913 | *pi = POSITION_LIST_END; |
| 167914 | } |
| 167915 | } |
| @@ -224505,11 +224664,11 @@ | |
| 224505 | int nArg, /* Number of args */ |
| 224506 | sqlite3_value **apUnused /* Function arguments */ |
| 224507 | ){ |
| 224508 | assert( nArg==0 ); |
| 224509 | UNUSED_PARAM2(nArg, apUnused); |
| 224510 | sqlite3_result_text(pCtx, "fts5: 2020-05-04 19:52:00 8eee591d3cb9fadfd5cac5543bd66ef9cb371a72d3ad3241fb3bfd67fb216eda", -1, SQLITE_TRANSIENT); |
| 224511 | } |
| 224512 | |
| 224513 | /* |
| 224514 | ** Return true if zName is the extension on one of the shadow tables used |
| 224515 | ** by this module. |
| @@ -229288,12 +229447,12 @@ | |
| 229288 | } |
| 229289 | #endif /* SQLITE_CORE */ |
| 229290 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 229291 | |
| 229292 | /************** End of stmt.c ************************************************/ |
| 229293 | #if __LINE__!=229293 |
| 229294 | #undef SQLITE_SOURCE_ID |
| 229295 | #define SQLITE_SOURCE_ID "2020-05-04 19:52:00 8eee591d3cb9fadfd5cac5543bd66ef9cb371a72d3ad3241fb3bfd67fb21alt2" |
| 229296 | #endif |
| 229297 | /* Return the source-id for this library */ |
| 229298 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 229299 | /************************** End of sqlite3.c ******************************/ |
| 229300 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1162,11 +1162,11 @@ | |
| 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1164 | */ |
| 1165 | #define SQLITE_VERSION "3.32.0" |
| 1166 | #define SQLITE_VERSION_NUMBER 3032000 |
| 1167 | #define SQLITE_SOURCE_ID "2020-05-08 19:02:21 3a16c0ce4d8851f79f670d94786032c8007619154ece44647dc9cc5b1f9654ff" |
| 1168 | |
| 1169 | /* |
| 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1172 | ** |
| @@ -1545,18 +1545,20 @@ | |
| 1545 | #define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8)) |
| 1546 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 1547 | #define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8)) |
| 1548 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 1549 | #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8)) |
| 1550 | #define SQLITE_BUSY_TIMEOUT (SQLITE_BUSY | (3<<8)) |
| 1551 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 1552 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 1553 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 1554 | #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) |
| 1555 | #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */ |
| 1556 | #define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8)) |
| 1557 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 1558 | #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8)) |
| 1559 | #define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8)) |
| 1560 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 1561 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 1562 | #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) |
| 1563 | #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) |
| 1564 | #define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8)) |
| @@ -14535,11 +14537,10 @@ | |
| 14537 | typedef struct BusyHandler BusyHandler; |
| 14538 | struct BusyHandler { |
| 14539 | int (*xBusyHandler)(void *,int); /* The busy callback */ |
| 14540 | void *pBusyArg; /* First arg to busy callback */ |
| 14541 | int nBusy; /* Incremented with each busy call */ |
| 14542 | }; |
| 14543 | |
| 14544 | /* |
| 14545 | ** Name of the master database table. The master database table |
| 14546 | ** is a special table that holds the names and attributes of all |
| @@ -15918,17 +15919,25 @@ | |
| 15919 | SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager); |
| 15920 | SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager); |
| 15921 | SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen); |
| 15922 | SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3*); |
| 15923 | # ifdef SQLITE_ENABLE_SNAPSHOT |
| 15924 | SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager*, sqlite3_snapshot **ppSnapshot); |
| 15925 | SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager*, sqlite3_snapshot *pSnapshot); |
| 15926 | SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager); |
| 15927 | SQLITE_PRIVATE int sqlite3PagerSnapshotCheck(Pager *pPager, sqlite3_snapshot *pSnapshot); |
| 15928 | SQLITE_PRIVATE void sqlite3PagerSnapshotUnlock(Pager *pPager); |
| 15929 | # endif |
| 15930 | #endif |
| 15931 | |
| 15932 | #if !defined(SQLITE_OMIT_WAL) && defined(SQLITE_ENABLE_SETLK_TIMEOUT) |
| 15933 | SQLITE_PRIVATE int sqlite3PagerWalWriteLock(Pager*, int); |
| 15934 | SQLITE_PRIVATE void sqlite3PagerWalDb(Pager*, sqlite3*); |
| 15935 | #else |
| 15936 | # define sqlite3PagerWalWriteLock(y,z) SQLITE_OK |
| 15937 | # define sqlite3PagerWalDb(x,y) |
| 15938 | #endif |
| 15939 | |
| 15940 | #ifdef SQLITE_DIRECT_OVERFLOW_READ |
| 15941 | SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno); |
| 15942 | #endif |
| 15943 | |
| @@ -15951,15 +15960,10 @@ | |
| 15960 | SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*); |
| 15961 | SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*); |
| 15962 | SQLITE_PRIVATE void sqlite3PagerCacheStat(Pager *, int, int, int *); |
| 15963 | SQLITE_PRIVATE void sqlite3PagerClearCache(Pager*); |
| 15964 | SQLITE_PRIVATE int sqlite3SectorSize(sqlite3_file *); |
| 15965 | |
| 15966 | /* Functions used to truncate the database file. */ |
| 15967 | SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno); |
| 15968 | |
| 15969 | SQLITE_PRIVATE void sqlite3PagerRekey(DbPage*, Pgno, u16); |
| @@ -19935,11 +19939,11 @@ | |
| 19939 | SQLITE_PRIVATE void sqlite3RenameExprUnmap(Parse*, Expr*); |
| 19940 | SQLITE_PRIVATE void sqlite3RenameExprlistUnmap(Parse*, ExprList*); |
| 19941 | SQLITE_PRIVATE CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*); |
| 19942 | SQLITE_PRIVATE char sqlite3AffinityType(const char*, Column*); |
| 19943 | SQLITE_PRIVATE void sqlite3Analyze(Parse*, Token*, Token*); |
| 19944 | SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler*); |
| 19945 | SQLITE_PRIVATE int sqlite3FindDb(sqlite3*, Token*); |
| 19946 | SQLITE_PRIVATE int sqlite3FindDbName(sqlite3 *, const char *); |
| 19947 | SQLITE_PRIVATE int sqlite3AnalysisLoad(sqlite3*,int iDB); |
| 19948 | SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3*,Index*); |
| 19949 | SQLITE_PRIVATE void sqlite3DefaultRowEst(Index*); |
| @@ -27730,14 +27734,16 @@ | |
| 27734 | if( nDiff>0 && sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= |
| 27735 | mem0.alarmThreshold-nDiff ){ |
| 27736 | sqlite3MallocAlarm(nDiff); |
| 27737 | } |
| 27738 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 27739 | #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 27740 | if( pNew==0 && mem0.alarmThreshold>0 ){ |
| 27741 | sqlite3MallocAlarm((int)nBytes); |
| 27742 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 27743 | } |
| 27744 | #endif |
| 27745 | if( pNew ){ |
| 27746 | nNew = sqlite3MallocSize(pNew); |
| 27747 | sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nNew-nOld); |
| 27748 | } |
| 27749 | sqlite3_mutex_leave(mem0.mutex); |
| @@ -34971,20 +34977,21 @@ | |
| 34977 | static int osSetPosixAdvisoryLock( |
| 34978 | int h, /* The file descriptor on which to take the lock */ |
| 34979 | struct flock *pLock, /* The description of the lock */ |
| 34980 | unixFile *pFile /* Structure holding timeout value */ |
| 34981 | ){ |
| 34982 | int tm = pFile->iBusyTimeout; |
| 34983 | int rc = osFcntl(h,F_SETLK,pLock); |
| 34984 | while( rc<0 && tm>0 ){ |
| 34985 | /* On systems that support some kind of blocking file lock with a timeout, |
| 34986 | ** make appropriate changes here to invoke that blocking file lock. On |
| 34987 | ** generic posix, however, there is no such API. So we simply try the |
| 34988 | ** lock once every millisecond until either the timeout expires, or until |
| 34989 | ** the lock is obtained. */ |
| 34990 | usleep(1000); |
| 34991 | rc = osFcntl(h,F_SETLK,pLock); |
| 34992 | tm--; |
| 34993 | } |
| 34994 | return rc; |
| 34995 | } |
| 34996 | #endif /* SQLITE_ENABLE_SETLK_TIMEOUT */ |
| 34997 | |
| @@ -37722,17 +37729,24 @@ | |
| 37729 | |
| 37730 | /* Locks are within range */ |
| 37731 | assert( n>=1 && n<=SQLITE_SHM_NLOCK ); |
| 37732 | |
| 37733 | if( pShmNode->hShm>=0 ){ |
| 37734 | int res; |
| 37735 | /* Initialize the locking parameters */ |
| 37736 | f.l_type = lockType; |
| 37737 | f.l_whence = SEEK_SET; |
| 37738 | f.l_start = ofst; |
| 37739 | f.l_len = n; |
| 37740 | res = osSetPosixAdvisoryLock(pShmNode->hShm, &f, pFile); |
| 37741 | if( res==-1 ){ |
| 37742 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 37743 | rc = (pFile->iBusyTimeout ? SQLITE_BUSY_TIMEOUT : SQLITE_BUSY); |
| 37744 | #else |
| 37745 | rc = SQLITE_BUSY; |
| 37746 | #endif |
| 37747 | } |
| 37748 | } |
| 37749 | |
| 37750 | /* Update the global lock state and do debug tracing */ |
| 37751 | #ifdef SQLITE_DEBUG |
| 37752 | { u16 mask; |
| @@ -38225,26 +38239,27 @@ | |
| 38239 | || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE) ); |
| 38240 | assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 ); |
| 38241 | assert( pShmNode->hShm>=0 || pDbFd->pInode->bProcessLock==1 ); |
| 38242 | assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 ); |
| 38243 | |
| 38244 | /* Check that, if this to be a blocking lock, no locks that occur later |
| 38245 | ** in the following list than the lock being obtained are already held: |
| 38246 | ** |
| 38247 | ** 1. Checkpointer lock (ofst==1). |
| 38248 | ** 2. Write lock (ofst==0). |
| 38249 | ** 3. Read locks (ofst>=3 && ofst<SQLITE_SHM_NLOCK). |
| 38250 | ** |
| 38251 | ** In other words, if this is a blocking lock, none of the locks that |
| 38252 | ** occur later in the above list than the lock being obtained may be |
| 38253 | ** held. */ |
| 38254 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 38255 | assert( (flags & SQLITE_SHM_UNLOCK) || pDbFd->iBusyTimeout==0 || ( |
| 38256 | (ofst!=2) /* not RECOVER */ |
| 38257 | && (ofst!=1 || (p->exclMask|p->sharedMask)==0) |
| 38258 | && (ofst!=0 || (p->exclMask|p->sharedMask)<3) |
| 38259 | && (ofst<3 || (p->exclMask|p->sharedMask)<(1<<ofst)) |
| 38260 | )); |
| 38261 | #endif |
| 38262 | |
| 38263 | mask = (1<<(ofst+n)) - (1<<ofst); |
| 38264 | assert( n>1 || mask==(1<<ofst) ); |
| 38265 | sqlite3_mutex_enter(pShmNode->pShmMutex); |
| @@ -51548,10 +51563,15 @@ | |
| 51563 | SQLITE_PRIVATE int sqlite3WalFramesize(Wal *pWal); |
| 51564 | #endif |
| 51565 | |
| 51566 | /* Return the sqlite3_file object for the WAL file */ |
| 51567 | SQLITE_PRIVATE sqlite3_file *sqlite3WalFile(Wal *pWal); |
| 51568 | |
| 51569 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 51570 | SQLITE_PRIVATE int sqlite3WalWriteLock(Wal *pWal, int bLock); |
| 51571 | SQLITE_PRIVATE void sqlite3WalDb(Wal *pWal, sqlite3 *db); |
| 51572 | #endif |
| 51573 | |
| 51574 | #endif /* ifndef SQLITE_OMIT_WAL */ |
| 51575 | #endif /* SQLITE_WAL_H */ |
| 51576 | |
| 51577 | /************** End of wal.h *************************************************/ |
| @@ -57238,11 +57258,10 @@ | |
| 57258 | Pager *pPager; |
| 57259 | assert( pPg!=0 ); |
| 57260 | assert( pPg->pgno==1 ); |
| 57261 | assert( (pPg->flags & PGHDR_MMAP)==0 ); /* Page1 is never memory mapped */ |
| 57262 | pPager = pPg->pPager; |
| 57263 | sqlite3PcacheRelease(pPg); |
| 57264 | pagerUnlockIfUnused(pPager); |
| 57265 | } |
| 57266 | |
| 57267 | /* |
| @@ -58531,20 +58550,10 @@ | |
| 58550 | */ |
| 58551 | SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager *pPager){ |
| 58552 | return pPager->fd; |
| 58553 | } |
| 58554 | |
| 58555 | /* |
| 58556 | ** Return the file handle for the journal file (if it exists). |
| 58557 | ** This will be either the rollback journal or the WAL file. |
| 58558 | */ |
| 58559 | SQLITE_PRIVATE sqlite3_file *sqlite3PagerJrnlFile(Pager *pPager){ |
| @@ -58954,11 +58963,10 @@ | |
| 58963 | (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler), |
| 58964 | pPager->pBusyHandlerArg, |
| 58965 | pPager->walSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace, |
| 58966 | pnLog, pnCkpt |
| 58967 | ); |
| 58968 | } |
| 58969 | return rc; |
| 58970 | } |
| 58971 | |
| 58972 | SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager){ |
| @@ -59119,11 +59127,35 @@ | |
| 59127 | } |
| 59128 | } |
| 59129 | return rc; |
| 59130 | } |
| 59131 | |
| 59132 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 59133 | /* |
| 59134 | ** If pager pPager is a wal-mode database not in exclusive locking mode, |
| 59135 | ** invoke the sqlite3WalWriteLock() function on the associated Wal object |
| 59136 | ** with the same db and bLock parameters as were passed to this function. |
| 59137 | ** Return an SQLite error code if an error occurs, or SQLITE_OK otherwise. |
| 59138 | */ |
| 59139 | SQLITE_PRIVATE int sqlite3PagerWalWriteLock(Pager *pPager, int bLock){ |
| 59140 | int rc = SQLITE_OK; |
| 59141 | if( pagerUseWal(pPager) && pPager->exclusiveMode==0 ){ |
| 59142 | rc = sqlite3WalWriteLock(pPager->pWal, bLock); |
| 59143 | } |
| 59144 | return rc; |
| 59145 | } |
| 59146 | |
| 59147 | /* |
| 59148 | ** Set the database handle used by the wal layer to determine if |
| 59149 | ** blocking locks are required. |
| 59150 | */ |
| 59151 | SQLITE_PRIVATE void sqlite3PagerWalDb(Pager *pPager, sqlite3 *db){ |
| 59152 | if( pagerUseWal(pPager) ){ |
| 59153 | sqlite3WalDb(pPager->pWal, db); |
| 59154 | } |
| 59155 | } |
| 59156 | #endif |
| 59157 | |
| 59158 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 59159 | /* |
| 59160 | ** If this is a WAL database, obtain a snapshot handle for the snapshot |
| 59161 | ** currently open. Otherwise, return an error. |
| @@ -59139,11 +59171,14 @@ | |
| 59171 | /* |
| 59172 | ** If this is a WAL database, store a pointer to pSnapshot. Next time a |
| 59173 | ** read transaction is opened, attempt to read from the snapshot it |
| 59174 | ** identifies. If this is not a WAL database, return an error. |
| 59175 | */ |
| 59176 | SQLITE_PRIVATE int sqlite3PagerSnapshotOpen( |
| 59177 | Pager *pPager, |
| 59178 | sqlite3_snapshot *pSnapshot |
| 59179 | ){ |
| 59180 | int rc = SQLITE_OK; |
| 59181 | if( pPager->pWal ){ |
| 59182 | sqlite3WalSnapshotOpen(pPager->pWal, pSnapshot); |
| 59183 | }else{ |
| 59184 | rc = SQLITE_ERROR; |
| @@ -59684,10 +59719,13 @@ | |
| 59719 | u8 lockError; /* True if a locking error has occurred */ |
| 59720 | #endif |
| 59721 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 59722 | WalIndexHdr *pSnapshot; /* Start transaction here if not NULL */ |
| 59723 | #endif |
| 59724 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 59725 | sqlite3 *db; |
| 59726 | #endif |
| 59727 | }; |
| 59728 | |
| 59729 | /* |
| 59730 | ** Candidate values for Wal.exclusiveMode. |
| 59731 | */ |
| @@ -60057,11 +60095,11 @@ | |
| 60095 | if( pWal->exclusiveMode ) return SQLITE_OK; |
| 60096 | rc = sqlite3OsShmLock(pWal->pDbFd, lockIdx, 1, |
| 60097 | SQLITE_SHM_LOCK | SQLITE_SHM_SHARED); |
| 60098 | WALTRACE(("WAL%p: acquire SHARED-%s %s\n", pWal, |
| 60099 | walLockName(lockIdx), rc ? "failed" : "ok")); |
| 60100 | VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && (rc&0xFF)!=SQLITE_BUSY); ) |
| 60101 | return rc; |
| 60102 | } |
| 60103 | static void walUnlockShared(Wal *pWal, int lockIdx){ |
| 60104 | if( pWal->exclusiveMode ) return; |
| 60105 | (void)sqlite3OsShmLock(pWal->pDbFd, lockIdx, 1, |
| @@ -60073,11 +60111,11 @@ | |
| 60111 | if( pWal->exclusiveMode ) return SQLITE_OK; |
| 60112 | rc = sqlite3OsShmLock(pWal->pDbFd, lockIdx, n, |
| 60113 | SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE); |
| 60114 | WALTRACE(("WAL%p: acquire EXCLUSIVE-%s cnt=%d %s\n", pWal, |
| 60115 | walLockName(lockIdx), n, rc ? "failed" : "ok")); |
| 60116 | VVA_ONLY( pWal->lockError = (u8)(rc!=SQLITE_OK && (rc&0xFF)!=SQLITE_BUSY); ) |
| 60117 | return rc; |
| 60118 | } |
| 60119 | static void walUnlockExclusive(Wal *pWal, int lockIdx, int n){ |
| 60120 | if( pWal->exclusiveMode ) return; |
| 60121 | (void)sqlite3OsShmLock(pWal->pDbFd, lockIdx, n, |
| @@ -60345,15 +60383,10 @@ | |
| 60383 | int rc; /* Return Code */ |
| 60384 | i64 nSize; /* Size of log file */ |
| 60385 | u32 aFrameCksum[2] = {0, 0}; |
| 60386 | int iLock; /* Lock offset to lock for checkpoint */ |
| 60387 | |
| 60388 | /* Obtain an exclusive lock on all byte in the locking range not already |
| 60389 | ** locked by the caller. The caller is guaranteed to have locked the |
| 60390 | ** WAL_WRITE_LOCK byte, and may have also locked the WAL_CKPT_LOCK byte. |
| 60391 | ** If successful, the same bytes that are locked here are unlocked before |
| 60392 | ** this function returns. |
| @@ -60897,10 +60930,93 @@ | |
| 60930 | p = 0; |
| 60931 | } |
| 60932 | *pp = p; |
| 60933 | return rc; |
| 60934 | } |
| 60935 | |
| 60936 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 60937 | /* |
| 60938 | ** Attempt to enable blocking locks. Blocking locks are enabled only if (a) |
| 60939 | ** they are supported by the VFS, and (b) the database handle is configured |
| 60940 | ** with a busy-timeout. Return 1 if blocking locks are successfully enabled, |
| 60941 | ** or 0 otherwise. |
| 60942 | */ |
| 60943 | static int walEnableBlocking(Wal *pWal){ |
| 60944 | int res = 0; |
| 60945 | if( pWal->db ){ |
| 60946 | int tmout = pWal->db->busyTimeout; |
| 60947 | if( tmout ){ |
| 60948 | int rc; |
| 60949 | rc = sqlite3OsFileControl( |
| 60950 | pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout |
| 60951 | ); |
| 60952 | res = (rc==SQLITE_OK); |
| 60953 | } |
| 60954 | } |
| 60955 | return res; |
| 60956 | } |
| 60957 | |
| 60958 | /* |
| 60959 | ** Disable blocking locks. |
| 60960 | */ |
| 60961 | static void walDisableBlocking(Wal *pWal){ |
| 60962 | int tmout = 0; |
| 60963 | sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout); |
| 60964 | } |
| 60965 | |
| 60966 | /* |
| 60967 | ** If parameter bLock is true, attempt to enable blocking locks, take |
| 60968 | ** the WRITER lock, and then disable blocking locks. If blocking locks |
| 60969 | ** cannot be enabled, no attempt to obtain the WRITER lock is made. Return |
| 60970 | ** an SQLite error code if an error occurs, or SQLITE_OK otherwise. It is not |
| 60971 | ** an error if blocking locks can not be enabled. |
| 60972 | ** |
| 60973 | ** If the bLock parameter is false and the WRITER lock is held, release it. |
| 60974 | */ |
| 60975 | SQLITE_PRIVATE int sqlite3WalWriteLock(Wal *pWal, int bLock){ |
| 60976 | int rc = SQLITE_OK; |
| 60977 | assert( pWal->readLock<0 || bLock==0 ); |
| 60978 | if( bLock ){ |
| 60979 | assert( pWal->db ); |
| 60980 | if( walEnableBlocking(pWal) ){ |
| 60981 | rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1); |
| 60982 | if( rc==SQLITE_OK ){ |
| 60983 | pWal->writeLock = 1; |
| 60984 | } |
| 60985 | walDisableBlocking(pWal); |
| 60986 | } |
| 60987 | }else if( pWal->writeLock ){ |
| 60988 | walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1); |
| 60989 | pWal->writeLock = 0; |
| 60990 | } |
| 60991 | return rc; |
| 60992 | } |
| 60993 | |
| 60994 | /* |
| 60995 | ** Set the database handle used to determine if blocking locks are required. |
| 60996 | */ |
| 60997 | SQLITE_PRIVATE void sqlite3WalDb(Wal *pWal, sqlite3 *db){ |
| 60998 | pWal->db = db; |
| 60999 | } |
| 61000 | |
| 61001 | /* |
| 61002 | ** Take an exclusive WRITE lock. Blocking if so configured. |
| 61003 | */ |
| 61004 | static int walLockWriter(Wal *pWal){ |
| 61005 | int rc; |
| 61006 | walEnableBlocking(pWal); |
| 61007 | rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1); |
| 61008 | walDisableBlocking(pWal); |
| 61009 | return rc; |
| 61010 | } |
| 61011 | #else |
| 61012 | # define walEnableBlocking(x) 0 |
| 61013 | # define walDisableBlocking(x) |
| 61014 | # define walLockWriter(pWal) walLockExclusive((pWal), WAL_WRITE_LOCK, 1) |
| 61015 | # define sqlite3WalDb(pWal, db) |
| 61016 | #endif /* ifdef SQLITE_ENABLE_SETLK_TIMEOUT */ |
| 61017 | |
| 61018 | |
| 61019 | /* |
| 61020 | ** Attempt to obtain the exclusive WAL lock defined by parameters lockIdx and |
| 61021 | ** n. If the attempt fails and parameter xBusy is not NULL, then it is a |
| 61022 | ** busy-handler function. Invoke it and retry the lock until either the |
| @@ -60915,10 +61031,16 @@ | |
| 61031 | ){ |
| 61032 | int rc; |
| 61033 | do { |
| 61034 | rc = walLockExclusive(pWal, lockIdx, n); |
| 61035 | }while( xBusy && rc==SQLITE_BUSY && xBusy(pBusyArg) ); |
| 61036 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 61037 | if( rc==SQLITE_BUSY_TIMEOUT ){ |
| 61038 | walDisableBlocking(pWal); |
| 61039 | rc = SQLITE_BUSY; |
| 61040 | } |
| 61041 | #endif |
| 61042 | return rc; |
| 61043 | } |
| 61044 | |
| 61045 | /* |
| 61046 | ** The cache of the wal-index header must be valid to call this function. |
| @@ -61394,32 +61516,36 @@ | |
| 61516 | badHdr = (page0 ? walIndexTryHdr(pWal, pChanged) : 1); |
| 61517 | |
| 61518 | /* If the first attempt failed, it might have been due to a race |
| 61519 | ** with a writer. So get a WRITE lock and try again. |
| 61520 | */ |
| 61521 | if( badHdr ){ |
| 61522 | if( pWal->bShmUnreliable==0 && (pWal->readOnly & WAL_SHM_RDONLY) ){ |
| 61523 | if( SQLITE_OK==(rc = walLockShared(pWal, WAL_WRITE_LOCK)) ){ |
| 61524 | walUnlockShared(pWal, WAL_WRITE_LOCK); |
| 61525 | rc = SQLITE_READONLY_RECOVERY; |
| 61526 | } |
| 61527 | }else{ |
| 61528 | int bWriteLock = pWal->writeLock; |
| 61529 | if( bWriteLock || SQLITE_OK==(rc = walLockWriter(pWal)) ){ |
| 61530 | pWal->writeLock = 1; |
| 61531 | if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){ |
| 61532 | badHdr = walIndexTryHdr(pWal, pChanged); |
| 61533 | if( badHdr ){ |
| 61534 | /* If the wal-index header is still malformed even while holding |
| 61535 | ** a WRITE lock, it can only mean that the header is corrupted and |
| 61536 | ** needs to be reconstructed. So run recovery to do exactly that. |
| 61537 | */ |
| 61538 | rc = walIndexRecover(pWal); |
| 61539 | *pChanged = 1; |
| 61540 | } |
| 61541 | } |
| 61542 | if( bWriteLock==0 ){ |
| 61543 | pWal->writeLock = 0; |
| 61544 | walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1); |
| 61545 | } |
| 61546 | } |
| 61547 | } |
| 61548 | } |
| 61549 | |
| 61550 | /* If the header is read successfully, check the version number to make |
| 61551 | ** sure the wal-index was not constructed with some future format that |
| @@ -61967,26 +62093,38 @@ | |
| 62093 | ** needs to be flushed. |
| 62094 | */ |
| 62095 | SQLITE_PRIVATE int sqlite3WalBeginReadTransaction(Wal *pWal, int *pChanged){ |
| 62096 | int rc; /* Return code */ |
| 62097 | int cnt = 0; /* Number of TryBeginRead attempts */ |
| 62098 | |
| 62099 | assert( pWal->ckptLock==0 ); |
| 62100 | |
| 62101 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 62102 | int bChanged = 0; |
| 62103 | WalIndexHdr *pSnapshot = pWal->pSnapshot; |
| 62104 | if( pSnapshot ){ |
| 62105 | if( memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){ |
| 62106 | bChanged = 1; |
| 62107 | } |
| 62108 | |
| 62109 | /* It is possible that there is a checkpointer thread running |
| 62110 | ** concurrent with this code. If this is the case, it may be that the |
| 62111 | ** checkpointer has already determined that it will checkpoint |
| 62112 | ** snapshot X, where X is later in the wal file than pSnapshot, but |
| 62113 | ** has not yet set the pInfo->nBackfillAttempted variable to indicate |
| 62114 | ** its intent. To avoid the race condition this leads to, ensure that |
| 62115 | ** there is no checkpointer process by taking a shared CKPT lock |
| 62116 | ** before checking pInfo->nBackfillAttempted. */ |
| 62117 | (void)walEnableBlocking(pWal); |
| 62118 | rc = walLockShared(pWal, WAL_CKPT_LOCK); |
| 62119 | walDisableBlocking(pWal); |
| 62120 | |
| 62121 | if( rc!=SQLITE_OK ){ |
| 62122 | return rc; |
| 62123 | } |
| 62124 | pWal->ckptLock = 1; |
| 62125 | } |
| 62126 | #endif |
| 62127 | |
| 62128 | do{ |
| 62129 | rc = walTryBeginRead(pWal, pChanged, 0, ++cnt); |
| 62130 | }while( rc==WAL_RETRY ); |
| @@ -61993,20 +62131,10 @@ | |
| 62131 | testcase( (rc&0xff)==SQLITE_BUSY ); |
| 62132 | testcase( (rc&0xff)==SQLITE_IOERR ); |
| 62133 | testcase( rc==SQLITE_PROTOCOL ); |
| 62134 | testcase( rc==SQLITE_OK ); |
| 62135 | |
| 62136 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 62137 | if( rc==SQLITE_OK ){ |
| 62138 | if( pSnapshot && memcmp(pSnapshot, &pWal->hdr, sizeof(WalIndexHdr))!=0 ){ |
| 62139 | /* At this point the client has a lock on an aReadMark[] slot holding |
| 62140 | ** a value equal to or smaller than pSnapshot->mxFrame, but pWal->hdr |
| @@ -62024,52 +62152,46 @@ | |
| 62152 | volatile WalCkptInfo *pInfo = walCkptInfo(pWal); |
| 62153 | |
| 62154 | assert( pWal->readLock>0 || pWal->hdr.mxFrame==0 ); |
| 62155 | assert( pInfo->aReadMark[pWal->readLock]<=pSnapshot->mxFrame ); |
| 62156 | |
| 62157 | /* Check that the wal file has not been wrapped. Assuming that it has |
| 62158 | ** not, also check that no checkpointer has attempted to checkpoint any |
| 62159 | ** frames beyond pSnapshot->mxFrame. If either of these conditions are |
| 62160 | ** true, return SQLITE_ERROR_SNAPSHOT. Otherwise, overwrite pWal->hdr |
| 62161 | ** with *pSnapshot and set *pChanged as appropriate for opening the |
| 62162 | ** snapshot. */ |
| 62163 | if( !memcmp(pSnapshot->aSalt, pWal->hdr.aSalt, sizeof(pWal->hdr.aSalt)) |
| 62164 | && pSnapshot->mxFrame>=pInfo->nBackfillAttempted |
| 62165 | ){ |
| 62166 | assert( pWal->readLock>0 ); |
| 62167 | memcpy(&pWal->hdr, pSnapshot, sizeof(WalIndexHdr)); |
| 62168 | *pChanged = bChanged; |
| 62169 | }else{ |
| 62170 | rc = SQLITE_ERROR_SNAPSHOT; |
| 62171 | } |
| 62172 | |
| 62173 | /* A client using a non-current snapshot may not ignore any frames |
| 62174 | ** from the start of the wal file. This is because, for a system |
| 62175 | ** where (minFrame < iSnapshot < maxFrame), a checkpointer may |
| 62176 | ** have omitted to checkpoint a frame earlier than minFrame in |
| 62177 | ** the file because there exists a frame after iSnapshot that |
| 62178 | ** is the same database page. */ |
| 62179 | pWal->minFrame = 1; |
| 62180 | |
| 62181 | if( rc!=SQLITE_OK ){ |
| 62182 | sqlite3WalEndReadTransaction(pWal); |
| 62183 | } |
| 62184 | } |
| 62185 | } |
| 62186 | |
| 62187 | /* Release the shared CKPT lock obtained above. */ |
| 62188 | if( pWal->ckptLock ){ |
| 62189 | assert( pSnapshot ); |
| 62190 | walUnlockShared(pWal, WAL_CKPT_LOCK); |
| 62191 | pWal->ckptLock = 0; |
| 62192 | } |
| 62193 | #endif |
| 62194 | return rc; |
| 62195 | } |
| 62196 | |
| 62197 | /* |
| @@ -62235,10 +62357,20 @@ | |
| 62357 | ** |
| 62358 | ** There can only be a single writer active at a time. |
| 62359 | */ |
| 62360 | SQLITE_PRIVATE int sqlite3WalBeginWriteTransaction(Wal *pWal){ |
| 62361 | int rc; |
| 62362 | |
| 62363 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 62364 | /* If the write-lock is already held, then it was obtained before the |
| 62365 | ** read-transaction was even opened, making this call a no-op. |
| 62366 | ** Return early. */ |
| 62367 | if( pWal->writeLock ){ |
| 62368 | assert( !memcmp(&pWal->hdr,(void *)walIndexHdr(pWal),sizeof(WalIndexHdr)) ); |
| 62369 | return SQLITE_OK; |
| 62370 | } |
| 62371 | #endif |
| 62372 | |
| 62373 | /* Cannot start a write transaction without first holding a read |
| 62374 | ** transaction. */ |
| 62375 | assert( pWal->readLock>=0 ); |
| 62376 | assert( pWal->writeLock==0 && pWal->iReCksum==0 ); |
| @@ -62811,50 +62943,57 @@ | |
| 62943 | ** in the SQLITE_CHECKPOINT_PASSIVE mode. */ |
| 62944 | assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 ); |
| 62945 | |
| 62946 | if( pWal->readOnly ) return SQLITE_READONLY; |
| 62947 | WALTRACE(("WAL%p: checkpoint begins\n", pWal)); |
| 62948 | |
| 62949 | /* Enable blocking locks, if possible. If blocking locks are successfully |
| 62950 | ** enabled, set xBusy2=0 so that the busy-handler is never invoked. */ |
| 62951 | sqlite3WalDb(pWal, db); |
| 62952 | (void)walEnableBlocking(pWal); |
| 62953 | |
| 62954 | /* IMPLEMENTATION-OF: R-62028-47212 All calls obtain an exclusive |
| 62955 | ** "checkpoint" lock on the database file. |
| 62956 | ** EVIDENCE-OF: R-10421-19736 If any other process is running a |
| 62957 | ** checkpoint operation at the same time, the lock cannot be obtained and |
| 62958 | ** SQLITE_BUSY is returned. |
| 62959 | ** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured, |
| 62960 | ** it will not be invoked in this case. |
| 62961 | */ |
| 62962 | rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1); |
| 62963 | testcase( rc==SQLITE_BUSY ); |
| 62964 | testcase( rc!=SQLITE_OK && xBusy2!=0 ); |
| 62965 | if( rc==SQLITE_OK ){ |
| 62966 | pWal->ckptLock = 1; |
| 62967 | |
| 62968 | /* IMPLEMENTATION-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART and |
| 62969 | ** TRUNCATE modes also obtain the exclusive "writer" lock on the database |
| 62970 | ** file. |
| 62971 | ** |
| 62972 | ** EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained |
| 62973 | ** immediately, and a busy-handler is configured, it is invoked and the |
| 62974 | ** writer lock retried until either the busy-handler returns 0 or the |
| 62975 | ** lock is successfully obtained. |
| 62976 | */ |
| 62977 | if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){ |
| 62978 | rc = walBusyLock(pWal, xBusy2, pBusyArg, WAL_WRITE_LOCK, 1); |
| 62979 | if( rc==SQLITE_OK ){ |
| 62980 | pWal->writeLock = 1; |
| 62981 | }else if( rc==SQLITE_BUSY ){ |
| 62982 | eMode2 = SQLITE_CHECKPOINT_PASSIVE; |
| 62983 | xBusy2 = 0; |
| 62984 | rc = SQLITE_OK; |
| 62985 | } |
| 62986 | } |
| 62987 | } |
| 62988 | |
| 62989 | |
| 62990 | /* Read the wal-index header. */ |
| 62991 | if( rc==SQLITE_OK ){ |
| 62992 | walDisableBlocking(pWal); |
| 62993 | rc = walIndexReadHdr(pWal, &isChanged); |
| 62994 | (void)walEnableBlocking(pWal); |
| 62995 | if( isChanged && pWal->pDbFd->pMethods->iVersion>=3 ){ |
| 62996 | sqlite3OsUnfetch(pWal->pDbFd, 0, 0); |
| 62997 | } |
| 62998 | } |
| 62999 | |
| @@ -62881,16 +63020,24 @@ | |
| 63020 | ** next time the pager opens a snapshot on this database it knows that |
| 63021 | ** the cache needs to be reset. |
| 63022 | */ |
| 63023 | memset(&pWal->hdr, 0, sizeof(WalIndexHdr)); |
| 63024 | } |
| 63025 | |
| 63026 | walDisableBlocking(pWal); |
| 63027 | sqlite3WalDb(pWal, 0); |
| 63028 | |
| 63029 | /* Release the locks. */ |
| 63030 | sqlite3WalEndWriteTransaction(pWal); |
| 63031 | if( pWal->ckptLock ){ |
| 63032 | walUnlockExclusive(pWal, WAL_CKPT_LOCK, 1); |
| 63033 | pWal->ckptLock = 0; |
| 63034 | } |
| 63035 | WALTRACE(("WAL%p: checkpoint %s\n", pWal, rc ? "failed" : "ok")); |
| 63036 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 63037 | if( rc==SQLITE_BUSY_TIMEOUT ) rc = SQLITE_BUSY; |
| 63038 | #endif |
| 63039 | return (rc==SQLITE_OK && eMode!=eMode2 ? SQLITE_BUSY : rc); |
| 63040 | } |
| 63041 | |
| 63042 | /* Return the value to pass to a sqlite3_wal_hook callback, the |
| 63043 | ** number of frames in the WAL at the point of the last commit since |
| @@ -63003,11 +63150,14 @@ | |
| 63150 | return rc; |
| 63151 | } |
| 63152 | |
| 63153 | /* Try to open on pSnapshot when the next read-transaction starts |
| 63154 | */ |
| 63155 | SQLITE_PRIVATE void sqlite3WalSnapshotOpen( |
| 63156 | Wal *pWal, |
| 63157 | sqlite3_snapshot *pSnapshot |
| 63158 | ){ |
| 63159 | pWal->pSnapshot = (WalIndexHdr*)pSnapshot; |
| 63160 | } |
| 63161 | |
| 63162 | /* |
| 63163 | ** Return a +ve value if snapshot p1 is newer than p2. A -ve value if |
| @@ -63522,11 +63672,11 @@ | |
| 63672 | u8 incrVacuum; /* True if incr-vacuum is enabled */ |
| 63673 | u8 bDoTruncate; /* True to truncate db on commit */ |
| 63674 | #endif |
| 63675 | u8 inTransaction; /* Transaction state */ |
| 63676 | u8 max1bytePayload; /* Maximum first byte of cell for a 1-byte payload */ |
| 63677 | u8 nReserveWanted; /* Desired number of extra bytes per page */ |
| 63678 | u16 btsFlags; /* Boolean parameters. See BTS_* macros below */ |
| 63679 | u16 maxLocal; /* Maximum local payload in non-LEAFDATA tables */ |
| 63680 | u16 minLocal; /* Minimum local payload in non-LEAFDATA tables */ |
| 63681 | u16 maxLeaf; /* Maximum local payload in a LEAFDATA table */ |
| 63682 | u16 minLeaf; /* Minimum local payload in a LEAFDATA table */ |
| @@ -66416,12 +66566,11 @@ | |
| 66566 | */ |
| 66567 | static int btreeInvokeBusyHandler(void *pArg){ |
| 66568 | BtShared *pBt = (BtShared*)pArg; |
| 66569 | assert( pBt->db ); |
| 66570 | assert( sqlite3_mutex_held(pBt->db->mutex) ); |
| 66571 | return sqlite3InvokeBusyHandler(&pBt->db->busyHandler); |
| 66572 | } |
| 66573 | |
| 66574 | /* |
| 66575 | ** Open a database file. |
| 66576 | ** |
| @@ -66968,23 +67117,21 @@ | |
| 67117 | ** If the iFix!=0 then the BTS_PAGESIZE_FIXED flag is set so that the page size |
| 67118 | ** and autovacuum mode can no longer be changed. |
| 67119 | */ |
| 67120 | SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve, int iFix){ |
| 67121 | int rc = SQLITE_OK; |
| 67122 | int x; |
| 67123 | BtShared *pBt = p->pBt; |
| 67124 | assert( nReserve>=0 && nReserve<=255 ); |
| 67125 | sqlite3BtreeEnter(p); |
| 67126 | pBt->nReserveWanted = nReserve; |
| 67127 | x = pBt->pageSize - pBt->usableSize; |
| 67128 | if( nReserve<x ) nReserve = x; |
| 67129 | if( pBt->btsFlags & BTS_PAGESIZE_FIXED ){ |
| 67130 | sqlite3BtreeLeave(p); |
| 67131 | return SQLITE_READONLY; |
| 67132 | } |
| 67133 | assert( nReserve>=0 && nReserve<=255 ); |
| 67134 | if( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE && |
| 67135 | ((pageSize-1)&pageSize)==0 ){ |
| 67136 | assert( (pageSize & 7)==0 ); |
| 67137 | assert( !pBt->pCursor ); |
| @@ -67031,16 +67178,16 @@ | |
| 67178 | ** The value returned is the larger of the current reserve size and |
| 67179 | ** the latest reserve size requested by SQLITE_FILECTRL_RESERVE_BYTES. |
| 67180 | ** The amount of reserve can only grow - never shrink. |
| 67181 | */ |
| 67182 | SQLITE_PRIVATE int sqlite3BtreeGetRequestedReserve(Btree *p){ |
| 67183 | int n1, n2; |
| 67184 | sqlite3BtreeEnter(p); |
| 67185 | n1 = (int)p->pBt->nReserveWanted; |
| 67186 | n2 = sqlite3BtreeGetReserveNoMutex(p); |
| 67187 | sqlite3BtreeLeave(p); |
| 67188 | return n1>n2 ? n1 : n2; |
| 67189 | } |
| 67190 | |
| 67191 | |
| 67192 | /* |
| 67193 | ** Set the maximum page count for a database if mxPage is positive. |
| @@ -67486,10 +67633,11 @@ | |
| 67633 | ** when A already has a read lock, we encourage A to give up and let B |
| 67634 | ** proceed. |
| 67635 | */ |
| 67636 | SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){ |
| 67637 | BtShared *pBt = p->pBt; |
| 67638 | Pager *pPager = pBt->pPager; |
| 67639 | int rc = SQLITE_OK; |
| 67640 | |
| 67641 | sqlite3BtreeEnter(p); |
| 67642 | btreeIntegrity(p); |
| 67643 | |
| @@ -67501,11 +67649,11 @@ | |
| 67649 | goto trans_begun; |
| 67650 | } |
| 67651 | assert( pBt->inTransaction==TRANS_WRITE || IfNotOmitAV(pBt->bDoTruncate)==0 ); |
| 67652 | |
| 67653 | if( (p->db->flags & SQLITE_ResetDatabase) |
| 67654 | && sqlite3PagerIsreadonly(pPager)==0 |
| 67655 | ){ |
| 67656 | pBt->btsFlags &= ~BTS_READ_ONLY; |
| 67657 | } |
| 67658 | |
| 67659 | /* Write transactions are not possible on a read-only database */ |
| @@ -67549,10 +67697,22 @@ | |
| 67697 | if( SQLITE_OK!=rc ) goto trans_begun; |
| 67698 | |
| 67699 | pBt->btsFlags &= ~BTS_INITIALLY_EMPTY; |
| 67700 | if( pBt->nPage==0 ) pBt->btsFlags |= BTS_INITIALLY_EMPTY; |
| 67701 | do { |
| 67702 | sqlite3PagerWalDb(pPager, p->db); |
| 67703 | |
| 67704 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 67705 | /* If transitioning from no transaction directly to a write transaction, |
| 67706 | ** block for the WRITER lock first if possible. */ |
| 67707 | if( pBt->pPage1==0 && wrflag ){ |
| 67708 | assert( pBt->inTransaction==TRANS_NONE ); |
| 67709 | rc = sqlite3PagerWalWriteLock(pPager, 1); |
| 67710 | if( rc!=SQLITE_BUSY && rc!=SQLITE_OK ) break; |
| 67711 | } |
| 67712 | #endif |
| 67713 | |
| 67714 | /* Call lockBtree() until either pBt->pPage1 is populated or |
| 67715 | ** lockBtree() returns something other than SQLITE_OK. lockBtree() |
| 67716 | ** may return SQLITE_OK but leave pBt->pPage1 set to 0 if after |
| 67717 | ** reading page 1 it discovers that the page-size of the database |
| 67718 | ** file is not pBt->pageSize. In this case lockBtree() will update |
| @@ -67562,11 +67722,11 @@ | |
| 67722 | |
| 67723 | if( rc==SQLITE_OK && wrflag ){ |
| 67724 | if( (pBt->btsFlags & BTS_READ_ONLY)!=0 ){ |
| 67725 | rc = SQLITE_READONLY; |
| 67726 | }else{ |
| 67727 | rc = sqlite3PagerBegin(pPager, wrflag>1, sqlite3TempInMemory(p->db)); |
| 67728 | if( rc==SQLITE_OK ){ |
| 67729 | rc = newDatabase(pBt); |
| 67730 | }else if( rc==SQLITE_BUSY_SNAPSHOT && pBt->inTransaction==TRANS_NONE ){ |
| 67731 | /* if there was no transaction opened when this function was |
| 67732 | ** called and SQLITE_BUSY_SNAPSHOT is returned, change the error |
| @@ -67575,15 +67735,19 @@ | |
| 67735 | } |
| 67736 | } |
| 67737 | } |
| 67738 | |
| 67739 | if( rc!=SQLITE_OK ){ |
| 67740 | (void)sqlite3PagerWalWriteLock(pPager, 0); |
| 67741 | unlockBtreeIfUnused(pBt); |
| 67742 | } |
| 67743 | }while( (rc&0xFF)==SQLITE_BUSY && pBt->inTransaction==TRANS_NONE && |
| 67744 | btreeInvokeBusyHandler(pBt) ); |
| 67745 | sqlite3PagerWalDb(pPager, 0); |
| 67746 | #ifdef SQLITE_ENABLE_SETLK_TIMEOUT |
| 67747 | if( rc==SQLITE_BUSY_TIMEOUT ) rc = SQLITE_BUSY; |
| 67748 | #endif |
| 67749 | |
| 67750 | if( rc==SQLITE_OK ){ |
| 67751 | if( p->inTrans==TRANS_NONE ){ |
| 67752 | pBt->nTransaction++; |
| 67753 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| @@ -67631,11 +67795,11 @@ | |
| 67795 | if( wrflag ){ |
| 67796 | /* This call makes sure that the pager has the correct number of |
| 67797 | ** open savepoints. If the second parameter is greater than 0 and |
| 67798 | ** the sub-journal is not already open, then it will be opened here. |
| 67799 | */ |
| 67800 | rc = sqlite3PagerOpenSavepoint(pPager, p->db->nSavepoint); |
| 67801 | } |
| 67802 | } |
| 67803 | |
| 67804 | btreeIntegrity(p); |
| 67805 | sqlite3BtreeLeave(p); |
| @@ -71267,11 +71431,11 @@ | |
| 71431 | |
| 71432 | /* Remove cells from the start and end of the page */ |
| 71433 | assert( nCell>=0 ); |
| 71434 | if( iOld<iNew ){ |
| 71435 | int nShift = pageFreeArray(pPg, iOld, iNew-iOld, pCArray); |
| 71436 | if( NEVER(nShift>nCell) ) return SQLITE_CORRUPT_BKPT; |
| 71437 | memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2); |
| 71438 | nCell -= nShift; |
| 71439 | } |
| 71440 | if( iNewEnd < iOldEnd ){ |
| 71441 | int nTail = pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray); |
| @@ -74746,11 +74910,11 @@ | |
| 74910 | ** Attempt to set the page size of the destination to match the page size |
| 74911 | ** of the source. |
| 74912 | */ |
| 74913 | static int setDestPgsz(sqlite3_backup *p){ |
| 74914 | int rc; |
| 74915 | rc = sqlite3BtreeSetPageSize(p->pDest,sqlite3BtreeGetPageSize(p->pSrc),0,0); |
| 74916 | return rc; |
| 74917 | } |
| 74918 | |
| 74919 | /* |
| 74920 | ** Check that there is no open read-transaction on the b-tree passed as the |
| @@ -90540,16 +90704,23 @@ | |
| 90704 | rc = sqlite3VdbeSorterWrite(pC, pIn2); |
| 90705 | if( rc) goto abort_due_to_error; |
| 90706 | break; |
| 90707 | } |
| 90708 | |
| 90709 | /* Opcode: IdxDelete P1 P2 P3 * P5 |
| 90710 | ** Synopsis: key=r[P2@P3] |
| 90711 | ** |
| 90712 | ** The content of P3 registers starting at register P2 form |
| 90713 | ** an unpacked index key. This opcode removes that entry from the |
| 90714 | ** index opened by cursor P1. |
| 90715 | ** |
| 90716 | ** If P5 is not zero, then raise an SQLITE_CORRUPT_INDEX error |
| 90717 | ** if no matching index entry is found. This happens when running |
| 90718 | ** an UPDATE or DELETE statement and the index entry to be updated |
| 90719 | ** or deleted is not found. For some uses of IdxDelete |
| 90720 | ** (example: the EXCEPT operator) it does not matter that no matching |
| 90721 | ** entry is found. For those cases, P5 is zero. |
| 90722 | */ |
| 90723 | case OP_IdxDelete: { |
| 90724 | VdbeCursor *pC; |
| 90725 | BtCursor *pCrsr; |
| 90726 | int res; |
| @@ -90562,20 +90733,22 @@ | |
| 90733 | assert( pC!=0 ); |
| 90734 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 90735 | sqlite3VdbeIncrWriteCounter(p, pC); |
| 90736 | pCrsr = pC->uc.pCursor; |
| 90737 | assert( pCrsr!=0 ); |
| 90738 | r.pKeyInfo = pC->pKeyInfo; |
| 90739 | r.nField = (u16)pOp->p3; |
| 90740 | r.default_rc = 0; |
| 90741 | r.aMem = &aMem[pOp->p2]; |
| 90742 | rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res); |
| 90743 | if( rc ) goto abort_due_to_error; |
| 90744 | if( res==0 ){ |
| 90745 | rc = sqlite3BtreeDelete(pCrsr, BTREE_AUXDELETE); |
| 90746 | if( rc ) goto abort_due_to_error; |
| 90747 | }else if( pOp->p5 ){ |
| 90748 | rc = SQLITE_CORRUPT_INDEX; |
| 90749 | goto abort_due_to_error; |
| 90750 | } |
| 90751 | assert( pC->deferredMoveto==0 ); |
| 90752 | pC->cacheStatus = CACHE_STALE; |
| 90753 | pC->seekResult = 0; |
| 90754 | break; |
| @@ -103684,11 +103857,11 @@ | |
| 103857 | assert( pExpr->affExpr==OE_Rollback |
| 103858 | || pExpr->affExpr==OE_Abort |
| 103859 | || pExpr->affExpr==OE_Fail |
| 103860 | || pExpr->affExpr==OE_Ignore |
| 103861 | ); |
| 103862 | if( !pParse->pTriggerTab && !pParse->nested ){ |
| 103863 | sqlite3ErrorMsg(pParse, |
| 103864 | "RAISE() may only be used within a trigger-program"); |
| 103865 | return 0; |
| 103866 | } |
| 103867 | if( pExpr->affExpr==OE_Abort ){ |
| @@ -103698,12 +103871,13 @@ | |
| 103871 | if( pExpr->affExpr==OE_Ignore ){ |
| 103872 | sqlite3VdbeAddOp4( |
| 103873 | v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0); |
| 103874 | VdbeCoverage(v); |
| 103875 | }else{ |
| 103876 | sqlite3HaltConstraint(pParse, |
| 103877 | pParse->pTriggerTab ? SQLITE_CONSTRAINT_TRIGGER : SQLITE_ERROR, |
| 103878 | pExpr->affExpr, pExpr->u.zToken, 0, 0); |
| 103879 | } |
| 103880 | |
| 103881 | break; |
| 103882 | } |
| 103883 | #endif |
| @@ -105454,10 +105628,26 @@ | |
| 105628 | exit_rename_table: |
| 105629 | sqlite3SrcListDelete(db, pSrc); |
| 105630 | sqlite3DbFree(db, zName); |
| 105631 | db->mDbFlags = savedDbFlags; |
| 105632 | } |
| 105633 | |
| 105634 | /* |
| 105635 | ** Write code that will raise an error if the table described by |
| 105636 | ** zDb and zTab is not empty. |
| 105637 | */ |
| 105638 | static void sqlite3ErrorIfNotEmpty( |
| 105639 | Parse *pParse, /* Parsing context */ |
| 105640 | const char *zDb, /* Schema holding the table */ |
| 105641 | const char *zTab, /* Table to check for empty */ |
| 105642 | const char *zErr /* Error message text */ |
| 105643 | ){ |
| 105644 | sqlite3NestedParse(pParse, |
| 105645 | "SELECT raise(ABORT,%Q) FROM \"%w\".\"%w\"", |
| 105646 | zErr, zDb, zTab |
| 105647 | ); |
| 105648 | } |
| 105649 | |
| 105650 | /* |
| 105651 | ** This function is called after an "ALTER TABLE ... ADD" statement |
| 105652 | ** has been parsed. Argument pColDef contains the text of the new |
| 105653 | ** column definition. |
| @@ -105507,11 +105697,12 @@ | |
| 105697 | if( pCol->colFlags & COLFLAG_PRIMKEY ){ |
| 105698 | sqlite3ErrorMsg(pParse, "Cannot add a PRIMARY KEY column"); |
| 105699 | return; |
| 105700 | } |
| 105701 | if( pNew->pIndex ){ |
| 105702 | sqlite3ErrorMsg(pParse, |
| 105703 | "Cannot add a UNIQUE column"); |
| 105704 | return; |
| 105705 | } |
| 105706 | if( (pCol->colFlags & COLFLAG_GENERATED)==0 ){ |
| 105707 | /* If the default value for the new column was specified with a |
| 105708 | ** literal NULL, then set pDflt to 0. This simplifies checking |
| @@ -105520,19 +105711,18 @@ | |
| 105711 | assert( pDflt==0 || pDflt->op==TK_SPAN ); |
| 105712 | if( pDflt && pDflt->pLeft->op==TK_NULL ){ |
| 105713 | pDflt = 0; |
| 105714 | } |
| 105715 | if( (db->flags&SQLITE_ForeignKeys) && pNew->pFKey && pDflt ){ |
| 105716 | sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, |
| 105717 | "Cannot add a REFERENCES column with non-NULL default value"); |
| 105718 | } |
| 105719 | if( pCol->notNull && !pDflt ){ |
| 105720 | sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, |
| 105721 | "Cannot add a NOT NULL column with default value NULL"); |
| 105722 | } |
| 105723 | |
| 105724 | |
| 105725 | /* Ensure the default expression is something that sqlite3ValueFromExpr() |
| 105726 | ** can handle (i.e. not CURRENT_TIME etc.) |
| 105727 | */ |
| 105728 | if( pDflt ){ |
| @@ -105543,18 +105733,17 @@ | |
| 105733 | if( rc!=SQLITE_OK ){ |
| 105734 | assert( db->mallocFailed == 1 ); |
| 105735 | return; |
| 105736 | } |
| 105737 | if( !pVal ){ |
| 105738 | sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, |
| 105739 | "Cannot add a column with non-constant default"); |
| 105740 | } |
| 105741 | sqlite3ValueFree(pVal); |
| 105742 | } |
| 105743 | }else if( pCol->colFlags & COLFLAG_STORED ){ |
| 105744 | sqlite3ErrorIfNotEmpty(pParse, zDb, zTab, "cannot add a STORED column"); |
| 105745 | } |
| 105746 | |
| 105747 | |
| 105748 | /* Modify the CREATE TABLE statement. */ |
| 105749 | zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n); |
| @@ -114373,11 +114562,11 @@ | |
| 114562 | pParse->rc = rc; |
| 114563 | return 1; |
| 114564 | } |
| 114565 | db->aDb[1].pBt = pBt; |
| 114566 | assert( db->aDb[1].pSchema ); |
| 114567 | if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, 0, 0) ){ |
| 114568 | sqlite3OomFault(db); |
| 114569 | return 1; |
| 114570 | } |
| 114571 | } |
| 114572 | return 0; |
| @@ -114484,11 +114673,11 @@ | |
| 114673 | char *p4, /* Error message */ |
| 114674 | i8 p4type, /* P4_STATIC or P4_TRANSIENT */ |
| 114675 | u8 p5Errmsg /* P5_ErrMsg type */ |
| 114676 | ){ |
| 114677 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 114678 | assert( (errCode&0xff)==SQLITE_CONSTRAINT || pParse->nested ); |
| 114679 | if( onError==OE_Abort ){ |
| 114680 | sqlite3MayAbort(pParse); |
| 114681 | } |
| 114682 | sqlite3VdbeAddOp4(v, OP_Halt, errCode, onError, 0, p4, p4type); |
| 114683 | sqlite3VdbeChangeP5(v, p5Errmsg); |
| @@ -116197,10 +116386,11 @@ | |
| 116386 | VdbeModuleComment((v, "GenRowIdxDel for %s", pIdx->zName)); |
| 116387 | r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 1, |
| 116388 | &iPartIdxLabel, pPrior, r1); |
| 116389 | sqlite3VdbeAddOp3(v, OP_IdxDelete, iIdxCur+i, r1, |
| 116390 | pIdx->uniqNotNull ? pIdx->nKeyCol : pIdx->nColumn); |
| 116391 | sqlite3VdbeChangeP5(v, 1); /* Cause IdxDelete to error if no entry found */ |
| 116392 | sqlite3ResolvePartIdxLabel(pParse, iPartIdxLabel); |
| 116393 | pPrior = pIdx; |
| 116394 | } |
| 116395 | } |
| 116396 | |
| @@ -125555,11 +125745,11 @@ | |
| 125745 | }else{ |
| 125746 | /* Malloc may fail when setting the page-size, as there is an internal |
| 125747 | ** buffer that the pager module resizes using sqlite3_realloc(). |
| 125748 | */ |
| 125749 | db->nextPagesize = sqlite3Atoi(zRight); |
| 125750 | if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,0,0) ){ |
| 125751 | sqlite3OomFault(db); |
| 125752 | } |
| 125753 | } |
| 125754 | break; |
| 125755 | } |
| @@ -135193,17 +135383,19 @@ | |
| 135383 | ** |
| 135384 | ** In practice the KeyInfo structure will not be used. It is only |
| 135385 | ** passed to keep OP_OpenRead happy. |
| 135386 | */ |
| 135387 | if( !HasRowid(pTab) ) pBest = sqlite3PrimaryKeyIndex(pTab); |
| 135388 | if( !p->pSrc->a[0].fg.notIndexed ){ |
| 135389 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 135390 | if( pIdx->bUnordered==0 |
| 135391 | && pIdx->szIdxRow<pTab->szTabRow |
| 135392 | && pIdx->pPartIdxWhere==0 |
| 135393 | && (!pBest || pIdx->szIdxRow<pBest->szIdxRow) |
| 135394 | ){ |
| 135395 | pBest = pIdx; |
| 135396 | } |
| 135397 | } |
| 135398 | } |
| 135399 | if( pBest ){ |
| 135400 | iRoot = pBest->tnum; |
| 135401 | pKeyInfo = sqlite3KeyInfoOfIndex(pParse, pBest); |
| @@ -138439,11 +138631,11 @@ | |
| 138631 | db->mDbFlags = saved_mDbFlags; |
| 138632 | db->flags = saved_flags; |
| 138633 | db->nChange = saved_nChange; |
| 138634 | db->nTotalChange = saved_nTotalChange; |
| 138635 | db->mTrace = saved_mTrace; |
| 138636 | sqlite3BtreeSetPageSize(pMain, -1, 0, 1); |
| 138637 | |
| 138638 | /* Currently there is an SQL level transaction open on the vacuum |
| 138639 | ** database. No locks are held on any other files (since the main file |
| 138640 | ** was committed at the btree level). So it safe to end the transaction |
| 138641 | ** by manually setting the autoCommit flag to true and detaching the |
| @@ -161431,12 +161623,11 @@ | |
| 161623 | ** Return non-zero to retry the lock. Return zero to stop trying |
| 161624 | ** and cause SQLite to return SQLITE_BUSY. |
| 161625 | */ |
| 161626 | static int sqliteDefaultBusyCallback( |
| 161627 | void *ptr, /* Database connection */ |
| 161628 | int count /* Number of times table has been busy */ |
| 161629 | ){ |
| 161630 | #if SQLITE_OS_WIN || HAVE_USLEEP |
| 161631 | /* This case is for systems that have support for sleeping for fractions of |
| 161632 | ** a second. Examples: All windows systems, unix systems with usleep() */ |
| 161633 | static const u8 delays[] = |
| @@ -161446,35 +161637,10 @@ | |
| 161637 | # define NDELAY ArraySize(delays) |
| 161638 | sqlite3 *db = (sqlite3 *)ptr; |
| 161639 | int tmout = db->busyTimeout; |
| 161640 | int delay, prior; |
| 161641 | |
| 161642 | assert( count>=0 ); |
| 161643 | if( count < NDELAY ){ |
| 161644 | delay = delays[count]; |
| 161645 | prior = totals[count]; |
| 161646 | }else{ |
| @@ -161490,11 +161656,10 @@ | |
| 161656 | #else |
| 161657 | /* This case for unix systems that lack usleep() support. Sleeping |
| 161658 | ** must be done in increments of whole seconds */ |
| 161659 | sqlite3 *db = (sqlite3 *)ptr; |
| 161660 | int tmout = ((sqlite3 *)ptr)->busyTimeout; |
| 161661 | if( (count+1)*1000 > tmout ){ |
| 161662 | return 0; |
| 161663 | } |
| 161664 | sqlite3OsSleep(db->pVfs, 1000000); |
| 161665 | return 1; |
| @@ -161508,23 +161673,14 @@ | |
| 161673 | ** lock on VFS file pFile. |
| 161674 | ** |
| 161675 | ** If this routine returns non-zero, the lock is retried. If it |
| 161676 | ** returns 0, the operation aborts with an SQLITE_BUSY error. |
| 161677 | */ |
| 161678 | SQLITE_PRIVATE int sqlite3InvokeBusyHandler(BusyHandler *p){ |
| 161679 | int rc; |
| 161680 | if( p->xBusyHandler==0 || p->nBusy<0 ) return 0; |
| 161681 | rc = p->xBusyHandler(p->pBusyArg, p->nBusy); |
| 161682 | if( rc==0 ){ |
| 161683 | p->nBusy = -1; |
| 161684 | }else{ |
| 161685 | p->nBusy++; |
| 161686 | } |
| @@ -161545,11 +161701,10 @@ | |
| 161701 | #endif |
| 161702 | sqlite3_mutex_enter(db->mutex); |
| 161703 | db->busyHandler.xBusyHandler = xBusy; |
| 161704 | db->busyHandler.pBusyArg = pArg; |
| 161705 | db->busyHandler.nBusy = 0; |
| 161706 | db->busyTimeout = 0; |
| 161707 | sqlite3_mutex_leave(db->mutex); |
| 161708 | return SQLITE_OK; |
| 161709 | } |
| 161710 | |
| @@ -161596,11 +161751,10 @@ | |
| 161751 | #endif |
| 161752 | if( ms>0 ){ |
| 161753 | sqlite3_busy_handler(db, (int(*)(void*,int))sqliteDefaultBusyCallback, |
| 161754 | (void*)db); |
| 161755 | db->busyTimeout = ms; |
| 161756 | }else{ |
| 161757 | sqlite3_busy_handler(db, 0, 0); |
| 161758 | } |
| 161759 | return SQLITE_OK; |
| 161760 | } |
| @@ -163071,10 +163225,13 @@ | |
| 163225 | | SQLITE_EnableQPSG |
| 163226 | #endif |
| 163227 | #if defined(SQLITE_DEFAULT_DEFENSIVE) |
| 163228 | | SQLITE_Defensive |
| 163229 | #endif |
| 163230 | #if defined(SQLITE_DEFAULT_LEGACY_ALTER_TABLE) |
| 163231 | | SQLITE_LegacyAlter |
| 163232 | #endif |
| 163233 | ; |
| 163234 | sqlite3HashInit(&db->aCollSeq); |
| 163235 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 163236 | sqlite3HashInit(&db->aModule); |
| 163237 | #endif |
| @@ -163668,11 +163825,11 @@ | |
| 163825 | *(unsigned int*)pArg = sqlite3PagerDataVersion(pPager); |
| 163826 | rc = SQLITE_OK; |
| 163827 | }else if( op==SQLITE_FCNTL_RESERVE_BYTES ){ |
| 163828 | int iNew = *(int*)pArg; |
| 163829 | *(int*)pArg = sqlite3BtreeGetRequestedReserve(pBtree); |
| 163830 | if( iNew>=0 && iNew<=255 ){ |
| 163831 | sqlite3BtreeSetPageSize(pBtree, 0, iNew, 0); |
| 163832 | } |
| 163833 | rc = SQLITE_OK; |
| 163834 | }else{ |
| 163835 | rc = sqlite3OsFileControl(fd, op, pArg); |
| @@ -167905,11 +168062,13 @@ | |
| 168062 | static void fts3ReadNextPos( |
| 168063 | char **pp, /* IN/OUT: Pointer into position-list buffer */ |
| 168064 | sqlite3_int64 *pi /* IN/OUT: Value read from position-list */ |
| 168065 | ){ |
| 168066 | if( (**pp)&0xFE ){ |
| 168067 | int iVal; |
| 168068 | *pp += fts3GetVarint32((*pp), &iVal); |
| 168069 | *pi += iVal; |
| 168070 | *pi -= 2; |
| 168071 | }else{ |
| 168072 | *pi = POSITION_LIST_END; |
| 168073 | } |
| 168074 | } |
| @@ -224505,11 +224664,11 @@ | |
| 224664 | int nArg, /* Number of args */ |
| 224665 | sqlite3_value **apUnused /* Function arguments */ |
| 224666 | ){ |
| 224667 | assert( nArg==0 ); |
| 224668 | UNUSED_PARAM2(nArg, apUnused); |
| 224669 | sqlite3_result_text(pCtx, "fts5: 2020-05-08 19:02:21 3a16c0ce4d8851f79f670d94786032c8007619154ece44647dc9cc5b1f9654ff", -1, SQLITE_TRANSIENT); |
| 224670 | } |
| 224671 | |
| 224672 | /* |
| 224673 | ** Return true if zName is the extension on one of the shadow tables used |
| 224674 | ** by this module. |
| @@ -229288,12 +229447,12 @@ | |
| 229447 | } |
| 229448 | #endif /* SQLITE_CORE */ |
| 229449 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 229450 | |
| 229451 | /************** End of stmt.c ************************************************/ |
| 229452 | #if __LINE__!=229452 |
| 229453 | #undef SQLITE_SOURCE_ID |
| 229454 | #define SQLITE_SOURCE_ID "2020-05-08 19:02:21 3a16c0ce4d8851f79f670d94786032c8007619154ece44647dc9cc5b1f96alt2" |
| 229455 | #endif |
| 229456 | /* Return the source-id for this library */ |
| 229457 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 229458 | /************************** End of sqlite3.c ******************************/ |
| 229459 |
+3
-1
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -123,11 +123,11 @@ | ||
| 123 | 123 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 124 | 124 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 125 | 125 | */ |
| 126 | 126 | #define SQLITE_VERSION "3.32.0" |
| 127 | 127 | #define SQLITE_VERSION_NUMBER 3032000 |
| 128 | -#define SQLITE_SOURCE_ID "2020-05-04 19:52:00 8eee591d3cb9fadfd5cac5543bd66ef9cb371a72d3ad3241fb3bfd67fb216eda" | |
| 128 | +#define SQLITE_SOURCE_ID "2020-05-08 19:02:21 3a16c0ce4d8851f79f670d94786032c8007619154ece44647dc9cc5b1f9654ff" | |
| 129 | 129 | |
| 130 | 130 | /* |
| 131 | 131 | ** CAPI3REF: Run-Time Library Version Numbers |
| 132 | 132 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 133 | 133 | ** |
| @@ -506,18 +506,20 @@ | ||
| 506 | 506 | #define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8)) |
| 507 | 507 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 508 | 508 | #define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8)) |
| 509 | 509 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 510 | 510 | #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8)) |
| 511 | +#define SQLITE_BUSY_TIMEOUT (SQLITE_BUSY | (3<<8)) | |
| 511 | 512 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 512 | 513 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 513 | 514 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 514 | 515 | #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) |
| 515 | 516 | #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */ |
| 516 | 517 | #define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8)) |
| 517 | 518 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 518 | 519 | #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8)) |
| 520 | +#define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8)) | |
| 519 | 521 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 520 | 522 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 521 | 523 | #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) |
| 522 | 524 | #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) |
| 523 | 525 | #define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8)) |
| 524 | 526 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -123,11 +123,11 @@ | |
| 123 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 124 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 125 | */ |
| 126 | #define SQLITE_VERSION "3.32.0" |
| 127 | #define SQLITE_VERSION_NUMBER 3032000 |
| 128 | #define SQLITE_SOURCE_ID "2020-05-04 19:52:00 8eee591d3cb9fadfd5cac5543bd66ef9cb371a72d3ad3241fb3bfd67fb216eda" |
| 129 | |
| 130 | /* |
| 131 | ** CAPI3REF: Run-Time Library Version Numbers |
| 132 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 133 | ** |
| @@ -506,18 +506,20 @@ | |
| 506 | #define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8)) |
| 507 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 508 | #define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8)) |
| 509 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 510 | #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8)) |
| 511 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 512 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 513 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 514 | #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) |
| 515 | #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */ |
| 516 | #define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8)) |
| 517 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 518 | #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8)) |
| 519 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 520 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 521 | #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) |
| 522 | #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) |
| 523 | #define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8)) |
| 524 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -123,11 +123,11 @@ | |
| 123 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 124 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 125 | */ |
| 126 | #define SQLITE_VERSION "3.32.0" |
| 127 | #define SQLITE_VERSION_NUMBER 3032000 |
| 128 | #define SQLITE_SOURCE_ID "2020-05-08 19:02:21 3a16c0ce4d8851f79f670d94786032c8007619154ece44647dc9cc5b1f9654ff" |
| 129 | |
| 130 | /* |
| 131 | ** CAPI3REF: Run-Time Library Version Numbers |
| 132 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 133 | ** |
| @@ -506,18 +506,20 @@ | |
| 506 | #define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8)) |
| 507 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 508 | #define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8)) |
| 509 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 510 | #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8)) |
| 511 | #define SQLITE_BUSY_TIMEOUT (SQLITE_BUSY | (3<<8)) |
| 512 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 513 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 514 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 515 | #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) |
| 516 | #define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */ |
| 517 | #define SQLITE_CANTOPEN_SYMLINK (SQLITE_CANTOPEN | (6<<8)) |
| 518 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 519 | #define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8)) |
| 520 | #define SQLITE_CORRUPT_INDEX (SQLITE_CORRUPT | (3<<8)) |
| 521 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 522 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 523 | #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) |
| 524 | #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) |
| 525 | #define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8)) |
| 526 |