mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-17 11:05:03 +02:00
changed set|getTimeout() => set|getLoginTimeout()
added set|getConnectionTimeout()
This commit is contained in:
@@ -63,7 +63,7 @@ public:
|
||||
/// Returns the name associated with this connector.
|
||||
|
||||
virtual Poco::AutoPtr<Poco::Data::SessionImpl> createSession(const std::string& connectionString,
|
||||
std::size_t timeout = Poco::Data::SessionImpl::CONNECT_TIMEOUT_DEFAULT);
|
||||
std::size_t timeout = Poco::Data::SessionImpl::LOGIN_TIMEOUT_DEFAULT);
|
||||
/// Creates a MySQL SessionImpl object and initializes it with the given connectionString.
|
||||
|
||||
static void registerConnector();
|
||||
|
@@ -63,7 +63,7 @@ public:
|
||||
static const std::string MYSQL_SERIALIZABLE;
|
||||
|
||||
SessionImpl(const std::string& connectionString,
|
||||
std::size_t timeout = CONNECT_TIMEOUT_DEFAULT);
|
||||
std::size_t loginTimeout = LOGIN_TIMEOUT_DEFAULT);
|
||||
/// Creates the SessionImpl. Opens a connection to the database
|
||||
///
|
||||
/// Connection string format:
|
||||
@@ -91,6 +91,12 @@ public:
|
||||
bool isConnected();
|
||||
/// Returns true if connected, false otherwise.
|
||||
|
||||
void setConnectionTimeout(std::size_t timeout);
|
||||
/// Sets the session connection timeout value.
|
||||
|
||||
std::size_t getConnectionTimeout();
|
||||
/// Returns the session connection timeout value.
|
||||
|
||||
void begin();
|
||||
/// Starts a transaction
|
||||
|
||||
@@ -171,6 +177,7 @@ private:
|
||||
SessionHandle _handle;
|
||||
bool _connected;
|
||||
bool _inTransaction;
|
||||
std::size_t _timeout;
|
||||
Poco::FastMutex _mutex;
|
||||
};
|
||||
|
||||
@@ -207,12 +214,30 @@ inline const std::string& SessionImpl::connectorName()
|
||||
}
|
||||
|
||||
|
||||
inline bool SessionImpl::isTransaction()
|
||||
{
|
||||
return _inTransaction;
|
||||
}
|
||||
|
||||
|
||||
inline bool SessionImpl::isTransactionIsolation(Poco::UInt32 ti)
|
||||
{
|
||||
return getTransactionIsolation() == ti;
|
||||
}
|
||||
|
||||
|
||||
inline bool SessionImpl::isConnected()
|
||||
{
|
||||
return _connected;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t SessionImpl::getConnectionTimeout()
|
||||
{
|
||||
return _timeout;
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
inline std::string& SessionImpl::getValue(MYSQL_BIND* pResult, std::string& val)
|
||||
{
|
||||
|
@@ -66,8 +66,8 @@ const std::string SessionImpl::MYSQL_REPEATABLE_READ = "REPEATABLE READ";
|
||||
const std::string SessionImpl::MYSQL_SERIALIZABLE = "SERIALIZABLE";
|
||||
|
||||
|
||||
SessionImpl::SessionImpl(const std::string& connectionString, std::size_t timeout) :
|
||||
Poco::Data::AbstractSessionImpl<SessionImpl>(toLower(connectionString), timeout),
|
||||
SessionImpl::SessionImpl(const std::string& connectionString, std::size_t loginTimeout) :
|
||||
Poco::Data::AbstractSessionImpl<SessionImpl>(toLower(connectionString), loginTimeout),
|
||||
_handle(0),
|
||||
_connected(false),
|
||||
_inTransaction(false)
|
||||
@@ -77,6 +77,7 @@ SessionImpl::SessionImpl(const std::string& connectionString, std::size_t timeou
|
||||
&SessionImpl::getInsertId);
|
||||
|
||||
open();
|
||||
setConnectionTimeout(CONNECTION_TIMEOUT_DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +96,7 @@ void SessionImpl::open(const std::string& connect)
|
||||
|
||||
_handle.init();
|
||||
|
||||
unsigned int timeout = static_cast<unsigned int>(getTimeout());
|
||||
unsigned int timeout = static_cast<unsigned int>(getLoginTimeout());
|
||||
_handle.options(MYSQL_OPT_CONNECT_TIMEOUT, timeout);
|
||||
|
||||
std::map<std::string, std::string> options;
|
||||
@@ -275,17 +276,13 @@ void SessionImpl::close()
|
||||
_connected = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool SessionImpl::isConnected()
|
||||
{
|
||||
return _connected;
|
||||
}
|
||||
|
||||
|
||||
bool SessionImpl::isTransaction()
|
||||
void SessionImpl::setConnectionTimeout(std::size_t timeout)
|
||||
{
|
||||
return _inTransaction;
|
||||
_handle.options(MYSQL_OPT_READ_TIMEOUT, static_cast<unsigned int>(timeout));
|
||||
_handle.options(MYSQL_OPT_WRITE_TIMEOUT, static_cast<unsigned int>(timeout));
|
||||
_timeout = timeout;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -43,6 +43,7 @@
|
||||
#include "Poco/Data/MySQL/Connector.h"
|
||||
#include "Poco/Data/MySQL/MySQLException.h"
|
||||
#include "Poco/Data/Nullable.h"
|
||||
#include "Poco/Data/DataException.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace Poco::Data;
|
||||
@@ -764,7 +765,7 @@ CppUnit::Test* MySQLTest::suite()
|
||||
{
|
||||
_pSession = new Session(MySQL::Connector::KEY, _dbConnString);
|
||||
}
|
||||
catch (ConnectionException& ex)
|
||||
catch (ConnectionFailedException& ex)
|
||||
{
|
||||
std::cout << ex.displayText() << std::endl;
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user