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.
23 using FirebirdSql.Data.Firebird;
24 using NUnit.Framework;
26 namespace FirebirdSql.Data.Firebird.Tests
29 public class FbImplicitTransactionTest : BaseTest
31 public FbImplicitTransactionTest() : base(false)
36 public void DataAdapterFillTest()
38 FbCommand command = new FbCommand("select * from TEST where DATE_FIELD = ?", Connection);
39 FbDataAdapter adapter = new FbDataAdapter(command);
41 adapter.SelectCommand.Parameters.Add("@DATE_FIELD", FbDbType.Date, 4, "DATE_FIELD").Value = new DateTime(2003, 1, 5);
43 FbCommandBuilder builder = new FbCommandBuilder(adapter);
45 DataSet ds = new DataSet();
46 adapter.Fill(ds, "TEST");
49 Console.WriteLine("Implicit transactions - DataAdapter Fill Method - Test");
51 foreach (DataTable table in ds.Tables)
53 foreach (DataColumn col in table.Columns)
55 Console.Write(col.ColumnName + "\t\t");
60 foreach (DataRow row in table.Rows)
62 for (int i = 0; i < table.Columns.Count; i++)
64 Console.Write(row[i] + "\t\t");
67 Console.WriteLine("");
77 public void MultipleDataAdapterFillTest()
79 FbCommand command = new FbCommand("select * from TEST where DATE_FIELD = ?", Connection);
80 FbDataAdapter adapter = new FbDataAdapter(command);
82 adapter.SelectCommand.Parameters.Add("@DATE_FIELD", FbDbType.Date, 4, "DATE_FIELD").Value = new DateTime(2003, 1, 5);
84 FbCommandBuilder builder = new FbCommandBuilder(adapter);
86 DataSet ds = new DataSet();
87 adapter.Fill(ds, "TEST");
90 Console.WriteLine("Implicit transactions - DataAdapter Fill Method - Test");
92 foreach (DataTable table in ds.Tables)
94 foreach (DataColumn col in table.Columns)
96 Console.Write(col.ColumnName + "\t\t");
101 foreach (DataRow row in table.Rows)
103 for (int i = 0; i < table.Columns.Count; i++)
105 Console.Write(row[i] + "\t\t");
108 Console.WriteLine("");
112 adapter.SelectCommand.Parameters[0].Value = new DateTime(2003, 1, 6);
115 adapter.Fill(ds, "TEST");
118 Console.WriteLine("Implicit transactions - DataAdapter Fill Method - Test");
120 foreach (DataTable table in ds.Tables)
122 foreach (DataColumn col in table.Columns)
124 Console.Write(col.ColumnName + "\t\t");
129 foreach (DataRow row in table.Rows)
131 for (int i = 0; i < table.Columns.Count; i++)
133 Console.Write(row[i] + "\t\t");
136 Console.WriteLine("");
147 public void ExecuteScalarTest()
149 FbCommand command = new FbCommand("select sum(int_field) from TEST", Connection);
151 Console.WriteLine("\r\nExecuteScalar with implicit transaction: {0}", command.ExecuteScalar());
157 public void UpdatedClobFieldTest()
159 Console.WriteLine("\r\nUpdate CLOB field with implicit transaction.");
161 FbCommand command = new FbCommand("update TEST set clob_field = @clob_field where int_field = @int_field", Connection);
162 command.Parameters.Add("@int_field", FbDbType.Integer).Value = 1;
163 command.Parameters.Add("@clob_field", FbDbType.Text).Value = "Clob field update with implicit transaction";
165 int i = command.ExecuteNonQuery();
167 Assert.AreEqual(i, 1, "Clob field update with implicit transaction failed");
169 // Force the implicit transaction to be committed
174 public void UpdatedBlobFieldTest()
176 Console.WriteLine("\r\nUpdate BLOB field with implicit transaction.");
178 FbCommand command = new FbCommand("update TEST set blob_field = @blob_field where int_field = @int_field", Connection);
179 command.Parameters.Add("@int_field", FbDbType.Integer).Value = 1;
180 command.Parameters.Add("@blob_field", FbDbType.Binary).Value =
181 Encoding.Default.GetBytes("Blob field update with implicit transaction");
183 int i = command.ExecuteNonQuery();
185 Assert.AreEqual(i, 1, "Blob field update with implicit transaction failed");
187 // Force the implicit transaction to be committed
192 public void UpdatedArrayFieldTest()
194 Console.WriteLine("\r\nUpdate CLOB field with implicit transaction.");
196 int[] values = new int[4];
203 FbCommand command = new FbCommand("update TEST set iarray_field = @iarray_field where int_field = @int_field", Connection);
204 command.Parameters.Add("@int_field", FbDbType.Integer).Value = 1;
205 command.Parameters.Add("@iarray_field", FbDbType.Array).Value = values;
207 int i = command.ExecuteNonQuery();
209 Assert.AreEqual(i, 1, "Array field update with implicit transaction failed");
211 // Force the implicit transaction to be committed