mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-29 04:17:55 +01:00
more callbacks and transaction tests
- added callbacks for commit and rollback with tests - added transaction tests
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
#include "Poco/ActiveMethod.h"
|
||||
#include "Poco/ActiveResult.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/Data/DataException.h"
|
||||
#include "sqlite3.h"
|
||||
#include <cstdlib>
|
||||
@@ -67,6 +68,9 @@ SessionImpl::SessionImpl(const std::string& fileName, std::size_t loginTimeout):
|
||||
open();
|
||||
setConnectionTimeout(CONNECTION_TIMEOUT_DEFAULT);
|
||||
setProperty("handle", _pDB);
|
||||
addFeature("autoCommit",
|
||||
&SessionImpl::autoCommit,
|
||||
&SessionImpl::isAutoCommit);
|
||||
}
|
||||
|
||||
|
||||
@@ -85,6 +89,7 @@ Poco::Data::StatementImpl* SessionImpl::createStatementImpl()
|
||||
|
||||
void SessionImpl::begin()
|
||||
{
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
SQLiteStatementImpl tmp(*this, _pDB);
|
||||
tmp.add(DEFERRED_BEGIN_TRANSACTION);
|
||||
tmp.execute();
|
||||
@@ -94,6 +99,7 @@ void SessionImpl::begin()
|
||||
|
||||
void SessionImpl::commit()
|
||||
{
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
SQLiteStatementImpl tmp(*this, _pDB);
|
||||
tmp.add(COMMIT_TRANSACTION);
|
||||
tmp.execute();
|
||||
@@ -103,6 +109,7 @@ void SessionImpl::commit()
|
||||
|
||||
void SessionImpl::rollback()
|
||||
{
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
SQLiteStatementImpl tmp(*this, _pDB);
|
||||
tmp.add(ABORT_TRANSACTION);
|
||||
tmp.execute();
|
||||
@@ -233,4 +240,21 @@ void SessionImpl::setConnectionTimeout(std::size_t timeout)
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::autoCommit(const std::string&, bool)
|
||||
{
|
||||
// The problem here is to decide whether to call commit or rollback
|
||||
// when autocommit is set to true. Hence, it is best not to implement
|
||||
// this explicit call and only implicitly support autocommit setting.
|
||||
throw NotImplementedException(
|
||||
"SQLite autocommit is implicit with begin/commit/rollback.");
|
||||
}
|
||||
|
||||
|
||||
bool SessionImpl::isAutoCommit(const std::string&)
|
||||
{
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
return (0 != sqlite3_get_autocommit(_pDB));
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
Reference in New Issue
Block a user