openbsd-ports/databases/sqlite3/patches/patch-src_btree_c

70 lines
2.9 KiB
Plaintext

$OpenBSD: patch-src_btree_c,v 1.1 2005/01/12 17:54:05 jolan Exp $
--- src/btree.c.orig Fri Oct 8 08:03:06 2004
+++ src/btree.c Fri Jan 7 03:26:40 2005
@@ -2753,13 +2753,19 @@ static void dropCell(MemPage *pPage, int
** in pTemp or the original pCell) and also record its index.
** Allocating a new entry in pPage->aCell[] implies that
** pPage->nOverflow is incremented.
+**
+** If nSkip is non-zero, then do not copy the first nSkip bytes of the
+** cell. The caller will overwrite them after this function returns. If
+** nSkip is non-zero, then pCell may not point to a valid memory location
+** (but pCell+nSkip is always valid).
*/
static void insertCell(
MemPage *pPage, /* Page into which we are copying */
int i, /* New cell becomes the i-th cell of the page */
u8 *pCell, /* Content of the new cell */
int sz, /* Bytes of content in pCell */
- u8 *pTemp /* Temp storage space for pCell, if needed */
+ u8 *pTemp, /* Temp storage space for pCell, if needed */
+ u8 nSkip /* Do not write the first nSkip bytes of the cell */
){
int idx; /* Where to write new cell content in data[] */
int j; /* Loop counter */
@@ -2776,7 +2782,7 @@ static void insertCell(
assert( sqlite3pager_iswriteable(pPage->aData) );
if( pPage->nOverflow || sz+2>pPage->nFree ){
if( pTemp ){
- memcpy(pTemp, pCell, sz);
+ memcpy(pTemp+nSkip, pCell+nSkip, sz-nSkip);
pCell = pTemp;
}
j = pPage->nOverflow++;
@@ -2801,7 +2807,7 @@ static void insertCell(
assert( end <= get2byte(&data[hdr+5]) );
pPage->nCell++;
pPage->nFree -= 2;
- memcpy(&data[idx], pCell, sz);
+ memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip);
for(j=end-2, ptr=&data[j]; j>ins; j-=2, ptr-=2){
ptr[0] = ptr[-2];
ptr[1] = ptr[-1];
@@ -3280,7 +3286,7 @@ static int balance_nonroot(MemPage *pPag
iSpace += sz;
assert( iSpace<=pBt->pageSize*5 );
}
- insertCell(pParent, nxDiv, pCell, sz, pTemp);
+ insertCell(pParent, nxDiv, pCell, sz, pTemp, 4);
put4byte(findOverflowCell(pParent,nxDiv), pNew->pgno);
j++;
nxDiv++;
@@ -3584,7 +3590,7 @@ int sqlite3BtreeInsert(
}else{
assert( pPage->leaf );
}
- insertCell(pPage, pCur->idx, newCell, szNew, 0);
+ insertCell(pPage, pCur->idx, newCell, szNew, 0, 0);
rc = balance(pPage);
/* sqlite3BtreePageDump(pCur->pBt, pCur->pgnoRoot, 1); */
/* fflush(stdout); */
@@ -3662,7 +3668,7 @@ int sqlite3BtreeDelete(BtCursor *pCur){
assert( MX_CELL_SIZE(pBt)>=szNext+4 );
tempCell = sqliteMallocRaw( MX_CELL_SIZE(pBt) );
if( tempCell==0 ) return SQLITE_NOMEM;
- insertCell(pPage, pCur->idx, pNext-4, szNext+4, tempCell);
+ insertCell(pPage, pCur->idx, pNext-4, szNext+4, tempCell, 0);
put4byte(findOverflowCell(pPage, pCur->idx), pgnoChild);
rc = balance(pPage);
sqliteFree(tempCell);