mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-29 11:09:42 +01:00
added Session::isTransaction()
This commit is contained in:
parent
a04bae94d7
commit
dfbc0e1d24
@ -90,6 +90,9 @@ public:
|
|||||||
bool isConnected();
|
bool isConnected();
|
||||||
/// Returns true if session is connected
|
/// Returns true if session is connected
|
||||||
|
|
||||||
|
bool isTransaction();
|
||||||
|
/// Returns true iff a transaction is in progress.
|
||||||
|
|
||||||
void setEnforceCapability(const std::string&, bool val);
|
void setEnforceCapability(const std::string&, bool val);
|
||||||
/// Configures session to enforce driver capability check
|
/// Configures session to enforce driver capability check
|
||||||
/// after connection.
|
/// after connection.
|
||||||
|
@ -185,6 +185,20 @@ bool SessionImpl::isConnected()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool SessionImpl::isTransaction()
|
||||||
|
{
|
||||||
|
Poco::UInt32 value = 0;
|
||||||
|
|
||||||
|
checkError(SQLGetConnectAttr(_db,
|
||||||
|
SQL_ATTR_AUTOCOMMIT,
|
||||||
|
&value,
|
||||||
|
0,
|
||||||
|
0));
|
||||||
|
|
||||||
|
return (0 == value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SessionImpl::close()
|
void SessionImpl::close()
|
||||||
{
|
{
|
||||||
if (!isConnected()) return;
|
if (!isConnected()) return;
|
||||||
|
@ -83,6 +83,9 @@ public:
|
|||||||
bool isConnected();
|
bool isConnected();
|
||||||
/// Returns true if connected, false otherwise.
|
/// Returns true if connected, false otherwise.
|
||||||
|
|
||||||
|
bool isTransaction();
|
||||||
|
/// Returns true iff a transaction is in progress.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void open();
|
void open();
|
||||||
/// Opens a connection to the Database.
|
/// Opens a connection to the Database.
|
||||||
@ -90,6 +93,7 @@ private:
|
|||||||
std::string _dbFileName;
|
std::string _dbFileName;
|
||||||
sqlite3* _pDB;
|
sqlite3* _pDB;
|
||||||
bool _connected;
|
bool _connected;
|
||||||
|
bool _isTransaction;
|
||||||
|
|
||||||
static const std::string DEFERRED_BEGIN_TRANSACTION;
|
static const std::string DEFERRED_BEGIN_TRANSACTION;
|
||||||
static const std::string COMMIT_TRANSACTION;
|
static const std::string COMMIT_TRANSACTION;
|
||||||
@ -97,6 +101,15 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// inlines
|
||||||
|
//
|
||||||
|
inline bool SessionImpl::isTransaction()
|
||||||
|
{
|
||||||
|
return _isTransaction;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} } } // namespace Poco::Data::SQLite
|
} } } // namespace Poco::Data::SQLite
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,7 +54,8 @@ const std::string SessionImpl::ABORT_TRANSACTION("ROLLBACK");
|
|||||||
SessionImpl::SessionImpl(const std::string& fileName):
|
SessionImpl::SessionImpl(const std::string& fileName):
|
||||||
_dbFileName(fileName),
|
_dbFileName(fileName),
|
||||||
_pDB(0),
|
_pDB(0),
|
||||||
_connected(false)
|
_connected(false),
|
||||||
|
_isTransaction(false)
|
||||||
{
|
{
|
||||||
open();
|
open();
|
||||||
}
|
}
|
||||||
@ -78,6 +79,7 @@ void SessionImpl::begin()
|
|||||||
SQLiteStatementImpl tmp(*this, _pDB);
|
SQLiteStatementImpl tmp(*this, _pDB);
|
||||||
tmp.add(DEFERRED_BEGIN_TRANSACTION);
|
tmp.add(DEFERRED_BEGIN_TRANSACTION);
|
||||||
tmp.execute();
|
tmp.execute();
|
||||||
|
_isTransaction = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -86,6 +88,7 @@ void SessionImpl::commit()
|
|||||||
SQLiteStatementImpl tmp(*this, _pDB);
|
SQLiteStatementImpl tmp(*this, _pDB);
|
||||||
tmp.add(COMMIT_TRANSACTION);
|
tmp.add(COMMIT_TRANSACTION);
|
||||||
tmp.execute();
|
tmp.execute();
|
||||||
|
_isTransaction = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -94,6 +97,7 @@ void SessionImpl::rollback()
|
|||||||
SQLiteStatementImpl tmp(*this, _pDB);
|
SQLiteStatementImpl tmp(*this, _pDB);
|
||||||
tmp.add(ABORT_TRANSACTION);
|
tmp.add(ABORT_TRANSACTION);
|
||||||
tmp.execute();
|
tmp.execute();
|
||||||
|
_isTransaction = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// PooledSessionImpl.h
|
// PooledSessionImpl.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/Main/Data/include/Poco/Data/PooledSessionImpl.h#2 $
|
// $Id: //poco/Main/Data/include/Poco/Data/PooledSessionImpl.h#3 $
|
||||||
//
|
//
|
||||||
// Library: Data
|
// Library: Data
|
||||||
// Package: SessionPooling
|
// Package: SessionPooling
|
||||||
@ -72,6 +72,7 @@ public:
|
|||||||
void rollback();
|
void rollback();
|
||||||
void close();
|
void close();
|
||||||
bool isConnected();
|
bool isConnected();
|
||||||
|
bool isTransaction();
|
||||||
void setFeature(const std::string& name, bool state);
|
void setFeature(const std::string& name, bool state);
|
||||||
bool getFeature(const std::string& name);
|
bool getFeature(const std::string& name);
|
||||||
void setProperty(const std::string& name, const Poco::Any& value);
|
void setProperty(const std::string& name, const Poco::Any& value);
|
||||||
|
@ -203,7 +203,10 @@ public:
|
|||||||
/// Closes the session.
|
/// Closes the session.
|
||||||
|
|
||||||
bool isConnected();
|
bool isConnected();
|
||||||
/// Returns true if session is connected, false otherwise.
|
/// Returns true iff session is connected, false otherwise.
|
||||||
|
|
||||||
|
bool isTransaction();
|
||||||
|
/// Returns true iff a transaction is in progress, false otherwise.
|
||||||
|
|
||||||
void setFeature(const std::string& name, bool state);
|
void setFeature(const std::string& name, bool state);
|
||||||
/// Set the state of a feature.
|
/// Set the state of a feature.
|
||||||
@ -291,6 +294,12 @@ inline bool Session::isConnected()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool Session::isTransaction()
|
||||||
|
{
|
||||||
|
return _ptrImpl->isTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Session::setFeature(const std::string& name, bool state)
|
inline void Session::setFeature(const std::string& name, bool state)
|
||||||
{
|
{
|
||||||
_ptrImpl->setFeature(name, state);
|
_ptrImpl->setFeature(name, state);
|
||||||
|
@ -81,6 +81,9 @@ public:
|
|||||||
virtual bool isConnected() = 0;
|
virtual bool isConnected() = 0;
|
||||||
/// Returns true if session is connected, false otherwise.
|
/// Returns true if session is connected, false otherwise.
|
||||||
|
|
||||||
|
virtual bool isTransaction() = 0;
|
||||||
|
/// Returns true iff a transaction is a transaction is in progress, false otherwise.
|
||||||
|
|
||||||
virtual void setFeature(const std::string& name, bool state) = 0;
|
virtual void setFeature(const std::string& name, bool state) = 0;
|
||||||
/// Set the state of a feature.
|
/// Set the state of a feature.
|
||||||
///
|
///
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// PooledSessionImpl.cpp
|
// PooledSessionImpl.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/Main/Data/src/PooledSessionImpl.cpp#2 $
|
// $Id: //poco/Main/Data/src/PooledSessionImpl.cpp#3 $
|
||||||
//
|
//
|
||||||
// Library: Data
|
// Library: Data
|
||||||
// Package: SessionPooling
|
// Package: SessionPooling
|
||||||
@ -79,6 +79,12 @@ bool PooledSessionImpl::isConnected()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PooledSessionImpl::isTransaction()
|
||||||
|
{
|
||||||
|
return access()->isTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PooledSessionImpl::rollback()
|
void PooledSessionImpl::rollback()
|
||||||
{
|
{
|
||||||
return access()->rollback();
|
return access()->rollback();
|
||||||
@ -89,6 +95,18 @@ void PooledSessionImpl::close()
|
|||||||
{
|
{
|
||||||
if (_pHolder)
|
if (_pHolder)
|
||||||
{
|
{
|
||||||
|
if (isTransaction())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rollback();
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
// Something's wrong with the session. Get rid of it.
|
||||||
|
access()->close();
|
||||||
|
}
|
||||||
|
}
|
||||||
_pHolder->owner().putBack(_pHolder);
|
_pHolder->owner().putBack(_pHolder);
|
||||||
_pHolder = 0;
|
_pHolder = 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user