aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordan <dan@noemail.net>2010-08-02 10:47:05 +0000
committerdan <dan@noemail.net>2010-08-02 10:47:05 +0000
commita550f2decd6c9a7d4fa309d2272b4ea0ec195a3c (patch)
tree4c4bffb39c6b592bac7fc9cbd0999b61961a14dc /src
parent1c320a4366c9a1da926de879fc14f0838021b044 (diff)
downloadsqlite-a550f2decd6c9a7d4fa309d2272b4ea0ec195a3c.tar.gz
sqlite-a550f2decd6c9a7d4fa309d2272b4ea0ec195a3c.zip
In shared-cache mode, do not allow one connection to checkpoint a database while a second connection is reading or writing the same shared-cache.
FossilOrigin-Name: e75b52d156905ce16bedb94f65c01a4640bdfa75
Diffstat (limited to 'src')
-rw-r--r--src/btree.c23
-rw-r--r--src/btree.h4
-rw-r--r--src/main.c11
3 files changed, 28 insertions, 10 deletions
diff --git a/src/btree.c b/src/btree.c
index d07e4c3d6..c03d3c92b 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -7848,6 +7848,29 @@ int sqlite3BtreeIsInTrans(Btree *p){
return (p && (p->inTrans==TRANS_WRITE));
}
+#ifndef SQLITE_OMIT_WAL
+/*
+** Run a checkpoint on the Btree passed as the first argument.
+**
+** Return SQLITE_LOCKED if this or any other connection has an open
+** transaction on the shared-cache the argument Btree is connected to.
+*/
+int sqlite3BtreeCheckpoint(Btree *p){
+ int rc = SQLITE_OK;
+ if( p ){
+ BtShared *pBt = p->pBt;
+ sqlite3BtreeEnter(p);
+ if( pBt->inTransaction!=TRANS_NONE ){
+ rc = SQLITE_LOCKED;
+ }else{
+ rc = sqlite3PagerCheckpoint(pBt->pPager);
+ }
+ sqlite3BtreeLeave(p);
+ }
+ return rc;
+}
+#endif
+
/*
** Return non-zero if a read (or write) transaction is active.
*/
diff --git a/src/btree.h b/src/btree.h
index 584b46338..c989307aa 100644
--- a/src/btree.h
+++ b/src/btree.h
@@ -201,6 +201,10 @@ int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
void sqlite3BtreeCursorList(Btree*);
#endif
+#ifndef SQLITE_OMIT_WAL
+ int sqlite3BtreeCheckpoint(Btree*);
+#endif
+
/*
** If we are not using shared cache, then there is no need to
** use mutexes to access the BtShared structures. So make the
diff --git a/src/main.c b/src/main.c
index c3828d5d9..b233c8473 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1308,16 +1308,7 @@ int sqlite3Checkpoint(sqlite3 *db, int iDb){
for(i=0; i<db->nDb && rc==SQLITE_OK; i++){
if( i==iDb || iDb==SQLITE_MAX_ATTACHED ){
- Btree *pBt = db->aDb[i].pBt;
- if( pBt ){
- if( sqlite3BtreeIsInReadTrans(pBt) ){
- rc = SQLITE_LOCKED;
- }else{
- sqlite3BtreeEnter(pBt);
- rc = sqlite3PagerCheckpoint(sqlite3BtreePager(pBt));
- sqlite3BtreeLeave(pBt);
- }
- }
+ rc = sqlite3BtreeCheckpoint(db->aDb[i].pBt);
}
}