added Session::isTransaction()

This commit is contained in:
Guenter Obiltschnig 2007-08-10 14:08:45 +00:00
parent a04bae94d7
commit dfbc0e1d24
10 changed files with 9722 additions and 5857 deletions

View File

@ -90,6 +90,9 @@ public:
bool isConnected();
/// Returns true if session is connected
bool isTransaction();
/// Returns true iff a transaction is in progress.
void setEnforceCapability(const std::string&, bool val);
/// Configures session to enforce driver capability check
/// after connection.

View File

@ -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()
{
if (!isConnected()) return;

View File

@ -83,6 +83,9 @@ public:
bool isConnected();
/// Returns true if connected, false otherwise.
bool isTransaction();
/// Returns true iff a transaction is in progress.
private:
void open();
/// Opens a connection to the Database.
@ -90,6 +93,7 @@ private:
std::string _dbFileName;
sqlite3* _pDB;
bool _connected;
bool _isTransaction;
static const std::string DEFERRED_BEGIN_TRANSACTION;
static const std::string COMMIT_TRANSACTION;
@ -97,6 +101,15 @@ private:
};
//
// inlines
//
inline bool SessionImpl::isTransaction()
{
return _isTransaction;
}
} } } // namespace Poco::Data::SQLite

View File

@ -54,7 +54,8 @@ const std::string SessionImpl::ABORT_TRANSACTION("ROLLBACK");
SessionImpl::SessionImpl(const std::string& fileName):
_dbFileName(fileName),
_pDB(0),
_connected(false)
_connected(false),
_isTransaction(false)
{
open();
}
@ -78,6 +79,7 @@ void SessionImpl::begin()
SQLiteStatementImpl tmp(*this, _pDB);
tmp.add(DEFERRED_BEGIN_TRANSACTION);
tmp.execute();
_isTransaction = true;
}
@ -86,6 +88,7 @@ void SessionImpl::commit()
SQLiteStatementImpl tmp(*this, _pDB);
tmp.add(COMMIT_TRANSACTION);
tmp.execute();
_isTransaction = false;
}
@ -94,6 +97,7 @@ void SessionImpl::rollback()
SQLiteStatementImpl tmp(*this, _pDB);
tmp.add(ABORT_TRANSACTION);
tmp.execute();
_isTransaction = false;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
//
// PooledSessionImpl.h
//
// $Id: //poco/Main/Data/include/Poco/Data/PooledSessionImpl.h#2 $
// $Id: //poco/Main/Data/include/Poco/Data/PooledSessionImpl.h#3 $
//
// Library: Data
// Package: SessionPooling
@ -72,6 +72,7 @@ public:
void rollback();
void close();
bool isConnected();
bool isTransaction();
void setFeature(const std::string& name, bool state);
bool getFeature(const std::string& name);
void setProperty(const std::string& name, const Poco::Any& value);

View File

@ -203,7 +203,10 @@ public:
/// Closes the session.
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);
/// 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)
{
_ptrImpl->setFeature(name, state);

View File

@ -81,6 +81,9 @@ public:
virtual bool isConnected() = 0;
/// 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;
/// Set the state of a feature.
///

View File

@ -1,7 +1,7 @@
//
// PooledSessionImpl.cpp
//
// $Id: //poco/Main/Data/src/PooledSessionImpl.cpp#2 $
// $Id: //poco/Main/Data/src/PooledSessionImpl.cpp#3 $
//
// Library: Data
// Package: SessionPooling
@ -79,6 +79,12 @@ bool PooledSessionImpl::isConnected()
}
bool PooledSessionImpl::isTransaction()
{
return access()->isTransaction();
}
void PooledSessionImpl::rollback()
{
return access()->rollback();
@ -89,6 +95,18 @@ void PooledSessionImpl::close()
{
if (_pHolder)
{
if (isTransaction())
{
try
{
rollback();
}
catch (...)
{
// Something's wrong with the session. Get rid of it.
access()->close();
}
}
_pHolder->owner().putBack(_pHolder);
_pHolder = 0;
}