Title: [195508] trunk
Revision
195508
Author
beid...@apple.com
Date
2016-01-23 00:19:12 -0800 (Sat, 23 Jan 2016)

Log Message

Modern IDB: Implement clearing object stores and opening cursors in the SQLite backend.
https://bugs.webkit.org/show_bug.cgi?id=153396

Reviewed by Alex Christensen.

Source/WebCore:

No new tests (Some failing tests now pass, others improved).

Copy more LegacyIDB SQLite backend code over to the new SQLite backend.

* Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
(WebCore::IDBServer::SQLiteIDBBackingStore::clearObjectStore):
(WebCore::IDBServer::SQLiteIDBBackingStore::openCursor):
(WebCore::IDBServer::SQLiteIDBBackingStore::iterateCursor):

LayoutTests:

* platform/mac-wk1/TestExpectations:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (195507 => 195508)


--- trunk/LayoutTests/ChangeLog	2016-01-23 07:13:53 UTC (rev 195507)
+++ trunk/LayoutTests/ChangeLog	2016-01-23 08:19:12 UTC (rev 195508)
@@ -1,3 +1,12 @@
+2016-01-23  Brady Eidson  <beid...@apple.com>
+
+        Modern IDB: Implement clearing object stores and opening cursors in the SQLite backend.
+        https://bugs.webkit.org/show_bug.cgi?id=153396
+
+        Reviewed by Alex Christensen.
+
+        * platform/mac-wk1/TestExpectations:
+
 2016-01-22  Commit Queue  <commit-qu...@webkit.org>
 
         Unreviewed, rolling out r195493.

Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (195507 => 195508)


--- trunk/LayoutTests/platform/mac-wk1/TestExpectations	2016-01-23 07:13:53 UTC (rev 195507)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations	2016-01-23 08:19:12 UTC (rev 195508)
@@ -556,13 +556,11 @@
 storage/indexeddb/prefetch-bugfix-108071.html [ Failure ]
 storage/indexeddb/queued-commands.html [ Failure ]
 storage/indexeddb/readonly.html [ Failure ]
-storage/indexeddb/request-continue-abort.html [ Failure ]
 storage/indexeddb/structured-clone.html [ Failure ]
 storage/indexeddb/transaction-active-flag.html [ Failure ]
 storage/indexeddb/transaction-and-objectstore-calls.html [ Failure ]
 storage/indexeddb/transaction-basics.html [ Failure ]
 storage/indexeddb/transaction-error.html [ Failure ]
-storage/indexeddb/transaction-read-only.html [ Failure ]
 storage/indexeddb/transaction-rollback.html [ Failure ]
 storage/indexeddb/value-undefined.html [ Failure ]
 storage/indexeddb/values-odd-types.html [ Failure ]

Modified: trunk/Source/WebCore/ChangeLog (195507 => 195508)


--- trunk/Source/WebCore/ChangeLog	2016-01-23 07:13:53 UTC (rev 195507)
+++ trunk/Source/WebCore/ChangeLog	2016-01-23 08:19:12 UTC (rev 195508)
@@ -1,3 +1,19 @@
+2016-01-23  Brady Eidson  <beid...@apple.com>
+
+        Modern IDB: Implement clearing object stores and opening cursors in the SQLite backend.
+        https://bugs.webkit.org/show_bug.cgi?id=153396
+
+        Reviewed by Alex Christensen.
+
+        No new tests (Some failing tests now pass, others improved).
+
+        Copy more LegacyIDB SQLite backend code over to the new SQLite backend.
+        
+        * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
+        (WebCore::IDBServer::SQLiteIDBBackingStore::clearObjectStore):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::openCursor):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::iterateCursor):
+
 2016-01-22  Commit Queue  <commit-qu...@webkit.org>
 
         Unreviewed, rolling out r195493.

Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp (195507 => 195508)


--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp	2016-01-23 07:13:53 UTC (rev 195507)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp	2016-01-23 08:19:12 UTC (rev 195508)
@@ -31,6 +31,7 @@
 #include "FileSystem.h"
 #include "IDBBindingUtilities.h"
 #include "IDBDatabaseException.h"
+#include "IDBGetResult.h"
 #include "IDBKeyData.h"
 #include "IDBSerialization.h"
 #include "IDBTransactionInfo.h"
@@ -639,9 +640,42 @@
     return true;
 }
 
-IDBError SQLiteIDBBackingStore::clearObjectStore(const IDBResourceIdentifier&, uint64_t)
+IDBError SQLiteIDBBackingStore::clearObjectStore(const IDBResourceIdentifier& transactionIdentifier, uint64_t objectStoreID)
 {
-    return { IDBDatabaseException::UnknownError, ASCIILiteral("Not implemented") };
+    ASSERT(m_sqliteDB);
+    ASSERT(m_sqliteDB->isOpen());
+
+    auto* transaction = m_transactions.get(transactionIdentifier);
+    if (!transaction || !transaction->inProgress()) {
+        LOG_ERROR("Attempt to clear an object store without an in-progress transaction");
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Attempt to clear an object store without an in-progress transaction") };
+    }
+    if (transaction->mode() == IndexedDB::TransactionMode::ReadOnly) {
+        LOG_ERROR("Attempt to clear an object store in a read-only transaction");
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Attempt to clear an object store in a read-only transaction") };
+    }
+
+    {
+        SQLiteStatement sql(*m_sqliteDB, ASCIILiteral("DELETE FROM Records WHERE objectStoreID = ?;"));
+        if (sql.prepare() != SQLITE_OK
+            || sql.bindInt64(1, objectStoreID) != SQLITE_OK
+            || sql.step() != SQLITE_DONE) {
+            LOG_ERROR("Could not clear records from object store id %" PRIi64 " (%i) - %s", objectStoreID, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
+            return { IDBDatabaseException::UnknownError, ASCIILiteral("Unable to clear object store") };
+        }
+    }
+
+    {
+        SQLiteStatement sql(*m_sqliteDB, ASCIILiteral("DELETE FROM IndexRecords WHERE objectStoreID = ?;"));
+        if (sql.prepare() != SQLITE_OK
+            || sql.bindInt64(1, objectStoreID) != SQLITE_OK
+            || sql.step() != SQLITE_DONE) {
+            LOG_ERROR("Could not delete records from index record store id %" PRIi64 " (%i) - %s", objectStoreID, m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
+            return { IDBDatabaseException::UnknownError, ASCIILiteral("Unable to delete index records while clearing object store") };
+        }
+    }
+
+    return { };
 }
 
 IDBError SQLiteIDBBackingStore::createIndex(const IDBResourceIdentifier&, const IDBIndexInfo&)
@@ -913,14 +947,63 @@
     return { IDBDatabaseException::UnknownError, ASCIILiteral("Not implemented") };
 }
 
-IDBError SQLiteIDBBackingStore::openCursor(const IDBResourceIdentifier&, const IDBCursorInfo&, IDBGetResult&)
+IDBError SQLiteIDBBackingStore::openCursor(const IDBResourceIdentifier& transactionIdentifier, const IDBCursorInfo& info, IDBGetResult& result)
 {
-    return { IDBDatabaseException::UnknownError, ASCIILiteral("Not implemented") };
+    ASSERT(m_sqliteDB);
+    ASSERT(m_sqliteDB->isOpen());
+
+    auto* transaction = m_transactions.get(transactionIdentifier);
+    if (!transaction || !transaction->inProgress()) {
+        LOG_ERROR("Attempt to open a cursor in database without an in-progress transaction");
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Attempt to open a cursor in database without an in-progress transaction") };
+    }
+
+    auto* cursor = transaction->maybeOpenCursor(info);
+    if (!cursor) {
+        LOG_ERROR("Unable to open cursor");
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Unable to open cursor") };
+    }
+
+    m_cursors.set(cursor->identifier(), cursor);
+
+    result = { cursor->currentKey(), cursor->currentPrimaryKey(), ThreadSafeDataBuffer::copyVector(cursor->currentValueBuffer()) };
+    return { };
 }
 
-IDBError SQLiteIDBBackingStore::iterateCursor(const IDBResourceIdentifier&, const IDBResourceIdentifier&, const IDBKeyData&, uint32_t, IDBGetResult&)
+IDBError SQLiteIDBBackingStore::iterateCursor(const IDBResourceIdentifier& transactionIdentifier, const IDBResourceIdentifier& cursorIdentifier, const IDBKeyData& key, uint32_t count, IDBGetResult& result)
 {
-    return { IDBDatabaseException::UnknownError, ASCIILiteral("Not implemented") };
+    ASSERT(m_sqliteDB);
+    ASSERT(m_sqliteDB->isOpen());
+
+    auto* cursor = m_cursors.get(cursorIdentifier);
+    if (!cursor) {
+        LOG_ERROR("Attempt to iterate a cursor that doesn't exist");
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Attempt to iterate a cursor that doesn't exist") };
+    }
+
+    ASSERT_UNUSED(transactionIdentifier, cursor->transaction()->transactionIdentifier() == transactionIdentifier);
+
+    if (!cursor->transaction() || !cursor->transaction()->inProgress()) {
+        LOG_ERROR("Attempt to iterate a cursor without an in-progress transaction");
+        return { IDBDatabaseException::UnknownError, ASCIILiteral("Attempt to iterate a cursor without an in-progress transaction") };
+    }
+
+    if (key.isValid()) {
+        if (!cursor->iterate(key)) {
+            LOG_ERROR("Attempt to iterate cursor failed");
+            return { IDBDatabaseException::UnknownError, ASCIILiteral("Attempt to iterate cursor failed") };
+        }
+    } else {
+        if (!count)
+            count = 1;
+        if (!cursor->advance(count)) {
+            LOG_ERROR("Attempt to advance cursor failed");
+            return { IDBDatabaseException::UnknownError, ASCIILiteral("Attempt to advance cursor failed") };
+        }
+    }
+
+    result = { cursor->currentKey(), cursor->currentPrimaryKey(), ThreadSafeDataBuffer::copyVector(cursor->currentValueBuffer()) };
+    return { };
 }
 
 void SQLiteIDBBackingStore::deleteBackingStore()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to