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.

151 lines
4.4 KiB

  1. //========= Copyright �, Valve LLC, All rights reserved. ============
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #ifndef GCSQLQUERY_H
  8. #define GCSQLQUERY_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "gamecoordinator/igcsqlquery.h"
  13. #include "refcount.h"
  14. #include "tier0/memdbgon.h"
  15. namespace GCSDK
  16. {
  17. struct GCSQLBindParam_t
  18. {
  19. EGCSQLType m_eType;
  20. uint8 *m_pubData;
  21. size_t m_cubData;
  22. };
  23. class CGCSQLQuery
  24. {
  25. public:
  26. CGCSQLQuery();
  27. virtual ~CGCSQLQuery();
  28. void SetCommand( const char *pchCommand ) { m_sCommand = pchCommand; }
  29. void AddBindParam( const char *pchValue )
  30. {
  31. AddBindParamRaw( k_EGCSQLType_String, (byte *)pchValue, Q_strlen( pchValue ) );
  32. }
  33. void AddBindParam( const int16 nValue )
  34. {
  35. AddBindParamRaw( k_EGCSQLType_int16, (byte *)&nValue, sizeof( nValue ) );
  36. }
  37. void AddBindParam( const uint16 uValue )
  38. {
  39. AddBindParamRaw( k_EGCSQLType_int16, (byte *)&uValue, sizeof( uValue ) );
  40. }
  41. void AddBindParam( const int32 nValue )
  42. {
  43. AddBindParamRaw( k_EGCSQLType_int32, (byte *)&nValue, sizeof( nValue ) );
  44. }
  45. void AddBindParam( const uint32 uValue )
  46. {
  47. AddBindParamRaw( k_EGCSQLType_int32, (byte *)&uValue, sizeof( uValue ) );
  48. }
  49. void AddBindParam( const uint64 ulValue )
  50. {
  51. AddBindParamRaw( k_EGCSQLType_int64, (byte *)&ulValue, sizeof( ulValue ) );
  52. }
  53. void AddBindParam( const uint8 *ubValue, const int cubValue )
  54. {
  55. AddBindParamRaw( k_EGCSQLType_Blob, (byte *)ubValue, cubValue );
  56. }
  57. void AddBindParam( const float fValue )
  58. {
  59. AddBindParamRaw( k_EGCSQLType_float, (byte *)&fValue, sizeof ( fValue ) );
  60. }
  61. void AddBindParam( const double dValue )
  62. {
  63. AddBindParamRaw( k_EGCSQLType_double, (byte *)&dValue, sizeof ( dValue ) );
  64. }
  65. void ClearParams();
  66. // this is used internally to bind a field with its type. You probably want
  67. // some version of AddBindParam instead of this.
  68. void AddBindParamRaw( EGCSQLType eType, const byte *pubData, uint32 cubData );
  69. // ------- Interface implementation from IGCSQLQuery -----
  70. // get the null-terminated query string itself
  71. virtual const char *PchCommand() { return m_sCommand.Get(); }
  72. // gets the parameter data
  73. virtual uint32 CnParams() { return m_vecParams.Count(); }
  74. virtual EGCSQLType EParamType( uint32 uIndex ) { return m_vecParams[uIndex].m_eType; }
  75. virtual byte *PubParam( uint32 uIndex ) { return m_vecParams[uIndex].m_pubData; }
  76. virtual uint32 CubParam( uint32 uIndex ) { return m_vecParams[uIndex].m_cubData; }
  77. private:
  78. CUtlString m_sCommand;
  79. CUtlVector< GCSQLBindParam_t > m_vecParams;
  80. };
  81. class CGCSQLQueryGroup : public IGCSQLQuery, public CRefCount
  82. {
  83. // create query groups on the heap with alloc
  84. CGCSQLQueryGroup();
  85. // destroy query groups by releasing them
  86. virtual ~CGCSQLQueryGroup();
  87. public:
  88. static CGCSQLQueryGroup *Alloc() { return new CGCSQLQueryGroup(); }
  89. void AddQuery( CGCSQLQuery *pQuery );
  90. void SetName( const char *sName );
  91. // returns the number of statements in the transaction
  92. // represented by this query object
  93. virtual uint32 GetStatementCount() { return m_vecQueries.Count(); }
  94. // returns a string that represents where in the GC this
  95. // query came from. Usually this is FILE_AND_LINE.
  96. virtual const char *PchName() { return m_sName; }
  97. // get the null-terminated query string itself
  98. virtual const char *PchCommand( uint32 unStatement ) { return m_vecQueries[unStatement]->PchCommand(); }
  99. // gets the parameter data
  100. virtual uint32 CnParams( uint32 unStatement ) { return m_vecQueries[unStatement]->CnParams(); }
  101. virtual EGCSQLType EParamType( uint32 unStatement, uint32 uIndex ) { return m_vecQueries[unStatement]->EParamType( uIndex ); }
  102. virtual byte *PubParam( uint32 unStatement, uint32 uIndex ) { return m_vecQueries[unStatement]->PubParam( uIndex ); }
  103. virtual uint32 CubParam( uint32 unStatement, uint32 uIndex ) { return m_vecQueries[unStatement]->CubParam( uIndex ); };
  104. // reports the result
  105. virtual void SetResults( IGCSQLResultSetList *pResults );
  106. IGCSQLResultSetList *GetResults() { return m_pResults; }
  107. // clears all the queries in the query group and resets its name
  108. void Clear();
  109. private:
  110. CUtlVector< CGCSQLQuery * > m_vecQueries;
  111. CUtlString m_sName;
  112. IGCSQLResultSetList *m_pResults;
  113. };
  114. } // namespace GCSDK
  115. #include "tier0/memdbgoff.h"
  116. #endif // GCSQLQUERY_H