00001
00002
00003 #ifndef __ARC_MYSQLWRAPPER_H__
00004 #define __ARC_MYSQLWRAPPER_H__
00005
00006 #include <string>
00007 #include <map>
00008 #include <vector>
00009 #include <mysql.h>
00010 #include <arc/DBInterface.h>
00011
00012 namespace Arc {
00015 class MySQLDatabase
00016 : public Database {
00017 friend class MySQLQuery;
00018 public:
00019 MySQLDatabase(std::string& server, int port);
00020 MySQLDatabase(const MySQLDatabase& other);
00021 virtual ~MySQLDatabase();
00022
00023 virtual bool connect(std::string& dbname, std::string& user,
00024 std::string& password);
00025
00026 virtual bool isconnected() const {
00027 return is_connected;
00028 }
00029
00030 virtual void close();
00031
00032 virtual bool enable_ssl(const std::string& keyfile = "", const std::string& certfile = "",
00033 const std::string& cafile = "", const std::string& capath = "");
00034
00035 virtual bool shutdown();
00036
00037 private:
00038 bool is_connected;
00039 std::string server_;
00040 int port_;
00041 std::string dbname_;
00042 std::string user_;
00043 std::string password_;
00044
00045 MYSQL *mysql;
00046 };
00047
00048 class MySQLQuery
00049 : public Query {
00050 public:
00051 MySQLQuery(Database *db);
00052
00053 virtual ~MySQLQuery();
00054
00055 virtual int get_num_colums();
00056 virtual int get_num_rows();
00057 virtual bool execute(const std::string& sqlstr);
00058 virtual QueryRowResult get_row(int row_number) const;
00059 virtual QueryRowResult get_row() const;
00060 virtual std::string get_row_field(int row_number, std::string& field_name);
00061 virtual bool get_array(std::string& sqlstr, QueryArrayResult& result, std::vector<std::string>& arguments);
00062
00063 private:
00064 MySQLDatabase *db_;
00065 MYSQL_RES *res;
00066 int num_rows;
00067 int num_colums;
00068 std::map<std::string, int> field_names;
00069 };
00070
00071 }
00072
00073 #endif