Bug 638067 - 'IndexedDB: Inserting data with multiple indexes on an autoIncrement object store throws an error'. r=sdwilsh.

This commit is contained in:
Ben Turner 2011-04-13 00:26:20 -07:00
Родитель 5fd52f20d0
Коммит 3d078b9b8a
4 изменённых файлов: 93 добавлений и 18 удалений

Просмотреть файл

@ -737,18 +737,21 @@ IDBObjectStore::UpdateIndexes(IDBTransaction* aTransaction,
aObjectDataId);
NS_ENSURE_SUCCESS(rv, rv);
NS_NAMED_LITERAL_CSTRING(objectDataKey, "object_data_key");
if (!updateInfo.info.autoIncrement) {
NS_NAMED_LITERAL_CSTRING(objectDataKey, "object_data_key");
if (aObjectStoreKey.IsInt()) {
rv = stmt->BindInt64ByName(objectDataKey, aObjectStoreKey.IntValue());
if (aObjectStoreKey.IsInt()) {
rv = stmt->BindInt64ByName(objectDataKey, aObjectStoreKey.IntValue());
}
else if (aObjectStoreKey.IsString()) {
rv = stmt->BindStringByName(objectDataKey,
aObjectStoreKey.StringValue());
}
else {
NS_NOTREACHED("Unknown key type!");
}
NS_ENSURE_SUCCESS(rv, rv);
}
else if (aObjectStoreKey.IsString()) {
rv = stmt->BindStringByName(objectDataKey, aObjectStoreKey.StringValue());
}
else {
NS_NOTREACHED("Unknown key type!");
}
NS_ENSURE_SUCCESS(rv, rv);
NS_NAMED_LITERAL_CSTRING(value, "value");

Просмотреть файл

@ -479,27 +479,27 @@ IDBTransaction::IndexUpdateStatement(bool aAutoIncrement,
if (aOverwrite) {
return GetCachedStatement(
"INSERT OR REPLACE INTO ai_unique_index_data "
"(index_id, ai_object_data_id, id, value) "
"VALUES (:index_id, :object_data_id, :object_data_key, :value)"
"(index_id, ai_object_data_id, value) "
"VALUES (:index_id, :object_data_id, :value)"
);
}
return GetCachedStatement(
"INSERT INTO ai_unique_index_data "
"(index_id, aI_object_data_id, id, value) "
"VALUES (:index_id, :object_data_id, :object_data_key, :value)"
"(index_id, aI_object_data_id, value) "
"VALUES (:index_id, :object_data_id, :value)"
);
}
if (aOverwrite) {
return GetCachedStatement(
"INSERT OR REPLACE INTO ai_index_data "
"(index_id, ai_object_data_id, id, value) "
"VALUES (:index_id, :object_data_id, :object_data_key, :value)"
"(index_id, ai_object_data_id, value) "
"VALUES (:index_id, :object_data_id, :value)"
);
}
return GetCachedStatement(
"INSERT INTO ai_index_data "
"(index_id, ai_object_data_id, id, value) "
"VALUES (:index_id, :object_data_id, :object_data_key, :value)"
"(index_id, ai_object_data_id, value) "
"VALUES (:index_id, :object_data_id, :value)"
);
}
if (aUnique) {

Просмотреть файл

@ -53,6 +53,7 @@ TEST_FILES = \
helpers.js \
leaving_page_iframe.html \
test_add_twice_failure.html \
test_autoIncrement_indexes.html \
test_bad_keypath.html \
test_bfcache.html \
test_clear.html \

Просмотреть файл

@ -0,0 +1,71 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<html>
<head>
<title>Indexed Database Property Test</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="text/javascript;version=1.7">
function testSteps()
{
let request = mozIndexedDB.open(window.location.pathname);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
let event = yield;
let db = request.result;
db.onerror = errorHandler;
db.setVersion("1").onsuccess = grabEventAndContinueHandler;
let event = yield;
let objectStore = db.createObjectStore("foo", { keyPath: "id",
autoIncrement: true });
objectStore.createIndex("first","first");
objectStore.createIndex("second","second");
objectStore.createIndex("third","third");
let data = { first: "foo", second: "foo", third: "foo" };
objectStore.add(data).onsuccess = grabEventAndContinueHandler;
event = yield;
let key = event.target.result;
ok(key, "Added entry");
let objectStore = db.transaction("foo").objectStore("foo");
let first = objectStore.index("first");
let second = objectStore.index("second");
let third = objectStore.index("third");
first.get("foo").onsuccess = grabEventAndContinueHandler;
event = yield;
is (event.target.result.id, key, "Entry in first");
second.get("foo").onsuccess = grabEventAndContinueHandler;
event = yield;
is (event.target.result.id, key, "Entry in second");
third.get("foo").onsuccess = grabEventAndContinueHandler;
event = yield;
is (event.target.result.id, key, "Entry in third");
finishTest();
yield;
}
</script>
<script type="text/javascript;version=1.7" src="helpers.js"></script>
</head>
<body onload="runTest();"></body>
</html>