Advertisement
Codefox

Untitled

Nov 26th, 2013
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1. #ifndef MYSQLQUERY_H
  2. #define MYSQLQUERY_H
  3. #include <mysql.h>
  4. #include <stdint.h>
  5. #include <string.h>
  6. #include <algorithm>
  7. #include <map>
  8.  
  9. class MySQLConnection
  10. {
  11.  
  12. public:
  13.     MySQLConnection();
  14.     ~MySQLConnection();
  15.     bool Connect(std::string sHostname, uint16_t wPort, std::string sUsername, std::string sPassword, std::string sDB);
  16.     bool SelectDB(std::string sSchemaName);
  17.     void Disconnect();
  18.     std::string GetLastError();
  19.     MYSQL *getConn();
  20.     bool IsConnected();
  21.     std::string EscapeString(std::string value);
  22.  
  23. private:
  24.     MYSQL *m_MySQLConn;
  25.     bool m_bIsConnected;
  26.     std::string m_sHostname;
  27.     std::string m_sUsername;
  28.     std::string m_sPassword;
  29.     std::string m_sSchemaName;
  30.     uint16_t m_wPort;
  31. };
  32.  
  33. class MySQLQuery
  34. {
  35.  
  36. public:
  37.     MySQLQuery(MySQLConnection *mConn, std::string sStatement);
  38.     ~MySQLQuery();
  39.  
  40.     std::string setArgString(int idx, std::string value);
  41.     int setArgInt(int idx, int value);
  42.     double setArgDouble(int idx, double value);
  43.     float setArgFloat(int idx, float value);
  44.     time_t setArgTime(int idx, time_t value);
  45.  
  46.     bool ExecuteQuery();
  47.  
  48.     std::string BuildQueryString();
  49.  
  50.     std::string getResultString(int row, int field);
  51.     std::string getResultString(int row, std::string field);
  52.     int getResultInt(int row, int field);
  53.     int getResultInt(int row, std::string field);
  54.     double getResultDouble(int row, int field);
  55.     double getResultDouble(int row, std::string field);
  56.     float getResultFloat(int row, int field);
  57.     float getResultFloat(int row, std::string field);
  58.     time_t getResultTime(int row, int field);
  59.     time_t getResultTime(int row, std::string field);
  60.  
  61.     int getResultRowCount();
  62.  
  63.  
  64. private:
  65.     typedef std::map<int, std::string> TResultRow;
  66.     MySQLConnection *m_sqlConn;
  67.     int m_iResultRowCount;
  68.     std::string m_sStatement;
  69.     std::map<int, std::string> m_mArgMap;
  70.     std::map<int, TResultRow> m_mResultMap;
  71.     std::map<int, std::string> m_mFieldMap;
  72.  
  73. };
  74.  
  75. #endif // MYSQLQUERY_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement