Bug 769805 - Contacts API broken due to IndexedDB API Change. r=khuey

This commit is contained in:
Guillermo Lopez 2012-07-02 12:03:49 -07:00
parent b3808e2e18
commit f47fee5145

View File

@ -14,7 +14,7 @@ if (DEBUG) {
debug = function (s) {} debug = function (s) {}
} }
const Cu = Components.utils; const Cu = Components.utils;
const Cc = Components.classes; const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
@ -76,7 +76,7 @@ ContactDB.prototype = {
} else if (currVersion == 1) { } else if (currVersion == 1) {
debug("upgrade 1"); debug("upgrade 1");
// Create a new scheme for the tel field. We move from an array of tel-numbers to an array of // Create a new scheme for the tel field. We move from an array of tel-numbers to an array of
// ContactTelephone. // ContactTelephone.
if (!objectStore) { if (!objectStore) {
objectStore = aTransaction.objectStore(STORE_NAME); objectStore = aTransaction.objectStore(STORE_NAME);
@ -85,7 +85,7 @@ ContactDB.prototype = {
objectStore.deleteIndex("tel"); objectStore.deleteIndex("tel");
// Upgrade existing tel field in the DB. // Upgrade existing tel field in the DB.
objectStore.openCursor().onsuccess = function(event) { objectStore.openCursor().onsuccess = function(event) {
let cursor = event.target.result; let cursor = event.target.result;
if (cursor) { if (cursor) {
debug("upgrade tel1: " + JSON.stringify(cursor.value)); debug("upgrade tel1: " + JSON.stringify(cursor.value));
@ -95,7 +95,7 @@ ContactDB.prototype = {
cursor.update(cursor.value); cursor.update(cursor.value);
debug("upgrade tel2: " + JSON.stringify(cursor.value)); debug("upgrade tel2: " + JSON.stringify(cursor.value));
cursor.continue(); cursor.continue();
} }
}; };
// Create new searchable indexes. // Create new searchable indexes.
@ -155,7 +155,7 @@ ContactDB.prototype = {
for (let i = 0; i <= aContact.properties[field].length; i++) { for (let i = 0; i <= aContact.properties[field].length; i++) {
if (aContact.properties[field][i]) { if (aContact.properties[field][i]) {
if (field == "tel") { if (field == "tel") {
// Special case telephone number. // Special case telephone number.
// "+1-234-567" should also be found with 1234, 234-56, 23456 // "+1-234-567" should also be found with 1234, 234-56, 23456
// Chop off the first characters // Chop off the first characters
@ -308,21 +308,21 @@ ContactDB.prototype = {
let request; let request;
if (key == "id") { if (key == "id") {
// store.get would return an object and not an array // store.get would return an object and not an array
request = store.getAll(options.filterValue); request = store.mozGetAll(options.filterValue);
} else if (key == "category") { } else if (key == "category") {
let index = store.index(key); let index = store.index(key);
request = index.getAll(options.filterValue, limit); request = index.mozGetAll(options.filterValue, limit);
} else if (options.filterOp == "equals") { } else if (options.filterOp == "equals") {
debug("Getting index: " + key); debug("Getting index: " + key);
// case sensitive // case sensitive
let index = store.index(key); let index = store.index(key);
request = index.getAll(options.filterValue, limit); request = index.mozGetAll(options.filterValue, limit);
} else { } else {
// not case sensitive // not case sensitive
let tmp = options.filterValue.toLowerCase(); let tmp = options.filterValue.toLowerCase();
let range = this._global.IDBKeyRange.bound(tmp, tmp + "\uFFFF"); let range = this._global.IDBKeyRange.bound(tmp, tmp + "\uFFFF");
let index = store.index(key + "LowerCase"); let index = store.index(key + "LowerCase");
request = index.getAll(range, limit); request = index.mozGetAll(range, limit);
} }
if (!txn.result) if (!txn.result)
txn.result = {}; txn.result = {};
@ -341,7 +341,7 @@ ContactDB.prototype = {
txn.result = {}; txn.result = {};
// Sorting functions takes care of limit if set. // Sorting functions takes care of limit if set.
let limit = options.sortBy === 'undefined' ? options.filterLimit : null; let limit = options.sortBy === 'undefined' ? options.filterLimit : null;
store.getAll(null, limit).onsuccess = function (event) { store.mozGetAll(null, limit).onsuccess = function (event) {
debug("Request successful. Record count:", event.target.result.length); debug("Request successful. Record count:", event.target.result.length);
for (let i in event.target.result) for (let i in event.target.result)
txn.result[event.target.result[i].id] = this.makeExport(event.target.result[i]); txn.result[event.target.result[i].id] = this.makeExport(event.target.result[i]);