Allow nested database transactions within the same wait level and disallow database access from higher levels
This commit is contained in:
parent
3c02f0b0e6
commit
16a3d3f1ed
|
@ -65,6 +65,7 @@ Zotero.DBConnection = function(dbName) {
|
||||||
this._lastTransactionDate = null;
|
this._lastTransactionDate = null;
|
||||||
this._transactionRollback = null;
|
this._transactionRollback = null;
|
||||||
this._transactionNestingLevel = 0;
|
this._transactionNestingLevel = 0;
|
||||||
|
this._transactionWaitLevel = 0;
|
||||||
this._callbacks = { begin: [], commit: [], rollback: [] };
|
this._callbacks = { begin: [], commit: [], rollback: [] };
|
||||||
this._dbIsCorrupt = null
|
this._dbIsCorrupt = null
|
||||||
this._self = this;
|
this._self = this;
|
||||||
|
@ -223,8 +224,8 @@ Zotero.DBConnection.prototype.getStatement = function (sql, params, checkParams)
|
||||||
var db = this._getDBConnection();
|
var db = this._getDBConnection();
|
||||||
|
|
||||||
// TODO: limit to Zotero.DB, not all Zotero.DBConnections?
|
// TODO: limit to Zotero.DB, not all Zotero.DBConnections?
|
||||||
if (db.transactionInProgress && Zotero.waiting) {
|
if (db.transactionInProgress && Zotero.waiting > this._transactionWaitLevel) {
|
||||||
throw ("Cannot access database layer during active Zotero.wait() if a transaction is open");
|
throw ("Cannot access database layer from a higher wait level if a transaction is open");
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, determine the type of query using first word
|
// First, determine the type of query using first word
|
||||||
|
@ -426,8 +427,8 @@ Zotero.DBConnection.prototype.beginTransaction = function () {
|
||||||
|
|
||||||
if (db.transactionInProgress) {
|
if (db.transactionInProgress) {
|
||||||
// TODO: limit to Zotero.DB, not all Zotero.DBConnections?
|
// TODO: limit to Zotero.DB, not all Zotero.DBConnections?
|
||||||
if (Zotero.waiting) {
|
if (Zotero.waiting != this._transactionWaitLevel) {
|
||||||
var msg = "Cannot access database layer during active Zotero.wait() if a transaction is in progress";
|
var msg = "Cannot start a DB transaction from a different wait level";
|
||||||
Zotero.debug(msg, 2);
|
Zotero.debug(msg, 2);
|
||||||
throw (msg);
|
throw (msg);
|
||||||
}
|
}
|
||||||
|
@ -437,6 +438,8 @@ Zotero.DBConnection.prototype.beginTransaction = function () {
|
||||||
+ this._transactionNestingLevel, 5);
|
+ this._transactionNestingLevel, 5);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
this._transactionWaitLevel = Zotero.waiting;
|
||||||
|
|
||||||
this._debug('Beginning DB transaction', 5);
|
this._debug('Beginning DB transaction', 5);
|
||||||
db.beginTransaction();
|
db.beginTransaction();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user