Skip to content

Commit a62ee5b

Browse files
committed
Return byte array type for OCTETS fields
1 parent b12039a commit a62ee5b

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎src/FirebirdSql.Data.FirebirdClient.Tests/FbDataReaderTests.cs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,4 +535,22 @@ public async Task GetFieldValueTest()
535535
await transaction.RollbackAsync();
536536
}
537537
}
538+
539+
[Test]
540+
public async Task GetFieldTypeMatchesGetValueForOctetsTest()
541+
{
542+
// IDataRecord.GetFieldType: "the type of Object that would be returned from GetValue."
543+
await using (var command = new FbCommand("select cast('ab' as varchar(10) character set octets), cast('ab' as char(4) character set octets) from rdb$database", Connection))
544+
{
545+
await using (var reader = await command.ExecuteReaderAsync())
546+
{
547+
Assert.IsTrue(await reader.ReadAsync());
548+
for (var i = 0; i < reader.FieldCount; i++)
549+
{
550+
Assert.AreEqual(typeof(byte[]), reader.GetValue(i).GetType());
551+
Assert.AreEqual(typeof(byte[]), reader.GetFieldType(i));
552+
}
553+
}
554+
}
555+
}
538556
}

‎src/FirebirdSql.Data.FirebirdClient/Common/DbField.cs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,12 @@ public void FixNull()
549549

550550
public Type GetSystemType()
551551
{
552+
// SetValue stores CHAR and VARCHAR in the OCTETS character set as byte[], so that is the type GetValue returns.
553+
if ((SqlType == IscCodes.SQL_TEXT || SqlType == IscCodes.SQL_VARYING) && (Charset?.IsOctetsCharset ?? false) && DbDataType != DbDataType.Guid)
554+
{
555+
return typeof(byte[]);
556+
}
557+
552558
return TypeHelper.GetTypeFromDbDataType(DbDataType);
553559
}
554560

0 commit comments

Comments
 (0)