At the first glance, my problem seems to be quite trivial. I have to read data from Firebird's database, but this database was created by someone else. Raw binary data (like pictures) is stored in BLOB SUB_TYPE TEXT
instead of BLOB SUB_TYPE BINARY
and this is the problem, because Firebird ADO.NET Data Provider (FirebirdSql.Data.FirebirdClient 7.10.1) converts binary data to a string and I cannot find a proper method in this driver that returns binary data as a byte array from BLOB SUB_TYPE TEXT
.
I was trying to reverse binary data converted to a string by provider but without success. I use this provider in the following way (simplified example):
using var fbConnection = new FbConnection(connectionString);
fbConnection.Open();
var readCommand = new FbCommand(command, fbConnection);
var reader = readCommand.ExecuteReader();
while (reader.Read())
{
// reader[0] contains data from column with BLOB SUB_TYPE TEXT type
var rawData = Encoding.Default.GetBytes(reader[0].ToString());
// ...
}
According to this post, this kind of conversion is not possible: https://stackoverflow.com/a/14168060/1281652
Theoretically, one of the workarounds is described here: https://stackoverflow.com/a/24821965 but I cannot modify this database, so in my case, it is not applicable.
How can I read this data correctly in c#?