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