2 * Firebird ADO.NET Data provider for .NET and Mono
4 * The contents of this file are subject to the Initial
5 * Developer's Public License Version 1.0 (the "License");
6 * you may not use this file except in compliance with the
7 * License. You may obtain a copy of the License at
8 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
10 * Software distributed under the License is distributed on
11 * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
12 * express or implied. See the License for the specific
13 * language governing rights and limitations under the License.
15 * Copyright (c) 2002, 2004 Carlos Guzman Alvarez
16 * All Rights Reserved.
19 using NUnit.Framework;
21 using System.Collections;
22 using System.Security.Cryptography;
23 using FirebirdSql.Data.Firebird;
25 namespace FirebirdSql.Data.Firebird.Tests
28 public class FbBlobTest : BaseTest
30 public FbBlobTest() : base(false)
35 public void BinaryBlobTest()
37 int id_value = this.GetId();
39 string selectText = "SELECT blob_field FROM TEST WHERE int_field = " + id_value.ToString();
40 string insertText = "INSERT INTO TEST (int_field, blob_field) values(@int_field, @blob_field)";
42 Console.WriteLine("\r\n\r\nBinary Blob Test");
44 Console.WriteLine("Generating an array of temp data");
45 // Generate an array of temp data
46 byte[] insert_values = new byte[100000*4];
47 RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
48 rng.GetBytes(insert_values);
50 Console.WriteLine("Executing insert command");
52 // Execute insert command
53 FbTransaction transaction = Connection.BeginTransaction();
55 FbCommand insert = new FbCommand(insertText, Connection, transaction);
56 insert.Parameters.Add("@int_field", FbDbType.Integer).Value = id_value;
57 insert.Parameters.Add("@blob_field", FbDbType.Binary).Value = insert_values;
58 insert.ExecuteNonQuery();
62 Console.WriteLine("Checking inserted values");
64 // Check that inserted values are correct
65 FbCommand select = new FbCommand(selectText, Connection);
66 byte[] select_values = (byte[])select.ExecuteScalar();
68 for (int i = 0; i < insert_values.Length; i++)
70 if (insert_values[i] != select_values[i])
72 throw new Exception("differences at index " + i.ToString());
76 Console.WriteLine("Finishing test");
80 public void ReaderGetBytes()
82 int id_value = this.GetId();
84 string selectText = "SELECT blob_field FROM TEST WHERE int_field = " + id_value.ToString();
85 string insertText = "INSERT INTO TEST (int_field, blob_field) values(@int_field, @blob_field)";
87 Console.WriteLine("\r\n\r\nFbDataReader.GetBytes with Binary Blob Test");
89 Console.WriteLine("Generating an array of temp data");
90 // Generate an array of temp data
91 byte[] insert_values = new byte[100000*4];
92 RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
93 rng.GetBytes(insert_values);
95 Console.WriteLine("Executing insert command");
97 // Execute insert command
98 FbTransaction transaction = Connection.BeginTransaction();
100 FbCommand insert = new FbCommand(insertText, Connection, transaction);
101 insert.Parameters.Add("@int_field", FbDbType.Integer).Value = id_value;
102 insert.Parameters.Add("@blob_field", FbDbType.Binary).Value = insert_values;
103 insert.ExecuteNonQuery();
105 transaction.Commit();
107 Console.WriteLine("Checking inserted values");
109 // Check that inserted values are correct
110 FbCommand select = new FbCommand(selectText, Connection);
112 FbDataReader reader = select.ExecuteReader();
115 int segmentSize = 1000;
116 byte[] select_values = new byte[100000*4];
117 while (reader.Read())
119 while (index < 400000)
121 reader.GetBytes(0, index, select_values, index, segmentSize);
123 index += segmentSize;
127 for (int i = 0; i < insert_values.Length; i++)
129 if (insert_values[i] != select_values[i])
131 throw new Exception("differences at index " + i.ToString());