DatabaseNew.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef COMMON_DATABASE_H_
  2. #define COMMON_DATABASE_H_
  3. #include <string>
  4. #include "DatabaseResult.h"
  5. using namespace std;
  6. class DatabaseNew {
  7. public:
  8. DatabaseNew();
  9. virtual ~DatabaseNew();
  10. unsigned int GetError() {return mysql_errno(&mysql);}
  11. const char * GetErrorMsg() {return mysql_error(&mysql);}
  12. bool Connect();
  13. bool Connect(const char *host, const char *user, const char *password, const char *database, unsigned int port = 3306);
  14. bool Query(const char *query, ...);
  15. bool Select(DatabaseResult *result, const char *query, ...);
  16. int32 LastInsertID();
  17. long AffectedRows();
  18. //these two must free() the return char* after it's used in a query
  19. char * Escape(const char *str, size_t len);
  20. char * Escape(const char *str);
  21. //does not need free()
  22. string EscapeStr(const char *str, size_t len);
  23. string EscapeStr(const char *str);
  24. string EscapeStr(string str);
  25. bool QueriesFromFile(const char *file);
  26. void SetIgnoredErrno(unsigned int db_errno);
  27. void RemoveIgnoredErrno(unsigned int db_errno);
  28. bool IsIgnoredErrno(unsigned int db_errno);
  29. void PingNewDB();
  30. private:
  31. MYSQL mysql;
  32. Mutex MMysql;
  33. vector<unsigned int> ignored_errnos;
  34. };
  35. #endif