IDB: Handle "nextunique" and "prevunique" cursors, and handle "advance()" correctly
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 1 Feb 2014 07:04:18 +0000 (07:04 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 1 Feb 2014 07:04:18 +0000 (07:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=128040

Reviewed by Jer Noble.

* DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.cpp:
(WebKit::SQLiteIDBCursor::advance): Entry point for advancing by a number of steps,
  calls either advanceUnique or advanceOnce the appropriate number of times.
(WebKit::SQLiteIDBCursor::advanceUnique): Call advanceOnce until the key has changed.
(WebKit::SQLiteIDBCursor::advanceOnce):
* DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@163237 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.cpp
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.h

index 93eebec..21c6a5a 100644 (file)
@@ -1,5 +1,19 @@
 2014-01-31  Brady Eidson  <beidson@apple.com>
 
+        IDB: Handle "nextunique" and "prevunique" cursors, and handle "advance()" correctly
+        https://bugs.webkit.org/show_bug.cgi?id=128040
+
+        Reviewed by Jer Noble.
+
+        * DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.cpp:
+        (WebKit::SQLiteIDBCursor::advance): Entry point for advancing by a number of steps,
+          calls either advanceUnique or advanceOnce the appropriate number of times.
+        (WebKit::SQLiteIDBCursor::advanceUnique): Call advanceOnce until the key has changed.
+        (WebKit::SQLiteIDBCursor::advanceOnce):
+        * DatabaseProcess/IndexedDB/sqlite/SQLiteIDBCursor.h:
+
+2014-01-31  Brady Eidson  <beidson@apple.com>
+
         IDB: Index cursors use wrong deserialization for the retrieved value
         https://bugs.webkit.org/show_bug.cgi?id=128035
 
index e465182..a15250e 100644 (file)
@@ -210,6 +210,41 @@ bool SQLiteIDBCursor::createSQLiteStatement(const String& sql, int64_t idToBind)
 
 bool SQLiteIDBCursor::advance(uint64_t count)
 {
+    bool isUnique = m_cursorDirection == IndexedDB::CursorDirection::NextNoDuplicate || m_cursorDirection == IndexedDB::CursorDirection::PrevNoDuplicate;
+
+    for (uint64_t i = 0; i < count; ++i) {
+        if (!isUnique) {
+            if (!advanceOnce())
+                return false;
+            continue;
+        }
+
+        if (!advanceUnique())
+            return false;
+    }
+
+    return true;
+}
+
+bool SQLiteIDBCursor::advanceUnique()
+{
+    IDBKeyData currentKey = m_currentKey;
+
+    while (!m_completed) {
+        if (!advanceOnce())
+            return false;
+
+        // If the new current key is different from the old current key, we're done.
+        if (currentKey.compare(m_currentKey))
+            return true;
+    }
+
+    return false;
+}
+
+
+bool SQLiteIDBCursor::advanceOnce()
+{
     ASSERT(m_transaction->sqliteTransaction());
     ASSERT(m_statement);
 
index c5bd3b2..640952e 100644 (file)
@@ -70,6 +70,9 @@ private:
     bool establishStatement();
     bool createSQLiteStatement(const String& sql, int64_t idToBind);
 
+    bool advanceOnce();
+    bool advanceUnique();
+
     SQLiteIDBTransaction* m_transaction;
     IDBIdentifier m_cursorIdentifier;
     int64_t m_objectStoreID;