1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Use the read and write version fields of the database header to mark a database as operating in wal-mode.

FossilOrigin-Name: 96bef18c1411c3e0348295886f105e1646c46320
This commit is contained in:
dan
2010-04-20 18:53:15 +00:00
parent 8d22a17411
commit e04dc88be5
10 changed files with 327 additions and 128 deletions

View File

@@ -2261,13 +2261,25 @@ static int lockBtree(BtShared *pBt){
if( memcmp(page1, zMagicHeader, 16)!=0 ){
goto page1_init_failed;
}
if( page1[18]>1 ){
if( page1[18]>2 ){
pBt->readOnly = 1;
}
if( page1[19]>1 ){
if( page1[19]>2 ){
goto page1_init_failed;
}
/* If the write version is set to 2, turn on write-ahead logging mode. */
if( page1[19]==2 ){
int isOpen = 0;
rc = sqlite3PagerOpenLog(pBt->pPager, &isOpen);
if( rc!=SQLITE_OK ){
goto page1_init_failed;
}else if( isOpen==0 ){
releasePage(pPage1);
return SQLITE_OK;
}
}
/* The maximum embedded fraction must be exactly 25%. And the minimum
** embedded fraction must be 12.5% for both leaf-data and non-leaf-data.
** The original design allowed these amounts to vary, but as of
@@ -7963,3 +7975,26 @@ void sqlite3BtreeCacheOverflow(BtCursor *pCur){
pCur->isIncrblobHandle = 1;
}
#endif
/*
** Set both the "read version" (single byte at byte offset 18) and
** "write version" (single byte at byte offset 19) fields in the database
** header to iVersion.
*/
int sqlite3BtreeSetVersion(Btree *pBtree, int iVersion){
BtShared *pBt = pBtree->pBt;
int rc; /* Return code */
assert( pBtree->inTrans==TRANS_WRITE );
assert( pBt->pPage1 );
assert( iVersion==1 || iVersion==2 );
rc = sqlite3PagerWrite(pBt->pPage1->pDbPage);
if( rc==SQLITE_OK ){
u8 *aData = pBt->pPage1->aData;
aData[18] = (u8)iVersion;
aData[19] = (u8)iVersion;
}
return rc;
}