This source file includes following definitions.
- m_newVersion
- performPreflight
- performPostflight
- handleCommitFailedAfterPostflight
#include "config.h"
#include "modules/webdatabase/ChangeVersionWrapper.h"
#include "modules/webdatabase/Database.h"
#include "modules/webdatabase/SQLError.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefPtr.h"
namespace WebCore {
ChangeVersionWrapper::ChangeVersionWrapper(const String& oldVersion, const String& newVersion)
: m_oldVersion(oldVersion.isolatedCopy())
, m_newVersion(newVersion.isolatedCopy())
{
}
bool ChangeVersionWrapper::performPreflight(SQLTransactionBackend* transaction)
{
ASSERT(transaction && transaction->database());
DatabaseBackend* database = transaction->database();
String actualVersion;
if (!database->getVersionFromDatabase(actualVersion)) {
int sqliteError = database->sqliteDatabase().lastError();
database->reportChangeVersionResult(1, SQLError::UNKNOWN_ERR, sqliteError);
m_sqlError = SQLErrorData::create(SQLError::UNKNOWN_ERR, "unable to read the current version",
sqliteError, database->sqliteDatabase().lastErrorMsg());
return false;
}
if (actualVersion != m_oldVersion) {
database->reportChangeVersionResult(2, SQLError::VERSION_ERR, 0);
m_sqlError = SQLErrorData::create(SQLError::VERSION_ERR, "current version of the database and `oldVersion` argument do not match");
return false;
}
return true;
}
bool ChangeVersionWrapper::performPostflight(SQLTransactionBackend* transaction)
{
ASSERT(transaction && transaction->database());
DatabaseBackend* database = transaction->database();
if (!database->setVersionInDatabase(m_newVersion)) {
int sqliteError = database->sqliteDatabase().lastError();
database->reportChangeVersionResult(3, SQLError::UNKNOWN_ERR, sqliteError);
m_sqlError = SQLErrorData::create(SQLError::UNKNOWN_ERR, "unable to set new version in database",
sqliteError, database->sqliteDatabase().lastErrorMsg());
return false;
}
database->setExpectedVersion(m_newVersion);
database->reportChangeVersionResult(0, -1, 0);
return true;
}
void ChangeVersionWrapper::handleCommitFailedAfterPostflight(SQLTransactionBackend* transaction)
{
transaction->database()->setCachedVersion(m_oldVersion);
}
}