-C After\scode\sis\sgenerated\sfor\sa\ssubquery,\sdelete\sthe\sSelect\sstructure\sin\sorder\nto\sforce\sthe\stemporary\stable\sto\sbe\sused\sand\sto\sprevent\sthe\ssubquery\sfrom\nbeing\sevaluated\sa\ssecond\stime.\s\sTicket\s#601.\s(CVS\s1216)
-D 2004-02-09T14:37:50
+C Allow\sSQLITE_PAGE_SIZE\sto\sbe\sredefined\son\sthe\scompiler\scommand-line.\s(CVS\s1217)
+D 2004-02-10T01:54:28
F Makefile.in cfd75c46b335881999333a9e4b982fa8491f200b
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
F src/attach.c 4a0a3c0885fec11a0a199a8031694d08925d0a27
F src/auth.c c59ad0dab501888f8b1fccc25e2f5965d2265116
-F src/btree.c 9ab30f0504ef69ba4cba2f264d8096c5abc2b7b8
+F src/btree.c 26d10f3149311665b2373273ca1cce29c3bc042f
F src/btree.h 9b7c09f1e64274d7bb74a57bbfc63778f67b1048
F src/btree_rb.c 50210dfd2a5f410c8624ef8fde8e82babd376d9f
F src/build.c 0fdb0ce4bd87419b3930d0279e8277c4f9f69c1f
F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565
F src/os.c 681ec36217bc7c795d55d9a63ff79a8614ddee8c
F src/os.h 8d02b622153d2df442da1ec37cdd6b1bd9804a25
-F src/pager.c 71d17c231d1bec68190be088a9652d31294ec30f
-F src/pager.h 767867c835ebc29bb8929c50e6036ae8e79d534a
+F src/pager.c cde4fd5a47b5109a26d44ac9daac94c0ea8e100d
+F src/pager.h b618354fa6270a87e0105be8aeaa0a0c7c545ee2
F src/parse.y 7a121554c0c0c0150a77ab05417b01fa44813ac4
F src/pragma.c 89d62c31c6f0a43376fe8d20549b87a6d30c467a
F src/printf.c 84e4ea4ba49cbbf930e95e82295127ad5843ae1f
F src/table.c d845cb101b5afc1f7fea083c99e3d2fa7998d895
F src/tclsqlite.c 30afbb2e446d193d867e49fb0ca5ed84f1e0867f
F src/test1.c 56e9a156df3ad5e4e98df776776e963effc727f7
-F src/test2.c 5014337d8576b731cce5b5a14bec4f0daf432700
+F src/test2.c 75819b0f2c63c6a0fd6995445881f2eb94036996
F src/test3.c 30985ebdfaf3ee1462a9b0652d3efbdc8d9798f5
F src/test4.c dcbbbb382626fd466a7c46907f74db35fc8bad64
F src/tokenize.c 8c95dcd2620b18dc0db1cdc97f9e111d11e55fe0
F test/bigfile.test ea904b853ce2d703b16c5ce90e2b54951bc1ae81
F test/bigrow.test 8ab252dba108f12ad64e337b0f2ff31a807ac578
F test/bind.test 56a57043b42c4664ca705f6050e56717a8a6699a
-F test/btree.test 1e3463c7838e7e71bbf37c9c6e45beee9c8975ba
+F test/btree.test 677aeaac7b7b81980b446ca9cab15aa0cc5550d5
F test/btree2.test e3b81ec33dc2f89b3e6087436dfe605b870c9080
F test/btree3.test e597fb59be2ac0ea69c62aaa2064e998e528b665
F test/btree3rb.test 127efcf5cdfcc352054e7db12622b01cdd8b36ac
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
-P 096312dacb9eb2f8da3cec1504aef8629b505e7f
-R 485fc15d5916c254834a6d63a2aa701b
+P 1cff18868dab5f8ead8ed8d07e088d7fdda04569
+R 2282b1880e3a49fd92893af5cc842432
U drh
-Z 235197ea178a89eec5c2077e08869e28
+Z 382396977f47fa557ea3e3bc564ad2a2
-1cff18868dab5f8ead8ed8d07e088d7fdda04569
\ No newline at end of file
+4c7bf714b5f3d2bb7366367ddf906141a7e36407
\ No newline at end of file
** May you share freely, never taking more than you give.
**
*************************************************************************
-** $Id: btree.c,v 1.98 2004/01/01 12:33:43 drh Exp $
+** $Id: btree.c,v 1.99 2004/02/10 01:54:28 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
** The maximum number of database entries that can be held in a single
** page of the database.
*/
-#define MX_CELL ((SQLITE_PAGE_SIZE-sizeof(PageHdr))/MIN_CELL_SIZE)
+#define MX_CELL ((SQLITE_USABLE_SIZE-sizeof(PageHdr))/MIN_CELL_SIZE)
/*
** The amount of usable space on a single page of the BTree. This is the
** page size minus the overhead of the page header.
*/
-#define USABLE_SPACE (SQLITE_PAGE_SIZE - sizeof(PageHdr))
+#define USABLE_SPACE (SQLITE_USABLE_SIZE - sizeof(PageHdr))
/*
** The maximum amount of payload (in bytes) that can be stored locally for
/*
** The number of bytes of payload that will fit on a single overflow page.
*/
-#define OVERFLOW_SIZE (SQLITE_PAGE_SIZE-sizeof(Pgno))
+#define OVERFLOW_SIZE (SQLITE_USABLE_SIZE-sizeof(Pgno))
/*
** When the key and data for a single entry in the BTree will not fit in
** The pageDestructor() routine handles that chore.
*/
struct MemPage {
- union {
+ union u_page_data {
char aDisk[SQLITE_PAGE_SIZE]; /* Page data stored on disk */
PageHdr hdr; /* Overlay page header */
} u;
** to the end. EXTRA_SIZE is the number of bytes of space needed to hold
** that extra information.
*/
-#define EXTRA_SIZE (sizeof(MemPage)-SQLITE_PAGE_SIZE)
+#define EXTRA_SIZE (sizeof(MemPage)-sizeof(union u_page_data))
/*
** Everything we need to know about an open database
static void defragmentPage(Btree *pBt, MemPage *pPage){
int pc, i, n;
FreeBlk *pFBlk;
- char newPage[SQLITE_PAGE_SIZE];
+ char newPage[SQLITE_USABLE_SIZE];
assert( sqlitepager_iswriteable(pPage) );
assert( pPage->isInit );
/* This routine should never be called on an overfull page. The
** following asserts verify that constraint. */
assert( Addr(pCell) > Addr(pPage) );
- assert( Addr(pCell) < Addr(pPage) + SQLITE_PAGE_SIZE );
+ assert( Addr(pCell) < Addr(pPage) + SQLITE_USABLE_SIZE );
n = cellSize(pBt, pCell);
pCell->h.iNext = SWAB16(pBt, pc + n);
pPage->apCell[i] = (Cell*)&pPage->u.aDisk[pc];
pc += n;
}
- assert( pPage->nFree==SQLITE_PAGE_SIZE-pc );
+ assert( pPage->nFree==SQLITE_USABLE_SIZE-pc );
memcpy(pPage->u.aDisk, newPage, pc);
if( pPage->nCell>0 ){
pPage->apCell[pPage->nCell-1]->h.iNext = 0;
}
pFBlk = (FreeBlk*)&pPage->u.aDisk[pc];
- pFBlk->iSize = SWAB16(pBt, SQLITE_PAGE_SIZE - pc);
+ pFBlk->iSize = SWAB16(pBt, SQLITE_USABLE_SIZE - pc);
pFBlk->iNext = 0;
pPage->u.hdr.firstFree = SWAB16(pBt, pc);
- memset(&pFBlk[1], 0, SQLITE_PAGE_SIZE - pc - sizeof(FreeBlk));
+ memset(&pFBlk[1], 0, SQLITE_USABLE_SIZE - pc - sizeof(FreeBlk));
}
/*
pIdx = &pPage->u.hdr.firstFree;
p = (FreeBlk*)&pPage->u.aDisk[SWAB16(pBt, *pIdx)];
while( (iSize = SWAB16(pBt, p->iSize))<nByte ){
- assert( cnt++ < SQLITE_PAGE_SIZE/4 );
+ assert( cnt++ < SQLITE_USABLE_SIZE/4 );
if( p->iNext==0 ){
defragmentPage(pBt, pPage);
pIdx = &pPage->u.hdr.firstFree;
freeSpace = USABLE_SPACE;
idx = SWAB16(pBt, pPage->u.hdr.firstCell);
while( idx!=0 ){
- if( idx>SQLITE_PAGE_SIZE-MIN_CELL_SIZE ) goto page_format_error;
+ if( idx>SQLITE_USABLE_SIZE-MIN_CELL_SIZE ) goto page_format_error;
if( idx<sizeof(PageHdr) ) goto page_format_error;
if( idx!=ROUNDUP(idx) ) goto page_format_error;
pCell = (Cell*)&pPage->u.aDisk[idx];
sz = cellSize(pBt, pCell);
- if( idx+sz > SQLITE_PAGE_SIZE ) goto page_format_error;
+ if( idx+sz > SQLITE_USABLE_SIZE ) goto page_format_error;
freeSpace -= sz;
pPage->apCell[pPage->nCell++] = pCell;
idx = SWAB16(pBt, pCell->h.iNext);
idx = SWAB16(pBt, pPage->u.hdr.firstFree);
while( idx!=0 ){
int iNext;
- if( idx>SQLITE_PAGE_SIZE-sizeof(FreeBlk) ) goto page_format_error;
+ if( idx>SQLITE_USABLE_SIZE-sizeof(FreeBlk) ) goto page_format_error;
if( idx<sizeof(PageHdr) ) goto page_format_error;
pFBlk = (FreeBlk*)&pPage->u.aDisk[idx];
pPage->nFree += SWAB16(pBt, pFBlk->iSize);
PageHdr *pHdr;
FreeBlk *pFBlk;
assert( sqlitepager_iswriteable(pPage) );
- memset(pPage, 0, SQLITE_PAGE_SIZE);
+ memset(pPage, 0, SQLITE_USABLE_SIZE);
pHdr = &pPage->u.hdr;
pHdr->firstCell = 0;
pHdr->firstFree = SWAB16(pBt, sizeof(*pHdr));
pFBlk = (FreeBlk*)&pHdr[1];
pFBlk->iNext = 0;
- pPage->nFree = SQLITE_PAGE_SIZE - sizeof(*pHdr);
+ pPage->nFree = SQLITE_USABLE_SIZE - sizeof(*pHdr);
pFBlk->iSize = SWAB16(pBt, pPage->nFree);
pPage->nCell = 0;
pPage->isOverfull = 0;
assert( sizeof(PageHdr)==8 );
assert( sizeof(CellHdr)==12 );
assert( sizeof(FreeBlk)==4 );
- assert( sizeof(OverflowPage)==SQLITE_PAGE_SIZE );
+ assert( sizeof(OverflowPage)==SQLITE_USABLE_SIZE );
assert( sizeof(FreelistInfo)==OVERFLOW_SIZE );
assert( sizeof(ptr)==sizeof(char*) );
assert( sizeof(uptr)==sizeof(ptr) );
pIdx = &pPage->u.hdr.firstCell;
for(i=0; i<pPage->nCell; i++){
int idx = Addr(pPage->apCell[i]) - Addr(pPage);
- assert( idx>0 && idx<SQLITE_PAGE_SIZE );
+ assert( idx>0 && idx<SQLITE_USABLE_SIZE );
*pIdx = SWAB16(pBt, idx);
pIdx = &pPage->apCell[i]->h.iNext;
}
static void copyPage(MemPage *pTo, MemPage *pFrom){
uptr from, to;
int i;
- memcpy(pTo->u.aDisk, pFrom->u.aDisk, SQLITE_PAGE_SIZE);
+ memcpy(pTo->u.aDisk, pFrom->u.aDisk, SQLITE_USABLE_SIZE);
pTo->pParent = 0;
pTo->isInit = 1;
pTo->nCell = pFrom->nCell;
from = Addr(pFrom);
for(i=0; i<pTo->nCell; i++){
uptr x = Addr(pFrom->apCell[i]);
- if( x>from && x<from+SQLITE_PAGE_SIZE ){
+ if( x>from && x<from+SQLITE_USABLE_SIZE ){
*((uptr*)&pTo->apCell[i]) = x + to - from;
}else{
pTo->apCell[i] = pFrom->apCell[i];
** underfull.
*/
assert( sqlitepager_iswriteable(pPage) );
- if( !pPage->isOverfull && pPage->nFree<SQLITE_PAGE_SIZE/2
+ if( !pPage->isOverfull && pPage->nFree<SQLITE_USABLE_SIZE/2
&& pPage->nCell>=2){
relinkCellList(pBt, pPage);
return SQLITE_OK;
pgnoChild = SWAB32(pBt, pPage->u.hdr.rightChild);
rc = sqlitepager_get(pBt->pPager, pgnoChild, (void**)&pChild);
if( rc ) return rc;
- memcpy(pPage, pChild, SQLITE_PAGE_SIZE);
+ memcpy(pPage, pChild, SQLITE_USABLE_SIZE);
pPage->isInit = 0;
rc = initPage(pBt, pPage, sqlitepager_pagenumber(pPage), 0);
assert( rc==SQLITE_OK );
if( rc==SQLITE_OK ){
rc = sqlitepager_write(pNew);
if( rc==SQLITE_OK ){
- memcpy(pNew, pOvfl, SQLITE_PAGE_SIZE);
+ memcpy(pNew, pOvfl, SQLITE_USABLE_SIZE);
*pPrev = SWAB32(pBtTo, new);
if( pPrevPg ){
sqlitepager_unref(pPrevPg);
rc = sqlitepager_write(pPage);
}
if( rc==SQLITE_OK ){
- memcpy(pPage, pPageFrom, SQLITE_PAGE_SIZE);
+ memcpy(pPage, pPageFrom, SQLITE_USABLE_SIZE);
idx = SWAB16(pBt, pPage->u.hdr.firstCell);
while( idx>0 ){
pCell = (Cell*)&pPage->u.aDisk[idx];
if( recursive ) printf("PAGE %d:\n", pgno);
i = 0;
idx = SWAB16(pBt, pPage->u.hdr.firstCell);
- while( idx>0 && idx<=SQLITE_PAGE_SIZE-MIN_CELL_SIZE ){
+ while( idx>0 && idx<=SQLITE_USABLE_SIZE-MIN_CELL_SIZE ){
Cell *pCell = (Cell*)&pPage->u.aDisk[idx];
int sz = cellSize(pBt, pCell);
sprintf(range,"%d..%d", idx, idx+sz-1);
nFree = 0;
i = 0;
idx = SWAB16(pBt, pPage->u.hdr.firstFree);
- while( idx>0 && idx<SQLITE_PAGE_SIZE ){
+ while( idx>0 && idx<SQLITE_USABLE_SIZE ){
FreeBlk *p = (FreeBlk*)&pPage->u.aDisk[idx];
sprintf(range,"%d..%d", idx, idx+p->iSize-1);
nFree += SWAB16(pBt, p->iSize);
}
if( recursive && pPage->u.hdr.rightChild!=0 ){
idx = SWAB16(pBt, pPage->u.hdr.firstCell);
- while( idx>0 && idx<SQLITE_PAGE_SIZE-MIN_CELL_SIZE ){
+ while( idx>0 && idx<SQLITE_USABLE_SIZE-MIN_CELL_SIZE ){
Cell *pCell = (Cell*)&pPage->u.aDisk[idx];
fileBtreePageDump(pBt, SWAB32(pBt, pCell->h.leftChild), 1);
idx = SWAB16(pBt, pCell->h.iNext);
aResult[4] = pPage->nFree;
cnt = 0;
idx = SWAB16(pBt, pPage->u.hdr.firstFree);
- while( idx>0 && idx<SQLITE_PAGE_SIZE ){
+ while( idx>0 && idx<SQLITE_USABLE_SIZE ){
cnt++;
idx = SWAB16(pBt, ((FreeBlk*)&pPage->u.aDisk[idx])->iNext);
}
Btree *pBt;
char zMsg[100];
char zContext[100];
- char hit[SQLITE_PAGE_SIZE];
+ char hit[SQLITE_USABLE_SIZE];
/* Check that the page exists
*/
*/
memset(hit, 0, sizeof(hit));
memset(hit, 1, sizeof(PageHdr));
- for(i=SWAB16(pBt, pPage->u.hdr.firstCell); i>0 && i<SQLITE_PAGE_SIZE; ){
+ for(i=SWAB16(pBt, pPage->u.hdr.firstCell); i>0 && i<SQLITE_USABLE_SIZE; ){
Cell *pCell = (Cell*)&pPage->u.aDisk[i];
int j;
for(j=i+cellSize(pBt, pCell)-1; j>=i; j--) hit[j]++;
i = SWAB16(pBt, pCell->h.iNext);
}
- for(i=SWAB16(pBt,pPage->u.hdr.firstFree); i>0 && i<SQLITE_PAGE_SIZE; ){
+ for(i=SWAB16(pBt,pPage->u.hdr.firstFree); i>0 && i<SQLITE_USABLE_SIZE; ){
FreeBlk *pFBlk = (FreeBlk*)&pPage->u.aDisk[i];
int j;
for(j=i+SWAB16(pBt,pFBlk->iSize)-1; j>=i; j--) hit[j]++;
i = SWAB16(pBt,pFBlk->iNext);
}
- for(i=0; i<SQLITE_PAGE_SIZE; i++){
+ for(i=0; i<SQLITE_USABLE_SIZE; i++){
if( hit[i]==0 ){
sprintf(zMsg, "Unused space at byte %d of page %d", i, iPage);
checkAppendMsg(pCheck, zMsg, 0);
/* Check that free space is kept to a minimum
*/
#if 0
- if( pParent && pParent->nCell>2 && pPage->nFree>3*SQLITE_PAGE_SIZE/4 ){
+ if( pParent && pParent->nCell>2 && pPage->nFree>3*SQLITE_USABLE_SIZE/4 ){
sprintf(zMsg, "free space (%d) greater than max (%d)", pPage->nFree,
- SQLITE_PAGE_SIZE/3);
+ SQLITE_USABLE_SIZE/3);
checkAppendMsg(pCheck, zContext, zMsg);
}
#endif
if( !pBtTo->inTrans || !pBtFrom->inTrans ) return SQLITE_ERROR;
if( pBtTo->needSwab!=pBtFrom->needSwab ) return SQLITE_ERROR;
if( pBtTo->pCursor ) return SQLITE_BUSY;
- memcpy(pBtTo->page1, pBtFrom->page1, SQLITE_PAGE_SIZE);
+ memcpy(pBtTo->page1, pBtFrom->page1, SQLITE_USABLE_SIZE);
rc = sqlitepager_overwrite(pBtTo->pPager, 1, pBtFrom->page1);
nToPage = sqlitepager_pagecount(pBtTo->pPager);
nPage = sqlitepager_pagecount(pBtFrom->pPager);
** file simultaneously, or one process from reading the database while
** another is writing.
**
-** @(#) $Id: pager.c,v 1.96 2004/02/09 01:20:37 drh Exp $
+** @(#) $Id: pager.c,v 1.97 2004/02/10 01:54:28 drh Exp $
*/
#include "os.h" /* Must be first to enable large file support */
#include "sqliteInt.h"
#define TRACE3(X,Y,Z)
#endif
-/*
-** Number of extra bytes of data allocated at the end of each page and
-** stored on disk but not used by the higher level btree layer.
-*/
-#ifndef SQLITE_PAGE_RESERVE
-#define SQLITE_PAGE_RESERVE 0
-#endif
-
-/*
-** The total number of bytes stored on disk for each page.
-*/
-#define SQLITE_BLOCK_SIZE (SQLITE_PAGE_SIZE+SQLITE_PAGE_RESERVE)
-
/*
** The page cache as a whole is always in one of the following
u8 needSync; /* Sync journal before writing this page */
u8 alwaysRollback; /* Disable dont_rollback() for this page */
PgHdr *pDirty; /* Dirty pages sorted by PgHdr.pgno */
- /* SQLITE_BLOCK_SIZE bytes of page data follow this header */
+ /* SQLITE_PAGE_SIZE bytes of page data follow this header */
/* Pager.nExtra bytes of local data follow the page data */
};
*/
#define PGHDR_TO_DATA(P) ((void*)(&(P)[1]))
#define DATA_TO_PGHDR(D) (&((PgHdr*)(D))[-1])
-#define PGHDR_TO_EXTRA(P) ((void*)&((char*)(&(P)[1]))[SQLITE_BLOCK_SIZE])
+#define PGHDR_TO_EXTRA(P) ((void*)&((char*)(&(P)[1]))[SQLITE_PAGE_SIZE])
/*
** How big to make the hash table used for locating in-memory pages
typedef struct PageRecord PageRecord;
struct PageRecord {
Pgno pgno; /* The page number */
- char aData[SQLITE_BLOCK_SIZE]; /* Original data for page pgno */
+ char aData[SQLITE_PAGE_SIZE]; /* Original data for page pgno */
};
/*
**
** The sanity checking information for the 3rd journal format consists
** of a 32-bit checksum on each page of data. The checksum covers both
-** the page number and the SQLITE_BLOCK_SIZE bytes of data for the page.
+** the page number and the SQLITE_PAGE_SIZE bytes of data for the page.
** This cksum is initialized to a 32-bit random value that appears in the
** journal file right after the header. The random initializer is important,
** because garbage data that appears at the end of a journal is likely
#define JOURNAL_HDR_SZ(X) \
(sizeof(aJournalMagic1) + sizeof(Pgno) + ((X)>=3)*2*sizeof(u32))
#define JOURNAL_PG_SZ(X) \
- (SQLITE_BLOCK_SIZE + sizeof(Pgno) + ((X)>=3)*sizeof(u32))
+ (SQLITE_PAGE_SIZE + sizeof(Pgno) + ((X)>=3)*sizeof(u32))
/*
** Enable reference count tracking here:
*/
pPg = pager_lookup(pPager, pgRec.pgno);
TRACE2("PLAYBACK %d\n", pgRec.pgno);
- sqliteOsSeek(&pPager->fd, (pgRec.pgno-1)*(off_t)SQLITE_BLOCK_SIZE);
- rc = sqliteOsWrite(&pPager->fd, pgRec.aData, SQLITE_BLOCK_SIZE);
+ sqliteOsSeek(&pPager->fd, (pgRec.pgno-1)*(off_t)SQLITE_PAGE_SIZE);
+ rc = sqliteOsWrite(&pPager->fd, pgRec.aData, SQLITE_PAGE_SIZE);
if( pPg ){
/* No page should ever be rolled back that is in use, except for page
** 1 which is held in use in order to keep the lock on the database
** active.
*/
assert( pPg->nRef==0 || pPg->pgno==1 );
- memcpy(PGHDR_TO_DATA(pPg), pgRec.aData, SQLITE_BLOCK_SIZE);
+ memcpy(PGHDR_TO_DATA(pPg), pgRec.aData, SQLITE_PAGE_SIZE);
memset(PGHDR_TO_EXTRA(pPg), 0, pPager->nExtra);
pPg->dirty = 0;
pPg->needSync = 0;
if( pPager->xCodec ){
- pPager->xCodec(pPager->pCodecArg, PGHDR_TO_DATA(pPg), 0);
+ pPager->xCodec(pPager->pCodecArg, PGHDR_TO_DATA(pPg), 2);
}
}
return rc;
** database to during a rollback.
** * Zero or more pages instances, each as follows:
** + 4 byte page number.
-** + SQLITE_BLOCK_SIZE bytes of data.
+** + SQLITE_PAGE_SIZE bytes of data.
** + 4 byte checksum (format 3 only)
**
** When we speak of the journal header, we mean the first 4 bullets above.
goto end_playback;
}
assert( pPager->origDbSize==0 || pPager->origDbSize==mxPg );
- rc = sqliteOsTruncate(&pPager->fd, SQLITE_BLOCK_SIZE*(off_t)mxPg);
+ rc = sqliteOsTruncate(&pPager->fd, SQLITE_PAGE_SIZE*(off_t)mxPg);
if( rc!=SQLITE_OK ){
goto end_playback;
}
if( rc==SQLITE_OK ){
PgHdr *pPg;
for(pPg=pPager->pAll; pPg; pPg=pPg->pNextAll){
- char zBuf[SQLITE_BLOCK_SIZE];
+ char zBuf[SQLITE_PAGE_SIZE];
if( !pPg->dirty ) continue;
if( (int)pPg->pgno <= pPager->origDbSize ){
- sqliteOsSeek(&pPager->fd, SQLITE_BLOCK_SIZE*(off_t)(pPg->pgno-1));
- rc = sqliteOsRead(&pPager->fd, zBuf, SQLITE_BLOCK_SIZE);
+ sqliteOsSeek(&pPager->fd, SQLITE_PAGE_SIZE*(off_t)(pPg->pgno-1));
+ rc = sqliteOsRead(&pPager->fd, zBuf, SQLITE_PAGE_SIZE);
if( rc ) break;
if( pPager->xCodec ){
pPager->xCodec(pPager->pCodecArg, zBuf, 0);
}
}else{
- memset(zBuf, 0, SQLITE_BLOCK_SIZE);
+ memset(zBuf, 0, SQLITE_PAGE_SIZE);
}
- if( pPg->nRef==0 || memcmp(zBuf, PGHDR_TO_DATA(pPg), SQLITE_BLOCK_SIZE) ){
- memcpy(PGHDR_TO_DATA(pPg), zBuf, SQLITE_BLOCK_SIZE);
+ if( pPg->nRef==0 || memcmp(zBuf, PGHDR_TO_DATA(pPg), SQLITE_PAGE_SIZE) ){
+ memcpy(PGHDR_TO_DATA(pPg), zBuf, SQLITE_PAGE_SIZE);
memset(PGHDR_TO_EXTRA(pPg), 0, pPager->nExtra);
}
pPg->needSync = 0;
/* Truncate the database back to its original size.
*/
- rc = sqliteOsTruncate(&pPager->fd, SQLITE_BLOCK_SIZE*(off_t)pPager->ckptSize);
+ rc = sqliteOsTruncate(&pPager->fd, SQLITE_PAGE_SIZE*(off_t)pPager->ckptSize);
pPager->dbSize = pPager->ckptSize;
/* Figure out how many records are in the checkpoint journal.
pPager->errMask |= PAGER_ERR_DISK;
return 0;
}
- n /= SQLITE_BLOCK_SIZE;
+ n /= SQLITE_PAGE_SIZE;
if( pPager->state!=SQLITE_UNLOCK ){
pPager->dbSize = n;
}
return SQLITE_OK;
}
syncJournal(pPager);
- rc = sqliteOsTruncate(&pPager->fd, SQLITE_BLOCK_SIZE*(off_t)nPage);
+ rc = sqliteOsTruncate(&pPager->fd, SQLITE_PAGE_SIZE*(off_t)nPage);
if( rc==SQLITE_OK ){
pPager->dbSize = nPage;
}
pPager = pList->pPager;
while( pList ){
assert( pList->dirty );
- sqliteOsSeek(&pPager->fd, (pList->pgno-1)*(off_t)SQLITE_BLOCK_SIZE);
+ sqliteOsSeek(&pPager->fd, (pList->pgno-1)*(off_t)SQLITE_PAGE_SIZE);
if( pPager->xCodec ){
pPager->xCodec(pPager->pCodecArg, PGHDR_TO_DATA(pList), 1);
}
- rc = sqliteOsWrite(&pPager->fd, PGHDR_TO_DATA(pList), SQLITE_BLOCK_SIZE);
+ rc = sqliteOsWrite(&pPager->fd, PGHDR_TO_DATA(pList), SQLITE_PAGE_SIZE);
if( pPager->xCodec ){
pPager->xCodec(pPager->pCodecArg, PGHDR_TO_DATA(pList), 0);
}
pPager->nMiss++;
if( pPager->nPage<pPager->mxPage || pPager->pFirst==0 ){
/* Create a new page */
- pPg = sqliteMallocRaw( sizeof(*pPg) + SQLITE_BLOCK_SIZE
+ pPg = sqliteMallocRaw( sizeof(*pPg) + SQLITE_PAGE_SIZE
+ sizeof(u32) + pPager->nExtra );
if( pPg==0 ){
pager_unwritelock(pPager);
return rc;
}
if( pPager->dbSize<(int)pgno ){
- memset(PGHDR_TO_DATA(pPg), 0, SQLITE_BLOCK_SIZE);
+ memset(PGHDR_TO_DATA(pPg), 0, SQLITE_PAGE_SIZE);
}else{
int rc;
- sqliteOsSeek(&pPager->fd, (pgno-1)*(off_t)SQLITE_BLOCK_SIZE);
- rc = sqliteOsRead(&pPager->fd, PGHDR_TO_DATA(pPg), SQLITE_BLOCK_SIZE);
+ sqliteOsSeek(&pPager->fd, (pgno-1)*(off_t)SQLITE_PAGE_SIZE);
+ rc = sqliteOsRead(&pPager->fd, PGHDR_TO_DATA(pPg), SQLITE_PAGE_SIZE);
if( rc!=SQLITE_OK ){
off_t fileSize;
if( sqliteOsFileSize(&pPager->fd,&fileSize)!=SQLITE_OK
- || fileSize>=pgno*SQLITE_BLOCK_SIZE ){
+ || fileSize>=pgno*SQLITE_PAGE_SIZE ){
sqlitepager_unref(PGHDR_TO_DATA(pPg));
return rc;
}else{
- memset(PGHDR_TO_DATA(pPg), 0, SQLITE_BLOCK_SIZE);
+ memset(PGHDR_TO_DATA(pPg), 0, SQLITE_PAGE_SIZE);
}
}else if( pPager->xCodec ){
pPager->xCodec(pPager->pCodecArg, PGHDR_TO_DATA(pPg), 0);
}
store32bits(pPg->pgno, pPg, -4);
if( pPager->xCodec ){
- pPager->xCodec(pPager->pCodecArg, pData, 1);
+ pPager->xCodec(pPager->pCodecArg, pData, 3);
}
rc = sqliteOsWrite(&pPager->jfd, &((char*)pData)[-4], szPg);
if( pPager->xCodec ){
- pPager->xCodec(pPager->pCodecArg, pData, 0);
+ pPager->xCodec(pPager->pCodecArg, pData, 2);
}
if( journal_format>=JOURNAL_FORMAT_3 ){
*(u32*)PGHDR_TO_EXTRA(pPg) = saved;
if( pPager->ckptInUse && !pPg->inCkpt && (int)pPg->pgno<=pPager->ckptSize ){
assert( pPg->inJournal || (int)pPg->pgno>pPager->origDbSize );
store32bits(pPg->pgno, pPg, -4);
- rc = sqliteOsWrite(&pPager->cpfd, &((char*)pData)[-4], SQLITE_BLOCK_SIZE+4);
+ rc = sqliteOsWrite(&pPager->cpfd, &((char*)pData)[-4], SQLITE_PAGE_SIZE+4);
if( rc!=SQLITE_OK ){
sqlitepager_rollback(pPager);
pPager->errMask |= PAGER_ERR_FULL;
if( rc==SQLITE_OK ){
rc = sqlitepager_write(pPage);
if( rc==SQLITE_OK ){
- memcpy(pPage, pData, SQLITE_BLOCK_SIZE);
+ memcpy(pPage, pData, SQLITE_PAGE_SIZE);
}
sqlitepager_unref(pPage);
}
** subsystem. The page cache subsystem reads and writes a file a page
** at a time and provides a journal for rollback.
**
-** @(#) $Id: pager.h,v 1.24 2004/02/09 01:20:37 drh Exp $
+** @(#) $Id: pager.h,v 1.25 2004/02/10 01:54:28 drh Exp $
*/
/*
** The size of one page
**
-** You can change this value to another (reasonable) power of two
-** such as 512, 2048, 4096, or 8192 and things will still work. But
-** experiments show that a page size of 1024 gives the best speed.
-** (The speed differences are minimal.)
+** You can change this value to another (reasonable) value you want.
+** It need not be a power of two, though the interface to the disk
+** will likely be faster if it is.
+**
+** Experiments show that a page size of 1024 gives the best speed
+** for common usages. The speed differences for different sizes
+** such as 512, 2048, 4096, an so forth, is minimal. Note, however,
+** that changing the page size results in a completely imcompatible
+** file format.
*/
#ifndef SQLITE_PAGE_SIZE
#define SQLITE_PAGE_SIZE 1024
#endif
+/*
+** Number of extra bytes of data allocated at the end of each page and
+** stored on disk but not used by the higher level btree layer. Changing
+** this value results in a completely incompatible file format.
+*/
+#ifndef SQLITE_PAGE_RESERVE
+#define SQLITE_PAGE_RESERVE 0
+#endif
+
+/*
+** The total number of usable bytes stored on disk for each page.
+** The usable bytes come at the beginning of the page and the reserve
+** bytes come at the end.
+*/
+#define SQLITE_USABLE_SIZE (SQLITE_PAGE_SIZE-SQLITE_PAGE_RESERVE)
+
/*
** Maximum number of pages in one database. (This is a limitation of
** imposed by 4GB files size limits.)
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
-** $Id: test2.c,v 1.15 2003/02/11 14:55:41 drh Exp $
+** $Id: test2.c,v 1.16 2004/02/10 01:54:28 drh Exp $
*/
#include "os.h"
#include "sqliteInt.h"
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
}
- strncpy((char*)pPage, argv[2], SQLITE_PAGE_SIZE-1);
- ((char*)pPage)[SQLITE_PAGE_SIZE-1] = 0;
+ strncpy((char*)pPage, argv[2], SQLITE_USABLE_SIZE-1);
+ ((char*)pPage)[SQLITE_USABLE_SIZE-1] = 0;
return TCL_OK;
}
*/
int Sqlitetest2_Init(Tcl_Interp *interp){
extern int sqlite_io_error_pending;
+ char zBuf[100];
static struct {
char *zName;
Tcl_CmdProc *xProc;
Tcl_LinkVar(interp, "journal_format",
(char*)&journal_format, TCL_LINK_INT);
#endif
+ sprintf(zBuf, "%d", SQLITE_PAGE_SIZE);
+ Tcl_SetVar(interp, "SQLITE_PAGE_SIZE", zBuf, TCL_GLOBAL_ONLY);
+ sprintf(zBuf, "%d", SQLITE_PAGE_RESERVE);
+ Tcl_SetVar(interp, "SQLITE_PAGE_RESERVE", zBuf, TCL_GLOBAL_ONLY);
+ sprintf(zBuf, "%d", SQLITE_USABLE_SIZE);
+ Tcl_SetVar(interp, "SQLITE_USABLE_SIZE", zBuf, TCL_GLOBAL_ONLY);
return TCL_OK;
}
# This file implements regression tests for SQLite library. The
# focus of this script is btree database backend
#
-# $Id: btree.test,v 1.14 2003/02/12 14:09:45 drh Exp $
+# $Id: btree.test,v 1.15 2004/02/10 01:54:28 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
-if {[info commands btree_open]!=""} {
+if {[info commands btree_open]!="" && $SQLITE_PAGE_SIZE==1024
+ && $SQLITE_USABLE_SIZE==1024} {
# Basic functionality. Open and close a database.
#