Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef MYSQL_WRAPPER_H
  8. #define MYSQL_WRAPPER_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "utlvector.h"
  13. class IMySQL;
  14. // This is a helper class to build queries like the stream IO.
  15. class CMySQLQuery
  16. {
  17. friend class CMySQL;
  18. public:
  19. // This is like a sprintf, but it will grow the string as necessary.
  20. void Format( const char *pFormat, ... );
  21. private:
  22. CUtlVector<char> m_QueryText;
  23. };
  24. class CColumnValue
  25. {
  26. public:
  27. CColumnValue( CMySQL *pSQL, int iColumn );
  28. const char* String();
  29. long Int32();
  30. unsigned long UInt32();
  31. private:
  32. CMySQL *m_pSQL;
  33. int m_iColumn;
  34. };
  35. class IMySQL
  36. {
  37. public:
  38. virtual void Release() = 0;
  39. // These execute SQL commands. They return 0 if the query was successful.
  40. virtual int Execute( const char *pString ) = 0;
  41. virtual int Execute( CMySQLQuery &query ) = 0;
  42. // If you just inserted rows into a table with an AUTO_INCREMENT column,
  43. // then this returns the (unique) value of that column.
  44. virtual unsigned long InsertID() = 0;
  45. // If you just executed a select statement, then you can use these functions to
  46. // iterate over the result set.
  47. // Get the number of columns in the data returned from the last query (if it was a select statement).
  48. virtual int NumFields() = 0;
  49. // Get the name of each column returned by the last query.
  50. virtual const char* GetFieldName( int iColumn ) = 0;
  51. // Call this in a loop until it returns false to iterate over all rows the query returned.
  52. virtual bool NextRow() = 0;
  53. // You can call this to start iterating over the result set from the start again.
  54. // Note: after calling this, you have to call NextRow() to actually get the first row's value ready.
  55. virtual bool SeekToFirstRow() = 0;
  56. virtual CColumnValue GetColumnValue( int iColumn ) = 0;
  57. virtual CColumnValue GetColumnValue( const char *pColumnName ) = 0;
  58. // You can call this to get the index of a column for faster lookups with GetColumnValue( int ).
  59. // Returns -1 if the column can't be found.
  60. virtual int GetColumnIndex( const char *pColumnName ) = 0;
  61. };
  62. IMySQL* InitMySQL( const char *pDBName, const char *pHostName="", const char *pUserName="", const char *pPassword="" );
  63. // ------------------------------------------------------------------------------------------------ //
  64. // Inlines.
  65. // ------------------------------------------------------------------------------------------------ //
  66. inline CColumnValue::CColumnValue( CMySQL *pSQL, int iColumn )
  67. {
  68. m_pSQL = pSQL;
  69. m_iColumn = iColumn;
  70. }
  71. #endif // MYSQL_WRAPPER_H