From 51664bc51a9c77f3489c50470c6b560b55b309c1 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 24 Oct 2006 18:22:56 +0000 Subject: [PATCH] Always try to commit open transactions at shutdown --- chrome/content/zotero/xpcom/db.js | 19 +++++++++++++++++++ chrome/content/zotero/xpcom/zotero.js | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/chrome/content/zotero/xpcom/db.js b/chrome/content/zotero/xpcom/db.js index a2846204f..4eb351ed2 100644 --- a/chrome/content/zotero/xpcom/db.js +++ b/chrome/content/zotero/xpcom/db.js @@ -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); } diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 0830f0d8a..a20746221 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -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();