<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[162682] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/162682">162682</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2014-01-23 19:52:30 -0800 (Thu, 23 Jan 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>IDB: Implement SQLite backing store 'get' support
https://bugs.webkit.org/show_bug.cgi?id=127502

Reviewed by Tim Horton.

Source/WebCore:

Get a KeyRange from a KeyRangeData:
* Modules/indexeddb/IDBKeyRangeData.cpp:
(WebCore::IDBKeyRangeData::maybeCreateIDBKeyRange):
* Modules/indexeddb/IDBKeyRangeData.h:

Add collation function support to SQLiteDatabase:
* platform/sql/SQLiteDatabase.cpp:
(WebCore::destroyCollationFunction):
(WebCore::callCollationFunction):
(WebCore::SQLiteDatabase::setCollationFunction):
(WebCore::SQLiteDatabase::removeCollationFunction):
* platform/sql/SQLiteDatabase.h:

* WebCore.exp.in:

Source/WebKit2:

This makes get of a single IDBKey work, and lays the groundwork for getting an IDBKeyRange.

* DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp:
(WebKit::UniqueIDBDatabase::getRecordFromBackingStore):
* DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h:

* DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp:
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::createAndPopulateInitialMetadata): Add custom collation
  to the Records table.
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::getOrEstablishMetadata): Install the custom collator.
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::getKeyRecordFromObjectStore):
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::getKeyRangeRecordFromObjectStore):
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::collate): Collation function to be filled in later.
* DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbIDBKeyRangeDatacpp">trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbIDBKeyRangeDatah">trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.h</a></li>
<li><a href="#trunkSourceWebCoreWebCoreexpin">trunk/Source/WebCore/WebCore.exp.in</a></li>
<li><a href="#trunkSourceWebCoreplatformsqlSQLiteDatabasecpp">trunk/Source/WebCore/platform/sql/SQLiteDatabase.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformsqlSQLiteDatabaseh">trunk/Source/WebCore/platform/sql/SQLiteDatabase.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2DatabaseProcessIndexedDBUniqueIDBDatabasecpp">trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp</a></li>
<li><a href="#trunkSourceWebKit2DatabaseProcessIndexedDBUniqueIDBDatabaseBackingStoreh">trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h</a></li>
<li><a href="#trunkSourceWebKit2DatabaseProcessIndexedDBsqliteUniqueIDBDatabaseBackingStoreSQLitecpp">trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp</a></li>
<li><a href="#trunkSourceWebKit2DatabaseProcessIndexedDBsqliteUniqueIDBDatabaseBackingStoreSQLiteh">trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (162681 => 162682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-01-24 03:41:22 UTC (rev 162681)
+++ trunk/Source/WebCore/ChangeLog        2014-01-24 03:52:30 UTC (rev 162682)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2014-01-23  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        IDB: Implement SQLite backing store 'get' support
+        https://bugs.webkit.org/show_bug.cgi?id=127502
+
+        Reviewed by Tim Horton.
+
+        Get a KeyRange from a KeyRangeData:
+        * Modules/indexeddb/IDBKeyRangeData.cpp:
+        (WebCore::IDBKeyRangeData::maybeCreateIDBKeyRange):
+        * Modules/indexeddb/IDBKeyRangeData.h:
+
+        Add collation function support to SQLiteDatabase:
+        * platform/sql/SQLiteDatabase.cpp:
+        (WebCore::destroyCollationFunction):
+        (WebCore::callCollationFunction):
+        (WebCore::SQLiteDatabase::setCollationFunction):
+        (WebCore::SQLiteDatabase::removeCollationFunction):
+        * platform/sql/SQLiteDatabase.h:
+
+        * WebCore.exp.in:
+
</ins><span class="cx"> 2014-01-23  Jon Honeycutt  &lt;jhoneycutt@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Assertion failure in WebCore::PseudoElement::didRecalcStyle()
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbIDBKeyRangeDatacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp (162681 => 162682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp        2014-01-24 03:41:22 UTC (rev 162681)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp        2014-01-24 03:52:30 UTC (rev 162682)
</span><span class="lines">@@ -43,6 +43,14 @@
</span><span class="cx">     return result;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+PassRefPtr&lt;IDBKeyRange&gt; IDBKeyRangeData::maybeCreateIDBKeyRange() const
+{
+    if (isNull)
+        return nullptr;
+
+    return IDBKeyRange::create(lowerKey.maybeCreateIDBKey(), upperKey.maybeCreateIDBKey(), lowerOpen ? IDBKeyRange::LowerBoundOpen : IDBKeyRange::LowerBoundClosed, upperOpen ? IDBKeyRange::UpperBoundOpen : IDBKeyRange::UpperBoundClosed);
+}
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(INDEXED_DATABASE)
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbIDBKeyRangeDatah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.h (162681 => 162682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.h        2014-01-24 03:41:22 UTC (rev 162681)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.h        2014-01-24 03:52:30 UTC (rev 162682)
</span><span class="lines">@@ -57,6 +57,8 @@
</span><span class="cx"> 
</span><span class="cx">     IDBKeyRangeData isolatedCopy() const;
</span><span class="cx"> 
</span><ins>+    PassRefPtr&lt;IDBKeyRange&gt; maybeCreateIDBKeyRange() const;
+
</ins><span class="cx">     bool isNull;
</span><span class="cx"> 
</span><span class="cx">     IDBKeyData lowerKey;
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCoreexpin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.exp.in (162681 => 162682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.exp.in        2014-01-24 03:41:22 UTC (rev 162681)
+++ trunk/Source/WebCore/WebCore.exp.in        2014-01-24 03:52:30 UTC (rev 162682)
</span><span class="lines">@@ -84,6 +84,7 @@
</span><span class="cx"> __ZN7WebCore10RenderView7hitTestERKNS_14HitTestRequestERNS_13HitTestResultE
</span><span class="cx"> __ZN7WebCore15SQLiteStatement13getColumnBlobEiRi
</span><span class="cx"> __ZN7WebCore15SQLiteStatement14getColumnInt64Ei
</span><ins>+__ZN7WebCore15SQLiteStatement21getColumnBlobAsVectorEiRN3WTF6VectorIcLm0ENS1_15CrashOnOverflowEEE
</ins><span class="cx"> __ZN7WebCore10ScrollView16setParentVisibleEb
</span><span class="cx"> __ZN7WebCore10ScrollView17setUseFixedLayoutEb
</span><span class="cx"> __ZN7WebCore10ScrollView18setFixedLayoutSizeERKNS_7IntSizeE
</span><span class="lines">@@ -374,6 +375,7 @@
</span><span class="cx"> __ZN7WebCore14ResourceLoader6cancelEv
</span><span class="cx"> __ZN7WebCore14SQLiteDatabase11tableExistsERKN3WTF6StringE
</span><span class="cx"> __ZN7WebCore14SQLiteDatabase12lastErrorMsgEv
</span><ins>+__ZN7WebCore14SQLiteDatabase20setCollationFunctionERKN3WTF6StringENSt3__18functionIFiiPKviS8_EEE
</ins><span class="cx"> __ZN7WebCore14SQLiteDatabase14executeCommandERKN3WTF6StringE
</span><span class="cx"> __ZN7WebCore14SQLiteDatabase4openERKN3WTF6StringEb
</span><span class="cx"> __ZN7WebCore14SQLiteDatabase5closeEv
</span><span class="lines">@@ -3081,6 +3083,8 @@
</span><span class="cx"> #if ENABLE(INDEXED_DATABASE)
</span><span class="cx"> __ZNK7WebCore10IDBKeyData17maybeCreateIDBKeyEv
</span><span class="cx"> __ZNK7WebCore10IDBKeyPath6encodeERNS_12KeyedEncoderE
</span><ins>+__ZNK7WebCore11IDBKeyRange9isOnlyKeyEv
+__ZNK7WebCore15IDBKeyRangeData22maybeCreateIDBKeyRangeEv
</ins><span class="cx"> __ZNK7WebCore6IDBKey6encodeERNS_12KeyedEncoderE
</span><span class="cx"> __ZNK7WebCore6IDBKey7isValidEv
</span><span class="cx"> __ZN7WebCore10IDBKeyDataC1EPNS_6IDBKeyE
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformsqlSQLiteDatabasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/sql/SQLiteDatabase.cpp (162681 => 162682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/sql/SQLiteDatabase.cpp        2014-01-24 03:41:22 UTC (rev 162681)
+++ trunk/Source/WebCore/platform/sql/SQLiteDatabase.cpp        2014-01-24 03:52:30 UTC (rev 162682)
</span><span class="lines">@@ -506,4 +506,27 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static void destroyCollationFunction(void* arg)
+{
+    auto f = static_cast&lt;std::function&lt;int(int, const void*, int, const void*)&gt;*&gt;(arg);
+    delete f;
+}
+
+static int callCollationFunction(void* arg, int aLength, const void* a, int bLength, const void* b)
+{
+    auto f = static_cast&lt;std::function&lt;int(int, const void*, int, const void*)&gt;*&gt;(arg);
+    return (*f)(aLength, a, bLength, b);
+}
+
+void SQLiteDatabase::setCollationFunction(const String&amp; collationName, std::function&lt;int(int, const void*, int, const void*)&gt; collationFunction)
+{
+    auto functionObject = new std::function&lt;int(int, const void*, int, const void*)&gt;(collationFunction);
+    sqlite3_create_collation_v2(m_db, collationName.utf8().data(), SQLITE_UTF8, functionObject, callCollationFunction, destroyCollationFunction);
+}
+
+void SQLiteDatabase::removeCollationFunction(const String&amp; collationName)
+{
+    sqlite3_create_collation_v2(m_db, collationName.utf8().data(), SQLITE_UTF8, nullptr, nullptr, nullptr);
+}
+
</ins><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformsqlSQLiteDatabaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/sql/SQLiteDatabase.h (162681 => 162682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/sql/SQLiteDatabase.h        2014-01-24 03:41:22 UTC (rev 162681)
+++ trunk/Source/WebCore/platform/sql/SQLiteDatabase.h        2014-01-24 03:52:30 UTC (rev 162682)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> #ifndef SQLiteDatabase_h
</span><span class="cx"> #define SQLiteDatabase_h
</span><span class="cx"> 
</span><ins>+#include &lt;functional&gt;
</ins><span class="cx"> #include &lt;wtf/Threading.h&gt;
</span><span class="cx"> #include &lt;wtf/text/CString.h&gt;
</span><span class="cx"> #include &lt;wtf/text/WTFString.h&gt;
</span><span class="lines">@@ -130,6 +131,9 @@
</span><span class="cx">     enum AutoVacuumPragma { AutoVacuumNone = 0, AutoVacuumFull = 1, AutoVacuumIncremental = 2 };
</span><span class="cx">     bool turnOnIncrementalAutoVacuum();
</span><span class="cx"> 
</span><ins>+    void setCollationFunction(const String&amp; collationName, std::function&lt;int(int, const void*, int, const void*)&gt;);
+    void removeCollationFunction(const String&amp; collationName);
+
</ins><span class="cx">     // Set this flag to allow access from multiple threads.  Not all multi-threaded accesses are safe!
</span><span class="cx">     // See http://www.sqlite.org/cvstrac/wiki?p=MultiThreading for more info.
</span><span class="cx"> #ifndef NDEBUG
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (162681 => 162682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-01-24 03:41:22 UTC (rev 162681)
+++ trunk/Source/WebKit2/ChangeLog        2014-01-24 03:52:30 UTC (rev 162682)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2014-01-23  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        IDB: Implement SQLite backing store 'get' support
+        https://bugs.webkit.org/show_bug.cgi?id=127502
+
+        Reviewed by Tim Horton.
+
+        This makes get of a single IDBKey work, and lays the groundwork for getting an IDBKeyRange.
+
+        * DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp:
+        (WebKit::UniqueIDBDatabase::getRecordFromBackingStore):
+        * DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h:
+
+        * DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp:
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::createAndPopulateInitialMetadata): Add custom collation
+          to the Records table.
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::getOrEstablishMetadata): Install the custom collator.
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::getKeyRecordFromObjectStore):
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::getKeyRangeRecordFromObjectStore):
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::collate): Collation function to be filled in later.
+        * DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h:
+
</ins><span class="cx"> 2014-01-23  Jon Honeycutt  &lt;jhoneycutt@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Assertion failure in WebCore::PseudoElement::didRecalcStyle()
</span></span></pre></div>
<a id="trunkSourceWebKit2DatabaseProcessIndexedDBUniqueIDBDatabasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp (162681 => 162682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp        2014-01-24 03:41:22 UTC (rev 162681)
+++ trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp        2014-01-24 03:52:30 UTC (rev 162682)
</span><span class="lines">@@ -577,11 +577,45 @@
</span><span class="cx">     request-&gt;completeRequest(keyData, errorCode, errorMessage);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void UniqueIDBDatabase::getRecordFromBackingStore(uint64_t requestID, const IDBTransactionIdentifier&amp;, const WebCore::IDBObjectStoreMetadata&amp;, int64_t indexID, const WebCore::IDBKeyRangeData&amp;, WebCore::IndexedDB::CursorType)
</del><ins>+void UniqueIDBDatabase::getRecordFromBackingStore(uint64_t requestID, const IDBTransactionIdentifier&amp; transaction, const WebCore::IDBObjectStoreMetadata&amp; objectStoreMetadata, int64_t indexID, const WebCore::IDBKeyRangeData&amp; keyRangeData, WebCore::IndexedDB::CursorType cursorType)
</ins><span class="cx"> {
</span><del>-    // FIXME: Implement (https://bugs.webkit.org/show_bug.cgi?id=127502)
</del><ins>+    ASSERT(!isMainThread());
+    ASSERT(m_backingStore);
</ins><span class="cx"> 
</span><del>-    postMainThreadTask(createAsyncTask(*this, &amp;UniqueIDBDatabase::didGetRecordFromBackingStore, requestID, IDBGetResult(), IDBDatabaseException::UnknownError, ASCIILiteral(&quot;'get' support not yet implemented&quot;)));
</del><ins>+    RefPtr&lt;IDBKeyRange&gt; keyRange = keyRangeData.maybeCreateIDBKeyRange();
+    ASSERT(keyRange);
+    if (!keyRange) {
+        postMainThreadTask(createAsyncTask(*this, &amp;UniqueIDBDatabase::didGetRecordFromBackingStore, requestID, IDBGetResult(), IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Invalid IDBKeyRange requested from backing store&quot;)));
+        return;
+    }
+
+    if (indexID == IDBIndexMetadata::InvalidId) {
+        // IDBObjectStore get record
+        RefPtr&lt;SharedBuffer&gt; result;
+
+        if (keyRange-&gt;isOnlyKey()) {
+            if (!m_backingStore-&gt;getKeyRecordFromObjectStore(transaction, objectStoreMetadata.id, *keyRange-&gt;lower(), result))
+                postMainThreadTask(createAsyncTask(*this, &amp;UniqueIDBDatabase::didGetRecordFromBackingStore, requestID, IDBGetResult(), IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Failed to get key record from object store in backing store&quot;)));
+            else
+                postMainThreadTask(createAsyncTask(*this, &amp;UniqueIDBDatabase::didGetRecordFromBackingStore, requestID, IDBGetResult(result.release()), 0, String(StringImpl::empty())));
+
+            return;
+        }
+
+        RefPtr&lt;IDBKey&gt; resultKey;
+
+        if (!m_backingStore-&gt;getKeyRangeRecordFromObjectStore(transaction, objectStoreMetadata.id, *keyRange, result, resultKey))
+            postMainThreadTask(createAsyncTask(*this, &amp;UniqueIDBDatabase::didGetRecordFromBackingStore, requestID, IDBGetResult(), IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Failed to get key range record from object store in backing store&quot;)));
+        else
+            postMainThreadTask(createAsyncTask(*this, &amp;UniqueIDBDatabase::didGetRecordFromBackingStore, requestID, IDBGetResult(result.release(), resultKey.release(), IDBKeyPath()), 0, String(StringImpl::empty())));
+
+        return;
+    }
+
+    // IDBIndex get record
+
+    // FIXME: Implement index gets (&lt;rdar://problem/15779642&gt;)
+    postMainThreadTask(createAsyncTask(*this, &amp;UniqueIDBDatabase::didGetRecordFromBackingStore, requestID, IDBGetResult(), IDBDatabaseException::UnknownError, ASCIILiteral(&quot;'get' from indexes not supported yet&quot;)));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void UniqueIDBDatabase::didGetRecordFromBackingStore(uint64_t requestID, const IDBGetResult&amp; result, uint32_t errorCode, const String&amp; errorMessage)
</span></span></pre></div>
<a id="trunkSourceWebKit2DatabaseProcessIndexedDBUniqueIDBDatabaseBackingStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h (162681 => 162682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h        2014-01-24 03:41:22 UTC (rev 162681)
+++ trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h        2014-01-24 03:52:30 UTC (rev 162682)
</span><span class="lines">@@ -33,6 +33,8 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> class IDBKey;
</span><ins>+class IDBKeyRange;
+class SharedBuffer;
</ins><span class="cx"> 
</span><span class="cx"> struct IDBDatabaseMetadata;
</span><span class="cx"> struct IDBObjectStoreMetadata;
</span><span class="lines">@@ -63,7 +65,8 @@
</span><span class="cx">     virtual bool putRecord(const IDBTransactionIdentifier&amp;, int64_t objectStoreID, const WebCore::IDBKey&amp;, const uint8_t* valueBuffer, size_t valueSize) = 0;
</span><span class="cx">     virtual bool updateKeyGenerator(const IDBTransactionIdentifier&amp;, int64_t objectStoreId, const WebCore::IDBKey&amp;, bool checkCurrent) = 0;
</span><span class="cx"> 
</span><del>-
</del><ins>+    virtual bool getKeyRecordFromObjectStore(const IDBTransactionIdentifier&amp;, int64_t objectStoreID, const WebCore::IDBKey&amp;, RefPtr&lt;WebCore::SharedBuffer&gt;&amp; result) = 0;
+    virtual bool getKeyRangeRecordFromObjectStore(const IDBTransactionIdentifier&amp;, int64_t objectStoreID, const WebCore::IDBKeyRange&amp;, RefPtr&lt;WebCore::SharedBuffer&gt;&amp; result, RefPtr&lt;WebCore::IDBKey&gt;&amp; resultKey) = 0;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2DatabaseProcessIndexedDBsqliteUniqueIDBDatabaseBackingStoreSQLitecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp (162681 => 162682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp        2014-01-24 03:41:22 UTC (rev 162681)
+++ trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp        2014-01-24 03:52:30 UTC (rev 162682)
</span><span class="lines">@@ -34,8 +34,10 @@
</span><span class="cx"> #include &lt;WebCore/FileSystem.h&gt;
</span><span class="cx"> #include &lt;WebCore/IDBDatabaseMetadata.h&gt;
</span><span class="cx"> #include &lt;WebCore/IDBKeyData.h&gt;
</span><ins>+#include &lt;WebCore/IDBKeyRange.h&gt;
</ins><span class="cx"> #include &lt;WebCore/SQLiteDatabase.h&gt;
</span><span class="cx"> #include &lt;WebCore/SQLiteStatement.h&gt;
</span><ins>+#include &lt;WebCore/SharedBuffer.h&gt;
</ins><span class="cx"> #include &lt;wtf/MainThread.h&gt;
</span><span class="cx"> 
</span><span class="cx"> using namespace WebCore;
</span><span class="lines">@@ -90,7 +92,7 @@
</span><span class="cx">         return nullptr;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (!m_sqliteDB-&gt;executeCommand(&quot;CREATE TABLE Records (objectStoreID INTEGER NOT NULL ON CONFLICT FAIL, key BLOB NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE, value BLOB NOT NULL ON CONFLICT FAIL);&quot;)) {
</del><ins>+    if (!m_sqliteDB-&gt;executeCommand(&quot;CREATE TABLE Records (objectStoreID INTEGER NOT NULL ON CONFLICT FAIL, key BLOB COLLATE IDBKEY NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE, value BLOB NOT NULL ON CONFLICT FAIL);&quot;)) {
</ins><span class="cx">         LOG_ERROR(&quot;Could not create Records table in database (%i) - %s&quot;, m_sqliteDB-&gt;lastError(), m_sqliteDB-&gt;lastErrorMsg());
</span><span class="cx">         m_sqliteDB = nullptr;
</span><span class="cx">         return nullptr;
</span><span class="lines">@@ -247,6 +249,11 @@
</span><span class="cx">     if (!m_sqliteDB)
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span><ins>+    RefPtr&lt;UniqueIDBDatabaseBackingStoreSQLite&gt; protector(this);
+    m_sqliteDB-&gt;setCollationFunction(&quot;IDBKEY&quot;, [this](int aLength, const void* a, int bLength, const void* b) {
+        return collate(aLength, a, bLength, b);
+    });
+
</ins><span class="cx">     std::unique_ptr&lt;IDBDatabaseMetadata&gt; metadata = extractExistingMetadata();
</span><span class="cx">     if (!metadata)
</span><span class="cx">         metadata = createAndPopulateInitialMetadata();
</span><span class="lines">@@ -476,7 +483,112 @@
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool UniqueIDBDatabaseBackingStoreSQLite::getKeyRecordFromObjectStore(const IDBTransactionIdentifier&amp; identifier, int64_t objectStoreID, const WebCore::IDBKey&amp; key, RefPtr&lt;WebCore::SharedBuffer&gt;&amp; result)
+{
+    ASSERT(!isMainThread());
+    ASSERT(m_sqliteDB);
+    ASSERT(m_sqliteDB-&gt;isOpen());
</ins><span class="cx"> 
</span><ins>+    SQLiteIDBTransaction* transaction = m_transactions.get(identifier);
+    if (!transaction || !transaction-&gt;inProgress()) {
+        LOG_ERROR(&quot;Attempt to put a record into database without an established, in-progress transaction&quot;);
+        return false;
+    }
+
+    RefPtr&lt;SharedBuffer&gt; keyBuffer = serializeIDBKey(key);
+    if (!keyBuffer) {
+        LOG_ERROR(&quot;Unable to serialize IDBKey to be stored in the database&quot;);
+        return false;
+    }
+
+    {
+        SQLiteStatement sql(*m_sqliteDB, ASCIILiteral(&quot;SELECT value FROM Records WHERE objectStoreID = ? AND key = ?;&quot;));
+        if (sql.prepare() != SQLResultOk
+            || sql.bindInt64(1, objectStoreID) != SQLResultOk
+            || sql.bindBlob(2, keyBuffer-&gt;data(), keyBuffer-&gt;size()) != SQLResultOk) {
+            LOG_ERROR(&quot;Could not get record from object store %lli from Records table (%i) - %s&quot;, objectStoreID, m_sqliteDB-&gt;lastError(), m_sqliteDB-&gt;lastErrorMsg());
+            return false;
+        }
+
+        int sqlResult = sql.step();
+        if (sqlResult == SQLResultOk || sqlResult == SQLResultDone) {
+            // There was no record for the key in the database.
+            return true;
+        }
+        if (sqlResult != SQLResultRow) {
+            // There was an error fetching the record from the database.
+            LOG_ERROR(&quot;Could not get record from object store %lli from Records table (%i) - %s&quot;, objectStoreID, m_sqliteDB-&gt;lastError(), m_sqliteDB-&gt;lastErrorMsg());
+            return false;
+        }
+
+        Vector&lt;char&gt; buffer;
+        sql.getColumnBlobAsVector(0, buffer);
+        result = SharedBuffer::create(static_cast&lt;const char*&gt;(buffer.data()), buffer.size());
+    }
+
+    return true;
+}
+
+bool UniqueIDBDatabaseBackingStoreSQLite::getKeyRangeRecordFromObjectStore(const IDBTransactionIdentifier&amp; identifier, int64_t objectStoreID, const WebCore::IDBKeyRange&amp; keyRange, RefPtr&lt;WebCore::SharedBuffer&gt;&amp; result, RefPtr&lt;WebCore::IDBKey&gt;&amp; resultKey)
+{
+    ASSERT(!isMainThread());
+    ASSERT(m_sqliteDB);
+    ASSERT(m_sqliteDB-&gt;isOpen());
+
+    SQLiteIDBTransaction* transaction = m_transactions.get(identifier);
+    if (!transaction || !transaction-&gt;inProgress()) {
+        LOG_ERROR(&quot;Attempt to put a record into database without an established, in-progress transaction&quot;);
+        return false;
+    }
+
+    RefPtr&lt;SharedBuffer&gt; lowerBuffer = serializeIDBKey(*keyRange.lower());
+    if (!lowerBuffer) {
+        LOG_ERROR(&quot;Unable to serialize IDBKey to be stored in the database&quot;);
+        return false;
+    }
+
+    RefPtr&lt;SharedBuffer&gt; upperBuffer = serializeIDBKey(*keyRange.upper());
+    if (!upperBuffer) {
+        LOG_ERROR(&quot;Unable to serialize IDBKey to be stored in the database&quot;);
+        return false;
+    }
+
+    {
+        SQLiteStatement sql(*m_sqliteDB, ASCIILiteral(&quot;SELECT value FROM Records WHERE objectStoreID = ? AND key &gt;= ? AND key &lt;= ? ORDER BY key;&quot;));
+        if (sql.prepare() != SQLResultOk
+            || sql.bindInt64(1, objectStoreID) != SQLResultOk
+            || sql.bindBlob(2, lowerBuffer-&gt;data(), lowerBuffer-&gt;size()) != SQLResultOk
+            || sql.bindBlob(3, upperBuffer-&gt;data(), upperBuffer-&gt;size()) != SQLResultOk) {
+            LOG_ERROR(&quot;Could not get key range record from object store %lli from Records table (%i) - %s&quot;, objectStoreID, m_sqliteDB-&gt;lastError(), m_sqliteDB-&gt;lastErrorMsg());
+            return false;
+        }
+
+        int sqlResult = sql.step();
+
+        if (sqlResult == SQLResultOk || sqlResult == SQLResultDone) {
+            // There was no record for the key in the database.
+            return true;
+        }
+        if (sqlResult != SQLResultRow) {
+            // There was an error fetching the record from the database.
+            LOG_ERROR(&quot;Could not get record from object store %lli from Records table (%i) - %s&quot;, objectStoreID, m_sqliteDB-&gt;lastError(), m_sqliteDB-&gt;lastErrorMsg());
+            return false;
+        }
+
+        Vector&lt;char&gt; buffer;
+        sql.getColumnBlobAsVector(0, buffer);
+        result = SharedBuffer::create(static_cast&lt;const char*&gt;(buffer.data()), buffer.size());
+    }
+
+    return true;
+}
+
+int UniqueIDBDatabaseBackingStoreSQLite::collate(int aLength, const void* a, int bLength, const void* b)
+{
+    // FIXME: Implement
+    return 0;
+}
+
</ins><span class="cx"> } // namespace WebKit
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(INDEXED_DATABASE) &amp;&amp; ENABLE(DATABASE_PROCESS)
</span></span></pre></div>
<a id="trunkSourceWebKit2DatabaseProcessIndexedDBsqliteUniqueIDBDatabaseBackingStoreSQLiteh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h (162681 => 162682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h        2014-01-24 03:41:22 UTC (rev 162681)
+++ trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h        2014-01-24 03:52:30 UTC (rev 162682)
</span><span class="lines">@@ -69,6 +69,9 @@
</span><span class="cx">     virtual bool putRecord(const IDBTransactionIdentifier&amp;, int64_t objectStoreID, const WebCore::IDBKey&amp;, const uint8_t* valueBuffer, size_t valueSize) override;
</span><span class="cx">     virtual bool updateKeyGenerator(const IDBTransactionIdentifier&amp;, int64_t objectStoreId, const WebCore::IDBKey&amp;, bool checkCurrent) override;
</span><span class="cx"> 
</span><ins>+    virtual bool getKeyRecordFromObjectStore(const IDBTransactionIdentifier&amp;, int64_t objectStoreID, const WebCore::IDBKey&amp;, RefPtr&lt;WebCore::SharedBuffer&gt;&amp; result) override;
+    virtual bool getKeyRangeRecordFromObjectStore(const IDBTransactionIdentifier&amp;, int64_t objectStoreID, const WebCore::IDBKeyRange&amp;, RefPtr&lt;WebCore::SharedBuffer&gt;&amp; result, RefPtr&lt;WebCore::IDBKey&gt;&amp; resultKey) override;
+
</ins><span class="cx"> private:
</span><span class="cx">     UniqueIDBDatabaseBackingStoreSQLite(const UniqueIDBDatabaseIdentifier&amp;, const String&amp; databaseDirectory);
</span><span class="cx"> 
</span><span class="lines">@@ -76,6 +79,8 @@
</span><span class="cx">     std::unique_ptr&lt;WebCore::IDBDatabaseMetadata&gt; extractExistingMetadata();
</span><span class="cx">     std::unique_ptr&lt;WebCore::IDBDatabaseMetadata&gt; createAndPopulateInitialMetadata();
</span><span class="cx"> 
</span><ins>+    int collate(int aLength, const void* a, int bLength, const void* b);
+
</ins><span class="cx">     UniqueIDBDatabaseIdentifier m_identifier;
</span><span class="cx">     String m_absoluteDatabaseDirectory;
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>