Fossil SCM
Update the built-in SQLite to the latest 3.7.16 beta from upstream.
Commit
6e460c3427d9495976dd3615ec3ba4e5e22bdced
Parent
a5dc5332d4d948b…
2 files changed
+51
-20
+2
-1
+51
-20
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -674,11 +674,11 @@ | ||
| 674 | 674 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 675 | 675 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 676 | 676 | */ |
| 677 | 677 | #define SQLITE_VERSION "3.7.16" |
| 678 | 678 | #define SQLITE_VERSION_NUMBER 3007016 |
| 679 | -#define SQLITE_SOURCE_ID "2013-03-01 23:40:26 780d06c5e54590f677f993fa9c313989c2eab8c7" | |
| 679 | +#define SQLITE_SOURCE_ID "2013-03-06 01:55:27 7097241c1220ada318f8eda938c3e3430b94a606" | |
| 680 | 680 | |
| 681 | 681 | /* |
| 682 | 682 | ** CAPI3REF: Run-Time Library Version Numbers |
| 683 | 683 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 684 | 684 | ** |
| @@ -1048,10 +1048,11 @@ | ||
| 1048 | 1048 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 1049 | 1049 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 1050 | 1050 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 1051 | 1051 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 1052 | 1052 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 1053 | +#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) | |
| 1053 | 1054 | #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) |
| 1054 | 1055 | #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) |
| 1055 | 1056 | #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) |
| 1056 | 1057 | #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) |
| 1057 | 1058 | #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) |
| @@ -23459,11 +23460,14 @@ | ||
| 23459 | 23460 | #endif |
| 23460 | 23461 | }while( fd<0 && errno==EINTR ); |
| 23461 | 23462 | if( fd>=0 ){ |
| 23462 | 23463 | if( m!=0 ){ |
| 23463 | 23464 | struct stat statbuf; |
| 23464 | - if( osFstat(fd, &statbuf)==0 && (statbuf.st_mode&0777)!=m ){ | |
| 23465 | + if( osFstat(fd, &statbuf)==0 | |
| 23466 | + && statbuf.st_size==0 | |
| 23467 | + && (statbuf.st_mode&0777)!=m | |
| 23468 | + ){ | |
| 23465 | 23469 | osFchmod(fd, m); |
| 23466 | 23470 | } |
| 23467 | 23471 | } |
| 23468 | 23472 | #if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0) |
| 23469 | 23473 | osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC); |
| @@ -41111,16 +41115,30 @@ | ||
| 41111 | 41115 | /* |
| 41112 | 41116 | ** Truncate the in-memory database file image to nPage pages. This |
| 41113 | 41117 | ** function does not actually modify the database file on disk. It |
| 41114 | 41118 | ** just sets the internal state of the pager object so that the |
| 41115 | 41119 | ** truncation will be done when the current transaction is committed. |
| 41120 | +** | |
| 41121 | +** This function is only called right before committing a transaction. | |
| 41122 | +** Once this function has been called, the transaction must either be | |
| 41123 | +** rolled back or committed. It is not safe to call this function and | |
| 41124 | +** then continue writing to the database. | |
| 41116 | 41125 | */ |
| 41117 | 41126 | SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){ |
| 41118 | 41127 | assert( pPager->dbSize>=nPage ); |
| 41119 | 41128 | assert( pPager->eState>=PAGER_WRITER_CACHEMOD ); |
| 41120 | 41129 | pPager->dbSize = nPage; |
| 41121 | - assertTruncateConstraint(pPager); | |
| 41130 | + | |
| 41131 | + /* At one point the code here called assertTruncateConstraint() to | |
| 41132 | + ** ensure that all pages being truncated away by this operation are, | |
| 41133 | + ** if one or more savepoints are open, present in the savepoint | |
| 41134 | + ** journal so that they can be restored if the savepoint is rolled | |
| 41135 | + ** back. This is no longer necessary as this function is now only | |
| 41136 | + ** called right before committing a transaction. So although the | |
| 41137 | + ** Pager object may still have open savepoints (Pager.nSavepoint!=0), | |
| 41138 | + ** they cannot be rolled back. So the assertTruncateConstraint() call | |
| 41139 | + ** is no longer correct. */ | |
| 41122 | 41140 | } |
| 41123 | 41141 | |
| 41124 | 41142 | |
| 41125 | 41143 | /* |
| 41126 | 41144 | ** This function is called before attempting a hot-journal rollback. It |
| @@ -42169,10 +42187,15 @@ | ||
| 42169 | 42187 | } |
| 42170 | 42188 | if( rc!=SQLITE_OK ){ |
| 42171 | 42189 | goto failed; |
| 42172 | 42190 | } |
| 42173 | 42191 | if( bHotJournal ){ |
| 42192 | + if( pPager->readOnly ){ | |
| 42193 | + rc = SQLITE_READONLY_ROLLBACK; | |
| 42194 | + goto failed; | |
| 42195 | + } | |
| 42196 | + | |
| 42174 | 42197 | /* Get an EXCLUSIVE lock on the database file. At this point it is |
| 42175 | 42198 | ** important that a RESERVED lock is not obtained on the way to the |
| 42176 | 42199 | ** EXCLUSIVE lock. If it were, another process might open the |
| 42177 | 42200 | ** database file, detect the RESERVED lock, and conclude that the |
| 42178 | 42201 | ** database is safe to read while this process is still rolling the |
| @@ -51340,11 +51363,11 @@ | ||
| 51340 | 51363 | } |
| 51341 | 51364 | releasePage(pFreePg); |
| 51342 | 51365 | }while( bCommit && iFreePg>nFin ); |
| 51343 | 51366 | assert( iFreePg<iLastPg ); |
| 51344 | 51367 | |
| 51345 | - rc = relocatePage(pBt, pLastPg, eType, iPtrPage, iFreePg, nFin!=0); | |
| 51368 | + rc = relocatePage(pBt, pLastPg, eType, iPtrPage, iFreePg, bCommit); | |
| 51346 | 51369 | releasePage(pLastPg); |
| 51347 | 51370 | if( rc!=SQLITE_OK ){ |
| 51348 | 51371 | return rc; |
| 51349 | 51372 | } |
| 51350 | 51373 | } |
| @@ -53211,25 +53234,27 @@ | ||
| 53211 | 53234 | ** |
| 53212 | 53235 | ** SQLITE_OK is returned on success. Any other return value indicates |
| 53213 | 53236 | ** an error. *ppPage and *pPgno are undefined in the event of an error. |
| 53214 | 53237 | ** Do not invoke sqlite3PagerUnref() on *ppPage if an error is returned. |
| 53215 | 53238 | ** |
| 53216 | -** If the "nearby" parameter is not 0, then a (feeble) effort is made to | |
| 53239 | +** If the "nearby" parameter is not 0, then an effort is made to | |
| 53217 | 53240 | ** locate a page close to the page number "nearby". This can be used in an |
| 53218 | 53241 | ** attempt to keep related pages close to each other in the database file, |
| 53219 | 53242 | ** which in turn can make database access faster. |
| 53220 | 53243 | ** |
| 53221 | -** If the "exact" parameter is not 0, and the page-number nearby exists | |
| 53222 | -** anywhere on the free-list, then it is guarenteed to be returned. This | |
| 53223 | -** is only used by auto-vacuum databases when allocating a new table. | |
| 53244 | +** If the eMode parameter is BTALLOC_EXACT and the nearby page exists | |
| 53245 | +** anywhere on the free-list, then it is guaranteed to be returned. If | |
| 53246 | +** eMode is BTALLOC_LT then the page returned will be less than or equal | |
| 53247 | +** to nearby if any such page exists. If eMode is BTALLOC_ANY then there | |
| 53248 | +** are no restrictions on which page is returned. | |
| 53224 | 53249 | */ |
| 53225 | 53250 | static int allocateBtreePage( |
| 53226 | - BtShared *pBt, | |
| 53227 | - MemPage **ppPage, | |
| 53228 | - Pgno *pPgno, | |
| 53229 | - Pgno nearby, | |
| 53230 | - u8 eMode | |
| 53251 | + BtShared *pBt, /* The btree */ | |
| 53252 | + MemPage **ppPage, /* Store pointer to the allocated page here */ | |
| 53253 | + Pgno *pPgno, /* Store the page number here */ | |
| 53254 | + Pgno nearby, /* Search for a page near this one */ | |
| 53255 | + u8 eMode /* BTALLOC_EXACT, BTALLOC_LT, or BTALLOC_ANY */ | |
| 53231 | 53256 | ){ |
| 53232 | 53257 | MemPage *pPage1; |
| 53233 | 53258 | int rc; |
| 53234 | 53259 | u32 n; /* Number of pages on the freelist */ |
| 53235 | 53260 | u32 k; /* Number of leaves on the trunk of the freelist */ |
| @@ -53236,10 +53261,11 @@ | ||
| 53236 | 53261 | MemPage *pTrunk = 0; |
| 53237 | 53262 | MemPage *pPrevTrunk = 0; |
| 53238 | 53263 | Pgno mxPage; /* Total size of the database file */ |
| 53239 | 53264 | |
| 53240 | 53265 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 53266 | + assert( eMode==BTALLOC_ANY || (nearby>0 && pBt->autoVacuum) ); | |
| 53241 | 53267 | pPage1 = pBt->pPage1; |
| 53242 | 53268 | mxPage = btreePagecount(pBt); |
| 53243 | 53269 | n = get4byte(&pPage1->aData[36]); |
| 53244 | 53270 | testcase( n==mxPage-1 ); |
| 53245 | 53271 | if( n>=mxPage ){ |
| @@ -53248,11 +53274,11 @@ | ||
| 53248 | 53274 | if( n>0 ){ |
| 53249 | 53275 | /* There are pages on the freelist. Reuse one of those pages. */ |
| 53250 | 53276 | Pgno iTrunk; |
| 53251 | 53277 | u8 searchList = 0; /* If the free-list must be searched for 'nearby' */ |
| 53252 | 53278 | |
| 53253 | - /* If the 'exact' parameter was true and a query of the pointer-map | |
| 53279 | + /* If eMode==BTALLOC_EXACT and a query of the pointer-map | |
| 53254 | 53280 | ** shows that the page 'nearby' is somewhere on the free-list, then |
| 53255 | 53281 | ** the entire-list will be searched for that page. |
| 53256 | 53282 | */ |
| 53257 | 53283 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 53258 | 53284 | if( eMode==BTALLOC_EXACT ){ |
| @@ -53278,11 +53304,12 @@ | ||
| 53278 | 53304 | if( rc ) return rc; |
| 53279 | 53305 | put4byte(&pPage1->aData[36], n-1); |
| 53280 | 53306 | |
| 53281 | 53307 | /* The code within this loop is run only once if the 'searchList' variable |
| 53282 | 53308 | ** is not true. Otherwise, it runs once for each trunk-page on the |
| 53283 | - ** free-list until the page 'nearby' is located. | |
| 53309 | + ** free-list until the page 'nearby' is located (eMode==BTALLOC_EXACT) | |
| 53310 | + ** or until a page less than 'nearby' is located (eMode==BTALLOC_LT) | |
| 53284 | 53311 | */ |
| 53285 | 53312 | do { |
| 53286 | 53313 | pPrevTrunk = pTrunk; |
| 53287 | 53314 | if( pPrevTrunk ){ |
| 53288 | 53315 | iTrunk = get4byte(&pPrevTrunk->aData[0]); |
| @@ -103557,13 +103584,12 @@ | ||
| 103557 | 103584 | ** |
| 103558 | 103585 | ** If there are multiple terms in the WHERE clause of the form "X <op> <expr>" |
| 103559 | 103586 | ** then try for the one with no dependencies on <expr> - in other words where |
| 103560 | 103587 | ** <expr> is a constant expression of some kind. Only return entries of |
| 103561 | 103588 | ** the form "X <op> Y" where Y is a column in another table if no terms of |
| 103562 | -** the form "X <op> <const-expr>" exist. Other than this priority, if there | |
| 103563 | -** are two or more terms that match, then the choice of which term to return | |
| 103564 | -** is arbitrary. | |
| 103589 | +** the form "X <op> <const-expr>" exist. If no terms with a constant RHS | |
| 103590 | +** exist, try to return a term that does not use WO_EQUIV. | |
| 103565 | 103591 | */ |
| 103566 | 103592 | static WhereTerm *findTerm( |
| 103567 | 103593 | WhereClause *pWC, /* The WHERE clause to be searched */ |
| 103568 | 103594 | int iCur, /* Cursor number of LHS */ |
| 103569 | 103595 | int iColumn, /* Column number of LHS */ |
| @@ -103618,12 +103644,16 @@ | ||
| 103618 | 103644 | } |
| 103619 | 103645 | if( sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ){ |
| 103620 | 103646 | continue; |
| 103621 | 103647 | } |
| 103622 | 103648 | } |
| 103623 | - pResult = pTerm; | |
| 103624 | - if( pTerm->prereqRight==0 ) goto findTerm_success; | |
| 103649 | + if( pTerm->prereqRight==0 ){ | |
| 103650 | + pResult = pTerm; | |
| 103651 | + goto findTerm_success; | |
| 103652 | + }else if( pResult==0 ){ | |
| 103653 | + pResult = pTerm; | |
| 103654 | + } | |
| 103625 | 103655 | } |
| 103626 | 103656 | if( (pTerm->eOperator & WO_EQUIV)!=0 |
| 103627 | 103657 | && nEquiv<ArraySize(aEquiv) |
| 103628 | 103658 | ){ |
| 103629 | 103659 | pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight); |
| @@ -107145,10 +107175,11 @@ | ||
| 107145 | 107175 | testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */ |
| 107146 | 107176 | iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, iReleaseReg); |
| 107147 | 107177 | addrNxt = pLevel->addrNxt; |
| 107148 | 107178 | sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt); |
| 107149 | 107179 | sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, iRowidReg); |
| 107180 | + sqlite3ExprCacheAffinityChange(pParse, iRowidReg, 1); | |
| 107150 | 107181 | sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg); |
| 107151 | 107182 | VdbeComment((v, "pk")); |
| 107152 | 107183 | pLevel->op = OP_Noop; |
| 107153 | 107184 | }else if( pLevel->plan.wsFlags & WHERE_ROWID_RANGE ){ |
| 107154 | 107185 | /* Case 2: We have an inequality comparison against the ROWID field. |
| 107155 | 107186 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -674,11 +674,11 @@ | |
| 674 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 675 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 676 | */ |
| 677 | #define SQLITE_VERSION "3.7.16" |
| 678 | #define SQLITE_VERSION_NUMBER 3007016 |
| 679 | #define SQLITE_SOURCE_ID "2013-03-01 23:40:26 780d06c5e54590f677f993fa9c313989c2eab8c7" |
| 680 | |
| 681 | /* |
| 682 | ** CAPI3REF: Run-Time Library Version Numbers |
| 683 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 684 | ** |
| @@ -1048,10 +1048,11 @@ | |
| 1048 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 1049 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 1050 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 1051 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 1052 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 1053 | #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) |
| 1054 | #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) |
| 1055 | #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) |
| 1056 | #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) |
| 1057 | #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) |
| @@ -23459,11 +23460,14 @@ | |
| 23459 | #endif |
| 23460 | }while( fd<0 && errno==EINTR ); |
| 23461 | if( fd>=0 ){ |
| 23462 | if( m!=0 ){ |
| 23463 | struct stat statbuf; |
| 23464 | if( osFstat(fd, &statbuf)==0 && (statbuf.st_mode&0777)!=m ){ |
| 23465 | osFchmod(fd, m); |
| 23466 | } |
| 23467 | } |
| 23468 | #if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0) |
| 23469 | osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC); |
| @@ -41111,16 +41115,30 @@ | |
| 41111 | /* |
| 41112 | ** Truncate the in-memory database file image to nPage pages. This |
| 41113 | ** function does not actually modify the database file on disk. It |
| 41114 | ** just sets the internal state of the pager object so that the |
| 41115 | ** truncation will be done when the current transaction is committed. |
| 41116 | */ |
| 41117 | SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){ |
| 41118 | assert( pPager->dbSize>=nPage ); |
| 41119 | assert( pPager->eState>=PAGER_WRITER_CACHEMOD ); |
| 41120 | pPager->dbSize = nPage; |
| 41121 | assertTruncateConstraint(pPager); |
| 41122 | } |
| 41123 | |
| 41124 | |
| 41125 | /* |
| 41126 | ** This function is called before attempting a hot-journal rollback. It |
| @@ -42169,10 +42187,15 @@ | |
| 42169 | } |
| 42170 | if( rc!=SQLITE_OK ){ |
| 42171 | goto failed; |
| 42172 | } |
| 42173 | if( bHotJournal ){ |
| 42174 | /* Get an EXCLUSIVE lock on the database file. At this point it is |
| 42175 | ** important that a RESERVED lock is not obtained on the way to the |
| 42176 | ** EXCLUSIVE lock. If it were, another process might open the |
| 42177 | ** database file, detect the RESERVED lock, and conclude that the |
| 42178 | ** database is safe to read while this process is still rolling the |
| @@ -51340,11 +51363,11 @@ | |
| 51340 | } |
| 51341 | releasePage(pFreePg); |
| 51342 | }while( bCommit && iFreePg>nFin ); |
| 51343 | assert( iFreePg<iLastPg ); |
| 51344 | |
| 51345 | rc = relocatePage(pBt, pLastPg, eType, iPtrPage, iFreePg, nFin!=0); |
| 51346 | releasePage(pLastPg); |
| 51347 | if( rc!=SQLITE_OK ){ |
| 51348 | return rc; |
| 51349 | } |
| 51350 | } |
| @@ -53211,25 +53234,27 @@ | |
| 53211 | ** |
| 53212 | ** SQLITE_OK is returned on success. Any other return value indicates |
| 53213 | ** an error. *ppPage and *pPgno are undefined in the event of an error. |
| 53214 | ** Do not invoke sqlite3PagerUnref() on *ppPage if an error is returned. |
| 53215 | ** |
| 53216 | ** If the "nearby" parameter is not 0, then a (feeble) effort is made to |
| 53217 | ** locate a page close to the page number "nearby". This can be used in an |
| 53218 | ** attempt to keep related pages close to each other in the database file, |
| 53219 | ** which in turn can make database access faster. |
| 53220 | ** |
| 53221 | ** If the "exact" parameter is not 0, and the page-number nearby exists |
| 53222 | ** anywhere on the free-list, then it is guarenteed to be returned. This |
| 53223 | ** is only used by auto-vacuum databases when allocating a new table. |
| 53224 | */ |
| 53225 | static int allocateBtreePage( |
| 53226 | BtShared *pBt, |
| 53227 | MemPage **ppPage, |
| 53228 | Pgno *pPgno, |
| 53229 | Pgno nearby, |
| 53230 | u8 eMode |
| 53231 | ){ |
| 53232 | MemPage *pPage1; |
| 53233 | int rc; |
| 53234 | u32 n; /* Number of pages on the freelist */ |
| 53235 | u32 k; /* Number of leaves on the trunk of the freelist */ |
| @@ -53236,10 +53261,11 @@ | |
| 53236 | MemPage *pTrunk = 0; |
| 53237 | MemPage *pPrevTrunk = 0; |
| 53238 | Pgno mxPage; /* Total size of the database file */ |
| 53239 | |
| 53240 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 53241 | pPage1 = pBt->pPage1; |
| 53242 | mxPage = btreePagecount(pBt); |
| 53243 | n = get4byte(&pPage1->aData[36]); |
| 53244 | testcase( n==mxPage-1 ); |
| 53245 | if( n>=mxPage ){ |
| @@ -53248,11 +53274,11 @@ | |
| 53248 | if( n>0 ){ |
| 53249 | /* There are pages on the freelist. Reuse one of those pages. */ |
| 53250 | Pgno iTrunk; |
| 53251 | u8 searchList = 0; /* If the free-list must be searched for 'nearby' */ |
| 53252 | |
| 53253 | /* If the 'exact' parameter was true and a query of the pointer-map |
| 53254 | ** shows that the page 'nearby' is somewhere on the free-list, then |
| 53255 | ** the entire-list will be searched for that page. |
| 53256 | */ |
| 53257 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 53258 | if( eMode==BTALLOC_EXACT ){ |
| @@ -53278,11 +53304,12 @@ | |
| 53278 | if( rc ) return rc; |
| 53279 | put4byte(&pPage1->aData[36], n-1); |
| 53280 | |
| 53281 | /* The code within this loop is run only once if the 'searchList' variable |
| 53282 | ** is not true. Otherwise, it runs once for each trunk-page on the |
| 53283 | ** free-list until the page 'nearby' is located. |
| 53284 | */ |
| 53285 | do { |
| 53286 | pPrevTrunk = pTrunk; |
| 53287 | if( pPrevTrunk ){ |
| 53288 | iTrunk = get4byte(&pPrevTrunk->aData[0]); |
| @@ -103557,13 +103584,12 @@ | |
| 103557 | ** |
| 103558 | ** If there are multiple terms in the WHERE clause of the form "X <op> <expr>" |
| 103559 | ** then try for the one with no dependencies on <expr> - in other words where |
| 103560 | ** <expr> is a constant expression of some kind. Only return entries of |
| 103561 | ** the form "X <op> Y" where Y is a column in another table if no terms of |
| 103562 | ** the form "X <op> <const-expr>" exist. Other than this priority, if there |
| 103563 | ** are two or more terms that match, then the choice of which term to return |
| 103564 | ** is arbitrary. |
| 103565 | */ |
| 103566 | static WhereTerm *findTerm( |
| 103567 | WhereClause *pWC, /* The WHERE clause to be searched */ |
| 103568 | int iCur, /* Cursor number of LHS */ |
| 103569 | int iColumn, /* Column number of LHS */ |
| @@ -103618,12 +103644,16 @@ | |
| 103618 | } |
| 103619 | if( sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ){ |
| 103620 | continue; |
| 103621 | } |
| 103622 | } |
| 103623 | pResult = pTerm; |
| 103624 | if( pTerm->prereqRight==0 ) goto findTerm_success; |
| 103625 | } |
| 103626 | if( (pTerm->eOperator & WO_EQUIV)!=0 |
| 103627 | && nEquiv<ArraySize(aEquiv) |
| 103628 | ){ |
| 103629 | pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight); |
| @@ -107145,10 +107175,11 @@ | |
| 107145 | testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */ |
| 107146 | iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, iReleaseReg); |
| 107147 | addrNxt = pLevel->addrNxt; |
| 107148 | sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt); |
| 107149 | sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, iRowidReg); |
| 107150 | sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg); |
| 107151 | VdbeComment((v, "pk")); |
| 107152 | pLevel->op = OP_Noop; |
| 107153 | }else if( pLevel->plan.wsFlags & WHERE_ROWID_RANGE ){ |
| 107154 | /* Case 2: We have an inequality comparison against the ROWID field. |
| 107155 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -674,11 +674,11 @@ | |
| 674 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 675 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 676 | */ |
| 677 | #define SQLITE_VERSION "3.7.16" |
| 678 | #define SQLITE_VERSION_NUMBER 3007016 |
| 679 | #define SQLITE_SOURCE_ID "2013-03-06 01:55:27 7097241c1220ada318f8eda938c3e3430b94a606" |
| 680 | |
| 681 | /* |
| 682 | ** CAPI3REF: Run-Time Library Version Numbers |
| 683 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 684 | ** |
| @@ -1048,10 +1048,11 @@ | |
| 1048 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 1049 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 1050 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 1051 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 1052 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 1053 | #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) |
| 1054 | #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) |
| 1055 | #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) |
| 1056 | #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) |
| 1057 | #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) |
| 1058 | #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) |
| @@ -23459,11 +23460,14 @@ | |
| 23460 | #endif |
| 23461 | }while( fd<0 && errno==EINTR ); |
| 23462 | if( fd>=0 ){ |
| 23463 | if( m!=0 ){ |
| 23464 | struct stat statbuf; |
| 23465 | if( osFstat(fd, &statbuf)==0 |
| 23466 | && statbuf.st_size==0 |
| 23467 | && (statbuf.st_mode&0777)!=m |
| 23468 | ){ |
| 23469 | osFchmod(fd, m); |
| 23470 | } |
| 23471 | } |
| 23472 | #if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0) |
| 23473 | osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC); |
| @@ -41111,16 +41115,30 @@ | |
| 41115 | /* |
| 41116 | ** Truncate the in-memory database file image to nPage pages. This |
| 41117 | ** function does not actually modify the database file on disk. It |
| 41118 | ** just sets the internal state of the pager object so that the |
| 41119 | ** truncation will be done when the current transaction is committed. |
| 41120 | ** |
| 41121 | ** This function is only called right before committing a transaction. |
| 41122 | ** Once this function has been called, the transaction must either be |
| 41123 | ** rolled back or committed. It is not safe to call this function and |
| 41124 | ** then continue writing to the database. |
| 41125 | */ |
| 41126 | SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){ |
| 41127 | assert( pPager->dbSize>=nPage ); |
| 41128 | assert( pPager->eState>=PAGER_WRITER_CACHEMOD ); |
| 41129 | pPager->dbSize = nPage; |
| 41130 | |
| 41131 | /* At one point the code here called assertTruncateConstraint() to |
| 41132 | ** ensure that all pages being truncated away by this operation are, |
| 41133 | ** if one or more savepoints are open, present in the savepoint |
| 41134 | ** journal so that they can be restored if the savepoint is rolled |
| 41135 | ** back. This is no longer necessary as this function is now only |
| 41136 | ** called right before committing a transaction. So although the |
| 41137 | ** Pager object may still have open savepoints (Pager.nSavepoint!=0), |
| 41138 | ** they cannot be rolled back. So the assertTruncateConstraint() call |
| 41139 | ** is no longer correct. */ |
| 41140 | } |
| 41141 | |
| 41142 | |
| 41143 | /* |
| 41144 | ** This function is called before attempting a hot-journal rollback. It |
| @@ -42169,10 +42187,15 @@ | |
| 42187 | } |
| 42188 | if( rc!=SQLITE_OK ){ |
| 42189 | goto failed; |
| 42190 | } |
| 42191 | if( bHotJournal ){ |
| 42192 | if( pPager->readOnly ){ |
| 42193 | rc = SQLITE_READONLY_ROLLBACK; |
| 42194 | goto failed; |
| 42195 | } |
| 42196 | |
| 42197 | /* Get an EXCLUSIVE lock on the database file. At this point it is |
| 42198 | ** important that a RESERVED lock is not obtained on the way to the |
| 42199 | ** EXCLUSIVE lock. If it were, another process might open the |
| 42200 | ** database file, detect the RESERVED lock, and conclude that the |
| 42201 | ** database is safe to read while this process is still rolling the |
| @@ -51340,11 +51363,11 @@ | |
| 51363 | } |
| 51364 | releasePage(pFreePg); |
| 51365 | }while( bCommit && iFreePg>nFin ); |
| 51366 | assert( iFreePg<iLastPg ); |
| 51367 | |
| 51368 | rc = relocatePage(pBt, pLastPg, eType, iPtrPage, iFreePg, bCommit); |
| 51369 | releasePage(pLastPg); |
| 51370 | if( rc!=SQLITE_OK ){ |
| 51371 | return rc; |
| 51372 | } |
| 51373 | } |
| @@ -53211,25 +53234,27 @@ | |
| 53234 | ** |
| 53235 | ** SQLITE_OK is returned on success. Any other return value indicates |
| 53236 | ** an error. *ppPage and *pPgno are undefined in the event of an error. |
| 53237 | ** Do not invoke sqlite3PagerUnref() on *ppPage if an error is returned. |
| 53238 | ** |
| 53239 | ** If the "nearby" parameter is not 0, then an effort is made to |
| 53240 | ** locate a page close to the page number "nearby". This can be used in an |
| 53241 | ** attempt to keep related pages close to each other in the database file, |
| 53242 | ** which in turn can make database access faster. |
| 53243 | ** |
| 53244 | ** If the eMode parameter is BTALLOC_EXACT and the nearby page exists |
| 53245 | ** anywhere on the free-list, then it is guaranteed to be returned. If |
| 53246 | ** eMode is BTALLOC_LT then the page returned will be less than or equal |
| 53247 | ** to nearby if any such page exists. If eMode is BTALLOC_ANY then there |
| 53248 | ** are no restrictions on which page is returned. |
| 53249 | */ |
| 53250 | static int allocateBtreePage( |
| 53251 | BtShared *pBt, /* The btree */ |
| 53252 | MemPage **ppPage, /* Store pointer to the allocated page here */ |
| 53253 | Pgno *pPgno, /* Store the page number here */ |
| 53254 | Pgno nearby, /* Search for a page near this one */ |
| 53255 | u8 eMode /* BTALLOC_EXACT, BTALLOC_LT, or BTALLOC_ANY */ |
| 53256 | ){ |
| 53257 | MemPage *pPage1; |
| 53258 | int rc; |
| 53259 | u32 n; /* Number of pages on the freelist */ |
| 53260 | u32 k; /* Number of leaves on the trunk of the freelist */ |
| @@ -53236,10 +53261,11 @@ | |
| 53261 | MemPage *pTrunk = 0; |
| 53262 | MemPage *pPrevTrunk = 0; |
| 53263 | Pgno mxPage; /* Total size of the database file */ |
| 53264 | |
| 53265 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 53266 | assert( eMode==BTALLOC_ANY || (nearby>0 && pBt->autoVacuum) ); |
| 53267 | pPage1 = pBt->pPage1; |
| 53268 | mxPage = btreePagecount(pBt); |
| 53269 | n = get4byte(&pPage1->aData[36]); |
| 53270 | testcase( n==mxPage-1 ); |
| 53271 | if( n>=mxPage ){ |
| @@ -53248,11 +53274,11 @@ | |
| 53274 | if( n>0 ){ |
| 53275 | /* There are pages on the freelist. Reuse one of those pages. */ |
| 53276 | Pgno iTrunk; |
| 53277 | u8 searchList = 0; /* If the free-list must be searched for 'nearby' */ |
| 53278 | |
| 53279 | /* If eMode==BTALLOC_EXACT and a query of the pointer-map |
| 53280 | ** shows that the page 'nearby' is somewhere on the free-list, then |
| 53281 | ** the entire-list will be searched for that page. |
| 53282 | */ |
| 53283 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 53284 | if( eMode==BTALLOC_EXACT ){ |
| @@ -53278,11 +53304,12 @@ | |
| 53304 | if( rc ) return rc; |
| 53305 | put4byte(&pPage1->aData[36], n-1); |
| 53306 | |
| 53307 | /* The code within this loop is run only once if the 'searchList' variable |
| 53308 | ** is not true. Otherwise, it runs once for each trunk-page on the |
| 53309 | ** free-list until the page 'nearby' is located (eMode==BTALLOC_EXACT) |
| 53310 | ** or until a page less than 'nearby' is located (eMode==BTALLOC_LT) |
| 53311 | */ |
| 53312 | do { |
| 53313 | pPrevTrunk = pTrunk; |
| 53314 | if( pPrevTrunk ){ |
| 53315 | iTrunk = get4byte(&pPrevTrunk->aData[0]); |
| @@ -103557,13 +103584,12 @@ | |
| 103584 | ** |
| 103585 | ** If there are multiple terms in the WHERE clause of the form "X <op> <expr>" |
| 103586 | ** then try for the one with no dependencies on <expr> - in other words where |
| 103587 | ** <expr> is a constant expression of some kind. Only return entries of |
| 103588 | ** the form "X <op> Y" where Y is a column in another table if no terms of |
| 103589 | ** the form "X <op> <const-expr>" exist. If no terms with a constant RHS |
| 103590 | ** exist, try to return a term that does not use WO_EQUIV. |
| 103591 | */ |
| 103592 | static WhereTerm *findTerm( |
| 103593 | WhereClause *pWC, /* The WHERE clause to be searched */ |
| 103594 | int iCur, /* Cursor number of LHS */ |
| 103595 | int iColumn, /* Column number of LHS */ |
| @@ -103618,12 +103644,16 @@ | |
| 103644 | } |
| 103645 | if( sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ){ |
| 103646 | continue; |
| 103647 | } |
| 103648 | } |
| 103649 | if( pTerm->prereqRight==0 ){ |
| 103650 | pResult = pTerm; |
| 103651 | goto findTerm_success; |
| 103652 | }else if( pResult==0 ){ |
| 103653 | pResult = pTerm; |
| 103654 | } |
| 103655 | } |
| 103656 | if( (pTerm->eOperator & WO_EQUIV)!=0 |
| 103657 | && nEquiv<ArraySize(aEquiv) |
| 103658 | ){ |
| 103659 | pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight); |
| @@ -107145,10 +107175,11 @@ | |
| 107175 | testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */ |
| 107176 | iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, iReleaseReg); |
| 107177 | addrNxt = pLevel->addrNxt; |
| 107178 | sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt); |
| 107179 | sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, iRowidReg); |
| 107180 | sqlite3ExprCacheAffinityChange(pParse, iRowidReg, 1); |
| 107181 | sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg); |
| 107182 | VdbeComment((v, "pk")); |
| 107183 | pLevel->op = OP_Noop; |
| 107184 | }else if( pLevel->plan.wsFlags & WHERE_ROWID_RANGE ){ |
| 107185 | /* Case 2: We have an inequality comparison against the ROWID field. |
| 107186 |
+2
-1
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -107,11 +107,11 @@ | ||
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 109 | */ |
| 110 | 110 | #define SQLITE_VERSION "3.7.16" |
| 111 | 111 | #define SQLITE_VERSION_NUMBER 3007016 |
| 112 | -#define SQLITE_SOURCE_ID "2013-03-01 23:40:26 780d06c5e54590f677f993fa9c313989c2eab8c7" | |
| 112 | +#define SQLITE_SOURCE_ID "2013-03-06 01:55:27 7097241c1220ada318f8eda938c3e3430b94a606" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| @@ -481,10 +481,11 @@ | ||
| 481 | 481 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 482 | 482 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 483 | 483 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 484 | 484 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 485 | 485 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 486 | +#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) | |
| 486 | 487 | #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) |
| 487 | 488 | #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) |
| 488 | 489 | #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) |
| 489 | 490 | #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) |
| 490 | 491 | #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) |
| 491 | 492 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -107,11 +107,11 @@ | |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.7.16" |
| 111 | #define SQLITE_VERSION_NUMBER 3007016 |
| 112 | #define SQLITE_SOURCE_ID "2013-03-01 23:40:26 780d06c5e54590f677f993fa9c313989c2eab8c7" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -481,10 +481,11 @@ | |
| 481 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 482 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 483 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 484 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 485 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 486 | #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) |
| 487 | #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) |
| 488 | #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) |
| 489 | #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) |
| 490 | #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) |
| 491 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -107,11 +107,11 @@ | |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.7.16" |
| 111 | #define SQLITE_VERSION_NUMBER 3007016 |
| 112 | #define SQLITE_SOURCE_ID "2013-03-06 01:55:27 7097241c1220ada318f8eda938c3e3430b94a606" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -481,10 +481,11 @@ | |
| 481 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 482 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 483 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 484 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 485 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 486 | #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) |
| 487 | #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) |
| 488 | #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) |
| 489 | #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) |
| 490 | #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) |
| 491 | #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) |
| 492 |