Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DESDBProviderMySQL.h
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DESDBProviderMySQL.h
4 // Creator: sdobbs
5 //
6 // Interface for EventStore database connection
7 //
8 
9 #ifndef _DESDBProviderMySQL_
10 #define _DESDBProviderMySQL_
11 
12 #include "DESDBProvider.h"
13 
14 #include <iostream>
15 #include <sstream>
16 
17 #include <JANA/jerror.h>
18 #include <JANA/JException.h>
19 #include <JANA/JStreamLog.h>
20 #include <mysql.h>
21 
22 
23 using namespace jana;
24 using namespace std;
25 
26 
28  public:
29  DESDBProviderMySQL(string connection_str);
30  virtual ~DESDBProviderMySQL();
31 
32  bool Open();
33 
34  // accessors
35  bool GetGrades(vector<string> &grades);
36  bool GetSkims(vector<string> &grades, string timestamp, string grade);
37 
38  protected:
39  // MySQL connection information
40  string user_name;
41  string password;
42  string host_name;
43  string database;
44  int port;
45 
46  MYSQL *DBptr;
47  MYSQL_RES *DBresult;
49 
50  // allow for connecting/disconnecting to MySQL DB so that we don't always keep
51  // the connection open
52  bool Connect();
53  void Disconnect();
54  inline bool IsConnected() { return is_connected; }
55 
56  // misc functions
57  inline string FormatMySQLError(string mysql_func_name) {
58  stringstream ss;
59  ss << mysql_func_name << " failed: Error " << mysql_errno(DBptr)
60  << " (" << mysql_error(DBptr) << ")";
61  return ss.str();
62  }
63 
64 };
65 
66 #endif // _DESDBProviderMySQL_
string FormatMySQLError(string mysql_func_name)