1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-01-31 09:57:14 +01:00

Add a property to the MySQL result-set to retrieve field wrapper instances for all available fields as a table.

This commit is contained in:
Sandu Liviu Catalin 2016-07-28 01:15:39 +03:00
parent 522ae735e1
commit 27df4fe282
2 changed files with 36 additions and 0 deletions

View File

@ -207,6 +207,36 @@ Array ResultSet::GetFieldsArray() const
return arr;
}
// ------------------------------------------------------------------------------------------------
Table ResultSet::GetFieldsTable() 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 Table();
}
// Create a field instance to insert as copy
Field field(m_Handle);
// Allocate a table to be populated with field instances
Table tbl;
// Iterate over all the available fields and insert them into the created table
for (SQInteger n = 0; n < fcount; ++n)
{
// Update the field index
field.SetIndex(ConvTo< Int32 >::From(n));
// Insert a copy of the field instance into the table
tbl.SetValue((fields[n].name == nullptr) ? ToStrF("<field_%ld>", n) : fields[n].name, field);
}
// Return the resulted table
return tbl;
}
// ================================================================================================
void Register_ResultSet(Table & sqlns)
{
@ -223,6 +253,7 @@ void Register_ResultSet(Table & sqlns)
.Prop(_SC("IsValid"), &ResultSet::IsValid)
.Prop(_SC("FieldNames"), &ResultSet::FieldNames)
.Prop(_SC("FieldsArray"), &ResultSet::GetFieldsArray)
.Prop(_SC("FieldsTable"), &ResultSet::GetFieldsTable)
.Prop(_SC("RowIndex"), &ResultSet::RowIndex)
.Prop(_SC("RowCount"), &ResultSet::RowCount)
// Member Methods

View File

@ -202,6 +202,11 @@ public:
*/
Array GetFieldsArray() const;
/* --------------------------------------------------------------------------------------------
* Returns a table with wrapper instances for all the field available in the managed result set.
*/
Table GetFieldsTable() const;
/* --------------------------------------------------------------------------------------------
* Returns the current position of the row cursor for the last Next().
*/