Skip to content

Commit a27653a

Browse files
committed
Output specific array datatypes from GetDataTypeName
Fixes npgsql#787
1 parent 49297b3 commit a27653a

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

src/Npgsql/NpgsqlDataReader.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,8 @@ public override int GetOrdinal(string name)
11381138

11391139
/// <summary>
11401140
/// Gets the data type information for the specified field.
1141-
/// This will be the Postgresql type name (e.g. int4), not the .NET type (<see cref="GetFieldType"/>)
1141+
/// This will be the PostgreSQL type name (e.g. int4) as in the pg_type table,
1142+
/// not the .NET type (see <see cref="GetFieldType"/> for that).
11421143
/// </summary>
11431144
/// <param name="ordinal"></param>
11441145
/// <returns></returns>

src/Npgsql/TypeHandlerRegistry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ void RegisterArrayType(BackendType backendType)
342342
arrayHandler = (TypeHandler)Activator.CreateInstance(arrayHandlerType, elementHandler);
343343
}
344344

345-
arrayHandler.PgName = "array";
345+
arrayHandler.PgName = backendType.Name;
346346
arrayHandler.OID = backendType.OID;
347347
OIDIndex[backendType.OID] = arrayHandler;
348348

test/Npgsql.Tests/ReaderTests.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,21 @@ public void GetValueByName()
198198
}
199199

200200
[Test]
201+
[IssueLink("https://github.com/npgsql/npgsql/issues/787")]
201202
public void GetDataTypeName()
202203
{
203-
var command = new NpgsqlCommand(@"SELECT 1::INT4 AS some_column", Conn);
204-
var dr = command.ExecuteReader();
205-
dr.Read();
206-
Assert.That(dr.GetDataTypeName(0), Is.EqualTo("int4"));
207-
command.Dispose();
204+
using (var command = new NpgsqlCommand(@"SELECT 1::INT4 AS some_column", Conn))
205+
using (var reader = command.ExecuteReader())
206+
{
207+
reader.Read();
208+
Assert.That(reader.GetDataTypeName(0), Is.EqualTo("int4"));
209+
}
210+
using (var command = new NpgsqlCommand(@"SELECT '{1}'::INT4[] AS some_column", Conn))
211+
using (var reader = command.ExecuteReader())
212+
{
213+
reader.Read();
214+
Assert.That(reader.GetDataTypeName(0), Is.EqualTo("_int4"));
215+
}
208216
}
209217

210218
[Test]

0 commit comments

Comments
 (0)