Codefox icon

Untitled

Codefox | PRO | 11/26/13 07:14:30 AM UTC | 0 ⭐ | 696 👁️ | Never ⏰ | []
C++ |

2.02 KB

|

None

|

0 👍

/

0 👎

#ifndef MYSQLQUERY_H
#define MYSQLQUERY_H
#include <mysql.h>
#include <stdint.h>
#include <string.h>
#include <algorithm>
#include <map>
 
class MySQLConnection
{
 
public:
    MySQLConnection();
    ~MySQLConnection();
    bool Connect(std::string sHostname, uint16_t wPort, std::string sUsername, std::string sPassword, std::string sDB);
    bool SelectDB(std::string sSchemaName);
    void Disconnect();
    std::string GetLastError();
    MYSQL *getConn();
    bool IsConnected();
    std::string EscapeString(std::string value);
 
private:
    MYSQL *m_MySQLConn;
    bool m_bIsConnected;
    std::string m_sHostname;
    std::string m_sUsername;
    std::string m_sPassword;
    std::string m_sSchemaName;
    uint16_t m_wPort;
};
 
class MySQLQuery
{
 
public:
    MySQLQuery(MySQLConnection *mConn, std::string sStatement);
    ~MySQLQuery();
 
    std::string setArgString(int idx, std::string value);
    int setArgInt(int idx, int value);
    double setArgDouble(int idx, double value);
    float setArgFloat(int idx, float value);
    time_t setArgTime(int idx, time_t value);
 
    bool ExecuteQuery();
 
    std::string BuildQueryString();
 
    std::string getResultString(int row, int field);
    std::string getResultString(int row, std::string field);
    int getResultInt(int row, int field);
    int getResultInt(int row, std::string field);
    double getResultDouble(int row, int field);
    double getResultDouble(int row, std::string field);
    float getResultFloat(int row, int field);
    float getResultFloat(int row, std::string field);
    time_t getResultTime(int row, int field);
    time_t getResultTime(int row, std::string field);
 
    int getResultRowCount();
 
 
private:
    typedef std::map<int, std::string> TResultRow;
    MySQLConnection *m_sqlConn;
    int m_iResultRowCount;
    std::string m_sStatement;
    std::map<int, std::string> m_mArgMap;
    std::map<int, TResultRow> m_mResultMap;
    std::map<int, std::string> m_mFieldMap;
 
};
 
#endif // MYSQLQUERY_H

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎