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