DatabaseResult.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef COMMON_DATABASERESULT_H_
  2. #define COMMON_DATABASERESULT_H_
  3. #include "types.h"
  4. #ifdef _WIN32
  5. #include <WinSock2.h> //#include <my_global.h> when we/if we go to winsock2 :/
  6. #endif
  7. #include <mysql.h>
  8. #include <map>
  9. class DatabaseResult {
  10. public:
  11. DatabaseResult();
  12. virtual ~DatabaseResult();
  13. bool StoreResult(MYSQL_RES* result, uint8 field_count, uint8 row_count);
  14. bool Next();
  15. bool IsNull(unsigned int index);
  16. bool IsNullStr(const char *field_name);
  17. int8 GetInt8(unsigned int index);
  18. int8 GetInt8Str(const char *field_name);
  19. sint8 GetSInt8(unsigned int index);
  20. sint8 GetSInt8Str(const char *field_name);
  21. int16 GetInt16(unsigned int index);
  22. int16 GetInt16Str(const char *field_name);
  23. sint16 GetSInt16(unsigned int index);
  24. sint16 GetSInt16Str(const char *field_name);
  25. int32 GetInt32(unsigned int index);
  26. int32 GetInt32Str(const char *field_name);
  27. sint32 GetSInt32(unsigned int index);
  28. sint32 GetSInt32Str(const char *field_name);
  29. int64 GetInt64(unsigned int index);
  30. int64 GetInt64Str(const char *field_name);
  31. sint64 GetSInt64(unsigned int index);
  32. sint64 GetSInt64Str(const char *field_name);
  33. float GetFloat(unsigned int index);
  34. float GetFloatStr(const char *field_name);
  35. char GetChar(unsigned int index);
  36. char GetCharStr(const char *field_name);
  37. const char * GetString(unsigned int index);
  38. const char * GetStringStr(const char *field_name);
  39. const unsigned int GetNumRows() { return num_rows; }
  40. const char * GetFieldValue(unsigned int index);
  41. const char * GetFieldValueStr(const char *field_name);
  42. private:
  43. MYSQL_RES *result;
  44. MYSQL_ROW row;
  45. unsigned int num_rows;
  46. unsigned int num_fields;
  47. std::map<std::string_view,uint8> field_map;
  48. };
  49. #endif