diff options
author | drh <drh@noemail.net> | 2014-11-18 21:20:57 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2014-11-18 21:20:57 +0000 |
commit | 04e8a5866948996e4dd1540a9a736d00609c27e8 (patch) | |
tree | fcf53188c46e77ce3d90818bc17e118298813b18 /src/backup.c | |
parent | ca3e10ea37c4808fa84063f06b02229801b28cc0 (diff) | |
parent | 64b600ff13d4bac1d459cf54b649b45e520aba4c (diff) | |
download | sqlite-04e8a5866948996e4dd1540a9a736d00609c27e8.tar.gz sqlite-04e8a5866948996e4dd1540a9a736d00609c27e8.zip |
Merge recent trunk enhancements, including the read-after-ROLLBACK change
and the addition of sqlite3_stmt_scanstatus() support, as well as various
minor bug fixes.
FossilOrigin-Name: f09055f3c4348264c7336f90646375f0d98b061e
Diffstat (limited to 'src/backup.c')
-rw-r--r-- | src/backup.c | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/backup.c b/src/backup.c index da4303e5f..e3f869035 100644 --- a/src/backup.c +++ b/src/backup.c @@ -123,6 +123,20 @@ static int setDestPgsz(sqlite3_backup *p){ } /* +** Check that there is no open read-transaction on the b-tree passed as the +** second argument. If there is not, return SQLITE_OK. Otherwise, if there +** is an open read-transaction, return SQLITE_ERROR and leave an error +** message in database handle db. +*/ +static int checkReadTransaction(sqlite3 *db, Btree *p){ + if( sqlite3BtreeIsInReadTrans(p) ){ + sqlite3ErrorWithMsg(db, SQLITE_ERROR, "destination database is in use"); + return SQLITE_ERROR; + } + return SQLITE_OK; +} + +/* ** Create an sqlite3_backup process to copy the contents of zSrcDb from ** connection handle pSrcDb to zDestDb in pDestDb. If successful, return ** a pointer to the new sqlite3_backup object. @@ -181,12 +195,15 @@ sqlite3_backup *sqlite3_backup_init( p->iNext = 1; p->isAttached = 0; - if( 0==p->pSrc || 0==p->pDest || setDestPgsz(p)==SQLITE_NOMEM ){ + if( 0==p->pSrc || 0==p->pDest + || setDestPgsz(p)==SQLITE_NOMEM + || checkReadTransaction(pDestDb, p->pDest)!=SQLITE_OK + ){ /* One (or both) of the named databases did not exist or an OOM - ** error was hit. The error has already been written into the - ** pDestDb handle. All that is left to do here is free the - ** sqlite3_backup structure. - */ + ** error was hit. Or there is a transaction open on the destination + ** database. The error has already been written into the pDestDb + ** handle. All that is left to do here is free the sqlite3_backup + ** structure. */ sqlite3_free(p); p = 0; } @@ -607,7 +624,7 @@ int sqlite3_backup_finish(sqlite3_backup *p){ } /* If a transaction is still open on the Btree, roll it back. */ - sqlite3BtreeRollback(p->pDest, SQLITE_OK); + sqlite3BtreeRollback(p->pDest, SQLITE_OK, 0); /* Set the error code of the destination database handle. */ rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc; |