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;
23 using FirebirdSql.Data.Firebird;
25 namespace FirebirdSql.Data.Firebird.Tests
28 public class FbDataReaderTest : BaseTest
30 public FbDataReaderTest() : base(false)
35 public void ReadTest()
37 FbTransaction transaction = Connection.BeginTransaction();
39 FbCommand command = new FbCommand("select * from TEST", Connection, transaction);
42 Console.WriteLine("DataReader - Read Method - Test");
44 IDataReader reader = command.ExecuteReader();
47 for(int i = 0; i < reader.FieldCount; i++)
49 Console.Write(reader.GetValue(i) + "\t");
57 transaction.Rollback();
61 public void BigIntGetStringTest()
63 FbTransaction transaction = Connection.BeginTransaction();
65 FbCommand command = new FbCommand("select * from TEST", Connection, transaction);
68 Console.WriteLine("DataReader - Read Method - Test");
70 IDataReader reader = command.ExecuteReader();
73 Console.Write(reader.GetString(reader.GetOrdinal("bigint_field")) + "\t");
80 transaction.Rollback();
84 public void GetValuesTest()
86 FbTransaction transaction = Connection.BeginTransaction();
88 FbCommand command = new FbCommand("select * from TEST", Connection, transaction);
91 Console.WriteLine("DataReader - Read Method - Test");
93 IDataReader reader = command.ExecuteReader();
96 object[] values = new object[reader.FieldCount];
97 reader.GetValues(values);
99 for (int i = 0; i < values.Length; i++)
101 Console.Write(values[i] + "\t");
108 transaction.Rollback();
113 public void IndexerByIndexTest()
115 FbTransaction transaction = Connection.BeginTransaction();
117 FbCommand command = new FbCommand("select * from TEST", Connection, transaction);
120 Console.WriteLine("DataReader - Read Method - Test");
122 IDataReader reader = command.ExecuteReader();
123 while (reader.Read())
125 for(int i = 0; i < reader.FieldCount; i++)
127 Console.Write(reader[i] + "\t");
134 transaction.Rollback();
139 public void IndexerByNameTest()
141 FbTransaction transaction = Connection.BeginTransaction();
143 FbCommand command = new FbCommand("select * from TEST", Connection, transaction);
146 Console.WriteLine("DataReader - Read Method - Test");
148 IDataReader reader = command.ExecuteReader();
149 while (reader.Read())
151 for(int i = 0; i < reader.FieldCount; i++)
153 Console.Write(reader[reader.GetName(i)] + "\t");
160 transaction.Rollback();
165 public void GetSchemaTableTest()
167 FbTransaction transaction = Connection.BeginTransaction();
168 FbCommand command = new FbCommand("select * from TEST", Connection, transaction);
170 FbDataReader reader = command.ExecuteReader(CommandBehavior.SchemaOnly);
172 DataTable schema = reader.GetSchemaTable();
175 Console.WriteLine("DataReader - GetSchemaTable Method- Test");
177 DataRow[] currRows = schema.Select(null, null, DataViewRowState.CurrentRows);
179 foreach (DataColumn myCol in schema.Columns)
181 Console.Write("{0}\t\t", myCol.ColumnName);
186 foreach (DataRow myRow in currRows)
188 foreach (DataColumn myCol in schema.Columns)
190 Console.Write("{0}\t\t", myRow[myCol]);
197 transaction.Rollback();
202 public void GetSchemaTableWithExpressionFieldTest()
204 FbTransaction transaction = Connection.BeginTransaction();
205 FbCommand command = new FbCommand("select TEST.*, 0 AS VALOR from TEST", Connection, transaction);
207 FbDataReader reader = command.ExecuteReader(CommandBehavior.SchemaOnly);
209 DataTable schema = reader.GetSchemaTable();
212 Console.WriteLine("DataReader - GetSchemaTable Method- Test");
214 DataRow[] currRows = schema.Select(null, null, DataViewRowState.CurrentRows);
216 foreach (DataColumn myCol in schema.Columns)
218 Console.Write("{0}\t\t", myCol.ColumnName);
223 foreach (DataRow myRow in currRows)
225 foreach (DataColumn myCol in schema.Columns)
227 Console.Write("{0}\t\t", myRow[myCol]);
234 transaction.Rollback();
239 [Ignore("Not supported")]
240 public void NextResultTest()
242 string querys = "select * from TEST order by INT_FIELD asc;" +
243 "select * from TEST order by INT_FIELD desc;";
245 FbTransaction transaction = Connection.BeginTransaction();
246 FbCommand command = new FbCommand(querys, Connection, transaction);
248 FbDataReader reader = command.ExecuteReader();
251 Console.WriteLine("DataReader - NextResult Method - Test ( First Result )");
253 while (reader.Read())
255 for(int i = 0; i < reader.FieldCount; i++)
257 Console.Write(reader.GetValue(i) + "\t");
263 if(reader.NextResult())
265 Console.WriteLine("DataReader - NextResult Method - Test ( Second Result )");
267 while (reader.Read())
269 for(int i = 0; i < reader.FieldCount; i++)
271 Console.Write(reader.GetValue(i) + "\t");
279 transaction.Rollback();
284 public void RecordAffectedTest()
286 string sql = "insert into test (int_field) values (100000)";
288 FbCommand command = new FbCommand(sql, this.Connection);
290 FbDataReader reader = command.ExecuteReader();
292 bool nextResult = true;
296 while (reader.Read())
300 nextResult = reader.NextResult();
305 Assert.AreEqual(1, reader.RecordsAffected, "RecordsAffected value is incorrect");
309 public void GetBytesLengthTest()
311 string sql = "select blob_field from TEST where int_field = @int_field";
313 FbCommand command = new FbCommand(sql, this.Connection);
314 command.Parameters.Add("@int_field", FbDbType.Integer).Value = 2;
316 FbDataReader reader = command.ExecuteReader();
320 long length = reader.GetBytes(0, 0, null, 0, 0);
324 Assert.AreEqual(13, length, "Incorrect blob length");
328 public void GetCharsLengthTest()
330 string sql = "select clob_field from TEST where int_field = @int_field";
332 FbCommand command = new FbCommand(sql, this.Connection);
333 command.Parameters.Add("@int_field", FbDbType.Integer).Value = 50;
335 FbDataReader reader = command.ExecuteReader();
339 long length = reader.GetChars(0, 0, null, 0, 0);
343 Assert.AreEqual(14, length, "Incorrect clob length");
347 public void ValidateDecimalSchema()
349 string sql = "select decimal_field from test";
351 FbCommand test = new FbCommand(sql, this.Connection);
352 FbDataReader r = test.ExecuteReader(CommandBehavior.SchemaOnly);
354 DataTable schema = r.GetSchemaTable();
358 // Check schema values
359 Assert.AreEqual(schema.Rows[0]["ColumnSize"], 8, "Invalid length");
360 Assert.AreEqual(schema.Rows[0]["NumericPrecision"], 15, "Invalid precision");
361 Assert.AreEqual(schema.Rows[0]["NumericScale"], 2, "Invalid scale");
365 public void DisposeTest()
367 using (FbCommand command = new FbCommand("DATAREADERTEST", Connection))
369 command.CommandType = CommandType.StoredProcedure;
371 FbCommandBuilder.DeriveParameters(command);
373 using (IDataReader reader = command.ExecuteReader())
375 while (reader.Read())