|
From:
<car...@te...> - 2003-11-25 16:00:41
|
Hello:
> Hi,
> I am using Firebird .Net 1.4 beta4 net framework version 1.1.
> The getbytes would not return a data for blob columns.
> It look like have a bug in Getbytes procedure.
Seems to be working for me, here is the source:
[Test]
public void ReaderGetBytes()
{
int id_value = System.DateTime.Now.Millisecond + 20000;
string selectText = "SELECT blob_field FROM TEST WHERE int_field = " +
id_value.ToString();
string insertText = "INSERT INTO TEST (int_field, blob_field)
values(@int_field, @blob_field)";
Console.WriteLine("\r\n\r\nFbDataReader.GetBytes with Binary Blob Test");
Console.WriteLine("Generating an array of temp data");
// Generate an array of temp data
byte[] insert_values = new byte[100000*4];
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
rng.GetBytes(insert_values);
Console.WriteLine("Executing insert command");
// Execute insert command
FbTransaction transaction = Connection.BeginTransaction();
FbCommand insert = new FbCommand(insertText, Connection, transaction);
insert.Parameters.Add("@int_field", FbDbType.Integer).Value = id_value;
insert.Parameters.Add("@blob_field", FbDbType.Binary).Value =
insert_values;
insert.ExecuteNonQuery();
transaction.Commit();
Console.WriteLine("Checking inserted values");
// Check that inserted values are correct
FbCommand select = new FbCommand(selectText, Connection);
FbDataReader reader = select.ExecuteReader();
int index = 0;
int segmentSize = 1000;
byte[] select_values = new byte[100000*4];
while (reader.Read())
{
while (index < 400000)
{
reader.GetBytes(0, index, select_values, index, segmentSize);
index += segmentSize;
}
}
for (int i = 0; i < insert_values.Length; i++)
{
if (insert_values[i] != select_values[i])
{
throw new Exception("differences at index " + i.ToString());
}
}
}
--
Best regards
Carlos Guzmán Álvarez
Vigo-Spain
|