2 // Rafael Mizrahi <rafim@mainsoft.com>
3 // Erez Lotan <erezl@mainsoft.com>
4 // Oren Gurfinkel <oreng@mainsoft.com>
7 // Copyright (c) 2004 Mainsoft Co.
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Data.OracleClient ;
33 using System.Collections;
35 using MonoTests.System.Data.Utils.Data;
37 // Provide All Data required by the diffderent tests e.g.DataTable, DataRow ...
38 namespace MonoTests.System.Data.Utils {
40 /// Types of Database Servers that tests can be run on.
42 public enum DataBaseServer {
51 public class ConnectedDataProvider {
54 //A string containing all printable charachters.
55 private const string SAMPLE_STRING = "abcdefghijklmnopqrstuvwxyz1234567890~!@#$%^&*()_+-=[]\\|;:,./<>? ";
60 /// Name of the table in the database, that contain columns of simple types.
62 public const string SIMPLE_TYPES_TABLE_NAME = "TYPES_SIMPLE";
64 /// Name of the table in the database, that contain columns of extended types.
66 public const string EXTENDED_TYPES_TABLE_NAME = "TYPES_EXTENDED";
68 /// Name of the table in the database, that contain columns of DB specific types.
70 public const string SPECIFIC_TYPES_TABLE_NAME = "TYPES_SPECIFIC";
73 public static string ConnectionString {
75 string connection_string = Sys.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
76 if(connection_string == null)
77 NUnit.Framework.Assert.Ignore ("Please consult README.tests.");
78 return connection_string;
82 // SQLClient does not allow to use the Provider token
83 // since Provider is always the first parameter(in GHT framework),
85 public static string ConnectionStringSQLClient {
87 return ConnectionString.Substring(ConnectionString.IndexOf(";"));
93 /// Resolves the type of DB server specified by the "ADOConString.txt" file.
95 /// <returns>The type of DB server specified by the "ADOConString.txt" file.</returns>
96 public static DataBaseServer GetDbType() {
97 return ConnectedDataProvider.GetDbType(ConnectedDataProvider.ConnectionString);
101 /// Resolves the type of DB server that the specified connection refers.
103 /// <param name="OleCon">A valid connection object to a DataBase.</param>
104 /// <returns>The type of DB server that the specified connection refers to.</returns>
105 public static DataBaseServer GetDbType(Sys.Data.OracleClient.OracleConnection OleCon) {
106 return ConnectedDataProvider.GetDbType(OleCon.ConnectionString);
110 /// Resolves the type of DB server that the specified connection string refers.
112 /// <param name="ConnectionString">A valid connection string to a DataBase server.</param>
113 /// <returns>The type of DB server that the specified connection string refers to.</returns>
114 public static DataBaseServer GetDbType(string ConnectionString) {
115 return DataBaseServer.Oracle;
119 /// Creates a DbTypeParametersCollection with default types and data for the TYPES_SIMPLE table.
121 /// <returns>The initialized DbTypeParametersCollection</returns>
122 public static DbTypeParametersCollection GetSimpleDbTypesParameters() {
123 DbTypeParametersCollection row = new DbTypeParametersCollection(SIMPLE_TYPES_TABLE_NAME);
124 switch (ConnectedDataProvider.GetDbType(ConnectedDataProvider.ConnectionString)) {
126 case MonoTests.System.Data.Utils.DataBaseServer.SQLServer:
127 row.Add("bit", true, 1);
128 row.Add("tinyint", (byte)25, 1);
129 row.Add("smallint", (Int16)77, 2);
130 row.Add("int", (Int32)2525, 4);
131 row.Add("bigint", (Int64)25251414, 8);
132 row.Add("decimal", 10M, 9); //(Decimal)10
133 row.Add("numeric", 123123M, 9); //(Decimal)123123
134 row.Add("float", 17.1414257, 8);
135 row.Add("real", (float)0.71425, 4);
136 row.Add("char", "abcdefghij", 10);
137 row.Add("nchar", "klmnopqrst", 10);
138 row.Add("varchar", "qwertasdfg", 50);
139 row.Add("nvarchar", "qwertasdfg", 50);
144 case MonoTests.System.Data.Utils.DataBaseServer.Sybase:
145 //row.Add("BIT", true, 1);
146 row.Add("TINYINT", (byte)25, 1);
147 row.Add("SMALLINT", (Int16)77, 2);
148 row.Add("INT", (Int32)2525, 4);
149 //row.Add("BIGINT", (Int64)25251414, 8);
150 row.Add("DECIMAL", 10M, 9); //(Decimal)10
151 row.Add("NUMERIC", 123123M, 9); //(Decimal)123123
152 row.Add("FLOAT", 17.1414257, 8);
153 row.Add("REAL", (float)0.71425, 4);
154 row.Add("CHAR", "abcdefghij", 10);
155 row.Add("NCHAR", "klmnopqrst", 10);
156 row.Add("VARCHAR", "qwertasdfg", 50);
157 row.Add("NVARCHAR", "qwertasdfg", 50);
162 case MonoTests.System.Data.Utils.DataBaseServer.Oracle:
163 row.Add("NUMBER", 21M, 22); //(Decimal)21
164 row.Add("LONG", SAMPLE_STRING, 2147483647); //Default data type in .NET is system.String.
165 row.Add("FLOAT", 1.234, 22);
166 row.Add("VARCHAR", "qwertasdfg", 10);
167 row.Add("NVARCHAR", "qwertasdfg", 20);
168 row.Add("CHAR", "abcdefghij", 10);
169 row.Add("NCHAR", "abcdefghij", 10);
174 case MonoTests.System.Data.Utils.DataBaseServer.DB2:
175 row.Add("SMALLINT", (Int16)2, 2);
176 row.Add("INTEGER", 7777, 4);
177 row.Add("BIGINT", (Int64)21767267, 8);
178 row.Add("DECIMAL", 123M, 9); //(decimal)123
179 row.Add("REAL", (float)0.7, 4);
180 row.Add("DOUBLE", 1.7, 8);
181 row.Add("CHARACTER", "abcdefghij", 10);
182 row.Add("VARCHAR", "qwertasdfg", 10);
183 row.Add("LONGVARCHAR", SAMPLE_STRING, 32000);
188 case MonoTests.System.Data.Utils.DataBaseServer.PostgreSQL:
190 // PostgreSQL ODBC Type BOOL returns String with value "1"
191 // so we don't run it on .NET
192 // if (!GHTEnvironment.IsJavaRunTime())
194 // row.Add("BOOL", "1", 1);
198 row.Add("BOOL", (bool)true, 1);
201 row.Add("INT2", (Int16)21, 2);
202 row.Add("INT4", (Int32)30000, 4);
203 row.Add("INT8", (Int64)30001, 8);
204 row.Add("NUMERIC", (decimal)100000M, 10); //(decimal)100000
205 row.Add("FLOAT4", (Single)7.23157, 4);
206 row.Add("FLOAT8", (Double)7.123456, 8);
207 row.Add("VARCHAR", "qwertasdfg", 10);
208 row.Add("CHAR", "abcdefghij", 10);
209 row.Add("NCHAR", "klmnopqrst", 10);
216 /// Creates a DbTypeParametersCollection with default types and data for the TYPES_EXTENDED table.
218 /// <returns>The initialized DbTypeParametersCollection</returns>
219 public static DbTypeParametersCollection GetExtendedDbTypesParameters() {
220 DbTypeParametersCollection row = new DbTypeParametersCollection(EXTENDED_TYPES_TABLE_NAME);
221 switch (ConnectedDataProvider.GetDbType(ConnectedDataProvider.ConnectionString)) {
223 case MonoTests.System.Data.Utils.DataBaseServer.SQLServer:
224 row.Add("text", SAMPLE_STRING, 16);
225 row.Add("ntext", SAMPLE_STRING, 16);
226 row.Add("binary", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
227 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
228 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
229 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
230 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
231 row.Add("varbinary", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
232 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
233 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
234 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
235 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
236 row.Add("datetime", new DateTime(2004, 8, 9, 20, 30, 15, 500), 8);
237 row.Add("smalldatetime", new DateTime(2004, 8, 9, 20, 30, 00), 4);
242 case MonoTests.System.Data.Utils.DataBaseServer.Sybase:
243 row.Add("TEXT", SAMPLE_STRING, 16);
244 //There is probably a bug in the jdbc driver , we've tried to insert this string using
245 //sybase command tool and it gave the same result (3850)
246 row.Add("NTEXT", SAMPLE_STRING.Trim() , 16);
247 row.Add("BINARY", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
248 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
249 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
250 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
251 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
252 row.Add("VARBINARY", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
253 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
254 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
255 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
256 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
257 row.Add("DATETIME", new DateTime(2004, 8, 9, 20, 30, 15, 500), 8);
258 row.Add("SMALLDATETIME", new DateTime(2004, 8, 9, 20, 30, 00), 4);
263 case MonoTests.System.Data.Utils.DataBaseServer.Oracle:
264 row.Add("RAW", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 10);
265 row.Add("LONGRAW", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
266 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
267 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
268 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
269 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
270 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
271 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
272 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
273 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
274 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
276 row.Add("DATE", new DateTime(2004, 8, 9, 20, 30, 15), 7);
278 // The .NET Framework provides support for Oracle LOBs in the OracleClient namespace, but not in the Oracle namespace.
279 // Since Visual MainWin does not support the OracleClient namespace, a partial support for this important feature is provided in the Oracle namespace.
280 // See ms-help://MS.VSCC.2003/VMW.GH.1033/ghdoc/vmwdoc_ADONET_data_access_limitations_51.htm
283 row.Add("BLOB", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
284 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
285 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
286 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
287 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
288 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
289 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
290 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
291 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
292 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
294 row.Add("CLOB", SAMPLE_STRING
301 row.Add("NCLOB", SAMPLE_STRING
313 case MonoTests.System.Data.Utils.DataBaseServer.DB2:
314 row.Add("DATE", new DateTime(2004, 8, 9, 20, 30, 15, 500).Date);
315 row.Add("TIME", new TimeSpan(20, 30, 15));
316 row.Add("TIMESTAMP", new DateTime(2004, 8, 9, 20, 30, 15, 500));
317 row.Add("BLOB", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
318 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
319 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
320 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
321 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
322 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
323 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
324 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
325 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
326 ,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
328 row.Add("CLOB", SAMPLE_STRING
335 row.Add("DBCLOB", SAMPLE_STRING
346 case MonoTests.System.Data.Utils.DataBaseServer.PostgreSQL:
347 row.Add("BYTEA", new byte[] {0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
348 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
349 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
350 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
351 0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
352 row.Add("DATE", new DateTime(2004, 8, 9));
353 row.Add("TEXT", "abcdefg", 16);
354 row.Add("TIME", new Sys.TimeSpan(02,02,02));
355 row.Add("TIMESTAMP", new DateTime(2004, 8, 9, 20, 30, 15, 500), 8);