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__ */
Arc namespace contains all core ARC classes.
Definition: ArcConfig.h:11
Implements a MySQL version of the Database interface.
Definition: MysqlWrapper.h:16
virtual std::string get_row_field(int row_number, std::string &field_name)
Get the value of one specific field in one specific row.
virtual void close()
Close the connection with database server.
Class representing a database query.
Definition: DBInterface.h:54
virtual int get_num_rows()
Get the row number in the query result.
virtual bool get_array(std::string &sqlstr, QueryArrayResult &result, std::vector< std::string > &arguments)
Query the database by using some parameters into sql sentence.
Interface for calling database client library.
Definition: DBInterface.h:15
virtual bool shutdown()
Ask database server to shutdown.
Implements a MySQL version of the Query database query class.
Definition: MysqlWrapper.h:52
virtual bool isconnected() const
Get the connection status.
Definition: MysqlWrapper.h:27
virtual bool enable_ssl(const std::string &keyfile="", const std::string &certfile="", const std::string &cafile="", const std::string &capath="")
Enable ssl communication for the connection.
virtual int get_num_colums()
Get the column number in the query result.
virtual bool execute(const std::string &sqlstr)
Execute the query.
virtual QueryRowResult get_row() const
Get the value of one row in the query result.
virtual bool connect(std::string &dbname, std::string &user, std::string &password)
Do connection with database server.