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.

115 lines
3.1 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. #include "interface.h"
  14. class IMySQLRowSet;
  15. class CColumnValue
  16. {
  17. public:
  18. CColumnValue( IMySQLRowSet *pSQL, int iColumn );
  19. const char* String();
  20. long Int32();
  21. private:
  22. IMySQLRowSet *m_pSQL;
  23. int m_iColumn;
  24. };
  25. class IMySQLRowSet
  26. {
  27. public:
  28. virtual void Release() = 0;
  29. // Get the number of columns in the data returned from the last query (if it was a select statement).
  30. virtual int NumFields() = 0;
  31. // Get the name of each column returned by the last query.
  32. virtual const char* GetFieldName( int iColumn ) = 0;
  33. // Call this in a loop until it returns false to iterate over all rows the query returned.
  34. virtual bool NextRow() = 0;
  35. // You can call this to start iterating over the result set from the start again.
  36. // Note: after calling this, you have to call NextRow() to actually get the first row's value ready.
  37. virtual bool SeekToFirstRow() = 0;
  38. virtual CColumnValue GetColumnValue( int iColumn ) = 0;
  39. virtual CColumnValue GetColumnValue( const char *pColumnName ) = 0;
  40. virtual const char* GetColumnValue_String( int iColumn ) = 0;
  41. virtual long GetColumnValue_Int( int iColumn ) = 0;
  42. // You can call this to get the index of a column for faster lookups with GetColumnValue( int ).
  43. // Returns -1 if the column can't be found.
  44. virtual int GetColumnIndex( const char *pColumnName ) = 0;
  45. };
  46. class IMySQL : public IMySQLRowSet
  47. {
  48. public:
  49. virtual bool InitMySQL( const char *pDBName, const char *pHostName="", const char *pUserName="", const char *pPassword="" ) = 0;
  50. virtual void Release() = 0;
  51. // These execute SQL commands. They return 0 if the query was successful.
  52. virtual int Execute( const char *pString ) = 0;
  53. // This reads in all of the data in the last row set you queried with Execute and builds a separate
  54. // copy. This is useful in some of the VMPI tools to have a thread repeatedly execute a slow query, then
  55. // store off the results for the main thread to parse.
  56. virtual IMySQLRowSet* DuplicateRowSet() = 0;
  57. // If you just inserted rows into a table with an AUTO_INCREMENT column,
  58. // then this returns the (unique) value of that column.
  59. virtual unsigned long InsertID() = 0;
  60. // Returns the last error message, if an error took place
  61. virtual const char * GetLastError() = 0;
  62. };
  63. #define MYSQL_WRAPPER_VERSION_NAME "MySQLWrapper001"
  64. // ------------------------------------------------------------------------------------------------ //
  65. // Inlines.
  66. // ------------------------------------------------------------------------------------------------ //
  67. inline CColumnValue::CColumnValue( IMySQLRowSet *pSQL, int iColumn )
  68. {
  69. m_pSQL = pSQL;
  70. m_iColumn = iColumn;
  71. }
  72. inline const char* CColumnValue::String()
  73. {
  74. return m_pSQL->GetColumnValue_String( m_iColumn );
  75. }
  76. inline long CColumnValue::Int32()
  77. {
  78. return m_pSQL->GetColumnValue_Int( m_iColumn );
  79. }
  80. #endif // MYSQL_WRAPPER_H