Bug 618616 - 'IndexedDB: Make IDBObjectStore.get() accept a key range'. r=sicking, a=blocking.

This commit is contained in:
Ben Turner 2010-12-15 13:21:20 -08:00
parent 2fe29b705a
commit 68954fc1d7
2 changed files with 37 additions and 1 deletions

View File

@ -934,7 +934,30 @@ IDBObjectStore::Get(nsIVariant* aKey,
Key key;
nsresult rv = GetKeyFromVariant(aKey, key);
if (NS_FAILED(rv)) {
return rv;
// Check to see if this is a key range.
PRUint16 type;
rv = aKey->GetDataType(&type);
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
if (type != nsIDataType::VTYPE_INTERFACE &&
type != nsIDataType::VTYPE_INTERFACE_IS) {
return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
}
// XXX I hate this API. Move to jsvals, stat.
nsID* iid;
nsCOMPtr<nsISupports> supports;
rv = aKey->GetAsInterface(&iid, getter_AddRefs(supports));
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
NS_Free(iid);
nsCOMPtr<nsIIDBKeyRange> keyRange = do_QueryInterface(supports);
if (!keyRange) {
return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
}
return GetAll(keyRange, 0, 0, _retval);
}
if (key.IsUnset()) {

View File

@ -105,6 +105,19 @@
is(event.result[i], values[parseInt(i) + 3], "Same value");
}
// Get should take a key range also.
request = db.transaction("foo").objectStore("foo").get(keyRange);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.result instanceof Array, true, "Got an array object");
is(event.result.length, 4, "Correct length");
for (let i in event.result) {
is(event.result[i], values[parseInt(i) + 3], "Same value");
}
keyRange = IDBKeyRange.bound(4, 7);
request = db.transaction("foo").objectStore("foo").getAll(keyRange, 2);