Bug 706088 Make .put allow no key being provided if it's an autoIncrement object store. r=bent

This commit is contained in:
Kyle Huey 2011-12-06 02:45:46 -08:00
parent c650c15043
commit e6b29675f2
3 changed files with 13 additions and 13 deletions

View File

@ -1109,8 +1109,8 @@ IDBObjectStore::AddOrPut(const jsval& aValue,
return rv;
}
// Put requires a key.
if (aOverwrite && key.IsUnset()) {
// Put requires a key, unless this is an autoIncrementing objectStore.
if (aOverwrite && !mAutoIncrement && key.IsUnset()) {
return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
}
@ -1793,7 +1793,7 @@ AddHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
}
// If we are supposed to generate a key, get the new id.
if (autoIncrement && !mOverwrite) {
if (autoIncrement && !mayOverwrite) {
#ifdef DEBUG
PRInt64 oldKey = unsetKey ? 0 : mKey.ToInteger();
#endif

View File

@ -61,18 +61,18 @@
try {
objectStore.put({});
ok(false, "put with no key should throw!");
ok(true, "put with no key should not throw with autoIncrement!");
}
catch (e) {
ok(true, "put with no key threw");
ok(false, "put with no key threw with autoIncrement");
}
try {
objectStore.put({});
ok(false, "put with no key should throw!");
ok(true, "put with no key should not throw with autoIncrement!");
}
catch (e) {
ok(true, "put with no key threw");
ok(false, "put with no key threw with autoIncrement");
}
try {
@ -247,18 +247,18 @@
try {
objectStore.put({});
ok(false, "put with no key should throw!");
ok(true, "put with no key should not throw with autoIncrement!");
}
catch (e) {
ok(true, "put with no key threw");
ok(false, "put with no key threw with autoIncrement");
}
try {
objectStore.put({});
ok(false, "put with no key should throw!");
ok(true, "put with no key should not throw with autoIncrement!");
}
catch (e) {
ok(true, "put with no key threw");
ok(false, "put with no key threw with autoIncrement");
}
try {

View File

@ -29,7 +29,7 @@
let objectStore = db.createObjectStore(objectStoreName,
{ autoIncrement: 1 });
request = objectStore.add(testString.value);
request = objectStore.put(testString.value);
request.onerror = errorHandler;
request.onsuccess = function(event) {
testString.key = event.target.result;
@ -40,7 +40,7 @@
};
};
request = objectStore.add(testInt.value);
request = objectStore.put(testInt.value);
request.onerror = errorHandler;
request.onsuccess = function(event) {
testInt.key = event.target.result;