Diff
Modified: trunk/Source/WebCore/ChangeLog (163248 => 163249)
--- trunk/Source/WebCore/ChangeLog 2014-02-01 20:37:15 UTC (rev 163248)
+++ trunk/Source/WebCore/ChangeLog 2014-02-01 21:00:30 UTC (rev 163249)
@@ -1,3 +1,21 @@
+2014-02-01 Brady Eidson <[email protected]>
+
+ IDB: Implement IDBObjectStore.delete()
+ https://bugs.webkit.org/show_bug.cgi?id=127880
+
+ Reviewed by Sam Weinig.
+
+ * Modules/indexeddb/IDBKeyData.cpp:
+ (WebCore::IDBKeyData::compare): Make this const.
+ * Modules/indexeddb/IDBKeyData.h:
+
+ * Modules/indexeddb/IDBKeyRangeData.cpp:
+ (WebCore::IDBKeyRangeData::isExactlyOneKey): Returns whether or not
+ the key range is known to represent precisely one key.
+ * Modules/indexeddb/IDBKeyRangeData.h:
+
+ * WebCore.exp.in:
+
2014-02-01 Anders Carlsson <[email protected]>
SVGTextLayoutAttributesBuilder shouldn't use RenderText::deprecatedCharacters()
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKeyData.cpp (163248 => 163249)
--- trunk/Source/WebCore/Modules/indexeddb/IDBKeyData.cpp 2014-02-01 20:37:15 UTC (rev 163248)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKeyData.cpp 2014-02-01 21:00:30 UTC (rev 163249)
@@ -200,7 +200,7 @@
return decoder.decodeObjects("array", result.arrayValue, arrayFunction);
}
-int IDBKeyData::compare(const IDBKeyData& other)
+int IDBKeyData::compare(const IDBKeyData& other) const
{
if (type == IDBKey::InvalidType) {
if (other.type != IDBKey::InvalidType)
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKeyData.h (163248 => 163249)
--- trunk/Source/WebCore/Modules/indexeddb/IDBKeyData.h 2014-02-01 20:37:15 UTC (rev 163248)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKeyData.h 2014-02-01 21:00:30 UTC (rev 163249)
@@ -56,7 +56,7 @@
// - Returns negative if this IDBKeyData is less than other.
// - Returns positive if this IDBKeyData is greater than other.
// - Returns zero if this IDBKeyData is equal to other.
- int compare(const IDBKeyData& other);
+ int compare(const IDBKeyData& other) const;
#ifndef NDEBUG
String loggingString() const;
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp (163248 => 163249)
--- trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp 2014-02-01 20:37:15 UTC (rev 163248)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp 2014-02-01 21:00:30 UTC (rev 163249)
@@ -51,6 +51,14 @@
return IDBKeyRange::create(lowerKey.maybeCreateIDBKey(), upperKey.maybeCreateIDBKey(), lowerOpen ? IDBKeyRange::LowerBoundOpen : IDBKeyRange::LowerBoundClosed, upperOpen ? IDBKeyRange::UpperBoundOpen : IDBKeyRange::UpperBoundClosed);
}
+bool IDBKeyRangeData::isExactlyOneKey() const
+{
+ if (isNull || lowerOpen || upperOpen)
+ return false;
+
+ return !lowerKey.compare(upperKey);
+}
+
} // namespace WebCore
#endif // ENABLE(INDEXED_DATABASE)
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.h (163248 => 163249)
--- trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.h 2014-02-01 20:37:15 UTC (rev 163248)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.h 2014-02-01 21:00:30 UTC (rev 163249)
@@ -59,6 +59,8 @@
PassRefPtr<IDBKeyRange> maybeCreateIDBKeyRange() const;
+ bool isExactlyOneKey() const;
+
bool isNull;
IDBKeyData lowerKey;
Modified: trunk/Source/WebCore/WebCore.exp.in (163248 => 163249)
--- trunk/Source/WebCore/WebCore.exp.in 2014-02-01 20:37:15 UTC (rev 163248)
+++ trunk/Source/WebCore/WebCore.exp.in 2014-02-01 21:00:30 UTC (rev 163249)
@@ -3092,12 +3092,13 @@
#endif
__ZNK7WebCore10IDBKeyData17maybeCreateIDBKeyEv
__ZNK7WebCore10IDBKeyData6encodeERNS_12KeyedEncoderE
+__ZNK7WebCore10IDBKeyData7compareERKS0_
__ZNK7WebCore10IDBKeyPath6encodeERNS_12KeyedEncoderE
__ZNK7WebCore11IDBKeyRange9isOnlyKeyEv
+__ZNK7WebCore15IDBKeyRangeData15isExactlyOneKeyEv
__ZNK7WebCore15IDBKeyRangeData22maybeCreateIDBKeyRangeEv
__ZNK7WebCore6IDBKey7isValidEv
__ZN7WebCore10IDBKeyData6decodeERNS_12KeyedDecoderERS0_
-__ZN7WebCore10IDBKeyData7compareERKS0_
__ZN7WebCore10IDBKeyDataC1EPKNS_6IDBKeyE
__ZN7WebCore10IDBKeyPathC1ERKN3WTF6StringE
__ZN7WebCore10IDBKeyPathC1ERKN3WTF6VectorINS1_6StringELm0ENS1_15CrashOnOverflowEEE
Modified: trunk/Source/WebKit2/ChangeLog (163248 => 163249)
--- trunk/Source/WebKit2/ChangeLog 2014-02-01 20:37:15 UTC (rev 163248)
+++ trunk/Source/WebKit2/ChangeLog 2014-02-01 21:00:30 UTC (rev 163249)
@@ -1,5 +1,32 @@
2014-02-01 Brady Eidson <[email protected]>
+ IDB: Implement IDBObjectStore.delete()
+ https://bugs.webkit.org/show_bug.cgi?id=127880
+
+ Reviewed by Sam Weinig.
+
+ Implementing IDBObjectStore.delete() involves filling in the already-stubbed deleteRange() method.
+
+ * DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp:
+ (WebKit::UniqueIDBDatabase::deleteRangeInBackingStore): Call through to the backing store.
+
+ * DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h:
+ * DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp:
+ (WebKit::UniqueIDBDatabaseBackingStoreSQLite::deleteRange): Call deleteRecord on each key represented
+ by the passed-in keyRange. This involves collecting each key using a cursor.
+ (WebKit::UniqueIDBDatabaseBackingStoreSQLite::deleteRecord): Delete an individual record from the
+ object store and all associated indexes.
+ * DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h:
+
+ Teach the SQLiteIDBCursor to remember if it ended in an error condition:
+ * DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.cpp:
+ (WebKit::SQLiteIDBCursor::SQLiteIDBCursor):
+ (WebKit::SQLiteIDBCursor::advanceOnce):
+ * DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.h:
+ (WebKit::SQLiteIDBCursor::didError):
+
+2014-02-01 Brady Eidson <[email protected]>
+
IDB: Index reading
<rdar://problem/15899973> and https://bugs.webkit.org/show_bug.cgi?id=127868
Modified: trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp (163248 => 163249)
--- trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp 2014-02-01 20:37:15 UTC (rev 163248)
+++ trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp 2014-02-01 21:00:30 UTC (rev 163249)
@@ -989,11 +989,14 @@
request->completeRequest(count, errorCode, errorMessage);
}
-void UniqueIDBDatabase::deleteRangeInBackingStore(uint64_t requestID, const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, const IDBKeyRangeData&)
+void UniqueIDBDatabase::deleteRangeInBackingStore(uint64_t requestID, const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, const IDBKeyRangeData& keyRangeData)
{
- // FIXME: Implement
+ if (!m_backingStore->deleteRange(transactionIdentifier, objectStoreID, keyRangeData)) {
+ LOG_ERROR("Failed to delete range from backing store.");
+ postMainThreadTask(createAsyncTask(*this, &UniqueIDBDatabase::didDeleteRangeInBackingStore, requestID, IDBDatabaseException::UnknownError, ASCIILiteral("Failed to get count from backing store")));
+ }
- postMainThreadTask(createAsyncTask(*this, &UniqueIDBDatabase::didDeleteRangeInBackingStore, requestID, IDBDatabaseException::UnknownError, ASCIILiteral("deleteRange in backing store not supported yet")));
+ postMainThreadTask(createAsyncTask(*this, &UniqueIDBDatabase::didDeleteRangeInBackingStore, requestID, 0, String(StringImpl::empty())));
}
void UniqueIDBDatabase::didDeleteRangeInBackingStore(uint64_t requestID, uint32_t errorCode, const String& errorMessage)
Modified: trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h (163248 => 163249)
--- trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h 2014-02-01 20:37:15 UTC (rev 163248)
+++ trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h 2014-02-01 21:00:30 UTC (rev 163249)
@@ -70,6 +70,7 @@
virtual bool putRecord(const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKey&, const uint8_t* valueBuffer, size_t valueSize) = 0;
virtual bool putIndexRecord(const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, int64_t indexID, const WebCore::IDBKeyData&, const WebCore::IDBKeyData& indexKey) = 0;
virtual bool getIndexRecord(const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, int64_t indexID, const WebCore::IDBKeyRangeData&, RefPtr<WebCore::SharedBuffer>& result) = 0;
+ virtual bool deleteRange(const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKeyRangeData&) = 0;
virtual bool getKeyRecordFromObjectStore(const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKey&, RefPtr<WebCore::SharedBuffer>& result) = 0;
virtual bool getKeyRangeRecordFromObjectStore(const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKeyRange&, RefPtr<WebCore::SharedBuffer>& result, RefPtr<WebCore::IDBKey>& resultKey) = 0;
Modified: trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.cpp (163248 => 163249)
--- trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.cpp 2014-02-01 20:37:15 UTC (rev 163248)
+++ trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.cpp 2014-02-01 21:00:30 UTC (rev 163249)
@@ -59,6 +59,7 @@
, m_cursorDirection(cursorDirection)
, m_keyRange(keyRange)
, m_completed(false)
+ , m_errored(false)
{
ASSERT(m_objectStoreID);
}
@@ -262,6 +263,7 @@
if (result != SQLResultRow) {
LOG_ERROR("Error advancing cursor - (%i) %s", result, m_transaction->sqliteTransaction()->database().lastErrorMsg());
m_completed = true;
+ m_errored = true;
return false;
}
@@ -272,6 +274,7 @@
if (!deserializeIDBKeyData(reinterpret_cast<const uint8_t*>(keyData.data()), keyData.size(), key)) {
LOG_ERROR("Unable to deserialize key data from database while advancing cursor");
m_completed = true;
+ m_errored = true;
return false;
}
@@ -285,6 +288,7 @@
if (!deserializeIDBKeyData(reinterpret_cast<const uint8_t*>(keyData.data()), keyData.size(), m_currentValueKey)) {
LOG_ERROR("Unable to deserialize value data from database while advancing index cursor");
m_completed = true;
+ m_errored = true;
return false;
}
@@ -295,6 +299,8 @@
|| objectStoreStatement.bindInt64(2, m_objectStoreID) != SQLResultOk
|| objectStoreStatement.step() != SQLResultRow) {
LOG_ERROR("Could not create index cursor statement into object store records");
+ m_completed = true;
+ m_errored = true;
return false;
}
Modified: trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.h (163248 => 163249)
--- trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.h 2014-02-01 20:37:15 UTC (rev 163248)
+++ trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.h 2014-02-01 21:00:30 UTC (rev 163249)
@@ -64,6 +64,8 @@
bool advance(uint64_t count);
bool iterate(const WebCore::IDBKeyData& targetKey);
+ bool didError() const { return m_errored; }
+
private:
SQLiteIDBCursor(SQLiteIDBTransaction*, const IDBIdentifier& cursorIdentifier, int64_t objectStoreID, int64_t indexID, WebCore::IndexedDB::CursorDirection, WebCore::IndexedDB::CursorType, WebCore::IDBDatabaseBackend::TaskType, const WebCore::IDBKeyRangeData&);
@@ -88,6 +90,7 @@
std::unique_ptr<WebCore::SQLiteStatement> m_statement;
bool m_completed;
+ bool m_errored;
};
} // namespace WebKit
Modified: trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp (163248 => 163249)
--- trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp 2014-02-01 20:37:15 UTC (rev 163248)
+++ trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp 2014-02-01 21:00:30 UTC (rev 163249)
@@ -838,6 +838,108 @@
return true;
}
+bool UniqueIDBDatabaseBackingStoreSQLite::deleteRange(const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, const IDBKeyRangeData& keyRangeData)
+{
+ ASSERT(!isMainThread());
+ ASSERT(m_sqliteDB);
+ ASSERT(m_sqliteDB->isOpen());
+
+ SQLiteIDBTransaction* transaction = m_transactions.get(transactionIdentifier);
+ if (!transaction || !transaction->inProgress()) {
+ LOG_ERROR("Attempt to get count from database without an established, in-progress transaction");
+ return false;
+ }
+
+ if (transaction->mode() == IndexedDB::TransactionMode::ReadOnly) {
+ LOG_ERROR("Attempt to delete range from a read-only transaction");
+ return false;
+ }
+
+ // If the range to delete is exactly one key we can delete it right now.
+ if (keyRangeData.isExactlyOneKey()) {
+ if (!deleteRecord(*transaction, objectStoreID, keyRangeData.lowerKey)) {
+ LOG_ERROR("Failed to delete record for key '%s'", keyRangeData.lowerKey.loggingString().utf8().data());
+ return false;
+ }
+ return true;
+ }
+
+ // Otherwise the range might span multiple keys so we collect them with a cursor.
+ SQLiteIDBCursor* cursor = transaction->openCursor(objectStoreID, IDBIndexMetadata::InvalidId, IndexedDB::CursorDirection::Next, IndexedDB::CursorType::KeyAndValue, IDBDatabaseBackend::NormalTask, keyRangeData);
+
+ if (!cursor) {
+ LOG_ERROR("Cannot open cursor to perform index get in database");
+ return false;
+ }
+
+ m_cursors.set(cursor->identifier(), cursor);
+
+ Vector<IDBKeyData> keys;
+ do
+ keys.append(cursor->currentKey());
+ while (cursor->advance(1));
+
+ bool cursorDidError = cursor->didError();
+
+ // closeCursor() will remove the cursor from m_cursors and delete the cursor object
+ transaction->closeCursor(*cursor);
+
+ if (cursorDidError) {
+ LOG_ERROR("Unable to iterate over object store to deleteRange in database");
+ return false;
+ }
+
+ for (auto& key : keys) {
+ if (!deleteRecord(*transaction, objectStoreID, key)) {
+ LOG_ERROR("Failed to delete record for key '%s'", key.loggingString().utf8().data());
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool UniqueIDBDatabaseBackingStoreSQLite::deleteRecord(SQLiteIDBTransaction& transaction, int64_t objectStoreID, const WebCore::IDBKeyData& key)
+{
+ ASSERT(!isMainThread());
+ ASSERT(m_sqliteDB);
+ ASSERT(m_sqliteDB->isOpen());
+
+ RefPtr<SharedBuffer> keyBuffer = serializeIDBKeyData(key);
+ if (!keyBuffer) {
+ LOG_ERROR("Unable to serialize IDBKeyData to be removed from the database");
+ return false;
+ }
+
+ // Delete record from object store
+ {
+ SQLiteStatement sql(*m_sqliteDB, ASCIILiteral("DELETE FROM Records WHERE objectStoreID = ? AND key = CAST(? AS TEXT);"));
+
+ if (sql.prepare() != SQLResultOk
+ || sql.bindInt64(1, objectStoreID) != SQLResultOk
+ || sql.bindBlob(2, keyBuffer->data(), keyBuffer->size()) != SQLResultOk
+ || sql.step() != SQLResultDone) {
+ LOG_ERROR("Could not delete record from object store %lli (%i) - %s", objectStoreID, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
+ return false;
+ }
+ }
+
+ // Delete record from indexes store
+ {
+ SQLiteStatement sql(*m_sqliteDB, ASCIILiteral("DELETE FROM IndexRecords WHERE objectStoreID = ? AND value = CAST(? AS TEXT);"));
+
+ if (sql.prepare() != SQLResultOk
+ || sql.bindInt64(1, objectStoreID) != SQLResultOk
+ || sql.bindBlob(2, keyBuffer->data(), keyBuffer->size()) != SQLResultOk
+ || sql.step() != SQLResultDone) {
+ LOG_ERROR("Could not delete record from indexes for object store %lli (%i) - %s", objectStoreID, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
+ return false;
+ }
+ }
+
+ return true;
+}
+
bool UniqueIDBDatabaseBackingStoreSQLite::getKeyRecordFromObjectStore(const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, const IDBKey& key, RefPtr<SharedBuffer>& result)
{
ASSERT(!isMainThread());
Modified: trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h (163248 => 163249)
--- trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h 2014-02-01 20:37:15 UTC (rev 163248)
+++ trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h 2014-02-01 21:00:30 UTC (rev 163249)
@@ -75,6 +75,7 @@
virtual bool putRecord(const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKey&, const uint8_t* valueBuffer, size_t valueSize) override;
virtual bool putIndexRecord(const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, int64_t indexID, const WebCore::IDBKeyData& keyValue, const WebCore::IDBKeyData& indexKey) override;
virtual bool getIndexRecord(const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, int64_t indexID, const WebCore::IDBKeyRangeData&, RefPtr<WebCore::SharedBuffer>& result) override;
+ virtual bool deleteRange(const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKeyRangeData&) override;
virtual bool getKeyRecordFromObjectStore(const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKey&, RefPtr<WebCore::SharedBuffer>& result) override;
virtual bool getKeyRangeRecordFromObjectStore(const IDBIdentifier& transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKeyRange&, RefPtr<WebCore::SharedBuffer>& result, RefPtr<WebCore::IDBKey>& resultKey) override;
@@ -93,6 +94,8 @@
std::unique_ptr<WebCore::IDBDatabaseMetadata> extractExistingMetadata();
std::unique_ptr<WebCore::IDBDatabaseMetadata> createAndPopulateInitialMetadata();
+ bool deleteRecord(SQLiteIDBTransaction&, int64_t objectStoreID, const WebCore::IDBKeyData&);
+
int idbKeyCollate(int aLength, const void* a, int bLength, const void* b);
UniqueIDBDatabaseIdentifier m_identifier;