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.

116 lines
4.1 KiB

  1. //========= Copyright � 1996-2004, Valve LLC, All rights reserved. ============
  2. //
  3. // Purpose: Sql wrapper, encapsulates basic SQL functionality
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #ifndef ISQLWRAPPER_H
  8. #define ISQLWRAPPER_H
  9. #include "tier0/platform.h"
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. // SQL column types
  14. enum EColumnType
  15. {
  16. SQL_NONE = 0,
  17. SQL_INT,
  18. SQL_STRING,
  19. SQL_FLOAT,
  20. SQL_TIME,
  21. SQL_UINT64
  22. };
  23. //-----------------------------------------------------------------------------
  24. // encapsulates a table's description
  25. //-----------------------------------------------------------------------------
  26. class ISQLTable
  27. {
  28. public:
  29. virtual int GetCSQLColumn() const = 0;
  30. virtual const char *PchColumnName( int iSQLColumn ) const = 0;
  31. virtual EColumnType GetEColumnType( int iSQLColumn ) const = 0;
  32. virtual const char *PchName() const = 0;
  33. };
  34. //-----------------------------------------------------------------------------
  35. // encapsulates a database worth of tables
  36. //-----------------------------------------------------------------------------
  37. class ISQLTableSet
  38. {
  39. public:
  40. virtual int GetCSQLTable() const = 0;
  41. virtual const ISQLTable *PSQLTable( int iSQLTable ) const = 0;
  42. };
  43. //-----------------------------------------------------------------------------
  44. // encapsulates a single returned row from a valid SQL query
  45. //-----------------------------------------------------------------------------
  46. class ISQLRow
  47. {
  48. public:
  49. virtual int GetCSQLRowData() const = 0;
  50. virtual const char *PchData( int iSQLColumn ) const = 0;
  51. virtual int NData( int iSQLColumn ) const = 0;
  52. virtual uint64 UlData( int iSQLColumn ) const = 0;
  53. virtual float FlData( int iSQLColumn ) const = 0;
  54. virtual uint64 UlTime( int iSQLColumn ) const = 0;
  55. virtual bool BData( int iSQLColumn ) const = 0;
  56. virtual EColumnType GetEColumnType( int iSQLColumn ) const = 0;
  57. };
  58. //-----------------------------------------------------------------------------
  59. // encapsulates a result set, which is made up of a series of rows
  60. // You need to call PNextResult() NRow() times to get all the results
  61. // (there is no random access to the result set).
  62. //-----------------------------------------------------------------------------
  63. class IResultSet
  64. {
  65. public:
  66. virtual int GetCSQLRow() const = 0;
  67. virtual const ISQLRow *PSQLRowNextResult() = 0; // note, not const on the class because it makes a new row object
  68. };
  69. //-----------------------------------------------------------------------------
  70. // This interface encapsulates a database connection and lets you operate on it.
  71. // Use the ISQLWrapperFactory factory to get access to the interface.
  72. // NOTE - you can only have one outstanding query at a time. When you are done with a query call FreeResult()
  73. //-----------------------------------------------------------------------------
  74. class ISQLWrapper
  75. {
  76. public:
  77. // run a SQL statement against the DB, typically an insert statement as no data is returned
  78. virtual bool BInsert( const char *pchQueryString ) = 0;
  79. // get a description of the tables associated with the db you connected to
  80. virtual const ISQLTableSet *PSQLTableSetDescription() = 0;
  81. // run a query against the db and then iterate the result set (you can only have 1 outstanding query at a time, and call FreeResults() when you are done)
  82. virtual IResultSet *PResultSetQuery( const char *pchQueryString ) = 0;
  83. // you MUST call then after you finish with the IResultSet from the above query
  84. virtual void FreeResult() = 0;
  85. };
  86. //-----------------------------------------------------------------------------
  87. // This is a factory to create objects that let you interact with a MySQL database.
  88. // Make sure you Free() any interfaces you create.
  89. //-----------------------------------------------------------------------------
  90. class ISQLWrapperFactory
  91. {
  92. public:
  93. // setup details about this db connection
  94. virtual ISQLWrapper *Create( const char *pchDB, const char *pchHost, const char *pchUsername, const char *pchPassword ) = 0;
  95. virtual void Free( ISQLWrapper *pSQLWrapper ) = 0;
  96. };
  97. #define INTERFACEVERSION_ISQLWRAPPER "ISQLWRAPPER001"
  98. #endif // ISQLWRAPPER_H