-C Simplifications\sand\scomment\scleanup\sin\svdbeaux.c.\s(CVS\s6849)
-D 2009-07-06T00:44:09
+C Make\sthe\ssqlite3BtreeMoveto\sfunction\sstatic,\ssince\sit\sis\sonly\sused\sfrom\swithin\sbtree.c.\sRemove\sunused\sfunction\slockBtreeWithRetry\sfrom\sbtree.c.\s(CVS\s6850)
+D 2009-07-06T18:56:13
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in df9359da7a726ccb67a45db905c5447d5c00c6ef
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
F src/backup.c 97a3859d8585eb4fcb1e81a795cf4b3fdd82f30f
F src/bitvec.c 0ef0651714728055d43de7a4cdd95e703fac0119
F src/btmutex.c 9b899c0d8df3bd68f527b0afe03088321b696d3c
-F src/btree.c 1c12a097a14ea756696a8a0857e587a1fc5533de
-F src/btree.h 8cae6364735a5cb2d577ddb23fa6d0e655a4b931
+F src/btree.c 1a7caa2b0dfd76a7e28049e2333997e6f317c9f3
+F src/btree.h e761619e76a1125d2d82bd3613b5a7ac7d1ee6f7
F src/btreeInt.h b31e5ac04181c7e2892c33ab06228c551df6233c
F src/build.c 867028ee9f63f7bc8eb8d4a720bb98cf9b9a12b4
F src/callback.c cb68b21b0d4ae7d11ae0e487933bce3323784dcf
F src/tclsqlite.c e18e5013dc6bca9f25e6022fbe17ba3ccb821f95
F src/test1.c c8f9358879876660b721369f576bf6e4ac5b9210
F src/test2.c d73e4a490349245fb196b990b80684513e0ceaee
-F src/test3.c a06da9e41583fe8e4eb8c4dea323bb72bdbaaa1e
+F src/test3.c ec1592b2660c0e0a353659fe3f7538fbbbce50ec
F src/test4.c f79ab52d27ff49b784b631a42e2ccd52cfd5c84c
F src/test5.c 162a1cea2105a2c460a3f39fa6919617b562a288
F src/test6.c 1a0a7a1f179469044b065b4a88aab9faee114101
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl 672f81d693a03f80f5ae60bfefacd8a349e76746
-P c76a366ed4dc63604ff695b3ee9c183e430a367e
-R ad4ffc2a251f0cb49d86125eb3a3f81a
-U drh
-Z 7f4c0366c55a62863a847bc059dca81a
+P 1636e7831a21d401a48aa74d884444a287f14f72
+R 7e38f383918ece6e29e3d7609123e090
+U danielk1977
+Z e5cf1d022d5f233619186bb620497925
** May you share freely, never taking more than you give.
**
*************************************************************************
-** $Id: btree.c,v 1.652 2009/07/04 17:16:01 danielk1977 Exp $
+** $Id: btree.c,v 1.653 2009/07/06 18:56:13 danielk1977 Exp $
**
** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
pCur->eState = CURSOR_INVALID;
}
+/*
+** In this version of BtreeMoveto, pKey is a packed index record
+** such as is generated by the OP_MakeRecord opcode. Unpack the
+** record and then call BtreeMovetoUnpacked() to do the work.
+*/
+static int btreeMoveto(
+ BtCursor *pCur, /* Cursor open on the btree to be searched */
+ const void *pKey, /* Packed key if the btree is an index */
+ i64 nKey, /* Integer key for tables. Size of pKey for indices */
+ int bias, /* Bias search to the high end */
+ int *pRes /* Write search results here */
+){
+ int rc; /* Status code */
+ UnpackedRecord *pIdxKey; /* Unpacked index key */
+ char aSpace[150]; /* Temp space for pIdxKey - to avoid a malloc */
+
+ if( pKey ){
+ assert( nKey==(i64)(int)nKey );
+ pIdxKey = sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey,
+ aSpace, sizeof(aSpace));
+ if( pIdxKey==0 ) return SQLITE_NOMEM;
+ }else{
+ pIdxKey = 0;
+ }
+ rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes);
+ if( pKey ){
+ sqlite3VdbeDeleteUnpackedRecord(pIdxKey);
+ }
+ return rc;
+}
+
/*
** Restore the cursor to the position it was in (or as close to as possible)
** when saveCursorPosition() was called. Note that this call deletes the
return pCur->skip;
}
pCur->eState = CURSOR_INVALID;
- rc = sqlite3BtreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &pCur->skip);
+ rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &pCur->skip);
if( rc==SQLITE_OK ){
sqlite3_free(pCur->pKey);
pCur->pKey = 0;
return rc;
}
-/*
-** This routine works like lockBtree() except that it also invokes the
-** busy callback if there is lock contention.
-*/
-static int lockBtreeWithRetry(Btree *pRef){
- int rc = SQLITE_OK;
-
- assert( sqlite3BtreeHoldsMutex(pRef) );
- if( pRef->inTrans==TRANS_NONE ){
- u8 inTransaction = pRef->pBt->inTransaction;
- btreeIntegrity(pRef);
- rc = sqlite3BtreeBeginTrans(pRef, 0);
- pRef->pBt->inTransaction = inTransaction;
- pRef->inTrans = TRANS_NONE;
- if( rc==SQLITE_OK ){
- pRef->pBt->nTransaction--;
- }
- btreeIntegrity(pRef);
- }
- return rc;
-}
-
-
/*
** If there are no outstanding cursors and we are not in the middle
** of a transaction but there is a read lock on the database, then
return rc;
}
-/*
-** In this version of BtreeMoveto, pKey is a packed index record
-** such as is generated by the OP_MakeRecord opcode. Unpack the
-** record and then call BtreeMovetoUnpacked() to do the work.
-*/
-int sqlite3BtreeMoveto(
- BtCursor *pCur, /* Cursor open on the btree to be searched */
- const void *pKey, /* Packed key if the btree is an index */
- i64 nKey, /* Integer key for tables. Size of pKey for indices */
- int bias, /* Bias search to the high end */
- int *pRes /* Write search results here */
-){
- int rc; /* Status code */
- UnpackedRecord *pIdxKey; /* Unpacked index key */
- char aSpace[150]; /* Temp space for pIdxKey - to avoid a malloc */
-
-
- if( pKey ){
- assert( nKey==(i64)(int)nKey );
- pIdxKey = sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey,
- aSpace, sizeof(aSpace));
- if( pIdxKey==0 ) return SQLITE_NOMEM;
- }else{
- pIdxKey = 0;
- }
- rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes);
- if( pKey ){
- sqlite3VdbeDeleteUnpackedRecord(pIdxKey);
- }
- return rc;
-}
-
/*
** Return TRUE if the cursor is not pointing at an entry of the table.
** ignored. For a ZERODATA table, the pData and nData are both ignored.
**
** If the seekResult parameter is non-zero, then a successful call to
-** sqlite3BtreeMoveto() to seek cursor pCur to (pKey, nKey) has already
+** MovetoUnpacked() to seek cursor pCur to (pKey, nKey) has already
** been performed. seekResult is the search result returned (a negative
** number if pCur points at an entry that is smaller than (pKey, nKey), or
** a positive value if pCur points at an etry that is larger than
const void *pData, int nData, /* The data of the new record */
int nZero, /* Number of extra 0 bytes to append to data */
int appendBias, /* True if this is likely an append */
- int seekResult /* Result of prior sqlite3BtreeMoveto() call */
+ int seekResult /* Result of prior MovetoUnpacked() call */
){
int rc;
int loc = seekResult;
/* Save the positions of any other cursors open on this table.
**
- ** In some cases, the call to sqlite3BtreeMoveto() below is a no-op. For
+ ** In some cases, the call to btreeMoveto() below is a no-op. For
** example, when inserting data into a table with auto-generated integer
** keys, the VDBE layer invokes sqlite3BtreeLast() to figure out the
** integer key to use. It then calls this function to actually insert the
- ** data into the intkey B-Tree. In this case sqlite3BtreeMoveto() recognizes
+ ** data into the intkey B-Tree. In this case btreeMoveto() recognizes
** that the cursor is already where it needs to be and returns without
** doing any work. To avoid thwarting these optimizations, it is important
** not to clear the cursor here.
*/
if(
SQLITE_OK!=(rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur)) || (!loc &&
- SQLITE_OK!=(rc = sqlite3BtreeMoveto(pCur, pKey, nKey, appendBias, &loc))
+ SQLITE_OK!=(rc = btreeMoveto(pCur, pKey, nKey, appendBias, &loc))
)){
return rc;
}
** an array of pages numbers were each page number is the root page of
** a table. nRoot is the number of entries in aRoot.
**
+** A read-only or read-write transaction must be opened before calling
+** this function.
+**
** Write the number of error seen in *pnErr. Except for some memory
** allocation errors, an error message held in memory obtained from
** malloc is returned if *pnErr is non-zero. If *pnErr==0 then NULL is
char zErr[100];
sqlite3BtreeEnter(p);
+ assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
nRef = sqlite3PagerRefcount(pBt->pPager);
- if( lockBtreeWithRetry(p)!=SQLITE_OK ){
- *pnErr = 1;
- sqlite3BtreeLeave(p);
- return sqlite3DbStrDup(0, "cannot acquire a read lock on the database");
- }
sCheck.pBt = pBt;
sCheck.pPager = pBt->pPager;
sCheck.nPage = pagerPagecount(sCheck.pBt);
sCheck.mallocFailed = 0;
*pnErr = 0;
if( sCheck.nPage==0 ){
- unlockBtreeIfUnused(pBt);
sqlite3BtreeLeave(p);
return 0;
}
sCheck.anRef = sqlite3Malloc( (sCheck.nPage+1)*sizeof(sCheck.anRef[0]) );
if( !sCheck.anRef ){
- unlockBtreeIfUnused(pBt);
*pnErr = 1;
sqlite3BtreeLeave(p);
return 0;
** This is an internal consistency check; an integrity check
** of the integrity check.
*/
- unlockBtreeIfUnused(pBt);
if( NEVER(nRef != sqlite3PagerRefcount(pBt->pPager)) ){
checkAppendMsg(&sCheck, 0,
"Outstanding page count goes from %d to %d during this analysis",