MCS: Use remote.h and cleanup header file inclusion
[remote/remote-mci.git] / mcs / database.h
blob5e25e441cad899b5079e751ab1e2efde90243e2e
1 #ifndef REMOTE_MCS_DATABASE_H
2 #define REMOTE_MCS_DATABASE_H
4 #include <mysql++/mysql++.h>
6 namespace remote { namespace mcs {
8 //using namespace mysqlpp;
10 /** The mysql++ database connection handler class handles the database connection and
11 * reconnects when needed.
12 **/
13 class ManagedConnection
15 public:
16 /** Constructor **/
17 ManagedConnection();
18 /** Destructor **/
19 virtual ~ManagedConnection();
20 /** Connect to the specified database
21 * \param db Database name
22 * \param host Host name
23 * \param user User name
24 * \param password Password
25 * \returns true if connection is successful
26 **/
27 bool connect (std::string db, std::string host, std::string user, std::string password);
28 /**
29 * \param check If true, check if the connection is alive.
30 * \returns A reference to the current connection object
31 **/
32 mysqlpp::Connection& getConnection(bool check=true);
33 private:
34 /** Check if the database connection is still alive and try to reconnect if not. **/
35 void checkDBConnection();
36 /** The database connection object **/
37 mysqlpp::Connection sqlConn;
38 /** Database name **/
39 std::string db;
40 /** Host name **/
41 std::string host;
42 /** User name **/
43 std::string user;
44 /** Password **/
45 std::string password;
48 extern ManagedConnection dbConn;
55 #endif