Modify the interface to the pager sub-system in preparation for performing IO in blocks based on sector-size, not database page-size. (CVS 3705)

FossilOrigin-Name: 7dc7658887046f066b564a5994578074a99756ba
This commit is contained in:
danielk1977 2007-03-19 17:44:26 +00:00
parent a8553141c9
commit 3b8a05f681
9 changed files with 405 additions and 375 deletions

View File

@ -1,5 +1,5 @@
C Add\ssome\stest\scases\ssimulating\scrashes\swith\svarious\sstorage\smedium\ssector\ssizes.\s(CVS\s3704) C Modify\sthe\sinterface\sto\sthe\spager\ssub-system\sin\spreparation\sfor\sperforming\sIO\sin\sblocks\sbased\son\ssector-size,\snot\sdatabase\spage-size.\s(CVS\s3705)
D 2007-03-19T15:04:54 D 2007-03-19T17:44:27
F Makefile.in 1fe3d0b46e40fd684e1e61f8e8056cefed16de9f F Makefile.in 1fe3d0b46e40fd684e1e61f8e8056cefed16de9f
F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -58,7 +58,7 @@ F src/alter.c 2c79ec40f65e33deaf90ca493422c74586e481a3
F src/analyze.c 7d2b7ab9a9c2fd6e55700f69064dfdd3e36d7a8a F src/analyze.c 7d2b7ab9a9c2fd6e55700f69064dfdd3e36d7a8a
F src/attach.c fd286a9140a2df84b1482f052b67ff5fad9569a1 F src/attach.c fd286a9140a2df84b1482f052b67ff5fad9569a1
F src/auth.c 902f4722661c796b97f007d9606bd7529c02597f F src/auth.c 902f4722661c796b97f007d9606bd7529c02597f
F src/btree.c f5278b44929198098ed382101ce97b58ceacb5cd F src/btree.c 4d94251b59fa33c888efc43881729f7d297899a4
F src/btree.h 066444ee25bd6e6accb997bfd2cf5ace14dbcd00 F src/btree.h 066444ee25bd6e6accb997bfd2cf5ace14dbcd00
F src/build.c f2edc786b5bf165a7d0949ed3a5872455a610c0e F src/build.c f2edc786b5bf165a7d0949ed3a5872455a610c0e
F src/callback.c 31d22b4919c7645cbcbb1591ce2453e8c677c558 F src/callback.c 31d22b4919c7645cbcbb1591ce2453e8c677c558
@ -86,10 +86,10 @@ F src/os_unix.c 33ee7c1483fbd4d67cf5638c87622c277442b744
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
F src/os_win.c f3ca3e08167eb3382781b840e787809eccb626dc F src/os_win.c f3ca3e08167eb3382781b840e787809eccb626dc
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
F src/pager.c 3688e882a10a693cbdc9303426d3a52b8f48ccd5 F src/pager.c dec2b25851190ab2d5b7d44065fae625c566dda5
F src/pager.h 8881591ca23d1e5fd83c95fa8317245fbcf64227 F src/pager.h 9f6b5ef42c761deec8a9b1966b32e9a9dc89a631
F src/parse.y bcfe366c1fd61cfc40e5344eb69a31997a821af0 F src/parse.y bcfe366c1fd61cfc40e5344eb69a31997a821af0
F src/pragma.c b52dcf2fbb46f3266f9d00b88054c684df3af2e7 F src/pragma.c a3fe1dacdbf320ad99d4125a60a5bce8f1808bc8
F src/prepare.c 4e075fe28591b7d4ffbf818fb88a7e19bbe98065 F src/prepare.c 4e075fe28591b7d4ffbf818fb88a7e19bbe98065
F src/printf.c aade23a789d7cc88b397ec0d33a0a01a33a7a9c1 F src/printf.c aade23a789d7cc88b397ec0d33a0a01a33a7a9c1
F src/random.c 6119474a6f6917f708c1dee25b9a8e519a620e88 F src/random.c 6119474a6f6917f708c1dee25b9a8e519a620e88
@ -102,8 +102,8 @@ F src/sqliteInt.h 6e3ac7a1a8f51e24ce4784236aa957e9bd11217f
F src/table.c 6d0da66dde26ee75614ed8f584a1996467088d06 F src/table.c 6d0da66dde26ee75614ed8f584a1996467088d06
F src/tclsqlite.c cd2b3b86ab07c0e0779f6c6e71e72c6c7dc1e704 F src/tclsqlite.c cd2b3b86ab07c0e0779f6c6e71e72c6c7dc1e704
F src/test1.c b4ff8f82f84d2ccdf07a2db5acae7b47c12f60d7 F src/test1.c b4ff8f82f84d2ccdf07a2db5acae7b47c12f60d7
F src/test2.c 59085c04e22a22bed9f1078ab318adc34c1229f3 F src/test2.c dc48c84ce68b3bc2f2d01871d709f20dc77003b0
F src/test3.c ed494a126221c4b9f66f8f0445554ad749764709 F src/test3.c f78f1d83d8c50926fa080abbf8769b9d47ed623e
F src/test4.c 8b784cd82de158a2317cb4ac4bc86f91ad315e25 F src/test4.c 8b784cd82de158a2317cb4ac4bc86f91ad315e25
F src/test5.c 7162f8526affb771c4ed256826eee7bb9eca265f F src/test5.c 7162f8526affb771c4ed256826eee7bb9eca265f
F src/test6.c 5957d249d437e4db74045ce2f1f661648d94bf94 F src/test6.c 5957d249d437e4db74045ce2f1f661648d94bf94
@ -120,7 +120,7 @@ F src/tokenize.c bb1732ef2b6fc2143f93ff28a45d3dcb04c1d396
F src/trigger.c 8c55d31876013ed4e97ee7ce24478fbe00db49bb F src/trigger.c 8c55d31876013ed4e97ee7ce24478fbe00db49bb
F src/update.c 876b3142b8db9ce6ddf8374a2ced65e576acabc7 F src/update.c 876b3142b8db9ce6ddf8374a2ced65e576acabc7
F src/utf.c 67ecb1032bc0b42c105e88d65ef9d9f626eb0e1f F src/utf.c 67ecb1032bc0b42c105e88d65ef9d9f626eb0e1f
F src/util.c 5fd552a3e810bb284c7721dc9ae936636db511f4 F src/util.c f6d739fc25026cecb59ac98344a1f12fcbee074f
F src/vacuum.c 327c6ffa38935163db7c1e256ff5f788e901b318 F src/vacuum.c 327c6ffa38935163db7c1e256ff5f788e901b318
F src/vdbe.c 19e244e554e5df3f49d4e15233527753fadbcc4d F src/vdbe.c 19e244e554e5df3f49d4e15233527753fadbcc4d
F src/vdbe.h 0025259af1939fb264a545816c69e4b5b8d52691 F src/vdbe.h 0025259af1939fb264a545816c69e4b5b8d52691
@ -437,7 +437,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P 9f62ef1ec385d9f1a1913439dc4c2d710373f12a P c3c5f658cf9c69b6e81e63fbde5dd0a854be9fc7
R 784c351e0fe2c19f26c03e7b8875efc3 R 8bc9543d27c6957ab236f6b14f2fea11
U danielk1977 U danielk1977
Z bcc4c2f06f6fc376240bcf364d3a6431 Z 733a417800b51f433ae2631c0b87c550

View File

@ -1 +1 @@
c3c5f658cf9c69b6e81e63fbde5dd0a854be9fc7 7dc7658887046f066b564a5994578074a99756ba

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while ** file simultaneously, or one process from reading the database while
** another is writing. ** another is writing.
** **
** @(#) $Id: pager.c,v 1.291 2007/03/19 13:53:38 danielk1977 Exp $ ** @(#) $Id: pager.c,v 1.292 2007/03/19 17:44:27 danielk1977 Exp $
*/ */
#ifndef SQLITE_OMIT_DISKIO #ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h" #include "sqliteInt.h"
@ -90,15 +90,15 @@
** committed. ** committed.
** **
** The page cache comes up in PAGER_UNLOCK. The first time a ** The page cache comes up in PAGER_UNLOCK. The first time a
** sqlite3pager_get() occurs, the state transitions to PAGER_SHARED. ** sqlite3PagerGet() occurs, the state transitions to PAGER_SHARED.
** After all pages have been released using sqlite_page_unref(), ** After all pages have been released using sqlite_page_unref(),
** the state transitions back to PAGER_UNLOCK. The first time ** the state transitions back to PAGER_UNLOCK. The first time
** that sqlite3pager_write() is called, the state transitions to ** that sqlite3PagerWrite() is called, the state transitions to
** PAGER_RESERVED. (Note that sqlite_page_write() can only be ** PAGER_RESERVED. (Note that sqlite_page_write() can only be
** called on an outstanding page which means that the pager must ** called on an outstanding page which means that the pager must
** be in PAGER_SHARED before it transitions to PAGER_RESERVED.) ** be in PAGER_SHARED before it transitions to PAGER_RESERVED.)
** The transition to PAGER_EXCLUSIVE occurs when before any changes ** The transition to PAGER_EXCLUSIVE occurs when before any changes
** are made to the database file. After an sqlite3pager_rollback() ** are made to the database file. After an sqlite3PagerRollback()
** or sqlite_pager_commit(), the state goes back to PAGER_SHARED. ** or sqlite_pager_commit(), the state goes back to PAGER_SHARED.
*/ */
#define PAGER_UNLOCK 0 #define PAGER_UNLOCK 0
@ -135,8 +135,8 @@
** This header is only visible to this pager module. The client ** This header is only visible to this pager module. The client
** code that calls pager sees only the data that follows the header. ** code that calls pager sees only the data that follows the header.
** **
** Client code should call sqlite3pager_write() on a page prior to making ** Client code should call sqlite3PagerWrite() on a page prior to making
** any modifications to that page. The first time sqlite3pager_write() ** any modifications to that page. The first time sqlite3PagerWrite()
** is called, the original page contents are written into the rollback ** is called, the original page contents are written into the rollback
** journal and PgHdr.inJournal and PgHdr.needSync are set. Later, once ** journal and PgHdr.inJournal and PgHdr.needSync are set. Later, once
** the journal page has made it onto the disk surface, PgHdr.needSync ** the journal page has made it onto the disk surface, PgHdr.needSync
@ -144,7 +144,7 @@
** database file until the journal pages has been synced to disk and the ** database file until the journal pages has been synced to disk and the
** PgHdr.needSync has been cleared. ** PgHdr.needSync has been cleared.
** **
** The PgHdr.dirty flag is set when sqlite3pager_write() is called and ** The PgHdr.dirty flag is set when sqlite3PagerWrite() is called and
** is cleared again when the page content is written back to the original ** is cleared again when the page content is written back to the original
** database file. ** database file.
*/ */
@ -217,7 +217,7 @@ struct PgHistory {
** and is returned as the result of every major pager API call. The ** and is returned as the result of every major pager API call. The
** SQLITE_FULL return code is slightly different. It persists only until the ** SQLITE_FULL return code is slightly different. It persists only until the
** next successful rollback is performed on the pager cache. Also, ** next successful rollback is performed on the pager cache. Also,
** SQLITE_FULL does not affect the sqlite3pager_get() and sqlite3pager_lookup() ** SQLITE_FULL does not affect the sqlite3PagerGet() and sqlite3PagerLookup()
** APIs, they may still be used successfully. ** APIs, they may still be used successfully.
*/ */
struct Pager { struct Pager {
@ -275,8 +275,8 @@ struct Pager {
int nHit, nMiss, nOvfl; /* Cache hits, missing, and LRU overflows */ int nHit, nMiss, nOvfl; /* Cache hits, missing, and LRU overflows */
int nRead,nWrite; /* Database pages read/written */ int nRead,nWrite; /* Database pages read/written */
#endif #endif
void (*xDestructor)(void*,int); /* Call this routine when freeing pages */ void (*xDestructor)(DbPage*,int); /* Call this routine when freeing pages */
void (*xReiniter)(void*,int); /* Call this routine when reloading pages */ void (*xReiniter)(DbPage*,int); /* Call this routine when reloading pages */
void *(*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */ void *(*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */
void *pCodecArg; /* First argument to xCodec() */ void *pCodecArg; /* First argument to xCodec() */
int nHash; /* Size of the pager hash table */ int nHash; /* Size of the pager hash table */
@ -801,7 +801,7 @@ static int writeMasterJournal(Pager *pPager, const char *zMaster){
** statement journal. ** statement journal.
** **
** The Pager keeps a separate list of pages that are currently in ** The Pager keeps a separate list of pages that are currently in
** the statement journal. This helps the sqlite3pager_stmt_commit() ** the statement journal. This helps the sqlite3PagerStmtCommit()
** routine run MUCH faster for the common case where there are many ** routine run MUCH faster for the common case where there are many
** pages in memory but only a few are in the statement journal. ** pages in memory but only a few are in the statement journal.
*/ */
@ -890,7 +890,7 @@ static void pager_reset(Pager *pPager){
pPager->nPage = 0; pPager->nPage = 0;
pPager->aHash = 0; pPager->aHash = 0;
if( pPager->state>=PAGER_RESERVED ){ if( pPager->state>=PAGER_RESERVED ){
sqlite3pager_rollback(pPager); sqlite3PagerRollback(pPager);
} }
pager_unlock(pPager); pager_unlock(pPager);
pPager->nRef = 0; pPager->nRef = 0;
@ -914,7 +914,7 @@ static int pager_unwritelock(Pager *pPager){
if( pPager->state<PAGER_RESERVED ){ if( pPager->state<PAGER_RESERVED ){
return SQLITE_OK; return SQLITE_OK;
} }
sqlite3pager_stmt_commit(pPager); sqlite3PagerStmtCommit(pPager);
if( pPager->stmtOpen ){ if( pPager->stmtOpen ){
sqlite3OsClose(&pPager->stfd); sqlite3OsClose(&pPager->stfd);
pPager->stmtOpen = 0; pPager->stmtOpen = 0;
@ -1069,14 +1069,14 @@ static int pager_playback_one_page(Pager *pPager, OsFile *jfd, int useCksum){
** for page 1 which is held in use in order to keep the lock on the ** for page 1 which is held in use in order to keep the lock on the
** database active. However such a page may be rolled back as a result ** database active. However such a page may be rolled back as a result
** of an internal error resulting in an automatic call to ** of an internal error resulting in an automatic call to
** sqlite3pager_rollback(). ** sqlite3PagerRollback().
*/ */
void *pData; void *pData;
/* assert( pPg->nRef==0 || pPg->pgno==1 ); */ /* assert( pPg->nRef==0 || pPg->pgno==1 ); */
pData = PGHDR_TO_DATA(pPg); pData = PGHDR_TO_DATA(pPg);
memcpy(pData, aData, pPager->pageSize); memcpy(pData, aData, pPager->pageSize);
if( pPager->xDestructor ){ /*** FIX ME: Should this be xReinit? ***/ if( pPager->xDestructor ){ /*** FIX ME: Should this be xReinit? ***/
pPager->xDestructor(pData, pPager->pageSize); pPager->xDestructor(pPg, pPager->pageSize);
} }
#ifdef SQLITE_CHECK_PAGES #ifdef SQLITE_CHECK_PAGES
pPg->pageHash = pager_pagehash(pPg); pPg->pageHash = pager_pagehash(pPg);
@ -1201,7 +1201,7 @@ static int pager_reload_cache(Pager *pPager){
if( pPg->nRef==0 || memcmp(zBuf, PGHDR_TO_DATA(pPg), pPager->pageSize) ){ if( pPg->nRef==0 || memcmp(zBuf, PGHDR_TO_DATA(pPg), pPager->pageSize) ){
memcpy(PGHDR_TO_DATA(pPg), zBuf, pPager->pageSize); memcpy(PGHDR_TO_DATA(pPg), zBuf, pPager->pageSize);
if( pPager->xReiniter ){ if( pPager->xReiniter ){
pPager->xReiniter(PGHDR_TO_DATA(pPg), pPager->pageSize); pPager->xReiniter(pPg, pPager->pageSize);
}else{ }else{
memset(PGHDR_TO_EXTRA(pPg, pPager), 0, pPager->nExtra); memset(PGHDR_TO_EXTRA(pPg, pPager), 0, pPager->nExtra);
} }
@ -1513,7 +1513,7 @@ end_stmt_playback:
/* /*
** Change the maximum number of in-memory pages that are allowed. ** Change the maximum number of in-memory pages that are allowed.
*/ */
void sqlite3pager_set_cachesize(Pager *pPager, int mxPage){ void sqlite3PagerSetCachesize(Pager *pPager, int mxPage){
if( mxPage>10 ){ if( mxPage>10 ){
pPager->mxPage = mxPage; pPager->mxPage = mxPage;
}else{ }else{
@ -1548,7 +1548,7 @@ void sqlite3pager_set_cachesize(Pager *pPager, int mxPage){
** and FULL=3. ** and FULL=3.
*/ */
#ifndef SQLITE_OMIT_PAGER_PRAGMAS #ifndef SQLITE_OMIT_PAGER_PRAGMAS
void sqlite3pager_set_safety_level(Pager *pPager, int level, int full_fsync){ void sqlite3PagerSetSafetyLevel(Pager *pPager, int level, int full_fsync){
pPager->noSync = level==1 || pPager->tempFile; pPager->noSync = level==1 || pPager->tempFile;
pPager->fullSync = level==3 && !pPager->tempFile; pPager->fullSync = level==3 && !pPager->tempFile;
pPager->full_fsync = full_fsync; pPager->full_fsync = full_fsync;
@ -1574,7 +1574,7 @@ int sqlite3_opentemp_count = 0;
** The OS will automatically delete the temporary file when it is ** The OS will automatically delete the temporary file when it is
** closed. ** closed.
*/ */
static int sqlite3pager_opentemp(OsFile **pFd){ static int sqlite3PagerOpentemp(OsFile **pFd){
int cnt = 8; int cnt = 8;
int rc; int rc;
char zFile[SQLITE_TEMPNAME_SIZE]; char zFile[SQLITE_TEMPNAME_SIZE];
@ -1593,8 +1593,8 @@ static int sqlite3pager_opentemp(OsFile **pFd){
/* /*
** Create a new page cache and put a pointer to the page cache in *ppPager. ** Create a new page cache and put a pointer to the page cache in *ppPager.
** The file to be cached need not exist. The file is not locked until ** The file to be cached need not exist. The file is not locked until
** the first call to sqlite3pager_get() and is only held open until the ** the first call to sqlite3PagerGet() and is only held open until the
** last page is released using sqlite3pager_unref(). ** last page is released using sqlite3PagerUnref().
** **
** If zFilename is NULL then a randomly-named temporary file is created ** If zFilename is NULL then a randomly-named temporary file is created
** and used as the file to be cached. The file will be deleted ** and used as the file to be cached. The file will be deleted
@ -1604,7 +1604,7 @@ static int sqlite3pager_opentemp(OsFile **pFd){
** It is never written to disk. This can be used to implement an ** It is never written to disk. This can be used to implement an
** in-memory database. ** in-memory database.
*/ */
int sqlite3pager_open( int sqlite3PagerOpen(
Pager **ppPager, /* Return the Pager structure here */ Pager **ppPager, /* Return the Pager structure here */
const char *zFilename, /* Name of the database file to open */ const char *zFilename, /* Name of the database file to open */
int nExtra, /* Extra bytes append to each in-memory page */ int nExtra, /* Extra bytes append to each in-memory page */
@ -1661,7 +1661,7 @@ int sqlite3pager_open(
} }
} }
}else{ }else{
rc = sqlite3pager_opentemp(&fd); rc = sqlite3PagerOpentemp(&fd);
sqlite3OsTempFileName(zTemp); sqlite3OsTempFileName(zTemp);
zFilename = zTemp; zFilename = zTemp;
zFullPathname = sqlite3OsFullPathname(zFilename); zFullPathname = sqlite3OsFullPathname(zFilename);
@ -1752,7 +1752,7 @@ int sqlite3pager_open(
/* /*
** Set the busy handler function. ** Set the busy handler function.
*/ */
void sqlite3pager_set_busyhandler(Pager *pPager, BusyHandler *pBusyHandler){ void sqlite3PagerSetBusyhandler(Pager *pPager, BusyHandler *pBusyHandler){
pPager->pBusyHandler = pBusyHandler; pPager->pBusyHandler = pBusyHandler;
} }
@ -1761,10 +1761,10 @@ void sqlite3pager_set_busyhandler(Pager *pPager, BusyHandler *pBusyHandler){
** when the reference count on each page reaches zero. The destructor can ** when the reference count on each page reaches zero. The destructor can
** be used to clean up information in the extra segment appended to each page. ** be used to clean up information in the extra segment appended to each page.
** **
** The destructor is not called as a result sqlite3pager_close(). ** The destructor is not called as a result sqlite3PagerClose().
** Destructors are only called by sqlite3pager_unref(). ** Destructors are only called by sqlite3PagerUnref().
*/ */
void sqlite3pager_set_destructor(Pager *pPager, void (*xDesc)(void*,int)){ void sqlite3PagerSetDestructor(Pager *pPager, void (*xDesc)(DbPage*,int)){
pPager->xDestructor = xDesc; pPager->xDestructor = xDesc;
} }
@ -1775,7 +1775,7 @@ void sqlite3pager_set_destructor(Pager *pPager, void (*xDesc)(void*,int)){
** an opportunity to restore the EXTRA section to agree with the restored ** an opportunity to restore the EXTRA section to agree with the restored
** page data. ** page data.
*/ */
void sqlite3pager_set_reiniter(Pager *pPager, void (*xReinit)(void*,int)){ void sqlite3PagerSetReiniter(Pager *pPager, void (*xReinit)(DbPage*,int)){
pPager->xReiniter = xReinit; pPager->xReiniter = xReinit;
} }
@ -1784,7 +1784,7 @@ void sqlite3pager_set_reiniter(Pager *pPager, void (*xReinit)(void*,int)){
** size is inappropriate, then an alternative page size is selected ** size is inappropriate, then an alternative page size is selected
** and returned. ** and returned.
*/ */
int sqlite3pager_set_pagesize(Pager *pPager, int pageSize){ int sqlite3PagerSetPagesize(Pager *pPager, int pageSize){
assert( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE ); assert( pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE );
if( !pPager->memDb ){ if( !pPager->memDb ){
pPager->pageSize = pageSize; pPager->pageSize = pageSize;
@ -1831,7 +1831,7 @@ void enable_simulated_io_errors(void){
** response is to zero the memory at pDest and continue. A real IO error ** response is to zero the memory at pDest and continue. A real IO error
** will presumably recur and be picked up later (Todo: Think about this). ** will presumably recur and be picked up later (Todo: Think about this).
*/ */
int sqlite3pager_read_fileheader(Pager *pPager, int N, unsigned char *pDest){ int sqlite3PagerReadFileheader(Pager *pPager, int N, unsigned char *pDest){
int rc = SQLITE_OK; int rc = SQLITE_OK;
memset(pDest, 0, N); memset(pDest, 0, N);
if( MEMDB==0 ){ if( MEMDB==0 ){
@ -1856,7 +1856,7 @@ int sqlite3pager_read_fileheader(Pager *pPager, int N, unsigned char *pDest){
** PENDING_BYTE is byte 4096 (the first byte of page 5) and the size of the ** PENDING_BYTE is byte 4096 (the first byte of page 5) and the size of the
** file is 4096 bytes, 5 is returned instead of 4. ** file is 4096 bytes, 5 is returned instead of 4.
*/ */
int sqlite3pager_pagecount(Pager *pPager){ int sqlite3PagerPagecount(Pager *pPager){
i64 n; i64 n;
int rc; int rc;
assert( pPager!=0 ); assert( pPager!=0 );
@ -1908,7 +1908,7 @@ static int syncJournal(Pager*);
/* /*
** Unlink pPg from it's hash chain. Also set the page number to 0 to indicate ** Unlink pPg from it's hash chain. Also set the page number to 0 to indicate
** that the page is not part of any hash chain. This is required because the ** that the page is not part of any hash chain. This is required because the
** sqlite3pager_movepage() routine can leave a page in the ** sqlite3PagerMovepage() routine can leave a page in the
** pNextFree/pPrevFree list that is not a part of any hash-chain. ** pNextFree/pPrevFree list that is not a part of any hash-chain.
*/ */
static void unlinkHashChain(Pager *pPager, PgHdr *pPg){ static void unlinkHashChain(Pager *pPager, PgHdr *pPg){
@ -2033,10 +2033,10 @@ static int pager_wait_on_lock(Pager *pPager, int locktype){
/* /*
** Truncate the file to the number of pages specified. ** Truncate the file to the number of pages specified.
*/ */
int sqlite3pager_truncate(Pager *pPager, Pgno nPage){ int sqlite3PagerTruncate(Pager *pPager, Pgno nPage){
int rc; int rc;
assert( pPager->state>=PAGER_SHARED || MEMDB ); assert( pPager->state>=PAGER_SHARED || MEMDB );
sqlite3pager_pagecount(pPager); sqlite3PagerPagecount(pPager);
if( pPager->errCode ){ if( pPager->errCode ){
rc = pPager->errCode; rc = pPager->errCode;
return rc; return rc;
@ -2081,7 +2081,7 @@ int sqlite3pager_truncate(Pager *pPager, Pgno nPage){
** a hot journal may be left in the filesystem but no error is returned ** a hot journal may be left in the filesystem but no error is returned
** to the caller. ** to the caller.
*/ */
int sqlite3pager_close(Pager *pPager){ int sqlite3PagerClose(Pager *pPager){
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
/* A malloc() cannot fail in sqlite3ThreadData() as one or more calls to /* A malloc() cannot fail in sqlite3ThreadData() as one or more calls to
** malloc() must have already been made by this thread before it gets ** malloc() must have already been made by this thread before it gets
@ -2135,8 +2135,7 @@ int sqlite3pager_close(Pager *pPager){
/* /*
** Return the page number for the given page data. ** Return the page number for the given page data.
*/ */
Pgno sqlite3pager_pagenumber(void *pData){ Pgno sqlite3PagerPagenumber(DbPage *p){
PgHdr *p = DATA_TO_PGHDR(pData);
return p->pgno; return p->pgno;
} }
@ -2189,8 +2188,7 @@ static void _page_ref(PgHdr *pPg){
** Increment the reference count for a page. The input pointer is ** Increment the reference count for a page. The input pointer is
** a reference to the page data. ** a reference to the page data.
*/ */
int sqlite3pager_ref(void *pData){ int sqlite3PagerRef(DbPage *pPg){
PgHdr *pPg = DATA_TO_PGHDR(pData);
page_ref(pPg); page_ref(pPg);
return SQLITE_OK; return SQLITE_OK;
} }
@ -2394,7 +2392,7 @@ static int pager_write_pagelist(PgHdr *pList){
rc = sqlite3OsSeek(pPager->fd, (pList->pgno-1)*(i64)pPager->pageSize); rc = sqlite3OsSeek(pPager->fd, (pList->pgno-1)*(i64)pPager->pageSize);
if( rc ) return rc; if( rc ) return rc;
/* If there are dirty pages in the page cache with page numbers greater /* If there are dirty pages in the page cache with page numbers greater
** than Pager.dbSize, this means sqlite3pager_truncate() was called to ** than Pager.dbSize, this means sqlite3PagerTruncate() was called to
** make the file smaller (presumably by auto-vacuum code). Do not write ** make the file smaller (presumably by auto-vacuum code). Do not write
** any such pages to the file. ** any such pages to the file.
*/ */
@ -2441,7 +2439,7 @@ static int hasHotJournal(Pager *pPager){
if( !pPager->useJournal ) return 0; if( !pPager->useJournal ) return 0;
if( !sqlite3OsFileExists(pPager->zJournal) ) return 0; if( !sqlite3OsFileExists(pPager->zJournal) ) return 0;
if( sqlite3OsCheckReservedLock(pPager->fd) ) return 0; if( sqlite3OsCheckReservedLock(pPager->fd) ) return 0;
if( sqlite3pager_pagecount(pPager)==0 ){ if( sqlite3PagerPagecount(pPager)==0 ){
sqlite3OsDelete(pPager->zJournal); sqlite3OsDelete(pPager->zJournal);
return 0; return 0;
}else{ }else{
@ -2545,7 +2543,7 @@ static int pager_recycle(Pager *pPager, int syncOk, PgHdr **ppPg){
** of bytes of memory released. ** of bytes of memory released.
*/ */
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
int sqlite3pager_release_memory(int nReq){ int sqlite3PagerReleaseMemory(int nReq){
const ThreadData *pTsdro = sqlite3ThreadDataReadOnly(); const ThreadData *pTsdro = sqlite3ThreadDataReadOnly();
Pager *p; Pager *p;
int nReleased = 0; int nReleased = 0;
@ -2632,7 +2630,7 @@ int sqlite3pager_release_memory(int nReq){
** The acquisition might fail for several reasons. In all cases, ** The acquisition might fail for several reasons. In all cases,
** an appropriate error code is returned and *ppPage is set to NULL. ** an appropriate error code is returned and *ppPage is set to NULL.
** **
** See also sqlite3pager_lookup(). Both this routine and _lookup() attempt ** See also sqlite3PagerLookup(). Both this routine and _lookup() attempt
** to find a page in the in-memory cache first. If the page is not already ** to find a page in the in-memory cache first. If the page is not already
** in memory, this routine goes to disk to read it in whereas _lookup() ** in memory, this routine goes to disk to read it in whereas _lookup()
** just returns 0. This routine acquires a read-lock the first time it ** just returns 0. This routine acquires a read-lock the first time it
@ -2645,7 +2643,7 @@ int sqlite3pager_release_memory(int nReq){
** rewritten without first being read so there is no point it doing ** rewritten without first being read so there is no point it doing
** the disk I/O. ** the disk I/O.
*/ */
int sqlite3pager_acquire(Pager *pPager, Pgno pgno, void **ppPage, int clrFlag){ int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag){
PgHdr *pPg; PgHdr *pPg;
int rc; int rc;
@ -2797,7 +2795,7 @@ int sqlite3pager_acquire(Pager *pPager, Pgno pgno, void **ppPage, int clrFlag){
memset(PGHDR_TO_EXTRA(pPg, pPager), 0, pPager->nExtra); memset(PGHDR_TO_EXTRA(pPg, pPager), 0, pPager->nExtra);
} }
if( pPager->errCode ){ if( pPager->errCode ){
sqlite3pager_unref(PGHDR_TO_DATA(pPg)); sqlite3PagerUnref(pPg);
rc = pPager->errCode; rc = pPager->errCode;
return rc; return rc;
} }
@ -2805,7 +2803,7 @@ int sqlite3pager_acquire(Pager *pPager, Pgno pgno, void **ppPage, int clrFlag){
/* Populate the page with data, either by reading from the database /* Populate the page with data, either by reading from the database
** file, or by setting the entire page to zero. ** file, or by setting the entire page to zero.
*/ */
if( sqlite3pager_pagecount(pPager)<(int)pgno || MEMDB if( sqlite3PagerPagecount(pPager)<(int)pgno || MEMDB
|| (clrFlag && !pPager->alwaysRollback) || (clrFlag && !pPager->alwaysRollback)
){ ){
memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize); memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize);
@ -2821,7 +2819,7 @@ int sqlite3pager_acquire(Pager *pPager, Pgno pgno, void **ppPage, int clrFlag){
CODEC1(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3); CODEC1(pPager, PGHDR_TO_DATA(pPg), pPg->pgno, 3);
if( rc!=SQLITE_OK && rc!=SQLITE_IOERR_SHORT_READ ){ if( rc!=SQLITE_OK && rc!=SQLITE_IOERR_SHORT_READ ){
pPg->pgno = 0; pPg->pgno = 0;
sqlite3pager_unref(PGHDR_TO_DATA(pPg)); sqlite3PagerUnref(pPg);
return rc; return rc;
}else{ }else{
TEST_INCR(pPager->nRead); TEST_INCR(pPager->nRead);
@ -2846,7 +2844,7 @@ int sqlite3pager_acquire(Pager *pPager, Pgno pgno, void **ppPage, int clrFlag){
TEST_INCR(pPager->nHit); TEST_INCR(pPager->nHit);
page_ref(pPg); page_ref(pPg);
} }
*ppPage = PGHDR_TO_DATA(pPg); *ppPage = pPg;
return SQLITE_OK; return SQLITE_OK;
} }
@ -2855,13 +2853,13 @@ int sqlite3pager_acquire(Pager *pPager, Pgno pgno, void **ppPage, int clrFlag){
** not read the page from disk. Return a pointer to the page, ** not read the page from disk. Return a pointer to the page,
** or 0 if the page is not in cache. ** or 0 if the page is not in cache.
** **
** See also sqlite3pager_get(). The difference between this routine ** See also sqlite3PagerGet(). The difference between this routine
** and sqlite3pager_get() is that _get() will go to the disk and read ** and sqlite3PagerGet() is that _get() will go to the disk and read
** in the page if the page is not already in cache. This routine ** in the page if the page is not already in cache. This routine
** returns NULL if the page is not in cache or if a disk I/O error ** returns NULL if the page is not in cache or if a disk I/O error
** has ever happened. ** has ever happened.
*/ */
void *sqlite3pager_lookup(Pager *pPager, Pgno pgno){ DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno){
PgHdr *pPg; PgHdr *pPg;
assert( pPager!=0 ); assert( pPager!=0 );
@ -2872,7 +2870,7 @@ void *sqlite3pager_lookup(Pager *pPager, Pgno pgno){
pPg = pager_lookup(pPager, pgno); pPg = pager_lookup(pPager, pgno);
if( pPg==0 ) return 0; if( pPg==0 ) return 0;
page_ref(pPg); page_ref(pPg);
return PGHDR_TO_DATA(pPg); return pPg;
} }
/* /*
@ -2883,12 +2881,10 @@ void *sqlite3pager_lookup(Pager *pPager, Pgno pgno){
** are released, a rollback occurs and the lock on the database is ** are released, a rollback occurs and the lock on the database is
** removed. ** removed.
*/ */
int sqlite3pager_unref(void *pData){ int sqlite3PagerUnref(DbPage *pPg){
PgHdr *pPg;
/* Decrement the reference count for this page /* Decrement the reference count for this page
*/ */
pPg = DATA_TO_PGHDR(pData);
assert( pPg->nRef>0 ); assert( pPg->nRef>0 );
pPg->nRef--; pPg->nRef--;
REFINFO(pPg); REFINFO(pPg);
@ -2913,7 +2909,7 @@ int sqlite3pager_unref(void *pData){
pPager->pFirstSynced = pPg; pPager->pFirstSynced = pPg;
} }
if( pPager->xDestructor ){ if( pPager->xDestructor ){
pPager->xDestructor(pData, pPager->pageSize); pPager->xDestructor(pPg, pPager->pageSize);
} }
/* When all pages reach the freelist, drop the read lock from /* When all pages reach the freelist, drop the read lock from
@ -2942,7 +2938,7 @@ static int pager_open_journal(Pager *pPager){
assert( pPager->journalOpen==0 ); assert( pPager->journalOpen==0 );
assert( pPager->useJournal ); assert( pPager->useJournal );
assert( pPager->aInJournal==0 ); assert( pPager->aInJournal==0 );
sqlite3pager_pagecount(pPager); sqlite3PagerPagecount(pPager);
pPager->aInJournal = sqliteMalloc( pPager->dbSize/8 + 1 ); pPager->aInJournal = sqliteMalloc( pPager->dbSize/8 + 1 );
if( pPager->aInJournal==0 ){ if( pPager->aInJournal==0 ){
rc = SQLITE_NOMEM; rc = SQLITE_NOMEM;
@ -2973,7 +2969,7 @@ static int pager_open_journal(Pager *pPager){
rc = writeJournalHdr(pPager); rc = writeJournalHdr(pPager);
if( pPager->stmtAutoopen && rc==SQLITE_OK ){ if( pPager->stmtAutoopen && rc==SQLITE_OK ){
rc = sqlite3pager_stmt_begin(pPager); rc = sqlite3PagerStmtBegin(pPager);
} }
if( rc!=SQLITE_OK && rc!=SQLITE_NOMEM ){ if( rc!=SQLITE_OK && rc!=SQLITE_NOMEM ){
rc = pager_unwritelock(pPager); rc = pager_unwritelock(pPager);
@ -3003,10 +2999,10 @@ failed_to_open_journal:
** Acquire a write-lock on the database. The lock is removed when ** Acquire a write-lock on the database. The lock is removed when
** the any of the following happen: ** the any of the following happen:
** **
** * sqlite3pager_commit() is called. ** * sqlite3PagerCommit() is called.
** * sqlite3pager_rollback() is called. ** * sqlite3PagerRollback() is called.
** * sqlite3pager_close() is called. ** * sqlite3PagerClose() is called.
** * sqlite3pager_unref() is called to on every outstanding page. ** * sqlite3PagerUnref() is called to on every outstanding page.
** **
** The first parameter to this routine is a pointer to any open page of the ** The first parameter to this routine is a pointer to any open page of the
** database file. Nothing changes about the page - it is used merely to ** database file. Nothing changes about the page - it is used merely to
@ -3026,8 +3022,7 @@ failed_to_open_journal:
** immediately instead of waiting until we try to flush the cache. The ** immediately instead of waiting until we try to flush the cache. The
** exFlag is ignored if a transaction is already active. ** exFlag is ignored if a transaction is already active.
*/ */
int sqlite3pager_begin(void *pData, int exFlag){ int sqlite3PagerBegin(DbPage *pPg, int exFlag){
PgHdr *pPg = DATA_TO_PGHDR(pData);
Pager *pPager = pPg->pPager; Pager *pPager = pPg->pPager;
int rc = SQLITE_OK; int rc = SQLITE_OK;
assert( pPg->nRef>0 ); assert( pPg->nRef>0 );
@ -3108,11 +3103,11 @@ static void makeClean(PgHdr *pPg){
** If the journal file could not be written because the disk is full, ** If the journal file could not be written because the disk is full,
** then this routine returns SQLITE_FULL and does an immediate rollback. ** then this routine returns SQLITE_FULL and does an immediate rollback.
** All subsequent write attempts also return SQLITE_FULL until there ** All subsequent write attempts also return SQLITE_FULL until there
** is a call to sqlite3pager_commit() or sqlite3pager_rollback() to ** is a call to sqlite3PagerCommit() or sqlite3PagerRollback() to
** reset. ** reset.
*/ */
static int pager_write(void *pData){ static int pager_write(PgHdr *pPg){
PgHdr *pPg = DATA_TO_PGHDR(pData); void *pData = PGHDR_TO_DATA(pPg);
Pager *pPager = pPg->pPager; Pager *pPager = pPg->pPager;
int rc = SQLITE_OK; int rc = SQLITE_OK;
@ -3145,7 +3140,7 @@ static int pager_write(void *pData){
** create it if it does not. ** create it if it does not.
*/ */
assert( pPager->state!=PAGER_UNLOCK ); assert( pPager->state!=PAGER_UNLOCK );
rc = sqlite3pager_begin(pData, 0); rc = sqlite3PagerBegin(pPg, 0);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
return rc; return rc;
} }
@ -3275,10 +3270,10 @@ static int pager_write(void *pData){
** fit on a single disk sector. In this case all co-resident pages ** fit on a single disk sector. In this case all co-resident pages
** must have been written to the journal file before returning. ** must have been written to the journal file before returning.
*/ */
int sqlite3pager_write(void *pData){ int sqlite3PagerWrite(DbPage *pDbPage){
int rc = SQLITE_OK; int rc = SQLITE_OK;
PgHdr *pPg = DATA_TO_PGHDR(pData); PgHdr *pPg = pDbPage;
Pager *pPager = pPg->pPager; Pager *pPager = pPg->pPager;
Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize); Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize);
@ -3300,7 +3295,7 @@ int sqlite3pager_write(void *pData){
*/ */
pg1 = ((pPg->pgno-1) & ~(nPagePerSector-1)) + 1; pg1 = ((pPg->pgno-1) & ~(nPagePerSector-1)) + 1;
nPageCount = sqlite3pager_pagecount(pPager); nPageCount = sqlite3PagerPagecount(pPager);
if( pPg->pgno>nPageCount ){ if( pPg->pgno>nPageCount ){
nPage = (pPg->pgno - pg1)+1; nPage = (pPg->pgno - pg1)+1;
}else if( (pg1+nPagePerSector-1)>nPageCount ){ }else if( (pg1+nPagePerSector-1)>nPageCount ){
@ -3318,11 +3313,11 @@ int sqlite3pager_write(void *pData){
pg>pPager->origDbSize || !(pPager->aInJournal[pg/8]&(1<<(pg&7))) pg>pPager->origDbSize || !(pPager->aInJournal[pg/8]&(1<<(pg&7)))
) { ) {
if( pg!=PAGER_MJ_PGNO(pPager) ){ if( pg!=PAGER_MJ_PGNO(pPager) ){
void *pPage; PgHdr *pPage;
rc = sqlite3pager_get(pPager, pg, &pPage); rc = sqlite3PagerGet(pPager, pg, &pPage);
if( rc==SQLITE_OK ){ if( rc==SQLITE_OK ){
rc = pager_write(pPage); rc = pager_write(pPage);
sqlite3pager_unref(pPage); sqlite3PagerUnref(pPage);
} }
} }
} }
@ -3331,19 +3326,18 @@ int sqlite3pager_write(void *pData){
assert( pPager->doNotSync==1 ); assert( pPager->doNotSync==1 );
pPager->doNotSync = 0; pPager->doNotSync = 0;
}else{ }else{
rc = pager_write(pData); rc = pager_write(pDbPage);
} }
return rc; return rc;
} }
/* /*
** Return TRUE if the page given in the argument was previously passed ** Return TRUE if the page given in the argument was previously passed
** to sqlite3pager_write(). In other words, return TRUE if it is ok ** to sqlite3PagerWrite(). In other words, return TRUE if it is ok
** to change the content of the page. ** to change the content of the page.
*/ */
#ifndef NDEBUG #ifndef NDEBUG
int sqlite3pager_iswriteable(void *pData){ int sqlite3PagerIswriteable(DbPage *pPg){
PgHdr *pPg = DATA_TO_PGHDR(pData);
return pPg->dirty; return pPg->dirty;
} }
#endif #endif
@ -3353,17 +3347,17 @@ int sqlite3pager_iswriteable(void *pData){
** Replace the content of a single page with the information in the third ** Replace the content of a single page with the information in the third
** argument. ** argument.
*/ */
int sqlite3pager_overwrite(Pager *pPager, Pgno pgno, void *pData){ int sqlite3PagerOverwrite(Pager *pPager, Pgno pgno, void *pData){
void *pPage; PgHdr *pPg;
int rc; int rc;
rc = sqlite3pager_get(pPager, pgno, &pPage); rc = sqlite3PagerGet(pPager, pgno, &pPg);
if( rc==SQLITE_OK ){ if( rc==SQLITE_OK ){
rc = sqlite3pager_write(pPage); rc = sqlite3PagerWrite(pPg);
if( rc==SQLITE_OK ){ if( rc==SQLITE_OK ){
memcpy(pPage, pData, pPager->pageSize); memcpy(sqlite3PagerGetData(pPg), pData, pPager->pageSize);
} }
sqlite3pager_unref(pPage); sqlite3PagerUnref(pPg);
} }
return rc; return rc;
} }
@ -3379,11 +3373,11 @@ int sqlite3pager_overwrite(Pager *pPager, Pgno pgno, void *pData){
** that it does not get written to disk. ** that it does not get written to disk.
** **
** Tests show that this optimization, together with the ** Tests show that this optimization, together with the
** sqlite3pager_dont_rollback() below, more than double the speed ** sqlite3PagerDontRollback() below, more than double the speed
** of large INSERT operations and quadruple the speed of large DELETEs. ** of large INSERT operations and quadruple the speed of large DELETEs.
** **
** When this routine is called, set the alwaysRollback flag to true. ** When this routine is called, set the alwaysRollback flag to true.
** Subsequent calls to sqlite3pager_dont_rollback() for the same page ** Subsequent calls to sqlite3PagerDontRollback() for the same page
** will thereafter be ignored. This is necessary to avoid a problem ** will thereafter be ignored. This is necessary to avoid a problem
** where a page with data is added to the freelist during one part of ** where a page with data is added to the freelist during one part of
** a transaction then removed from the freelist during a later part ** a transaction then removed from the freelist during a later part
@ -3393,7 +3387,7 @@ int sqlite3pager_overwrite(Pager *pPager, Pgno pgno, void *pData){
** critical data, we still need to be sure it gets rolled back in spite ** critical data, we still need to be sure it gets rolled back in spite
** of the dont_rollback() call. ** of the dont_rollback() call.
*/ */
void sqlite3pager_dont_write(Pager *pPager, Pgno pgno){ void sqlite3PagerDontWrite(Pager *pPager, Pgno pgno){
PgHdr *pPg; PgHdr *pPg;
if( MEMDB ) return; if( MEMDB ) return;
@ -3429,8 +3423,7 @@ void sqlite3pager_dont_write(Pager *pPager, Pgno pgno){
** means that the pager does not have to record the given page in the ** means that the pager does not have to record the given page in the
** rollback journal. ** rollback journal.
*/ */
void sqlite3pager_dont_rollback(void *pData){ void sqlite3PagerDontRollback(DbPage *pPg){
PgHdr *pPg = DATA_TO_PGHDR(pData);
Pager *pPager = pPg->pPager; Pager *pPager = pPg->pPager;
assert( pPager->state>=PAGER_RESERVED ); assert( pPager->state>=PAGER_RESERVED );
@ -3463,7 +3456,7 @@ void sqlite3pager_dont_rollback(void *pData){
** and an error code is returned. If the commit worked, SQLITE_OK ** and an error code is returned. If the commit worked, SQLITE_OK
** is returned. ** is returned.
*/ */
int sqlite3pager_commit(Pager *pPager){ int sqlite3PagerCommit(Pager *pPager){
int rc; int rc;
PgHdr *pPg; PgHdr *pPg;
@ -3506,7 +3499,7 @@ int sqlite3pager_commit(Pager *pPager){
return rc; return rc;
} }
assert( pPager->journalOpen ); assert( pPager->journalOpen );
rc = sqlite3pager_sync(pPager, 0, 0); rc = sqlite3PagerSync(pPager, 0, 0);
if( rc==SQLITE_OK ){ if( rc==SQLITE_OK ){
rc = pager_unwritelock(pPager); rc = pager_unwritelock(pPager);
} }
@ -3525,7 +3518,7 @@ int sqlite3pager_commit(Pager *pPager){
** codes are returned for all these occasions. Otherwise, ** codes are returned for all these occasions. Otherwise,
** SQLITE_OK is returned. ** SQLITE_OK is returned.
*/ */
int sqlite3pager_rollback(Pager *pPager){ int sqlite3PagerRollback(Pager *pPager){
int rc; int rc;
TRACE2("ROLLBACK %d\n", PAGERID(pPager)); TRACE2("ROLLBACK %d\n", PAGERID(pPager));
if( MEMDB ){ if( MEMDB ){
@ -3552,7 +3545,7 @@ int sqlite3pager_rollback(Pager *pPager){
p->inStmt = 0; p->inStmt = 0;
p->pPrevStmt = p->pNextStmt = 0; p->pPrevStmt = p->pNextStmt = 0;
if( pPager->xReiniter ){ if( pPager->xReiniter ){
pPager->xReiniter(PGHDR_TO_DATA(p), pPager->pageSize); pPager->xReiniter(p, pPager->pageSize);
} }
} }
pPager->pDirty = 0; pPager->pDirty = 0;
@ -3598,14 +3591,14 @@ int sqlite3pager_rollback(Pager *pPager){
** Return TRUE if the database file is opened read-only. Return FALSE ** Return TRUE if the database file is opened read-only. Return FALSE
** if the database is (in theory) writable. ** if the database is (in theory) writable.
*/ */
int sqlite3pager_isreadonly(Pager *pPager){ int sqlite3PagerIsreadonly(Pager *pPager){
return pPager->readOnly; return pPager->readOnly;
} }
/* /*
** Return the number of references to the pager. ** Return the number of references to the pager.
*/ */
int sqlite3pager_refcount(Pager *pPager){ int sqlite3PagerRefcount(Pager *pPager){
return pPager->nRef; return pPager->nRef;
} }
@ -3613,7 +3606,7 @@ int sqlite3pager_refcount(Pager *pPager){
/* /*
** This routine is used for testing and analysis only. ** This routine is used for testing and analysis only.
*/ */
int *sqlite3pager_stats(Pager *pPager){ int *sqlite3PagerStats(Pager *pPager){
static int a[11]; static int a[11];
a[0] = pPager->nRef; a[0] = pPager->nRef;
a[1] = pPager->nPage; a[1] = pPager->nPage;
@ -3637,7 +3630,7 @@ int *sqlite3pager_stats(Pager *pPager){
** open. A new statement journal is created that can be used to rollback ** open. A new statement journal is created that can be used to rollback
** changes of a single SQL command within a larger transaction. ** changes of a single SQL command within a larger transaction.
*/ */
int sqlite3pager_stmt_begin(Pager *pPager){ int sqlite3PagerStmtBegin(Pager *pPager){
int rc; int rc;
assert( !pPager->stmtInUse ); assert( !pPager->stmtInUse );
assert( pPager->state>=PAGER_SHARED ); assert( pPager->state>=PAGER_SHARED );
@ -3668,7 +3661,7 @@ int sqlite3pager_stmt_begin(Pager *pPager){
pPager->stmtHdrOff = 0; pPager->stmtHdrOff = 0;
pPager->stmtCksum = pPager->cksumInit; pPager->stmtCksum = pPager->cksumInit;
if( !pPager->stmtOpen ){ if( !pPager->stmtOpen ){
rc = sqlite3pager_opentemp(&pPager->stfd); rc = sqlite3PagerOpentemp(&pPager->stfd);
if( rc ) goto stmt_begin_failed; if( rc ) goto stmt_begin_failed;
pPager->stmtOpen = 1; pPager->stmtOpen = 1;
pPager->stmtNRec = 0; pPager->stmtNRec = 0;
@ -3687,7 +3680,7 @@ stmt_begin_failed:
/* /*
** Commit a statement. ** Commit a statement.
*/ */
int sqlite3pager_stmt_commit(Pager *pPager){ int sqlite3PagerStmtCommit(Pager *pPager){
if( pPager->stmtInUse ){ if( pPager->stmtInUse ){
PgHdr *pPg, *pNext; PgHdr *pPg, *pNext;
TRACE2("STMT-COMMIT %d\n", PAGERID(pPager)); TRACE2("STMT-COMMIT %d\n", PAGERID(pPager));
@ -3719,7 +3712,7 @@ int sqlite3pager_stmt_commit(Pager *pPager){
/* /*
** Rollback a statement. ** Rollback a statement.
*/ */
int sqlite3pager_stmt_rollback(Pager *pPager){ int sqlite3PagerStmtRollback(Pager *pPager){
int rc; int rc;
if( pPager->stmtInUse ){ if( pPager->stmtInUse ){
TRACE2("STMT-ROLLBACK %d\n", PAGERID(pPager)); TRACE2("STMT-ROLLBACK %d\n", PAGERID(pPager));
@ -3739,7 +3732,7 @@ int sqlite3pager_stmt_rollback(Pager *pPager){
}else{ }else{
rc = pager_stmt_playback(pPager); rc = pager_stmt_playback(pPager);
} }
sqlite3pager_stmt_commit(pPager); sqlite3PagerStmtCommit(pPager);
}else{ }else{
rc = SQLITE_OK; rc = SQLITE_OK;
} }
@ -3750,21 +3743,21 @@ int sqlite3pager_stmt_rollback(Pager *pPager){
/* /*
** Return the full pathname of the database file. ** Return the full pathname of the database file.
*/ */
const char *sqlite3pager_filename(Pager *pPager){ const char *sqlite3PagerFilename(Pager *pPager){
return pPager->zFilename; return pPager->zFilename;
} }
/* /*
** Return the directory of the database file. ** Return the directory of the database file.
*/ */
const char *sqlite3pager_dirname(Pager *pPager){ const char *sqlite3PagerDirname(Pager *pPager){
return pPager->zDirectory; return pPager->zDirectory;
} }
/* /*
** Return the full pathname of the journal file. ** Return the full pathname of the journal file.
*/ */
const char *sqlite3pager_journalname(Pager *pPager){ const char *sqlite3PagerJournalname(Pager *pPager){
return pPager->zJournal; return pPager->zJournal;
} }
@ -3772,14 +3765,14 @@ const char *sqlite3pager_journalname(Pager *pPager){
** Return true if fsync() calls are disabled for this pager. Return FALSE ** Return true if fsync() calls are disabled for this pager. Return FALSE
** if fsync()s are executed normally. ** if fsync()s are executed normally.
*/ */
int sqlite3pager_nosync(Pager *pPager){ int sqlite3PagerNosync(Pager *pPager){
return pPager->noSync; return pPager->noSync;
} }
/* /*
** Set the codec for this pager ** Set the codec for this pager
*/ */
void sqlite3pager_set_codec( void sqlite3PagerSetCodec(
Pager *pPager, Pager *pPager,
void *(*xCodec)(void*,void*,Pgno,int), void *(*xCodec)(void*,void*,Pgno,int),
void *pCodecArg void *pCodecArg
@ -3793,19 +3786,17 @@ void sqlite3pager_set_codec(
** stored at byte 24 of the pager file. ** stored at byte 24 of the pager file.
*/ */
static int pager_incr_changecounter(Pager *pPager){ static int pager_incr_changecounter(Pager *pPager){
void *pPage;
PgHdr *pPgHdr; PgHdr *pPgHdr;
u32 change_counter; u32 change_counter;
int rc; int rc;
/* Open page 1 of the file for writing. */ /* Open page 1 of the file for writing. */
rc = sqlite3pager_get(pPager, 1, &pPage); rc = sqlite3PagerGet(pPager, 1, &pPgHdr);
if( rc!=SQLITE_OK ) return rc; if( rc!=SQLITE_OK ) return rc;
rc = sqlite3pager_write(pPage); rc = sqlite3PagerWrite(pPgHdr);
if( rc!=SQLITE_OK ) return rc; if( rc!=SQLITE_OK ) return rc;
/* Read the current value at byte 24. */ /* Read the current value at byte 24. */
pPgHdr = DATA_TO_PGHDR(pPage);
change_counter = retrieve32bits(pPgHdr, 24); change_counter = retrieve32bits(pPgHdr, 24);
/* Increment the value just read and write it back to byte 24. */ /* Increment the value just read and write it back to byte 24. */
@ -3813,7 +3804,7 @@ static int pager_incr_changecounter(Pager *pPager){
put32bits(((char*)PGHDR_TO_DATA(pPgHdr))+24, change_counter); put32bits(((char*)PGHDR_TO_DATA(pPgHdr))+24, change_counter);
/* Release the page reference. */ /* Release the page reference. */
sqlite3pager_unref(pPage); sqlite3PagerUnref(pPgHdr);
return SQLITE_OK; return SQLITE_OK;
} }
@ -3829,12 +3820,12 @@ static int pager_incr_changecounter(Pager *pPager){
** master journal file if specified). ** master journal file if specified).
** **
** Note that if zMaster==NULL, this does not overwrite a previous value ** Note that if zMaster==NULL, this does not overwrite a previous value
** passed to an sqlite3pager_sync() call. ** passed to an sqlite3PagerSync() call.
** **
** If parameter nTrunc is non-zero, then the pager file is truncated to ** If parameter nTrunc is non-zero, then the pager file is truncated to
** nTrunc pages (this is used by auto-vacuum databases). ** nTrunc pages (this is used by auto-vacuum databases).
*/ */
int sqlite3pager_sync(Pager *pPager, const char *zMaster, Pgno nTrunc){ int sqlite3PagerSync(Pager *pPager, const char *zMaster, Pgno nTrunc){
int rc = SQLITE_OK; int rc = SQLITE_OK;
TRACE4("DATABASE SYNC: File=%s zMaster=%s nTrunc=%d\n", TRACE4("DATABASE SYNC: File=%s zMaster=%s nTrunc=%d\n",
@ -3863,14 +3854,13 @@ int sqlite3pager_sync(Pager *pPager, const char *zMaster, Pgno nTrunc){
** file. ** file.
*/ */
Pgno i; Pgno i;
void *pPage;
int iSkip = PAGER_MJ_PGNO(pPager); int iSkip = PAGER_MJ_PGNO(pPager);
for( i=nTrunc+1; i<=pPager->origDbSize; i++ ){ for( i=nTrunc+1; i<=pPager->origDbSize; i++ ){
if( !(pPager->aInJournal[i/8] & (1<<(i&7))) && i!=iSkip ){ if( !(pPager->aInJournal[i/8] & (1<<(i&7))) && i!=iSkip ){
rc = sqlite3pager_get(pPager, i, &pPage); rc = sqlite3PagerGet(pPager, i, &pPg);
if( rc!=SQLITE_OK ) goto sync_exit; if( rc!=SQLITE_OK ) goto sync_exit;
rc = sqlite3pager_write(pPage); rc = sqlite3PagerWrite(pPg);
sqlite3pager_unref(pPage); sqlite3PagerUnref(pPg);
if( rc!=SQLITE_OK ) goto sync_exit; if( rc!=SQLITE_OK ) goto sync_exit;
} }
} }
@ -3884,7 +3874,7 @@ int sqlite3pager_sync(Pager *pPager, const char *zMaster, Pgno nTrunc){
#ifndef SQLITE_OMIT_AUTOVACUUM #ifndef SQLITE_OMIT_AUTOVACUUM
if( nTrunc!=0 ){ if( nTrunc!=0 ){
rc = sqlite3pager_truncate(pPager, nTrunc); rc = sqlite3PagerTruncate(pPager, nTrunc);
if( rc!=SQLITE_OK ) goto sync_exit; if( rc!=SQLITE_OK ) goto sync_exit;
} }
#endif #endif
@ -3902,7 +3892,7 @@ int sqlite3pager_sync(Pager *pPager, const char *zMaster, Pgno nTrunc){
pPager->state = PAGER_SYNCED; pPager->state = PAGER_SYNCED;
}else if( MEMDB && nTrunc!=0 ){ }else if( MEMDB && nTrunc!=0 ){
rc = sqlite3pager_truncate(pPager, nTrunc); rc = sqlite3PagerTruncate(pPager, nTrunc);
} }
sync_exit: sync_exit:
@ -3927,8 +3917,7 @@ sync_exit:
** has been removed (CREATE INDEX needs to move a page when a statement ** has been removed (CREATE INDEX needs to move a page when a statement
** transaction is active). ** transaction is active).
*/ */
int sqlite3pager_movepage(Pager *pPager, void *pData, Pgno pgno){ int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno){
PgHdr *pPg = DATA_TO_PGHDR(pData);
PgHdr *pPgOld; PgHdr *pPgOld;
int h; int h;
Pgno needSyncPgno = 0; Pgno needSyncPgno = 0;
@ -3989,32 +3978,48 @@ int sqlite3pager_movepage(Pager *pPager, void *pData, Pgno pgno){
** Pager.aInJournal bit has been set. This needs to be remedied by loading ** Pager.aInJournal bit has been set. This needs to be remedied by loading
** the page into the pager-cache and setting the PgHdr.needSync flag. ** the page into the pager-cache and setting the PgHdr.needSync flag.
** **
** The sqlite3pager_get() call may cause the journal to sync. So make ** The sqlite3PagerGet() call may cause the journal to sync. So make
** sure the Pager.needSync flag is set too. ** sure the Pager.needSync flag is set too.
*/ */
int rc; int rc;
void *pNeedSync; PgHdr *pPgHdr;
assert( pPager->needSync ); assert( pPager->needSync );
rc = sqlite3pager_get(pPager, needSyncPgno, &pNeedSync); rc = sqlite3PagerGet(pPager, needSyncPgno, &pPgHdr);
if( rc!=SQLITE_OK ) return rc; if( rc!=SQLITE_OK ) return rc;
pPager->needSync = 1; pPager->needSync = 1;
DATA_TO_PGHDR(pNeedSync)->needSync = 1; pPgHdr->needSync = 1;
DATA_TO_PGHDR(pNeedSync)->inJournal = 1; pPgHdr->inJournal = 1;
makeDirty(DATA_TO_PGHDR(pNeedSync)); makeDirty(pPgHdr);
sqlite3pager_unref(pNeedSync); sqlite3PagerUnref(pPgHdr);
} }
return SQLITE_OK; return SQLITE_OK;
} }
#endif #endif
/*
** Return a pointer to the data for the specified page.
*/
void *sqlite3PagerGetData(DbPage *pPg){
return PGHDR_TO_DATA(pPg);
}
/*
** Return a pointer to the Pager.nExtra bytes of "extra" space
** allocated along with the specified page.
*/
void *sqlite3PagerGetExtra(DbPage *pPg){
Pager *pPager = pPg->pPager;
return (pPager?PGHDR_TO_EXTRA(pPg, pPager):0);
}
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
/* /*
** Return the current state of the file lock for the given pager. ** Return the current state of the file lock for the given pager.
** The return value is one of NO_LOCK, SHARED_LOCK, RESERVED_LOCK, ** The return value is one of NO_LOCK, SHARED_LOCK, RESERVED_LOCK,
** PENDING_LOCK, or EXCLUSIVE_LOCK. ** PENDING_LOCK, or EXCLUSIVE_LOCK.
*/ */
int sqlite3pager_lockstate(Pager *pPager){ int sqlite3PagerLockstate(Pager *pPager){
return sqlite3OsLockState(pPager->fd); return sqlite3OsLockState(pPager->fd);
} }
#endif #endif
@ -4023,7 +4028,7 @@ int sqlite3pager_lockstate(Pager *pPager){
/* /*
** Print a listing of all referenced pages and their ref count. ** Print a listing of all referenced pages and their ref count.
*/ */
void sqlite3pager_refdump(Pager *pPager){ void sqlite3PagerRefdump(Pager *pPager){
PgHdr *pPg; PgHdr *pPg;
for(pPg=pPager->pAll; pPg; pPg=pPg->pNextAll){ for(pPg=pPager->pAll; pPg; pPg=pPg->pNextAll){
if( pPg->nRef<=0 ) continue; if( pPg->nRef<=0 ) continue;

View File

@ -13,7 +13,7 @@
** subsystem. The page cache subsystem reads and writes a file a page ** subsystem. The page cache subsystem reads and writes a file a page
** at a time and provides a journal for rollback. ** at a time and provides a journal for rollback.
** **
** @(#) $Id: pager.h,v 1.53 2007/03/04 13:15:28 drh Exp $ ** @(#) $Id: pager.h,v 1.54 2007/03/19 17:44:27 danielk1977 Exp $
*/ */
#ifndef _PAGER_H_ #ifndef _PAGER_H_
@ -57,7 +57,12 @@ typedef unsigned int Pgno;
typedef struct Pager Pager; typedef struct Pager Pager;
/* /*
** Allowed values for the flags parameter to sqlite3pager_open(). ** Handle type for pages.
*/
typedef struct PgHdr DbPage;
/*
** Allowed values for the flags parameter to sqlite3PagerOpen().
** **
** NOTE: This values must match the corresponding BTREE_ values in btree.h. ** NOTE: This values must match the corresponding BTREE_ values in btree.h.
*/ */
@ -69,55 +74,58 @@ typedef struct Pager Pager;
** See source code comments for a detailed description of the following ** See source code comments for a detailed description of the following
** routines: ** routines:
*/ */
int sqlite3pager_open(Pager **ppPager, const char *zFilename, int sqlite3PagerOpen(Pager **ppPager, const char *zFilename,
int nExtra, int flags); int nExtra, int flags);
void sqlite3pager_set_busyhandler(Pager*, BusyHandler *pBusyHandler); void sqlite3PagerSetBusyhandler(Pager*, BusyHandler *pBusyHandler);
void sqlite3pager_set_destructor(Pager*, void(*)(void*,int)); void sqlite3PagerSetDestructor(Pager*, void(*)(DbPage*,int));
void sqlite3pager_set_reiniter(Pager*, void(*)(void*,int)); void sqlite3PagerSetReiniter(Pager*, void(*)(DbPage*,int));
int sqlite3pager_set_pagesize(Pager*, int); int sqlite3PagerSetPagesize(Pager*, int);
int sqlite3pager_read_fileheader(Pager*, int, unsigned char*); int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
void sqlite3pager_set_cachesize(Pager*, int); void sqlite3PagerSetCachesize(Pager*, int);
int sqlite3pager_close(Pager *pPager); int sqlite3PagerClose(Pager *pPager);
int sqlite3pager_acquire(Pager *pPager, Pgno pgno, void **ppPage, int clrFlag); int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
#define sqlite3pager_get(A,B,C) sqlite3pager_acquire(A,B,C,0) #define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0)
void *sqlite3pager_lookup(Pager *pPager, Pgno pgno); DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
int sqlite3pager_ref(void*); int sqlite3PagerRef(DbPage*);
int sqlite3pager_unref(void*); int sqlite3PagerUnref(DbPage*);
Pgno sqlite3pager_pagenumber(void*); Pgno sqlite3PagerPagenumber(DbPage*);
int sqlite3pager_write(void*); int sqlite3PagerWrite(DbPage*);
int sqlite3pager_iswriteable(void*); int sqlite3PagerIswriteable(DbPage*);
int sqlite3pager_overwrite(Pager *pPager, Pgno pgno, void*); int sqlite3PagerOverwrite(Pager *pPager, Pgno pgno, void*);
int sqlite3pager_pagecount(Pager*); int sqlite3PagerPagecount(Pager*);
int sqlite3pager_truncate(Pager*,Pgno); int sqlite3PagerTruncate(Pager*,Pgno);
int sqlite3pager_begin(void*, int exFlag); int sqlite3PagerBegin(DbPage*, int exFlag);
int sqlite3pager_commit(Pager*); int sqlite3PagerCommit(Pager*);
int sqlite3pager_sync(Pager*,const char *zMaster, Pgno); int sqlite3PagerSync(Pager*,const char *zMaster, Pgno);
int sqlite3pager_rollback(Pager*); int sqlite3PagerRollback(Pager*);
int sqlite3pager_isreadonly(Pager*); int sqlite3PagerIsreadonly(Pager*);
int sqlite3pager_stmt_begin(Pager*); int sqlite3PagerStmtBegin(Pager*);
int sqlite3pager_stmt_commit(Pager*); int sqlite3PagerStmtCommit(Pager*);
int sqlite3pager_stmt_rollback(Pager*); int sqlite3PagerStmtRollback(Pager*);
void sqlite3pager_dont_rollback(void*); void sqlite3PagerDontRollback(DbPage*);
void sqlite3pager_dont_write(Pager*, Pgno); void sqlite3PagerDontWrite(Pager*, Pgno);
int sqlite3pager_refcount(Pager*); int sqlite3PagerRefcount(Pager*);
int *sqlite3pager_stats(Pager*); int *sqlite3PagerStats(Pager*);
void sqlite3pager_set_safety_level(Pager*,int,int); void sqlite3PagerSetSafetyLevel(Pager*,int,int);
const char *sqlite3pager_filename(Pager*); const char *sqlite3PagerFilename(Pager*);
const char *sqlite3pager_dirname(Pager*); const char *sqlite3PagerDirname(Pager*);
const char *sqlite3pager_journalname(Pager*); const char *sqlite3PagerJournalname(Pager*);
int sqlite3pager_nosync(Pager*); int sqlite3PagerNosync(Pager*);
int sqlite3pager_rename(Pager*, const char *zNewName); int sqlite3PagerRename(Pager*, const char *zNewName);
void sqlite3pager_set_codec(Pager*,void*(*)(void*,void*,Pgno,int),void*); void sqlite3PagerSetCodec(Pager*,void*(*)(void*,void*,Pgno,int),void*);
int sqlite3pager_movepage(Pager*,void*,Pgno); int sqlite3PagerMovepage(Pager*,DbPage*,Pgno);
int sqlite3pager_reset(Pager*); int sqlite3PagerReset(Pager*);
int sqlite3pager_release_memory(int); int sqlite3PagerReleaseMemory(int);
void *sqlite3PagerGetData(DbPage *);
void *sqlite3PagerGetExtra(DbPage *);
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
int sqlite3pager_lockstate(Pager*); int sqlite3PagerLockstate(Pager*);
#endif #endif
#ifdef SQLITE_TEST #ifdef SQLITE_TEST
void sqlite3pager_refdump(Pager*); void sqlite3PagerRefdump(Pager*);
int pager3_refinfo_enable; int pager3_refinfo_enable;
#endif #endif

View File

@ -11,7 +11,7 @@
************************************************************************* *************************************************************************
** This file contains code used to implement the PRAGMA command. ** This file contains code used to implement the PRAGMA command.
** **
** $Id: pragma.c,v 1.128 2007/03/14 15:37:04 danielk1977 Exp $ ** $Id: pragma.c,v 1.129 2007/03/19 17:44:28 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "os.h" #include "os.h"
@ -941,7 +941,7 @@ void sqlite3Pragma(
if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){ if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){
sqlite3VdbeOp3(v, OP_String8, 0, 0, "closed", P3_STATIC); sqlite3VdbeOp3(v, OP_String8, 0, 0, "closed", P3_STATIC);
}else{ }else{
int j = sqlite3pager_lockstate(pPager); int j = sqlite3PagerLockstate(pPager);
sqlite3VdbeOp3(v, OP_String8, 0, 0, sqlite3VdbeOp3(v, OP_String8, 0, 0,
(j>=0 && j<=4) ? azLockName[j] : "unknown", P3_STATIC); (j>=0 && j<=4) ? azLockName[j] : "unknown", P3_STATIC);
} }

View File

@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated ** is not included in the SQLite library. It is used for automated
** testing of the SQLite library. ** testing of the SQLite library.
** **
** $Id: test2.c,v 1.40 2007/03/15 12:17:43 drh Exp $ ** $Id: test2.c,v 1.41 2007/03/19 17:44:28 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "os.h" #include "os.h"
@ -78,13 +78,13 @@ static int pager_open(
return TCL_ERROR; return TCL_ERROR;
} }
if( Tcl_GetInt(interp, argv[2], &nPage) ) return TCL_ERROR; if( Tcl_GetInt(interp, argv[2], &nPage) ) return TCL_ERROR;
rc = sqlite3pager_open(&pPager, argv[1], 0, 0); rc = sqlite3PagerOpen(&pPager, argv[1], 0, 0);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0); Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR; return TCL_ERROR;
} }
sqlite3pager_set_cachesize(pPager, nPage); sqlite3PagerSetCachesize(pPager, nPage);
sqlite3pager_set_pagesize(pPager, test_pagesize); sqlite3PagerSetPagesize(pPager, test_pagesize);
sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPager); sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPager);
Tcl_AppendResult(interp, zBuf, 0); Tcl_AppendResult(interp, zBuf, 0);
return TCL_OK; return TCL_OK;
@ -109,7 +109,7 @@ static int pager_close(
return TCL_ERROR; return TCL_ERROR;
} }
pPager = sqlite3TextToPtr(argv[1]); pPager = sqlite3TextToPtr(argv[1]);
rc = sqlite3pager_close(pPager); rc = sqlite3PagerClose(pPager);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0); Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR; return TCL_ERROR;
@ -136,7 +136,7 @@ static int pager_rollback(
return TCL_ERROR; return TCL_ERROR;
} }
pPager = sqlite3TextToPtr(argv[1]); pPager = sqlite3TextToPtr(argv[1]);
rc = sqlite3pager_rollback(pPager); rc = sqlite3PagerRollback(pPager);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0); Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR; return TCL_ERROR;
@ -163,7 +163,7 @@ static int pager_commit(
return TCL_ERROR; return TCL_ERROR;
} }
pPager = sqlite3TextToPtr(argv[1]); pPager = sqlite3TextToPtr(argv[1]);
rc = sqlite3pager_commit(pPager); rc = sqlite3PagerCommit(pPager);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0); Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR; return TCL_ERROR;
@ -190,7 +190,7 @@ static int pager_stmt_begin(
return TCL_ERROR; return TCL_ERROR;
} }
pPager = sqlite3TextToPtr(argv[1]); pPager = sqlite3TextToPtr(argv[1]);
rc = sqlite3pager_stmt_begin(pPager); rc = sqlite3PagerStmtBegin(pPager);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0); Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR; return TCL_ERROR;
@ -217,7 +217,7 @@ static int pager_stmt_rollback(
return TCL_ERROR; return TCL_ERROR;
} }
pPager = sqlite3TextToPtr(argv[1]); pPager = sqlite3TextToPtr(argv[1]);
rc = sqlite3pager_stmt_rollback(pPager); rc = sqlite3PagerStmtRollback(pPager);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0); Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR; return TCL_ERROR;
@ -244,7 +244,7 @@ static int pager_stmt_commit(
return TCL_ERROR; return TCL_ERROR;
} }
pPager = sqlite3TextToPtr(argv[1]); pPager = sqlite3TextToPtr(argv[1]);
rc = sqlite3pager_stmt_commit(pPager); rc = sqlite3PagerStmtCommit(pPager);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0); Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR; return TCL_ERROR;
@ -271,7 +271,7 @@ static int pager_stats(
return TCL_ERROR; return TCL_ERROR;
} }
pPager = sqlite3TextToPtr(argv[1]); pPager = sqlite3TextToPtr(argv[1]);
a = sqlite3pager_stats(pPager); a = sqlite3PagerStats(pPager);
for(i=0; i<9; i++){ for(i=0; i<9; i++){
static char *zName[] = { static char *zName[] = {
"ref", "page", "max", "size", "state", "err", "ref", "page", "max", "size", "state", "err",
@ -304,7 +304,7 @@ static int pager_pagecount(
return TCL_ERROR; return TCL_ERROR;
} }
pPager = sqlite3TextToPtr(argv[1]); pPager = sqlite3TextToPtr(argv[1]);
sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",sqlite3pager_pagecount(pPager)); sqlite3_snprintf(sizeof(zBuf),zBuf,"%d",sqlite3PagerPagecount(pPager));
Tcl_AppendResult(interp, zBuf, 0); Tcl_AppendResult(interp, zBuf, 0);
return TCL_OK; return TCL_OK;
} }
@ -322,7 +322,7 @@ static int page_get(
){ ){
Pager *pPager; Pager *pPager;
char zBuf[100]; char zBuf[100];
void *pPage; DbPage *pPage;
int pgno; int pgno;
int rc; int rc;
if( argc!=3 ){ if( argc!=3 ){
@ -332,7 +332,7 @@ static int page_get(
} }
pPager = sqlite3TextToPtr(argv[1]); pPager = sqlite3TextToPtr(argv[1]);
if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR; if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR;
rc = sqlite3pager_get(pPager, pgno, &pPage); rc = sqlite3PagerGet(pPager, pgno, &pPage);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0); Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR; return TCL_ERROR;
@ -356,7 +356,7 @@ static int page_lookup(
){ ){
Pager *pPager; Pager *pPager;
char zBuf[100]; char zBuf[100];
void *pPage; DbPage *pPage;
int pgno; int pgno;
if( argc!=3 ){ if( argc!=3 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
@ -365,7 +365,7 @@ static int page_lookup(
} }
pPager = sqlite3TextToPtr(argv[1]); pPager = sqlite3TextToPtr(argv[1]);
if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR; if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR;
pPage = sqlite3pager_lookup(pPager, pgno); pPage = sqlite3PagerLookup(pPager, pgno);
if( pPage ){ if( pPage ){
sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPage); sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPage);
Tcl_AppendResult(interp, zBuf, 0); Tcl_AppendResult(interp, zBuf, 0);
@ -392,7 +392,7 @@ static int pager_truncate(
} }
pPager = sqlite3TextToPtr(argv[1]); pPager = sqlite3TextToPtr(argv[1]);
if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR; if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR;
rc = sqlite3pager_truncate(pPager, pgno); rc = sqlite3PagerTruncate(pPager, pgno);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0); Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR; return TCL_ERROR;
@ -412,15 +412,15 @@ static int page_unref(
int argc, /* Number of arguments */ int argc, /* Number of arguments */
const char **argv /* Text of each argument */ const char **argv /* Text of each argument */
){ ){
void *pPage; DbPage *pPage;
int rc; int rc;
if( argc!=2 ){ if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" PAGE\"", 0); " PAGE\"", 0);
return TCL_ERROR; return TCL_ERROR;
} }
pPage = sqlite3TextToPtr(argv[1]); pPage = (DbPage *)sqlite3TextToPtr(argv[1]);
rc = sqlite3pager_unref(pPage); rc = sqlite3PagerUnref(pPage);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0); Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR; return TCL_ERROR;
@ -440,14 +440,14 @@ static int page_read(
const char **argv /* Text of each argument */ const char **argv /* Text of each argument */
){ ){
char zBuf[100]; char zBuf[100];
void *pPage; DbPage *pPage;
if( argc!=2 ){ if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" PAGE\"", 0); " PAGE\"", 0);
return TCL_ERROR; return TCL_ERROR;
} }
pPage = sqlite3TextToPtr(argv[1]); pPage = sqlite3TextToPtr(argv[1]);
memcpy(zBuf, pPage, sizeof(zBuf)); memcpy(zBuf, sqlite3PagerGetData(pPage), sizeof(zBuf));
Tcl_AppendResult(interp, zBuf, 0); Tcl_AppendResult(interp, zBuf, 0);
return TCL_OK; return TCL_OK;
} }
@ -464,14 +464,14 @@ static int page_number(
const char **argv /* Text of each argument */ const char **argv /* Text of each argument */
){ ){
char zBuf[100]; char zBuf[100];
void *pPage; DbPage *pPage;
if( argc!=2 ){ if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" PAGE\"", 0); " PAGE\"", 0);
return TCL_ERROR; return TCL_ERROR;
} }
pPage = sqlite3TextToPtr(argv[1]); pPage = (DbPage *)sqlite3TextToPtr(argv[1]);
sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", sqlite3pager_pagenumber(pPage)); sqlite3_snprintf(sizeof(zBuf), zBuf, "%d", sqlite3PagerPagenumber(pPage));
Tcl_AppendResult(interp, zBuf, 0); Tcl_AppendResult(interp, zBuf, 0);
return TCL_OK; return TCL_OK;
} }
@ -487,21 +487,23 @@ static int page_write(
int argc, /* Number of arguments */ int argc, /* Number of arguments */
const char **argv /* Text of each argument */ const char **argv /* Text of each argument */
){ ){
void *pPage; DbPage *pPage;
char *pData;
int rc; int rc;
if( argc!=3 ){ if( argc!=3 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" PAGE DATA\"", 0); " PAGE DATA\"", 0);
return TCL_ERROR; return TCL_ERROR;
} }
pPage = sqlite3TextToPtr(argv[1]); pPage = (DbPage *)sqlite3TextToPtr(argv[1]);
rc = sqlite3pager_write(pPage); rc = sqlite3PagerWrite(pPage);
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0); Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR; return TCL_ERROR;
} }
strncpy((char*)pPage, argv[2], test_pagesize-1); pData = sqlite3PagerGetData(pPage);
((char*)pPage)[test_pagesize-1] = 0; strncpy(pData, argv[2], test_pagesize-1);
pData[test_pagesize-1] = 0;
return TCL_OK; return TCL_OK;
} }

View File

@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated ** is not included in the SQLite library. It is used for automated
** testing of the SQLite library. ** testing of the SQLite library.
** **
** $Id: test3.c,v 1.70 2007/02/10 19:22:36 drh Exp $ ** $Id: test3.c,v 1.71 2007/03/19 17:44:28 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "pager.h" #include "pager.h"
@ -511,7 +511,7 @@ static int btree_pager_stats(
return TCL_ERROR; return TCL_ERROR;
} }
pBt = sqlite3TextToPtr(argv[1]); pBt = sqlite3TextToPtr(argv[1]);
a = sqlite3pager_stats(sqlite3BtreePager(pBt)); a = sqlite3PagerStats(sqlite3BtreePager(pBt));
for(i=0; i<11; i++){ for(i=0; i<11; i++){
static char *zName[] = { static char *zName[] = {
"ref", "page", "max", "size", "state", "err", "ref", "page", "max", "size", "state", "err",
@ -545,7 +545,7 @@ static int btree_pager_ref_dump(
} }
pBt = sqlite3TextToPtr(argv[1]); pBt = sqlite3TextToPtr(argv[1]);
#ifdef SQLITE_DEBUG #ifdef SQLITE_DEBUG
sqlite3pager_refdump(sqlite3BtreePager(pBt)); sqlite3PagerRefdump(sqlite3BtreePager(pBt));
#endif #endif
return TCL_OK; return TCL_OK;
} }
@ -1282,15 +1282,17 @@ static int btree_ovfl_info(
n = (n + dataSize - 1)/dataSize; n = (n + dataSize - 1)/dataSize;
pgno = (u32)aResult[10]; pgno = (u32)aResult[10];
while( pgno && n-- ){ while( pgno && n-- ){
DbPage *pDbPage;
sprintf(zElem, "%d", pgno); sprintf(zElem, "%d", pgno);
Tcl_DStringAppendElement(&str, zElem); Tcl_DStringAppendElement(&str, zElem);
if( sqlite3pager_get(pPager, pgno, &pPage)!=SQLITE_OK ){ if( sqlite3PagerGet(pPager, pgno, &pDbPage)!=SQLITE_OK ){
Tcl_DStringFree(&str); Tcl_DStringFree(&str);
Tcl_AppendResult(interp, "unable to get page ", zElem, 0); Tcl_AppendResult(interp, "unable to get page ", zElem, 0);
return TCL_ERROR; return TCL_ERROR;
} }
pPage = sqlite3PagerGetData(pDbPage);
pgno = get4byte((unsigned char*)pPage); pgno = get4byte((unsigned char*)pPage);
sqlite3pager_unref(pPage); sqlite3PagerUnref(pDbPage);
} }
Tcl_DStringResult(interp, &str); Tcl_DStringResult(interp, &str);
return SQLITE_OK; return SQLITE_OK;

View File

@ -14,7 +14,7 @@
** This file contains functions for allocating memory, comparing ** This file contains functions for allocating memory, comparing
** strings, and stuff like that. ** strings, and stuff like that.
** **
** $Id: util.c,v 1.194 2007/03/15 15:33:32 danielk1977 Exp $ ** $Id: util.c,v 1.195 2007/03/19 17:44:28 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "os.h" #include "os.h"
@ -83,7 +83,7 @@ void sqlite3_soft_heap_limit(int n){
** Release memory held by SQLite instances created by the current thread. ** Release memory held by SQLite instances created by the current thread.
*/ */
int sqlite3_release_memory(int n){ int sqlite3_release_memory(int n){
return sqlite3pager_release_memory(n); return sqlite3PagerReleaseMemory(n);
} }
#else #else
/* If SQLITE_ENABLE_MEMORY_MANAGEMENT is not defined, then define a version /* If SQLITE_ENABLE_MEMORY_MANAGEMENT is not defined, then define a version