Back to index

nordugrid-arc-nox  1.1.0~rc6
MysqlWrapper.h
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
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 "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     bool secured; //whether ssl is used
00045 
00046     MYSQL *mysql;
00047   };
00048 
00049   class MySQLQuery
00050     : public Query {
00051   public:
00052     MySQLQuery(Database *db);
00053     //MySQLQuery(Database* db, const std::string& sqlstr);
00054     virtual ~MySQLQuery();
00055 
00056     virtual int get_num_colums();
00057     virtual int get_num_rows();
00058     virtual bool execute(const std::string& sqlstr);
00059     virtual QueryRowResult get_row(int row_number) const;
00060     virtual QueryRowResult get_row() const;
00061     virtual std::string get_row_field(int row_number, std::string& field_name);
00062     virtual bool get_array(std::string& sqlstr, QueryArrayResult& result, std::vector<std::string>& arguments);
00063 
00064   private:
00065     MySQLDatabase *db_;
00066     MYSQL_RES *res;
00067     int num_rows;
00068     int num_colums;
00069     std::map<std::string, int> field_names;
00070   };
00071 
00072 } // namespace Arc
00073 
00074 #endif /* __ARC_MYSQLWRAPPER_H__ */