aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authordan <dan@noemail.net>2018-08-06 17:12:36 +0000
committerdan <dan@noemail.net>2018-08-06 17:12:36 +0000
commitfa3d4c19a9ee0d87fc0fe5aec374cd2fe47af24e (patch)
treedbce774822c55a42e99ec2e32e6fcdf2a887f995 /src/main.c
parentf018fd52849be551bc00966dd3088d517b27d4a0 (diff)
downloadsqlite-fa3d4c19a9ee0d87fc0fe5aec374cd2fe47af24e.tar.gz
sqlite-fa3d4c19a9ee0d87fc0fe5aec374cd2fe47af24e.zip
Allow sqlite3_snapshot_open() to be called to change the snapshot after a
read transaction is already open on database. FossilOrigin-Name: 051ac0152048ef52723196c26ca5f2629dafb782aec1c66fc30531bf54335043
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index 4ae5c7ecd..4ea7c2077 100644
--- a/src/main.c
+++ b/src/main.c
@@ -4209,11 +4209,29 @@ int sqlite3_snapshot_open(
iDb = sqlite3FindDbName(db, zDb);
if( iDb==0 || iDb>1 ){
Btree *pBt = db->aDb[iDb].pBt;
- if( 0==sqlite3BtreeIsInReadTrans(pBt) ){
- rc = sqlite3PagerSnapshotOpen(sqlite3BtreePager(pBt), pSnapshot);
+ if( sqlite3BtreeIsInTrans(pBt)==0 ){
+ Pager *pPager = sqlite3BtreePager(pBt);
+ int bUnlock = 0;
+ if( sqlite3BtreeIsInReadTrans(pBt) ){
+ if( db->nVdbeActive==0 ){
+ rc = sqlite3PagerSnapshotCheck(pPager, pSnapshot);
+ if( rc==SQLITE_OK ){
+ bUnlock = 1;
+ rc = sqlite3BtreeCommit(pBt);
+ }
+ }
+ }else{
+ rc = SQLITE_OK;
+ }
+ if( rc==SQLITE_OK ){
+ rc = sqlite3PagerSnapshotOpen(pPager, pSnapshot);
+ }
if( rc==SQLITE_OK ){
rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
- sqlite3PagerSnapshotOpen(sqlite3BtreePager(pBt), 0);
+ sqlite3PagerSnapshotOpen(pPager, 0);
+ }
+ if( bUnlock ){
+ sqlite3PagerSnapshotUnlock(pPager);
}
}
}