From d0106977b66bb1c7a05346fb36ca3f97518f9d17 Mon Sep 17 00:00:00 2001 From: Johannes Pfau Date: Sun, 21 Oct 2018 18:10:38 +0200 Subject: [PATCH] Expose column names in row struct --- source/mysql/protocol/comms.d | 5 +++-- source/mysql/result.d | 11 ++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/source/mysql/protocol/comms.d b/source/mysql/protocol/comms.d index 0fb0ccb3..dcf49e4e 100644 --- a/source/mysql/protocol/comms.d +++ b/source/mysql/protocol/comms.d @@ -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); @@ -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) { @@ -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) diff --git a/source/mysql/result.d b/source/mysql/result.d index 13ac0cfa..0928b53c 100644 --- a/source/mysql/result.d +++ b/source/mysql/result.d @@ -35,6 +35,7 @@ package: Variant[] _values; // Temporarily "package" instead of "private" private: bool[] _nulls; + string[] _names; public: @@ -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); } /++ @@ -72,6 +73,14 @@ public: return _values[i]; } + /++ + Get the name of the column with specified index. + +/ + inout(string) getName(size_t index) inout + { + return _names[index]; + } + /++ Check if a column in the result row was NULL