diff options
author | drh <drh@noemail.net> | 2011-11-16 23:29:37 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2011-11-16 23:29:37 +0000 |
commit | f20fb8c6f3e65f10675baabe37008d5d74e3dbfd (patch) | |
tree | 4e5d71a4cc47d4dea62139e768c1fd8ad2f9bbe9 /src | |
parent | 09419b4bae13024d9bfc011e0a108eb3dfc6296f (diff) | |
parent | c90747313ea9489052675421a140eaf00a71b1ad (diff) | |
download | sqlite-f20fb8c6f3e65f10675baabe37008d5d74e3dbfd.tar.gz sqlite-f20fb8c6f3e65f10675baabe37008d5d74e3dbfd.zip |
Back out the [ceee03c79a] change.
FossilOrigin-Name: 69ec53fc1c60b07bf4aaa983dcd5bf3164fb1ea5
Diffstat (limited to 'src')
-rw-r--r-- | src/btree.c | 66 |
1 files changed, 39 insertions, 27 deletions
diff --git a/src/btree.c b/src/btree.c index 43933fa27..a1b05e1f3 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1776,12 +1776,7 @@ int sqlite3BtreeOpen( sqlite3_free(p); return SQLITE_NOMEM; } - rc = sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname); - if( rc ){ - sqlite3_free(zFullPathname); - sqlite3_free(p); - return rc; - } + sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname); #if SQLITE_THREADSAFE mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN); sqlite3_mutex_enter(mutexOpen); @@ -2482,9 +2477,9 @@ static int newDatabase(BtShared *pBt){ } pP1 = pBt->pPage1; assert( pP1!=0 ); + data = pP1->aData; rc = sqlite3PagerWrite(pP1->pDbPage); if( rc ) return rc; - data = pP1->aData; memcpy(data, zMagicHeader, sizeof(zMagicHeader)); assert( sizeof(zMagicHeader)==16 ); data[16] = (u8)((pBt->pageSize>>8)&0xff); @@ -3783,6 +3778,38 @@ static int getOverflowPage( } /* +** Copy data from a buffer to a page, or from a page to a buffer. +** +** pPayload is a pointer to data stored on database page pDbPage. +** If argument eOp is false, then nByte bytes of data are copied +** from pPayload to the buffer pointed at by pBuf. If eOp is true, +** then sqlite3PagerWrite() is called on pDbPage and nByte bytes +** of data are copied from the buffer pBuf to pPayload. +** +** SQLITE_OK is returned on success, otherwise an error code. +*/ +static int copyPayload( + void *pPayload, /* Pointer to page data */ + void *pBuf, /* Pointer to buffer */ + int nByte, /* Number of bytes to copy */ + int eOp, /* 0 -> copy from page, 1 -> copy to page */ + DbPage *pDbPage /* Page containing pPayload */ +){ + if( eOp ){ + /* Copy data from buffer to page (a write operation) */ + int rc = sqlite3PagerWrite(pDbPage); + if( rc!=SQLITE_OK ){ + return rc; + } + memcpy(pPayload, pBuf, nByte); + }else{ + /* Copy data from page to buffer (a read operation) */ + memcpy(pBuf, pPayload, nByte); + } + return SQLITE_OK; +} + +/* ** This function is used to read or overwrite payload information ** for the entry that the pCur cursor is pointing to. If the eOp ** parameter is 0, this is a read operation (data copied into @@ -3829,7 +3856,6 @@ static int accessPayload( assert( pCur->aiIdx[pCur->iPage]<pPage->nCell ); assert( cursorHoldsMutex(pCur) ); - getCellInfo(pCur); aPayload = pCur->info.pCell + pCur->info.nHeader; nKey = (pPage->intKey ? 0 : (int)pCur->info.nKey); @@ -3847,14 +3873,7 @@ static int accessPayload( if( a+offset>pCur->info.nLocal ){ a = pCur->info.nLocal - offset; } - if( eOp ){ - if( (rc = sqlite3PagerWrite(pPage->pDbPage))!=SQLITE_OK ) return rc; - getCellInfo(pCur); - aPayload = pCur->info.pCell + pCur->info.nHeader; - memcpy(aPayload+offset, pBuf, a); - }else{ - memcpy(pBuf, aPayload+offset, a); - } + rc = copyPayload(&aPayload[offset], pBuf, a, eOp, pPage->pDbPage); offset = 0; pBuf += a; amt -= a; @@ -3965,17 +3984,9 @@ static int accessPayload( DbPage *pDbPage; rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage); if( rc==SQLITE_OK ){ - if( eOp && (rc = sqlite3PagerWrite(pDbPage))!=SQLITE_OK ){ - sqlite3PagerUnref(pDbPage); - return rc; - } aPayload = sqlite3PagerGetData(pDbPage); nextPage = get4byte(aPayload); - if( eOp ){ - memcpy(&aPayload[offset+4], pBuf, a); - }else{ - memcpy(pBuf, &aPayload[offset+4], a); - } + rc = copyPayload(&aPayload[offset+4], pBuf, a, eOp, pDbPage); sqlite3PagerUnref(pDbPage); offset = 0; } @@ -7374,14 +7385,16 @@ void sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){ */ int sqlite3BtreeUpdateMeta(Btree *p, int idx, u32 iMeta){ BtShared *pBt = p->pBt; + unsigned char *pP1; int rc; assert( idx>=1 && idx<=15 ); sqlite3BtreeEnter(p); assert( p->inTrans==TRANS_WRITE ); assert( pBt->pPage1!=0 ); + pP1 = pBt->pPage1->aData; rc = sqlite3PagerWrite(pBt->pPage1->pDbPage); if( rc==SQLITE_OK ){ - put4byte(&pBt->pPage1->aData[36 + idx*4], iMeta); + put4byte(&pP1[36 + idx*4], iMeta); #ifndef SQLITE_OMIT_AUTOVACUUM if( idx==BTREE_INCR_VACUUM ){ assert( pBt->autoVacuum || iMeta==0 ); @@ -8210,7 +8223,6 @@ int sqlite3BtreeSetVersion(Btree *pBtree, int iVersion){ if( rc==SQLITE_OK ){ rc = sqlite3PagerWrite(pBt->pPage1->pDbPage); if( rc==SQLITE_OK ){ - aData = pBt->pPage1->aData; aData[18] = (u8)iVersion; aData[19] = (u8)iVersion; } |