IDB: Cannot open new databases with the default version
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Feb 2014 06:19:25 +0000 (06:19 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Feb 2014 06:19:25 +0000 (06:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=128096

Reviewed by Tim Horton.

Source/WebCore:

* Modules/indexeddb/IDBDatabaseBackend.cpp:
(WebCore::IDBDatabaseBackend::openConnectionInternal): Update logic to handle the
  current version being NoIntVersion.

* Modules/indexeddb/IDBTransactionBackendOperations.cpp:
(WebCore::IDBDatabaseBackend::VersionChangeOperation::perform): Update ASSERT.

Source/WebKit2:

* DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp:
(WebKit::UniqueIDBDatabaseBackingStoreSQLite::createAndPopulateInitialMetadata): New databases should
  have the magic "no version set" version.

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBDatabaseBackend.cpp
Source/WebCore/Modules/indexeddb/IDBTransactionBackendOperations.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp

index 7590e62..d9c64f3 100644 (file)
@@ -1,3 +1,17 @@
+2014-02-02  Brady Eidson  <beidson@apple.com>
+
+        IDB: Cannot open new databases with the default version
+        https://bugs.webkit.org/show_bug.cgi?id=128096
+
+        Reviewed by Tim Horton.
+
+        * Modules/indexeddb/IDBDatabaseBackend.cpp:
+        (WebCore::IDBDatabaseBackend::openConnectionInternal): Update logic to handle the
+          current version being NoIntVersion.
+
+        * Modules/indexeddb/IDBTransactionBackendOperations.cpp:
+        (WebCore::IDBDatabaseBackend::VersionChangeOperation::perform): Update ASSERT.
+
 2014-02-02  Darin Adler  <darin@apple.com>
 
         Fix context save/restore mistake spotted in SVGInlineTextBox::paintTextWithShadows
index 999a167..12873ba 100644 (file)
@@ -463,31 +463,26 @@ void IDBDatabaseBackend::openConnectionInternal(PassRefPtr<IDBCallbacks> prpCall
     RefPtr<IDBCallbacks> callbacks = prpCallbacks;
     RefPtr<IDBDatabaseCallbacks> databaseCallbacks = prpDatabaseCallbacks;
 
-    // We infer that the database didn't exist from its lack of either type of version.
+    // We infer that the database didn't exist from its lack of version.
     bool isNewDatabase = m_metadata.version == IDBDatabaseMetadata::NoIntVersion;
 
-    if (version == IDBDatabaseMetadata::DefaultIntVersion) {
+    if (version == IDBDatabaseMetadata::DefaultIntVersion && !isNewDatabase) {
         m_databaseCallbacksSet.add(databaseCallbacks);
         callbacks->onSuccess(this, this->metadata());
         return;
     }
 
-    if (version == IDBDatabaseMetadata::NoIntVersion) {
-        if (!isNewDatabase) {
-            m_databaseCallbacksSet.add(RefPtr<IDBDatabaseCallbacks>(databaseCallbacks));
-            callbacks->onSuccess(this, this->metadata());
-            return;
-        }
+    if (isNewDatabase && version == IDBDatabaseMetadata::DefaultIntVersion) {
         // Spec says: If no version is specified and no database exists, set database version to 1.
         version = 1;
     }
 
-    if (version > m_metadata.version) {
+    if (version > m_metadata.version || m_metadata.version == IDBDatabaseMetadata::NoIntVersion) {
         runIntVersionChangeTransaction(callbacks, databaseCallbacks, transactionId, version);
         return;
     }
 
-    if (version < m_metadata.version) {
+    if (version < m_metadata.version && m_metadata.version != IDBDatabaseMetadata::NoIntVersion) {
         callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::VersionError, String::format("The requested version (%llu) is less than the existing version (%llu).", static_cast<unsigned long long>(version), static_cast<unsigned long long>(m_metadata.version))));
         return;
     }
index 4a757ef..8d92097 100644 (file)
@@ -243,7 +243,7 @@ void IDBDatabaseBackend::VersionChangeOperation::perform(std::function<void()> c
 
     uint64_t oldVersion = m_transaction->database().metadata().version;
     RefPtr<IDBDatabaseBackend::VersionChangeOperation> operation(this);
-    ASSERT(static_cast<uint64_t>(m_version) > oldVersion);
+    ASSERT(static_cast<uint64_t>(m_version) > oldVersion || oldVersion == IDBDatabaseMetadata::NoIntVersion);
 
     std::function<void(PassRefPtr<IDBDatabaseError>)> operationCallback = [oldVersion, operation, this, completionCallback](PassRefPtr<IDBDatabaseError> prpError) {
         RefPtr<IDBDatabaseError> error = prpError;
index 66f7991..82148ca 100644 (file)
@@ -1,3 +1,14 @@
+2014-02-02  Brady Eidson  <beidson@apple.com>
+
+        IDB: Cannot open new databases with the default version
+        https://bugs.webkit.org/show_bug.cgi?id=128096
+
+        Reviewed by Tim Horton.
+
+        * DatabaseProcess/IndexedDB/sqlite/UniqueIDBDatabaseBackingStoreSQLite.cpp:
+        (WebKit::UniqueIDBDatabaseBackingStoreSQLite::createAndPopulateInitialMetadata): New databases should
+          have the magic "no version set" version.
+
 2014-02-02  Sanghyup Lee  <sh53.lee@samsung.com>
 
         [EFL][WK2] Add a logic for checking multi touch in GestureRecognizer::noGesture
index 7bbfda1..fc03932 100644 (file)
@@ -140,7 +140,7 @@ std::unique_ptr<IDBDatabaseMetadata> UniqueIDBDatabaseBackingStoreSQLite::create
         // Therefore we'll store the version as a String.
         SQLiteStatement sql(*m_sqliteDB, ASCIILiteral("INSERT INTO IDBDatabaseInfo VALUES ('DatabaseVersion', ?);"));
         if (sql.prepare() != SQLResultOk
-            || sql.bindText(1, String::number(0)) != SQLResultOk
+            || sql.bindText(1, String::number(IDBDatabaseMetadata::NoIntVersion)) != SQLResultOk
             || sql.step() != SQLResultDone) {
             LOG_ERROR("Could not insert default version into IDBDatabaseInfo table (%i) - %s", m_sqliteDB->lastError(), m_sqliteDB->lastErrorMsg());
             m_sqliteDB = nullptr;
@@ -157,7 +157,7 @@ std::unique_ptr<IDBDatabaseMetadata> UniqueIDBDatabaseBackingStoreSQLite::create
     // This initial metadata matches the default values we just put into the metadata database.
     auto metadata = std::make_unique<IDBDatabaseMetadata>();
     metadata->name = m_identifier.databaseName();
-    metadata->version = 0;
+    metadata->version = IDBDatabaseMetadata::NoIntVersion;
     metadata->maxObjectStoreId = 1;
 
     return metadata;