Fix savepoint rollback code

This commit is contained in:
Ben Turner 2010-06-02 20:08:23 -07:00
parent 86cff3e357
commit ed34b07500
3 changed files with 22 additions and 1 deletions

View File

@ -209,6 +209,22 @@ IDBTransactionRequest::ReleaseSavepoint()
return NS_OK;
}
void
IDBTransactionRequest::RollbackSavepoint()
{
NS_PRECONDITION(!NS_IsMainThread(), "Wrong thread!");
NS_PRECONDITION(mConnection, "No connection!");
NS_ASSERTION(mSavepointCount == 1, "Mismatch!");
mSavepointCount = 0;
// TODO try to cache this statement
NS_NAMED_LITERAL_CSTRING(savepoint, "ROLLBACK TO " SAVEPOINT_INTERMEDIATE);
if (NS_FAILED(mConnection->ExecuteSimpleSQL(savepoint))) {
NS_ERROR("Rollback failed!");
}
}
nsresult
IDBTransactionRequest::GetOrCreateConnection(mozIStorageConnection** aResult)
{

View File

@ -88,6 +88,7 @@ public:
bool StartSavepoint();
nsresult ReleaseSavepoint();
void RollbackSavepoint();
already_AddRefed<mozIStorageStatement> AddStatement(bool aCreate,
bool aOverwrite,

View File

@ -53,13 +53,17 @@ public:
: mTransaction(aTransaction)
, mHasSavepoint(false)
{
NS_ASSERTION(mTransaction, "Null pointer!");
mHasSavepoint = mTransaction->StartSavepoint();
NS_WARN_IF_FALSE(mHasSavepoint, "Failed to make savepoint!");
}
~Savepoint()
{
Release();
if (mHasSavepoint) {
mTransaction->RollbackSavepoint();
}
}
nsresult Release()