1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-02-21 20:27:13 +01:00

Add a property to the MySQL result-set to retrieve all available field names as an array.

This commit is contained in:
Sandu Liviu Catalin 2016-07-28 01:11:21 +03:00
parent 8ce40ee74c
commit f660e2a155
2 changed files with 30 additions and 0 deletions

View File

@ -156,6 +156,30 @@ void ResultSet::ValidateField(Int32 idx) const
} }
#endif // _DEBUG #endif // _DEBUG
// ------------------------------------------------------------------------------------------------
Array ResultSet::FieldNames() const
{
SQMOD_VALIDATE_CREATED(*this);
// Grab the number of available fields
const SQInteger fcount = ConvTo< SQInteger >::From(m_Handle->mFieldCount);
// Grab the array with field instances
const ResHnd::FieldType * fields = m_Handle->mFields;
// Is there even something to process?
if (!fcount || !fields)
{
return Array(DefaultVM::Get(), 0);
}
// Allocate an array with the same amount of elements as the number of fields
Array arr(DefaultVM::Get(), fcount);
// Iterate over all the available fields and insert them into the created array
for (SQInteger n = 0; n < fcount; ++n)
{
arr.SetValue(n, (fields[n].name == nullptr) ? ToStrF("<field_%ld>", n) : fields[n].name);
}
// Return the resulted array
return arr;
}
// ================================================================================================ // ================================================================================================
void Register_ResultSet(Table & sqlns) void Register_ResultSet(Table & sqlns)
{ {
@ -170,6 +194,7 @@ void Register_ResultSet(Table & sqlns)
.Func(_SC("_tostring"), &ResultSet::ToString) .Func(_SC("_tostring"), &ResultSet::ToString)
// Properties // Properties
.Prop(_SC("IsValid"), &ResultSet::IsValid) .Prop(_SC("IsValid"), &ResultSet::IsValid)
.Prop(_SC("FieldNames"), &ResultSet::FieldNames)
.Prop(_SC("RowIndex"), &ResultSet::RowIndex) .Prop(_SC("RowIndex"), &ResultSet::RowIndex)
.Prop(_SC("RowCount"), &ResultSet::RowCount) .Prop(_SC("RowCount"), &ResultSet::RowCount)
// Member Methods // Member Methods

View File

@ -192,6 +192,11 @@ public:
return m_Handle; return m_Handle;
} }
/* --------------------------------------------------------------------------------------------
* Returns an array with all the field names available in the managed result set.
*/
Array FieldNames() const;
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Returns the current position of the row cursor for the last Next(). * Returns the current position of the row cursor for the last Next().
*/ */