Added FieldName for column name requests

This commit is contained in:
Arthur Ice 2014-07-06 16:01:10 -07:00
parent d514eef59b
commit 923adc3ea5
2 changed files with 20 additions and 3 deletions

View File

@ -32,10 +32,11 @@ MySQLRequestResult::MySQLRequestResult(MYSQL_RES* result, uint32 rowsAffected, u
m_RowsAffected = rowsAffected;
m_RowCount = rowCount;
m_ColumnCount = columnCount;
// If we actually need the column length it will be requested
// at that time, no need to pull it in just to cache it.
// If we actually need the column length / fields it will be
// requested at that time, no need to pull it in just to cache it.
// Normal usage would have it as nullptr most likely anyways.
m_ColumnLengths = nullptr;
m_Fields = nullptr;
m_LastInsertedID = lastInsertedID;
m_ErrorNumber = errorNumber;
}
@ -56,6 +57,7 @@ void MySQLRequestResult::ZeroOut()
m_Result = nullptr;
m_ErrorBuffer = nullptr;
m_ColumnLengths = nullptr;
m_Fields = nullptr;
m_RowCount = 0;
m_RowsAffected = 0;
m_LastInsertedID = 0;
@ -88,6 +90,17 @@ uint32 MySQLRequestResult::LengthOfColumn(int columnIndex)
return m_ColumnLengths[columnIndex];
}
const std::string MySQLRequestResult::FieldName(int columnIndex)
{
if (columnIndex >= m_ColumnCount || m_Result == nullptr)
return std::string();
if (m_Fields == nullptr)
m_Fields = mysql_fetch_fields(m_Result);
return std::string(m_Fields[columnIndex].name);
}
MySQLRequestResult::MySQLRequestResult(MySQLRequestResult&& moveItem)
: m_CurrentRow(moveItem.m_CurrentRow), m_OneBeyondRow()
{
@ -98,6 +111,7 @@ MySQLRequestResult::MySQLRequestResult(MySQLRequestResult&& moveItem)
m_RowsAffected = moveItem.m_RowsAffected;
m_LastInsertedID = moveItem.m_LastInsertedID;
m_ColumnLengths = moveItem.m_ColumnLengths;
m_Fields = moveItem.m_Fields;
// Keeps deconstructor from double freeing
// pre move instance.
@ -124,7 +138,8 @@ MySQLRequestResult& MySQLRequestResult::operator=(MySQLRequestResult&& other)
m_CurrentRow = other.m_CurrentRow;
m_OneBeyondRow = other.m_OneBeyondRow;
m_ColumnLengths = other.m_ColumnLengths;
m_Fields = other.m_Fields;
// Keeps deconstructor from double freeing
// pre move instance.
other.ZeroOut();

View File

@ -16,6 +16,7 @@
class MySQLRequestResult {
private:
MYSQL_RES* m_Result;
MYSQL_FIELD* m_Fields;
char* m_ErrorBuffer;
unsigned long* m_ColumnLengths;
MySQLRequestRow m_CurrentRow;
@ -47,6 +48,7 @@ public:
uint32 LastInsertedID() const {return m_LastInsertedID;}
// default to 0 index since we mostly use it that way anyways.
uint32 LengthOfColumn(int columnIndex = 0);
const std::string FieldName(int columnIndex);
MySQLRequestRow& begin() { return m_CurrentRow; }
MySQLRequestRow& end() { return m_OneBeyondRow;}