MySQLInterface.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #ifndef __MY_SQL_INTERFACE_H
  11. #define __MY_SQL_INTERFACE_H
  12. #include "RakString.h"
  13. struct st_mysql_res;
  14. struct st_mysql;
  15. class MySQLInterface
  16. {
  17. public:
  18. MySQLInterface();
  19. virtual ~MySQLInterface();
  20. /// Calls mysql_real_connect with the implicit mySqlConnection
  21. bool Connect (const char *host,
  22. const char *user,
  23. const char *passwd,
  24. const char *db,
  25. unsigned int port,
  26. const char *unix_socket,
  27. unsigned long clientflag);
  28. /// Disconnect from the database
  29. void Disconnect(void);
  30. /// Returns if we are connected to the database
  31. bool IsConnected(void) const;
  32. /// If any of the above functions fail, the error string is stored internally. Call this to get it.
  33. virtual const char *GetLastError(void) const;
  34. /// Returns the result of SELECT LOCALTIMESTAMP
  35. char *GetLocalTimestamp(void);
  36. protected:
  37. // Pass queries to the server
  38. bool ExecuteBlockingCommand(const char *command);
  39. bool ExecuteBlockingCommand(const char *command, st_mysql_res **result, bool rollbackOnFailure = false);
  40. bool ExecuteQueryReadInt (const char * query, int *value);
  41. void Commit(void);
  42. void Rollback(void);
  43. RakNet::RakString GetEscapedString(const char *input) const;
  44. st_mysql *mySqlConnection;
  45. char lastError[1024];
  46. // Copy of connection parameters
  47. RakNet::RakString _host;
  48. RakNet::RakString _user;
  49. RakNet::RakString _passwd;
  50. RakNet::RakString _db;
  51. unsigned int _port;
  52. RakNet::RakString _unix_socket;
  53. unsigned long _clientflag;
  54. };
  55. #endif
粤ICP备19079148号