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