Skip to content

Commit

Permalink
Expose column names in row struct
Browse files Browse the repository at this point in the history
  • Loading branch information
jpf91 committed Dec 15, 2018
1 parent d28a180 commit bb272f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 3 additions & 2 deletions source/mysql/protocol/comms.d
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ body

// Moved here from `struct Row.this`
package(mysql) void ctorRow(Connection conn, ref ubyte[] packet, ResultSetHeaders rh, bool binary,
out Variant[] _values, out bool[] _nulls)
out Variant[] _values, out bool[] _nulls, out string[] _names)
in
{
assert(rh.fieldCount <= uint.max);
Expand All @@ -646,7 +646,7 @@ body
scope(failure) conn.kill();

uint fieldCount = cast(uint)rh.fieldCount;
_values.length = _nulls.length = fieldCount;
_values.length = _nulls.length = _names.length = fieldCount;

if(binary)
{
Expand All @@ -669,6 +669,7 @@ body
do
{
FieldDescription fd = rh[i];
_names[i] = fd.name;
sqlValue = packet.consumeIfComplete(fd.type, binary, fd.unsigned, fd.charSet);
// TODO: Support chunk delegate
if(sqlValue.isIncomplete)
Expand Down
11 changes: 10 additions & 1 deletion source/mysql/result.d
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ package:
Variant[] _values; // Temporarily "package" instead of "private"
private:
bool[] _nulls;
string[] _names;

public:

Expand All @@ -51,7 +52,7 @@ public:
+/
this(Connection con, ref ubyte[] packet, ResultSetHeaders rh, bool binary)
{
ctorRow(con, packet, rh, binary, _values, _nulls);
ctorRow(con, packet, rh, binary, _values, _nulls, _names);
}

/++
Expand All @@ -72,6 +73,14 @@ public:
return _values[i];
}

/++
Get the name of the column with specified index.
+/
string getName(size_t index)
{
return _names[index];
}

/++
Check if a column in the result row was NULL
Expand Down

0 comments on commit bb272f0

Please sign in to comment.