TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SQLQueryHolder Class Reference

#include <QueryHolder.h>

Public Member Functions

 SQLQueryHolder ()
 
virtual ~SQLQueryHolder ()
 
bool SetQuery (size_t index, const char *sql)
 
template<typename Format , typename... Args>
bool SetPQuery (size_t index, Format &&sql, Args &&...args)
 
bool SetPreparedQuery (size_t index, PreparedStatement *stmt)
 
void SetSize (size_t size)
 
QueryResult GetResult (size_t index)
 
PreparedQueryResult GetPreparedResult (size_t index)
 
void SetResult (size_t index, ResultSet *result)
 
void SetPreparedResult (size_t index, PreparedResultSet *result)
 

Private Types

typedef std::pair
< SQLElementData,
SQLResultSetUnion
SQLResultPair
 

Private Attributes

std::vector< SQLResultPairm_queries
 

Friends

class SQLQueryHolderTask
 

Member Typedef Documentation

Constructor & Destructor Documentation

SQLQueryHolder::SQLQueryHolder ( )
inline
30 { }
SQLQueryHolder::~SQLQueryHolder ( )
virtual

if the result was never used, free the resources results used already (getresult called) are expected to be deleted

120 {
121  for (size_t i = 0; i < m_queries.size(); i++)
122  {
125  if (SQLElementData* data = &m_queries[i].first)
126  {
127  switch (data->type)
128  {
129  case SQL_ELEMENT_RAW:
130  free((void*)(const_cast<char*>(data->element.query)));
131  break;
133  delete data->element.stmt;
134  break;
135  }
136  }
137  }
138 }
Definition: SQLOperation.h:36
std::vector< SQLResultPair > m_queries
Definition: QueryHolder.h:28
Definition: SQLOperation.h:41
Definition: SQLOperation.h:37

Member Function Documentation

PreparedQueryResult SQLQueryHolder::GetPreparedResult ( size_t  index)
79 {
80  // Don't call to this function if the index is of a prepared statement
81  if (index < m_queries.size())
82  {
83  PreparedResultSet* result = m_queries[index].second.presult;
84  if (!result || !result->GetRowCount())
85  return PreparedQueryResult(NULL);
86 
87  return PreparedQueryResult(result);
88  }
89  else
90  return PreparedQueryResult(NULL);
91 }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
std::vector< SQLResultPair > m_queries
Definition: QueryHolder.h:28
arena_t NULL
Definition: jemalloc_internal.h:624
uint64 GetRowCount() const
Definition: QueryResult.h:70
Definition: QueryResult.h:63

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QueryResult SQLQueryHolder::GetResult ( size_t  index)
64 {
65  // Don't call to this function if the index is of an ad-hoc statement
66  if (index < m_queries.size())
67  {
68  ResultSet* result = m_queries[index].second.qresult;
69  if (!result || !result->GetRowCount() || !result->NextRow())
70  return QueryResult(NULL);
71 
72  return QueryResult(result);
73  }
74  else
75  return QueryResult(NULL);
76 }
bool NextRow()
Definition: QueryResult.cpp:176
std::vector< SQLResultPair > m_queries
Definition: QueryHolder.h:28
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: QueryResult.h:30
uint64 GetRowCount() const
Definition: QueryResult.h:37
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61

+ Here is the call graph for this function:

template<typename Format , typename... Args>
bool SQLQueryHolder::SetPQuery ( size_t  index,
Format &&  sql,
Args &&...  args 
)
inline
35  {
36  return SetQuery(index, Trinity::StringFormat(std::forward<Format>(sql), std::forward<Args>(args)...).c_str());
37  }
bool SetQuery(size_t index, const char *sql)
Definition: QueryHolder.cpp:23
std::string StringFormat(Format &&fmt, Args &&...args)
Default TC string format function.
Definition: StringFormat.h:28

+ Here is the call graph for this function:

bool SQLQueryHolder::SetPreparedQuery ( size_t  index,
PreparedStatement stmt 
)

not executed yet, just stored (it's not called a holder for nothing)

44 {
45  if (m_queries.size() <= index)
46  {
47  TC_LOG_ERROR("sql.sql", "Query index (%u) out of range (size: %u) for prepared statement", uint32(index), (uint32)m_queries.size());
48  return false;
49  }
50 
52  SQLElementData element;
53  element.type = SQL_ELEMENT_PREPARED;
54  element.element.stmt = stmt;
55 
56  SQLResultSetUnion result;
57  result.presult = NULL;
58 
59  m_queries[index] = SQLResultPair(element, result);
60  return true;
61 }
PreparedResultSet * presult
Definition: SQLOperation.h:50
std::vector< SQLResultPair > m_queries
Definition: QueryHolder.h:28
std::pair< SQLElementData, SQLResultSetUnion > SQLResultPair
Definition: QueryHolder.h:27
arena_t NULL
Definition: jemalloc_internal.h:624
PreparedStatement * stmt
Definition: SQLOperation.h:29
Definition: SQLOperation.h:48
uint32_t uint32
Definition: Define.h:150
SQLElementDataType type
Definition: SQLOperation.h:44
Definition: SQLOperation.h:41
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
uint32_t uint32
Definition: g3dmath.h:168
SQLElementUnion element
Definition: SQLOperation.h:43
Definition: SQLOperation.h:37

+ Here is the caller graph for this function:

void SQLQueryHolder::SetPreparedResult ( size_t  index,
PreparedResultSet result 
)

store the result in the holder

107 {
108  if (result && !result->GetRowCount())
109  {
110  delete result;
111  result = NULL;
112  }
113 
115  if (index < m_queries.size())
116  m_queries[index].second.presult = result;
117 }
std::vector< SQLResultPair > m_queries
Definition: QueryHolder.h:28
arena_t NULL
Definition: jemalloc_internal.h:624
uint64 GetRowCount() const
Definition: QueryResult.h:70

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool SQLQueryHolder::SetQuery ( size_t  index,
const char *  sql 
)

not executed yet, just stored (it's not called a holder for nothing)

24 {
25  if (m_queries.size() <= index)
26  {
27  TC_LOG_ERROR("sql.sql", "Query index (%u) out of range (size: %u) for query: %s", uint32(index), (uint32)m_queries.size(), sql);
28  return false;
29  }
30 
32  SQLElementData element;
33  element.type = SQL_ELEMENT_RAW;
34  element.element.query = strdup(sql);
35 
36  SQLResultSetUnion result;
37  result.qresult = NULL;
38 
39  m_queries[index] = SQLResultPair(element, result);
40  return true;
41 }
Definition: SQLOperation.h:36
ResultSet * qresult
Definition: SQLOperation.h:51
std::vector< SQLResultPair > m_queries
Definition: QueryHolder.h:28
std::pair< SQLElementData, SQLResultSetUnion > SQLResultPair
Definition: QueryHolder.h:27
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: SQLOperation.h:48
const char * query
Definition: SQLOperation.h:30
uint32_t uint32
Definition: Define.h:150
SQLElementDataType type
Definition: SQLOperation.h:44
Definition: SQLOperation.h:41
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
uint32_t uint32
Definition: g3dmath.h:168
SQLElementUnion element
Definition: SQLOperation.h:43
void SQLQueryHolder::SetResult ( size_t  index,
ResultSet result 
)

store the result in the holder

94 {
95  if (result && !result->GetRowCount())
96  {
97  delete result;
98  result = NULL;
99  }
100 
102  if (index < m_queries.size())
103  m_queries[index].second.qresult = result;
104 }
std::vector< SQLResultPair > m_queries
Definition: QueryHolder.h:28
arena_t NULL
Definition: jemalloc_internal.h:624
uint64 GetRowCount() const
Definition: QueryResult.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SQLQueryHolder::SetSize ( size_t  size)

to optimize push_back, reserve the number of queries about to be executed

141 {
143  m_queries.resize(size);
144 }
std::vector< SQLResultPair > m_queries
Definition: QueryHolder.h:28

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend class SQLQueryHolderTask
friend

Member Data Documentation

std::vector<SQLResultPair> SQLQueryHolder::m_queries
private

The documentation for this class was generated from the following files: