2 // Copyright (c) 2006 Mainsoft Co.
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 using System.Data.OleDb ;
28 using MonoTests.System.Data.Utils;
31 using NUnit.Framework;
33 using Microsoft.ApplicationBlocks.Data;
36 namespace MonoTests.System.Data.OleDb
39 public class OleDbCommand_CommandType : ADONetTesterClass
42 // transaction is must on PostgreSQL
45 OleDbDataReader dr = null;
46 DataBaseServer dbServerType;
55 con = new OleDbConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
57 tr = con.BeginTransaction();
58 cmd = new OleDbCommand("", con, tr);
59 dbServerType = ConnectedDataProvider.GetDbType(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
60 Assert.AreEqual("Setup", "Setup");
62 catch(Exception ex) {exp = ex;}
63 finally {EndCase(exp); exp = null;}
66 public void TearDown()
70 if (con.State == ConnectionState.Open) con.Close();
74 public static void Main()
76 OleDbCommand_CommandType tc = new OleDbCommand_CommandType();
80 tc.BeginTest("OleDbCommand_CommandType");
85 catch(Exception ex){exp = ex;}
86 finally {tc.EndTest(exp);}
94 OleDbCommand cmd = new OleDbCommand();
97 BeginCase("CommandType - default");
98 Assert.AreEqual(cmd.CommandType , CommandType.Text );
100 catch(Exception ex){exp = ex;}
101 finally{EndCase(exp); exp = null;}
105 BeginCase("CommandType - TableDirect");
106 cmd.CommandType = CommandType.TableDirect;
107 Assert.AreEqual(cmd.CommandType , CommandType.TableDirect);
109 catch(Exception ex){exp = ex;}
110 finally{EndCase(exp); exp = null;}
114 BeginCase("CommandType - Text");
115 cmd.CommandType = CommandType.Text ;
116 Assert.AreEqual(cmd.CommandType , CommandType.Text);
118 catch(Exception ex){exp = ex;}
119 finally{EndCase(exp); exp = null;}
123 #region ---- CommandType.Text using Parameters.Add ----
126 BeginCase("CommandType.Text using Parameters.Add");
128 cmd = new OleDbCommand();
129 cmd.Connection = con;
130 cmd.Transaction = tr;
131 cmd.CommandType = CommandType.Text;
132 switch (dbServerType)
134 case DataBaseServer.PostgreSQL:
135 cmd.CommandText = "SELECT * FROM GH_REFCURSOR3(?)";
138 cmd.CommandText = "{call GH_REFCURSOR3(?)}";
142 OleDbParameter param1 = cmd.Parameters.Add("IN_LASTNAME", OleDbType.VarChar,20);
143 param1.Direction = ParameterDirection.Input;
144 param1.Value = "Yavine";
147 if ((dbServerType == DataBaseServer.PostgreSQL))
149 dr = PostgresOleDbHelper.OLEDB4ODBCExecuteReader(cmd,true);
155 dr = cmd.ExecuteReader();
161 Assert.AreEqual(dr.GetValue(0).ToString(),"1");
162 Assert.AreEqual(dr.GetString(1),"Yavine");
165 Assert.AreEqual("error","HasRows=0");
174 if (dr != null)dr.Close();
176 {if (con.State == ConnectionState.Open) con.Close();}
183 CommandTypeSP_Manual_InOutParameters();
185 #region ---- ORACLE CommandType.StoredProcedure using DeriveParameters ----
186 if (ConnectedDataProvider.GetDbType(con) == MonoTests.System.Data.Utils.DataBaseServer.Oracle)
190 BeginCase("ORACLE CommandType.StoredProcedure using DeriveParameters");
193 cmd = new OleDbCommand();
194 cmd.Connection = con;
195 cmd.Transaction = tr;
196 cmd.CommandType = CommandType.StoredProcedure;
197 cmd.CommandText = "GH_REFCURSOR3";
199 OleDbCommandBuilder.DeriveParameters(cmd);
200 cmd.Parameters[0].Value = "Yavine";
201 cmd.Parameters.RemoveAt(1); // the ORACLE DAAB trick is to remove the out parameter
203 dr = cmd.ExecuteReader();
207 Assert.AreEqual(dr.GetValue(0).ToString(),"1");
208 Assert.AreEqual(dr.GetString(1),"Yavine");
211 Assert.AreEqual("error","HasRows=0");
220 if (dr != null)dr.Close();
222 {if (con.State == ConnectionState.Open) con.Close();}
230 #region CommandType.StoredProcedure in order to repreduce bug 4003
231 if (ConnectedDataProvider.GetDbType(con) == MonoTests.System.Data.Utils.DataBaseServer.SQLServer)
236 if (con.State == ConnectionState.Closed) con.Open();
237 BeginCase("Bug 4003");
238 OleDbCommand cmd4003 = new OleDbCommand("[mainsoft].[GH_DUMMY]",con);
239 cmd4003.CommandType = CommandType.StoredProcedure;
240 cmd4003.Parameters.Add("@EmployeeIDPrm","1");
241 cmd4003.ExecuteReader();
250 if (con.State == ConnectionState.Open) con.Close();
259 #region ---- CommandType.StoredProcedure manual in out parameters ----
260 public void CommandTypeSP_Manual_InOutParameters()
262 Exception exp = null;
265 BeginCase("CommandType.StoredProcedure manual in out parameters");
267 if (ConnectedDataProvider.GetDbType(con) == MonoTests.System.Data.Utils.DataBaseServer.PostgreSQL)
269 this.Log("CommandType.StoredProcedure manual in out parameters is not tested in oracle.");
274 cmd = new OleDbCommand();
275 cmd.Connection = con;
277 cmd.CommandType = CommandType.StoredProcedure;
278 cmd.CommandText = "GH_INOUT1";
280 //RETURN_VALUE for SQLServer
281 if (ConnectedDataProvider.GetDbType(con) == MonoTests.System.Data.Utils.DataBaseServer.SQLServer)
283 OleDbParameter param0 = cmd.Parameters.Add("@RETURN_VALUE", OleDbType.Integer);
284 param0.Direction = ParameterDirection.ReturnValue;
287 OleDbParameter param1 = cmd.Parameters.Add("@INPARAM", OleDbType.VarChar,20);
288 param1.Direction = ParameterDirection.Input;
289 param1.Value = Convert.ToString("dummy");
291 OleDbParameter param2 = cmd.Parameters.Add("@OUTPARAM", OleDbType.Integer);//VarNumeric);
292 param2.Direction = ParameterDirection.Output;
294 int ret = cmd.ExecuteNonQuery();
296 intReturn = Convert.ToInt32(cmd.Parameters["@OUTPARAM"].Value);
297 Assert.AreEqual(intReturn,100);
306 if (dr != null)dr.Close();
308 {if (con.State == ConnectionState.Open) con.Close();}