From bb5eead71b82aaf0edd50eb4e5212c13a9fe5345 Mon Sep 17 00:00:00 2001 From: "jonathandicarlo@jonathan-dicarlos-macbook-pro.local" Date: Thu, 15 Jan 2009 14:05:50 -0800 Subject: [PATCH] Added a method to historyStore called tempTableExists which does a SELECT (rather than using tableExists) to correctly tell whether a temp table is there or not, so that historyEngine will work correctly on both Fennec and Firefox (See bug 472963) --- services/sync/modules/engines.js | 2 +- services/sync/modules/engines/history.js | 40 +++++++++++++++++++++--- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/services/sync/modules/engines.js b/services/sync/modules/engines.js index 069e0405a043..1a29d9f31330 100644 --- a/services/sync/modules/engines.js +++ b/services/sync/modules/engines.js @@ -143,7 +143,7 @@ Engine.prototype = { this._osPrefix = "weave:" + this.name + ":"; this._tracker; // initialize tracker to load previously changed IDs - + dump(this.name + "engine initialized.\n"); this._log.debug("Engine initialized"); }, diff --git a/services/sync/modules/engines/history.js b/services/sync/modules/engines/history.js index fff12323de78..7914aa250f05 100644 --- a/services/sync/modules/engines/history.js +++ b/services/sync/modules/engines/history.js @@ -61,7 +61,16 @@ HistoryEngine.prototype = { displayName: "History", logName: "History", _storeObj: HistoryStore, - _trackerObj: HistoryTracker + _trackerObj: HistoryTracker, + // TODO the following overridden method has been defined just to facilitate + // debugging of tempTableExists. Once that debugging is done, this should + // be deleted. + _syncFinish: function HistoryEngine__syncFinish(error) { + let self = yield; + this._log.debug("Finishing up sync"); + this._log.debug(this._store._pidStm); + this._tracker.resetScore(); + } }; function HistoryStore() { @@ -123,10 +132,33 @@ HistoryStore.prototype = { } }, + tempTableExists: function HistStore__tempTableExists(tableName) { + // Check for table existance manually + // (just using this._db.tableExists() gives us false negatives on + // Firefox for temp tables.) + let statement = this._db.createStatement( + "SELECT count(*) as count FROM sqlite_temp_master WHERE type='table' " + + "AND name='" + tableName + "'" + ); + dump("Checking if temp table " + tableName + " exists.\n"); + this._log.debug("Checking if temp table " + tableName + " exists."); + statement.step(); + let num = statement.row["count"]; + if (num == 0) { + this._log.debug("No: the table does not exist."); + dump("No: the table does not exist.\n"); + return false; + } else { + this._log.debug("Yes: the table exists."); + dump("Yes: the table exists.\n"); + return true; + } + }, + get _visitStm() { this._log.trace("Creating SQL statement: _visitStm"); let stm; - if (this._db.tableExists("moz_historyvisits_temp")) { + if (this.tempTableExists("moz_historyvisits_temp")) { stm = this._db.createStatement( "SELECT * FROM ( " + "SELECT visit_type AS type, visit_date AS date " + @@ -161,7 +193,7 @@ HistoryStore.prototype = { this._log.trace("Creating SQL statement: _pidStm"); let stm; // See comment in get _urlStm() - if (this._db.tableExists("moz_places_temp")) { + if (this.tempTableExists("moz_places_temp")) { stm = this._db.createStatement( "SELECT * FROM " + "(SELECT id FROM moz_places_temp WHERE url = :url LIMIT 1) " + @@ -190,7 +222,7 @@ HistoryStore.prototype = { * that table. */ let stm; - if (this._db.tableExists("moz_places_temp")) { + if (this.tempTableExists("moz_places_temp")) { stm = this._db.createStatement( "SELECT * FROM " + "(SELECT url,title FROM moz_places_temp WHERE id = :id LIMIT 1) " +