Skip to content

Commit bb272f0

Browse files
committed
Expose column names in row struct
1 parent d28a180 commit bb272f0

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

source/mysql/protocol/comms.d

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ body
636636

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

648648
uint fieldCount = cast(uint)rh.fieldCount;
649-
_values.length = _nulls.length = fieldCount;
649+
_values.length = _nulls.length = _names.length = fieldCount;
650650

651651
if(binary)
652652
{
@@ -669,6 +669,7 @@ body
669669
do
670670
{
671671
FieldDescription fd = rh[i];
672+
_names[i] = fd.name;
672673
sqlValue = packet.consumeIfComplete(fd.type, binary, fd.unsigned, fd.charSet);
673674
// TODO: Support chunk delegate
674675
if(sqlValue.isIncomplete)

source/mysql/result.d

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ package:
3535
Variant[] _values; // Temporarily "package" instead of "private"
3636
private:
3737
bool[] _nulls;
38+
string[] _names;
3839

3940
public:
4041

@@ -51,7 +52,7 @@ public:
5152
+/
5253
this(Connection con, ref ubyte[] packet, ResultSetHeaders rh, bool binary)
5354
{
54-
ctorRow(con, packet, rh, binary, _values, _nulls);
55+
ctorRow(con, packet, rh, binary, _values, _nulls, _names);
5556
}
5657

5758
/++
@@ -72,6 +73,14 @@ public:
7273
return _values[i];
7374
}
7475

76+
/++
77+
Get the name of the column with specified index.
78+
+/
79+
string getName(size_t index)
80+
{
81+
return _names[index];
82+
}
83+
7584
/++
7685
Check if a column in the result row was NULL
7786

0 commit comments

Comments
 (0)