Team Fortress 2 Source Code as on 22/4/2020
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.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "stdafx.h"
  8. #include "tier0/memdbgoff.h"
  9. namespace GCSDK
  10. {
  11. IMPLEMENT_CLASS_MEMPOOL( CGCSQLQuery, 1000, UTLMEMORYPOOL_GROW_SLOW );
  12. IMPLEMENT_CLASS_MEMPOOL( CGCSQLQueryGroup, 1000, UTLMEMORYPOOL_GROW_SLOW );
  13. }
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. namespace GCSDK
  17. {
  18. //----------------------------------------------------------------------------
  19. // Purpose: Constructor.
  20. //----------------------------------------------------------------------------
  21. // create queries on the heap with Alloc
  22. CGCSQLQuery::CGCSQLQuery()
  23. {
  24. m_pBufParams = GetBufferPool().GetBuffer();
  25. }
  26. //----------------------------------------------------------------------------
  27. // Purpose: Destructor.
  28. //----------------------------------------------------------------------------
  29. CGCSQLQuery::~CGCSQLQuery()
  30. {
  31. // free all the data
  32. ClearParams();
  33. GetBufferPool().ReturnBuffer( m_pBufParams );
  34. }
  35. //----------------------------------------------------------------------------
  36. // Purpose: Gets a singleton buffer pool for bind params
  37. //----------------------------------------------------------------------------
  38. static GCConVar sql_bind_param_max_pool_size_mb( "sql_bind_param_max_pool_size_mb", "10", "Maximum size in bytes of the SQL Bind Param buffer pool" );
  39. static GCConVar sql_bind_param_init_buffer_size( "sql_bind_param_init_buffer_size", "16384", "Initial buffer size for buffers in the SQL Bind Param buffer pool" );
  40. /*static*/ CBufferPool &CGCSQLQuery::GetBufferPool()
  41. {
  42. static CBufferPool s_bufferPool( "SQL bind params", sql_bind_param_max_pool_size_mb, sql_bind_param_init_buffer_size );
  43. return s_bufferPool;
  44. }
  45. //----------------------------------------------------------------------------
  46. // Purpose: Allocates a bit of memory for the parameter and adds it to the list
  47. //----------------------------------------------------------------------------
  48. void CGCSQLQuery::AddBindParamRaw( EGCSQLType eType, const byte *pubData, uint32 cubData )
  49. {
  50. Assert( m_vecParams.Count() < k_cMaxBindParams );
  51. if( m_vecParams.Count() >= k_cMaxBindParams )
  52. return;
  53. GCSQLBindParam_t &param = m_vecParams[ m_vecParams.AddToTail() ];
  54. param.m_eType = eType;
  55. param.m_cubData = cubData;
  56. if ( cubData )
  57. {
  58. param.m_nOffset = m_pBufParams->TellPut();
  59. m_pBufParams->Put( pubData, cubData );
  60. }
  61. else
  62. {
  63. param.m_nOffset = 0;
  64. }
  65. }
  66. //----------------------------------------------------------------------------
  67. // Purpose: frees all the bind params
  68. //----------------------------------------------------------------------------
  69. void CGCSQLQuery::ClearParams()
  70. {
  71. m_vecParams.RemoveAll();
  72. m_pBufParams->Clear();
  73. }
  74. //----------------------------------------------------------------------------
  75. // Purpose: Constructor.
  76. //----------------------------------------------------------------------------
  77. // create queries on the heap with Alloc
  78. CGCSQLQueryGroup::CGCSQLQueryGroup()
  79. : m_pResults( NULL )
  80. {
  81. }
  82. //----------------------------------------------------------------------------
  83. // Purpose: Sets the result pointer
  84. //----------------------------------------------------------------------------
  85. CGCSQLQueryGroup::~CGCSQLQueryGroup()
  86. {
  87. // free all the data
  88. Clear();
  89. if( m_pResults )
  90. m_pResults->Destroy();
  91. }
  92. //----------------------------------------------------------------------------
  93. // Purpose: Adds a new query to the group
  94. //----------------------------------------------------------------------------
  95. void CGCSQLQueryGroup::AddQuery( CGCSQLQuery *pQuery )
  96. {
  97. m_vecQueries.AddToTail( pQuery );
  98. }
  99. //----------------------------------------------------------------------------
  100. // Purpose: Sets the name (file and line) for the group
  101. //----------------------------------------------------------------------------
  102. void CGCSQLQueryGroup::SetName( const char *sName )
  103. {
  104. m_sName = sName;
  105. }
  106. //----------------------------------------------------------------------------
  107. // Purpose: clears all the queries in the query group and resets its name
  108. //----------------------------------------------------------------------------
  109. void CGCSQLQueryGroup::Clear()
  110. {
  111. m_vecQueries.PurgeAndDeleteElements();
  112. m_sName = "";
  113. }
  114. //----------------------------------------------------------------------------
  115. // Purpose: Sets the result pointer
  116. //----------------------------------------------------------------------------
  117. void CGCSQLQueryGroup::SetResults( IGCSQLResultSetList *pResults )
  118. {
  119. if( m_pResults )
  120. m_pResults->Destroy();
  121. m_pResults = pResults;
  122. }
  123. } // namespace GCSDK