OregonCore  revision 3611e8a-git
Your Favourite TBC server
QueryResult Class Reference

#include <QueryResult.h>

Public Member Functions

 QueryResult (MYSQL_RES *result, MYSQL_FIELD *fields, uint64 rowCount, uint32 fieldCount)
 
 ~QueryResult ()
 
bool NextRow ()
 
FieldFetch () const
 
Field const & operator[] (int index) const
 
Field const & operator[] (const char *name) const
 
uint32 GetFieldCount () const
 
uint64 GetRowCount () const
 
size_t GetField_idx (const char *name) const
 

Protected Attributes

FieldmCurrentRow
 
uint32 mFieldCount
 
uint64 mRowCount
 
MYSQL_FIELD * mFields
 

Private Member Functions

void EndQuery ()
 

Private Attributes

MYSQL_RES * mResult
 

Detailed Description

Definition at line 33 of file QueryResult.h.

Constructor & Destructor Documentation

QueryResult::QueryResult ( MYSQL_RES *  result,
MYSQL_FIELD *  fields,
uint64  rowCount,
uint32  fieldCount 
)

Definition at line 21 of file QueryResult.cpp.

References ASSERT, mCurrentRow, and mFieldCount.

22  : mFieldCount(fieldCount)
23  , mRowCount(rowCount)
24  , mFields(fields)
25  , mResult(result)
26 {
29 
30  for (uint32 i = 0; i < mFieldCount; i++)
31  mCurrentRow[i].SetType(fields[i].type);
32 }
Definition: Field.h:24
uint64 mRowCount
Definition: QueryResult.h:63
uint32 mFieldCount
Definition: QueryResult.h:62
MYSQL_RES * mResult
Definition: QueryResult.h:69
MYSQL_FIELD * mFields
Definition: QueryResult.h:64
Field * mCurrentRow
Definition: QueryResult.h:61
#define ASSERT
Definition: Errors.h:33
ACE_UINT32 uint32
Definition: Define.h:71
QueryResult::~QueryResult ( )

Definition at line 141 of file QueryResult.cpp.

References PreparedQueryResult::EndQuery().

142 {
143  EndQuery();
144 }
void EndQuery()

Member Function Documentation

void QueryResult::EndQuery ( )
private

Definition at line 166 of file QueryResult.cpp.

References PreparedQueryResult::mCurrentRow.

167 {
168  if (mCurrentRow)
169  {
170  delete [] mCurrentRow;
171  mCurrentRow = 0;
172  }
173 
174  if (mResult)
175  {
176  mysql_free_result(mResult);
177  mResult = 0;
178  }
179 }
MYSQL_RES * mResult
Definition: QueryResult.h:69
Field * mCurrentRow
Definition: QueryResult.h:61
Field* QueryResult::Fetch ( ) const
inline

Definition at line 41 of file QueryResult.h.

References mCurrentRow.

41 { return mCurrentRow; }
Field * mCurrentRow
Definition: QueryResult.h:61
size_t QueryResult::GetField_idx ( const char *  name) const
inline

Definition at line 48 of file QueryResult.h.

References mFieldCount, and mFields.

Referenced by operator[](), and PreparedQueryResult::operator[]().

49  {
50  for (size_t i = 0; i < mFieldCount; ++i)
51  if (!strcmp(name, mFields[i].name))
52  return i;
53 
54  std::string err = "No column named ";
55  err += name;
56  err += "in field list!";
57  throw std::invalid_argument(err);
58  }
uint32 mFieldCount
Definition: QueryResult.h:62
MYSQL_FIELD * mFields
Definition: QueryResult.h:64
uint32 QueryResult::GetFieldCount ( ) const
inline

Definition at line 45 of file QueryResult.h.

References mFieldCount.

45 { return mFieldCount; }
uint32 mFieldCount
Definition: QueryResult.h:62
uint64 QueryResult::GetRowCount ( ) const
inline

Definition at line 46 of file QueryResult.h.

References mRowCount.

46 { return mRowCount; }
uint64 mRowCount
Definition: QueryResult.h:63
bool QueryResult::NextRow ( )

Definition at line 146 of file QueryResult.cpp.

References PreparedQueryResult::EndQuery(), PreparedQueryResult::mCurrentRow, and PreparedQueryResult::mFieldCount.

Referenced by Database::Query().

147 {
148  MYSQL_ROW row;
149 
150  if (!mResult)
151  return false;
152 
153  row = mysql_fetch_row(mResult);
154  if (!row)
155  {
156  EndQuery();
157  return false;
158  }
159 
160  for (uint32 i = 0; i < mFieldCount; i++)
161  mCurrentRow[i].SetValue(row[i]);
162 
163  return true;
164 }
void EndQuery()
uint32 mFieldCount
Definition: QueryResult.h:62
MYSQL_RES * mResult
Definition: QueryResult.h:69
Field * mCurrentRow
Definition: QueryResult.h:61
ACE_UINT32 uint32
Definition: Define.h:71
Field const& QueryResult::operator[] ( int  index) const
inline

Definition at line 42 of file QueryResult.h.

References mCurrentRow.

42 { return mCurrentRow[index]; }
Field * mCurrentRow
Definition: QueryResult.h:61
Field const& QueryResult::operator[] ( const char *  name) const
inline

Definition at line 43 of file QueryResult.h.

References GetField_idx(), and mCurrentRow.

43 { return mCurrentRow[GetField_idx(name)]; }
size_t GetField_idx(const char *name) const
Definition: QueryResult.h:48
Field * mCurrentRow
Definition: QueryResult.h:61

Member Data Documentation

Field* QueryResult::mCurrentRow
protected
uint32 QueryResult::mFieldCount
protected
MYSQL_FIELD* QueryResult::mFields
protected

Definition at line 64 of file QueryResult.h.

Referenced by GetField_idx(), and PreparedQueryResult::GetField_idx().

MYSQL_RES* QueryResult::mResult
private

Definition at line 69 of file QueryResult.h.

uint64 QueryResult::mRowCount
protected

Definition at line 63 of file QueryResult.h.

Referenced by GetRowCount(), and PreparedQueryResult::GetRowCount().


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