9
3

DatabaseNew.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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);
  14. bool Connect(const char *host, const char *user, const char *password, const char *database, unsigned int port);
  15. bool Query(const char *query, ...);
  16. bool Select(DatabaseResult *result, const char *query, ...);
  17. int32 LastInsertID();
  18. long AffectedRows();
  19. //these two must free() the return char* after it's used in a query
  20. char * Escape(const char *str, size_t len);
  21. char * Escape(const char *str);
  22. //does not need free()
  23. string EscapeStr(const char *str, size_t len);
  24. string EscapeStr(const char *str);
  25. string EscapeStr(string str);
  26. bool QueriesFromFile(const char *file);
  27. void SetIgnoredErrno(unsigned int db_errno);
  28. void RemoveIgnoredErrno(unsigned int db_errno);
  29. bool IsIgnoredErrno(unsigned int db_errno);
  30. void PingNewDB();
  31. private:
  32. MYSQL mysql;
  33. Mutex MMysql;
  34. vector<unsigned int> ignored_errnos;
  35. };
  36. #endif