AzeorthCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
ResultSet Class Reference

#include "QueryResult.h"

Public Member Functions

 ResultSet (MySQLResult *result, MySQLField *fields, uint64 rowCount, uint32 fieldCount)
 
 ~ResultSet ()
 
bool NextRow ()
 
uint64 GetRowCount () const
 
uint32 GetFieldCount () const
 
std::string GetFieldName (uint32 index) const
 
FieldFetch () const
 
Field const & operator[] (std::size_t index) const
 
template<typename... Ts>
std::tuple< Ts... > FetchTuple ()
 
auto begin ()
 

Static Public Member Functions

static auto end ()
 

Protected Attributes

std::vector< QueryResultFieldMetadata_fieldMetadata
 
uint64 _rowCount
 
Field_currentRow
 
uint32 _fieldCount
 

Private Member Functions

void CleanUp ()
 
void AssertRows (std::size_t sizeRows)
 
 ResultSet (ResultSet const &right)=delete
 
ResultSetoperator= (ResultSet const &right)=delete
 

Private Attributes

MySQLResult_result
 
MySQLField_fields
 

Detailed Description

Constructor & Destructor Documentation

◆ ResultSet() [1/2]

ResultSet::ResultSet ( MySQLResult result,
MySQLField fields,
uint64  rowCount,
uint32  fieldCount 
)
167 :
168 _rowCount(rowCount),
169 _fieldCount(fieldCount),
170 _result(result),
171 _fields(fields)
172{
175
176 for (uint32 i = 0; i < _fieldCount; i++)
177 {
180 }
181}
std::uint32_t uint32
Definition: Define.h:108
void InitializeDatabaseFieldMetadata(QueryResultFieldMetadata *meta, MySQLField const *field, uint32 fieldIndex)
Definition: QueryResult.cpp:155
Class used to access individual fields of database query result.
Definition: Field.h:99
void SetMetadata(QueryResultFieldMetadata const *fieldMeta)
Definition: Field.cpp:190
uint32 _fieldCount
Definition: QueryResult.h:85
Field * _currentRow
Definition: QueryResult.h:84
uint64 _rowCount
Definition: QueryResult.h:83
MySQLField * _fields
Definition: QueryResult.h:92
std::vector< QueryResultFieldMetadata > _fieldMetadata
Definition: QueryResult.h:82
MySQLResult * _result
Definition: QueryResult.h:91

References _currentRow, _fieldCount, _fieldMetadata, _fields, and Field::SetMetadata().

◆ ~ResultSet()

ResultSet::~ResultSet ( )
184{
185 CleanUp();
186}
void CleanUp()
Definition: QueryResult.cpp:222

References CleanUp().

◆ ResultSet() [2/2]

ResultSet::ResultSet ( ResultSet const &  right)
privatedelete

Member Function Documentation

◆ AssertRows()

void ResultSet::AssertRows ( std::size_t  sizeRows)
private
244{
245 ASSERT(sizeRows == _fieldCount);
246}
#define ASSERT
Definition: Errors.h:68

References _fieldCount, and ASSERT.

◆ begin()

auto ResultSet::begin ( )
inline
78{ return ResultIterator<ResultSet>(this); }
Definition: QueryResult.h:29

◆ CleanUp()

void ResultSet::CleanUp ( )
private
223{
224 if (_currentRow)
225 {
226 delete[] _currentRow;
227 _currentRow = nullptr;
228 }
229
230 if (_result)
231 {
232 mysql_free_result(_result);
233 _result = nullptr;
234 }
235}

References _currentRow, and _result.

Referenced by NextRow(), and ~ResultSet().

◆ end()

static auto ResultSet::end ( )
inlinestatic
79{ return ResultIterator<ResultSet>(nullptr); }

◆ Fetch()

Field * ResultSet::Fetch ( ) const
inline
59{ return _currentRow; }

◆ FetchTuple()

template<typename... Ts>
std::tuple< Ts... > ResultSet::FetchTuple ( )
inline
64 {
65 AssertRows(sizeof...(Ts));
66
67 std::tuple<Ts...> theTuple = {};
68
69 std::apply([this](Ts&... args)
70 {
71 uint8 index{ 0 };
72 ((args = _currentRow[index].Get<Ts>(), index++), ...);
73 }, theTuple);
74
75 return theTuple;
76 }
std::uint8_t uint8
Definition: Define.h:110
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:113
void AssertRows(std::size_t sizeRows)
Definition: QueryResult.cpp:243

◆ GetFieldCount()

uint32 ResultSet::GetFieldCount ( ) const
inline
56{ return _fieldCount; }

◆ GetFieldName()

std::string ResultSet::GetFieldName ( uint32  index) const
217{
218 ASSERT(index < _fieldCount);
219 return _fields[index].name;
220}

References _fieldCount, _fields, and ASSERT.

◆ GetRowCount()

uint64 ResultSet::GetRowCount ( ) const
inline

◆ NextRow()

bool ResultSet::NextRow ( )
189{
190 MYSQL_ROW row;
191
192 if (!_result)
193 return false;
194
195 row = mysql_fetch_row(_result);
196 if (!row)
197 {
198 CleanUp();
199 return false;
200 }
201
202 unsigned long* lengths = mysql_fetch_lengths(_result);
203 if (!lengths)
204 {
205 LOG_WARN("sql.sql", "{}:mysql_fetch_lengths, cannot retrieve value lengths. Error {}.", __FUNCTION__, mysql_error(_result->handle));
206 CleanUp();
207 return false;
208 }
209
210 for (uint32 i = 0; i < _fieldCount; i++)
211 _currentRow[i].SetStructuredValue(row[i], lengths[i]);
212
213 return true;
214}
#define LOG_WARN(filterType__,...)
Definition: Log.h:163

References _currentRow, _fieldCount, _result, CleanUp(), and LOG_WARN.

Referenced by BasicStatementTask::Execute(), and DatabaseWorkerPool< T >::Query().

◆ operator=()

ResultSet & ResultSet::operator= ( ResultSet const &  right)
privatedelete

◆ operator[]()

Field const & ResultSet::operator[] ( std::size_t  index) const
238{
239 ASSERT(index < _fieldCount);
240 return _currentRow[index];
241}

References _currentRow, _fieldCount, and ASSERT.

Member Data Documentation

◆ _currentRow

Field* ResultSet::_currentRow
protected

◆ _fieldCount

uint32 ResultSet::_fieldCount
protected

◆ _fieldMetadata

std::vector<QueryResultFieldMetadata> ResultSet::_fieldMetadata
protected

Referenced by ResultSet().

◆ _fields

MySQLField* ResultSet::_fields
private

Referenced by GetFieldName(), and ResultSet().

◆ _result

MySQLResult* ResultSet::_result
private

Referenced by CleanUp(), and NextRow().

◆ _rowCount

uint64 ResultSet::_rowCount
protected