2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / FirebirdSql.Data.Firebird / Test / FbStoredProcCallsTest.cs
1 /*
2  *  Firebird ADO.NET Data provider for .NET and Mono 
3  * 
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
9  *
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.
14  * 
15  *  Copyright (c) 2002, 2004 Carlos Guzman Alvarez
16  *  All Rights Reserved.
17  */
18
19 using System;
20 using System.Data;
21 using FirebirdSql.Data.Firebird;
22 using NUnit.Framework;
23
24 namespace FirebirdSql.Data.Firebird.Tests
25 {
26         /// <summary>
27         /// All the test in this TestFixture are using implicit transaction support.
28         /// </summary>
29         [TestFixture]
30         public class FbStoredProcCallsTest : BaseTest 
31         {
32                 public FbStoredProcCallsTest() : base(false)
33                 {               
34                 }
35
36                 [Test]
37                 public void FirebirdLikeTest00()
38                 {
39                         FbCommand command = new FbCommand("EXECUTE PROCEDURE GETVARCHARFIELD(?)", Connection);
40                                 
41                         command.CommandType = CommandType.StoredProcedure;
42
43                         command.Parameters.Add("@ID", FbDbType.VarChar).Direction = ParameterDirection.Input;
44                         command.Parameters.Add("@VARCHAR_FIELD", FbDbType.VarChar).Direction = ParameterDirection.Output;
45
46                         command.Parameters[0].Value = 1;
47
48                         // This will fill output parameters values
49                         command.ExecuteNonQuery();
50
51             // Check the value
52             Assert.AreEqual("IRow Number 1", command.Parameters[1].Value);
53
54             // Dispose command - this will do a transaction commit
55                         command.Dispose();
56                 }
57
58                 [Test]
59                 public void FirebirdLikeTest01()
60                 {
61                         FbCommand command = new FbCommand("SELECT * FROM GETVARCHARFIELD(?)", Connection);                              
62                         command.CommandType = CommandType.StoredProcedure;
63
64                         command.Parameters.Add("@ID", FbDbType.VarChar).Direction = ParameterDirection.Input;
65                         command.Parameters[0].Value = 1;
66
67                         // This will fill output parameters values
68                         FbDataReader reader = command.ExecuteReader();
69                         reader.Read();
70
71                         // Print output value
72                         Console.WriteLine("Output Parameters - Result of SELECT command");
73                         Console.WriteLine(reader[0]);
74
75                         reader.Close();
76
77                         // Dispose command - this will do a transaction commit
78                         command.Dispose();
79                 }
80
81                 [Test]
82                 public void SqlServerLikeTest00()
83                 {
84                         FbCommand command = new FbCommand("GETVARCHARFIELD", Connection);
85                                 
86                         command.CommandType = CommandType.StoredProcedure;
87
88                         command.Parameters.Add("@ID", FbDbType.VarChar).Direction = ParameterDirection.Input;
89                         command.Parameters.Add("@VARCHAR_FIELD", FbDbType.VarChar).Direction = ParameterDirection.Output;
90
91                         command.Parameters[0].Value = 1;
92
93                         // This will fill output parameters values
94                         command.ExecuteNonQuery();
95
96                         // Print output value
97                         Console.WriteLine("Output Parameters");
98                         Console.WriteLine(command.Parameters[1].Value);
99
100                         // Dispose command - this will do a transaction commit
101                         command.Dispose();
102                 }
103
104                 [Test]
105                 public void SqlServerLikeTest01()
106                 {
107                         FbCommand command = new FbCommand("GETRECORDCOUNT", Connection);                        
108                         command.CommandType = CommandType.StoredProcedure;
109
110                         command.Parameters.Add("@RECORDCOUNT", FbDbType.Integer).Direction = ParameterDirection.Output;
111
112                         // This will fill output parameters values
113                         command.ExecuteNonQuery();
114
115                         // Print output value
116                         Console.WriteLine("Output Parameters - Record Count");
117                         Console.WriteLine(command.Parameters[0].Value);
118
119                         // Dispose command - this will do a transaction commit
120                         command.Dispose();
121                 }
122
123                 [Test]
124                 public void SqlServerLikeTest02()
125                 {
126                         FbCommand command = new FbCommand("GETVARCHARFIELD", Connection);
127
128                         command.CommandType = CommandType.StoredProcedure;
129
130                         command.Parameters.Add("@ID", FbDbType.VarChar).Value = 1;
131
132                         // This will fill output parameters values
133                         FbDataReader r = command.ExecuteReader();
134
135                         int count = 0;
136
137                         while (r.Read())
138                         {
139                                 count++;
140                         }
141
142                         r.Close();
143
144                         // Dispose command - this will do a transaction commit
145                         command.Dispose();
146
147                         Assert.AreEqual(1, count);
148                 }
149         }
150 }