Reorganize to remove DIKU specific naming
[remote/remote-mci.git] / mcs / database.cc
blob641da80d7f564d1525cd5bff31e7c7b9bb928443
1 #include "database.h"
3 namespace remote { namespace mcs {
5 ManagedConnection::ManagedConnection() : sqlConn(true)
6 {}
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();
22 return sqlConn;
25 void ManagedConnection::checkDBConnection()
27 try
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;