Merge bug 616001 follow-up. a=blocking-beta9
authorPhilipp von Weitershausen <philipp@weitershausen.de>
Wed, 15 Dec 2010 16:11:29 -0800
changeset 59390 705ec6a77ab095361ba8f1ddb2d64978ca463bf7
parent 59389 ef51960b24ddd0b79fec1555e7d84764bac1f8af (current diff)
parent 59292 59fc12df9438bcd36de621baf2477906325a8bab (diff)
child 59391 776291003f32152403d132e9316765596fcd96c0
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersblocking-beta9
bugs616001
milestone2.0b8pre
Merge bug 616001 follow-up. a=blocking-beta9
services/sync/modules/engines/bookmarks.js
services/sync/modules/engines/history.js
services/sync/modules/service.js
--- a/services/sync/modules/engines/bookmarks.js
+++ b/services/sync/modules/engines/bookmarks.js
@@ -816,16 +816,32 @@ BookmarksStore.prototype = {
     if (query in this._stmts)
       return this._stmts[query];
 
     this._log.trace("Creating SQL statement: " + query);
     return this._stmts[query] = Utils.createStatement(this._hsvc.DBConnection,
                                                       query);
   },
 
+  __haveGUIDColumn: null,
+  get _haveGUIDColumn() {
+    if (this.__haveGUIDColumn !== null) {
+      return this.__haveGUIDColumn;
+    }
+    let stmt;
+    try {
+      stmt = this._hsvc.DBConnection.createStatement(
+        "SELECT guid FROM moz_places");
+      stmt.finalize();
+      return this.__haveGUIDColumn = true;
+    } catch(ex) {
+      return this.__haveGUIDColumn = false;
+    }
+  },
+
   get _frecencyStm() {
     return this._getStmt(
         "SELECT frecency " +
         "FROM moz_places " +
         "WHERE url = :url " +
         "LIMIT 1");
   },
 
@@ -862,23 +878,22 @@ BookmarksStore.prototype = {
   __setGUIDStm: null,
   get _setGUIDStm() {
     if (this.__setGUIDStm !== null) {
       return this.__setGUIDStm;
     }
 
     // Obtains a statement to set the guid iff the guid column exists.
     let stmt;
-    try {
+    if (this._haveGUIDColumn) {
       stmt = this._getStmt(
         "UPDATE moz_bookmarks " +
         "SET guid = :guid " +
         "WHERE id = :item_id");
-    }
-    catch (e) {
+    } else {
       stmt = false;
     }
     return this.__setGUIDStm = stmt;
   },
 
   // Some helper functions to handle GUIDs
   _setGUID: function _setGUID(id, guid) {
     if (arguments.length == 1)
@@ -931,23 +946,22 @@ BookmarksStore.prototype = {
     if (this.__guidForIdStm) {
       return this.__guidForIdStm;
     }
 
     // Try to first read from moz_bookmarks.  Creating the statement will
     // fail, however, if the guid column does not exist.  We fallback to just
     // reading the annotation table in this case.
     let stmt;
-    try {
+    if (this._haveGUIDColumn) {
       stmt = this._getStmt(
         "SELECT guid " +
         "FROM moz_bookmarks " +
         "WHERE id = :item_id");
-    }
-    catch (e) {
+    } else {
       stmt = this._getStmt(
         "SELECT a.content AS guid " +
         "FROM moz_items_annos a " +
         "JOIN moz_anno_attributes n ON n.id = a.anno_attribute_id " +
         "JOIN moz_bookmarks b ON b.id = a.item_id " +
         "WHERE n.name = '" + GUID_ANNO + "' " +
         "AND b.id = :item_id");
     }
@@ -978,23 +992,22 @@ BookmarksStore.prototype = {
       return this.__idForGUIDStm;
     }
 
 
     // Try to first read from moz_bookmarks.  Creating the statement will
     // fail, however, if the guid column does not exist.  We fallback to just
     // reading the annotation table in this case.
     let stmt;
-    try {
+    if (this._haveGUIDColumn) {
       stmt = this._getStmt(
         "SELECT id AS item_id " +
         "FROM moz_bookmarks " +
         "WHERE guid = :guid");
-    }
-    catch (e) {
+    } else {
       stmt = this._getStmt(
         "SELECT a.item_id AS item_id " +
         "FROM moz_items_annos a " +
         "JOIN moz_anno_attributes n ON n.id = a.anno_attribute_id " +
         "WHERE n.name = '" + GUID_ANNO + "' " +
         "AND a.content = :guid");
     }
 
--- a/services/sync/modules/engines/history.js
+++ b/services/sync/modules/engines/history.js
@@ -109,23 +109,39 @@ HistoryStore.prototype = {
   },
 
   get _haveTempTablesStm() {
     return this._getStmt(
       "SELECT name FROM sqlite_temp_master " +
       "WHERE name IN ('moz_places_temp', 'moz_historyvisits_temp')");
   },
 
+  __haveTempTables: null,
   get _haveTempTables() {
-    if (this.__haveTempTables == null)
+    if (this.__haveTempTables === null)
       this.__haveTempTables = !!Utils.queryAsync(this._haveTempTablesStm,
                                                  ["name"]).length;
     return this.__haveTempTables;
   },
 
+  __haveGUIDColumn: null,
+  get _haveGUIDColumn() {
+    if (this.__haveGUIDColumn !== null) {
+      return this.__haveGUIDColumn;
+    }
+    let stmt;
+    try {
+      stmt = this._db.createStatement("SELECT guid FROM moz_places");
+      stmt.finalize();
+      return this.__haveGUIDColumn = true;
+    } catch(ex) {
+      return this.__haveGUIDColumn = false;
+    }
+  },
+
   get _addGUIDAnnotationNameStm() {
     // Gecko <2.0 only
     let stmt = this._getStmt(
       "INSERT OR IGNORE INTO moz_anno_attributes (name) VALUES (:anno_name)");
     stmt.params.anno_name = GUID_ANNO;
     return stmt;
   },
 
@@ -157,23 +173,22 @@ HistoryStore.prototype = {
   __setGUIDStm: null,
   get _setGUIDStm() {
     if (this.__setGUIDStm !== null) {
       return this.__setGUIDStm;
     }
 
     // Obtains a statement to set the guid iff the guid column exists.
     let stmt;
-    try {
+    if (this._haveGUIDColumn) {
       stmt = this._getStmt(
         "UPDATE moz_places " +
         "SET guid = :guid " +
         "WHERE url = :page_url");
-    }
-    catch (e) {
+    } else {
       stmt = false;
     }
 
     return this.__setGUIDStm = stmt;
   },
 
   // Some helper functions to handle GUIDs
   setGUID: function setGUID(uri, guid) {
@@ -230,23 +245,22 @@ HistoryStore.prototype = {
     if (this.__guidStm) {
       return this.__guidStm;
     }
 
     // Try to first read from moz_places.  Creating the statement will throw
     // if the column doesn't exist, though so fallback to just reading from
     // the annotation table.
     let stmt;
-    try {
+    if (this._haveGUIDColumn) {
       stmt = this._getStmt(
         "SELECT guid " +
         "FROM moz_places " +
         "WHERE url = :page_url");
-    }
-    catch (e) {
+    } else {
       stmt = this._getStmt(
         "SELECT a.content AS guid " +
         "FROM moz_annos a " +
         "JOIN moz_anno_attributes n ON n.id = a.anno_attribute_id " +
         "JOIN ( " +
           "SELECT id FROM moz_places_temp WHERE url = :page_url " +
           "UNION " +
           "SELECT id FROM moz_places WHERE url = :page_url " +
@@ -299,23 +313,22 @@ HistoryStore.prototype = {
     if (this.__urlStmt) {
       return this.__urlStmt;
     }
 
     // Try to first read from moz_places.  Creating the statement will throw
     // if the column doesn't exist, though so fallback to just reading from
     // the annotation table.
     let stmt;
-    try {
+    if (this._haveGUIDColumn) {
       stmt = this._getStmt(
         "SELECT url, title, frecency " +
         "FROM moz_places " +
         "WHERE guid = :guid");
-    }
-    catch (e) {
+    } else {
       let where =
         "WHERE id = (" +
           "SELECT place_id " +
           "FROM moz_annos " +
           "WHERE content = :guid AND anno_attribute_id = (" +
             "SELECT id " +
             "FROM moz_anno_attributes " +
             "WHERE name = '" + GUID_ANNO + "')) ";
--- a/services/sync/modules/service.js
+++ b/services/sync/modules/service.js
@@ -1953,19 +1953,17 @@ WeaveSvc.prototype = {
       Clients.sync();
     }))(),
 
   /**
    * Reset local service information like logs, sync times, caches.
    */
   resetService: function WeaveSvc_resetService()
     this._catch(this._notify("reset-service", "", function() {
-      // First drop old logs to track client resetting behavior
-      this.clearLogs();
-      this._log.info("Logs reinitialized for service reset");
+      this._log.info("Service reset.");
 
       // Pretend we've never synced to the server and drop cached data
       this.syncID = "";
       Svc.Prefs.reset("lastSync");
       Records.clearCache();
     }))(),
 
   /**