3 namespace remote
{ namespace mcs
{
5 ManagedConnection::ManagedConnection() : sqlConn(true)
8 ManagedConnection::~ManagedConnection()
10 if (sqlConn
.connected()) sqlConn
.close();
13 bool ManagedConnection::connect(std::string db
, std::string host
, std::string user
, std::string password
)
15 this->db
= db
; this->host
= host
; this->user
= user
; this->password
= password
;
16 return sqlConn
.connect(db
.c_str(),host
.c_str(),user
.c_str(),password
.c_str());
19 mysqlpp::Connection
& ManagedConnection::getConnection(bool check
)
21 if (check
) checkDBConnection();
25 void ManagedConnection::checkDBConnection()
29 if (sqlConn
.ping() !=0)
31 sqlConn
.connect(db
.c_str(),host
.c_str(),user
.c_str(),password
.c_str());
34 catch ( mysqlpp::Exception e
)
36 sqlConn
.connect(db
.c_str(),host
.c_str(),user
.c_str(),password
.c_str());
40 ManagedConnection dbConn
;