commit 31502de08f8c9cd5a6e3b5c81bdd5ec19391d6c8
parent f5896dbb8dbbf61d2bb57a6b058fb80d3be61a7b
Author: Dan Stillman <dstillman@zotero.org>
Date: Sun, 10 Aug 2014 02:10:03 -0400
Zotero.DB updates
- Fix ES5 generator in executeFile()
- Remove deferred in executeAsyncStatement()
- Remove obsolete properties and wait level check
Diffstat:
1 file changed, 18 insertions(+), 19 deletions(-)
diff --git a/chrome/content/zotero/xpcom/db.js b/chrome/content/zotero/xpcom/db.js
@@ -70,13 +70,11 @@ Zotero.DBConnection = function(dbName) {
// Private members
this._dbName = dbName;
this._shutdown = false;
- this._connection = null;
this._connectionAsync = null;
this._transactionDate = null;
this._lastTransactionDate = null;
this._transactionRollback = false;
this._transactionNestingLevel = 0;
- this._transactionWaitLevel = 0;
this._asyncTransactionNestingLevel = 0;
this._callbacks = {
begin: [],
@@ -116,11 +114,6 @@ Zotero.DBConnection.prototype.getAsyncStatement = Zotero.Promise.coroutine(funct
var conn = yield this._getConnectionAsync();
conn = conn._connection;
- // TODO: limit to Zotero.DB, not all Zotero.DBConnections?
- if (conn.transactionInProgress && Zotero.waiting > this._transactionWaitLevel) {
- throw ("Cannot access database layer from a higher wait level if a transaction is open");
- }
-
try {
this._debug(sql, 5);
return conn.createAsyncStatement(sql);
@@ -258,30 +251,36 @@ Zotero.DBConnection.prototype.parseQueryAndParams = function (sql, params, optio
*
* Warning: This will freeze if used with a write statement within executeTransaction()!
*
- * @param {mozIStorageAsyncStatement} statement
- * @return {Promise} Resolved on completion, rejected with a reason on error,
- * and progressed with a mozIStorageRow for SELECT queries
+ * @param {mozIStorageAsyncStatement} statement - Statement to run
+ * @param {Function} [progressHandler] - Function to pass each available row to for SELECT queries
+ * @return {Promise} - Resolved on completion, rejected with a reason on error
*/
-Zotero.DBConnection.prototype.executeAsyncStatement = function (statement) {
- var deferred = Zotero.Promise.defer();
+Zotero.DBConnection.prototype.executeAsyncStatement = Zotero.Promise.method(function (statement, progressHandler) {
+ var resolve;
+ var reject;
statement.executeAsync({
handleResult: function (resultSet) {
- deferred.progress(resultSet.getNextRow());
+ if (progressHandler) {
+ progressHandler(resultSet.getNextRow());
+ }
},
handleError: function (e) {
- deferred.reject(e);
+ reject(e);
},
handleCompletion: function (reason) {
if (reason != Components.interfaces.mozIStorageStatementCallback.REASON_FINISHED) {
- deferred.reject(reason);
+ reject(reason);
}
- deferred.resolve();
+ resolve();
}
});
- return deferred.promise;
-}
+ return new Zotero.Promise(function () {
+ resolve = arguments[0];
+ reject = arguments[1];
+ });
+});
/*
@@ -859,7 +858,7 @@ Zotero.DBConnection.prototype.executeSQLFile = function (sql) {
var statements = sql.split(";")
.map(function (x) x.replace(/TEMPSEMI/g, ";"));
- return this.executeTransaction(function () {
+ return this.executeTransaction(function* () {
var statement;
while (statement = statements.shift()) {
yield Zotero.DB.queryAsync(statement);