9
3

DatabaseResult.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. class DatabaseResult {
  9. public:
  10. DatabaseResult();
  11. virtual ~DatabaseResult();
  12. bool StoreResult(MYSQL_RES *res);
  13. bool Next();
  14. bool IsNull(unsigned int index);
  15. bool IsNullStr(const char *field_name);
  16. int8 GetInt8(unsigned int index);
  17. int8 GetInt8Str(const char *field_name);
  18. sint8 GetSInt8(unsigned int index);
  19. sint8 GetSInt8Str(const char *field_name);
  20. int16 GetInt16(unsigned int index);
  21. int16 GetInt16Str(const char *field_name);
  22. sint16 GetSInt16(unsigned int index);
  23. sint16 GetSInt16Str(const char *field_name);
  24. int32 GetInt32(unsigned int index);
  25. int32 GetInt32Str(const char *field_name);
  26. sint32 GetSInt32(unsigned int index);
  27. sint32 GetSInt32Str(const char *field_name);
  28. int64 GetInt64(unsigned int index);
  29. int64 GetInt64Str(const char *field_name);
  30. sint64 GetSInt64(unsigned int index);
  31. sint64 GetSInt64Str(const char *field_name);
  32. float GetFloat(unsigned int index);
  33. float GetFloatStr(const char *field_name);
  34. char GetChar(unsigned int index);
  35. char GetCharStr(const char *field_name);
  36. const char * GetString(unsigned int index);
  37. const char * GetStringStr(const char *field_name);
  38. unsigned int GetNumRows() {return result == NULL ? 0 : (unsigned int)mysql_num_rows(result);}
  39. private:
  40. MYSQL_RES *result;
  41. MYSQL_ROW row;
  42. char **field_names;
  43. unsigned int num_fields;
  44. const char * GetFieldValue(unsigned int index);
  45. const char * GetFieldValueStr(const char *field_name);
  46. };
  47. #endif