Fossil SCM

Update the built-in SQLite to the latest 3.7.16 beta from upstream.

drh 2013-03-06 02:15 trunk
Commit 6e460c3427d9495976dd3615ec3ba4e5e22bdced
2 files changed +51 -20 +2 -1
+51 -20
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -674,11 +674,11 @@
674674
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
675675
** [sqlite_version()] and [sqlite_source_id()].
676676
*/
677677
#define SQLITE_VERSION "3.7.16"
678678
#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"
680680
681681
/*
682682
** CAPI3REF: Run-Time Library Version Numbers
683683
** KEYWORDS: sqlite3_version, sqlite3_sourceid
684684
**
@@ -1048,10 +1048,11 @@
10481048
#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
10491049
#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
10501050
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
10511051
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
10521052
#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
1053
+#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
10531054
#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
10541055
#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
10551056
#define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
10561057
#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
10571058
#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
@@ -23459,11 +23460,14 @@
2345923460
#endif
2346023461
}while( fd<0 && errno==EINTR );
2346123462
if( fd>=0 ){
2346223463
if( m!=0 ){
2346323464
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
+ ){
2346523469
osFchmod(fd, m);
2346623470
}
2346723471
}
2346823472
#if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
2346923473
osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
@@ -41111,16 +41115,30 @@
4111141115
/*
4111241116
** Truncate the in-memory database file image to nPage pages. This
4111341117
** function does not actually modify the database file on disk. It
4111441118
** just sets the internal state of the pager object so that the
4111541119
** 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.
4111641125
*/
4111741126
SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
4111841127
assert( pPager->dbSize>=nPage );
4111941128
assert( pPager->eState>=PAGER_WRITER_CACHEMOD );
4112041129
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. */
4112241140
}
4112341141
4112441142
4112541143
/*
4112641144
** This function is called before attempting a hot-journal rollback. It
@@ -42169,10 +42187,15 @@
4216942187
}
4217042188
if( rc!=SQLITE_OK ){
4217142189
goto failed;
4217242190
}
4217342191
if( bHotJournal ){
42192
+ if( pPager->readOnly ){
42193
+ rc = SQLITE_READONLY_ROLLBACK;
42194
+ goto failed;
42195
+ }
42196
+
4217442197
/* Get an EXCLUSIVE lock on the database file. At this point it is
4217542198
** important that a RESERVED lock is not obtained on the way to the
4217642199
** EXCLUSIVE lock. If it were, another process might open the
4217742200
** database file, detect the RESERVED lock, and conclude that the
4217842201
** database is safe to read while this process is still rolling the
@@ -51340,11 +51363,11 @@
5134051363
}
5134151364
releasePage(pFreePg);
5134251365
}while( bCommit && iFreePg>nFin );
5134351366
assert( iFreePg<iLastPg );
5134451367
51345
- rc = relocatePage(pBt, pLastPg, eType, iPtrPage, iFreePg, nFin!=0);
51368
+ rc = relocatePage(pBt, pLastPg, eType, iPtrPage, iFreePg, bCommit);
5134651369
releasePage(pLastPg);
5134751370
if( rc!=SQLITE_OK ){
5134851371
return rc;
5134951372
}
5135051373
}
@@ -53211,25 +53234,27 @@
5321153234
**
5321253235
** SQLITE_OK is returned on success. Any other return value indicates
5321353236
** an error. *ppPage and *pPgno are undefined in the event of an error.
5321453237
** Do not invoke sqlite3PagerUnref() on *ppPage if an error is returned.
5321553238
**
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
5321753240
** locate a page close to the page number "nearby". This can be used in an
5321853241
** attempt to keep related pages close to each other in the database file,
5321953242
** which in turn can make database access faster.
5322053243
**
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.
5322453249
*/
5322553250
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 */
5323153256
){
5323253257
MemPage *pPage1;
5323353258
int rc;
5323453259
u32 n; /* Number of pages on the freelist */
5323553260
u32 k; /* Number of leaves on the trunk of the freelist */
@@ -53236,10 +53261,11 @@
5323653261
MemPage *pTrunk = 0;
5323753262
MemPage *pPrevTrunk = 0;
5323853263
Pgno mxPage; /* Total size of the database file */
5323953264
5324053265
assert( sqlite3_mutex_held(pBt->mutex) );
53266
+ assert( eMode==BTALLOC_ANY || (nearby>0 && pBt->autoVacuum) );
5324153267
pPage1 = pBt->pPage1;
5324253268
mxPage = btreePagecount(pBt);
5324353269
n = get4byte(&pPage1->aData[36]);
5324453270
testcase( n==mxPage-1 );
5324553271
if( n>=mxPage ){
@@ -53248,11 +53274,11 @@
5324853274
if( n>0 ){
5324953275
/* There are pages on the freelist. Reuse one of those pages. */
5325053276
Pgno iTrunk;
5325153277
u8 searchList = 0; /* If the free-list must be searched for 'nearby' */
5325253278
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
5325453280
** shows that the page 'nearby' is somewhere on the free-list, then
5325553281
** the entire-list will be searched for that page.
5325653282
*/
5325753283
#ifndef SQLITE_OMIT_AUTOVACUUM
5325853284
if( eMode==BTALLOC_EXACT ){
@@ -53278,11 +53304,12 @@
5327853304
if( rc ) return rc;
5327953305
put4byte(&pPage1->aData[36], n-1);
5328053306
5328153307
/* The code within this loop is run only once if the 'searchList' variable
5328253308
** 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)
5328453311
*/
5328553312
do {
5328653313
pPrevTrunk = pTrunk;
5328753314
if( pPrevTrunk ){
5328853315
iTrunk = get4byte(&pPrevTrunk->aData[0]);
@@ -103557,13 +103584,12 @@
103557103584
**
103558103585
** If there are multiple terms in the WHERE clause of the form "X <op> <expr>"
103559103586
** then try for the one with no dependencies on <expr> - in other words where
103560103587
** <expr> is a constant expression of some kind. Only return entries of
103561103588
** 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.
103565103591
*/
103566103592
static WhereTerm *findTerm(
103567103593
WhereClause *pWC, /* The WHERE clause to be searched */
103568103594
int iCur, /* Cursor number of LHS */
103569103595
int iColumn, /* Column number of LHS */
@@ -103618,12 +103644,16 @@
103618103644
}
103619103645
if( sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ){
103620103646
continue;
103621103647
}
103622103648
}
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
+ }
103625103655
}
103626103656
if( (pTerm->eOperator & WO_EQUIV)!=0
103627103657
&& nEquiv<ArraySize(aEquiv)
103628103658
){
103629103659
pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight);
@@ -107145,10 +107175,11 @@
107145107175
testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */
107146107176
iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, iReleaseReg);
107147107177
addrNxt = pLevel->addrNxt;
107148107178
sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt);
107149107179
sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, iRowidReg);
107180
+ sqlite3ExprCacheAffinityChange(pParse, iRowidReg, 1);
107150107181
sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
107151107182
VdbeComment((v, "pk"));
107152107183
pLevel->op = OP_Noop;
107153107184
}else if( pLevel->plan.wsFlags & WHERE_ROWID_RANGE ){
107154107185
/* Case 2: We have an inequality comparison against the ROWID field.
107155107186
--- 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 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.7.16"
111111
#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"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -481,10 +481,11 @@
481481
#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
482482
#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
483483
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
484484
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
485485
#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
486
+#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
486487
#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
487488
#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
488489
#define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
489490
#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
490491
#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
491492
--- 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

Keyboard Shortcuts

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