[System.Data] Fixes tests build with mobile profiles
[mono.git] / mcs / class / System.Data / Test / ProviderTests / System.Data.Odbc / OdbcDataReaderTest.cs
1 //
2 // OdbcDataReaderTest.cs - NUnit Test Cases for testing the
3 // OdbcDataReader class
4 //
5 // Author: 
6 //      Sureshkumar T (TSureshkumar@novell.com)
7 // 
8 // Copyright (c) 2004 Novell Inc., and the individuals listed
9 // on the ChangeLog entries.
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if !NO_ODBC
32
33 using System;
34 using System.Data;
35 using System.Data.Common;
36 using System.Data.Odbc;
37 using System.Globalization;
38 using System.Text;
39 using NUnit.Framework;
40
41
42 namespace MonoTests.System.Data.Connected.Odbc
43 {
44         [TestFixture]
45         [Category ("odbc")]
46         public class OdbcDataReaderTest
47         {
48                 static byte [] long_bytes = new byte [] {
49                         0x00, 0x66, 0x06, 0x66, 0x97, 0x00, 0x66, 0x06, 0x66,
50                         0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
51                         0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
52                         0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
53                         0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
54                         0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
55                         0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
56                         0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
57                         0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
58                         0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
59                         0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
60                         0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
61                         0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
62                         0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
63                         0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
64                         0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
65                         0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
66                         0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
67                         0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
68                         0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
69                         0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
70                         0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
71                         0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
72                         0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
73                         0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
74                         0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
75                         0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
76                         0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
77                         0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
78                         0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
79                         0x06, 0x66, 0x06, 0x66, 0x98};
80
81                 OdbcConnection conn;
82                 OdbcCommand cmd;
83
84                 [SetUp]
85                 public void SetUp ()
86                 {
87                         conn = ConnectionManager.Instance.Odbc.Connection;
88                         cmd = conn.CreateCommand ();
89                 }
90
91                 [TearDown]
92                 public void TearDown ()
93                 {
94                         if (cmd != null)
95                                 cmd.Dispose ();
96                         ConnectionManager.Instance.Close ();
97                 }
98
99                 [Test]
100                 public void GetBytes ()
101                 {
102                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
103                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult | CommandBehavior.SequentialAccess)) {
104                                 Assert.IsTrue (reader.Read (), "#C1");
105
106                                 long totalsize = reader.GetBytes (0, 0, null, 0, 0);
107
108                                 byte [] val = new byte [totalsize];
109                                 long ret = reader.GetBytes (0, 0L, val, 0, (int) (totalsize * 2));
110                                 Assert.AreEqual (totalsize, ret, "#C2");
111                                 Assert.AreEqual (new byte [] { 0x32, 0x56, 0x00, 0x44, 0x22 }, val, "#C3");
112                         }
113
114                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 2";
115
116                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult | CommandBehavior.SequentialAccess)) {
117                                 Assert.IsTrue (reader.Read (), "#G1");
118
119                                 long totalsize = reader.GetBytes (0, 0, null, 0, 0);
120
121                                 byte [] val = new byte [totalsize];
122                                 int offset = 0;
123                                 long ret = 0;
124                                 long count = 0;
125                                 do {
126                                         ret = reader.GetBytes (0, offset, val, offset, 50);
127                                         offset += (int) ret;
128                                         count += ret;
129                                 } while (count < totalsize);
130
131                                 Assert.AreEqual (long_bytes.Length, count, "#G2");
132                                 Assert.AreEqual (long_bytes, val, "#G3");
133                         }
134
135                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult)) {
136                                 Assert.IsTrue (reader.Read (), "#H1");
137
138                                 long totalsize = reader.GetBytes (0, 0, null, 0, 0);
139
140                                 byte [] val = new byte [totalsize];
141                                 int offset = 0;
142                                 long ret = 0;
143                                 long count = 0;
144                                 do {
145                                         ret = reader.GetBytes (0, offset, val, offset, 50);
146                                         offset += (int) ret;
147                                         count += ret;
148                                 } while (count < totalsize);
149
150                                 Assert.AreEqual (long_bytes.Length, count, "#H2");
151                                 Assert.AreEqual (long_bytes, val, "#H3");
152                         }
153                 }
154
155                 [Test]
156                 public void GetBytes_Buffer_TooSmall ()
157                 {
158                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 2";
159
160                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult | CommandBehavior.SequentialAccess)) {
161                                 Assert.IsTrue (reader.Read ());
162
163                                 long totalsize = reader.GetBytes (0, 0, null, 0, 0);
164                                 byte [] val = new byte [totalsize - 1];
165
166                                 long ret = reader.GetBytes (0, 0, val, 0, (int) totalsize);
167                                 Assert.AreEqual (274, ret, "#A1");
168                                 for (int i = 0; i < ret; i++)
169                                         Assert.AreEqual (long_bytes [i], val [i], "#A2:" + i);
170                                 for (long i = ret; i < val.Length; i++)
171                                         Assert.AreEqual (0x00, val [i], "#A3:" + i);
172                         }
173
174                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult | CommandBehavior.SequentialAccess)) {
175                                 Assert.IsTrue (reader.Read ());
176
177                                 long totalsize = reader.GetBytes (0, 0, null, 0, 0);
178                                 byte [] val = new byte [totalsize];
179                                 int buffer_offset = 1;
180
181                                 long ret = reader.GetBytes (0, 0, val, buffer_offset, (int) totalsize);
182                                 Assert.AreEqual (274, ret, "#B1");
183                                 Assert.AreEqual (0x00, val [0], "#B2");
184                                 for (int i = 0; i < ret; i++)
185                                         Assert.AreEqual (long_bytes [i], val [i + buffer_offset], "#B2:" + i);
186                                 for (long i = (ret + buffer_offset); i < val.Length; i++)
187                                         Assert.AreEqual (0x00, val [i], "#B3:" + i);
188                         }
189
190                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult | CommandBehavior.SequentialAccess)) {
191                                 Assert.IsTrue (reader.Read ());
192
193                                 long totalsize = reader.GetBytes (0, 0, null, 0, 0);
194                                 byte [] val = new byte [totalsize];
195
196                                 long ret = reader.GetBytes (0, 0, val, 0, (int) (totalsize + 1));
197                                 Assert.AreEqual (totalsize, ret, "#C1");
198                         }
199
200                         ConnectionManager.Instance.Odbc.CloseConnection ();
201                 }
202
203                 [Test]
204                 public void GetBytes_BufferIndex_Negative ()
205                 {
206                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
207
208                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
209                                 Assert.IsTrue (reader.Read (), "#1");
210
211                                 try {
212                                         reader.GetBytes (0, 0, null, -1, 0);
213                                         Assert.Fail ("#2");
214                                 } catch (ArgumentOutOfRangeException ex) {
215                                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#3");
216                                         Assert.IsNull (ex.InnerException, "#4");
217                                         Assert.IsNotNull (ex.Message, "#5");
218                                         Assert.AreEqual ("bufferIndex", ex.ParamName, "#6");
219                                 }
220                         }
221                 }
222
223                 [Test]
224                 public void GetBytes_DataIndex_Negative ()
225                 {
226                         IDbCommand cmd = conn.CreateCommand ();
227                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
228
229                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
230                                 Assert.IsTrue (reader.Read (), "#A1");
231
232                                 try {
233                                         reader.GetBytes (0, -1L, null, 0, 0);
234                                         Assert.Fail ("#A2");
235                                 } catch (ArgumentOutOfRangeException ex) {
236                                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A3");
237                                         Assert.IsNull (ex.InnerException, "#A4");
238                                         Assert.IsNotNull (ex.Message, "#A5");
239                                         Assert.AreEqual ("dataIndex", ex.ParamName, "#A6");
240                                 }
241                         }
242
243                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult)) {
244                                 Assert.IsTrue (reader.Read (), "#B1");
245
246                                 try {
247                                         reader.GetBytes (0, -1L, null, 0, 0);
248                                         Assert.Fail ("#B2");
249                                 } catch (ArgumentOutOfRangeException ex) {
250                                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B3");
251                                         Assert.IsNull (ex.InnerException, "#B4");
252                                         Assert.IsNotNull (ex.Message, "#B5");
253                                         Assert.AreEqual ("dataIndex", ex.ParamName, "#B6");
254                                 }
255                         }
256                 }
257
258                 [Test]
259                 public void GetBytes_Length_Negative ()
260                 {
261                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
262
263                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
264                                 Assert.IsTrue (reader.Read (), "#1");
265
266                                 try {
267                                         reader.GetBytes (0, 0, null, 0, -1);
268                                         Assert.Fail ("#2");
269                                 } catch (ArgumentOutOfRangeException ex) {
270                                         Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#3");
271                                         Assert.IsNull (ex.InnerException, "#4");
272                                         Assert.IsNotNull (ex.Message, "#5");
273                                         Assert.AreEqual ("length", ex.ParamName, "#6");
274                                 }
275                         }
276                 }
277
278                 [Test]
279                 public void GetSchemaTable ()
280                 {
281                         IDataReader reader = null;
282                         DataTable schema;
283                         DataRow pkRow;
284
285                         try {
286                                 cmd.CommandText = "select id, fname, id + 20 as plustwenty from employee";
287                                 reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);
288                                 schema = reader.GetSchemaTable ();
289                                 reader.Close ();
290
291                                 AssertSchemaTableStructure (schema, "#A:");
292                                 Assert.AreEqual (3, schema.Rows.Count, "#A:RowCount");
293                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
294                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#A:ColumnName_IsNull");
295                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#A:ColumnName_Value");
296                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#A:ColumnOrdinal_IsNull");
297                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#A:ColumnOrdinal_Value");
298                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#A:ColumnSize_IsNull");
299                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#A:ColumnSize_Value");
300                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#A:NumericPrecision_IsNull");
301                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#A:NumericPrecision_Value");
302                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#A:NumericScale_IsNull");
303                                 Assert.AreEqual (0, pkRow ["NumericScale"], "#A:NumericScale_Value");
304                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#A:DataType_IsNull");
305                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#A:DataType_Value");
306                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#A:ProviderType_IsNull");
307                                 Assert.AreEqual (10, pkRow ["ProviderType"], "#A:ProviderType_Value");
308                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#A:IsLong_IsNull");
309                                 Assert.AreEqual (false, pkRow ["IsLong"], "#A:IsLong_Value");
310                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#A:AllowDBNull_IsNull");
311                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#A:AllowDBNull_Value");
312                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#A:IsReadOnly_IsNull");
313                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#A:IsReadOnly_Value");
314                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#A:IsRowVersion_IsNull");
315                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#A:IsRowVersion_Value");
316                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#A:IsUnique_IsNull");
317                                 Assert.AreEqual (true, pkRow ["IsUnique"], "#A:IsUnique_Value");
318                                 Assert.IsFalse (pkRow.IsNull ("IsKey"), "#A:IsKey_IsNull");
319                                 Assert.AreEqual (true, pkRow ["IsKey"], "#A:IsKey_Value");
320                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#A:IsAutoIncrement_IsNull");
321                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#A:IsAutoIncrement_Value");
322                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#A:BaseSchemaName_IsNull");
323                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#A:BaseSchemaName_Value");
324                                 Assert.IsFalse (pkRow.IsNull ("BaseCatalogName"), "#A:BaseCatalogName_IsNull");
325                                 Assert.AreEqual (ConnectionManager.Instance.DatabaseName, pkRow ["BaseCatalogName"], "#A:BaseCatalogName_Value");
326                                 Assert.IsFalse (pkRow.IsNull ("BaseTableName"), "#A:BaseTableName_IsNull");
327                                 Assert.AreEqual ("employee", pkRow ["BaseTableName"], "#A:BaseTableName_Value");
328                                 Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#A:BaseColumnName_IsNull");
329                                 Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#A:BaseColumnName_Value");
330
331                                 reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly);
332                                 schema = reader.GetSchemaTable ();
333                                 reader.Close ();
334
335                                 AssertSchemaTableStructure (schema, "#B:");
336                                 Assert.AreEqual (3, schema.Rows.Count, "#B:RowCount");
337                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
338                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#B:ColumnName_IsNull");
339                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#B:ColumnName_Value");
340                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#B:ColumnOrdinal_IsNull");
341                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#B:ColumnOrdinal_Value");
342                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#B:ColumnSize_IsNull");
343                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#B:ColumnSize_Value");
344                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#B:NumericPrecision_IsNull");
345                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#B:NumericPrecision_Value");
346                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#B:NumericScale_IsNull");
347                                 Assert.AreEqual (0, pkRow ["NumericScale"], "#B:NumericScale_Value");
348                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#B:DataType_IsNull");
349                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#B:DataType_Value");
350                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#B:ProviderType_IsNull");
351                                 Assert.AreEqual (10, pkRow ["ProviderType"], "#B:ProviderType_Value");
352                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#B:IsLong_IsNull");
353                                 Assert.AreEqual (false, pkRow ["IsLong"], "#B:IsLong_Value");
354                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#B:AllowDBNull_IsNull");
355                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#B:AllowDBNull_Value");
356                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#B:IsReadOnly_IsNull");
357                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#B:IsReadOnly_Value");
358                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#B:IsRowVersion_IsNull");
359                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#B:IsRowVersion_Value");
360                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#B:IsUnique_IsNull");
361                                 Assert.AreEqual (false, pkRow ["IsUnique"], "#B:IsUnique_Value");
362                                 Assert.IsFalse (pkRow.IsNull ("IsKey"), "#B:IsKey_IsNull");
363                                 Assert.AreEqual (false, pkRow ["IsKey"], "#B:IsKey_Value");
364                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#B:IsAutoIncrement_IsNull");
365                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#B:IsAutoIncrement_Value");
366                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#B:BaseSchemaName_IsNull");
367                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#B:BaseSchemaName_Value");
368                                 Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#B:BaseCatalogName_IsNull");
369                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#B:BaseCatalogName_Value");
370                                 Assert.IsTrue (pkRow.IsNull ("BaseTableName"), "#B:BaseTableName_IsNull");
371                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseTableName"], "#B:BaseTableName_Value");
372                                 Assert.IsTrue (pkRow.IsNull ("BaseColumnName"), "#B:BaseColumnName_IsNull");
373                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseColumnName"], "#B:BaseColumnName_Value");
374
375                                 reader = cmd.ExecuteReader (CommandBehavior.KeyInfo);
376                                 schema = reader.GetSchemaTable ();
377                                 reader.Close ();
378
379                                 AssertSchemaTableStructure (schema, "#C:");
380                                 Assert.AreEqual (3, schema.Rows.Count, "#C:RowCount");
381                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
382                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#C:ColumnName_IsNull");
383                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#C:ColumnName_Value");
384                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#C:ColumnOrdinal_IsNull");
385                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#C:ColumnOrdinal_Value");
386                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#C:ColumnSize_IsNull");
387                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#C:ColumnSize_Value");
388                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#C:NumericPrecision_IsNull");
389                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#C:NumericPrecision_Value");
390                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#C:NumericScale_IsNull");
391                                 Assert.AreEqual (0, pkRow ["NumericScale"], "#C:NumericScale_Value");
392                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#C:DataType_IsNull");
393                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#C:DataType_Value");
394                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#C:ProviderType_IsNull");
395                                 Assert.AreEqual (10, pkRow ["ProviderType"], "#C:ProviderType_Value");
396                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#C:IsLong_IsNull");
397                                 Assert.AreEqual (false, pkRow ["IsLong"], "#C:IsLong_Value");
398                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#C:AllowDBNull_IsNull");
399                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#C:AllowDBNull_Value");
400                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#C:IsReadOnly_IsNull");
401                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#C:IsReadOnly_Value");
402                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#C:IsRowVersion_IsNull");
403                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#C:IsRowVersion_Value");
404                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#C:IsUnique_IsNull");
405                                 Assert.AreEqual (true, pkRow ["IsUnique"], "#C:IsUnique_Value");
406                                 Assert.IsFalse (pkRow.IsNull ("IsKey"), "#C:IsKey_IsNull");
407                                 Assert.AreEqual (true, pkRow ["IsKey"], "#C:IsKey_Value");
408                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#C:IsAutoIncrement_IsNull");
409                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#C:IsAutoIncrement_Value");
410                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#C:BaseSchemaName_IsNull");
411                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#C:BaseSchemaName_Value");
412                                 Assert.IsFalse (pkRow.IsNull ("BaseCatalogName"), "#C:BaseCatalogName_IsNull");
413                                 Assert.AreEqual (ConnectionManager.Instance.DatabaseName, pkRow ["BaseCatalogName"], "#C:BaseCatalogName_Value");
414                                 Assert.IsFalse (pkRow.IsNull ("BaseTableName"), "#C:BaseTableName_IsNull");
415                                 Assert.AreEqual ("employee", pkRow ["BaseTableName"], "#C:BaseTableName_Value");
416                                 Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#C:BaseColumnName_IsNull");
417                                 Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#C:BaseColumnName_Value");
418
419                                 reader = cmd.ExecuteReader ();
420                                 schema = reader.GetSchemaTable ();
421                                 reader.Close ();
422
423                                 AssertSchemaTableStructure (schema, "#D:");
424                                 Assert.AreEqual (3, schema.Rows.Count, "#D:RowCount");
425                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
426                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#D:ColumnName_IsNull");
427                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#D:ColumnName_Value");
428                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#D:ColumnOrdinal_IsNull");
429                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#D:ColumnOrdinal_Value");
430                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#D:ColumnSize_IsNull");
431                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#D:ColumnSize_Value");
432                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#D:NumericPrecision_IsNull");
433                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#D:NumericPrecision_Value");
434                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#D:NumericScale_IsNull");
435                                 Assert.AreEqual (0, pkRow ["NumericScale"], "#D:NumericScale_Value");
436                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#D:DataType_IsNull");
437                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#D:DataType_Value");
438                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#D:ProviderType_IsNull");
439                                 Assert.AreEqual (10, pkRow ["ProviderType"], "#D:ProviderType_Value");
440                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#D:IsLong_IsNull");
441                                 Assert.AreEqual (false, pkRow ["IsLong"], "#D:IsLong_Value");
442                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#D:AllowDBNull_IsNull");
443                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#D:AllowDBNull_Value");
444                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#D:IsReadOnly_IsNull");
445                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#D:IsReadOnly_Value");
446                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#D:IsRowVersion_IsNull");
447                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#D:IsRowVersion_Value");
448                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#D:IsUnique_IsNull");
449                                 Assert.AreEqual (false, pkRow ["IsUnique"], "#D:IsUnique_Value");
450                                 Assert.IsFalse (pkRow.IsNull ("IsKey"), "#D:IsKey_IsNull");
451                                 Assert.AreEqual (false, pkRow ["IsKey"], "#D:IsKey_Value");
452                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#D:IsAutoIncrement_IsNull");
453                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#D:IsAutoIncrement_Value");
454                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#D:BaseSchemaName_IsNull");
455                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#D:BaseSchemaName_Value");
456                                 Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#D:BaseCatalogName_IsNull");
457                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#D:BaseCatalogName_Value");
458                                 Assert.IsTrue (pkRow.IsNull ("BaseTableName"), "#D:BaseTableName_IsNull");
459                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseTableName"], "#D:BaseTableName_Value");
460                                 Assert.IsTrue (pkRow.IsNull ("BaseColumnName"), "#D:BaseColumnName_IsNull");
461                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseColumnName"], "#D:BaseColumnName_Value");
462
463                                 cmd = conn.CreateCommand ();
464                                 cmd.CommandText = "select id, fname, id + 20 as plustwenty from employee";
465                                 cmd.Prepare ();
466                                 reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);
467                                 schema = reader.GetSchemaTable ();
468                                 reader.Close ();
469
470                                 AssertSchemaTableStructure (schema, "#E:");
471                                 Assert.AreEqual (3, schema.Rows.Count, "#E:RowCount");
472                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
473                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#E:ColumnName_IsNull");
474                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#E:ColumnName_Value");
475                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#E:ColumnOrdinal_IsNull");
476                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#E:ColumnOrdinal_Value");
477                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#E:ColumnSize_IsNull");
478                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#E:ColumnSize_Value");
479                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#E:NumericPrecision_IsNull");
480                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#E:NumericPrecision_Value");
481                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#E:NumericScale_IsNull");
482                                 Assert.AreEqual (0, pkRow ["NumericScale"], "#E:NumericScale_Value");
483                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#E:DataType_IsNull");
484                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#E:DataType_Value");
485                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#E:ProviderType_IsNull");
486                                 Assert.AreEqual (10, pkRow ["ProviderType"], "#E:ProviderType_Value");
487                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#E:IsLong_IsNull");
488                                 Assert.AreEqual (false, pkRow ["IsLong"], "#E:IsLong_Value");
489                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#E:AllowDBNull_IsNull");
490                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#E:AllowDBNull_Value");
491                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#E:IsReadOnly_IsNull");
492                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#E:IsReadOnly_Value");
493                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#E:IsRowVersion_IsNull");
494                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#E:IsRowVersion_Value");
495                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#E:IsUnique_IsNull");
496                                 Assert.AreEqual (true, pkRow ["IsUnique"], "#E:IsUnique_Value");
497                                 Assert.IsFalse (pkRow.IsNull ("IsKey"), "#E:IsKey_IsNull");
498                                 Assert.AreEqual (true, pkRow ["IsKey"], "#E:IsKey_Value");
499                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#E:IsAutoIncrement_IsNull");
500                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#E:IsAutoIncrement_Value");
501                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#E:BaseSchemaName_IsNull");
502                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#E:BaseSchemaName_Value");
503                                 Assert.IsFalse (pkRow.IsNull ("BaseCatalogName"), "#E:BaseCatalogName_IsNull");
504                                 Assert.AreEqual (ConnectionManager.Instance.DatabaseName, pkRow ["BaseCatalogName"], "#E:BaseCatalogName_Value");
505                                 Assert.IsFalse (pkRow.IsNull ("BaseTableName"), "#E:BaseTableName_IsNull");
506                                 Assert.AreEqual ("employee", pkRow ["BaseTableName"], "#E:BaseTableName_Value");
507                                 Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#E:BaseColumnName_IsNull");
508                                 Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#E:BaseColumnName_Value");
509
510                                 reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly);
511                                 schema = reader.GetSchemaTable ();
512                                 reader.Close ();
513
514                                 AssertSchemaTableStructure (schema, "#F:");
515                                 Assert.AreEqual (3, schema.Rows.Count, "#F:RowCount");
516                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
517                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#F:ColumnName_IsNull");
518                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#F:ColumnName_Value");
519                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#F:ColumnOrdinal_IsNull");
520                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#F:ColumnOrdinal_Value");
521                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#F:ColumnSize_IsNull");
522                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#F:ColumnSize_Value");
523                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#F:NumericPrecision_IsNull");
524                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#F:NumericPrecision_Value");
525                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#F:NumericScale_IsNull");
526                                 Assert.AreEqual (0, pkRow ["NumericScale"], "#F:NumericScale_Value");
527                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#F:DataType_IsNull");
528                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#F:DataType_Value");
529                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#F:ProviderType_IsNull");
530                                 Assert.AreEqual (10, pkRow ["ProviderType"], "#F:ProviderType_Value");
531                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#F:IsLong_IsNull");
532                                 Assert.AreEqual (false, pkRow ["IsLong"], "#F:IsLong_Value");
533                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#F:AllowDBNull_IsNull");
534                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#F:AllowDBNull_Value");
535                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#F:IsReadOnly_IsNull");
536                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#F:IsReadOnly_Value");
537                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#F:IsRowVersion_IsNull");
538                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#F:IsRowVersion_Value");
539                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#F:IsUnique_IsNull");
540                                 Assert.AreEqual (false, pkRow ["IsUnique"], "#F:IsUnique_Value");
541                                 Assert.IsFalse (pkRow.IsNull ("IsKey"), "#F:IsKey_IsNull");
542                                 Assert.AreEqual (false, pkRow ["IsKey"], "#F:IsKey_Value");
543                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#F:IsAutoIncrement_IsNull");
544                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#F:IsAutoIncrement_Value");
545                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#F:BaseSchemaName_IsNull");
546                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#F:BaseSchemaName_Value");
547                                 Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#F:BaseCatalogName_IsNull");
548                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#F:BaseCatalogName_Value");
549                                 Assert.IsTrue (pkRow.IsNull ("BaseTableName"), "#F:BaseTableName_IsNull");
550                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseTableName"], "#F:BaseTableName_Value");
551                                 Assert.IsTrue (pkRow.IsNull ("BaseColumnName"), "#F:BaseColumnName_IsNull");
552                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseColumnName"], "#F:BaseColumnName_Value");
553
554                                 reader = cmd.ExecuteReader (CommandBehavior.KeyInfo);
555                                 schema = reader.GetSchemaTable ();
556                                 reader.Close ();
557
558                                 AssertSchemaTableStructure (schema, "#G:");
559                                 Assert.AreEqual (3, schema.Rows.Count, "#G:RowCount");
560                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
561                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#G:ColumnName_IsNull");
562                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#G:ColumnName_Value");
563                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#G:ColumnOrdinal_IsNull");
564                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#G:ColumnOrdinal_Value");
565                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#G:ColumnSize_IsNull");
566                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#G:ColumnSize_Value");
567                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#G:NumericPrecision_IsNull");
568                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#G:NumericPrecision_Value");
569                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#G:NumericScale_IsNull");
570                                 Assert.AreEqual (0, pkRow ["NumericScale"], "#G:NumericScale_Value");
571                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#G:DataType_IsNull");
572                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#G:DataType_Value");
573                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#G:ProviderType_IsNull");
574                                 Assert.AreEqual (10, pkRow ["ProviderType"], "#G:ProviderType_Value");
575                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#G:IsLong_IsNull");
576                                 Assert.AreEqual (false, pkRow ["IsLong"], "#G:IsLong_Value");
577                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#G:AllowDBNull_IsNull");
578                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#G:AllowDBNull_Value");
579                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#G:IsReadOnly_IsNull");
580                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#G:IsReadOnly_Value");
581                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#G:IsRowVersion_IsNull");
582                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#G:IsRowVersion_Value");
583                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#G:IsUnique_IsNull");
584                                 Assert.AreEqual (true, pkRow ["IsUnique"], "#G:IsUnique_Value");
585                                 Assert.IsFalse (pkRow.IsNull ("IsKey"), "#G:IsKey_IsNull");
586                                 Assert.AreEqual (true, pkRow ["IsKey"], "#G:IsKey_Value");
587                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#G:IsAutoIncrement_IsNull");
588                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#G:IsAutoIncrement_Value");
589                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#G:BaseSchemaName_IsNull");
590                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#G:BaseSchemaName_Value");
591                                 Assert.IsFalse (pkRow.IsNull ("BaseCatalogName"), "#G:BaseCatalogName_IsNull");
592                                 Assert.AreEqual (ConnectionManager.Instance.DatabaseName, pkRow ["BaseCatalogName"], "#G:BaseCatalogName_Value");
593                                 Assert.IsFalse (pkRow.IsNull ("BaseTableName"), "#G:BaseTableName_IsNull");
594                                 Assert.AreEqual ("employee", pkRow ["BaseTableName"], "#G:BaseTableName_Value");
595                                 Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#G:BaseColumnName_IsNull");
596                                 Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#G:BaseColumnName_Value");
597
598                                 reader = cmd.ExecuteReader ();
599                                 schema = reader.GetSchemaTable ();
600                                 reader.Close ();
601
602                                 AssertSchemaTableStructure (schema, "#H:");
603                                 Assert.AreEqual (3, schema.Rows.Count, "#H:RowCount");
604                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
605                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#H:ColumnName_IsNull");
606                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#H:ColumnName_Value");
607                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#H:ColumnOrdinal_IsNull");
608                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#H:ColumnOrdinal_Value");
609                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#H:ColumnSize_IsNull");
610                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#H:ColumnSize_Value");
611                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#H:NumericPrecision_IsNull");
612                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#H:NumericPrecision_Value");
613                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#H:NumericScale_IsNull");
614                                 Assert.AreEqual (0, pkRow ["NumericScale"], "#H:NumericScale_Value");
615                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#H:DataType_IsNull");
616                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#H:DataType_Value");
617                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#H:ProviderType_IsNull");
618                                 Assert.AreEqual (10, pkRow ["ProviderType"], "#H:ProviderType_Value");
619                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#H:IsLong_IsNull");
620                                 Assert.AreEqual (false, pkRow ["IsLong"], "#H:IsLong_Value");
621                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#H:AllowDBNull_IsNull");
622                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#H:AllowDBNull_Value");
623                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#H:IsReadOnly_IsNull");
624                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#H:IsReadOnly_Value");
625                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#H:IsRowVersion_IsNull");
626                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#H:IsRowVersion_Value");
627                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#H:IsUnique_IsNull");
628                                 Assert.AreEqual (false, pkRow ["IsUnique"], "#H:IsUnique_Value");
629                                 Assert.IsFalse (pkRow.IsNull ("IsKey"), "#H:IsKey_IsNull");
630                                 Assert.AreEqual (false, pkRow ["IsKey"], "#H:IsKey_Value");
631                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#H:IsAutoIncrement_IsNull");
632                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#H:IsAutoIncrement_Value");
633                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#H:BaseSchemaName_IsNull");
634                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#H:BaseSchemaName_Value");
635                                 Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#H:BaseCatalogName_IsNull");
636                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#H:BaseCatalogName_Value");
637                                 Assert.IsTrue (pkRow.IsNull ("BaseTableName"), "#H:BaseTableName_IsNull");
638                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseTableName"], "#H:BaseTableName_Value");
639                                 Assert.IsTrue (pkRow.IsNull ("BaseColumnName"), "#H:BaseColumnName_IsNull");
640                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseColumnName"], "#H:BaseColumnName_Value");
641
642                                 cmd.CommandText = "select id, fname, id + 20 as plustwenty from employee where id = ?";
643                                 IDbDataParameter param = cmd.CreateParameter ();
644                                 cmd.Parameters.Add (param);
645                                 param.DbType = DbType.Int32;
646                                 param.Value = 2;
647                                 reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);
648                                 schema = reader.GetSchemaTable ();
649                                 reader.Close ();
650
651                                 AssertSchemaTableStructure (schema, "#I:");
652                                 Assert.AreEqual (3, schema.Rows.Count, "#I:RowCount");
653                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
654                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#I:ColumnName_IsNull");
655                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#I:ColumnName_Value");
656                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#I:ColumnOrdinal_IsNull");
657                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#I:ColumnOrdinal_Value");
658                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#I:ColumnSize_IsNull");
659                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#I:ColumnSize_Value");
660                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#I:NumericPrecision_IsNull");
661                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#I:NumericPrecision_Value");
662                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#I:NumericScale_IsNull");
663                                 Assert.AreEqual (0, pkRow ["NumericScale"], "#I:NumericScale_Value");
664                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#I:DataType_IsNull");
665                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#I:DataType_Value");
666                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#I:ProviderType_IsNull");
667                                 Assert.AreEqual (10, pkRow ["ProviderType"], "#I:ProviderType_Value");
668                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#I:IsLong_IsNull");
669                                 Assert.AreEqual (false, pkRow ["IsLong"], "#I:IsLong_Value");
670                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#I:AllowDBNull_IsNull");
671                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#I:AllowDBNull_Value");
672                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#I:IsReadOnly_IsNull");
673                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#I:IsReadOnly_Value");
674                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#I:IsRowVersion_IsNull");
675                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#I:IsRowVersion_Value");
676                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#I:IsUnique_IsNull");
677                                 Assert.AreEqual (true, pkRow ["IsUnique"], "#I:IsUnique_Value");
678                                 Assert.IsFalse (pkRow.IsNull ("IsKey"), "#I:IsKey_IsNull");
679                                 Assert.AreEqual (true, pkRow ["IsKey"], "#I:IsKey_Value");
680                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#I:IsAutoIncrement_IsNull");
681                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#I:IsAutoIncrement_Value");
682                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#I:BaseSchemaName_IsNull");
683                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#I:BaseSchemaName_Value");
684                                 Assert.IsFalse (pkRow.IsNull ("BaseCatalogName"), "#I:BaseCatalogName_IsNull");
685                                 Assert.AreEqual (ConnectionManager.Instance.DatabaseName, pkRow ["BaseCatalogName"], "#I:BaseCatalogName_Value");
686                                 Assert.IsFalse (pkRow.IsNull ("BaseTableName"), "#I:BaseTableName_IsNull");
687                                 Assert.AreEqual ("employee", pkRow ["BaseTableName"], "#I:BaseTableName_Value");
688                                 Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#I:BaseColumnName_IsNull");
689                                 Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#I:BaseColumnName_Value");
690
691                                 reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly);
692                                 schema = reader.GetSchemaTable ();
693                                 reader.Close ();
694
695                                 AssertSchemaTableStructure (schema, "#J:");
696                                 Assert.AreEqual (3, schema.Rows.Count, "#J:RowCount");
697                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
698                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#J:ColumnName_IsNull");
699                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#J:ColumnName_Value");
700                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#J:ColumnOrdinal_IsNull");
701                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#J:ColumnOrdinal_Value");
702                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#J:ColumnSize_IsNull");
703                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#J:ColumnSize_Value");
704                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#J:NumericPrecision_IsNull");
705                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#J:NumericPrecision_Value");
706                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#J:NumericScale_IsNull");
707                                 Assert.AreEqual (0, pkRow ["NumericScale"], "#J:NumericScale_Value");
708                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#J:DataType_IsNull");
709                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#J:DataType_Value");
710                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#J:ProviderType_IsNull");
711                                 Assert.AreEqual (10, pkRow ["ProviderType"], "#J:ProviderType_Value");
712                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#J:IsLong_IsNull");
713                                 Assert.AreEqual (false, pkRow ["IsLong"], "#J:IsLong_Value");
714                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#J:AllowDBNull_IsNull");
715                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#J:AllowDBNull_Value");
716                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#J:IsReadOnly_IsNull");
717                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#J:IsReadOnly_Value");
718                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#J:IsRowVersion_IsNull");
719                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#J:IsRowVersion_Value");
720                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#J:IsUnique_IsNull");
721                                 Assert.AreEqual (false, pkRow ["IsUnique"], "#J:IsUnique_Value");
722                                 Assert.IsFalse (pkRow.IsNull ("IsKey"), "#J:IsKey_IsNull");
723                                 Assert.AreEqual (false, pkRow ["IsKey"], "#J:IsKey_Value");
724                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#J:IsAutoIncrement_IsNull");
725                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#J:IsAutoIncrement_Value");
726                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#J:BaseSchemaName_IsNull");
727                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#J:BaseSchemaName_Value");
728                                 Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#J:BaseCatalogName_IsNull");
729                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#J:BaseCatalogName_Value");
730                                 Assert.IsTrue (pkRow.IsNull ("BaseTableName"), "#J:BaseTableName_IsNull");
731                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseTableName"], "#J:BaseTableName_Value");
732                                 Assert.IsTrue (pkRow.IsNull ("BaseColumnName"), "#J:BaseColumnName_IsNull");
733                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseColumnName"], "#J:BaseColumnName_Value");
734
735                                 reader = cmd.ExecuteReader (CommandBehavior.KeyInfo);
736                                 schema = reader.GetSchemaTable ();
737                                 reader.Close ();
738
739                                 AssertSchemaTableStructure (schema, "#K:");
740                                 Assert.AreEqual (3, schema.Rows.Count, "#K:RowCount");
741                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
742                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#K:ColumnName_IsNull");
743                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#K:ColumnName_Value");
744                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#K:ColumnOrdinal_IsNull");
745                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#K:ColumnOrdinal_Value");
746                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#K:ColumnSize_IsNull");
747                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#K:ColumnSize_Value");
748                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#K:NumericPrecision_IsNull");
749                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#K:NumericPrecision_Value");
750                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#K:NumericScale_IsNull");
751                                 Assert.AreEqual (0, pkRow ["NumericScale"], "#K:NumericScale_Value");
752                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#K:DataType_IsNull");
753                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#K:DataType_Value");
754                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#K:ProviderType_IsNull");
755                                 Assert.AreEqual (10, pkRow ["ProviderType"], "#K:ProviderType_Value");
756                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#K:IsLong_IsNull");
757                                 Assert.AreEqual (false, pkRow ["IsLong"], "#K:IsLong_Value");
758                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#K:AllowDBNull_IsNull");
759                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#K:AllowDBNull_Value");
760                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#K:IsReadOnly_IsNull");
761                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#K:IsReadOnly_Value");
762                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#K:IsRowVersion_IsNull");
763                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#K:IsRowVersion_Value");
764                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#K:IsUnique_IsNull");
765                                 Assert.AreEqual (true, pkRow ["IsUnique"], "#K:IsUnique_Value");
766                                 Assert.IsFalse (pkRow.IsNull ("IsKey"), "#K:IsKey_IsNull");
767                                 Assert.AreEqual (true, pkRow ["IsKey"], "#K:IsKey_Value");
768                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#K:IsAutoIncrement_IsNull");
769                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#K:IsAutoIncrement_Value");
770                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#K:BaseSchemaName_IsNull");
771                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#K:BaseSchemaName_Value");
772                                 Assert.IsFalse (pkRow.IsNull ("BaseCatalogName"), "#K:BaseCatalogName_IsNull");
773                                 Assert.AreEqual (ConnectionManager.Instance.DatabaseName, pkRow ["BaseCatalogName"], "#K:BaseCatalogName_Value");
774                                 Assert.IsFalse (pkRow.IsNull ("BaseTableName"), "#K:BaseTableName_IsNull");
775                                 Assert.AreEqual ("employee", pkRow ["BaseTableName"], "#K:BaseTableName_Value");
776                                 Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#K:BaseColumnName_IsNull");
777                                 Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#K:BaseColumnName_Value");
778
779                                 reader = cmd.ExecuteReader ();
780                                 schema = reader.GetSchemaTable ();
781                                 reader.Close ();
782
783                                 AssertSchemaTableStructure (schema, "#L:");
784                                 Assert.AreEqual (3, schema.Rows.Count, "#L:RowCount");
785                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
786                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#L:ColumnName_IsNull");
787                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#L:ColumnName_Value");
788                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#L:ColumnOrdinal_IsNull");
789                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#L:ColumnOrdinal_Value");
790                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#L:ColumnSize_IsNull");
791                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#L:ColumnSize_Value");
792                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#L:NumericPrecision_IsNull");
793                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#L:NumericPrecision_Value");
794                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#L:NumericScale_IsNull");
795                                 Assert.AreEqual (0, pkRow ["NumericScale"], "#L:NumericScale_Value");
796                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#L:DataType_IsNull");
797                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#L:DataType_Value");
798                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#L:ProviderType_IsNull");
799                                 Assert.AreEqual (10, pkRow ["ProviderType"], "#L:ProviderType_Value");
800                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#L:IsLong_IsNull");
801                                 Assert.AreEqual (false, pkRow ["IsLong"], "#L:IsLong_Value");
802                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#L:AllowDBNull_IsNull");
803                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#L:AllowDBNull_Value");
804                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#L:IsReadOnly_IsNull");
805                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#L:IsReadOnly_Value");
806                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#L:IsRowVersion_IsNull");
807                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#L:IsRowVersion_Value");
808                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#L:IsUnique_IsNull");
809                                 Assert.AreEqual (false, pkRow ["IsUnique"], "#L:IsUnique_Value");
810                                 Assert.IsFalse (pkRow.IsNull ("IsKey"), "#L:IsKey_IsNull");
811                                 Assert.AreEqual (false, pkRow ["IsKey"], "#L:IsKey_Value");
812                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#L:IsAutoIncrement_IsNull");
813                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#L:IsAutoIncrement_Value");
814                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#L:BaseSchemaName_IsNull");
815                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#L:BaseSchemaName_Value");
816                                 Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#L:BaseCatalogName_IsNull");
817                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#L:BaseCatalogName_Value");
818                                 Assert.IsTrue (pkRow.IsNull ("BaseTableName"), "#L:BaseTableName_IsNull");
819                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseTableName"], "#L:BaseTableName_Value");
820                                 Assert.IsTrue (pkRow.IsNull ("BaseColumnName"), "#L:BaseColumnName_IsNull");
821                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseColumnName"], "#L:BaseColumnName_Value");
822                         } finally {
823                                 if (reader != null)
824                                         reader.Close ();
825                         }
826                 }
827
828                 [Test]
829                 public void OutputParametersTest ()
830                 {
831                         // MySQL currently does not support output parameters
832                         // in its ODBC connector:
833                         // http://www.paragon-cs.com/mag/issue3.pdf
834                         if (ConnectionManager.Instance.Odbc.EngineConfig.Type != EngineType.SQLServer)
835                                 Assert.Ignore ("MySQL does not (yet) support output parameters using ODBC.");
836
837                         IDataReader reader = null;
838
839                         try {
840                                 cmd.CommandText = "{? = CALL sp_get_age (?, ?)}";
841
842                                 OdbcParameter ret = new OdbcParameter ("ret", OdbcType.Int);
843                                 cmd.Parameters.Add (ret);
844                                 ret.Direction = ParameterDirection.ReturnValue;
845
846                                 OdbcParameter name = new OdbcParameter ("fname", OdbcType.VarChar);
847                                 cmd.Parameters.Add (name);
848                                 name.Direction = ParameterDirection.Input;
849                                 name.Value = "suresh";
850
851                                 OdbcParameter age = new OdbcParameter ("age", OdbcType.Int);
852                                 cmd.Parameters.Add (age);
853                                 age.Direction = ParameterDirection.Output;
854
855                                 reader = cmd.ExecuteReader ();
856                                 reader.Close ();
857
858                                 /* FIXME: we don't support output/return parameters */
859                                 if (!RunningOnMono) {
860                                         Assert.IsTrue (((int) (age.Value)) > 0, "#1");
861                                         Assert.IsTrue (((int) ret.Value) > 0, "#2");
862                                 }
863                         } finally {
864                                 if (reader != null)
865                                         reader.Close ();
866                         }
867                 }
868
869                 [Test]
870                 public void LongTextTest ()
871                 {
872                         IDataReader reader = null;
873
874                         try {
875                                 cmd.CommandText = "Select type_text from string_family where id=2";
876
877                                 reader = cmd.ExecuteReader ();
878                                 reader.Read ();
879                                 reader.GetValue (0);
880                         }finally {
881                                 if (reader != null)
882                                         reader.Close ();
883                         }
884                 }
885                 
886                 [Test]
887                 public void Bug82135Test ()
888                 {
889                         const string drop_table = "drop table odbcnodatatest";
890
891                         // cleanup in case of previously failed test
892                         DBHelper.ExecuteNonQuery (conn, drop_table);
893
894                         cmd = new OdbcCommand ("create table odbcnodatatest (ID int not null, Val1 text)",
895                                 conn);
896                         cmd.ExecuteNonQuery ();
897                         cmd = new OdbcCommand ("delete from odbcnodatatest", conn);
898                         Assert.AreEqual (0, cmd.ExecuteNonQuery ());
899
900                         // cleanup
901                         cmd = new OdbcCommand (drop_table, conn);
902                         cmd.ExecuteNonQuery ();
903                 }
904
905                 [Test]
906                 public void Bug82560Test ()
907                 {
908                         string drop_table = "DROP TABLE odbc_alias_test";
909
910                         // cleanup in case of previously failed test
911                         DBHelper.ExecuteNonQuery (conn, drop_table);
912
913                         DoExecuteNonQuery (conn, "CREATE TABLE odbc_alias_test" + 
914                                            "(ifld INT NOT NULL PRIMARY KEY, sfld VARCHAR(20))");
915                         DoExecuteNonQuery (conn, "INSERT INTO odbc_alias_test" +
916                                            "(ifld, sfld) VALUES (1, '1111')");
917                         DoExecuteScalar (conn, "SELECT A.ifld FROM odbc_alias_test " +
918                                          "A WHERE A.ifld = 1");
919                         DoExecuteNonQuery (conn, drop_table);
920                 }
921
922                 [Test]
923                 public void FindZeroInToStringTest ()
924                 {
925                         if (ConnectionManager.Instance.Odbc.EngineConfig.Type != EngineType.MySQL)
926                                 Assert.Ignore ("Only applies to MySQL.");
927
928                         IDataReader reader = null;
929
930                         try {
931                                 // Create table
932                                 cmd.CommandText = "Create table foo ( bar long varchar )";
933                                 cmd.ExecuteNonQuery();
934                                 cmd.Dispose ();
935
936                                 // Insert a record into foo
937                                 cmd = conn.CreateCommand ();
938                                 cmd.CommandText = "Insert into foo (bar) values ( '"
939                                   + "This string has more than 255 characters"
940                                   + "This string has more than 255 characters"
941                                   + "This string has more than 255 characters"
942                                   + "This string has more than 255 characters"
943                                   + "This string has more than 255 characters"
944                                   + "This string has more than 255 characters"
945                                   + "This string has more than 255 characters"
946                                   + "This string has more than 255 characters"
947                                   + "This string has more than 255 characters"
948                                   + "This string has more than 255 characters"
949                                   + "This string has more than 255 characters"
950                                   + "This string has more than 255 characters"
951                                   + "This string has more than 255 characters"
952                                   + "This string has more than 255 characters"
953                                   + "This string has more than 255 characters"
954                                   + "This string has more than 255 characters"
955                                   + "This string has more than 255 characters"
956                                   + "This string has more than 255 characters"
957                                   + "This string has more than 255 characters"
958                                   + "This string has more than 255 characters"
959                                   + "This string has more than 255 characters"
960                                   + "This string has more than 255 characters"
961                                   + "This string has more than 255 characters"
962                                   + "This string has more than 255 characters"
963                                   + "' )";
964                                 cmd.ExecuteNonQuery();
965                                 cmd.Dispose ();
966
967                                 // Now, get the record back - try and read it two different ways.
968                                 cmd = conn.CreateCommand ();
969                                 cmd.CommandText = "SELECT bar FROM foo" ;
970                                 reader = cmd.ExecuteReader ();
971                                 string readAsString = "";
972                                 while (reader.Read ()) {
973                                         readAsString = reader[0].ToString();
974                                 }
975                                 reader.Close();
976                                 cmd.Dispose ();
977
978                                 // Now, read it using GetBytes
979                                 cmd = conn.CreateCommand ();
980                                 cmd.CommandText = "SELECT bar FROM foo";
981                                 reader = cmd.ExecuteReader ();
982                                 byte[] buffer = new byte [2048];
983                                 long total = 0;
984                                 while (reader.Read ()) {
985                                         total = reader.GetBytes (0, 0, buffer, 0, 2048);
986                                 }
987                                 reader.Close();
988                                 // Convert bytes read to string - look for binary zero - there is none (OK)
989                                 string readAsBytes = Encoding.Default.GetString (buffer, 0, (int) total);
990                                 Assert.AreEqual  (readAsBytes, readAsString, "#1 ReadAsString is not same as ReadAsBytes");
991                         } finally {
992                                 if (reader != null)
993                                         reader.Close ();
994                                 DBHelper.ExecuteNonQuery (conn, "Drop table foo");
995                         }
996                 }
997
998                 [Test]
999                 public void Bug332404Test ()
1000                 {
1001                         if (ConnectionManager.Instance.Odbc.EngineConfig.Type != EngineType.MySQL)
1002                                 Assert.Ignore ("Only applies to MySQL.");
1003
1004                         cmd = new OdbcCommand ("DROP TABLE IF EXISTS odbc_test");
1005                         cmd.Connection = conn;
1006                         cmd.ExecuteNonQuery ();
1007
1008                         cmd = new OdbcCommand ("CREATE TABLE odbc_test (id_test INTEGER NOT NULL, payload DECIMAL (14,4) NOT NULL)");
1009                         cmd.Connection = conn;
1010                         cmd.ExecuteNonQuery ();
1011
1012                         cmd = new OdbcCommand ("INSERT INTO odbc_test (id_test, payload) VALUES (1, 1.23456789)");
1013                         cmd.Connection = conn;
1014                         cmd.ExecuteNonQuery ();
1015
1016                         OdbcDataAdapter Adaptador = new OdbcDataAdapter ();
1017
1018                         DataSet Lector = new DataSet ();
1019
1020                         Adaptador.SelectCommand = new OdbcCommand ("SELECT * FROM odbc_test WHERE id_test=1", (OdbcConnection) conn);
1021                         Adaptador.Fill (Lector);
1022                         Assert.AreEqual (Lector.Tables[0].Rows[0]["payload"], 1.2346);
1023                 }
1024
1025                 [Test]
1026                 public void Bug332400Test ()
1027                 {
1028                         if (ConnectionManager.Instance.Odbc.EngineConfig.Type != EngineType.MySQL)
1029                                 Assert.Ignore ("Only applies to MySQL.");
1030
1031                         cmd = new OdbcCommand ("DROP TABLE IF EXISTS blob_test");
1032                         cmd.Connection = conn;
1033                         cmd.ExecuteNonQuery ();
1034
1035                         cmd = new OdbcCommand ("CREATE TABLE blob_test (id_test INTEGER NOT NULL, payload LONGBLOB NOT NULL)");
1036                         cmd.Connection = conn;
1037                         cmd.ExecuteNonQuery ();
1038
1039                         cmd = new OdbcCommand ("INSERT INTO blob_test (id_test, payload) VALUES (1, 'test')");
1040                         cmd.Connection = conn;
1041                         cmd.ExecuteNonQuery ();
1042
1043                         OdbcDataAdapter Adaptador = new OdbcDataAdapter();
1044                         DataSet Lector = new DataSet();
1045
1046                         Adaptador.SelectCommand = new OdbcCommand("SELECT * FROM blob_test WHERE id_test=1", (OdbcConnection) conn);
1047                         Adaptador.Fill(Lector);
1048                 }
1049
1050                 [Test]
1051                 public void Bug419224Test () 
1052                 {
1053                         cmd = new OdbcCommand ("DROP TABLE IF EXISTS odbc_test");
1054                         cmd.Connection = conn;
1055                         cmd.ExecuteNonQuery ();
1056
1057                         cmd = new OdbcCommand ("CREATE TABLE odbc_test (id_test INTEGER NOT NULL, payload TINYBLOB NOT NULL)");
1058                         cmd.Connection = conn;
1059                         cmd.ExecuteNonQuery ();
1060
1061                         cmd = new OdbcCommand ("INSERT INTO odbc_test (id_test, payload) VALUES (1, 'test for bug419224')");
1062                         cmd.Connection = conn;
1063                         cmd.ExecuteNonQuery ();
1064
1065                         OdbcDataAdapter adaptador = new OdbcDataAdapter ();
1066                         DataSet lector = new DataSet ();
1067
1068                         adaptador.SelectCommand = new OdbcCommand ("SELECT * FROM odbc_test WHERE id_test=1", (OdbcConnection) conn);
1069                         adaptador.Fill (lector);
1070                         var payload = (byte[])lector.Tables[0].Rows[0]["payload"];
1071                         Assert.AreEqual ("test for bug419224", Encoding.UTF8.GetString(payload));
1072
1073                         OdbcDataReader newRdr = cmd.ExecuteReader();
1074
1075                         // tinyblob column index:
1076                         int TinyblobIdx = 1;
1077
1078                         bool read = newRdr.Read();
1079
1080                         if (read)
1081                         {
1082                                         bool ret = newRdr.IsDBNull(TinyblobIdx); 
1083                                 Assert.AreEqual (ret, false);
1084                         }
1085                 }
1086
1087                 static void DoExecuteNonQuery (OdbcConnection conn, string sql)
1088                 {
1089                         IDbCommand cmd = new OdbcCommand (sql, conn);
1090                         cmd.ExecuteNonQuery ();
1091                 }
1092
1093                 static void DoExecuteScalar (OdbcConnection conn, string sql)
1094                 {
1095                         IDbCommand cmd = new OdbcCommand (sql, conn);
1096                         cmd.ExecuteScalar ();
1097                 }
1098
1099                 static void AssertSchemaTableStructure (DataTable schemaTable, string prefix)
1100                 {
1101                         object [] [] columns = {
1102                                 new object [] { "ColumnName", typeof (string) },
1103                                 new object [] { "ColumnOrdinal", typeof (int) },
1104                                 new object [] { "ColumnSize", typeof (int) },
1105                                 new object [] { "NumericPrecision", typeof (short) },
1106                                 new object [] { "NumericScale", typeof (short) },
1107                                 new object [] { "DataType", typeof (object) },
1108                                 new object [] { "ProviderType", typeof (int) },
1109                                 new object [] { "IsLong", typeof (bool) },
1110                                 new object [] { "AllowDBNull", typeof (bool) },
1111                                 new object [] { "IsReadOnly", typeof (bool) },
1112                                 new object [] { "IsRowVersion", typeof (bool) },
1113                                 new object [] { "IsUnique", typeof (bool) },
1114                                 new object [] { "IsKey", typeof (bool) },
1115                                 new object [] { "IsAutoIncrement", typeof (bool) },
1116                                 new object [] { "BaseSchemaName", typeof (string) },
1117                                 new object [] { "BaseCatalogName", typeof (string) },
1118                                 new object [] { "BaseTableName", typeof (string) },
1119                                 new object [] { "BaseColumnName", typeof (string) }
1120                                 };
1121
1122                         Assert.AreEqual (columns.Length, schemaTable.Columns.Count, prefix);
1123
1124                         for (int i = 0; i < columns.Length; i++) {
1125                                 DataColumn col = schemaTable.Columns [i];
1126                                 Assert.IsTrue (col.AllowDBNull, prefix + "AllowDBNull (" + i + ")");
1127                                 Assert.AreEqual (columns [i] [0], col.ColumnName, prefix + "ColumnName (" + i + ")");
1128                                 Assert.AreEqual (columns [i] [1], col.DataType, prefix + "DataType (" + i + ")");
1129                         }
1130                 }
1131
1132                 static bool RunningOnMono {
1133                         get {
1134                                 return (Type.GetType ("System.MonoType", false) != null);
1135                         }
1136                 }
1137         }
1138 }
1139
1140 #endif