Cause opening a transaction on a sharable b-tree module automatically obtain a read-lock on page 1. This means there is no way for sqlite3BtreeGetMeta() to fail. (CVS 6836)

FossilOrigin-Name: e3c055f167f895ae45858de9d9d8a264df2f36b6
This commit is contained in:
danielk1977
2009-07-02 07:47:33 +00:00
parent 325ccfa90e
commit 602b466e99
12 changed files with 168 additions and 163 deletions
+2 -2
View File
@@ -12,7 +12,7 @@
** This file contains the implementation of the sqlite3_backup_XXX()
** API functions and the related features.
**
** $Id: backup.c,v 1.17 2009/06/03 11:25:07 danielk1977 Exp $
** $Id: backup.c,v 1.18 2009/07/02 07:47:33 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "btreeInt.h"
@@ -318,7 +318,7 @@ int sqlite3_backup_step(sqlite3_backup *p, int nPage){
&& SQLITE_OK==(rc = sqlite3BtreeBeginTrans(p->pDest, 2))
){
p->bDestLocked = 1;
rc = sqlite3BtreeGetMeta(p->pDest, BTREE_SCHEMA_VERSION, &p->iDestSchema);
sqlite3BtreeGetMeta(p->pDest, BTREE_SCHEMA_VERSION, &p->iDestSchema);
}
/* If there is no open read-transaction on the source database, open
+43 -76
View File
@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.647 2009/07/02 05:23:26 danielk1977 Exp $
** $Id: btree.c,v 1.648 2009/07/02 07:47:33 danielk1977 Exp $
**
** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
@@ -366,7 +366,10 @@ static void clearAllSharedCacheTableLocks(Btree *p){
assert( pLock->pBtree->inTrans>=pLock->eLock );
if( pLock->pBtree==p ){
*ppIter = pLock->pNext;
sqlite3_free(pLock);
assert( pLock->iTable!=1 || pLock==&p->lock );
if( pLock->iTable!=1 ){
sqlite3_free(pLock);
}
}else{
ppIter = &pLock->pNext;
}
@@ -1605,6 +1608,10 @@ int sqlite3BtreeOpen(
}
p->inTrans = TRANS_NONE;
p->db = db;
#ifndef SQLITE_OMIT_SHARED_CACHE
p->lock.pBtree = p;
p->lock.iTable = 1;
#endif
#if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
/*
@@ -2376,6 +2383,13 @@ int sqlite3BtreeBeginTrans(Btree *p, int wrflag){
}
#endif
/* Any read-only or read-write transaction implies a read-lock on
** page 1. So if some other shared-cache client already has a write-lock
** on page 1, the transaction cannot be opened. */
if( SQLITE_OK!=(rc = querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK)) ){
goto trans_begun;
}
do {
/* Call lockBtree() until either pBt->pPage1 is populated or
** lockBtree() returns something other than SQLITE_OK. lockBtree()
@@ -2406,6 +2420,14 @@ int sqlite3BtreeBeginTrans(Btree *p, int wrflag){
if( rc==SQLITE_OK ){
if( p->inTrans==TRANS_NONE ){
pBt->nTransaction++;
#ifndef SQLITE_OMIT_SHARED_CACHE
if( p->sharable ){
assert( p->lock.pBtree==p && p->lock.iTable==1 );
p->lock.eLock = READ_LOCK;
p->lock.pNext = pBt->pLock;
pBt->pLock = &p->lock;
}
#endif
}
p->inTrans = (wrflag?TRANS_WRITE:TRANS_READ);
if( p->inTrans>pBt->inTransaction ){
@@ -3188,17 +3210,11 @@ static int btreeCursor(
assert( sqlite3BtreeHoldsMutex(p) );
assert( wrFlag==0 || wrFlag==1 );
/* The following assert statements verify that if this is a sharable b-tree
** database, the connection is holding the required table locks, and that
** no other connection has any open cursor that conflicts with this lock.
**
** The exception to this is read-only cursors open on the schema table.
** Such a cursor is opened without a lock while reading the database
** schema. This is safe because BtShared.mutex is held for the entire
** lifetime of this cursor. */
assert( (iTable==1 && wrFlag==0)
|| hasSharedCacheTableLock(p, iTable, pKeyInfo!=0, wrFlag+1)
);
/* The following assert statements verify that if this is a sharable
** b-tree database, the connection is holding the required table locks,
** and that no other connection has any open cursor that conflicts with
** this lock. */
assert( hasSharedCacheTableLock(p, iTable, pKeyInfo!=0, wrFlag+1) );
assert( wrFlag==0 || !hasReadConflicts(p, iTable) );
if( NEVER(wrFlag && pBt->readOnly) ){
@@ -6663,10 +6679,7 @@ static int btreeCreateTable(Btree *p, int *piTable, int flags){
** root page of the new table should go. meta[3] is the largest root-page
** created so far, so the new root-page is (meta[3]+1).
*/
rc = sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &pgnoRoot);
if( rc!=SQLITE_OK ){
return rc;
}
sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &pgnoRoot);
pgnoRoot++;
/* The new root-page may not be allocated on a pointer-map page, or the
@@ -6901,11 +6914,7 @@ static int btreeDropTable(Btree *p, Pgno iTable, int *piMoved){
#else
if( pBt->autoVacuum ){
Pgno maxRootPgno;
rc = sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &maxRootPgno);
if( rc!=SQLITE_OK ){
releasePage(pPage);
return rc;
}
sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &maxRootPgno);
if( iTable==maxRootPgno ){
/* If the table being dropped is the table with the largest root-page
@@ -6981,6 +6990,9 @@ int sqlite3BtreeDropTable(Btree *p, int iTable, int *piMoved){
/*
** This function may only be called if the b-tree connection already
** has a read or write transaction open on the database.
**
** Read the meta-information out of a database file. Meta[0]
** is the number of free pages currently in the database. Meta[1]
** through meta[15] are available for use by higher layers. Meta[0]
@@ -6990,71 +7002,24 @@ int sqlite3BtreeDropTable(Btree *p, int iTable, int *piMoved){
** layer (and the SetCookie and ReadCookie opcodes) the number of
** free pages is not visible. So Cookie[0] is the same as Meta[1].
*/
int sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){
DbPage *pDbPage = 0;
int rc;
unsigned char *pP1;
void sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){
BtShared *pBt = p->pBt;
sqlite3BtreeEnter(p);
/* Reading a meta-data value requires a read-lock on page 1 (and hence
** the sqlite_master table. We grab this lock regardless of whether or
** not the SQLITE_ReadUncommitted flag is set (the table rooted at page
** 1 is treated as a special case by querySharedCacheTableLock()
** and setSharedCacheTableLock()).
*/
rc = querySharedCacheTableLock(p, 1, READ_LOCK);
if( rc!=SQLITE_OK ){
sqlite3BtreeLeave(p);
return rc;
}
assert( p->inTrans>TRANS_NONE );
assert( SQLITE_OK==querySharedCacheTableLock(p, 1, READ_LOCK) );
assert( pBt->pPage1 );
assert( idx>=0 && idx<=15 );
if( pBt->pPage1 ){
/* The b-tree is already holding a reference to page 1 of the database
** file. In this case the required meta-data value can be read directly
** from the page data of this reference. This is slightly faster than
** requesting a new reference from the pager layer.
*/
pP1 = (unsigned char *)pBt->pPage1->aData;
}else{
/* The b-tree does not have a reference to page 1 of the database file.
** Obtain one from the pager layer.
*/
rc = sqlite3PagerGet(pBt->pPager, 1, &pDbPage);
if( rc ){
sqlite3BtreeLeave(p);
return rc;
}
pP1 = (unsigned char *)sqlite3PagerGetData(pDbPage);
}
*pMeta = get4byte(&pP1[36 + idx*4]);
/* If the b-tree is not holding a reference to page 1, then one was
** requested from the pager layer in the above block. Release it now.
*/
if( !pBt->pPage1 ){
sqlite3PagerUnref(pDbPage);
}
*pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]);
/* If autovacuumed is disabled in this build but we are trying to
** access an autovacuumed database, then make the database readonly.
*/
/* If auto-vacuum is disabled in this build and this is an auto-vacuum
** database, mark the database as read-only. */
#ifdef SQLITE_OMIT_AUTOVACUUM
if( idx==BTREE_LARGEST_ROOT_PAGE && *pMeta>0 ) pBt->readOnly = 1;
#endif
/* If there is currently an open transaction, grab a read-lock
** on page 1 of the database file. This is done to make sure that
** no other connection can modify the meta value just read from
** the database until the transaction is concluded.
*/
if( p->inTrans>0 ){
rc = setSharedCacheTableLock(p, 1, READ_LOCK);
}
sqlite3BtreeLeave(p);
return rc;
}
/*
@@ -7740,10 +7705,12 @@ int sqlite3BtreeSchemaLocked(Btree *p){
*/
int sqlite3BtreeLockTable(Btree *p, int iTab, u8 isWriteLock){
int rc = SQLITE_OK;
assert( p->inTrans!=TRANS_NONE );
if( p->sharable ){
u8 lockType = READ_LOCK + isWriteLock;
assert( READ_LOCK+1==WRITE_LOCK );
assert( isWriteLock==0 || isWriteLock==1 );
sqlite3BtreeEnter(p);
rc = querySharedCacheTableLock(p, iTab, lockType);
if( rc==SQLITE_OK ){
+4 -4
View File
@@ -13,7 +13,7 @@
** subsystem. See comments in the source code for a detailed description
** of what each interface routine does.
**
** @(#) $Id: btree.h,v 1.116 2009/06/03 11:25:07 danielk1977 Exp $
** @(#) $Id: btree.h,v 1.117 2009/07/02 07:47:33 danielk1977 Exp $
*/
#ifndef _BTREE_H_
#define _BTREE_H_
@@ -97,8 +97,8 @@ int sqlite3BtreeIsInTrans(Btree*);
int sqlite3BtreeIsInReadTrans(Btree*);
int sqlite3BtreeIsInBackup(Btree*);
void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
int sqlite3BtreeSchemaLocked(Btree *);
int sqlite3BtreeLockTable(Btree *, int, u8);
int sqlite3BtreeSchemaLocked(Btree *pBtree);
int sqlite3BtreeLockTable(Btree *pBtree, int iTab, u8 isWriteLock);
int sqlite3BtreeSavepoint(Btree *, int, int);
const char *sqlite3BtreeGetFilename(Btree *);
@@ -118,7 +118,7 @@ int sqlite3BtreeDropTable(Btree*, int, int*);
int sqlite3BtreeClearTable(Btree*, int, int*);
void sqlite3BtreeTripAllCursors(Btree*, int);
int sqlite3BtreeGetMeta(Btree*, int idx, u32 *pValue);
void sqlite3BtreeGetMeta(Btree *pBtree, int idx, u32 *pValue);
int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
/*
+22 -19
View File
@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btreeInt.h,v 1.49 2009/06/24 05:40:34 danielk1977 Exp $
** $Id: btreeInt.h,v 1.50 2009/07/02 07:47:33 danielk1977 Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
@@ -302,6 +302,24 @@ struct MemPage {
*/
#define EXTRA_SIZE sizeof(MemPage)
/*
** A linked list of the following structures is stored at BtShared.pLock.
** Locks are added (or upgraded from READ_LOCK to WRITE_LOCK) when a cursor
** is opened on the table with root page BtShared.iTable. Locks are removed
** from this list when a transaction is committed or rolled back, or when
** a btree handle is closed.
*/
struct BtLock {
Btree *pBtree; /* Btree handle holding this lock */
Pgno iTable; /* Root page of table */
u8 eLock; /* READ_LOCK or WRITE_LOCK */
BtLock *pNext; /* Next in BtShared.pLock list */
};
/* Candidate values for BtLock.eLock */
#define READ_LOCK 1
#define WRITE_LOCK 2
/* A Btree handle
**
** A database connection contains a pointer to an instance of
@@ -333,6 +351,9 @@ struct Btree {
int nBackup; /* Number of backup operations reading this btree */
Btree *pNext; /* List of other sharable Btrees from the same db */
Btree *pPrev; /* Back pointer of the same list */
#ifndef SQLITE_OMIT_SHARED_CACHE
BtLock lock; /* Object used to lock page 1 */
#endif
};
/*
@@ -516,24 +537,6 @@ struct BtCursor {
*/
# define PENDING_BYTE_PAGE(pBt) PAGER_MJ_PGNO(pBt)
/*
** A linked list of the following structures is stored at BtShared.pLock.
** Locks are added (or upgraded from READ_LOCK to WRITE_LOCK) when a cursor
** is opened on the table with root page BtShared.iTable. Locks are removed
** from this list when a transaction is committed or rolled back, or when
** a btree handle is closed.
*/
struct BtLock {
Btree *pBtree; /* Btree handle holding this lock */
Pgno iTable; /* Root page of table */
u8 eLock; /* READ_LOCK or WRITE_LOCK */
BtLock *pNext; /* Next in BtShared.pLock list */
};
/* Candidate values for BtLock.eLock */
#define READ_LOCK 1
#define WRITE_LOCK 2
/*
** These macros define the location of the pointer-map entry for a
** database page. The first argument to each is the number of usable
+12 -8
View File
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.213 2009/06/19 14:06:03 drh Exp $
** $Id: pragma.c,v 1.214 2009/07/02 07:47:33 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -318,12 +318,13 @@ void sqlite3Pragma(
*/
if( sqlite3StrICmp(zLeft,"default_cache_size")==0 ){
static const VdbeOpList getCacheSize[] = {
{ OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 0 */
{ OP_IfPos, 1, 6, 0},
{ OP_Transaction, 0, 0, 0}, /* 0 */
{ OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */
{ OP_IfPos, 1, 7, 0},
{ OP_Integer, 0, 2, 0},
{ OP_Subtract, 1, 2, 1},
{ OP_IfPos, 1, 6, 0},
{ OP_Integer, 0, 1, 0}, /* 5 */
{ OP_IfPos, 1, 7, 0},
{ OP_Integer, 0, 1, 0}, /* 6 */
{ OP_ResultRow, 1, 1, 0},
};
int addr;
@@ -335,7 +336,8 @@ void sqlite3Pragma(
pParse->nMem += 2;
addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
sqlite3VdbeChangeP1(v, addr, iDb);
sqlite3VdbeChangeP1(v, addr+5, SQLITE_DEFAULT_CACHE_SIZE);
sqlite3VdbeChangeP1(v, addr+1, iDb);
sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
}else{
int size = atoi(zRight);
if( size<0 ) size = -size;
@@ -1302,12 +1304,14 @@ void sqlite3Pragma(
}else{
/* Read the specified cookie value */
static const VdbeOpList readCookie[] = {
{ OP_ReadCookie, 0, 1, 0}, /* 0 */
{ OP_Transaction, 0, 0, 0}, /* 0 */
{ OP_ReadCookie, 0, 1, 0}, /* 1 */
{ OP_ResultRow, 1, 1, 0}
};
int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie);
sqlite3VdbeChangeP1(v, addr, iDb);
sqlite3VdbeChangeP3(v, addr, iCookie);
sqlite3VdbeChangeP1(v, addr+1, iDb);
sqlite3VdbeChangeP3(v, addr+1, iCookie);
sqlite3VdbeSetNumCols(v, 1);
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
}
+60 -23
View File
@@ -13,7 +13,7 @@
** interface, and routines that contribute to loading the database schema
** from disk.
**
** $Id: prepare.c,v 1.125 2009/06/25 11:50:21 drh Exp $
** $Id: prepare.c,v 1.126 2009/07/02 07:47:33 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -128,7 +128,6 @@ int sqlite3InitCallback(void *pInit, int argc, char **argv, char **NotUsed){
static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
int rc;
int i;
BtCursor *curMain;
int size;
Table *pTab;
Db *pDb;
@@ -137,6 +136,7 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
InitData initData;
char const *zMasterSchema;
char const *zMasterName = SCHEMA_TABLE(iDb);
int openedTransaction;
/*
** The master database table has a structure like this
@@ -210,14 +210,21 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
}
return SQLITE_OK;
}
curMain = sqlite3MallocZero(sqlite3BtreeCursorSize());
if( !curMain ){
rc = SQLITE_NOMEM;
goto error_out;
}
/* If there is not already a read-only (or read-write) transaction opened
** on the b-tree database, open one now. If a transaction is opened, it
** will be closed before this function returns. */
sqlite3BtreeEnter(pDb->pBt);
rc = sqlite3BtreeCursor(pDb->pBt, MASTER_ROOT, 0, 0, curMain);
if( rc==SQLITE_EMPTY ) rc = SQLITE_OK;
if( !sqlite3BtreeIsInReadTrans(pDb->pBt) ){
rc = sqlite3BtreeBeginTrans(pDb->pBt, 0);
if( rc!=SQLITE_OK ){
sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc));
goto initone_error_out;
}
openedTransaction = 1;
}else{
openedTransaction = 0;
}
/* Get the database meta information.
**
@@ -236,12 +243,8 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
** Note: The #defined SQLITE_UTF* symbols in sqliteInt.h correspond to
** the possible values of meta[4].
*/
for(i=0; rc==SQLITE_OK && i<ArraySize(meta); i++){
rc = sqlite3BtreeGetMeta(pDb->pBt, i+1, (u32 *)&meta[i]);
}
if( rc ){
sqlite3SetString(pzErrMsg, db, "%s", sqlite3ErrStr(rc));
goto initone_error_out;
for(i=0; i<ArraySize(meta); i++){
sqlite3BtreeGetMeta(pDb->pBt, i+1, (u32 *)&meta[i]);
}
pDb->pSchema->schema_cookie = meta[BTREE_SCHEMA_VERSION-1];
@@ -356,8 +359,9 @@ static int sqlite3InitOne(sqlite3 *db, int iDb, char **pzErrMsg){
** before that point, jump to error_out.
*/
initone_error_out:
sqlite3BtreeCloseCursor(curMain);
sqlite3_free(curMain);
if( openedTransaction ){
sqlite3BtreeCommit(pDb->pBt);
}
sqlite3BtreeLeave(pDb->pBt);
error_out:
@@ -437,13 +441,46 @@ int sqlite3ReadSchema(Parse *pParse){
** Check schema cookies in all databases. If any cookie is out
** of date, return 0. If all schema cookies are current, return 1.
*/
static int schemaIsValid(sqlite3 *db){
static void schemaIsValid(Parse *pParse){
sqlite3 *db = pParse->db;
int iDb;
int rc;
BtCursor *curTemp;
int cookie;
int allOk = 1;
assert( pParse->checkSchema );
assert( sqlite3_mutex_held(db->mutex) );
for(iDb=0; iDb<db->nDb; iDb++){
int openedTransaction = 0; /* True if a transaction is opened */
Btree *pBt = db->aDb[iDb].pBt; /* Btree database to read cookie from */
if( pBt==0 ) continue;
/* If there is not already a read-only (or read-write) transaction opened
** on the b-tree database, open one now. If a transaction is opened, it
** will be closed immediately after reading the meta-value. */
if( !sqlite3BtreeIsInReadTrans(pBt) ){
rc = sqlite3BtreeBeginTrans(pBt, 0);
if( NEVER(rc==SQLITE_NOMEM) || rc==SQLITE_IOERR_NOMEM ){
db->mallocFailed = 1;
}
if( rc!=SQLITE_OK ) return;
openedTransaction = 1;
}
/* Read the schema cookie from the database. If it does not match the
** value stored as part of the in the in-memory schema representation,
** set Parse.rc to SQLITE_SCHEMA. */
sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&cookie);
if( cookie!=db->aDb[iDb].pSchema->schema_cookie ){
pParse->rc = SQLITE_SCHEMA;
}
/* Close the transaction, if one was opened. */
if( openedTransaction ){
sqlite3BtreeCommit(pBt);
}
}
#if 0
curTemp = (BtCursor *)sqlite3Malloc(sqlite3BtreeCursorSize());
if( curTemp ){
assert( sqlite3_mutex_held(db->mutex) );
@@ -470,8 +507,8 @@ static int schemaIsValid(sqlite3 *db){
allOk = 0;
db->mallocFailed = 1;
}
return allOk;
#endif
}
/*
@@ -604,8 +641,8 @@ static int sqlite3Prepare(
pParse->rc = SQLITE_NOMEM;
}
if( pParse->rc==SQLITE_DONE ) pParse->rc = SQLITE_OK;
if( pParse->checkSchema && !schemaIsValid(db) ){
pParse->rc = SQLITE_SCHEMA;
if( pParse->checkSchema ){
schemaIsValid(pParse);
}
if( pParse->rc==SQLITE_SCHEMA ){
sqlite3ResetInternalSchema(db, 0);
+2 -6
View File
@@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test3.c,v 1.105 2009/06/29 06:00:37 danielk1977 Exp $
** $Id: test3.c,v 1.106 2009/07/02 07:47:33 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "btreeInt.h"
@@ -425,12 +425,8 @@ static int btree_get_meta(
char zBuf[30];
u32 v;
sqlite3BtreeEnter(pBt);
rc = sqlite3BtreeGetMeta(pBt, i, &v);
sqlite3BtreeGetMeta(pBt, i, &v);
sqlite3BtreeLeave(pBt);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
}
sqlite3_snprintf(sizeof(zBuf), zBuf,"%d",v);
Tcl_AppendElement(interp, zBuf);
}
+2 -3
View File
@@ -14,7 +14,7 @@
** Most of the code in this file may be omitted by defining the
** SQLITE_OMIT_VACUUM macro.
**
** $Id: vacuum.c,v 1.90 2009/06/03 11:25:07 danielk1977 Exp $
** $Id: vacuum.c,v 1.91 2009/07/02 07:47:33 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
@@ -254,8 +254,7 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
for(i=0; i<ArraySize(aCopy); i+=2){
/* GetMeta() and UpdateMeta() cannot fail in this context because
** we already have page 1 loaded into cache and marked dirty. */
rc = sqlite3BtreeGetMeta(pMain, aCopy[i], &meta);
if( NEVER(rc!=SQLITE_OK) ) goto end_of_vacuum;
sqlite3BtreeGetMeta(pMain, aCopy[i], &meta);
rc = sqlite3BtreeUpdateMeta(pTemp, aCopy[i], meta+aCopy[i+1]);
if( NEVER(rc!=SQLITE_OK) ) goto end_of_vacuum;
}
+4 -5
View File
@@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
** $Id: vdbe.c,v 1.867 2009/06/29 06:00:37 danielk1977 Exp $
** $Id: vdbe.c,v 1.868 2009/07/02 07:47:33 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "vdbeInt.h"
@@ -2759,7 +2759,7 @@ case OP_ReadCookie: { /* out2-prerelease */
assert( db->aDb[iDb].pBt!=0 );
assert( (p->btreeMask & (1<<iDb))!=0 );
rc = sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta);
pOut->u.i = iMeta;
MemSetTypeFlag(pOut, MEM_Int);
break;
@@ -2824,12 +2824,11 @@ case OP_VerifyCookie: {
assert( (p->btreeMask & (1<<pOp->p1))!=0 );
pBt = db->aDb[pOp->p1].pBt;
if( pBt ){
rc = sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta);
sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta);
}else{
rc = SQLITE_OK;
iMeta = 0;
}
if( rc==SQLITE_OK && iMeta!=pOp->p2 ){
if( iMeta!=pOp->p2 ){
sqlite3DbFree(db, p->zErrMsg);
p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
/* If the schema-cookie from the database file matches the cookie
+1 -1
View File
@@ -12,7 +12,7 @@
**
** This file contains code used to implement incremental BLOB I/O.
**
** $Id: vdbeblob.c,v 1.34 2009/06/29 06:00:37 danielk1977 Exp $
** $Id: vdbeblob.c,v 1.35 2009/07/02 07:47:33 danielk1977 Exp $
*/
#include "sqliteInt.h"