From 76e998252a3637fed7e477344c4295203b1aa495 Mon Sep 17 00:00:00 2001 From: Philipp von Weitershausen Date: Mon, 9 Aug 2010 18:38:18 +0200 Subject: [PATCH] Bug 583847 - Weave should be using createAsyncStatement instead of createStatement [r=mconnor] --- services/sync/modules/engines/bookmarks.js | 18 ++++++++---------- services/sync/modules/engines/forms.js | 4 ++-- services/sync/modules/engines/history.js | 2 +- services/sync/modules/util.js | 9 +++++++++ 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/services/sync/modules/engines/bookmarks.js b/services/sync/modules/engines/bookmarks.js index 7ace9da63873..de31fa57e56a 100644 --- a/services/sync/modules/engines/bookmarks.js +++ b/services/sync/modules/engines/bookmarks.js @@ -851,10 +851,12 @@ BookmarksStore.prototype = { get _frecencyStm() { if (!this.__frecencyStm) { this._log.trace("Creating SQL statement: _frecencyStm"); - this.__frecencyStm = Svc.History.DBConnection.createStatement( + this.__frecencyStm = Utils.createStatement( + Svc.History.DBConnection, "SELECT frecency " + "FROM moz_places " + - "WHERE url = :url"); + "WHERE url = :url " + + "LIMIT 1"); } return this.__frecencyStm; }, @@ -868,14 +870,10 @@ BookmarksStore.prototype = { // Add in the bookmark's frecency if we have something if (record.bmkUri != null) { - try { - this._frecencyStm.params.url = record.bmkUri; - if (this._frecencyStm.step()) - index += this._frecencyStm.row.frecency; - } - finally { - this._frecencyStm.reset(); - } + this._frecencyStm.params.url = record.bmkUri; + let result = Utils.queryAsync(this._frecencyStm, ["frecency"]); + if (result.length) + index += result.frecency; } return index; diff --git a/services/sync/modules/engines/forms.js b/services/sync/modules/engines/forms.js index 3c5dc10a9598..2a46fc902629 100644 --- a/services/sync/modules/engines/forms.js +++ b/services/sync/modules/engines/forms.js @@ -110,7 +110,7 @@ let FormWrapper = { createStatement: function createStatement(query) { try { // Just return the statement right away if it's okay - return Svc.Form.DBConnection.createStatement(query); + return Utils.createStatement(Svc.Form.DBConnection, query); } catch(ex) { // Assume guid column must not exist yet, so add it with an index @@ -121,7 +121,7 @@ let FormWrapper = { "ON moz_formhistory (guid)"); // Try creating the query now that the column exists - return Svc.Form.DBConnection.createStatement(query); + return Utils.createStatement(Svc.Form.DBConnection, query); } } }; diff --git a/services/sync/modules/engines/history.js b/services/sync/modules/engines/history.js index e20accb13fd4..30e17a9e0384 100644 --- a/services/sync/modules/engines/history.js +++ b/services/sync/modules/engines/history.js @@ -119,7 +119,7 @@ HistoryStore.prototype = { return this._stmts[query]; this._log.trace("Creating SQL statement: " + query); - return this._stmts[query] = this._db.createStatement(query); + return this._stmts[query] = Utils.createStatement(this._db, query); }, get _haveTempTablesStm() { diff --git a/services/sync/modules/util.js b/services/sync/modules/util.js index 2db234d030a2..c1b1d24c3e51 100644 --- a/services/sync/modules/util.js +++ b/services/sync/modules/util.js @@ -146,6 +146,15 @@ let Utils = { throw batchEx; }; }, + + createStatement: function createStatement(db, query) { + // Gecko 2.0 + if (db.createAsyncStatement) + return db.createAsyncStatement(query); + + // Gecko <2.0 + return db.createStatement(query); + }, queryAsync: function(query, names) { // Allow array of names, single name, and no name