mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-05 15:55:57 +03:00
Add support for the sqlite3_txn_state() interface.
FossilOrigin-Name: ad195e3dd89d0f33b50070c18fb8f43c4eb24162515dfdd7c04d9e7d96b902a2
This commit is contained in:
42
src/main.c
42
src/main.c
@@ -897,7 +897,7 @@ int sqlite3_db_cacheflush(sqlite3 *db){
|
||||
sqlite3BtreeEnterAll(db);
|
||||
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
|
||||
Btree *pBt = db->aDb[i].pBt;
|
||||
if( pBt && sqlite3BtreeIsInTrans(pBt) ){
|
||||
if( pBt && sqlite3BtreeTxnState(pBt)==SQLITE_TXN_WRITE ){
|
||||
Pager *pPager = sqlite3BtreePager(pBt);
|
||||
rc = sqlite3PagerFlush(pPager);
|
||||
if( rc==SQLITE_BUSY ){
|
||||
@@ -1241,6 +1241,36 @@ static int sqlite3Close(sqlite3 *db, int forceZombie){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the transaction state for a single databse, or the maximum
|
||||
** transaction state over all attached databases if zSchema is null.
|
||||
*/
|
||||
int sqlite3_txn_state(sqlite3 *db, const char *zSchema){
|
||||
int iDb, nDb;
|
||||
int iTxn = -1;
|
||||
#ifdef SQLITE_ENABLE_API_ARMOR
|
||||
if( !sqlite3SafetyCheckOk(db) ){
|
||||
(void)SQLITE_MISUSE_BKPT;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
if( zSchema ){
|
||||
nDb = iDb = sqlite3FindDbName(db, zSchema);
|
||||
if( iDb<0 ) nDb--;
|
||||
}else{
|
||||
iDb = 0;
|
||||
nDb = db->nDb-1;
|
||||
}
|
||||
for(; iDb<=nDb; iDb++){
|
||||
Btree *pBt = db->aDb[iDb].pBt;
|
||||
int x = pBt!=0 ? sqlite3BtreeTxnState(pBt) : SQLITE_TXN_NONE;
|
||||
if( x>iTxn ) iTxn = x;
|
||||
}
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
return iTxn;
|
||||
}
|
||||
|
||||
/*
|
||||
** Two variations on the public interface for closing a database
|
||||
** connection. The sqlite3_close() version returns SQLITE_BUSY and
|
||||
@@ -1401,7 +1431,7 @@ void sqlite3RollbackAll(sqlite3 *db, int tripCode){
|
||||
for(i=0; i<db->nDb; i++){
|
||||
Btree *p = db->aDb[i].pBt;
|
||||
if( p ){
|
||||
if( sqlite3BtreeIsInTrans(p) ){
|
||||
if( sqlite3BtreeTxnState(p)==SQLITE_TXN_WRITE ){
|
||||
inTrans = 1;
|
||||
}
|
||||
sqlite3BtreeRollback(p, tripCode, !schemaChange);
|
||||
@@ -4440,7 +4470,7 @@ int sqlite3_snapshot_get(
|
||||
int iDb = sqlite3FindDbName(db, zDb);
|
||||
if( iDb==0 || iDb>1 ){
|
||||
Btree *pBt = db->aDb[iDb].pBt;
|
||||
if( 0==sqlite3BtreeIsInTrans(pBt) ){
|
||||
if( SQLITE_TXN_WRITE!=sqlite3BtreeTxnState(pBt) ){
|
||||
rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3PagerSnapshotGet(sqlite3BtreePager(pBt), ppSnapshot);
|
||||
@@ -4476,10 +4506,10 @@ int sqlite3_snapshot_open(
|
||||
iDb = sqlite3FindDbName(db, zDb);
|
||||
if( iDb==0 || iDb>1 ){
|
||||
Btree *pBt = db->aDb[iDb].pBt;
|
||||
if( sqlite3BtreeIsInTrans(pBt)==0 ){
|
||||
if( sqlite3BtreeTxnState(pBt)!=SQLITE_TXN_WRITE ){
|
||||
Pager *pPager = sqlite3BtreePager(pBt);
|
||||
int bUnlock = 0;
|
||||
if( sqlite3BtreeIsInReadTrans(pBt) ){
|
||||
if( sqlite3BtreeTxnState(pBt)!=SQLITE_TXN_NONE ){
|
||||
if( db->nVdbeActive==0 ){
|
||||
rc = sqlite3PagerSnapshotCheck(pPager, pSnapshot);
|
||||
if( rc==SQLITE_OK ){
|
||||
@@ -4528,7 +4558,7 @@ int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb){
|
||||
iDb = sqlite3FindDbName(db, zDb);
|
||||
if( iDb==0 || iDb>1 ){
|
||||
Btree *pBt = db->aDb[iDb].pBt;
|
||||
if( 0==sqlite3BtreeIsInReadTrans(pBt) ){
|
||||
if( SQLITE_TXN_NONE==sqlite3BtreeTxnState(pBt) ){
|
||||
rc = sqlite3BtreeBeginTrans(pBt, 0, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3PagerSnapshotRecover(sqlite3BtreePager(pBt));
|
||||
|
Reference in New Issue
Block a user