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.
13 class ManagedConnection
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
27 bool connect (std::string db
, std::string host
, std::string user
, std::string password
);
29 * \param check If true, check if the connection is alive.
30 * \returns A reference to the current connection object
32 mysqlpp::Connection
& getConnection(bool check
=true);
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
;
48 extern ManagedConnection dbConn
;