DatabaseNew.h 1.2 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);
  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. private:
  31. MYSQL mysql;
  32. Mutex MMysql;
  33. vector<unsigned int> ignored_errnos;
  34. };
  35. #endif