From 16a3d3f1ed7f3ca469ba77126f3cfd39ad51a061 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 30 Aug 2011 01:05:12 +0000 Subject: [PATCH] Allow nested database transactions within the same wait level and disallow database access from higher levels --- chrome/content/zotero/xpcom/db.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/db.js b/chrome/content/zotero/xpcom/db.js index dd7674b2f..8e9136362 100644 --- a/chrome/content/zotero/xpcom/db.js +++ b/chrome/content/zotero/xpcom/db.js @@ -65,6 +65,7 @@ Zotero.DBConnection = function(dbName) { this._lastTransactionDate = null; this._transactionRollback = null; this._transactionNestingLevel = 0; + this._transactionWaitLevel = 0; this._callbacks = { begin: [], commit: [], rollback: [] }; this._dbIsCorrupt = null this._self = this; @@ -223,8 +224,8 @@ Zotero.DBConnection.prototype.getStatement = function (sql, params, checkParams) var db = this._getDBConnection(); // TODO: limit to Zotero.DB, not all Zotero.DBConnections? - if (db.transactionInProgress && Zotero.waiting) { - throw ("Cannot access database layer during active Zotero.wait() if a transaction is open"); + if (db.transactionInProgress && Zotero.waiting > this._transactionWaitLevel) { + throw ("Cannot access database layer from a higher wait level if a transaction is open"); } // First, determine the type of query using first word @@ -426,8 +427,8 @@ Zotero.DBConnection.prototype.beginTransaction = function () { if (db.transactionInProgress) { // TODO: limit to Zotero.DB, not all Zotero.DBConnections? - if (Zotero.waiting) { - var msg = "Cannot access database layer during active Zotero.wait() if a transaction is in progress"; + if (Zotero.waiting != this._transactionWaitLevel) { + var msg = "Cannot start a DB transaction from a different wait level"; Zotero.debug(msg, 2); throw (msg); } @@ -437,6 +438,8 @@ Zotero.DBConnection.prototype.beginTransaction = function () { + this._transactionNestingLevel, 5); } else { + this._transactionWaitLevel = Zotero.waiting; + this._debug('Beginning DB transaction', 5); db.beginTransaction();