ARC SDK
MysqlWrapper.h
1 // -*- indent-tabs-mode: nil -*-
2 
3 #ifndef __ARC_MYSQLWRAPPER_H__
4 #define __ARC_MYSQLWRAPPER_H__
5 
6 #include <string>
7 #include <map>
8 #include <vector>
9 #include <mysql.h>
10 #include <arc/DBInterface.h>
11 
12 namespace Arc {
14 
17  : public Database {
18  friend class MySQLQuery;
19  public:
20  MySQLDatabase(std::string& server, int port);
21  MySQLDatabase(const MySQLDatabase& other);
22  virtual ~MySQLDatabase();
23 
24  virtual bool connect(std::string& dbname, std::string& user,
25  std::string& password);
26 
27  virtual bool isconnected() const {
28  return is_connected;
29  }
30 
31  virtual void close();
32 
33  virtual bool enable_ssl(const std::string& keyfile = "", const std::string& certfile = "",
34  const std::string& cafile = "", const std::string& capath = "");
35 
36  virtual bool shutdown();
37 
38  private:
39  bool is_connected;
40  std::string server_;
41  int port_;
42  std::string dbname_;
43  std::string user_;
44  std::string password_;
45 
46  MYSQL *mysql;
47  };
48 
50 
52  class MySQLQuery
53  : public Query {
54  public:
55  MySQLQuery(Database *db);
56  //MySQLQuery(Database* db, const std::string& sqlstr);
57  virtual ~MySQLQuery();
58 
59  virtual int get_num_colums();
60  virtual int get_num_rows();
61  virtual bool execute(const std::string& sqlstr);
62  virtual QueryRowResult get_row(int row_number) const;
63  virtual QueryRowResult get_row() const;
64  virtual std::string get_row_field(int row_number, std::string& field_name);
65  virtual bool get_array(std::string& sqlstr, QueryArrayResult& result, std::vector<std::string>& arguments);
66 
67  private:
68  MySQLDatabase *db_;
69  MYSQL_RES *res;
70  int num_rows;
71  int num_colums;
72  std::map<std::string, int> field_names;
73  };
74 
75 } // namespace Arc
76 
77 #endif /* __ARC_MYSQLWRAPPER_H__ */