Bug 638067 - 'IndexedDB: Inserting data with multiple indexes on an autoIncrement object store throws an error'. r=sdwilsh.
authorBen Turner <bent.mozilla@gmail.com>
Wed, 13 Apr 2011 00:26:20 -0700
changeset 68285 6bcaec19d09ec670366544e0b14c715fada5a657
parent 68284 5542d52a48328d768b3f2ed4598bd22cb219925f
child 68286 2d69b518b6ab4994b80f532cc9a7c13a0a175890
push id76
push userbzbarsky@mozilla.com
push dateTue, 05 Jul 2011 17:00:57 +0000
treeherdermozilla-beta@d3a2732c35f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssdwilsh
bugs638067
milestone6.0a1
first release with
nightly linux32
6bcaec19d09e / 6.0a1 / 20110413030543 / files
nightly linux64
6bcaec19d09e / 6.0a1 / 20110413030543 / files
nightly mac
6bcaec19d09e / 6.0a1 / 20110413030543 / files
nightly win32
6bcaec19d09e / 6.0a1 / 20110413030543 / files
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
Bug 638067 - 'IndexedDB: Inserting data with multiple indexes on an autoIncrement object store throws an error'. r=sdwilsh.
dom/indexedDB/IDBObjectStore.cpp
dom/indexedDB/IDBTransaction.cpp
dom/indexedDB/test/Makefile.in
dom/indexedDB/test/test_autoIncrement_indexes.html
--- a/dom/indexedDB/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -732,28 +732,31 @@ IDBObjectStore::UpdateIndexes(IDBTransac
     rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("index_id"),
                                updateInfo.info.id);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("object_data_id"),
                                aObjectDataId);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    NS_NAMED_LITERAL_CSTRING(objectDataKey, "object_data_key");
-
-    if (aObjectStoreKey.IsInt()) {
-      rv = stmt->BindInt64ByName(objectDataKey, aObjectStoreKey.IntValue());
+    if (!updateInfo.info.autoIncrement) {
+      NS_NAMED_LITERAL_CSTRING(objectDataKey, "object_data_key");
+
+      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");
 
     if (updateInfo.value.IsInt()) {
       rv = stmt->BindInt64ByName(value, updateInfo.value.IntValue());
     }
     else if (updateInfo.value.IsString()) {
       rv = stmt->BindStringByName(value, updateInfo.value.StringValue());
--- a/dom/indexedDB/IDBTransaction.cpp
+++ b/dom/indexedDB/IDBTransaction.cpp
@@ -474,37 +474,37 @@ IDBTransaction::IndexUpdateStatement(boo
                                      bool aUnique,
                                      bool aOverwrite)
 {
   if (aAutoIncrement) {
     if (aUnique) {
       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) {
     if (aOverwrite) {
       return GetCachedStatement(
         "INSERT OR REPLACE INTO unique_index_data "
           "(index_id, object_data_id, object_data_key, value) "
         "VALUES (:index_id, :object_data_id, :object_data_key, :value)"
--- a/dom/indexedDB/test/Makefile.in
+++ b/dom/indexedDB/test/Makefile.in
@@ -48,16 +48,17 @@ TEST_FILES = \
   bfcache_iframe1.html \
   bfcache_iframe2.html \
   error_events_abort_transactions_iframe.html \
   event_propagation_iframe.html \
   exceptions_in_success_events_iframe.html \
   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 \
   test_create_index.html \
   test_create_index_with_integer_keys.html \
   test_create_objectStore.html \
   test_cursors.html \
   test_cursor_mutation.html \
new file mode 100644
--- /dev/null
+++ b/dom/indexedDB/test/test_autoIncrement_indexes.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>