|
@@ -16,24 +16,24 @@ MySQLClientImpl::~MySQLClientImpl()
|
|
|
{
|
|
{
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void MySQLClientImpl::Connect(const std::string& hostname, const std::string& username, const std::string& password)
|
|
|
|
|
|
|
+void MySQLClientImpl::Connect(const std::string& hostname, const std::string& username, const std::string& password, bool automaticReconnect)
|
|
|
{
|
|
{
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
m_hostname = hostname;
|
|
m_hostname = hostname;
|
|
|
m_username = username;
|
|
m_username = username;
|
|
|
m_password = password;
|
|
m_password = password;
|
|
|
m_database = "";
|
|
m_database = "";
|
|
|
- InternalConnect();
|
|
|
|
|
|
|
+ InternalConnect(automaticReconnect);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void MySQLClientImpl::Connect(const std::string& hostname, const std::string& username, const std::string& password, const std::string& database)
|
|
|
|
|
|
|
+void MySQLClientImpl::Connect(const std::string& hostname, const std::string& username, const std::string& password, const std::string& database, bool automaticReconnect)
|
|
|
{
|
|
{
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
m_hostname = hostname;
|
|
m_hostname = hostname;
|
|
|
m_username = username;
|
|
m_username = username;
|
|
|
m_password = password;
|
|
m_password = password;
|
|
|
m_database = database;
|
|
m_database = database;
|
|
|
- InternalConnect();
|
|
|
|
|
|
|
+ InternalConnect(automaticReconnect);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void MySQLClientImpl::Disconnect()
|
|
void MySQLClientImpl::Disconnect()
|
|
@@ -42,11 +42,11 @@ void MySQLClientImpl::Disconnect()
|
|
|
InternalDisconnect();
|
|
InternalDisconnect();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void MySQLClientImpl::Reconnect()
|
|
|
|
|
|
|
+void MySQLClientImpl::Reconnect(bool automaticReconnect)
|
|
|
{
|
|
{
|
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
std::unique_lock<std::mutex> lock(m_mutex);
|
|
|
InternalDisconnect();
|
|
InternalDisconnect();
|
|
|
- InternalConnect();
|
|
|
|
|
|
|
+ InternalConnect(automaticReconnect);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool MySQLClientImpl::Connected() const
|
|
bool MySQLClientImpl::Connected() const
|
|
@@ -117,20 +117,28 @@ std::shared_ptr<MySQLResultSetImpl> MySQLClientImpl::ExecuteQuery(const std::str
|
|
|
return std::make_shared<MySQLResultSetImpl>(nullptr);
|
|
return std::make_shared<MySQLResultSetImpl>(nullptr);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void MySQLClientImpl::InternalConnect()
|
|
|
|
|
|
|
+void MySQLClientImpl::InternalConnect(bool automaticReconnect)
|
|
|
{
|
|
{
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
if (m_pConnection)
|
|
if (m_pConnection)
|
|
|
- Disconnect();
|
|
|
|
|
-
|
|
|
|
|
- std::stringstream ss;
|
|
|
|
|
- ss << "tcp://" << m_hostname << ":3306";
|
|
|
|
|
|
|
+ InternalDisconnect();
|
|
|
|
|
|
|
|
|
|
+ std::string database;
|
|
|
if (!m_database.empty())
|
|
if (!m_database.empty())
|
|
|
- ss << "/" << m_database;
|
|
|
|
|
-
|
|
|
|
|
- m_pConnection = std::shared_ptr<sql::Connection>(m_pDriver->connect(ss.str(), m_username, m_password));
|
|
|
|
|
|
|
+ database = m_database;
|
|
|
|
|
+ else
|
|
|
|
|
+ database = "information_schema";
|
|
|
|
|
+
|
|
|
|
|
+ sql::ConnectOptionsMap options;
|
|
|
|
|
+ options["hostName"] = m_hostname;
|
|
|
|
|
+ options["userName"] = m_username;
|
|
|
|
|
+ options["password"] = m_password;
|
|
|
|
|
+ options["schema"] = database;
|
|
|
|
|
+ options["port"] = 3306;
|
|
|
|
|
+ options["OPT_RECONNECT"] = automaticReconnect;
|
|
|
|
|
+
|
|
|
|
|
+ m_pConnection = std::shared_ptr<sql::Connection>(m_pDriver->connect(options));
|
|
|
m_connected = true;
|
|
m_connected = true;
|
|
|
}
|
|
}
|
|
|
catch (sql::SQLException &e)
|
|
catch (sql::SQLException &e)
|