<!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>[163417] trunk</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/163417">163417</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2014-02-04 16:26:59 -0800 (Tue, 04 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>IDB: indexeddb/mozilla/add-twice-failure.html fails
&lt;rdar://problem/15982569&gt; and https://bugs.webkit.org/show_bug.cgi?id=128208

Reviewed by Tim Horton.

Source/WebCore:

Covered specifically by indexeddb/mozilla/add-twice-failure.html and a handful of others.

* Modules/indexeddb/IDBRequest.cpp:
(WebCore::IDBRequest::onError): Improve logging.

* Modules/indexeddb/IDBTransactionBackend.cpp:
(WebCore::IDBTransactionBackend::abort): Improve logging.

* Modules/indexeddb/IDBTransactionBackendOperations.cpp:
(WebCore::PutOperation::perform): Don’t abort the transaction when an error occurred.

* WebCore.exp.in:

Source/WebKit2:

Note that besides making indexeddb/mozilla/add-twice-failure.html pass this also makes some other tests
pass and also improves the failure modes of others.

A full accounting of which tests pass is coming soon.

* DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp:
(WebKit::UniqueIDBDatabase::putRecordInBackingStore): After checking for existence of the key and before
  adding the record, remove any previous record. (Defined by the spec, found exploring this test).

* DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h:
* DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp:
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::keyExistsInObjectStore): Implement this.
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::deleteRecord): Add a form to be used as mentioned above in
  UniqueIDBDatabase::putRecordInBackingStore.
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::getKeyRecordFromObjectStore): CAST the key argument properly.
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::getKeyRangeRecordFromObjectStore): Ditto.
* DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h:

LayoutTests:

* platform/mac-wk2/TestExpectations: Reenable this test for WK2</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformmacwk2TestExpectations">trunk/LayoutTests/platform/mac-wk2/TestExpectations</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbIDBRequestcpp">trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbIDBTransactionBackendcpp">trunk/Source/WebCore/Modules/indexeddb/IDBTransactionBackend.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbIDBTransactionBackendOperationscpp">trunk/Source/WebCore/Modules/indexeddb/IDBTransactionBackendOperations.cpp</a></li>
<li><a href="#trunkSourceWebCoreWebCoreexpin">trunk/Source/WebCore/WebCore.exp.in</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="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (163416 => 163417)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-02-05 00:23:26 UTC (rev 163416)
+++ trunk/LayoutTests/ChangeLog        2014-02-05 00:26:59 UTC (rev 163417)
</span><span class="lines">@@ -1,3 +1,12 @@
</span><ins>+2014-02-04  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        IDB: indexeddb/mozilla/add-twice-failure.html fails
+        &lt;rdar://problem/15982569&gt; and https://bugs.webkit.org/show_bug.cgi?id=128208
+
+        Reviewed by Tim Horton.
+
+        * platform/mac-wk2/TestExpectations: Reenable this test for WK2
+
</ins><span class="cx"> 2014-02-04  Yoav Weiss  &lt;yoav@yoav.ws&gt;
</span><span class="cx"> 
</span><span class="cx">         Use srcset's pixel density to determine intrinsic size
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacwk2TestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac-wk2/TestExpectations (163416 => 163417)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac-wk2/TestExpectations        2014-02-05 00:23:26 UTC (rev 163416)
+++ trunk/LayoutTests/platform/mac-wk2/TestExpectations        2014-02-05 00:26:59 UTC (rev 163417)
</span><span class="lines">@@ -464,6 +464,10 @@
</span><span class="cx"> # This test times out in WebKit1 only.
</span><span class="cx"> fullscreen/anonymous-block-merge-crash.html [ Pass ]
</span><span class="cx"> 
</span><ins>+# All IndexedDB tests are skipped in WK1.
+# Reenable individual tests here that are known to pass, with the eventual goal of re-enabling the entire directory.
+storage/indexeddb/mozilla/add-twice-failure.html [ Pass ]
+
</ins><span class="cx"> ### END OF (5) Features that are not supported in WebKit1, so skipped in mac/TestExpectations then re-enabled here
</span><span class="cx"> ########################################
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (163416 => 163417)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-02-05 00:23:26 UTC (rev 163416)
+++ trunk/Source/WebCore/ChangeLog        2014-02-05 00:26:59 UTC (rev 163417)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2014-02-04  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        IDB: indexeddb/mozilla/add-twice-failure.html fails
+        &lt;rdar://problem/15982569&gt; and https://bugs.webkit.org/show_bug.cgi?id=128208
+
+        Reviewed by Tim Horton.
+
+        Covered specifically by indexeddb/mozilla/add-twice-failure.html and a handful of others.
+
+        * Modules/indexeddb/IDBRequest.cpp:
+        (WebCore::IDBRequest::onError): Improve logging.
+
+        * Modules/indexeddb/IDBTransactionBackend.cpp:
+        (WebCore::IDBTransactionBackend::abort): Improve logging.
+
+        * Modules/indexeddb/IDBTransactionBackendOperations.cpp:
+        (WebCore::PutOperation::perform): Don’t abort the transaction when an error occurred.
+
+        * WebCore.exp.in:
+
</ins><span class="cx"> 2014-02-04  Yoav Weiss  &lt;yoav@yoav.ws&gt;
</span><span class="cx"> 
</span><span class="cx">         Use srcset's pixel density to determine intrinsic size
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbIDBRequestcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp (163416 => 163417)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp        2014-02-05 00:23:26 UTC (rev 163416)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp        2014-02-05 00:26:59 UTC (rev 163417)
</span><span class="lines">@@ -249,7 +249,7 @@
</span><span class="cx"> 
</span><span class="cx"> void IDBRequest::onError(PassRefPtr&lt;IDBDatabaseError&gt; error)
</span><span class="cx"> {
</span><del>-    LOG(StorageAPI, &quot;IDBRequest::onError()&quot;);
</del><ins>+    LOG(StorageAPI, &quot;IDBRequest::onError() (%s) '%s'&quot;, error-&gt;name().utf8().data(), error-&gt;message().utf8().data());
</ins><span class="cx">     if (!shouldEnqueueEvent())
</span><span class="cx">         return;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbIDBTransactionBackendcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/IDBTransactionBackend.cpp (163416 => 163417)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/IDBTransactionBackend.cpp        2014-02-05 00:23:26 UTC (rev 163416)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBTransactionBackend.cpp        2014-02-05 00:26:59 UTC (rev 163417)
</span><span class="lines">@@ -116,7 +116,13 @@
</span><span class="cx"> 
</span><span class="cx"> void IDBTransactionBackend::abort(PassRefPtr&lt;IDBDatabaseError&gt; error)
</span><span class="cx"> {
</span><del>-    LOG(StorageAPI, &quot;IDBTransactionBackend::abort&quot;);
</del><ins>+#ifndef NDEBUG
+    if (error)
+        LOG(StorageAPI, &quot;IDBTransactionBackend::abort - (%s) %s&quot;, error-&gt;name().utf8().data(), error-&gt;message().utf8().data());
+    else
+        LOG(StorageAPI, &quot;IDBTransactionBackend::abort (no error)&quot;);
+#endif
+
</ins><span class="cx">     if (m_state == Finished)
</span><span class="cx">         return;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbIDBTransactionBackendOperationscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/IDBTransactionBackendOperations.cpp (163416 => 163417)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/IDBTransactionBackendOperations.cpp        2014-02-05 00:23:26 UTC (rev 163416)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBTransactionBackendOperations.cpp        2014-02-05 00:26:59 UTC (rev 163417)
</span><span class="lines">@@ -123,10 +123,7 @@
</span><span class="cx">     ASSERT(m_transaction-&gt;mode() != IndexedDB::TransactionMode::ReadOnly);
</span><span class="cx">     ASSERT(m_indexIDs.size() == m_indexKeys.size());
</span><span class="cx"> 
</span><del>-    RefPtr&lt;PutOperation&gt; operation(this);
-    STANDARD_DATABASE_ERROR_CALLBACK;
-
-    m_transaction-&gt;database().serverConnection().put(*m_transaction, *this, [this, operation, operationCallback](PassRefPtr&lt;IDBKey&gt; key, PassRefPtr&lt;IDBDatabaseError&gt; prpError) {
</del><ins>+    m_transaction-&gt;database().serverConnection().put(*m_transaction, *this, [this, completionCallback](PassRefPtr&lt;IDBKey&gt; key, PassRefPtr&lt;IDBDatabaseError&gt; prpError) {
</ins><span class="cx">         RefPtr&lt;IDBDatabaseError&gt; error = prpError;
</span><span class="cx">         if (key) {
</span><span class="cx">             ASSERT(!error);
</span><span class="lines">@@ -135,7 +132,7 @@
</span><span class="cx">             ASSERT(error);
</span><span class="cx">             m_callbacks-&gt;onError(error);
</span><span class="cx">         }
</span><del>-        operationCallback(error.release());
</del><ins>+        completionCallback();
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCoreexpin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.exp.in (163416 => 163417)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.exp.in        2014-02-05 00:23:26 UTC (rev 163416)
+++ trunk/Source/WebCore/WebCore.exp.in        2014-02-05 00:26:59 UTC (rev 163417)
</span><span class="lines">@@ -774,6 +774,7 @@
</span><span class="cx"> __ZN7WebCore19PlatformCAAnimation6createEP19CAPropertyAnimation
</span><span class="cx"> __ZN7WebCore19PlatformCAAnimation10setToValueERKNS_20TransformationMatrixE
</span><span class="cx"> __ZN7WebCore19PlatformCAAnimationD1Ev
</span><ins>+__ZN7WebCore19SQLResultConstraintE
</ins><span class="cx"> __ZN7WebCore19TextResourceDecoder5flushEv
</span><span class="cx"> __ZN7WebCore19TextResourceDecoder6decodeEPKcm
</span><span class="cx"> __ZN7WebCore19TextResourceDecoderC1ERKN3WTF6StringERKNS_12TextEncodingEb
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (163416 => 163417)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-02-05 00:23:26 UTC (rev 163416)
+++ trunk/Source/WebKit2/ChangeLog        2014-02-05 00:26:59 UTC (rev 163417)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2014-02-04  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        IDB: indexeddb/mozilla/add-twice-failure.html fails
+        &lt;rdar://problem/15982569&gt; and https://bugs.webkit.org/show_bug.cgi?id=128208
+
+        Reviewed by Tim Horton.
+
+        Note that besides making indexeddb/mozilla/add-twice-failure.html pass this also makes some other tests
+        pass and also improves the failure modes of others.
+
+        A full accounting of which tests pass is coming soon.
+
+        * DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp:
+        (WebKit::UniqueIDBDatabase::putRecordInBackingStore): After checking for existence of the key and before
+          adding the record, remove any previous record. (Defined by the spec, found exploring this test).
+
+        * DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h:
+        * DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp:
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::keyExistsInObjectStore): Implement this.
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::deleteRecord): Add a form to be used as mentioned above in
+          UniqueIDBDatabase::putRecordInBackingStore.
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::getKeyRecordFromObjectStore): CAST the key argument properly.
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::getKeyRangeRecordFromObjectStore): Ditto.
+        * DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h:
+
</ins><span class="cx"> 2014-02-04  Dan Bernstein  &lt;mitz@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Cocoa] Expose more WKWebProcessPlugInNodeHandle properties
</span></span></pre></div>
<a id="trunkSourceWebKit2DatabaseProcessIndexedDBUniqueIDBDatabasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp (163416 => 163417)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp        2014-02-05 00:23:26 UTC (rev 163416)
+++ trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabase.cpp        2014-02-05 00:26:59 UTC (rev 163417)
</span><span class="lines">@@ -837,7 +837,7 @@
</span><span class="cx"> 
</span><span class="cx">     if (putMode == IDBDatabaseBackend::AddOnly) {
</span><span class="cx">         bool keyExists;
</span><del>-        if (!m_backingStore-&gt;keyExistsInObjectStore(transaction, objectStoreMetadata.id, *key, keyExists)) {
</del><ins>+        if (!m_backingStore-&gt;keyExistsInObjectStore(transaction, objectStoreMetadata.id, keyData, keyExists)) {
</ins><span class="cx">             postMainThreadTask(createAsyncTask(*this, &amp;UniqueIDBDatabase::didPutRecordInBackingStore, requestID, IDBKeyData(), IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Internal backing store error checking for key existence&quot;)));
</span><span class="cx">             return;
</span><span class="cx">         }
</span><span class="lines">@@ -847,6 +847,13 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    // The spec says that even if we're about to overwrite the record, perform the steps to delete it first.
+    // This is important because formally deleting it from from the object store also removes it from the appropriate indexes.
+    if (!m_backingStore-&gt;deleteRecord(transaction, objectStoreMetadata.id, keyData)) {
+        postMainThreadTask(createAsyncTask(*this, &amp;UniqueIDBDatabase::didPutRecordInBackingStore, requestID, IDBKeyData(), IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Replacing an existing key in backing store, unable to delete previous record.&quot;)));
+        return;
+    }
+
</ins><span class="cx">     if (!m_backingStore-&gt;putRecord(transaction, objectStoreMetadata.id, *key, value.data(), value.size())) {
</span><span class="cx">         postMainThreadTask(createAsyncTask(*this, &amp;UniqueIDBDatabase::didPutRecordInBackingStore, requestID, IDBKeyData(), IDBDatabaseException::UnknownError, ASCIILiteral(&quot;Internal backing store error putting a record&quot;)));
</span><span class="cx">         return;
</span></span></pre></div>
<a id="trunkSourceWebKit2DatabaseProcessIndexedDBUniqueIDBDatabaseBackingStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h (163416 => 163417)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h        2014-02-05 00:23:26 UTC (rev 163416)
+++ trunk/Source/WebKit2/DatabaseProcess/IndexedDB/UniqueIDBDatabaseBackingStore.h        2014-02-05 00:26:59 UTC (rev 163417)
</span><span class="lines">@@ -37,6 +37,7 @@
</span><span class="cx"> class SharedBuffer;
</span><span class="cx"> 
</span><span class="cx"> struct IDBDatabaseMetadata;
</span><ins>+struct IDBKeyData;
</ins><span class="cx"> struct IDBObjectStoreMetadata;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -66,11 +67,12 @@
</span><span class="cx">     virtual bool generateKeyNumber(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, int64_t&amp; generatedKey) = 0;
</span><span class="cx">     virtual bool updateKeyGeneratorNumber(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreId, int64_t keyNumber, bool checkCurrent) = 0;
</span><span class="cx"> 
</span><del>-    virtual bool keyExistsInObjectStore(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKey&amp;, bool&amp; keyExists) = 0;
</del><ins>+    virtual bool keyExistsInObjectStore(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKeyData&amp;, bool&amp; keyExists) = 0;
</ins><span class="cx">     virtual bool putRecord(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKey&amp;, const uint8_t* valueBuffer, size_t valueSize) = 0;
</span><span class="cx">     virtual bool putIndexRecord(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, int64_t indexID, const WebCore::IDBKeyData&amp;, const WebCore::IDBKeyData&amp; indexKey) = 0;
</span><span class="cx">     virtual bool getIndexRecord(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, int64_t indexID, const WebCore::IDBKeyRangeData&amp;, RefPtr&lt;WebCore::SharedBuffer&gt;&amp; result) = 0;
</span><span class="cx">     virtual bool deleteRange(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKeyRangeData&amp;) = 0;
</span><ins>+    virtual bool deleteRecord(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKeyData&amp;) = 0;
</ins><span class="cx"> 
</span><span class="cx">     virtual bool getKeyRecordFromObjectStore(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKey&amp;, RefPtr&lt;WebCore::SharedBuffer&gt;&amp; result) = 0;
</span><span class="cx">     virtual bool getKeyRangeRecordFromObjectStore(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKeyRange&amp;, RefPtr&lt;WebCore::SharedBuffer&gt;&amp; result, RefPtr&lt;WebCore::IDBKey&gt;&amp; resultKey) = 0;
</span></span></pre></div>
<a id="trunkSourceWebKit2DatabaseProcessIndexedDBsqliteUniqueIDBDatabaseBackingStoreSQLitecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp (163416 => 163417)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp        2014-02-05 00:23:26 UTC (rev 163416)
+++ trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp        2014-02-05 00:26:59 UTC (rev 163417)
</span><span class="lines">@@ -728,10 +728,48 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool UniqueIDBDatabaseBackingStoreSQLite::keyExistsInObjectStore(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, const IDBKey&amp;, bool&amp; keyExists)
</del><ins>+bool UniqueIDBDatabaseBackingStoreSQLite::keyExistsInObjectStore(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, const IDBKeyData&amp; keyData, bool&amp; keyExists)
</ins><span class="cx"> {
</span><del>-    // FIXME: When Get support is implemented, we need to implement this also (&lt;rdar://problem/15779644&gt;)
-    return false;
</del><ins>+    ASSERT(!isMainThread());
+    ASSERT(m_sqliteDB);
+    ASSERT(m_sqliteDB-&gt;isOpen());
+
+    keyExists = false;
+
+    SQLiteIDBTransaction* transaction = m_transactions.get(transactionIdentifier);
+    if (!transaction || !transaction-&gt;inProgress()) {
+        LOG_ERROR(&quot;Attempt to see if key exists in objectstore without established, in-progress transaction&quot;);
+        return false;
+    }
+
+    RefPtr&lt;SharedBuffer&gt; keyBuffer = serializeIDBKeyData(keyData);
+    if (!keyBuffer) {
+        LOG_ERROR(&quot;Unable to serialize IDBKey to check for existence&quot;);
+        return false;
+    }
+
+    SQLiteStatement sql(*m_sqliteDB, ASCIILiteral(&quot;SELECT key FROM Records WHERE objectStoreID = ? AND key = CAST(? AS TEXT) LIMIT 1;&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) {
+        keyExists = false;
+        return true;
+    }
+
+    if (sqlResult != SQLResultRow) {
+        // There was an error fetching the record from the database.
+        LOG_ERROR(&quot;Could not check if key exists in object store (%i) - %s&quot;, m_sqliteDB-&gt;lastError(), m_sqliteDB-&gt;lastErrorMsg());
+        return false;
+    }
+
+    keyExists = true;
+    return true;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool UniqueIDBDatabaseBackingStoreSQLite::putRecord(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, const IDBKey&amp; key, const uint8_t* valueBuffer, size_t valueSize)
</span><span class="lines">@@ -843,6 +881,26 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool UniqueIDBDatabaseBackingStoreSQLite::deleteRecord(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKeyData&amp; keyData)
+{
+    ASSERT(!isMainThread());
+    ASSERT(m_sqliteDB);
+    ASSERT(m_sqliteDB-&gt;isOpen());
+
+    SQLiteIDBTransaction* transaction = m_transactions.get(transactionIdentifier);
+    if (!transaction || !transaction-&gt;inProgress()) {
+        LOG_ERROR(&quot;Attempt to get count from database without an established, in-progress transaction&quot;);
+        return false;
+    }
+
+    if (transaction-&gt;mode() == IndexedDB::TransactionMode::ReadOnly) {
+        LOG_ERROR(&quot;Attempt to delete range from a read-only transaction&quot;);
+        return false;
+    }
+
+    return deleteRecord(*transaction, objectStoreID, keyData);
+}
+
</ins><span class="cx"> bool UniqueIDBDatabaseBackingStoreSQLite::deleteRange(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, const IDBKeyRangeData&amp; keyRangeData)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!isMainThread());
</span><span class="lines">@@ -964,7 +1022,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     {
</span><del>-        SQLiteStatement sql(*m_sqliteDB, ASCIILiteral(&quot;SELECT value FROM Records WHERE objectStoreID = ? AND key = ?;&quot;));
</del><ins>+        SQLiteStatement sql(*m_sqliteDB, ASCIILiteral(&quot;SELECT value FROM Records WHERE objectStoreID = ? AND key = CAST(? AS TEXT);&quot;));
</ins><span class="cx">         if (sql.prepare() != SQLResultOk
</span><span class="cx">             || sql.bindInt64(1, objectStoreID) != SQLResultOk
</span><span class="cx">             || sql.bindBlob(2, keyBuffer-&gt;data(), keyBuffer-&gt;size()) != SQLResultOk) {
</span><span class="lines">@@ -1016,7 +1074,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     {
</span><del>-        SQLiteStatement sql(*m_sqliteDB, ASCIILiteral(&quot;SELECT value FROM Records WHERE objectStoreID = ? AND key &gt;= ? AND key &lt;= ? ORDER BY key;&quot;));
</del><ins>+        SQLiteStatement sql(*m_sqliteDB, ASCIILiteral(&quot;SELECT value FROM Records WHERE objectStoreID = ? AND key &gt;= CAST(? AS TEXT) AND key &lt;= CAST(? AS TEXT) ORDER BY key;&quot;));
</ins><span class="cx">         if (sql.prepare() != SQLResultOk
</span><span class="cx">             || sql.bindInt64(1, objectStoreID) != SQLResultOk
</span><span class="cx">             || sql.bindBlob(2, lowerBuffer-&gt;data(), lowerBuffer-&gt;size()) != SQLResultOk
</span></span></pre></div>
<a id="trunkSourceWebKit2DatabaseProcessIndexedDBsqliteUniqueIDBDatabaseBackingStoreSQLiteh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h (163416 => 163417)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h        2014-02-05 00:23:26 UTC (rev 163416)
+++ trunk/Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.h        2014-02-05 00:26:59 UTC (rev 163417)
</span><span class="lines">@@ -71,11 +71,12 @@
</span><span class="cx">     virtual bool generateKeyNumber(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, int64_t&amp; generatedKey) override;
</span><span class="cx">     virtual bool updateKeyGeneratorNumber(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreId, int64_t keyNumber, bool checkCurrent) override;
</span><span class="cx"> 
</span><del>-    virtual bool keyExistsInObjectStore(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKey&amp;, bool&amp; keyExists) override;
</del><ins>+    virtual bool keyExistsInObjectStore(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKeyData&amp;, bool&amp; keyExists) override;
</ins><span class="cx">     virtual bool putRecord(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKey&amp;, const uint8_t* valueBuffer, size_t valueSize) override;
</span><span class="cx">     virtual bool putIndexRecord(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, int64_t indexID, const WebCore::IDBKeyData&amp; keyValue, const WebCore::IDBKeyData&amp; indexKey) override;
</span><span class="cx">     virtual bool getIndexRecord(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, int64_t indexID, const WebCore::IDBKeyRangeData&amp;, RefPtr&lt;WebCore::SharedBuffer&gt;&amp; result) override;
</span><span class="cx">     virtual bool deleteRange(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKeyRangeData&amp;) override;
</span><ins>+    virtual bool deleteRecord(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKeyData&amp;) override;
</ins><span class="cx"> 
</span><span class="cx">     virtual bool getKeyRecordFromObjectStore(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKey&amp;, RefPtr&lt;WebCore::SharedBuffer&gt;&amp; result) override;
</span><span class="cx">     virtual bool getKeyRangeRecordFromObjectStore(const IDBIdentifier&amp; transactionIdentifier, int64_t objectStoreID, const WebCore::IDBKeyRange&amp;, RefPtr&lt;WebCore::SharedBuffer&gt;&amp; result, RefPtr&lt;WebCore::IDBKey&gt;&amp; resultKey) override;
</span></span></pre>
</div>
</div>

</body>
</html>