void DatabaseSync::changeVersion(const String& oldVersion, const String& newVersion, PassOwnPtr<SQLTransactionSyncCallback> changeVersionCallback, ExceptionState& exceptionState) { ASSERT(m_executionContext->isContextThread()); if (sqliteDatabase().transactionInProgress()) { reportChangeVersionResult(1, SQLError::DATABASE_ERR, 0); setLastErrorMessage("unable to changeVersion from within a transaction"); exceptionState.throwUninformativeAndGenericDOMException(SQLDatabaseError); return; } RefPtr<SQLTransactionSync> transaction = SQLTransactionSync::create(this, changeVersionCallback, false); transaction->begin(exceptionState); if (exceptionState.hadException()) { ASSERT(!lastErrorMessage().isEmpty()); return; } String actualVersion; if (!getVersionFromDatabase(actualVersion)) { reportChangeVersionResult(2, SQLError::UNKNOWN_ERR, sqliteDatabase().lastError()); setLastErrorMessage("unable to read the current version", sqliteDatabase().lastError(), sqliteDatabase().lastErrorMsg()); exceptionState.throwDOMException(UnknownError, SQLError::unknownErrorMessage); return; } if (actualVersion != oldVersion) { reportChangeVersionResult(3, SQLError::VERSION_ERR, 0); setLastErrorMessage("current version of the database and `oldVersion` argument do not match"); exceptionState.throwDOMException(VersionError, SQLError::versionErrorMessage); return; } transaction->execute(exceptionState); if (exceptionState.hadException()) { ASSERT(!lastErrorMessage().isEmpty()); return; } if (!setVersionInDatabase(newVersion)) { reportChangeVersionResult(4, SQLError::UNKNOWN_ERR, sqliteDatabase().lastError()); setLastErrorMessage("unable to set the new version", sqliteDatabase().lastError(), sqliteDatabase().lastErrorMsg()); exceptionState.throwDOMException(UnknownError, SQLError::unknownErrorMessage); return; } transaction->commit(exceptionState); if (exceptionState.hadException()) { ASSERT(!lastErrorMessage().isEmpty()); setCachedVersion(oldVersion); return; } reportChangeVersionResult(0, -1, 0); // OK setExpectedVersion(newVersion); setLastErrorMessage(""); }
void DatabaseSync::changeVersion(const String& oldVersion, const String& newVersion, PassRefPtr<SQLTransactionSyncCallback> changeVersionCallback, ExceptionCode& ec) { ASSERT(m_scriptExecutionContext->isContextThread()); if (sqliteDatabase().transactionInProgress()) { reportChangeVersionResult(1, SQLException::DATABASE_ERR, 0); setLastErrorMessage("unable to changeVersion from within a transaction"); ec = SQLException::DATABASE_ERR; return; } RefPtr<SQLTransactionSync> transaction = SQLTransactionSync::create(this, changeVersionCallback, false); if ((ec = transaction->begin())) { ASSERT(!lastErrorMessage().isEmpty()); return; } String actualVersion; if (!getVersionFromDatabase(actualVersion)) { reportChangeVersionResult(2, SQLException::UNKNOWN_ERR, sqliteDatabase().lastError()); setLastErrorMessage("unable to read the current version", sqliteDatabase().lastError(), sqliteDatabase().lastErrorMsg()); ec = SQLException::UNKNOWN_ERR; return; } if (actualVersion != oldVersion) { reportChangeVersionResult(3, SQLException::VERSION_ERR, 0); setLastErrorMessage("current version of the database and `oldVersion` argument do not match"); ec = SQLException::VERSION_ERR; return; } if ((ec = transaction->execute())) { ASSERT(!lastErrorMessage().isEmpty()); return; } if (!setVersionInDatabase(newVersion)) { reportChangeVersionResult(4, SQLException::UNKNOWN_ERR, sqliteDatabase().lastError()); setLastErrorMessage("unable to set the new version", sqliteDatabase().lastError(), sqliteDatabase().lastErrorMsg()); ec = SQLException::UNKNOWN_ERR; return; } if ((ec = transaction->commit())) { ASSERT(!lastErrorMessage().isEmpty()); setCachedVersion(oldVersion); return; } reportChangeVersionResult(0, -1, 0); // OK setExpectedVersion(newVersion); setLastErrorMessage(""); }