Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ConnectedDataProvider.cs « MonoTests.System.Data.Utils « System.Data.OleDb.jvm « ProviderTests « Test « System.Data « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a91f79d2b9bb018e87ba460fed51d3526f054b00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
// Authors:
//   Rafael Mizrahi   <rafim@mainsoft.com>
//   Erez Lotan       <erezl@mainsoft.com>
//   Oren Gurfinkel   <oreng@mainsoft.com>
//   Ofer Borstein
// 
// Copyright (c) 2004 Mainsoft Co.
// 
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

using System;
using System.Data;
using System.Data.OleDb ;
using System.IO;
using System.Collections;
using Sys = System;
using MonoTests.System.Data.Utils.Data;

// Provide All Data required by the diffderent tests e.g.DataTable, DataRow ...
namespace MonoTests.System.Data.Utils {
	/// <summary>
	/// Types of Database Servers that tests can be run on.
	/// </summary>
	public enum DataBaseServer {
		SQLServer,
		Oracle,
		DB2,
		Sybase,
		PostgreSQL,
		Unknown
	}

	public class ConnectedDataProvider {

		#region Private
		//A string containing all printable charachters.
		private const string SAMPLE_STRING = "abcdefghijklmnopqrstuvwxyz1234567890~!@#$%^&*()_+-=[]\\|;:,./<>? ";
		#endregion

		#region Public
		/// <summary>
		/// Name of the table in the database, that contain columns of simple types.
		/// </summary>
		public const string SIMPLE_TYPES_TABLE_NAME = "TYPES_SIMPLE";
		/// <summary>
		/// Name of the table in the database, that contain columns of extended types.
		/// </summary>
		public const string EXTENDED_TYPES_TABLE_NAME = "TYPES_EXTENDED";
		/// <summary>
		/// Name of the table in the database, that contain columns of DB specific types.
		/// </summary>
		public const string SPECIFIC_TYPES_TABLE_NAME = "TYPES_SPECIFIC";
		#endregion

		public static string ConnectionString {
			get {
				return Sys.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
			}
		}

		//	SQLClient does not allow to use the Provider token
		//	since Provider is always the first parameter(in GHT framework),
		//	we trim it.
		public static string ConnectionStringSQLClient {
			get {
				return ConnectionString.Substring(ConnectionString.IndexOf(";"));
			}
		}
	

		/// <summary>
		/// Resolves the type of DB server specified by the "ADOConString.txt" file.
		/// </summary>
		/// <returns>The type of DB server specified by the "ADOConString.txt" file.</returns>
		public static DataBaseServer GetDbType() {
			return ConnectedDataProvider.GetDbType(ConnectedDataProvider.ConnectionString);
		}
		
		/// <summary>
		/// Resolves the type of DB server that the specified connection refers.
		/// </summary>
		/// <param name="OleCon">A valid connection object to a DataBase.</param>
		/// <returns>The type of DB server that the specified connection refers to.</returns>
		public static DataBaseServer GetDbType(Sys.Data.OleDb.OleDbConnection OleCon) {
			return ConnectedDataProvider.GetDbType(OleCon.ConnectionString);
		}

		/// <summary>
		/// Resolves the type of DB server that the specified connection string refers.
		/// </summary>
		/// <param name="ConnectionString">A valid connection string to a DataBase server.</param>
		/// <returns>The type of DB server that the specified connection string refers to.</returns>
		public static DataBaseServer GetDbType(string ConnectionString) {
			if (ConnectionString.ToUpper().IndexOf("PROVIDER=SQLOLEDB") >= 0) return DataBaseServer.SQLServer ;
			if (ConnectionString.ToUpper().IndexOf("SYBASE") >= 0) return DataBaseServer.Sybase ;
			if (ConnectionString.ToUpper().IndexOf("PROVIDER=MSDAORA") >= 0) return DataBaseServer.Oracle;
			if (ConnectionString.ToUpper().IndexOf("PROVIDER=IBMDADB2") >= 0) return DataBaseServer.DB2;
			if (ConnectionString.ToUpper().IndexOf("POSTGRESQL") >= 0) return DataBaseServer.PostgreSQL;
			return DataBaseServer.Unknown ;
		}

		/// <summary>
		/// Creates a DbTypeParametersCollection with default types and data for the TYPES_SIMPLE table.
		/// </summary>
		/// <returns>The initialized DbTypeParametersCollection</returns>
		public static DbTypeParametersCollection GetSimpleDbTypesParameters() {
			DbTypeParametersCollection row = new DbTypeParametersCollection(SIMPLE_TYPES_TABLE_NAME);
			switch (ConnectedDataProvider.GetDbType(ConnectedDataProvider.ConnectionString)) {
					#region SQLServer
				case MonoTests.System.Data.Utils.DataBaseServer.SQLServer:
					row.Add("bit", true, 1);
					row.Add("tinyint", (byte)25, 1);
					row.Add("smallint", (Int16)77, 2);
					row.Add("int", (Int32)2525, 4);
					row.Add("bigint", (Int64)25251414, 8);
					row.Add("decimal", 10M, 9);	//(Decimal)10
					row.Add("numeric", 123123M, 9); //(Decimal)123123
					row.Add("float", 17.1414257, 8);
					row.Add("real", (float)0.71425, 4);
					row.Add("char", "abcdefghij", 10);
					row.Add("nchar", "klmnopqrst", 10);
					row.Add("varchar", "qwertasdfg", 50);
					row.Add("nvarchar", "qwertasdfg", 50);
					break;
					#endregion

					#region Sybase
				case MonoTests.System.Data.Utils.DataBaseServer.Sybase:
					//row.Add("BIT", true, 1);
					row.Add("TINYINT", (byte)25, 1);
					row.Add("SMALLINT", (Int16)77, 2);
					row.Add("INT", (Int32)2525, 4);
					//row.Add("BIGINT", (Int64)25251414, 8);
					row.Add("DECIMAL", 10M, 9);	//(Decimal)10
					row.Add("NUMERIC", 123123M, 9); //(Decimal)123123
					row.Add("FLOAT", 17.1414257, 8);
					row.Add("REAL", (float)0.71425, 4);
					row.Add("CHAR", "abcdefghij", 10);
					row.Add("NCHAR", "klmnopqrst", 10);
					row.Add("VARCHAR", "qwertasdfg", 50);
					row.Add("NVARCHAR", "qwertasdfg", 50);
					break;
					#endregion

					#region ORACLE
				case MonoTests.System.Data.Utils.DataBaseServer.Oracle:
					row.Add("NUMBER", 21M, 22);	//(Decimal)21
					row.Add("LONG", SAMPLE_STRING, 2147483647);	//Default data type in .NET is system.String.
					row.Add("FLOAT", 1.234, 22);
					row.Add("VARCHAR", "qwertasdfg", 10);
					row.Add("NVARCHAR", "qwertasdfg", 20);
					row.Add("CHAR", "abcdefghij", 10);
					row.Add("NCHAR", "abcdefghij", 10);
					break;
					#endregion

					#region DB2
				case MonoTests.System.Data.Utils.DataBaseServer.DB2:
					row.Add("SMALLINT", (Int16)2, 2);
					row.Add("INTEGER", 7777, 4);
					row.Add("BIGINT", (Int64)21767267, 8);
					row.Add("DECIMAL", 123M, 9); //(decimal)123
					row.Add("REAL", (float)0.7, 4);
					row.Add("DOUBLE", 1.7, 8);
					row.Add("CHARACTER", "abcdefghij", 10);
					row.Add("VARCHAR", "qwertasdfg", 10);
					row.Add("LONGVARCHAR", SAMPLE_STRING, 32000);
					break;
					#endregion

					#region PostgreSQL
				case MonoTests.System.Data.Utils.DataBaseServer.PostgreSQL:
					
					// PostgreSQL ODBC Type BOOL returns String with value "1" 
					// so we don't run it on .NET
					//					if (!GHTEnvironment.IsJavaRunTime())
					//					{
					//						row.Add("BOOL", "1", 1);
					//					}
					//					else
					//					{
					row.Add("BOOL", (bool)true, 1);
					//					}

					row.Add("INT2", (Int16)21, 2);
					row.Add("INT4", (Int32)30000, 4);
					row.Add("INT8", (Int64)30001, 8);
					row.Add("NUMERIC", (decimal)100000M, 10); //(decimal)100000
					row.Add("FLOAT4", (Single)7.23157, 4);
					row.Add("FLOAT8", (Double)7.123456, 8);
					row.Add("VARCHAR", "qwertasdfg", 10);
					row.Add("CHAR", "abcdefghij", 10);
					row.Add("NCHAR", "klmnopqrst", 10);
					break;
					#endregion
			}
			return row;
		}
		/// <summary>
		/// Creates a DbTypeParametersCollection with default types and data for the TYPES_EXTENDED table.
		/// </summary>
		/// <returns>The initialized DbTypeParametersCollection</returns>
		public static DbTypeParametersCollection GetExtendedDbTypesParameters() {
			DbTypeParametersCollection row = new DbTypeParametersCollection(EXTENDED_TYPES_TABLE_NAME);
			switch (ConnectedDataProvider.GetDbType(ConnectedDataProvider.ConnectionString)) {
					#region SQLServer
				case MonoTests.System.Data.Utils.DataBaseServer.SQLServer:
					row.Add("text", SAMPLE_STRING, 16);
					row.Add("ntext", SAMPLE_STRING, 16);
					row.Add("binary", new byte[]	{0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
														0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
														0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
														0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
														0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
					row.Add("varbinary", new byte[]	{0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
														0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
														0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
														0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
														0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
					row.Add("datetime", new DateTime(2004, 8, 9, 20, 30, 15, 500), 8);
					row.Add("smalldatetime", new DateTime(2004, 8, 9, 20, 30, 00), 4);
					break;
					#endregion

					#region Sybase
				case MonoTests.System.Data.Utils.DataBaseServer.Sybase:
					row.Add("TEXT", SAMPLE_STRING, 16);
					//There is probably a bug in the jdbc driver , we've tried to insert this string using
					//sybase command tool and it gave the same result (3850)
					row.Add("NTEXT", SAMPLE_STRING.Trim() , 16);
					row.Add("BINARY", new byte[]	{0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
														0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
														0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
														0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
														0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
					row.Add("VARBINARY", new byte[]	{0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
														0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
														0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
														0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
														0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
					row.Add("DATETIME", new DateTime(2004, 8, 9, 20, 30, 15, 500), 8);
					row.Add("SMALLDATETIME", new DateTime(2004, 8, 9, 20, 30, 00), 4);
					break;
					#endregion

					#region ORACLE
				case MonoTests.System.Data.Utils.DataBaseServer.Oracle:
					row.Add("RAW", new byte[]	{0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 10);
					row.Add("LONGRAW", new byte[]	{0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
														,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
														,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
														,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
														,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
														,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
														,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
														,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
														,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
														,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
													}, 100);
					row.Add("DATE", new DateTime(2004, 8, 9, 20, 30, 15), 7);
					
					// The .NET Framework provides support for Oracle LOBs in the OracleClient namespace, but not in the OleDb namespace.
					// Since Visual MainWin does not support the OracleClient namespace, a partial support for this important feature is provided in the OleDb namespace.
					// See ms-help://MS.VSCC.2003/VMW.GH.1033/ghdoc/vmwdoc_ADONET_data_access_limitations_51.htm
#if TARGET_JVM

					row.Add("BLOB", new byte[]	{0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
													,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
													,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
													,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
													,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
													,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
													,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
													,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
													,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
													,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
												}, 4000);
					row.Add("CLOB",	SAMPLE_STRING
						+ SAMPLE_STRING
						+ SAMPLE_STRING
						+ SAMPLE_STRING
						+ SAMPLE_STRING
						+ SAMPLE_STRING
						, 4000);
					row.Add("NCLOB", SAMPLE_STRING
						+ SAMPLE_STRING
						+ SAMPLE_STRING
						+ SAMPLE_STRING
						+ SAMPLE_STRING
						+ SAMPLE_STRING
						, 4000);
#endif
					break;
					#endregion

					#region DB2
				case MonoTests.System.Data.Utils.DataBaseServer.DB2:
					row.Add("DATE", new DateTime(2004, 8, 9, 20, 30, 15, 500).Date);
					row.Add("TIME", new TimeSpan(20, 30, 15));
					row.Add("TIMESTAMP", new DateTime(2004, 8, 9, 20, 30, 15, 500));
					row.Add("BLOB", new byte[]	{0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
													,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
													,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
													,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
													,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
													,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
													,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
													,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
													,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
													,0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0
												});
					row.Add("CLOB", SAMPLE_STRING
						+ SAMPLE_STRING
						+ SAMPLE_STRING
						+ SAMPLE_STRING
						+ SAMPLE_STRING
						+ SAMPLE_STRING
						);
					row.Add("DBCLOB", SAMPLE_STRING
						+ SAMPLE_STRING
						+ SAMPLE_STRING
						+ SAMPLE_STRING
						+ SAMPLE_STRING
						+ SAMPLE_STRING
						);
					break;
					#endregion

					#region PostgreSQL
				case MonoTests.System.Data.Utils.DataBaseServer.PostgreSQL:
					row.Add("BYTEA", new byte[]	{0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
													0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
													0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
													0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0,
													0x00, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xFF, 0xF0}, 50);
					row.Add("DATE", new DateTime(2004, 8, 9));
					row.Add("TEXT", "abcdefg", 16); 
					row.Add("TIME", new Sys.TimeSpan(02,02,02));
					row.Add("TIMESTAMP", new DateTime(2004, 8, 9, 20, 30, 15, 500), 8);
					break;
					#endregion

			}
			return row;
		}
	}
}