e375cb451272b8c3fa9e98a0a83934e61a7835fe
[mono.git] / mcs / class / System.Data.OracleClient / Test / System.Data.OracleClient.jvm / OracleParameter / OracleParameter_ctor_SOtype.cs
1 // 
2 // Copyright (c) 2006 Mainsoft Co.
3 // 
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:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
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.
22 //
23
24 using System;
25 using System.Data;
26 using System.Data.OracleClient;
27
28 using MonoTests.System.Data.Utils;
29
30
31 using NUnit.Framework;
32
33 #if DAAB
34 using Microsoft.ApplicationBlocks;
35 #endif
36 namespace MonoTests.System.Data.OracleClient
37 {
38 [TestFixture]
39 [Category ("NotWorking")]
40 public class OracleParameter_ctor_SOtype : ADONetTesterClass
41 {
42         private Exception exp;
43         // transaction use was add for PostgreSQL
44         OracleTransaction tr;
45
46         public static void Main()
47         {
48                 OracleParameter_ctor_SOtype tc = new OracleParameter_ctor_SOtype();
49                 tc.exp = null;
50                 try
51                 {
52                         tc.BeginTest("OracleParameter_ctor_SOtype on " + ConnectedDataProvider.GetDbType().ToString());
53                         tc.run();
54                 }
55                 catch(Exception ex){tc.exp = ex;}
56                 finally {tc.EndTest(tc.exp);}
57         }
58
59         public void run()
60         {
61                 Log(string.Format("DB Server={0}.", ConnectedDataProvider.GetDbType()));
62                 AllTypes();
63                 SimpleTypesWithDBNull();
64         }
65
66         [Test]
67         public void AllTypes()
68         {
69                 exp = null;
70                 OracleParameter param = null;
71
72                 foreach (OracleType dbtype in Enum.GetValues(typeof(OracleType)))
73                 {
74
75                         param = new OracleParameter("myParam",dbtype);
76
77                         try
78                         {
79                                 BeginCase("ctor " + dbtype.ToString());
80                                 Compare(param != null, true);
81                         } 
82                         catch(Exception ex){exp = ex;}
83                         finally{EndCase(exp); exp = null;}
84
85                         try
86                         {
87                                 BeginCase("name " + dbtype.ToString());
88                                 Compare(param.ParameterName ,"myParam");
89                         } 
90                         catch(Exception ex){exp = ex;}
91                         finally{EndCase(exp); exp = null;}
92
93                 }
94         }
95
96         [Test]
97 //#if !TARGET_JVM
98 //      [Category("NotWorking")]
99 //#endif
100         public void SimpleTypesWithDBNull()
101         {
102                 OracleConnection con=null;
103                 OracleCommand cmd=null;
104                 OracleDataReader rdr=null;
105                 try
106                 {
107                         exp = null;
108                         BeginCase("Test simple types with DBNull");
109
110                         string connectionString = ConnectedDataProvider.ConnectionString;
111                         con = new       OracleConnection(connectionString);
112                         cmd = new OracleCommand();
113                         con.Open();
114                         // transaction use was add for PostgreSQL
115                         tr = con.BeginTransaction();
116                         
117                         cmd = new OracleCommand("", con, tr);
118                         cmd.CommandText = "GHSP_TYPES_SIMPLE_1";
119                         cmd.CommandType = CommandType.StoredProcedure;
120
121                         AddSimpleTypesNullParams(cmd);
122                         cmd.Parameters.Add(new OracleParameter("result",OracleType.Cursor)).Direction = ParameterDirection.Output;
123
124 #if !JAVA
125                         if (ConnectedDataProvider.GetDbType(con) == DataBaseServer.PostgreSQL)
126                         {
127 #if DAAB
128
129                                 rdr = Microsoft.ApplicationBlocks.Data.PostgresOracleHelper.OLEDB4ODBCExecuteReader(cmd,true);
130 #endif
131
132                         }
133                         else
134 #endif
135                         {
136
137                                 rdr = cmd.ExecuteReader();
138                         }
139
140                         rdr.Read();
141                         for (int i=0; i<rdr.FieldCount; i++)
142                         {
143                                 Compare(DBNull.Value, rdr.GetValue(i));
144                         }
145                         rdr.Close();
146                 }
147                 catch (Exception ex)
148                 {
149                         exp = ex;
150                 }
151                 finally
152                 {
153                         EndCase(exp);
154                         if(rdr != null && !rdr.IsClosed)
155                         {
156                                 rdr.Close();
157                         }
158                         if (con != null && con.State == ConnectionState.Open)
159                         {
160                                 con.Close();
161                         }
162                         exp=null;
163                 }
164         }
165
166         private void AddSimpleTypesNullParams(OracleCommand cmd)
167         {
168                 OracleParameter tmpParam;
169                 tmpParam = new OracleParameter("T_NUMBER", OracleType.Number);
170                 cmd.Parameters.Add(tmpParam);
171                 tmpParam = new OracleParameter("T_LONG", OracleType.LongVarChar);
172                 cmd.Parameters.Add(tmpParam);
173                 tmpParam = new OracleParameter("T_FLOAT", OracleType.Float);
174                 cmd.Parameters.Add(tmpParam);
175                 tmpParam = new OracleParameter("T_VARCHAR", OracleType.VarChar);
176                 cmd.Parameters.Add(tmpParam);
177                 tmpParam = new OracleParameter("T_NVARCHAR", OracleType.NVarChar);
178                 cmd.Parameters.Add(tmpParam);
179                 tmpParam = new OracleParameter("T_CHAR", OracleType.Char);
180                 cmd.Parameters.Add(tmpParam);
181                 tmpParam = new OracleParameter("T_NCHAR", OracleType.NChar);
182                 cmd.Parameters.Add(tmpParam);
183
184                 foreach (OracleParameter current in cmd.Parameters)
185                 {
186                         current.Value = DBNull.Value;
187                 }
188         }
189 }
190 }