Always try to commit open transactions at shutdown

This commit is contained in:
Dan Stillman 2006-10-24 18:22:56 +00:00
parent 0809408d4b
commit 51664bc51a
2 changed files with 25 additions and 0 deletions

View File

@ -37,6 +37,7 @@ Zotero.DB = new function(){
this.commitTransaction = commitTransaction;
this.rollbackTransaction = rollbackTransaction;
this.transactionInProgress = transactionInProgress;
this.commitAllTransactions = commitAllTransactions;
this.tableExists = tableExists;
this.getColumns = getColumns;
this.getColumnHash = getColumnHash;
@ -345,6 +346,24 @@ Zotero.DB = new function(){
}
/**
* Safety function used on shutdown to make sure we're not stuck in the
* middle of a transaction
*/
function commitAllTransactions(){
if (transactionInProgress()){
var level = _transactionNestingLevel;
_transactionNestingLevel = 0;
try {
Zotero.DB.commitTransaction();
}
catch (e){}
return level ? level : true;
}
return false;
}
function tableExists(table){
return _getDBConnection().tableExists(table);
}

View File

@ -137,6 +137,12 @@ var Zotero = new function(){
return false;
}
var level = Zotero.DB.commitAllTransactions();
if (level){
level = level===true ? '0' : level;
Zotero.debug("A transaction was still open! (level " + level + ")", 2);
}
_shutdown = true;
Zotero.backupDatabase();