copied mono-api-diff.cs from mono-2-2 branch so new patch can be applied and history...
[mono.git] / mcs / class / System.Data / Test / ProviderTests / System.Data.SqlClient / SqlDataReaderTest.cs
1 //
2 // SqlDataReaderTest.cs - NUnit Test Cases for testing the
3 //                          SqlDataReader class
4 // Author:
5 //      Umadevi S (sumadevi@novell.com)
6 //      Kornél Pál <http://www.kornelpal.hu/>
7 //      Sureshkumar T (tsureshkumar@novell.com)
8 //      Senganal T (tsenganal@novell.com)
9 //      Veerapuram Varadhan (vvaradhan@novell.com)
10 //
11 // Copyright (c) 2004 Novell Inc., and the individuals listed
12 // on the ChangeLog entries.
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 //
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 //
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 //
33
34 using System;
35 using System.Data;
36 using System.Data.Common;
37 using System.Data.SqlClient;
38 using System.Data.SqlTypes;
39 using System.Globalization;
40 using System.Text;
41
42 using NUnit.Framework;
43
44 namespace MonoTests.System.Data.SqlClient
45 {
46         [TestFixture]
47         [Category ("sqlserver")]
48         public class SqlDataReaderTest
49         {
50                 static byte [] long_bytes = new byte [] {
51                         0x00, 0x66, 0x06, 0x66, 0x97, 0x00, 0x66, 0x06, 0x66,
52                         0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
53                         0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
54                         0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
55                         0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
56                         0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
57                         0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
58                         0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
59                         0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
60                         0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
61                         0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
62                         0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
63                         0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
64                         0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
65                         0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
66                         0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
67                         0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
68                         0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
69                         0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
70                         0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
71                         0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
72                         0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
73                         0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
74                         0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
75                         0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
76                         0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66,
77                         0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06,
78                         0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06, 0x66,
79                         0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97, 0x06,
80                         0x66, 0x06, 0x66, 0x97, 0x06, 0x66, 0x06, 0x66, 0x97,
81                         0x06, 0x66, 0x06, 0x66, 0x98};
82
83                 SqlConnection conn = null;
84                 SqlCommand cmd = null;
85                 SqlDataReader reader = null;
86                 String query = "Select type_{0},type_{2},convert({1},null) from numeric_family where id=1";
87                 DataSet sqlDataset = null;
88                 EngineConfig engine;
89
90                 DataTable numericDataTable =null;
91                 DataTable stringDataTable =null;
92                 DataTable binaryDataTable =null;
93                 DataTable datetimeDataTable =null;
94
95                 DataRow numericRow = null; 
96                 DataRow stringRow = null; 
97                 DataRow binaryRow = null; 
98                 DataRow datetimeRow = null; 
99
100                 [TestFixtureSetUp]
101                 public void init ()
102                 {
103                         conn = new SqlConnection (ConnectionManager.Singleton.ConnectionString);
104                         cmd = conn.CreateCommand ();
105                         
106                         sqlDataset = (new DataProvider()).GetDataSet ();
107
108                         numericDataTable = sqlDataset.Tables["numeric_family"];
109                         stringDataTable = sqlDataset.Tables["string_family"];
110                         binaryDataTable = sqlDataset.Tables["binary_family"];
111                         datetimeDataTable = sqlDataset.Tables["datetime_family"];
112
113                         numericRow = numericDataTable.Select ("id=1")[0];
114                         stringRow = stringDataTable.Select ("id=1")[0];
115                         binaryRow = binaryDataTable.Select ("id=1")[0];
116                         datetimeRow = datetimeDataTable.Select ("id=1")[0];
117
118                 }
119
120                 [SetUp]
121                 public void Setup ()
122                 {
123                         conn.Open ();
124                         engine = ConnectionManager.Singleton.Engine;
125                 }
126
127                 [TearDown]
128                 public void TearDown ()
129                 {
130                         if (reader != null)
131                                 reader.Close ();
132
133                         conn.Close ();
134                 }
135
136                 [Test]
137                 public void ReadEmptyNTextFieldTest ()
138                 {
139                         try {
140                                 DBHelper.ExecuteNonQuery (conn, "create table #tmp_monotest (name ntext)");
141                                 DBHelper.ExecuteNonQuery (conn, "insert into #tmp_monotest values ('')");
142                                 
143                                 SqlCommand cmd = (SqlCommand) conn.CreateCommand ();
144                                 cmd.CommandText = "select * from #tmp_monotest";
145                                 SqlDataReader dr = cmd.ExecuteReader ();
146                                 if (dr.Read()) {
147                                         Assert.AreEqual("System.String",dr["NAME"].GetType().FullName);
148                                 }
149                                 Assert.AreEqual (false, dr.Read (), "#2");
150                         } finally {
151                                 ConnectionManager.Singleton.CloseConnection ();
152                         }
153                 }
154
155                 [Test]
156                 public void ReadBigIntTest()
157                 {
158                         if (ClientVersion <= 7)
159                                 Assert.Ignore ("BigInt data type is not supported.");
160
161                         try {
162                                 string query = "SELECT CAST(548967465189498 AS bigint) AS Value";
163                                 SqlCommand cmd = new SqlCommand();
164                                 cmd.Connection = conn;
165                                 cmd.CommandText = query;
166                                 SqlDataReader r = cmd.ExecuteReader();
167                                 using (r) {
168                                         Assert.AreEqual (true, r.Read(), "#1");
169                                         long id = r.GetInt64(0);
170                                         Assert.AreEqual(548967465189498, id, "#2");
171                                         id = r.GetSqlInt64(0).Value;
172                                         Assert.AreEqual(548967465189498, id, "#3");
173                                 }
174                         } finally {
175                                 ConnectionManager.Singleton.CloseConnection ();
176                         }
177                 }
178
179                 // This method just helps in Calling common tests among all the Get* Methods 
180                 // without replicating code 
181
182                 void CallGetMethod (string s, int i)
183                 {
184                         switch (s) {
185                         case "Boolean" : reader.GetBoolean (i) ; break; 
186                         case "SqlBoolean": reader.GetSqlBoolean (i); break;
187                         case "Int16" : reader.GetInt16 (i); break;
188                         case "SqlInt16" : reader.GetSqlInt16 (i); break;
189                         case "Int32" : reader.GetInt32 (i);break;
190                         case "SqlInt32" : reader.GetSqlInt32(i);break;
191                         case "Int64" : reader.GetInt64 (i);break;
192                         case "SqlInt64" : reader.GetSqlInt64(i); break;
193                         case "Decimal" : reader.GetDecimal(i);break;
194                         case "SqlDecimal" : reader.GetSqlDecimal (i);break;
195                         case "SqlMoney" : reader.GetSqlMoney (i);break;
196                         case "Float" : reader.GetFloat (i);break;
197                         case "SqlSingle" : reader.GetSqlSingle(i);break;
198                         case "Double" : reader.GetDouble (i);break;
199                         case "SqlDouble" : reader.GetSqlDouble(i);break;
200                         case "Guid" : reader.GetGuid(i);break;
201                         case "SqlGuid" : reader.GetSqlGuid(i);break;
202                         case "String" : reader.GetString(i);break;
203                         case "SqlString" : reader.GetSqlString(i);break;
204                         case "Char" : reader.GetChar(i);break;
205                         case "Byte" : reader.GetByte (i);break;
206                         case "SqlByte" : reader.GetSqlByte(i); break;
207                         case "DateTime" : reader.GetDateTime(i); break;
208                         case "SqlDateTime" : reader.GetSqlDateTime(i); break;
209                         case "SqlBinary" : reader.GetSqlBinary(i); break;
210                         default : Console.WriteLine ("OOOOPSSSSSS {0}",s);break;
211                         }
212                 }
213
214                 // This method just helps in Calling common tests among all the Get* Methods 
215                 // without replicating code 
216                 void GetMethodTests (string s)
217                 {
218
219                         try {
220                                 CallGetMethod (s, 1);
221                                 Assert.Fail ("#1[Get"+s+"] InvalidCastException must be thrown");
222                         } catch (InvalidCastException e) {
223                                 Assert.AreEqual (typeof (InvalidCastException), e.GetType (),
224                                         "#2[Get"+s+"] Incorrect Exception : " + e);
225                         }
226                 
227                         // GetSql* Methods do not throw SqlNullValueException   
228                         // So, Testimg only for Get* Methods 
229                         if (!s.StartsWith("Sql")) {
230                                 try {
231                                         CallGetMethod (s, 2);
232                                         Assert.Fail ("#3[Get"+s+"] Exception must be thrown");
233                                 } catch (SqlNullValueException e) {
234                                         Assert.AreEqual (typeof (SqlNullValueException), e.GetType (),
235                                                 "#4[Get"+s+"] Incorrect Exception : " + e);
236                                 }
237                         }
238
239                         try {
240                                 CallGetMethod (s, 3);
241                                 Assert.Fail ("#5[Get"+s+"] IndexOutOfRangeException must be thrown");
242                         } catch (IndexOutOfRangeException e) {
243                                 Assert.AreEqual (typeof (IndexOutOfRangeException), e.GetType (),
244                                         "#6[Get"+s+"] Incorrect Exception : " + e);
245                         }
246                 }
247
248                 [Test]
249                 public void GetBooleanTest ()
250                 {
251                         cmd.CommandText = string.Format (query, "bit", "bit", "int");
252                         reader = cmd.ExecuteReader ();
253                         reader.Read ();
254                         // Test for standard exceptions 
255                         GetMethodTests("Boolean");
256
257                         // Test if data is returned correctly
258                         Assert.AreEqual (numericRow ["type_bit"], reader.GetBoolean (0),
259                                                 "#2 DataValidation Failed");
260                         
261                         // Test for standard exceptions 
262                         GetMethodTests("SqlBoolean");
263
264                         // Test if data is returned correctly
265                         Assert.AreEqual (numericRow["type_bit"], reader.GetSqlBoolean(0).Value,
266                                 "#4 DataValidation Failed");    
267                         reader.Close ();
268                 }
269
270                 [Test]
271                 public void GetByteTest ()
272                 {
273                         cmd.CommandText = string.Format (query, "tinyint", "tinyint", "int");
274                         reader = cmd.ExecuteReader ();
275                         reader.Read ();
276                         // Test for standard exceptions 
277                         GetMethodTests("Byte");
278
279                         // Test if data is returned correctly
280                         Assert.AreEqual (numericRow["type_tinyint"], reader.GetByte(0),
281                                                 "#2 DataValidation Failed");
282
283                         // Test for standard exceptions 
284                         GetMethodTests("SqlByte");
285
286                         // Test if data is returned correctly
287                         Assert.AreEqual (numericRow["type_tinyint"], reader.GetSqlByte(0).Value,
288                                                 "#4 DataValidation Failed");
289                         reader.Close ();
290                 }
291
292                 [Test]
293                 public void GetInt16Test ()
294                 {
295                         cmd.CommandText = string.Format (query, "smallint", "smallint", "int");
296                         reader = cmd.ExecuteReader();
297                         reader.Read ();
298                         // Test for standard exceptions 
299                         GetMethodTests("Int16");
300
301                         // Test if data is returned correctly
302                         Assert.AreEqual (numericRow["type_smallint"], reader.GetInt16(0),
303                                                 "#2 DataValidation Failed");
304
305                         // Test for standard exceptions 
306                         GetMethodTests("SqlInt16");
307
308                         // Test if data is returned correctly
309                         Assert.AreEqual (numericRow["type_smallint"], reader.GetSqlInt16(0).Value,
310                                                 "#4 DataValidation Failed");
311                         reader.Close ();
312                 }
313
314                 [Test]
315                 public void GetInt32Test ()
316                 {
317                         if (ClientVersion == 7)
318                                 cmd.CommandText = string.Format (query, "int", "int", "decimal1");
319                         else
320                                 cmd.CommandText = string.Format (query, "int", "int", "bigint");
321
322                         reader = cmd.ExecuteReader ();
323                         reader.Read ();
324                         // Test for standard exceptions 
325                         GetMethodTests("Int32");
326
327                         // Test if data is returned correctly
328                         Assert.AreEqual (numericRow["type_int"], reader.GetInt32(0),
329                                 "#2 DataValidation Failed");
330
331                         // Test for standard exceptions 
332                         GetMethodTests("SqlInt32");
333
334                         // Test if data is returned correctly
335                         Assert.AreEqual (numericRow["type_int"], reader.GetSqlInt32(0).Value,
336                                 "#4 DataValidation Failed");
337                         reader.Close ();
338                 }
339
340                 [Test]
341                 public void GetInt64Test ()
342                 {
343                         if (ClientVersion == 7)
344                                 Assert.Ignore ("BigInt data type is not supported.");
345
346                         cmd.CommandText = string.Format (query, "bigint", "bigint", "int");
347                         reader = cmd.ExecuteReader ();
348                         reader.Read ();
349
350                         object value;
351
352                         // Test for standard exceptions
353                         GetMethodTests("Int64");
354
355                         // Test if data is returned correctly
356                         value = reader.GetInt64 (0);
357                         Assert.AreEqual (numericRow ["type_bigint"], value, "#A");
358
359                         // Test for standard exceptions
360                         GetMethodTests("SqlInt64");
361
362                         // Test if data is returned correctly
363                         value = reader.GetSqlInt64 (0);
364                         Assert.IsNotNull (value, "#B1");
365                         Assert.AreEqual (typeof (SqlInt64), value.GetType (), "#B2");
366                         SqlInt64 sqlValue = (SqlInt64) value;
367                         Assert.IsFalse (sqlValue.IsNull, "#B3");
368                         Assert.AreEqual (numericRow ["type_bigint"], sqlValue.Value, "#B4");
369
370                         value = reader.GetValue (0);
371                         Assert.IsNotNull (value, "#C1");
372                         Assert.AreEqual (typeof (long), value.GetType (), "#C2");
373                         Assert.AreEqual (numericRow ["type_bigint"], value, "#C3");
374
375                         reader.Close ();
376                 }
377
378                 [Test]
379                 public void GetDecimalTest ()
380                 {
381                         cmd.CommandText = string.Format (query, "decimal1", "decimal", "int");
382                         reader = cmd.ExecuteReader ();
383                         reader.Read ();
384                         // Test for standard exceptions 
385                         GetMethodTests("Decimal");
386
387                         // Test if data is returned correctly
388                         Assert.AreEqual (numericRow["type_decimal1"], reader.GetDecimal(0),
389                                 "#2 DataValidation Failed");
390
391                         // Test for standard exceptions 
392                         GetMethodTests("SqlDecimal");
393
394                         // Test if data is returned correctly
395                         Assert.AreEqual (numericRow["type_decimal1"], reader.GetSqlDecimal(0).Value,
396                                 "#4 DataValidation Failed");
397                         reader.Close ();
398                 }
399
400                 [Test]
401                 public void GetSqlMoneyTest ()
402                 {
403                         cmd.CommandText = string.Format (query, "money", "money", "int");
404                         reader = cmd.ExecuteReader ();
405                         reader.Read ();
406                         // Test for standard exceptions 
407                         GetMethodTests("SqlMoney");
408
409                         // Test if data is returned correctly
410                         Assert.AreEqual (numericRow["type_money"], reader.GetSqlMoney(0).Value,
411                                 "#2 DataValidation Failed");
412                         reader.Close ();
413                 }
414
415                 [Test]
416                 public void GetFloatTest ()
417                 {
418                         cmd.CommandText = "select type_float,type_double,convert(real,null)";
419                         cmd.CommandText += "from numeric_family where id=1"; 
420                         reader = cmd.ExecuteReader ();
421                         reader.Read ();
422                         // Test for standard exceptions 
423                         GetMethodTests("Float");
424
425                         // Test if data is returned correctly
426                         Assert.AreEqual (numericRow["type_float"], reader.GetFloat(0),
427                                 "#2 DataValidation Failed");
428
429                         // Test for standard exceptions 
430                         GetMethodTests("SqlSingle");
431
432                         // Test if data is returned correctly
433                         Assert.AreEqual (numericRow["type_float"], reader.GetSqlSingle(0).Value,
434                                 "#2 DataValidation Failed");
435                         reader.Close ();
436                 } 
437
438                 [Test]
439                 public void GetDoubleTest ()
440                 {
441                         cmd.CommandText = "select type_double,type_float,convert(float,null)";
442                         cmd.CommandText += " from numeric_family where id=1"; 
443                         reader = cmd.ExecuteReader ();
444                         reader.Read ();
445                         // Test for standard exceptions 
446                         GetMethodTests("Double");
447
448                         // Test if data is returned correctly
449                         Assert.AreEqual (numericRow["type_double"], reader.GetDouble(0),
450                                 "#2 DataValidation Failed");
451
452                         // Test for standard exceptions 
453                         GetMethodTests("SqlDouble");
454
455                         // Test if data is returned correctly
456                         Assert.AreEqual (numericRow["type_double"], reader.GetSqlDouble(0).Value,
457                                 "#4 DataValidation Failed");
458                         reader.Close ();
459                 }
460
461                 [Test]
462                 public void GetBytesTest ()
463                 {
464                         cmd.CommandText = "Select type_text,type_ntext,convert(text,null) ";
465                         cmd.CommandText += "from string_family where id=1";
466                         reader = cmd.ExecuteReader ();
467                         reader.Read ();
468 #if NET_2_0
469                         try {
470                                 long totalsize = reader.GetBytes (0, 0, null, 0, 0);
471                                 Assert.AreEqual (4, totalsize, "#1");
472                         } finally {
473                                 reader.Close ();
474                         }
475 #else
476                         try {
477                                 reader.GetBytes (0, 0, null, 0, 0);
478                                 Assert.Fail ("#1");
479                         } catch (InvalidCastException ex) {
480                                 Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#2");
481                                 Assert.IsNull (ex.InnerException, "#3");
482                                 Assert.AreEqual ((new InvalidCastException ()).Message, ex.Message, "#4");
483                         } finally {
484                                 reader.Close ();
485                         }
486 #endif
487                         
488                         byte[] asciiArray = (new ASCIIEncoding ()).GetBytes ("text");
489                         byte[] unicodeArray = (new UnicodeEncoding ()).GetBytes ("nt\u092d\u093ext");
490                         byte[] buffer = null ;
491                         long size = 0; 
492
493                         reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess);
494                         reader.Read ();
495                         size = reader.GetBytes (0,0,null,0,0);
496                         Assert.AreEqual (asciiArray.Length, size, "#3 Data Incorrect");
497
498                         buffer = new byte[size];
499                         size = reader.GetBytes (0,0,buffer,0,(int)size);
500                         for (int i=0;i<size; i++)
501                                 Assert.AreEqual (asciiArray[i], buffer[i], "#4 Data Incorrect");
502
503                         size = reader.GetBytes (1, 0, null, 0, 0);
504                         Assert.AreEqual (unicodeArray.Length, size, "#5 Data Incorrect");
505                         buffer = new byte[size];
506                         size = reader.GetBytes (1,0,buffer,0,(int)size);
507                         for (int i=0;i<size; i++)
508                                 Assert.AreEqual (unicodeArray[i], buffer[i], "#6 Data Incorrect");
509                         
510                         // Test if msdotnet behavior s followed when null value 
511                         // is read using GetBytes 
512 #if NET_2_0
513                         try {
514                                 reader.GetBytes (2, 0, null, 0, 0);
515                                 Assert.Fail ("#7");
516                         } catch (SqlNullValueException) {
517                         }
518
519                         try {
520                                 reader.GetBytes (2, 0, buffer, 0, 10);
521                                 Assert.Fail ("#8");
522                         } catch (SqlNullValueException) {
523                         }
524 #else
525                         Assert.AreEqual (0, reader.GetBytes (2, 0, null, 0, 0), "#7");
526                         Assert.AreEqual (0, reader.GetBytes (2, 0, buffer, 0, 10), "#8");
527 #endif
528                         reader.Close ();
529                         // do i need to test for image/binary values also ??? 
530                 }
531
532                 [Test]
533                 public void GetBytes_BufferIndex_Negative ()
534                 {
535                         IDbConnection conn = ConnectionManager.Singleton.Connection;
536                         conn.Open ();
537
538                         try {
539                                 IDbCommand cmd = conn.CreateCommand ();
540                                 cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
541
542                                 using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
543                                         Assert.IsTrue (reader.Read (), "#1");
544
545                                         long size = reader.GetBytes (0, 0, null, -1, 0);
546                                         Assert.AreEqual (5, size);
547                                 }
548                         } finally {
549                                 ConnectionManager.Singleton.CloseConnection ();
550                         }
551                 }
552
553                 [Test]
554                 public void GetBytes_DataIndex_Negative ()
555                 {
556                         IDbConnection conn = ConnectionManager.Singleton.Connection;
557                         conn.Open ();
558
559                         try {
560                                 IDbCommand cmd = conn.CreateCommand ();
561                                 cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
562
563                                 using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
564                                         Assert.IsTrue (reader.Read ());
565
566                                         long totalsize = reader.GetBytes (0, -1L, null, 0, 0);
567                                         Assert.AreEqual (5, totalsize, "#A");
568                                 }
569
570                                 using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
571                                         Assert.IsTrue (reader.Read ());
572
573                                         byte [] val = new byte [5];
574                                         try {
575                                                 reader.GetBytes (0, -1L, val, 0, 3);
576                                                 Assert.Fail ("#B1");
577                                         } catch (InvalidOperationException ex) {
578                                                 // Invalid GetBytes attempt at dataIndex '-1'
579                                                 // With CommandBehavior.SequentialAccess,
580                                                 // you may only read from dataIndex '0'
581                                                 // or greater.
582                                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
583                                                 Assert.IsNull (ex.InnerException, "#B3");
584                                                 Assert.IsNotNull (ex.Message, "#B4");
585                                                 Assert.IsTrue (ex.Message.IndexOf ("dataIndex") != -1, "#B5:" + ex.Message);
586                                         }
587                                 }
588
589                                 using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult)) {
590                                         Assert.IsTrue (reader.Read ());
591
592 #if NET_2_0
593                                         try {
594                                                 reader.GetBytes (0, -1L, null, 0, 0);
595                                                 Assert.Fail ("#C1");
596                                         } catch (InvalidOperationException ex) {
597                                                 // Invalid value for argument 'dataIndex'.
598                                                 // The value must be greater than or equal to 0
599                                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
600                                                 Assert.IsNull (ex.InnerException, "#C3");
601                                                 Assert.IsNotNull (ex.Message, "#C4");
602                                                 Assert.IsTrue (ex.Message.IndexOf ("'dataIndex'") != -1, "#C5:" + ex.Message);
603                                         }
604
605                                         byte [] val = new byte [3];
606                                         try {
607                                                 reader.GetBytes (0, -1L, val, 0, 3);
608                                                 Assert.Fail ("#D1");
609                                         } catch (InvalidOperationException ex) {
610                                                 // Invalid value for argument 'dataIndex'.
611                                                 // The value must be greater than or equal to 0
612                                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
613                                                 Assert.IsNull (ex.InnerException, "#D3");
614                                                 Assert.IsNotNull (ex.Message, "#D4");
615                                                 Assert.IsTrue (ex.Message.IndexOf ("'dataIndex'") != -1, "#D5:" + ex.Message);
616                                         }
617 #else
618                                         long totalsize = reader.GetBytes (0, -1L, null, 0, 0);
619                                         Assert.AreEqual (5, totalsize, "#C");
620
621                                         byte [] val = new byte [totalsize];
622                                         long read = reader.GetBytes (0, -1L, val, 0, 3);
623                                         Assert.AreEqual (0, read, "#D");
624 #endif
625                                 }
626
627                                 using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult)) {
628                                         Assert.IsTrue (reader.Read ());
629
630                                         byte [] val = new byte [5];
631 #if NET_2_0
632                                         try {
633                                                 reader.GetBytes (0, -1L, val, 0, 3);
634                                                 Assert.Fail ("#E1");
635                                         } catch (InvalidOperationException ex) {
636                                                 // Invalid value for argument 'dataIndex'.
637                                                 // The value must be greater than or equal to 0
638                                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
639                                                 Assert.IsNull (ex.InnerException, "#E3");
640                                                 Assert.IsNotNull (ex.Message, "#E4");
641                                                 Assert.IsTrue (ex.Message.IndexOf ("'dataIndex'") != -1, "#E5:" + ex.Message);
642                                         }
643 #else
644                                         long read = reader.GetBytes (0, -1L, val, 0, 3);
645                                         Assert.AreEqual (0, read, "#E");
646 #endif
647                                 }
648
649                                 using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
650                                         Assert.IsTrue (reader.Read ());
651
652                                         long totalsize = reader.GetBytes (0, -1L, null, 5, 8);
653                                         Assert.AreEqual (5, totalsize, "#F");
654                                 }
655
656                                 using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult)) {
657                                         Assert.IsTrue (reader.Read ());
658
659 #if NET_2_0
660                                         try {
661                                                 reader.GetBytes (0, -1L, null, 4, 8);
662                                                 Assert.Fail ("#G1");
663                                         } catch (InvalidOperationException ex) {
664                                                 // Invalid value for argument 'dataIndex'.
665                                                 // The value must be greater than or equal to 0
666                                                 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#G2");
667                                                 Assert.IsNull (ex.InnerException, "#G3");
668                                                 Assert.IsNotNull (ex.Message, "#G4");
669                                                 Assert.IsTrue (ex.Message.IndexOf ("'dataIndex'") != -1, "#G5:" + ex.Message);
670                                         }
671 #else
672                                         long totalsize = reader.GetBytes (0, -1L, null, 4, 8);
673                                         Assert.AreEqual (5, totalsize, "#G");
674 #endif
675                                 }
676                         } finally {
677                                 ConnectionManager.Singleton.CloseConnection ();
678                         }
679                 }
680
681                 [Test]
682                 public void GetBytes_Length_Negative ()
683                 {
684                         IDbConnection conn = ConnectionManager.Singleton.Connection;
685                         conn.Open ();
686
687                         try {
688                                 IDbCommand cmd = conn.CreateCommand ();
689                                 cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
690
691                                 using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
692                                         Assert.IsTrue (reader.Read (), "#A1");
693
694                                         long size = reader.GetBytes (0, 0, null, 0, -1);
695                                         Assert.AreEqual (5, size, "#A2");
696                                 }
697
698                                 using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult)) {
699                                         Assert.IsTrue (reader.Read (), "#B1");
700
701                                         long size = reader.GetBytes (0, 0, null, 0, -1);
702                                         Assert.AreEqual (5, size, "#B2");
703                                 }
704                         } finally {
705                                 ConnectionManager.Singleton.CloseConnection ();
706                         }
707                 }
708
709                 [Test]
710                 public void GetBytes_Buffer_TooSmall ()
711                 {
712                         cmd = conn.CreateCommand ();
713                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 2";
714
715                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult | CommandBehavior.SequentialAccess)) {
716                                 Assert.IsTrue (reader.Read ());
717
718                                 long totalsize = reader.GetBytes (0, 0, null, 0, 0);
719                                 byte [] val = new byte [totalsize -1];
720
721                                 try {
722                                         reader.GetBytes (0, 0, val, 0, (int) totalsize);
723                                         Assert.Fail ("#A1");
724 #if NET_2_0
725                                 } catch (IndexOutOfRangeException ex) {
726                                         // Buffer offset '0' plus the bytes available
727                                         // '275' is greater than the length of the
728                                         // passed in buffer
729                                         Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#A2");
730                                         Assert.IsNull (ex.InnerException, "#A3");
731                                         Assert.IsNotNull (ex.Message, "#A4");
732                                         Assert.IsTrue (ex.Message.IndexOf ("'0'") != -1, "#A5:" + ex.Message);
733                                         Assert.IsTrue (ex.Message.IndexOf ("'" + totalsize + "'") != -1, "#A6:" + ex.Message);
734                                 }
735 #else
736                                 } catch (ArgumentException ex) {
737                                         // Destination array was not long enough.
738                                         // Check destIndex and length, and the
739                                         // array's lower bounds
740                                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
741                                         Assert.IsNull (ex.InnerException, "#A3");
742                                         Assert.IsNotNull (ex.Message, "#A4");
743                                         Assert.IsNull (ex.ParamName, "#A5");
744                                 }
745 #endif
746                         }
747
748                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult | CommandBehavior.SequentialAccess)) {
749                                 Assert.IsTrue (reader.Read ());
750
751                                 long totalsize = reader.GetBytes (0, 0, null, 0, 0);
752                                 byte [] val = new byte [totalsize];
753
754                                 try {
755                                         reader.GetBytes (0, 0, val, 1, (int) totalsize);
756                                         Assert.Fail ("#B1");
757 #if NET_2_0
758                                 } catch (IndexOutOfRangeException ex) {
759                                         // Buffer offset '1' plus the bytes available
760                                         // '275' is greater than the length of the
761                                         // passed in buffer
762                                         Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#B2");
763                                         Assert.IsNull (ex.InnerException, "#B3");
764                                         Assert.IsNotNull (ex.Message, "#B4");
765                                         Assert.IsTrue (ex.Message.IndexOf ("'1'") != -1, "#B5:" + ex.Message);
766                                         Assert.IsTrue (ex.Message.IndexOf ("'" + totalsize + "'") != -1, "#B6:" + ex.Message);
767                                 }
768 #else
769                                 } catch (ArgumentException ex) {
770                                         // Destination array was not long enough.
771                                         // Check destIndex and length, and the
772                                         // array's lower bounds
773                                         Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
774                                         Assert.IsNull (ex.InnerException, "#B3");
775                                         Assert.IsNotNull (ex.Message, "#B4");
776                                         Assert.IsNull (ex.ParamName, "#B5");
777                                 }
778 #endif
779                         }
780
781                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult | CommandBehavior.SequentialAccess)) {
782                                 Assert.IsTrue (reader.Read ());
783
784                                 long totalsize = reader.GetBytes (0, 0, null, 0, 0);
785                                 byte [] val = new byte [totalsize];
786
787 #if NET_2_0
788                                 try {
789                                         reader.GetBytes (0, 0, val, 0, (int) (totalsize + 1));
790                                         Assert.Fail ("#C1");
791                                 } catch (IndexOutOfRangeException ex) {
792                                         // Buffer offset '0' plus the bytes available
793                                         // '277' is greater than the length of the
794                                         // passed in buffer
795                                         Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#C2");
796                                         Assert.IsNull (ex.InnerException, "#C3");
797                                         Assert.IsNotNull (ex.Message, "#C4");
798                                         Assert.IsTrue (ex.Message.IndexOf ("'0'") != -1, "#C5:" + ex.Message);
799                                         Assert.IsTrue (ex.Message.IndexOf ("'" + (totalsize + 1) + "'") != -1, "#C6:" + ex.Message);
800                                 }
801 #else
802                                 long ret = reader.GetBytes (0, 0, val, 0, (int) (totalsize + 1));
803                                 Assert.AreEqual (totalsize, ret, "#C1");
804 #endif
805                         }
806                 }
807
808                 [Test]
809                 public void GetBytes ()
810                 {
811                         cmd = conn.CreateCommand ();
812                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 2";
813
814                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SingleResult)) {
815                                 Assert.IsTrue (reader.Read (), "#H1");
816
817                                 long totalsize = reader.GetBytes (0, 0, null, 0, 0);
818
819                                 byte [] val = new byte [totalsize];
820                                 int offset = 0;
821                                 long ret = 0;
822                                 long count = 0;
823
824                                 do {
825                                         ret = reader.GetBytes (0, offset, val, offset, 50);
826                                         offset += (int) ret;
827                                         count += ret;
828                                 } while (count < totalsize);
829
830                                 Assert.AreEqual (long_bytes.Length, count, "#H2");
831                                 Assert.AreEqual (long_bytes, val, "#H3");
832                         }
833                 }
834
835                 [Test]
836                 public void GetBytes_Type_Binary ()
837                 {
838                         cmd.CommandText = "Select type_binary, type_varbinary, " +
839                                 "type_blob from binary_family where id = 1";
840                         reader = cmd.ExecuteReader ();
841                         reader.Read ();
842                         byte[] binary = (byte[])reader.GetValue (0);
843                         byte[] varbinary = (byte[])reader.GetValue (1);
844                         byte[] image = (byte[])reader.GetValue (2);
845                         reader.Close ();
846
847                         reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess);
848                         reader.Read ();
849                         int len = 0;
850                         byte[] arr ;
851                         len = (int)reader.GetBytes (0,0,null,0,0);
852                         Assert.AreEqual (binary.Length, len, "#1");
853                         arr = new byte [len];
854                         reader.GetBytes (0,0,arr,0,len);
855                         for (int i=0; i<len; ++i)
856                                 Assert.AreEqual (binary[i], arr[i], "#2");
857
858
859                         len = (int)reader.GetBytes (1,0,null,0,0);
860                         Assert.AreEqual (varbinary.Length, len, "#1");
861                         arr = new byte [len];
862                         reader.GetBytes (1,0,arr,0,len);
863                         for (int i=0; i<len; ++i)
864                                 Assert.AreEqual (varbinary[i], arr[i], "#2");
865
866                         len = (int)reader.GetBytes (2,0,null,0,0);
867                         Assert.AreEqual (image.Length, len, "#1");
868                         arr = new byte [len];
869                         reader.GetBytes (2,0,arr,0,len);
870                         for (int i=0; i<len; ++i)
871                                 Assert.AreEqual (image[i], arr[i], "#2");
872
873                         reader.Close ();
874
875                         cmd.CommandText = "Select type_binary,type_varbinary,type_blob ";
876                         cmd.CommandText += "from binary_family where id=1";
877                 
878                         reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess);
879                         reader.Read ();
880                 
881                         len  = (int)reader.GetBytes (0,0,null,0,0);
882                         arr = new byte [100];
883                         for (int i=0; i<len; ++i) {
884                                 Assert.AreEqual (len-i, reader.GetBytes (0, i, null, 0, 0), "#1_"+i);
885                                 Assert.AreEqual (1, reader.GetBytes (0, i, arr, 0, 1), "#2_"+i);
886                                 Assert.AreEqual (binary [i], arr [0], "#3_"+i);
887                         }
888                         Assert.AreEqual (0, reader.GetBytes (0, len+10, null, 0, 0));
889                         reader.Close ();
890                 }
891
892                 [Test]
893                 public void GetBytes_Type_DateTime ()
894                 {
895                         cmd.CommandText = "SELECT type_datetime FROM datetime_family where id = 1";
896
897                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
898                                 Assert.IsTrue (reader.Read ());
899
900                                 try {
901                                         reader.GetBytes (0, 0, null, 0, 0);
902                                         Assert.Fail ("#A1");
903                                 } catch (InvalidCastException ex) {
904                                         // Invalid attempt to GetBytes on column
905                                         // 'type_datetime'.
906                                         // The GetBytes function can only be used
907                                         // on columns of type Text, NText, or Image
908                                         Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#A2");
909                                         Assert.IsNull (ex.InnerException, "#A3");
910                                         Assert.IsNotNull (ex.Message, "#A4");
911                                         Assert.IsTrue (ex.Message.IndexOf ("'type_datetime'") != -1, "#A5:" + ex.Message);
912                                         Assert.IsTrue (ex.Message.IndexOf ("GetBytes") != -1, "#A6:" + ex.Message);
913                                         Assert.IsTrue (ex.Message.IndexOf ("Text") != -1, "#A7:" + ex.Message);
914                                         Assert.IsTrue (ex.Message.IndexOf ("NText") != -1, "#A8:" + ex.Message);
915                                         Assert.IsTrue (ex.Message.IndexOf ("Image") != -1, "#A9:" + ex.Message);
916                                 }
917                         }
918
919                         using (IDataReader reader = cmd.ExecuteReader ()) {
920                                 Assert.IsTrue (reader.Read ());
921
922                                 try {
923                                         reader.GetBytes (0, 0, null, 0, 0);
924                                         Assert.Fail ("#B1");
925                                 } catch (InvalidCastException ex) {
926                                         // Invalid attempt to GetBytes on column
927                                         // 'type_datetime'.
928                                         // The GetBytes function can only be used
929                                         // on columns of type Text, NText, or Image
930                                         Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
931                                         Assert.IsNull (ex.InnerException, "#B3");
932                                         Assert.IsNotNull (ex.Message, "#B4");
933                                         Assert.IsTrue (ex.Message.IndexOf ("'type_datetime'") != -1, "#B5:" + ex.Message);
934                                         Assert.IsTrue (ex.Message.IndexOf ("GetBytes") != -1, "#B6:" + ex.Message);
935                                         Assert.IsTrue (ex.Message.IndexOf ("Text") != -1, "#B7:" + ex.Message);
936                                         Assert.IsTrue (ex.Message.IndexOf ("NText") != -1, "#B8:" + ex.Message);
937                                         Assert.IsTrue (ex.Message.IndexOf ("Image") != -1, "#B9:" + ex.Message);
938                                 }
939                         }
940
941                         cmd.CommandText = "SELECT type_datetime FROM datetime_family where id = 4";
942
943                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
944                                 Assert.IsTrue (reader.Read ());
945
946                                 try {
947                                         reader.GetBytes (0, 0, null, 0, 0);
948                                         Assert.Fail ("#C1");
949                                 } catch (InvalidCastException ex) {
950                                         // Invalid attempt to GetBytes on column
951                                         // 'type_datetime'.
952                                         // The GetBytes function can only be used
953                                         // on columns of type Text, NText, or Image
954                                         Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#C2");
955                                         Assert.IsNull (ex.InnerException, "#C3");
956                                         Assert.IsNotNull (ex.Message, "#C4");
957                                         Assert.IsTrue (ex.Message.IndexOf ("'type_datetime'") != -1, "#C5:" + ex.Message);
958                                         Assert.IsTrue (ex.Message.IndexOf ("GetBytes") != -1, "#C6:" + ex.Message);
959                                         Assert.IsTrue (ex.Message.IndexOf ("Text") != -1, "#C7:" + ex.Message);
960                                         Assert.IsTrue (ex.Message.IndexOf ("NText") != -1, "#C8:" + ex.Message);
961                                         Assert.IsTrue (ex.Message.IndexOf ("Image") != -1, "#C9:" + ex.Message);
962                                 }
963                         }
964
965                         using (IDataReader reader = cmd.ExecuteReader ()) {
966                                 Assert.IsTrue (reader.Read ());
967
968                                 try {
969                                         reader.GetBytes (0, 0, null, 0, 0);
970                                         Assert.Fail ("#D1");
971                                 } catch (InvalidCastException ex) {
972                                         // Invalid attempt to GetBytes on column
973                                         // 'type_datetime'.
974                                         // The GetBytes function can only be used
975                                         // on columns of type Text, NText, or Image
976                                         Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#D2");
977                                         Assert.IsNull (ex.InnerException, "#D3");
978                                         Assert.IsNotNull (ex.Message, "#D4");
979                                         Assert.IsTrue (ex.Message.IndexOf ("'type_datetime'") != -1, "#D5:" + ex.Message);
980                                         Assert.IsTrue (ex.Message.IndexOf ("GetBytes") != -1, "#D6:" + ex.Message);
981                                         Assert.IsTrue (ex.Message.IndexOf ("Text") != -1, "#D7:" + ex.Message);
982                                         Assert.IsTrue (ex.Message.IndexOf ("NText") != -1, "#D8:" + ex.Message);
983                                         Assert.IsTrue (ex.Message.IndexOf ("Image") != -1, "#D9:" + ex.Message);
984                                 }
985                         }
986                 }
987
988                 [Test]
989                 public void GetBytes_Type_Text ()
990                 {
991                         long len;
992                         byte [] buffer;
993                         byte [] expected;
994
995                         cmd.CommandText = "SELECT type_text FROM string_family order by id asc";
996
997                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
998                                 expected = new byte [] { 0x74, 0x65, 0x78,
999                                         0x74 };
1000
1001                                 Assert.IsTrue (reader.Read (), "#A1");
1002                                 len = reader.GetBytes (0, 0, null, 0, 0);
1003                                 Assert.AreEqual (4, len, "#A2");
1004                                 buffer = new byte [len];
1005                                 len = reader.GetBytes (0, 0, buffer, 0, (int) len);
1006                                 Assert.AreEqual (4, len, "#A3");
1007                                 Assert.AreEqual (expected, buffer, "#A4");
1008
1009                                 expected = new byte [] { 0x00, 0x00, 0x6f, 0x6e,
1010                                         0x67, 0x00 };
1011
1012                                 Assert.IsTrue (reader.Read (), "#B1");
1013                                 len = reader.GetBytes (0, 0, null, 0, 0);
1014                                 Assert.AreEqual (270, len, "#B2");
1015                                 buffer = new byte [6];
1016                                 len = reader.GetBytes (0, 1, buffer, 2, 3);
1017                                 Assert.AreEqual (3, len, "#B3");
1018                                 Assert.AreEqual (expected, buffer, "#B4");
1019
1020                                 expected = new byte [0];
1021
1022                                 Assert.IsTrue (reader.Read (), "#C1");
1023                                 len = reader.GetBytes (0, 0, null, 0, 0);
1024                                 Assert.AreEqual (0, len, "#C2");
1025                                 buffer = new byte [len];
1026                                 len = reader.GetBytes (0, 0, buffer, 0, 0);
1027                                 Assert.AreEqual (0, len, "#C3");
1028                                 Assert.AreEqual (expected, buffer, "#C4");
1029
1030                                 Assert.IsTrue (reader.Read (), "#D1");
1031 #if NET_2_0
1032                                 try {
1033                                         reader.GetBytes (0, 0, null, 0, 0);
1034                                         Assert.Fail ("#D2");
1035                                 } catch (SqlNullValueException) {
1036                                 }
1037 #else
1038                                 len = reader.GetBytes (0, 0, null, 0, 0);
1039                                 Assert.AreEqual (0, len, "#D2");
1040 #endif
1041                         }
1042
1043                         using (IDataReader reader = cmd.ExecuteReader ()) {
1044                                 expected = new byte [] { 0x74, 0x65, 0x78,
1045                                         0x74 };
1046
1047                                 Assert.IsTrue (reader.Read (), "#E1");
1048 #if NET_2_0
1049                                 len = reader.GetBytes (0, 0, null, 0, 0);
1050                                 Assert.AreEqual (4, len, "#E2");
1051                                 buffer = new byte [len];
1052                                 len = reader.GetBytes (0, 0, buffer, 0, (int) len);
1053                                 Assert.AreEqual (4, len, "#E3");
1054                                 Assert.AreEqual (expected, buffer, "#E4");
1055 #else
1056                                 try {
1057                                         reader.GetBytes (0, 0, null, 0, 0);
1058                                         Assert.Fail ("#E2");
1059                                 } catch (InvalidCastException ex) {
1060                                         Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#E3");
1061                                         Assert.IsNull (ex.InnerException, "#E4");
1062                                         Assert.AreEqual ((new InvalidCastException ()).Message, ex.Message, "#E5");
1063                                 }
1064 #endif
1065
1066                                 expected = new byte [] { 0x00, 0x00, 0x6f, 0x6e,
1067                                         0x67, 0x00 };
1068
1069                                 Assert.IsTrue (reader.Read (), "#F1");
1070 #if NET_2_0
1071                                 len = reader.GetBytes (0, 0, null, 0, 0);
1072                                 Assert.AreEqual (270, len, "#F2");
1073                                 buffer = new byte [6];
1074                                 len = reader.GetBytes (0, 1, buffer, 2, 3);
1075                                 Assert.AreEqual (3, len, "#F3");
1076                                 Assert.AreEqual (expected, buffer, "#F4");
1077 #else
1078                                 try {
1079                                         reader.GetBytes (0, 0, null, 0, 0);
1080                                         Assert.Fail ("#F2");
1081                                 } catch (InvalidCastException ex) {
1082                                         Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#F3");
1083                                         Assert.IsNull (ex.InnerException, "#F4");
1084                                         Assert.AreEqual ((new InvalidCastException ()).Message, ex.Message, "#F5");
1085                                 }
1086 #endif
1087
1088                                 expected = new byte [0];
1089
1090                                 Assert.IsTrue (reader.Read (), "#G1");
1091 #if NET_2_0
1092                                 len = reader.GetBytes (0, 0, null, 0, 0);
1093                                 Assert.AreEqual (0, len, "#G2");
1094                                 buffer = new byte [len];
1095                                 len = reader.GetBytes (0, 0, buffer, 0, 0);
1096                                 Assert.AreEqual (0, len, "#G3");
1097                                 Assert.AreEqual (expected, buffer, "#G4");
1098 #else
1099                                 try {
1100                                         reader.GetBytes (0, 0, null, 0, 0);
1101                                         Assert.Fail ("#G2");
1102                                 } catch (InvalidCastException ex) {
1103                                         Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#G3");
1104                                         Assert.IsNull (ex.InnerException, "#G4");
1105                                         Assert.AreEqual ((new InvalidCastException ()).Message, ex.Message, "#G5");
1106                                 }
1107 #endif
1108
1109                                 Assert.IsTrue (reader.Read (), "#H1");
1110 #if NET_2_0
1111                                 try {
1112                                         reader.GetBytes (0, 0, new byte [0], 0, 0);
1113                                         Assert.Fail ("#H2");
1114                                 } catch (NullReferenceException) {
1115                                 }
1116                                 try {
1117                                         reader.GetBytes (0, 0, null, 0, 0);
1118                                         Assert.Fail ("#H3");
1119                                 } catch (NullReferenceException) {
1120                                 }
1121 #else
1122                                 try {
1123                                         reader.GetBytes (0, 0, null, 0, 3);
1124                                         Assert.Fail ("#H2");
1125                                 } catch (InvalidCastException ex) {
1126                                         Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#H3");
1127                                         Assert.IsNull (ex.InnerException, "#H4");
1128                                         Assert.AreEqual ((new InvalidCastException ()).Message, ex.Message, "#H5");
1129                                 }
1130 #endif
1131                         }
1132                 }
1133
1134                 [Test]
1135                 public void GetChar ()
1136                 {
1137                         cmd.CommandText = "SELECT type_char FROM string_family where id = 1";
1138
1139                         using (IDataReader reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess)) {
1140                                 Assert.IsTrue (reader.Read ());
1141
1142                                 try {
1143                                         reader.GetChar (0);
1144                                         Assert.Fail ("#A1");
1145                                 } catch (NotSupportedException ex) {
1146                                         Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#A2");
1147                                         Assert.IsNull (ex.InnerException, "#A3");
1148                                         Assert.IsNotNull (ex.Message, "#A4");
1149                                         Assert.AreEqual ((new NotSupportedException ()).Message, ex.Message, "#A5");
1150                                 }
1151                         }
1152
1153                         using (IDataReader reader = cmd.ExecuteReader ()) {
1154                                 Assert.IsTrue (reader.Read ());
1155
1156                                 try {
1157                                         reader.GetChar (0);
1158                                         Assert.Fail ("#B1");
1159                                 } catch (NotSupportedException ex) {
1160                                         Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#B2");
1161                                         Assert.IsNull (ex.InnerException, "#B3");
1162                                         Assert.IsNotNull (ex.Message, "#B4");
1163                                         Assert.AreEqual ((new NotSupportedException ()).Message, ex.Message, "#B5");
1164                                 }
1165                         }
1166                 }
1167
1168                 [Test]
1169                 public void GetChars ()
1170                 {
1171                         cmd.CommandText = "Select type_char, type_varchar,type_text, type_ntext ";
1172                         cmd.CommandText += "from string_family where id=1";
1173                         reader = cmd.ExecuteReader ();
1174                         reader.Read ();
1175                         string charstring = reader.GetString (0);
1176                         //string ncharstring = reader.GetString (1);
1177                         string varcharstring = reader.GetString (1);
1178                         //string nvarcharstring = reader.GetString (2);
1179                         string textstring = reader.GetString (2);
1180                         string ntextstring = reader.GetString (3);
1181                         reader.Close ();
1182                         
1183                         reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess);
1184                         reader.Read ();
1185                         int len = 0;
1186                         char[] arr; 
1187
1188                         len = (int) reader.GetChars (0, 0, null, 0, 0);
1189                         Assert.AreEqual (charstring.Length, len, "#1");
1190                         arr = new char [len];
1191                         reader.GetChars (0, 0, arr, 0, len);
1192                         Assert.AreEqual (0, charstring.CompareTo (new String (arr)), "#2");
1193
1194                         len = (int)reader.GetChars (1,0,null,0,0);
1195                         Assert.AreEqual (varcharstring.Length, len, "#3");
1196                         arr = new char [len];
1197                         reader.GetChars (1, 0,arr,0,len);
1198                         Assert.AreEqual (0, varcharstring.CompareTo (new String (arr)), "#4");
1199
1200                         len = (int)reader.GetChars (2,0,null,0,0);
1201                         Assert.AreEqual (textstring.Length, len, "#5");
1202                         arr = new char [len];
1203                         reader.GetChars (2,0,arr,0,len);
1204                         Assert.AreEqual (0, textstring.CompareTo (new String (arr)), "#6");
1205
1206                         len = (int)reader.GetChars (3,0,null,0,0);
1207                         Assert.AreEqual (ntextstring.Length, len, "#7");
1208                         arr = new char [len];
1209                         reader.GetChars (3,0,arr,0,len);
1210                         Assert.AreEqual (0, ntextstring.CompareTo (new String (arr)), "#8");
1211
1212                         reader.Close ();
1213
1214                         reader = cmd.ExecuteReader (CommandBehavior.SequentialAccess);
1215                         reader.Read ();
1216                         
1217                         len  = (int)reader.GetChars (0,0,null,0,0);
1218                         arr = new char [10];
1219                         for (int i = 0; i < len; ++i) {
1220                                 Assert.AreEqual (len - i, reader.GetChars (0, i, null, 0, 0), "#9_" + i);
1221                                 Assert.AreEqual (1, reader.GetChars (0, i, arr, 0, 1), "#10_" + i);
1222                                 Assert.AreEqual (charstring [i], arr [0], "#11_" + i);
1223                         }
1224                         Assert.AreEqual (0, reader.GetChars (0, len + 10, null, 0, 0));
1225
1226                         reader.Close ();
1227                 }
1228
1229                 [Test]
1230                 public void GetStringTest ()
1231                 {
1232                         cmd.CommandText = "Select type_varchar,10,convert(varchar,null)";
1233                         cmd.CommandText += "from string_family where id=1";
1234                         reader = cmd.ExecuteReader ();
1235                         reader.Read ();
1236                         // Test for standard exceptions 
1237                         GetMethodTests("String");
1238
1239                         // Test if data is returned correctly
1240                         Assert.AreEqual (stringRow["type_varchar"], reader.GetString(0),
1241                                 "#2 DataValidation Failed");
1242
1243                         // Test for standard exceptions 
1244                         GetMethodTests("SqlString");
1245
1246                         // Test if data is returned correctly
1247                         Assert.AreEqual (stringRow["type_varchar"], reader.GetSqlString(0).Value,
1248                                 "#4 DataValidation Failed");
1249                         reader.Close();
1250                 }
1251
1252                 [Test]
1253                 public void GetSqlBinaryTest ()
1254                 {
1255                         cmd.CommandText = "Select type_binary ,10 ,convert(binary,null)";
1256                         cmd.CommandText += "from binary_family where id=1";
1257                         reader = cmd.ExecuteReader ();
1258                         reader.Read ();
1259                         // Test for standard exceptions         
1260                         GetMethodTests ("SqlBinary");
1261
1262                         // Test if data is returned correctly
1263                         Assert.AreEqual (binaryRow["type_binary"], reader.GetSqlBinary(0).Value,
1264                                 "#2 DataValidation Failed");
1265                         reader.Close ();
1266                 }
1267
1268                 [Test]
1269                 public void GetGuidTest ()
1270                 {
1271                         cmd.CommandText = "Select type_guid,id,convert(uniqueidentifier,null)";
1272                         cmd.CommandText += "from string_family where id=1";
1273                         reader = cmd.ExecuteReader ();
1274                         reader.Read ();
1275
1276                         // Test for standard exceptions 
1277                         GetMethodTests("Guid");
1278
1279                         // Test if data is returned correctly
1280                         Assert.AreEqual (stringRow["type_guid"], reader.GetGuid(0),
1281                                 "#2 DataValidation Failed");
1282
1283                         // Test for standard exceptions 
1284                         GetMethodTests("SqlGuid");
1285
1286                         // Test if data is returned correctly
1287                         Assert.AreEqual (stringRow["type_guid"], reader.GetSqlGuid(0).Value,
1288                                 "#4 DataValidation Failed");
1289                         reader.Close ();
1290                 }
1291
1292                 [Test]
1293                 public void GetDateTimeTest ()
1294                 {
1295                         cmd.CommandText = "Select type_datetime,10,convert(datetime,null)";
1296                         cmd.CommandText += "from datetime_family where id=1";
1297                         reader = cmd.ExecuteReader ();
1298                         reader.Read ();
1299
1300                         // Test for standard exceptions 
1301                         GetMethodTests("DateTime");
1302
1303                         // Test if data is returned correctly
1304                         Assert.AreEqual (datetimeRow["type_datetime"], reader.GetDateTime(0),
1305                                 "#2 DataValidation Failed");
1306
1307                         // Test for standard exceptions 
1308                         GetMethodTests("SqlDateTime");
1309
1310                         // Test if data is returned correctly
1311                         Assert.AreEqual (datetimeRow["type_datetime"], reader.GetSqlDateTime(0).Value,
1312                                 "#2 DataValidation Failed");
1313                         reader.Close ();
1314                 }
1315
1316                 [Test]
1317                 [Ignore ("Not Supported by msdotnet")]
1318                 public void GetCharTest ()
1319                 {
1320                         cmd.CommandText = "Select type_char,type_guid,convert(char,null)"; 
1321                         cmd.CommandText += "from string_family where id=1";
1322                         reader = cmd.ExecuteReader ();
1323                         reader.Read ();
1324                         // Test for standard exceptions
1325                         GetMethodTests ("Char");
1326                         reader.Close ();
1327                 }
1328
1329                 [Test]
1330                 public void GetValueTest ()
1331                 {
1332                         cmd.CommandText = "Select id, null from numeric_family where id=1";
1333                         reader = cmd.ExecuteReader ();
1334                         reader.Read ();
1335
1336                         object obj = null; 
1337                         obj = reader.GetValue (0);
1338                         Assert.AreEqual ((byte)1, obj, "#1 Shud return the value of id");
1339                         obj = reader.GetValue (1);
1340                         Assert.AreEqual (DBNull.Value, obj, "#2 shud return DBNull");
1341                         reader.Close ();
1342                 }
1343
1344                 [Test]
1345                 public void GetValuesTest ()
1346                 {
1347                         cmd.CommandText = "Select 10,20,30 from numeric_family where id=1";
1348                         reader = cmd.ExecuteReader ();
1349                         reader.Read ();
1350                         object[] arr = null;
1351                         int count = 0; 
1352
1353                         arr = new object[1];
1354                         count = reader.GetValues (arr);
1355                         Assert.AreEqual (10, (int)arr[0], "#1 Only first object shud be copied");
1356                         Assert.AreEqual (1, count, "#1 return value shud equal objects copied");
1357
1358                         arr = new object[3];
1359                         count = reader.GetValues (arr);
1360                         Assert.AreEqual (3, count, "#2 return value shud equal objects copied");
1361
1362                         arr = new object [5];
1363                         count = reader.GetValues (arr);
1364                         Assert.AreEqual (3, count, "#3 return value shud equal objects copied");
1365                         Assert.IsNull (arr[3], "#4 Only 3 objects shud be copied");
1366
1367                         reader.Close ();
1368                 }
1369
1370                 [Test]
1371                 public void GetValues_Values_Null ()
1372                 {
1373                         cmd.CommandText = "SELECT type_blob FROM binary_family where id = 1";
1374
1375                         using (IDataReader rdr = cmd.ExecuteReader ()) {
1376                                 Assert.IsTrue (rdr.Read ());
1377
1378                                 try {
1379                                         rdr.GetValues ((object []) null);
1380                                         Assert.Fail ("#1");
1381                                 } catch (ArgumentNullException ex) {
1382                                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1383                                         Assert.IsNull (ex.InnerException, "#3");
1384                                         Assert.IsNotNull (ex.Message, "#4");
1385                                         Assert.AreEqual ("values", ex.ParamName, "#5");
1386                                 }
1387                         }
1388                 }
1389
1390                 [Test]
1391                 public void GetSqlValue ()
1392                 {
1393                         cmd.CommandText = "Select id, type_tinyint, null from numeric_family where id=1";
1394                         reader = cmd.ExecuteReader ();
1395                         reader.Read ();
1396
1397                         Assert.AreEqual ((byte) 255, ((SqlByte) reader.GetSqlValue (1)).Value, "#1");
1398                         //Assert.AreEqual (DBNull.Value, reader.GetSqlValue(2), "#2");
1399
1400                         reader.Close ();
1401                 }
1402
1403                 [Test]
1404                 public void GetSqlValue_Index_Invalid ()
1405                 {
1406                         cmd.CommandText = "Select id, type_tinyint, null from numeric_family where id=1";
1407                         reader = cmd.ExecuteReader ();
1408                         reader.Read ();
1409
1410                         try {
1411                                 reader.GetSqlValue (-1);
1412                                 Assert.Fail ("#A1");
1413                         } catch (IndexOutOfRangeException ex) {
1414                                 // Index was outside the bounds of the array
1415                                 Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#A2");
1416                                 Assert.IsNull (ex.InnerException, "#A3");
1417                                 Assert.IsNotNull (ex.Message, "#A4");
1418                         }
1419
1420                         try {
1421                                 reader.GetSqlValue (3);
1422                                 Assert.Fail ("#B1");
1423                         } catch (IndexOutOfRangeException ex) {
1424                                 // Index was outside the bounds of the array
1425                                 Assert.AreEqual (typeof (IndexOutOfRangeException), ex.GetType (), "#B2");
1426                                 Assert.IsNull (ex.InnerException, "#B3");
1427                                 Assert.IsNotNull (ex.Message, "#B4");
1428                         }
1429                 }
1430
1431                 [Test]
1432                 public void GetSqlValue_Reader_Closed ()
1433                 {
1434                         SqlCommand cmd = conn.CreateCommand ();
1435                         cmd.CommandText = "SELECT * FROM employee";
1436                         using (SqlDataReader rdr = cmd.ExecuteReader ()) {
1437                                 rdr.Read ();
1438                                 rdr.Close ();
1439                                 try {
1440                                         rdr.GetSqlValue (-1);
1441                                         Assert.Fail ("#1");
1442                                 } catch (InvalidOperationException ex) {
1443                                         // Invalid attempt to call MetaData
1444                                         // when reader is closed
1445                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1446                                         Assert.IsNull (ex.InnerException, "#3");
1447                                         Assert.IsNotNull (ex.Message, "#4");
1448                                 }
1449                         }
1450                 }
1451
1452                 [Test]
1453                 public void GetSqlValue_Reader_NoData ()
1454                 {
1455                         SqlCommand cmd = conn.CreateCommand ();
1456                         cmd.CommandText = "SELECT * FROM employee where id = 6666";
1457                         using (SqlDataReader rdr = cmd.ExecuteReader ()) {
1458                                 try {
1459                                         rdr.GetSqlValue (-1);
1460                                         Assert.Fail ("#A1");
1461                                 } catch (InvalidOperationException ex) {
1462                                         // Invalid attempt to read when no data
1463                                         // is present
1464                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1465                                         Assert.IsNull (ex.InnerException, "#A3");
1466                                         Assert.IsNotNull (ex.Message, "#A4");
1467                                 }
1468
1469                                 Assert.IsFalse (rdr.Read (), "#B");
1470
1471                                 try {
1472                                         rdr.GetSqlValue (-1);
1473                                         Assert.Fail ("#C1");
1474                                 } catch (InvalidOperationException ex) {
1475                                         // Invalid attempt to read when no data
1476                                         // is present
1477                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
1478                                         Assert.IsNull (ex.InnerException, "#C3");
1479                                         Assert.IsNotNull (ex.Message, "#C4");
1480                                 }
1481                         }
1482                 }
1483
1484                 [Test]
1485                 public void GetSqlValues ()
1486                 {
1487                         cmd.CommandText = "Select 10,20,30 from numeric_family where id=1";
1488                         reader = cmd.ExecuteReader ();
1489                         reader.Read ();
1490                         object[] arr = null;
1491                         int count = 0; 
1492
1493                         arr = new object[1];
1494                         count = reader.GetSqlValues (arr);
1495                         // Something is wrong with types ... gotta figure it out 
1496                         //Assert.AreEqual (10, arr[0], "#1 Only first object shud be copied");
1497                         Assert.AreEqual (1, count, "#1 return value shud equal objects copied");
1498
1499                         arr = new object[3];
1500                         count = reader.GetSqlValues (arr);
1501                         Assert.AreEqual (3, count, "#2 return value shud equal objects copied");
1502
1503                         arr = new object[5];
1504                         count = reader.GetSqlValues (arr);
1505                         Assert.AreEqual (3, count, "#3 return value shud equal objects copied");
1506                         Assert.IsNull (arr[3], "#4 Only 3 objects shud be copied");
1507
1508                         reader.Close ();
1509                 }
1510
1511                 [Test]
1512                 public void GetSqlValues_Reader_Closed ()
1513                 {
1514                         SqlCommand cmd = conn.CreateCommand ();
1515                         cmd.CommandText = "SELECT * FROM employee";
1516                         using (SqlDataReader rdr = cmd.ExecuteReader ()) {
1517                                 rdr.Read ();
1518                                 rdr.Close ();
1519                                 try {
1520                                         rdr.GetSqlValues (null);
1521                                         Assert.Fail ("#1");
1522                                 } catch (InvalidOperationException ex) {
1523                                         // Invalid attempt to call MetaData
1524                                         // when reader is closed
1525                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1526                                         Assert.IsNull (ex.InnerException, "#3");
1527                                         Assert.IsNotNull (ex.Message, "#4");
1528                                 }
1529                         }
1530                 }
1531
1532                 [Test]
1533                 public void GetSqlValues_Reader_NoData ()
1534                 {
1535                         SqlCommand cmd = conn.CreateCommand ();
1536                         cmd.CommandText = "SELECT * FROM employee where id = 6666";
1537                         using (SqlDataReader rdr = cmd.ExecuteReader ()) {
1538                                 try {
1539                                         rdr.GetSqlValues (null);
1540                                         Assert.Fail ("#A1");
1541                                 } catch (InvalidOperationException ex) {
1542                                         // Invalid attempt to read when no data
1543                                         // is present
1544                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1545                                         Assert.IsNull (ex.InnerException, "#A3");
1546                                         Assert.IsNotNull (ex.Message, "#A4");
1547                                 }
1548
1549                                 Assert.IsFalse (rdr.Read (), "#B");
1550
1551                                 try {
1552                                         rdr.GetSqlValues (null);
1553                                         Assert.Fail ("#C1");
1554                                 } catch (InvalidOperationException ex) {
1555                                         // Invalid attempt to read when no data
1556                                         // is present
1557                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
1558                                         Assert.IsNull (ex.InnerException, "#C3");
1559                                         Assert.IsNotNull (ex.Message, "#C4");
1560                                 }
1561                         }
1562                 }
1563
1564                 [Test]
1565                 public void GetSqlValues_Values_Null ()
1566                 {
1567                         SqlCommand cmd = conn.CreateCommand ();
1568                         cmd.CommandText = "SELECT * FROM employee";
1569                         using (SqlDataReader rdr = cmd.ExecuteReader ()) {
1570                                 rdr.Read ();
1571                                 try {
1572                                         rdr.GetSqlValues (null);
1573                                         Assert.Fail ("#1");
1574                                 } catch (ArgumentNullException ex) {
1575                                         Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
1576                                         Assert.IsNull (ex.InnerException, "#3");
1577                                         Assert.IsNotNull (ex.Message, "#4");
1578                                         Assert.AreEqual ("values", ex.ParamName, "#5");
1579                                 }
1580                         }
1581                 }
1582
1583                 [Test]
1584                 public void HasRows ()
1585                 {
1586                         SqlCommand cmd = conn.CreateCommand ();
1587                         cmd.CommandText = "SELECT id FROM employee WHERE id in (1, 2) ORDER BY id ASC";
1588                         using (SqlDataReader rdr = cmd.ExecuteReader ()) {
1589                                 Assert.IsTrue (rdr.HasRows, "#A1");
1590                                 try {
1591                                         rdr.GetValue (0);
1592                                         Assert.Fail ("#A2");
1593                                 } catch (InvalidOperationException) {
1594                                 }
1595                                 Assert.IsTrue (rdr.HasRows, "#A3");
1596                                 Assert.IsTrue (rdr.Read (), "#A4");
1597                                 Assert.AreEqual (1, rdr.GetValue (0), "#A5");
1598                                 Assert.IsTrue (rdr.HasRows, "#A6");
1599                                 Assert.AreEqual (1, rdr.GetValue (0), "#A7");
1600                                 Assert.IsTrue (rdr.Read (), "#A8");
1601                                 Assert.AreEqual (2, rdr.GetValue (0), "#A9");
1602                                 Assert.IsTrue (rdr.HasRows, "#A10");
1603                                 Assert.IsFalse (rdr.Read (), "#A11");
1604                                 Assert.IsTrue (rdr.HasRows, "#A12");
1605                                 Assert.IsFalse (rdr.NextResult (), "#A13");
1606                                 Assert.IsFalse (rdr.HasRows, "#A14");
1607                         }
1608
1609                         cmd.CommandText = "SELECT id FROM employee WHERE id = 666";
1610                         using (SqlDataReader rdr = cmd.ExecuteReader ()) {
1611                                 Assert.IsFalse (rdr.HasRows, "#B1");
1612                                 Assert.IsFalse (rdr.Read (), "#B2");
1613                         }
1614
1615                         cmd.CommandText = "SELECT id FROM employee WHERE id = 666; SELECT 3";
1616                         using (SqlDataReader rdr = cmd.ExecuteReader ()) {
1617                                 Assert.IsFalse (rdr.HasRows, "#C1");
1618                                 Assert.IsFalse (rdr.Read (), "#C2");
1619                                 Assert.IsFalse (rdr.HasRows, "#C3");
1620                                 Assert.IsTrue (rdr.NextResult (), "#C4");
1621                                 Assert.IsTrue (rdr.HasRows, "#C5");
1622                                 try {
1623                                         rdr.GetValue (0);
1624                                         Assert.Fail ("#C6");
1625                                 } catch (InvalidOperationException) {
1626                                 }
1627                                 Assert.IsTrue (rdr.Read (), "#C7");
1628                                 Assert.AreEqual (3, rdr.GetValue (0), "#C8");
1629                                 Assert.IsTrue (rdr.HasRows, "#C9");
1630                                 Assert.AreEqual (3, rdr.GetValue (0), "#C10");
1631                                 Assert.IsFalse (rdr.Read (), "#C11");
1632                                 Assert.IsTrue (rdr.HasRows, "#C12");
1633                                 try {
1634                                         rdr.GetValue (0);
1635                                         Assert.Fail ("#C13");
1636                                 } catch (InvalidOperationException) {
1637                                 }
1638                                 Assert.IsFalse (rdr.NextResult (), "#C14");
1639                                 Assert.IsFalse (rdr.HasRows, "#C15");
1640                                 Assert.IsFalse (rdr.Read (), "#C16");
1641                                 Assert.IsFalse (rdr.HasRows, "#C17");
1642                         }
1643
1644                         cmd.CommandText = "SELECT id FROM employee WHERE id = 1; SELECT 3";
1645                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.SingleResult)) {
1646                                 Assert.IsTrue (rdr.HasRows, "#D1");
1647                                 Assert.IsTrue (rdr.Read (), "#D2");
1648                                 Assert.IsTrue (rdr.HasRows, "#D3");
1649                                 Assert.IsFalse (rdr.NextResult (), "#D4");
1650                                 Assert.IsFalse (rdr.HasRows, "#D5");
1651                                 Assert.IsFalse (rdr.Read (), "#D6");
1652                                 Assert.IsFalse (rdr.HasRows, "#D7");
1653                         }
1654
1655                         cmd.CommandText = "SELECT id FROM employee WHERE id = 666; SELECT 3";
1656                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.SingleResult)) {
1657                                 Assert.IsFalse (rdr.HasRows, "#E1");
1658                                 Assert.IsFalse (rdr.Read (), "#E2");
1659                                 Assert.IsFalse (rdr.HasRows, "#E3");
1660                                 Assert.IsFalse (rdr.NextResult (), "#E4");
1661                                 Assert.IsFalse (rdr.HasRows, "#E5");
1662                                 Assert.IsFalse (rdr.Read (), "#E6");
1663                                 Assert.IsFalse (rdr.HasRows, "#E7");
1664                         }
1665
1666                         cmd.CommandText = "SELECT id FROM employee WHERE id = 1; SELECT 3";
1667                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.SchemaOnly)) {
1668                                 Assert.IsFalse (rdr.HasRows, "#F1");
1669                                 try {
1670                                         rdr.GetValue (0);
1671                                         Assert.Fail ("#F2");
1672                                 } catch (InvalidOperationException) {
1673                                 }
1674                                 Assert.IsFalse (rdr.Read (), "#F3");
1675                                 try {
1676                                         rdr.GetValue (0);
1677                                         Assert.Fail ("#F4");
1678                                 } catch (InvalidOperationException) {
1679                                 }
1680                                 Assert.IsFalse (rdr.HasRows, "#F5");
1681                                 try {
1682                                         rdr.GetValue (0);
1683                                         Assert.Fail ("#F6");
1684                                 } catch (InvalidOperationException) {
1685                                 }
1686                                 Assert.IsTrue (rdr.NextResult (), "#F7");
1687                                 try {
1688                                         rdr.GetValue (0);
1689                                         Assert.Fail ("#F8");
1690                                 } catch (InvalidOperationException) {
1691                                 }
1692                                 Assert.IsFalse (rdr.HasRows, "#F9");
1693                                 Assert.IsFalse (rdr.Read (), "#F10");
1694                                 Assert.IsFalse (rdr.HasRows, "#F11");
1695                                 Assert.IsFalse (rdr.NextResult (), "#F12");
1696                                 Assert.IsFalse (rdr.HasRows, "#F13");
1697                                 Assert.IsFalse (rdr.Read (), "#F14");
1698                                 Assert.IsFalse (rdr.HasRows, "#F15");
1699                         }
1700
1701                         cmd.CommandText = "SELECT id FROM employee WHERE id = 666; SELECT 3";
1702                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.SchemaOnly)) {
1703                                 Assert.IsFalse (rdr.HasRows, "#G1");
1704                                 Assert.IsFalse (rdr.Read (), "#G2");
1705                                 Assert.IsFalse (rdr.HasRows, "#G3");
1706                                 Assert.IsTrue (rdr.NextResult (), "#G4");
1707                                 Assert.IsFalse (rdr.HasRows, "#G5");
1708                                 Assert.IsFalse (rdr.Read (), "#G6");
1709                                 Assert.IsFalse (rdr.HasRows, "#G7");
1710                                 Assert.IsFalse (rdr.NextResult (), "#G8");
1711                                 Assert.IsFalse (rdr.HasRows, "#G9");
1712                                 Assert.IsFalse (rdr.Read (), "#G10");
1713                                 Assert.IsFalse (rdr.HasRows, "#G11");
1714                         }
1715                 }
1716
1717                 [Test]
1718                 public void HasRows_Reader_Closed ()
1719                 {
1720                         SqlCommand cmd = conn.CreateCommand ();
1721                         cmd.CommandText = "SELECT id FROM employee WHERE id in (1, 2) ORDER BY id ASC";
1722                         using (SqlDataReader rdr = cmd.ExecuteReader ()) {
1723                                 rdr.Close ();
1724                                 try {
1725                                         bool hasRows = rdr.HasRows;
1726                                         Assert.Fail ("#A1:" + hasRows);
1727                                 } catch (InvalidOperationException ex) {
1728                                         // Invalid attempt to call MetaData
1729                                         // when reader is closed
1730                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
1731                                         Assert.IsNull (ex.InnerException, "#A3");
1732                                         Assert.IsNotNull (ex.Message, "#A4");
1733                                 }
1734                         }
1735
1736                         using (SqlDataReader rdr = cmd.ExecuteReader ()) {
1737                                 Assert.IsTrue (rdr.Read (), "#B1");
1738                                 rdr.Close ();
1739                                 try {
1740                                         bool hasRows = rdr.HasRows;
1741                                         Assert.Fail ("#B2:" + hasRows);
1742                                 } catch (InvalidOperationException ex) {
1743                                         // Invalid attempt to call MetaData
1744                                         // when reader is closed
1745                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B3");
1746                                         Assert.IsNull (ex.InnerException, "#B4");
1747                                         Assert.IsNotNull (ex.Message, "#B5");
1748                                 }
1749                         }
1750                 }
1751
1752                 [Test]
1753                 public void isDBNullTest ()
1754                 {
1755                         cmd.CommandText = "select id , null from numeric_family where id=1";
1756                         reader = cmd.ExecuteReader ();
1757                         reader.Read ();
1758
1759                         Assert.IsFalse (reader.IsDBNull (0), "#1");
1760                         Assert.IsTrue (reader.IsDBNull (1) , "#2");
1761
1762                         try {
1763                                 reader.IsDBNull (10);
1764                                 Assert.Fail ("#1 Invalid Argument");
1765                         } catch (IndexOutOfRangeException e) {
1766                                 Assert.AreEqual (typeof(IndexOutOfRangeException), e.GetType(),
1767                                         "#1 Incorrect Exception : " + e); 
1768                         }
1769                 }
1770
1771                 [Test]
1772                 public void ReadTest ()
1773                 {
1774                         cmd.CommandText = "select id, type_bit from numeric_family where id=1" ;
1775                         reader = cmd.ExecuteReader ();
1776                         Assert.IsTrue (reader.Read () , "#1");
1777                         Assert.IsFalse (reader.Read (), "#2");
1778                         reader.Close ();
1779
1780                         try {
1781                                 reader.Read ();
1782                                 Assert.Fail ("#3 Exception shud be thrown : Reader is closed");
1783                         } catch (InvalidOperationException e) {
1784                                 Assert.AreEqual (typeof(InvalidOperationException), e.GetType (),
1785                                         "#4 Incorrect Exception : " + e);
1786                         }
1787                 }
1788
1789                 [Test]
1790                 public void NextResult ()
1791                 {
1792                         cmd.CommandText = "Select id from numeric_family where id=1";
1793                         reader = cmd.ExecuteReader ();
1794                         Assert.IsFalse (reader.NextResult (), "#1");
1795                         reader.Close ();
1796
1797                         cmd.CommandText = "select id from numeric_family where id=1;";
1798                         cmd.CommandText += "select type_bit from numeric_family where id=2;";
1799                         reader = cmd.ExecuteReader ();
1800                         Assert.IsTrue (reader.NextResult (), "#B1");
1801                         Assert.IsTrue (reader.Read (), "#B2");
1802                         Assert.IsFalse (reader.NextResult (), "#B3");
1803                         try {
1804                                 reader.GetValue (0);
1805                                 Assert.Fail ("#B3");
1806                         } catch (InvalidOperationException) {
1807                         }
1808                         Assert.IsFalse (reader.Read (), "#B4");
1809                         try {
1810                                 reader.GetValue (0);
1811                                 Assert.Fail ("#B5");
1812                         } catch (InvalidOperationException) {
1813                         }
1814                 }
1815
1816                 [Test]
1817                 public void NextResult_Reader_Close ()
1818                 {
1819                         SqlCommand cmd = conn.CreateCommand ();
1820                         cmd.CommandText = "SELECT * FROM employee";
1821                         using (SqlDataReader rdr = cmd.ExecuteReader ()) {
1822                                 rdr.Read ();
1823                                 rdr.Close ();
1824                                 try {
1825                                         rdr.NextResult ();
1826                                         Assert.Fail ("#1");
1827                                 } catch (InvalidOperationException ex) {
1828                                         // Invalid attempt to NextResult when
1829                                         // reader is closed
1830                                         Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
1831                                         Assert.IsNull (ex.InnerException, "#3");
1832                                         Assert.IsNotNull (ex.Message, "#4");
1833                                 }
1834                         }
1835                 }
1836
1837                 [Test]
1838                 public void GetNameTest ()
1839                 {
1840                         cmd.CommandText = "Select id,10 as gen,20 from numeric_family where id=1";
1841                         reader = cmd.ExecuteReader ();
1842
1843                         Assert.AreEqual ("id" , reader.GetName(0) , "#1");
1844                         Assert.AreEqual ("gen" , reader.GetName(1) , "#2");
1845
1846                         try {
1847                                 reader.GetName (3);
1848                                 Assert.Fail ("#4 Exception shud be thrown");
1849                         } catch (IndexOutOfRangeException e) {
1850                                 Assert.AreEqual (typeof(IndexOutOfRangeException), e.GetType(),
1851                                         "#5 Incorrect Exception : " + e);
1852                         }
1853                 }
1854
1855                 [Test]
1856                 public void GetOrdinalTest ()
1857                 {
1858                         //what is kana-width insensitive ????? 
1859                         cmd.CommandText = "Select id,10 as gen,20 from numeric_family where id=1";
1860                         reader = cmd.ExecuteReader ();
1861
1862                         Assert.AreEqual (0, reader.GetOrdinal ("id"), "#1");
1863                         Assert.AreEqual (0, reader.GetOrdinal ("ID"), "#2");
1864                         Assert.AreEqual (1, reader.GetOrdinal ("gen"), "#3");
1865                         // Would expect column1,columnn2 etc for unnamed columns,
1866                         // but msdotnet return empty string for unnamed columns
1867                         Assert.AreEqual (2, reader.GetOrdinal (""), "#4");
1868
1869                         try {
1870                                 reader.GetOrdinal ("invalidname");
1871                         } catch (IndexOutOfRangeException e) {
1872                                 Assert.AreEqual (typeof (IndexOutOfRangeException),
1873                                         e.GetType(), "#4 Incorrect Exception : " + e);
1874                         }
1875                 }
1876
1877                 [Test]
1878                 public void GetSchemaTable ()
1879                 {
1880                         IDbConnection conn = ConnectionManager.Singleton.Connection;
1881                         ConnectionManager.Singleton.OpenConnection ();
1882
1883                         IDbCommand cmd = null;
1884                         IDataReader reader = null;
1885                         DataTable schema;
1886                         DataRow pkRow;
1887
1888                         try {
1889                                 cmd = conn.CreateCommand ();
1890                                 cmd.CommandText = "select id, fname, id + 20 as plustwenty from employee";
1891                                 reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);
1892                                 schema = reader.GetSchemaTable ();
1893                                 reader.Close ();
1894
1895                                 AssertSchemaTableStructure (schema, "#A:");
1896                                 Assert.AreEqual (3, schema.Rows.Count, "#A:RowCount");
1897                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
1898                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#A:ColumnName_IsNull");
1899                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#A:ColumnName_Value");
1900                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#A:ColumnOrdinal_IsNull");
1901                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#A:ColumnOrdinal_Value");
1902                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#A:ColumnSize_IsNull");
1903                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#A:ColumnSize_Value");
1904                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#A:NumericPrecision_IsNull");
1905                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#A:NumericPrecision_Value");
1906                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#A:NumericScale_IsNull");
1907                                 Assert.AreEqual (255, pkRow ["NumericScale"], "#A:NumericScale_Value");
1908                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#A:DataType_IsNull");
1909                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#A:DataType_Value");
1910                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#A:ProviderType_IsNull");
1911                                 Assert.AreEqual (8, pkRow ["ProviderType"], "#A:ProviderType_Value");
1912                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#A:IsLong_IsNull");
1913                                 Assert.AreEqual (false, pkRow ["IsLong"], "#A:IsLong_Value");
1914                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#A:AllowDBNull_IsNull");
1915                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#A:AllowDBNull_Value");
1916                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#A:IsReadOnly_IsNull");
1917                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#A:IsReadOnly_Value");
1918                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#A:IsRowVersion_IsNull");
1919                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#A:IsRowVersion_Value");
1920                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#A:IsUnique_IsNull");
1921                                 Assert.AreEqual (false, pkRow ["IsUnique"], "#A:IsUnique_Value");
1922                                 Assert.IsFalse (pkRow.IsNull ("IsKey"), "#A:IsKey_IsNull");
1923                                 Assert.AreEqual (true, pkRow ["IsKey"], "#A:IsKey_Value");
1924                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#A:IsAutoIncrement_IsNull");
1925                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#A:IsAutoIncrement_Value");
1926                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#A:BaseSchemaName_IsNull");
1927                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#A:BaseSchemaName_Value");
1928                                 Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#A:BaseCatalogName_IsNull");
1929                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#A:BaseCatalogName_Value");
1930                                 Assert.IsFalse (pkRow.IsNull ("BaseTableName"), "#A:BaseTableName_IsNull");
1931                                 Assert.AreEqual ("employee", pkRow ["BaseTableName"], "#A:BaseTableName_Value");
1932                                 Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#A:BaseColumnName_IsNull");
1933                                 Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#A:BaseColumnName_Value");
1934
1935                                 reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly);
1936                                 schema = reader.GetSchemaTable ();
1937                                 reader.Close ();
1938
1939                                 AssertSchemaTableStructure (schema, "#B:");
1940                                 Assert.AreEqual (3, schema.Rows.Count, "#B:RowCount");
1941                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
1942                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#B:ColumnName_IsNull");
1943                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#B:ColumnName_Value");
1944                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#B:ColumnOrdinal_IsNull");
1945                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#B:ColumnOrdinal_Value");
1946                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#B:ColumnSize_IsNull");
1947                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#B:ColumnSize_Value");
1948                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#B:NumericPrecision_IsNull");
1949                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#B:NumericPrecision_Value");
1950                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#B:NumericScale_IsNull");
1951                                 Assert.AreEqual (255, pkRow ["NumericScale"], "#B:NumericScale_Value");
1952                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#B:DataType_IsNull");
1953                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#B:DataType_Value");
1954                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#B:ProviderType_IsNull");
1955                                 Assert.AreEqual (8, pkRow ["ProviderType"], "#B:ProviderType_Value");
1956                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#B:IsLong_IsNull");
1957                                 Assert.AreEqual (false, pkRow ["IsLong"], "#B:IsLong_Value");
1958                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#B:AllowDBNull_IsNull");
1959                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#B:AllowDBNull_Value");
1960                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#B:IsReadOnly_IsNull");
1961                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#B:IsReadOnly_Value");
1962                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#B:IsRowVersion_IsNull");
1963                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#B:IsRowVersion_Value");
1964                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#B:IsUnique_IsNull");
1965                                 Assert.AreEqual (false, pkRow ["IsUnique"], "#B:IsUnique_Value");
1966                                 Assert.IsTrue (pkRow.IsNull ("IsKey"), "#B:IsKey_IsNull");
1967                                 Assert.AreEqual (DBNull.Value, pkRow ["IsKey"], "#B:IsKey_Value");
1968                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#B:IsAutoIncrement_IsNull");
1969                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#B:IsAutoIncrement_Value");
1970                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#B:BaseSchemaName_IsNull");
1971                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#B:BaseSchemaName_Value");
1972                                 Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#B:BaseCatalogName_IsNull");
1973                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#B:BaseCatalogName_Value");
1974                                 Assert.IsTrue (pkRow.IsNull ("BaseTableName"), "#B:BaseTableName_IsNull");
1975                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseTableName"], "#B:BaseTableName_Value");
1976                                 Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#B:BaseColumnName_IsNull");
1977                                 Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#B:BaseColumnName_Value");
1978
1979                                 reader = cmd.ExecuteReader (CommandBehavior.KeyInfo);
1980                                 schema = reader.GetSchemaTable ();
1981                                 reader.Close ();
1982
1983                                 AssertSchemaTableStructure (schema, "#C:");
1984                                 Assert.AreEqual (3, schema.Rows.Count, "#C:RowCount");
1985                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
1986                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#C:ColumnName_IsNull");
1987                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#C:ColumnName_Value");
1988                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#C:ColumnOrdinal_IsNull");
1989                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#C:ColumnOrdinal_Value");
1990                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#C:ColumnSize_IsNull");
1991                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#C:ColumnSize_Value");
1992                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#C:NumericPrecision_IsNull");
1993                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#C:NumericPrecision_Value");
1994                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#C:NumericScale_IsNull");
1995                                 Assert.AreEqual (255, pkRow ["NumericScale"], "#C:NumericScale_Value");
1996                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#C:DataType_IsNull");
1997                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#C:DataType_Value");
1998                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#C:ProviderType_IsNull");
1999                                 Assert.AreEqual (8, pkRow ["ProviderType"], "#C:ProviderType_Value");
2000                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#C:IsLong_IsNull");
2001                                 Assert.AreEqual (false, pkRow ["IsLong"], "#C:IsLong_Value");
2002                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#C:AllowDBNull_IsNull");
2003                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#C:AllowDBNull_Value");
2004                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#C:IsReadOnly_IsNull");
2005                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#C:IsReadOnly_Value");
2006                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#C:IsRowVersion_IsNull");
2007                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#C:IsRowVersion_Value");
2008                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#C:IsUnique_IsNull");
2009                                 Assert.AreEqual (false, pkRow ["IsUnique"], "#C:IsUnique_Value");
2010                                 Assert.IsFalse (pkRow.IsNull ("IsKey"), "#C:IsKey_IsNull");
2011                                 Assert.AreEqual (true, pkRow ["IsKey"], "#C:IsKey_Value");
2012                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#C:IsAutoIncrement_IsNull");
2013                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#C:IsAutoIncrement_Value");
2014                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#C:BaseSchemaName_IsNull");
2015                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#C:BaseSchemaName_Value");
2016                                 Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#C:BaseCatalogName_IsNull");
2017                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#C:BaseCatalogName_Value");
2018                                 Assert.IsFalse (pkRow.IsNull ("BaseTableName"), "#C:BaseTableName_IsNull");
2019                                 Assert.AreEqual ("employee", pkRow ["BaseTableName"], "#C:BaseTableName_Value");
2020                                 Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#C:BaseColumnName_IsNull");
2021                                 Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#C:BaseColumnName_Value");
2022
2023                                 reader = cmd.ExecuteReader ();
2024                                 schema = reader.GetSchemaTable ();
2025                                 reader.Close ();
2026
2027                                 AssertSchemaTableStructure (schema, "#D:");
2028                                 Assert.AreEqual (3, schema.Rows.Count, "#D:RowCount");
2029                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
2030                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#D:ColumnName_IsNull");
2031                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#D:ColumnName_Value");
2032                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#D:ColumnOrdinal_IsNull");
2033                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#D:ColumnOrdinal_Value");
2034                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#D:ColumnSize_IsNull");
2035                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#D:ColumnSize_Value");
2036                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#D:NumericPrecision_IsNull");
2037                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#D:NumericPrecision_Value");
2038                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#D:NumericScale_IsNull");
2039                                 Assert.AreEqual (255, pkRow ["NumericScale"], "#D:NumericScale_Value");
2040                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#D:DataType_IsNull");
2041                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#D:DataType_Value");
2042                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#D:ProviderType_IsNull");
2043                                 Assert.AreEqual (8, pkRow ["ProviderType"], "#D:ProviderType_Value");
2044                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#D:IsLong_IsNull");
2045                                 Assert.AreEqual (false, pkRow ["IsLong"], "#D:IsLong_Value");
2046                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#D:AllowDBNull_IsNull");
2047                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#D:AllowDBNull_Value");
2048                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#D:IsReadOnly_IsNull");
2049                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#D:IsReadOnly_Value");
2050                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#D:IsRowVersion_IsNull");
2051                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#D:IsRowVersion_Value");
2052                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#D:IsUnique_IsNull");
2053                                 Assert.AreEqual (false, pkRow ["IsUnique"], "#D:IsUnique_Value");
2054                                 Assert.IsTrue (pkRow.IsNull ("IsKey"), "#D:IsKey_IsNull");
2055                                 Assert.AreEqual (DBNull.Value, pkRow ["IsKey"], "#D:IsKey_Value");
2056                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#D:IsAutoIncrement_IsNull");
2057                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#D:IsAutoIncrement_Value");
2058                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#D:BaseSchemaName_IsNull");
2059                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#D:BaseSchemaName_Value");
2060                                 Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#D:BaseCatalogName_IsNull");
2061                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#D:BaseCatalogName_Value");
2062                                 Assert.IsTrue (pkRow.IsNull ("BaseTableName"), "#D:BaseTableName_IsNull");
2063                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseTableName"], "#D:BaseTableName_Value");
2064                                 Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#D:BaseColumnName_IsNull");
2065                                 Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#D:BaseColumnName_Value");
2066
2067                                 cmd = conn.CreateCommand ();
2068                                 cmd.CommandText = "select id, fname, id + 20 as plustwenty from employee";
2069                                 cmd.Prepare ();
2070                                 reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);
2071                                 schema = reader.GetSchemaTable ();
2072                                 reader.Close ();
2073
2074                                 AssertSchemaTableStructure (schema, "#E:");
2075                                 Assert.AreEqual (3, schema.Rows.Count, "#E:RowCount");
2076                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
2077                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#E:ColumnName_IsNull");
2078                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#E:ColumnName_Value");
2079                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#E:ColumnOrdinal_IsNull");
2080                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#E:ColumnOrdinal_Value");
2081                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#E:ColumnSize_IsNull");
2082                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#E:ColumnSize_Value");
2083                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#E:NumericPrecision_IsNull");
2084                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#E:NumericPrecision_Value");
2085                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#E:NumericScale_IsNull");
2086                                 Assert.AreEqual (255, pkRow ["NumericScale"], "#E:NumericScale_Value");
2087                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#E:DataType_IsNull");
2088                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#E:DataType_Value");
2089                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#E:ProviderType_IsNull");
2090                                 Assert.AreEqual (8, pkRow ["ProviderType"], "#E:ProviderType_Value");
2091                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#E:IsLong_IsNull");
2092                                 Assert.AreEqual (false, pkRow ["IsLong"], "#E:IsLong_Value");
2093                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#E:AllowDBNull_IsNull");
2094                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#E:AllowDBNull_Value");
2095                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#E:IsReadOnly_IsNull");
2096                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#E:IsReadOnly_Value");
2097                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#E:IsRowVersion_IsNull");
2098                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#E:IsRowVersion_Value");
2099                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#E:IsUnique_IsNull");
2100                                 Assert.AreEqual (false, pkRow ["IsUnique"], "#E:IsUnique_Value");
2101                                 Assert.IsFalse (pkRow.IsNull ("IsKey"), "#E:IsKey_IsNull");
2102                                 Assert.AreEqual (true, pkRow ["IsKey"], "#E:IsKey_Value");
2103                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#E:IsAutoIncrement_IsNull");
2104                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#E:IsAutoIncrement_Value");
2105                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#E:BaseSchemaName_IsNull");
2106                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#E:BaseSchemaName_Value");
2107                                 Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#E:BaseCatalogName_IsNull");
2108                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#E:BaseCatalogName_Value");
2109                                 Assert.IsFalse (pkRow.IsNull ("BaseTableName"), "#E:BaseTableName_IsNull");
2110                                 Assert.AreEqual ("employee", pkRow ["BaseTableName"], "#E:BaseTableName_Value");
2111                                 Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#E:BaseColumnName_IsNull");
2112                                 Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#E:BaseColumnName_Value");
2113
2114                                 reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly);
2115                                 schema = reader.GetSchemaTable ();
2116                                 reader.Close ();
2117
2118                                 AssertSchemaTableStructure (schema, "#F:");
2119                                 Assert.AreEqual (3, schema.Rows.Count, "#F:RowCount");
2120                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
2121                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#F:ColumnName_IsNull");
2122                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#F:ColumnName_Value");
2123                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#F:ColumnOrdinal_IsNull");
2124                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#F:ColumnOrdinal_Value");
2125                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#F:ColumnSize_IsNull");
2126                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#F:ColumnSize_Value");
2127                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#F:NumericPrecision_IsNull");
2128                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#F:NumericPrecision_Value");
2129                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#F:NumericScale_IsNull");
2130                                 Assert.AreEqual (255, pkRow ["NumericScale"], "#F:NumericScale_Value");
2131                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#F:DataType_IsNull");
2132                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#F:DataType_Value");
2133                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#F:ProviderType_IsNull");
2134                                 Assert.AreEqual (8, pkRow ["ProviderType"], "#F:ProviderType_Value");
2135                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#F:IsLong_IsNull");
2136                                 Assert.AreEqual (false, pkRow ["IsLong"], "#F:IsLong_Value");
2137                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#F:AllowDBNull_IsNull");
2138                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#F:AllowDBNull_Value");
2139                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#F:IsReadOnly_IsNull");
2140                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#F:IsReadOnly_Value");
2141                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#F:IsRowVersion_IsNull");
2142                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#F:IsRowVersion_Value");
2143                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#F:IsUnique_IsNull");
2144                                 Assert.AreEqual (false, pkRow ["IsUnique"], "#F:IsUnique_Value");
2145                                 Assert.IsTrue (pkRow.IsNull ("IsKey"), "#F:IsKey_IsNull");
2146                                 Assert.AreEqual (DBNull.Value, pkRow ["IsKey"], "#F:IsKey_Value");
2147                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#F:IsAutoIncrement_IsNull");
2148                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#F:IsAutoIncrement_Value");
2149                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#F:BaseSchemaName_IsNull");
2150                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#F:BaseSchemaName_Value");
2151                                 Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#F:BaseCatalogName_IsNull");
2152                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#F:BaseCatalogName_Value");
2153                                 Assert.IsTrue (pkRow.IsNull ("BaseTableName"), "#F:BaseTableName_IsNull");
2154                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseTableName"], "#F:BaseTableName_Value");
2155                                 Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#F:BaseColumnName_IsNull");
2156                                 Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#F:BaseColumnName_Value");
2157
2158                                 reader = cmd.ExecuteReader (CommandBehavior.KeyInfo);
2159                                 schema = reader.GetSchemaTable ();
2160                                 reader.Close ();
2161
2162                                 AssertSchemaTableStructure (schema, "#G:");
2163                                 Assert.AreEqual (3, schema.Rows.Count, "#G:RowCount");
2164                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
2165                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#G:ColumnName_IsNull");
2166                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#G:ColumnName_Value");
2167                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#G:ColumnOrdinal_IsNull");
2168                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#G:ColumnOrdinal_Value");
2169                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#G:ColumnSize_IsNull");
2170                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#G:ColumnSize_Value");
2171                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#G:NumericPrecision_IsNull");
2172                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#G:NumericPrecision_Value");
2173                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#G:NumericScale_IsNull");
2174                                 Assert.AreEqual (255, pkRow ["NumericScale"], "#G:NumericScale_Value");
2175                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#G:DataType_IsNull");
2176                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#G:DataType_Value");
2177                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#G:ProviderType_IsNull");
2178                                 Assert.AreEqual (8, pkRow ["ProviderType"], "#G:ProviderType_Value");
2179                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#G:IsLong_IsNull");
2180                                 Assert.AreEqual (false, pkRow ["IsLong"], "#G:IsLong_Value");
2181                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#G:AllowDBNull_IsNull");
2182                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#G:AllowDBNull_Value");
2183                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#G:IsReadOnly_IsNull");
2184                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#G:IsReadOnly_Value");
2185                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#G:IsRowVersion_IsNull");
2186                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#G:IsRowVersion_Value");
2187                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#G:IsUnique_IsNull");
2188                                 Assert.AreEqual (false, pkRow ["IsUnique"], "#G:IsUnique_Value");
2189                                 Assert.IsFalse (pkRow.IsNull ("IsKey"), "#G:IsKey_IsNull");
2190                                 Assert.AreEqual (true, pkRow ["IsKey"], "#G:IsKey_Value");
2191                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#G:IsAutoIncrement_IsNull");
2192                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#G:IsAutoIncrement_Value");
2193                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#G:BaseSchemaName_IsNull");
2194                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#G:BaseSchemaName_Value");
2195                                 Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#G:BaseCatalogName_IsNull");
2196                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#G:BaseCatalogName_Value");
2197                                 Assert.IsFalse (pkRow.IsNull ("BaseTableName"), "#G:BaseTableName_IsNull");
2198                                 Assert.AreEqual ("employee", pkRow ["BaseTableName"], "#G:BaseTableName_Value");
2199                                 Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#G:BaseColumnName_IsNull");
2200                                 Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#G:BaseColumnName_Value");
2201
2202                                 reader = cmd.ExecuteReader ();
2203                                 schema = reader.GetSchemaTable ();
2204                                 reader.Close ();
2205
2206                                 AssertSchemaTableStructure (schema, "#H:");
2207                                 Assert.AreEqual (3, schema.Rows.Count, "#H:RowCount");
2208                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
2209                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#H:ColumnName_IsNull");
2210                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#H:ColumnName_Value");
2211                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#H:ColumnOrdinal_IsNull");
2212                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#H:ColumnOrdinal_Value");
2213                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#H:ColumnSize_IsNull");
2214                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#H:ColumnSize_Value");
2215                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#H:NumericPrecision_IsNull");
2216                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#H:NumericPrecision_Value");
2217                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#H:NumericScale_IsNull");
2218                                 Assert.AreEqual (255, pkRow ["NumericScale"], "#H:NumericScale_Value");
2219                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#H:DataType_IsNull");
2220                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#H:DataType_Value");
2221                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#H:ProviderType_IsNull");
2222                                 Assert.AreEqual (8, pkRow ["ProviderType"], "#H:ProviderType_Value");
2223                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#H:IsLong_IsNull");
2224                                 Assert.AreEqual (false, pkRow ["IsLong"], "#H:IsLong_Value");
2225                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#H:AllowDBNull_IsNull");
2226                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#H:AllowDBNull_Value");
2227                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#H:IsReadOnly_IsNull");
2228                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#H:IsReadOnly_Value");
2229                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#H:IsRowVersion_IsNull");
2230                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#H:IsRowVersion_Value");
2231                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#H:IsUnique_IsNull");
2232                                 Assert.AreEqual (false, pkRow ["IsUnique"], "#H:IsUnique_Value");
2233                                 Assert.IsTrue (pkRow.IsNull ("IsKey"), "#H:IsKey_IsNull");
2234                                 Assert.AreEqual (DBNull.Value, pkRow ["IsKey"], "#H:IsKey_Value");
2235                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#H:IsAutoIncrement_IsNull");
2236                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#H:IsAutoIncrement_Value");
2237                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#H:BaseSchemaName_IsNull");
2238                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#H:BaseSchemaName_Value");
2239                                 Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#H:BaseCatalogName_IsNull");
2240                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#H:BaseCatalogName_Value");
2241                                 Assert.IsTrue (pkRow.IsNull ("BaseTableName"), "#H:BaseTableName_IsNull");
2242                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseTableName"], "#H:BaseTableName_Value");
2243                                 Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#H:BaseColumnName_IsNull");
2244                                 Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#H:BaseColumnName_Value");
2245
2246                                 cmd.CommandText = "select id, fname, id + 20 as plustwenty from employee where id = @id";
2247                                 IDbDataParameter param = cmd.CreateParameter ();
2248                                 param.ParameterName = "@id";
2249                                 cmd.Parameters.Add (param);
2250                                 param.DbType = DbType.Int32;
2251                                 param.Value = 2;
2252                                 reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);
2253                                 schema = reader.GetSchemaTable ();
2254                                 reader.Close ();
2255
2256                                 AssertSchemaTableStructure (schema, "#I:");
2257                                 Assert.AreEqual (3, schema.Rows.Count, "#I:RowCount");
2258                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
2259                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#I:ColumnName_IsNull");
2260                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#I:ColumnName_Value");
2261                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#I:ColumnOrdinal_IsNull");
2262                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#I:ColumnOrdinal_Value");
2263                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#I:ColumnSize_IsNull");
2264                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#I:ColumnSize_Value");
2265                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#I:NumericPrecision_IsNull");
2266                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#I:NumericPrecision_Value");
2267                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#I:NumericScale_IsNull");
2268                                 Assert.AreEqual (255, pkRow ["NumericScale"], "#I:NumericScale_Value");
2269                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#I:DataType_IsNull");
2270                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#I:DataType_Value");
2271                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#I:ProviderType_IsNull");
2272                                 Assert.AreEqual (8, pkRow ["ProviderType"], "#I:ProviderType_Value");
2273                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#I:IsLong_IsNull");
2274                                 Assert.AreEqual (false, pkRow ["IsLong"], "#I:IsLong_Value");
2275                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#I:AllowDBNull_IsNull");
2276                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#I:AllowDBNull_Value");
2277                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#I:IsReadOnly_IsNull");
2278                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#I:IsReadOnly_Value");
2279                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#I:IsRowVersion_IsNull");
2280                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#I:IsRowVersion_Value");
2281                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#I:IsUnique_IsNull");
2282                                 Assert.AreEqual (false, pkRow ["IsUnique"], "#I:IsUnique_Value");
2283                                 Assert.IsFalse (pkRow.IsNull ("IsKey"), "#I:IsKey_IsNull");
2284                                 Assert.AreEqual (true, pkRow ["IsKey"], "#I:IsKey_Value");
2285                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#I:IsAutoIncrement_IsNull");
2286                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#I:IsAutoIncrement_Value");
2287                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#I:BaseSchemaName_IsNull");
2288                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#I:BaseSchemaName_Value");
2289                                 Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#I:BaseCatalogName_IsNull");
2290                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#I:BaseCatalogName_Value");
2291                                 Assert.IsFalse (pkRow.IsNull ("BaseTableName"), "#I:BaseTableName_IsNull");
2292                                 Assert.AreEqual ("employee", pkRow ["BaseTableName"], "#I:BaseTableName_Value");
2293                                 Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#I:BaseColumnName_IsNull");
2294                                 Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#I:BaseColumnName_Value");
2295
2296                                 reader = cmd.ExecuteReader (CommandBehavior.SchemaOnly);
2297                                 schema = reader.GetSchemaTable ();
2298                                 reader.Close ();
2299
2300                                 AssertSchemaTableStructure (schema, "#J:");
2301                                 Assert.AreEqual (3, schema.Rows.Count, "#J:RowCount");
2302                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
2303                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#J:ColumnName_IsNull");
2304                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#J:ColumnName_Value");
2305                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#J:ColumnOrdinal_IsNull");
2306                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#J:ColumnOrdinal_Value");
2307                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#J:ColumnSize_IsNull");
2308                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#J:ColumnSize_Value");
2309                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#J:NumericPrecision_IsNull");
2310                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#J:NumericPrecision_Value");
2311                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#J:NumericScale_IsNull");
2312                                 Assert.AreEqual (255, pkRow ["NumericScale"], "#J:NumericScale_Value");
2313                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#J:DataType_IsNull");
2314                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#J:DataType_Value");
2315                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#J:ProviderType_IsNull");
2316                                 Assert.AreEqual (8, pkRow ["ProviderType"], "#J:ProviderType_Value");
2317                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#J:IsLong_IsNull");
2318                                 Assert.AreEqual (false, pkRow ["IsLong"], "#J:IsLong_Value");
2319                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#J:AllowDBNull_IsNull");
2320                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#J:AllowDBNull_Value");
2321                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#J:IsReadOnly_IsNull");
2322                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#J:IsReadOnly_Value");
2323                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#J:IsRowVersion_IsNull");
2324                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#J:IsRowVersion_Value");
2325                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#J:IsUnique_IsNull");
2326                                 Assert.AreEqual (false, pkRow ["IsUnique"], "#J:IsUnique_Value");
2327                                 Assert.IsTrue (pkRow.IsNull ("IsKey"), "#J:IsKey_IsNull");
2328                                 Assert.AreEqual (DBNull.Value, pkRow ["IsKey"], "#J:IsKey_Value");
2329                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#J:IsAutoIncrement_IsNull");
2330                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#J:IsAutoIncrement_Value");
2331                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#J:BaseSchemaName_IsNull");
2332                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#J:BaseSchemaName_Value");
2333                                 Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#J:BaseCatalogName_IsNull");
2334                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#J:BaseCatalogName_Value");
2335                                 Assert.IsTrue (pkRow.IsNull ("BaseTableName"), "#J:BaseTableName_IsNull");
2336                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseTableName"], "#J:BaseTableName_Value");
2337                                 Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#J:BaseColumnName_IsNull");
2338                                 Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#J:BaseColumnName_Value");
2339
2340                                 reader = cmd.ExecuteReader (CommandBehavior.KeyInfo);
2341                                 schema = reader.GetSchemaTable ();
2342                                 reader.Close ();
2343
2344                                 AssertSchemaTableStructure (schema, "#K:");
2345                                 Assert.AreEqual (3, schema.Rows.Count, "#K:RowCount");
2346                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
2347                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#K:ColumnName_IsNull");
2348                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#K:ColumnName_Value");
2349                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#K:ColumnOrdinal_IsNull");
2350                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#K:ColumnOrdinal_Value");
2351                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#K:ColumnSize_IsNull");
2352                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#K:ColumnSize_Value");
2353                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#K:NumericPrecision_IsNull");
2354                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#K:NumericPrecision_Value");
2355                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#K:NumericScale_IsNull");
2356                                 Assert.AreEqual (255, pkRow ["NumericScale"], "#K:NumericScale_Value");
2357                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#K:DataType_IsNull");
2358                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#K:DataType_Value");
2359                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#K:ProviderType_IsNull");
2360                                 Assert.AreEqual (8, pkRow ["ProviderType"], "#K:ProviderType_Value");
2361                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#K:IsLong_IsNull");
2362                                 Assert.AreEqual (false, pkRow ["IsLong"], "#K:IsLong_Value");
2363                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#K:AllowDBNull_IsNull");
2364                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#K:AllowDBNull_Value");
2365                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#K:IsReadOnly_IsNull");
2366                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#K:IsReadOnly_Value");
2367                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#K:IsRowVersion_IsNull");
2368                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#K:IsRowVersion_Value");
2369                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#K:IsUnique_IsNull");
2370                                 Assert.AreEqual (false, pkRow ["IsUnique"], "#K:IsUnique_Value");
2371                                 Assert.IsFalse (pkRow.IsNull ("IsKey"), "#K:IsKey_IsNull");
2372                                 Assert.AreEqual (true, pkRow ["IsKey"], "#K:IsKey_Value");
2373                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#K:IsAutoIncrement_IsNull");
2374                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#K:IsAutoIncrement_Value");
2375                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#K:BaseSchemaName_IsNull");
2376                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#K:BaseSchemaName_Value");
2377                                 Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#K:BaseCatalogName_IsNull");
2378                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#K:BaseCatalogName_Value");
2379                                 Assert.IsFalse (pkRow.IsNull ("BaseTableName"), "#K:BaseTableName_IsNull");
2380                                 Assert.AreEqual ("employee", pkRow ["BaseTableName"], "#K:BaseTableName_Value");
2381                                 Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#K:BaseColumnName_IsNull");
2382                                 Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#K:BaseColumnName_Value");
2383
2384                                 reader = cmd.ExecuteReader ();
2385                                 schema = reader.GetSchemaTable ();
2386                                 reader.Close ();
2387
2388                                 AssertSchemaTableStructure (schema, "#L:");
2389                                 Assert.AreEqual (3, schema.Rows.Count, "#L:RowCount");
2390                                 pkRow = schema.Select ("ColumnName = 'id'") [0];
2391                                 Assert.IsFalse (pkRow.IsNull ("ColumnName"), "#L:ColumnName_IsNull");
2392                                 Assert.AreEqual ("id", pkRow ["ColumnName"], "#L:ColumnName_Value");
2393                                 Assert.IsFalse (pkRow.IsNull ("ColumnOrdinal"), "#L:ColumnOrdinal_IsNull");
2394                                 Assert.AreEqual (0, pkRow ["ColumnOrdinal"], "#L:ColumnOrdinal_Value");
2395                                 Assert.IsFalse (pkRow.IsNull ("ColumnSize"), "#L:ColumnSize_IsNull");
2396                                 Assert.AreEqual (4, pkRow ["ColumnSize"], "#L:ColumnSize_Value");
2397                                 Assert.IsFalse (pkRow.IsNull ("NumericPrecision"), "#L:NumericPrecision_IsNull");
2398                                 Assert.AreEqual (10, pkRow ["NumericPrecision"], "#L:NumericPrecision_Value");
2399                                 Assert.IsFalse (pkRow.IsNull ("NumericScale"), "#L:NumericScale_IsNull");
2400                                 Assert.AreEqual (255, pkRow ["NumericScale"], "#L:NumericScale_Value");
2401                                 Assert.IsFalse (pkRow.IsNull ("DataType"), "#L:DataType_IsNull");
2402                                 Assert.AreEqual (typeof (int), pkRow ["DataType"], "#L:DataType_Value");
2403                                 Assert.IsFalse (pkRow.IsNull ("ProviderType"), "#L:ProviderType_IsNull");
2404                                 Assert.AreEqual (8, pkRow ["ProviderType"], "#L:ProviderType_Value");
2405                                 Assert.IsFalse (pkRow.IsNull ("IsLong"), "#L:IsLong_IsNull");
2406                                 Assert.AreEqual (false, pkRow ["IsLong"], "#L:IsLong_Value");
2407                                 Assert.IsFalse (pkRow.IsNull ("AllowDBNull"), "#L:AllowDBNull_IsNull");
2408                                 Assert.AreEqual (false, pkRow ["AllowDBNull"], "#L:AllowDBNull_Value");
2409                                 Assert.IsFalse (pkRow.IsNull ("IsReadOnly"), "#L:IsReadOnly_IsNull");
2410                                 Assert.AreEqual (false, pkRow ["IsReadOnly"], "#L:IsReadOnly_Value");
2411                                 Assert.IsFalse (pkRow.IsNull ("IsRowVersion"), "#L:IsRowVersion_IsNull");
2412                                 Assert.AreEqual (false, pkRow ["IsRowVersion"], "#L:IsRowVersion_Value");
2413                                 Assert.IsFalse (pkRow.IsNull ("IsUnique"), "#L:IsUnique_IsNull");
2414                                 Assert.AreEqual (false, pkRow ["IsUnique"], "#L:IsUnique_Value");
2415                                 Assert.IsTrue (pkRow.IsNull ("IsKey"), "#L:IsKey_IsNull");
2416                                 Assert.AreEqual (DBNull.Value, pkRow ["IsKey"], "#L:IsKey_Value");
2417                                 Assert.IsFalse (pkRow.IsNull ("IsAutoIncrement"), "#L:IsAutoIncrement_IsNull");
2418                                 Assert.AreEqual (false, pkRow ["IsAutoIncrement"], "#L:IsAutoIncrement_Value");
2419                                 Assert.IsTrue (pkRow.IsNull ("BaseSchemaName"), "#L:BaseSchemaName_IsNull");
2420                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseSchemaName"], "#L:BaseSchemaName_Value");
2421                                 Assert.IsTrue (pkRow.IsNull ("BaseCatalogName"), "#L:BaseCatalogName_IsNull");
2422                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseCatalogName"], "#L:BaseCatalogName_Value");
2423                                 Assert.IsTrue (pkRow.IsNull ("BaseTableName"), "#L:BaseTableName_IsNull");
2424                                 Assert.AreEqual (DBNull.Value, pkRow ["BaseTableName"], "#L:BaseTableName_Value");
2425                                 Assert.IsFalse (pkRow.IsNull ("BaseColumnName"), "#L:BaseColumnName_IsNull");
2426                                 Assert.AreEqual ("id", pkRow ["BaseColumnName"], "#L:BaseColumnName_Value");
2427                         } finally {
2428                                 if (cmd != null)
2429                                         cmd.Dispose ();
2430                                 if (reader != null)
2431                                         reader.Close ();
2432                                 ConnectionManager.Singleton.CloseConnection ();
2433                         }
2434                 }
2435
2436                 [Test]
2437                 public void GetSchemaTableTest ()
2438                 {
2439                         cmd.CommandText = "Select type_decimal1 as decimal,id,10 ";
2440                         cmd.CommandText += "from numeric_family where id=1";
2441                         reader = cmd.ExecuteReader (CommandBehavior.KeyInfo);
2442                         DataTable schemaTable  = reader.GetSchemaTable ();
2443                         DataRow row0 = schemaTable.Rows[0]; 
2444                         DataRow row1 = schemaTable.Rows[1]; 
2445                 
2446                         Assert.AreEqual ("decimal", row0["ColumnName"], "#1");
2447                         Assert.AreEqual ("", schemaTable.Rows[2]["ColumnName"], "#2");
2448
2449                         Assert.AreEqual (0, row0["ColumnOrdinal"], "#2");
2450                         Assert.AreEqual (17, row0["ColumnSize"], "#3");
2451                         if (ClientVersion == 7)
2452                                 Assert.AreEqual (28, row0["NumericPrecision"], "#4"); 
2453                         else
2454                                 Assert.AreEqual (38, row0 ["NumericPrecision"], "#4"); 
2455                         Assert.AreEqual (0, row0["NumericScale"], "#5");
2456
2457                         Assert.AreEqual (false, row0["IsUnique"], "#6"); 
2458                         // msdotnet returns IsUnique as false for Primary key
2459                         // even though table consists of a single Primary Key
2460                         //Assert.AreEqual (true, row1["IsUnique"], "#7"); 
2461                         Assert.AreEqual (false, row0["IsKey"], "#8"); 
2462                         Assert.AreEqual (true, row1["IsKey"], "#9"); 
2463
2464                         //Assert.AreEqual ("servername", row0["BaseServerName"], "#10");
2465                         //Assert.AreEqual ("monotest", row0["BaseCatalogName"], "#11");  
2466                         Assert.AreEqual ("type_decimal1", row0["BaseColumnName"], "#12");
2467                         //Assert.IsNull(row0["BaseSchemaName"], "#13");
2468                         Assert.AreEqual ("numeric_family", row0["BaseTableName"], "#14");
2469                         Assert.AreEqual (typeof (Decimal), row0["DataType"], "#15"); 
2470                         Assert.AreEqual (true, row0["AllowDBNull"], "#16");
2471                         Assert.AreEqual (false, row1["AllowDBNull"], "#17");
2472                         //Assert.IsNull(row0["ProviderType"], "#18");
2473                         Assert.AreEqual (true, row0["IsAliased"], "#19");
2474                         Assert.AreEqual (false, row1["IsAliased"], "#20");
2475
2476                         Assert.AreEqual (false, row0["IsExpression"], "#21"); 
2477                         Assert.AreEqual (false, row0["IsIdentity"], "#22"); 
2478                         Assert.AreEqual (false, row0["IsAutoIncrement"], "#23");
2479                         Assert.AreEqual (false, row0["IsRowVersion"], "#24"); 
2480                         Assert.AreEqual (false, row0["IsHidden"], "#25"); 
2481                         Assert.AreEqual (false, row0["IsLong"], "#26"); 
2482                         Assert.AreEqual (false, row0["IsReadOnly"], "#27"); 
2483                         Assert.AreEqual (true, schemaTable.Rows[2]["IsReadOnly"], "#27"); 
2484
2485                         // Test Exception is thrown when reader is closed
2486                         reader.Close ();
2487                         try {
2488                                 reader.GetSchemaTable ();
2489                                 Assert.Fail ("#28 Exception shud be thrown" );
2490                         } catch (InvalidOperationException e) {
2491                                 Assert.AreEqual (typeof (InvalidOperationException), e.GetType(),
2492                                         "#29 Incorrect Exception");
2493                         }
2494                 }
2495
2496                 [Test]
2497                 public void GetDataTypeNameTest ()
2498                 {
2499                         cmd.CommandText = "Select id, type_tinyint, 10,null from numeric_family where id=1";
2500                         reader = cmd.ExecuteReader ();
2501
2502                         Assert.AreEqual ("tinyint", reader.GetDataTypeName(1), "#1");
2503                         Assert.AreEqual ("int", reader.GetDataTypeName(2), "#2");
2504                         //need check on windows 
2505                         Assert.AreEqual ("int", reader.GetDataTypeName(3), "#3");
2506                         try {
2507                                 reader.GetDataTypeName (10);
2508                                 Assert.Fail ("#4 Exception shud be thrown");
2509                         } catch (IndexOutOfRangeException e) {
2510                                 Assert.AreEqual (typeof (IndexOutOfRangeException), e.GetType (),
2511                                         "#5 Incorrect Exception : " + e);
2512                         }
2513                 }
2514
2515                 [Test]
2516                 public void GetFieldType_BigInt ()
2517                 {
2518                         if (ClientVersion <= 7)
2519                                 Assert.Ignore ("BigInt data type is not supported.");
2520
2521                         cmd.CommandText = "SELECT type_bigint FROM numeric_family WHERE id = 1";
2522
2523                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2524                                 Assert.AreEqual (typeof (long), rdr.GetFieldType (0));
2525                         }
2526                 }
2527
2528                 [Test]
2529                 public void GetFieldType_Binary ()
2530                 {
2531                         cmd.CommandText = "SELECT type_binary FROM binary_family WHERE id = 1";
2532
2533                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2534                                 Assert.AreEqual (typeof (byte []), rdr.GetFieldType (0));
2535                         }
2536                 }
2537
2538                 [Test]
2539                 public void GetFieldType_Bit ()
2540                 {
2541                         cmd.CommandText = "SELECT type_bit FROM numeric_family WHERE id = 1";
2542
2543                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2544                                 Assert.AreEqual (typeof (bool), rdr.GetFieldType (0));
2545                         }
2546                 }
2547
2548                 [Test]
2549                 public void GetFieldType_Char ()
2550                 {
2551                         cmd.CommandText = "SELECT type_char FROM string_family WHERE id = 1";
2552
2553                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2554                                 Assert.AreEqual (typeof (string), rdr.GetFieldType (0));
2555                         }
2556                 }
2557
2558                 [Test]
2559                 public void GetFieldType_Date ()
2560                 {
2561                         // TODO
2562                 }
2563
2564                 [Test]
2565                 public void GetFieldType_DateTime ()
2566                 {
2567                         cmd.CommandText = "SELECT type_datetime FROM datetime_family WHERE id = 1";
2568
2569                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2570                                 Assert.AreEqual (typeof (DateTime), rdr.GetFieldType (0));
2571                         }
2572                 }
2573
2574                 [Test]
2575                 public void GetFieldType_Decimal ()
2576                 {
2577                         cmd.CommandText = "SELECT type_decimal1 FROM numeric_family WHERE id = 1";
2578
2579                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2580                                 Assert.AreEqual (typeof (decimal), rdr.GetFieldType (0));
2581                         }
2582
2583                         cmd.CommandText = "SELECT type_decimal2 FROM numeric_family WHERE id = 1";
2584
2585                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2586                                 Assert.AreEqual (typeof (decimal), rdr.GetFieldType (0));
2587                         }
2588
2589                         cmd.CommandText = "SELECT type_numeric1 FROM numeric_family WHERE id = 1";
2590
2591                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2592                                 Assert.AreEqual (typeof (decimal), rdr.GetFieldType (0));
2593                         }
2594
2595                         cmd.CommandText = "SELECT type_numeric2 FROM numeric_family WHERE id = 1";
2596
2597                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2598                                 Assert.AreEqual (typeof (decimal), rdr.GetFieldType (0));
2599                         }
2600                 }
2601
2602                 [Test]
2603                 public void GetFieldType_Float ()
2604                 {
2605                         cmd.CommandText = "SELECT type_double FROM numeric_family WHERE id = 1";
2606
2607                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2608                                 Assert.AreEqual (typeof (double), rdr.GetFieldType (0));
2609                         }
2610                 }
2611
2612                 [Test]
2613                 public void GetFieldType_Image ()
2614                 {
2615                         cmd.CommandText = "SELECT type_tinyblob FROM binary_family WHERE id = 1";
2616
2617                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2618                                 Assert.AreEqual (typeof (byte []), rdr.GetFieldType (0));
2619                         }
2620                 }
2621
2622                 [Test]
2623                 public void GetFieldType_Int ()
2624                 {
2625                         cmd.CommandText = "SELECT type_int FROM numeric_family WHERE id = 1";
2626
2627                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2628                                 Assert.AreEqual (typeof (int), rdr.GetFieldType (0));
2629                         }
2630                 }
2631
2632                 [Test]
2633                 public void GetFieldType_Money ()
2634                 {
2635                         cmd.CommandText = "SELECT type_money FROM numeric_family WHERE id = 1";
2636
2637                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2638                                 Assert.AreEqual (typeof (decimal), rdr.GetFieldType (0));
2639                         }
2640                 }
2641
2642                 [Test]
2643                 public void GetFieldType_NChar ()
2644                 {
2645                         cmd.CommandText = "SELECT type_nchar FROM string_family WHERE id = 1";
2646
2647                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2648                                 Assert.AreEqual (typeof (string), rdr.GetFieldType (0));
2649                         }
2650                 }
2651
2652                 [Test]
2653                 public void GetFieldType_NText ()
2654                 {
2655                         cmd.CommandText = "SELECT type_ntext FROM string_family WHERE id = 1";
2656
2657                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2658                                 Assert.AreEqual (typeof (string), rdr.GetFieldType (0));
2659                         }
2660                 }
2661
2662                 [Test]
2663                 public void GetFieldType_NVarChar ()
2664                 {
2665                         cmd.CommandText = "SELECT type_nvarchar FROM string_family WHERE id = 1";
2666
2667                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2668                                 Assert.AreEqual (typeof (string), rdr.GetFieldType (0));
2669                         }
2670                 }
2671
2672                 [Test]
2673                 public void GetFieldType_Real ()
2674                 {
2675                         cmd.CommandText = "SELECT type_float FROM numeric_family WHERE id = 1";
2676
2677                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2678                                 Assert.AreEqual (typeof (float), rdr.GetFieldType (0));
2679                         }
2680
2681                 }
2682
2683                 [Test]
2684                 public void GetFieldType_SmallDateTime ()
2685                 {
2686                         cmd.CommandText = "SELECT type_smalldatetime FROM datetime_family WHERE id = 1";
2687
2688                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2689                                 Assert.AreEqual (typeof (DateTime), rdr.GetFieldType (0));
2690                         }
2691                 }
2692
2693                 [Test]
2694                 public void GetFieldType_SmallInt ()
2695                 {
2696                         cmd.CommandText = "SELECT type_smallint FROM numeric_family WHERE id = 1";
2697
2698                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2699                                 Assert.AreEqual (typeof (short), rdr.GetFieldType (0));
2700                         }
2701                 }
2702
2703                 [Test]
2704                 public void GetFieldType_SmallMoney ()
2705                 {
2706                         cmd.CommandText = "SELECT type_smallmoney FROM numeric_family WHERE id = 1";
2707
2708                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2709                                 Assert.AreEqual (typeof (decimal), rdr.GetFieldType (0));
2710                         }
2711                 }
2712
2713                 [Test]
2714                 public void GetFieldType_Text ()
2715                 {
2716                         cmd.CommandText = "SELECT type_text FROM string_family WHERE id = 1";
2717
2718                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2719                                 Assert.AreEqual (typeof (string), rdr.GetFieldType (0));
2720                         }
2721                 }
2722
2723                 [Test]
2724                 public void GetFieldType_Time ()
2725                 {
2726                         // TODO
2727                 }
2728
2729                 [Test]
2730                 public void GetFieldType_Timestamp ()
2731                 {
2732                         cmd.CommandText = "SELECT type_timestamp FROM binary_family WHERE id = 1";
2733
2734                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2735                                 Assert.AreEqual (typeof (byte []), rdr.GetFieldType (0));
2736                         }
2737                 }
2738
2739                 [Test]
2740                 public void GetFieldType_TinyInt ()
2741                 {
2742                         cmd.CommandText = "SELECT type_tinyint FROM numeric_family WHERE id = 1";
2743
2744                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2745                                 Assert.AreEqual (typeof (byte), rdr.GetFieldType (0));
2746                         }
2747                 }
2748
2749                 [Test]
2750                 public void GetFieldType_Udt ()
2751                 {
2752                         // TODO
2753                 }
2754
2755                 [Test]
2756                 public void GetFieldType_UniqueIdentifier ()
2757                 {
2758                         cmd.CommandText = "SELECT type_guid FROM string_family WHERE id = 1";
2759
2760                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2761                                 Assert.AreEqual (typeof (Guid), rdr.GetFieldType (0));
2762                         }
2763                 }
2764
2765                 [Test]
2766                 public void GetFieldType_VarBinary ()
2767                 {
2768                         cmd.CommandText = "SELECT type_varbinary FROM binary_family WHERE id = 1";
2769
2770                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2771                                 Assert.AreEqual (typeof (byte []), rdr.GetFieldType (0));
2772                         }
2773                 }
2774
2775                 [Test]
2776                 public void GetFieldType_VarChar ()
2777                 {
2778                         cmd.CommandText = "SELECT type_varchar FROM string_family WHERE id = 1";
2779
2780                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
2781                                 Assert.AreEqual (typeof (string), rdr.GetFieldType (0));
2782                         }
2783                 }
2784
2785                 // Need to populate the data from a config file
2786                 // Will be replaced later 
2787                 void validateData(string sqlQuery, DataTable table)
2788                 {
2789                         string fmt = "#TAB[{0}] ROW[{1}] COL[{2}] Data Mismatch";
2790
2791                         int noOfColumns = table.Columns.Count ;
2792                         int i=0;
2793
2794                         cmd.CommandText = sqlQuery ;
2795                         reader = cmd.ExecuteReader ();
2796
2797                         while (reader.Read ()){
2798                                 for (int j=1; j< noOfColumns ; ++j) {
2799                                         Assert.AreEqual (table.Rows[i][j], reader[j],
2800                                                 String.Format (fmt, table.TableName, i+1, j));
2801                                 }
2802                                 
2803                                 i++;
2804                         }
2805                         reader.Close ();
2806                 }
2807
2808                 [Test]
2809                 public void NumericDataValidation ()
2810                 {
2811                         validateData ("select * from numeric_family order by id ASC",
2812                                 numericDataTable);
2813                 }
2814                 
2815                 [Test]
2816                 public void StringDataValidation ()
2817                 {
2818                         validateData ("select * from string_family order by id ASC",
2819                                 stringDataTable);
2820                 }
2821
2822                 [Test]
2823                 public void BinaryDataValidation ()
2824                 {
2825                         validateData ("select * from binary_family order by id ASC",
2826                                 binaryDataTable);
2827                 }
2828
2829                 [Test]
2830                 public void DatetimeDataValidation ()
2831                 {
2832                         validateData ("select * from datetime_family order by id ASC",
2833                                 datetimeDataTable);
2834                 }
2835
2836 #if NET_2_0
2837                 string connectionString = ConnectionManager.Singleton.ConnectionString;
2838
2839                 //FIXME : Add more test cases
2840                 [Test]
2841                 public void GetProviderSpecificFieldTypeTest ()
2842                 {
2843                         using (SqlConnection conn = new SqlConnection (connectionString)) {
2844                                 conn.Open ();
2845                                 SqlCommand cmd = conn.CreateCommand ();
2846                                 cmd.CommandText = "SELECT * FROM employee";
2847                                 using (SqlDataReader rdr = cmd.ExecuteReader ()) {
2848                                         rdr.Read();
2849                                         Assert.AreEqual (6, rdr.FieldCount, "#A1");
2850                                         Assert.AreEqual(typeof(SqlInt32), rdr.GetProviderSpecificFieldType (0), "#A2");
2851                                         Assert.AreEqual(typeof(SqlString), rdr.GetProviderSpecificFieldType (1), "#A3");
2852                                         Assert.AreEqual(typeof(SqlString), rdr.GetProviderSpecificFieldType (2), "#A4");
2853                                         Assert.AreEqual(typeof(SqlDateTime), rdr.GetProviderSpecificFieldType (3), "#A5");
2854                                         Assert.AreEqual(typeof(SqlDateTime), rdr.GetProviderSpecificFieldType (4), "#A6");
2855                                         Assert.AreEqual(typeof(SqlString), rdr.GetProviderSpecificFieldType (5), "#A7");
2856                                 }
2857                                 cmd.CommandText = "SELECT * FROM numeric_family";
2858                                 using (SqlDataReader rdr = cmd.ExecuteReader ()) {
2859                                         rdr.Read();
2860                                         Assert.AreEqual (15, rdr.FieldCount, "#B1");
2861                                         Assert.AreEqual(typeof (SqlInt32), rdr.GetProviderSpecificFieldType(0), "#B2");
2862                                         Assert.AreEqual(typeof (SqlBoolean), rdr.GetProviderSpecificFieldType(1), "#B3");
2863                                         Assert.AreEqual(typeof (SqlByte), rdr.GetProviderSpecificFieldType(2), "#B4");
2864                                         Assert.AreEqual(typeof (SqlInt16), rdr.GetProviderSpecificFieldType(3), "#B5");
2865                                         Assert.AreEqual(typeof (SqlInt32), rdr.GetProviderSpecificFieldType(4), "#B6");
2866                                         Assert.AreEqual(typeof (SqlInt64), rdr.GetProviderSpecificFieldType(5), "#B7");
2867                                         Assert.AreEqual(typeof (SqlDecimal), rdr.GetProviderSpecificFieldType(6), "#B8");
2868                                         Assert.AreEqual(typeof (SqlDecimal), rdr.GetProviderSpecificFieldType(7), "#B9");
2869                                         Assert.AreEqual(typeof (SqlDecimal), rdr.GetProviderSpecificFieldType(8), "#B10");
2870                                         Assert.AreEqual(typeof (SqlDecimal), rdr.GetProviderSpecificFieldType(9), "#B11");
2871                                         Assert.AreEqual(typeof (SqlMoney), rdr.GetProviderSpecificFieldType(10), "#B12");
2872                                         Assert.AreEqual(typeof (SqlMoney), rdr.GetProviderSpecificFieldType(11), "#B13");
2873                                         Assert.AreEqual(typeof (SqlSingle), rdr.GetProviderSpecificFieldType(12), "#B14");
2874                                         Assert.AreEqual(typeof (SqlDouble), rdr.GetProviderSpecificFieldType(13), "#B15");
2875                                         Assert.AreEqual(typeof (SqlInt32), rdr.GetProviderSpecificFieldType(14), "#B16");
2876                                 }
2877                         }
2878                 }
2879
2880                 //FIXME : Add more test cases
2881                 [Test]
2882                 public void GetProviderSpecificValueTest ()
2883                 {
2884                         using (SqlConnection conn = new SqlConnection (connectionString)) {
2885                                 conn.Open ();
2886                                 SqlCommand cmd = conn.CreateCommand ();
2887                                 cmd.CommandText = "SELECT * FROM employee";
2888                                 using (SqlDataReader rdr = cmd.ExecuteReader ()) {
2889                                         rdr.Read();
2890                                         Assert.AreEqual (6, rdr.FieldCount, "#1");
2891                                         Assert.AreEqual((SqlInt32)1,rdr.GetProviderSpecificValue(0), "#2");
2892                                         Assert.AreEqual((SqlString)"suresh",rdr.GetProviderSpecificValue(1), "#3");
2893                                         Assert.AreEqual((SqlDateTime) new DateTime (1978, 8, 22), rdr.GetProviderSpecificValue(3), "#4");
2894                                 }
2895                         }
2896                 }
2897
2898                 [Test]
2899                 public void GetProviderSpecificValueLowerBoundaryTest ()
2900                 {
2901                         using (SqlConnection conn = new SqlConnection (connectionString)) {
2902                                 conn.Open ();
2903                                 SqlCommand cmd = conn.CreateCommand ();
2904                                 cmd.CommandText = "SELECT * FROM employee";
2905                                 using (SqlDataReader rdr = cmd.ExecuteReader ()) {
2906                                         rdr.Read();
2907                                         try {
2908                                                 object value = rdr.GetProviderSpecificValue (-1);
2909                                                 Assert.Fail ("#1:" + value);
2910                                         } catch (IndexOutOfRangeException) {
2911                                                 Assert.AreEqual((SqlInt32) 1, rdr.GetProviderSpecificValue (0), "#2");
2912                                                 Assert.AreEqual((SqlString) "suresh", rdr.GetProviderSpecificValue(1), "#3");
2913                                                 Assert.AreEqual((SqlDateTime) new DateTime (1978, 8, 22), rdr.GetProviderSpecificValue (3), "#4");
2914                                         }
2915                                 }
2916                         }
2917                 }
2918
2919                 [Test]
2920                 public void GetProviderSpecificValueUpperBoundaryTest ()
2921                 {
2922                         using (SqlConnection conn = new SqlConnection (connectionString)) {
2923                                 conn.Open ();
2924                                 SqlCommand cmd = conn.CreateCommand ();
2925                                 cmd.CommandText = "SELECT * FROM employee";
2926                                 using (SqlDataReader rdr = cmd.ExecuteReader ()) {
2927                                         rdr.Read();
2928                                         try {
2929                                                 object value = rdr.GetProviderSpecificValue (rdr.FieldCount);
2930                                                 Assert.Fail ("#1:" + value);
2931                                         } catch (IndexOutOfRangeException) {
2932                                                 Assert.AreEqual((SqlInt32) 1, rdr.GetProviderSpecificValue (0), "#2");
2933                                                 Assert.AreEqual((SqlString) "suresh", rdr.GetProviderSpecificValue (1), "#3");
2934                                                 Assert.AreEqual((SqlDateTime) new DateTime (1978, 8, 22), rdr.GetProviderSpecificValue (3), "#4");
2935                                         }
2936                                 }
2937                         }
2938                 }
2939
2940                 //FIXME : Add more test cases
2941                 [Test]
2942                 public void GetProviderSpecificValuesTest ()
2943                 {
2944                         using (SqlConnection conn = new SqlConnection (connectionString)) {
2945                                 conn.Open ();
2946                                 SqlCommand cmd = conn.CreateCommand ();
2947                                 cmd.CommandText = "SELECT * FROM employee";
2948                                 Object [] psValues = new Object[6];
2949                                 using (SqlDataReader rdr = cmd.ExecuteReader ()) {
2950                                         rdr.Read();
2951                                         int count = rdr.GetProviderSpecificValues (psValues);
2952                                         Assert.AreEqual (6, count, "#1");
2953                                         Assert.AreEqual ((SqlInt32) 1, psValues [0], "#2");
2954                                         Assert.AreEqual ((SqlString) "suresh", psValues [1], "#3");
2955                                         Assert.AreEqual ((SqlString) "kumar", psValues [2], "#4");
2956                                         Assert.AreEqual ((SqlDateTime) new DateTime (1978, 8, 22), psValues [3], "#5");
2957                                         Assert.AreEqual ((SqlDateTime) new DateTime (2001, 03, 12), psValues [4], "#6");
2958                                         Assert.AreEqual ((SqlString) "suresh@gmail.com", psValues [5], "#7");
2959                                 }
2960                         }
2961                 }
2962
2963                 [Test]
2964                 public void GetProviderSpecificValues_Values_Null ()
2965                 {
2966                         cmd.CommandText = "SELECT * FROM employee";
2967                         reader = cmd.ExecuteReader ();
2968                         reader.Read ();
2969
2970                         try {
2971                                 reader.GetProviderSpecificValues (null);
2972                                 Assert.Fail ("#1");
2973                         } catch (ArgumentNullException ex) {
2974                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
2975                                 Assert.IsNull (ex.InnerException, "#3");
2976                                 Assert.IsNotNull (ex.Message, "#4");
2977                                 Assert.AreEqual ("values", ex.ParamName, "#5");
2978                         }
2979                 }
2980
2981                 [Test]
2982                 public void GetProviderSpecificValuesSmallArrayTest ()
2983                 {
2984                         using (SqlConnection conn = new SqlConnection (connectionString)) {
2985                                 conn.Open ();
2986                                 SqlCommand cmd = conn.CreateCommand ();
2987                                 cmd.CommandText = "SELECT * FROM employee";
2988                                 Object [] psValues = new Object[2];
2989                                 using (SqlDataReader rdr = cmd.ExecuteReader ()) {
2990                                         rdr.Read();
2991                                         int count = rdr.GetProviderSpecificValues (psValues);
2992                                         Assert.AreEqual (2, count, "#1");
2993                                         Assert.AreEqual ((SqlInt32) 1, psValues [0], "#2");
2994                                         Assert.AreEqual ((SqlString) "suresh", psValues [1], "#3");
2995                                 }
2996                         }
2997                 }
2998
2999                 [Test]
3000                 public void GetProviderSpecificValuesLargeArrayTest ()
3001                 {
3002                         using (SqlConnection conn = new SqlConnection (connectionString)) {
3003                                 conn.Open ();
3004                                 SqlCommand cmd = conn.CreateCommand ();
3005                                 cmd.CommandText = "SELECT * FROM employee";
3006                                 Object [] psValues = new Object[10];
3007                                 using (SqlDataReader rdr = cmd.ExecuteReader ()) {
3008                                         rdr.Read();
3009                                         int count = rdr.GetProviderSpecificValues (psValues);
3010                                         Assert.AreEqual (6, count, "#1");
3011                                         Assert.AreEqual ((SqlInt32) 1, psValues [0], "#2");
3012                                         Assert.AreEqual ((SqlString) "suresh", psValues [1], "#3");
3013                                         Assert.AreEqual ((SqlString) "kumar", psValues [2], "#4");
3014                                         Assert.AreEqual ((SqlDateTime) new DateTime (1978, 8, 22), psValues [3], "#5");
3015                                         Assert.AreEqual ((SqlDateTime) new DateTime (2001, 03, 12), psValues [4], "#6");
3016                                         Assert.AreEqual ((SqlString) "suresh@gmail.com", psValues [5], "#7");
3017                                         Assert.IsNull (psValues [6], "#8");
3018                                         Assert.IsNull (psValues [7], "#9");
3019                                         Assert.IsNull (psValues [8], "#10");
3020                                         Assert.IsNull (psValues [9], "#11");
3021                                 }
3022                         }
3023                 }
3024
3025                 [Test]
3026                 public void GetSqlBytesTest ()
3027                 {
3028                         using (SqlConnection conn = new SqlConnection (connectionString)) {
3029                                 conn.Open ();
3030                                 SqlCommand cmd = conn.CreateCommand ();
3031                                 cmd.CommandText = "SELECT * FROM binary_family where id=1";
3032                                 using (SqlDataReader rdr = cmd.ExecuteReader ()) {
3033                                         rdr.Read();
3034                                         Assert.AreEqual (8, rdr.FieldCount);
3035                                         
3036                                         SqlBytes sb = rdr.GetSqlBytes (1);
3037                                         Assert.AreEqual (8, sb.Length, "#A1");
3038                                         Assert.AreEqual (53, sb [0], "#A2");
3039                                         Assert.AreEqual (0, sb [1], "#A3");
3040                                         Assert.AreEqual (0, sb [2], "#A4");
3041                                         Assert.AreEqual (0, sb [3], "#A5");
3042                                         Assert.AreEqual (0, sb [4], "#A6");
3043                                         Assert.AreEqual (0, sb [5], "#A7");
3044                                         Assert.AreEqual (0, sb [6], "#A8");
3045                                         Assert.AreEqual (0, sb [7], "#A9");
3046
3047                                         sb = rdr.GetSqlBytes (2);
3048                                         Assert.AreEqual (typeof (SqlBinary), rdr.GetSqlValue (2).GetType (), "B1#");
3049                                         Assert.AreEqual (33, sb.Length, "#B2");
3050                                         Assert.AreEqual (48, sb [0], "#B3");
3051                                         Assert.AreEqual (49, sb [1], "#B4");
3052                                         Assert.AreEqual (50, sb [2], "#B5");
3053                                         Assert.AreEqual (53, sb [15], "#B6");
3054                                         Assert.AreEqual (57, sb [29], "#B7");
3055                                 }
3056                         }
3057                         
3058                 }
3059
3060 #endif // NET_2_0
3061
3062                 static void AssertSchemaTableStructure (DataTable schemaTable, string prefix)
3063                 {
3064                         object [] [] columns = {
3065                                 new object [] { "ColumnName", typeof (string) },
3066                                 new object [] { "ColumnOrdinal", typeof (int) },
3067                                 new object [] { "ColumnSize", typeof (int) },
3068                                 new object [] { "NumericPrecision", typeof (short) },
3069                                 new object [] { "NumericScale", typeof (short) },
3070                                 new object [] { "IsUnique", typeof (bool) },
3071                                 new object [] { "IsKey", typeof (bool) },
3072                                 new object [] { "BaseServerName", typeof (string) },
3073                                 new object [] { "BaseCatalogName", typeof (string) },
3074                                 new object [] { "BaseColumnName", typeof (string) },
3075                                 new object [] { "BaseSchemaName", typeof (string) },
3076                                 new object [] { "BaseTableName", typeof (string) },
3077 #if NET_2_0
3078                                 new object [] { "DataType", typeof (Type) },
3079 #else
3080                                 new object [] { "DataType", typeof (object) },
3081 #endif
3082                                 new object [] { "AllowDBNull", typeof (bool) },
3083                                 new object [] { "ProviderType", typeof (int) },
3084                                 new object [] { "IsAliased", typeof (bool) },
3085                                 new object [] { "IsExpression", typeof (bool) },
3086                                 new object [] { "IsIdentity", typeof (bool) },
3087                                 new object [] { "IsAutoIncrement", typeof (bool) },
3088                                 new object [] { "IsRowVersion", typeof (bool) },
3089                                 new object [] { "IsHidden", typeof (bool) },
3090                                 new object [] { "IsLong", typeof (bool) },
3091                                 new object [] { "IsReadOnly", typeof (bool) },
3092 #if NET_2_0
3093                                 new object [] { "ProviderSpecificDataType", typeof (Type) },
3094                                 new object [] { "DataTypeName", typeof (string) },
3095                                 new object [] { "XmlSchemaCollectionDatabase", typeof (string) },
3096                                 new object [] { "XmlSchemaCollectionOwningSchema", typeof (string) },
3097                                 new object [] { "XmlSchemaCollectionName", typeof (string) },
3098                                 new object [] { "UdtAssemblyQualifiedName", typeof (string) },
3099                                 new object [] { "NonVersionedProviderType", typeof (int) },
3100                                 new object [] { "IsColumnSet", typeof (bool) }
3101 #endif
3102                                 };
3103
3104                         Assert.AreEqual (columns.Length, schemaTable.Columns.Count, prefix);
3105
3106                         for (int i = 0; i < columns.Length; i++) {
3107                                 DataColumn col = schemaTable.Columns [i];
3108                                 Assert.IsTrue (col.AllowDBNull, prefix + "AllowDBNull (" + i + ")");
3109                                 Assert.AreEqual (columns [i] [0], col.ColumnName, prefix + "ColumnName (" + i + ")");
3110                                 Assert.AreEqual (columns [i] [1], col.DataType, prefix + "DataType (" + i + ")");
3111                         }
3112                 }
3113
3114                 int ClientVersion {
3115                         get {
3116                                 return (engine.ClientVersion);
3117                         }
3118                 }
3119         }
3120
3121         [TestFixture]
3122         [Category ("sqlserver")]
3123         public class SqlDataReaderSchemaTest
3124         {
3125                 SqlConnection conn;
3126                 SqlCommand cmd;
3127                 EngineConfig engine;
3128
3129                 [SetUp]
3130                 public void SetUp ()
3131                 {
3132                         conn = (SqlConnection) ConnectionManager.Singleton.Connection;
3133                         ConnectionManager.Singleton.OpenConnection ();
3134                         cmd = conn.CreateCommand ();
3135                         engine = ConnectionManager.Singleton.Engine;
3136                 }
3137
3138                 [TearDown]
3139                 public void TearDown ()
3140                 {
3141                         if (cmd != null)
3142                                 cmd.Dispose ();
3143                         ConnectionManager.Singleton.CloseConnection ();
3144                 }
3145
3146                 [Test]
3147                 public void ColumnSize_BigInt ()
3148                 {
3149                         if (ClientVersion <= 7)
3150                                 Assert.Ignore ("BigInt data type is not supported.");
3151
3152                         cmd.CommandText = "SELECT type_bigint FROM numeric_family WHERE id = 1";
3153
3154                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3155                                 DataTable schemaTable = rdr.GetSchemaTable ();
3156                                 DataRow row = schemaTable.Rows [0];
3157                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3158                                 // we only support TDS 7.0, which returns bigint data values as decimal(19,0)
3159                                 if (ClientVersion > 7)
3160                                         Assert.AreEqual (8, row ["ColumnSize"], "Value");
3161                                 else
3162                                         Assert.AreEqual (17, row ["ColumnSize"], "Value");
3163                         }
3164                 }
3165
3166                 [Test]
3167                 public void ColumnSize_Binary ()
3168                 {
3169                         cmd.CommandText = "SELECT type_binary FROM binary_family WHERE id = 1";
3170
3171                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3172                                 DataTable schemaTable = rdr.GetSchemaTable ();
3173                                 DataRow row = schemaTable.Rows [0];
3174                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3175                                 Assert.AreEqual (8, row ["ColumnSize"], "Value");
3176                         }
3177                 }
3178
3179                 [Test]
3180                 public void ColumnSize_Bit ()
3181                 {
3182                         cmd.CommandText = "SELECT type_bit FROM numeric_family WHERE id = 1";
3183
3184                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3185                                 DataTable schemaTable = rdr.GetSchemaTable ();
3186                                 DataRow row = schemaTable.Rows [0];
3187                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3188                                 Assert.AreEqual (1, row ["ColumnSize"], "Value");
3189                         }
3190                 }
3191
3192                 [Test]
3193                 public void ColumnSize_Char ()
3194                 {
3195                         cmd.CommandText = "SELECT type_char FROM string_family WHERE id = 1";
3196
3197                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3198                                 DataTable schemaTable = rdr.GetSchemaTable ();
3199                                 DataRow row = schemaTable.Rows [0];
3200                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3201                                 Assert.AreEqual (10, row ["ColumnSize"], "Value");
3202                         }
3203                 }
3204
3205                 [Test]
3206                 public void ColumnSize_Date ()
3207                 {
3208                         // TODO
3209                 }
3210
3211                 [Test]
3212                 public void ColumnSize_DateTime ()
3213                 {
3214                         cmd.CommandText = "SELECT type_datetime FROM datetime_family WHERE id = 1";
3215
3216                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3217                                 DataTable schemaTable = rdr.GetSchemaTable ();
3218                                 DataRow row = schemaTable.Rows [0];
3219                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3220                                 Assert.AreEqual (8, row ["ColumnSize"], "Value");
3221                         }
3222                 }
3223
3224                 [Test]
3225                 public void ColumnSize_Decimal ()
3226                 {
3227                         cmd.CommandText = "SELECT type_decimal1 FROM numeric_family WHERE id = 1";
3228
3229                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3230                                 DataTable schemaTable = rdr.GetSchemaTable ();
3231                                 DataRow row = schemaTable.Rows [0];
3232                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "#A:IsNull");
3233                                 Assert.AreEqual (17, row ["ColumnSize"], "#A:Value");
3234                         }
3235
3236                         cmd.CommandText = "SELECT type_decimal2 FROM numeric_family WHERE id = 1";
3237
3238                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3239                                 DataTable schemaTable = rdr.GetSchemaTable ();
3240                                 DataRow row = schemaTable.Rows [0];
3241                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "#B:IsNull");
3242                                 Assert.AreEqual (17, row ["ColumnSize"], "#B:Value");
3243                         }
3244
3245                         cmd.CommandText = "SELECT type_numeric1 FROM numeric_family WHERE id = 1";
3246
3247                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3248                                 DataTable schemaTable = rdr.GetSchemaTable ();
3249                                 DataRow row = schemaTable.Rows [0];
3250                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "#C:IsNull");
3251                                 Assert.AreEqual (17, row ["ColumnSize"], "#C:Value");
3252                         }
3253
3254                         cmd.CommandText = "SELECT type_numeric2 FROM numeric_family WHERE id = 1";
3255
3256                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3257                                 DataTable schemaTable = rdr.GetSchemaTable ();
3258                                 DataRow row = schemaTable.Rows [0];
3259                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "#D:IsNull");
3260                                 Assert.AreEqual (17, row ["ColumnSize"], "#D:Value");
3261                         }
3262                 }
3263
3264                 [Test]
3265                 public void ColumnSize_Float ()
3266                 {
3267                         cmd.CommandText = "SELECT type_double FROM numeric_family WHERE id = 1";
3268
3269                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3270                                 DataTable schemaTable = rdr.GetSchemaTable ();
3271                                 DataRow row = schemaTable.Rows [0];
3272                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3273                                 Assert.AreEqual (8, row ["ColumnSize"], "Value");
3274                         }
3275                 }
3276
3277                 [Test]
3278                 public void ColumnSize_Image ()
3279                 {
3280                         cmd.CommandText = "SELECT type_tinyblob FROM binary_family WHERE id = 1";
3281
3282                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3283                                 DataTable schemaTable = rdr.GetSchemaTable ();
3284                                 DataRow row = schemaTable.Rows [0];
3285                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3286                                 Assert.AreEqual (int.MaxValue, row ["ColumnSize"], "Value");
3287                         }
3288                 }
3289
3290                 [Test]
3291                 public void ColumnSize_Int ()
3292                 {
3293                         cmd.CommandText = "SELECT type_int FROM numeric_family WHERE id = 1";
3294
3295                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3296                                 DataTable schemaTable = rdr.GetSchemaTable ();
3297                                 DataRow row = schemaTable.Rows [0];
3298                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3299                                 Assert.AreEqual (4, row ["ColumnSize"], "Value");
3300                         }
3301                 }
3302
3303                 [Test]
3304                 public void ColumnSize_Money ()
3305                 {
3306                         cmd.CommandText = "SELECT type_money FROM numeric_family WHERE id = 1";
3307
3308                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3309                                 DataTable schemaTable = rdr.GetSchemaTable ();
3310                                 DataRow row = schemaTable.Rows [0];
3311                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3312                                 Assert.AreEqual (8, row ["ColumnSize"], "Value");
3313                         }
3314                 }
3315
3316                 [Test]
3317                 public void ColumnSize_NChar ()
3318                 {
3319                         cmd.CommandText = "SELECT type_nchar FROM string_family WHERE id = 1";
3320
3321                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3322                                 DataTable schemaTable = rdr.GetSchemaTable ();
3323                                 DataRow row = schemaTable.Rows [0];
3324                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3325                                 Assert.AreEqual (10, row ["ColumnSize"], "Value");
3326                         }
3327                 }
3328
3329                 [Test]
3330                 public void ColumnSize_NText ()
3331                 {
3332                         cmd.CommandText = "SELECT type_ntext FROM string_family WHERE id = 1";
3333
3334                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3335                                 DataTable schemaTable = rdr.GetSchemaTable ();
3336                                 DataRow row = schemaTable.Rows [0];
3337                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3338                                 Assert.AreEqual (1073741823, row ["ColumnSize"], "Value");
3339                         }
3340                 }
3341
3342                 [Test]
3343                 public void ColumnSize_NVarChar ()
3344                 {
3345                         cmd.CommandText = "SELECT type_nvarchar FROM string_family WHERE id = 1";
3346
3347                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3348                                 DataTable schemaTable = rdr.GetSchemaTable ();
3349                                 DataRow row = schemaTable.Rows [0];
3350                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3351                                 Assert.AreEqual (10, row ["ColumnSize"], "Value");
3352                         }
3353                 }
3354
3355                 [Test]
3356                 public void ColumnSize_Real ()
3357                 {
3358                         cmd.CommandText = "SELECT type_float FROM numeric_family WHERE id = 1";
3359
3360                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3361                                 DataTable schemaTable = rdr.GetSchemaTable ();
3362                                 DataRow row = schemaTable.Rows [0];
3363                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3364                                 Assert.AreEqual (4, row ["ColumnSize"], "Value");
3365                         }
3366
3367                 }
3368
3369                 [Test]
3370                 public void ColumnSize_SmallDateTime ()
3371                 {
3372                         cmd.CommandText = "SELECT type_smalldatetime FROM datetime_family WHERE id = 1";
3373
3374                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3375                                 DataTable schemaTable = rdr.GetSchemaTable ();
3376                                 DataRow row = schemaTable.Rows [0];
3377                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3378                                 Assert.AreEqual (4, row ["ColumnSize"], "Value");
3379                         }
3380                 }
3381
3382                 [Test]
3383                 public void ColumnSize_SmallInt ()
3384                 {
3385                         cmd.CommandText = "SELECT type_smallint FROM numeric_family WHERE id = 1";
3386
3387                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3388                                 DataTable schemaTable = rdr.GetSchemaTable ();
3389                                 DataRow row = schemaTable.Rows [0];
3390                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3391                                 Assert.AreEqual (2, row ["ColumnSize"], "Value");
3392                         }
3393                 }
3394
3395                 [Test]
3396                 public void ColumnSize_SmallMoney ()
3397                 {
3398                         cmd.CommandText = "SELECT type_smallmoney FROM numeric_family WHERE id = 1";
3399
3400                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3401                                 DataTable schemaTable = rdr.GetSchemaTable ();
3402                                 DataRow row = schemaTable.Rows [0];
3403                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3404                                 Assert.AreEqual (4, row ["ColumnSize"], "Value");
3405                         }
3406                 }
3407
3408                 [Test]
3409                 public void ColumnSize_Text ()
3410                 {
3411                         cmd.CommandText = "SELECT type_text FROM string_family WHERE id = 1";
3412
3413                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3414                                 DataTable schemaTable = rdr.GetSchemaTable ();
3415                                 DataRow row = schemaTable.Rows [0];
3416                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3417                                 Assert.AreEqual (2147483647, row ["ColumnSize"], "Value");
3418                         }
3419                 }
3420
3421                 [Test]
3422                 public void ColumnSize_Time ()
3423                 {
3424                         // TODO
3425                 }
3426
3427                 [Test]
3428                 public void ColumnSize_Timestamp ()
3429                 {
3430                         cmd.CommandText = "SELECT type_timestamp FROM binary_family WHERE id = 1";
3431
3432                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3433                                 DataTable schemaTable = rdr.GetSchemaTable ();
3434                                 DataRow row = schemaTable.Rows [0];
3435                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3436                                 Assert.AreEqual (8, row ["ColumnSize"], "Value");
3437                         }
3438                 }
3439
3440                 [Test]
3441                 public void ColumnSize_TinyInt ()
3442                 {
3443                         cmd.CommandText = "SELECT type_tinyint FROM numeric_family WHERE id = 1";
3444
3445                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3446                                 DataTable schemaTable = rdr.GetSchemaTable ();
3447                                 DataRow row = schemaTable.Rows [0];
3448                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3449                                 Assert.AreEqual (1, row ["ColumnSize"], "Value");
3450                         }
3451                 }
3452
3453                 [Test]
3454                 public void ColumnSize_Udt ()
3455                 {
3456                         // TODO
3457                 }
3458
3459                 [Test]
3460                 public void ColumnSize_UniqueIdentifier ()
3461                 {
3462                         cmd.CommandText = "SELECT type_guid FROM string_family WHERE id = 1";
3463
3464                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3465                                 DataTable schemaTable = rdr.GetSchemaTable ();
3466                                 DataRow row = schemaTable.Rows [0];
3467                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3468                                 Assert.AreEqual (16, row ["ColumnSize"], "Value");
3469                         }
3470                 }
3471
3472                 [Test]
3473                 public void ColumnSize_VarBinary ()
3474                 {
3475                         cmd.CommandText = "SELECT type_varbinary FROM binary_family WHERE id = 1";
3476
3477                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3478                                 DataTable schemaTable = rdr.GetSchemaTable ();
3479                                 DataRow row = schemaTable.Rows [0];
3480                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3481                                 Assert.AreEqual (255, row ["ColumnSize"], "Value");
3482                         }
3483                 }
3484
3485                 [Test]
3486                 public void ColumnSize_VarChar ()
3487                 {
3488                         cmd.CommandText = "SELECT type_varchar FROM string_family WHERE id = 1";
3489
3490                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3491                                 DataTable schemaTable = rdr.GetSchemaTable ();
3492                                 DataRow row = schemaTable.Rows [0];
3493                                 Assert.IsFalse (row.IsNull ("ColumnSize"), "IsNull");
3494                                 Assert.AreEqual (10, row ["ColumnSize"], "Value");
3495                         }
3496                 }
3497
3498                 [Test]
3499                 public void DataType_BigInt ()
3500                 {
3501                         if (ClientVersion <= 7)
3502                                 Assert.Ignore ("BigInt data type is not supported.");
3503
3504                         cmd.CommandText = "SELECT type_bigint FROM numeric_family WHERE id = 1";
3505
3506                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3507                                 DataTable schemaTable = rdr.GetSchemaTable ();
3508                                 DataRow row = schemaTable.Rows [0];
3509                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3510                                 Assert.AreEqual (typeof (long), row ["DataType"], "Value");
3511                         }
3512                 }
3513
3514                 [Test]
3515                 public void DataType_Binary ()
3516                 {
3517                         cmd.CommandText = "SELECT type_binary FROM binary_family WHERE id = 1";
3518
3519                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3520                                 DataTable schemaTable = rdr.GetSchemaTable ();
3521                                 DataRow row = schemaTable.Rows [0];
3522                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3523                                 Assert.AreEqual (typeof (byte []), row ["DataType"], "Value");
3524                         }
3525                 }
3526
3527                 [Test]
3528                 public void DataType_Bit ()
3529                 {
3530                         cmd.CommandText = "SELECT type_bit FROM numeric_family WHERE id = 1";
3531
3532                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3533                                 DataTable schemaTable = rdr.GetSchemaTable ();
3534                                 DataRow row = schemaTable.Rows [0];
3535                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3536                                 Assert.AreEqual (typeof (bool), row ["DataType"], "Value");
3537                         }
3538                 }
3539
3540                 [Test]
3541                 public void DataType_Char ()
3542                 {
3543                         cmd.CommandText = "SELECT type_char FROM string_family WHERE id = 1";
3544
3545                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3546                                 DataTable schemaTable = rdr.GetSchemaTable ();
3547                                 DataRow row = schemaTable.Rows [0];
3548                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3549                                 Assert.AreEqual (typeof (string), row ["DataType"], "Value");
3550                         }
3551                 }
3552
3553                 [Test]
3554                 public void DataType_Date ()
3555                 {
3556                         // TODO
3557                 }
3558
3559                 [Test]
3560                 public void DataType_DateTime ()
3561                 {
3562                         cmd.CommandText = "SELECT type_datetime FROM datetime_family WHERE id = 1";
3563
3564                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3565                                 DataTable schemaTable = rdr.GetSchemaTable ();
3566                                 DataRow row = schemaTable.Rows [0];
3567                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3568                                 Assert.AreEqual (typeof (DateTime), row ["DataType"], "Value");
3569                         }
3570                 }
3571
3572                 [Test]
3573                 public void DataType_Decimal ()
3574                 {
3575                         cmd.CommandText = "SELECT type_decimal1 FROM numeric_family WHERE id = 1";
3576
3577                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3578                                 DataTable schemaTable = rdr.GetSchemaTable ();
3579                                 DataRow row = schemaTable.Rows [0];
3580                                 Assert.IsFalse (row.IsNull ("DataType"), "#A:IsNull");
3581                                 Assert.AreEqual (typeof (decimal), row ["DataType"], "#A:Value");
3582                         }
3583
3584                         cmd.CommandText = "SELECT type_decimal2 FROM numeric_family WHERE id = 1";
3585
3586                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3587                                 DataTable schemaTable = rdr.GetSchemaTable ();
3588                                 DataRow row = schemaTable.Rows [0];
3589                                 Assert.IsFalse (row.IsNull ("DataType"), "#B:IsNull");
3590                                 Assert.AreEqual (typeof (decimal), row ["DataType"], "#B:Value");
3591                         }
3592
3593                         cmd.CommandText = "SELECT type_numeric1 FROM numeric_family WHERE id = 1";
3594
3595                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3596                                 DataTable schemaTable = rdr.GetSchemaTable ();
3597                                 DataRow row = schemaTable.Rows [0];
3598                                 Assert.IsFalse (row.IsNull ("DataType"), "#C:IsNull");
3599                                 Assert.AreEqual (typeof (decimal), row ["DataType"], "#C:Value");
3600                         }
3601
3602                         cmd.CommandText = "SELECT type_numeric2 FROM numeric_family WHERE id = 1";
3603
3604                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3605                                 DataTable schemaTable = rdr.GetSchemaTable ();
3606                                 DataRow row = schemaTable.Rows [0];
3607                                 Assert.IsFalse (row.IsNull ("DataType"), "#D:IsNull");
3608                                 Assert.AreEqual (typeof (decimal), row ["DataType"], "#D:Value");
3609                         }
3610                 }
3611
3612                 [Test]
3613                 public void DataType_Float ()
3614                 {
3615                         cmd.CommandText = "SELECT type_double FROM numeric_family WHERE id = 1";
3616
3617                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3618                                 DataTable schemaTable = rdr.GetSchemaTable ();
3619                                 DataRow row = schemaTable.Rows [0];
3620                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3621                                 Assert.AreEqual (typeof (double), row ["DataType"], "Value");
3622                         }
3623                 }
3624
3625                 [Test]
3626                 public void DataType_Image ()
3627                 {
3628                         cmd.CommandText = "SELECT type_tinyblob FROM binary_family WHERE id = 1";
3629
3630                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3631                                 DataTable schemaTable = rdr.GetSchemaTable ();
3632                                 DataRow row = schemaTable.Rows [0];
3633                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3634                                 Assert.AreEqual (typeof (byte []), row ["DataType"], "Value");
3635                         }
3636                 }
3637
3638                 [Test]
3639                 public void DataType_Int ()
3640                 {
3641                         cmd.CommandText = "SELECT type_int FROM numeric_family WHERE id = 1";
3642
3643                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3644                                 DataTable schemaTable = rdr.GetSchemaTable ();
3645                                 DataRow row = schemaTable.Rows [0];
3646                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3647                                 Assert.AreEqual (typeof (int), row ["DataType"], "Value");
3648                         }
3649                 }
3650
3651                 [Test]
3652                 public void DataType_Money ()
3653                 {
3654                         cmd.CommandText = "SELECT type_money FROM numeric_family WHERE id = 1";
3655
3656                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3657                                 DataTable schemaTable = rdr.GetSchemaTable ();
3658                                 DataRow row = schemaTable.Rows [0];
3659                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3660                                 Assert.AreEqual (typeof (decimal), row ["DataType"], "Value");
3661                         }
3662                 }
3663
3664                 [Test]
3665                 public void DataType_NChar ()
3666                 {
3667                         cmd.CommandText = "SELECT type_nchar FROM string_family WHERE id = 1";
3668
3669                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3670                                 DataTable schemaTable = rdr.GetSchemaTable ();
3671                                 DataRow row = schemaTable.Rows [0];
3672                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3673                                 Assert.AreEqual (typeof (string), row ["DataType"], "Value");
3674                         }
3675                 }
3676
3677                 [Test]
3678                 public void DataType_NText ()
3679                 {
3680                         cmd.CommandText = "SELECT type_ntext FROM string_family WHERE id = 1";
3681
3682                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3683                                 DataTable schemaTable = rdr.GetSchemaTable ();
3684                                 DataRow row = schemaTable.Rows [0];
3685                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3686                                 Assert.AreEqual (typeof (string), row ["DataType"], "Value");
3687                         }
3688                 }
3689
3690                 [Test]
3691                 public void DataType_NVarChar ()
3692                 {
3693                         cmd.CommandText = "SELECT type_nvarchar FROM string_family WHERE id = 1";
3694
3695                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3696                                 DataTable schemaTable = rdr.GetSchemaTable ();
3697                                 DataRow row = schemaTable.Rows [0];
3698                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3699                                 Assert.AreEqual (typeof (string), row ["DataType"], "Value");
3700                         }
3701                 }
3702
3703                 [Test]
3704                 public void DataType_Real ()
3705                 {
3706                         cmd.CommandText = "SELECT type_float FROM numeric_family WHERE id = 1";
3707
3708                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3709                                 DataTable schemaTable = rdr.GetSchemaTable ();
3710                                 DataRow row = schemaTable.Rows [0];
3711                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3712                                 Assert.AreEqual (typeof (float), row ["DataType"], "Value");
3713                         }
3714
3715                 }
3716
3717                 [Test]
3718                 public void DataType_SmallDateTime ()
3719                 {
3720                         cmd.CommandText = "SELECT type_smalldatetime FROM datetime_family WHERE id = 1";
3721
3722                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3723                                 DataTable schemaTable = rdr.GetSchemaTable ();
3724                                 DataRow row = schemaTable.Rows [0];
3725                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3726                                 Assert.AreEqual (typeof (DateTime), row ["DataType"], "Value");
3727                         }
3728                 }
3729
3730                 [Test]
3731                 public void DataType_SmallInt ()
3732                 {
3733                         cmd.CommandText = "SELECT type_smallint FROM numeric_family WHERE id = 1";
3734
3735                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3736                                 DataTable schemaTable = rdr.GetSchemaTable ();
3737                                 DataRow row = schemaTable.Rows [0];
3738                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3739                                 Assert.AreEqual (typeof (short), row ["DataType"], "Value");
3740                         }
3741                 }
3742
3743                 [Test]
3744                 public void DataType_SmallMoney ()
3745                 {
3746                         cmd.CommandText = "SELECT type_smallmoney FROM numeric_family WHERE id = 1";
3747
3748                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3749                                 DataTable schemaTable = rdr.GetSchemaTable ();
3750                                 DataRow row = schemaTable.Rows [0];
3751                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3752                                 Assert.AreEqual (typeof (decimal), row ["DataType"], "Value");
3753                         }
3754                 }
3755
3756                 [Test]
3757                 public void DataType_Text ()
3758                 {
3759                         cmd.CommandText = "SELECT type_text FROM string_family WHERE id = 1";
3760
3761                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3762                                 DataTable schemaTable = rdr.GetSchemaTable ();
3763                                 DataRow row = schemaTable.Rows [0];
3764                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3765                                 Assert.AreEqual (typeof (string), row ["DataType"], "Value");
3766                         }
3767                 }
3768
3769                 [Test]
3770                 public void DataType_Time ()
3771                 {
3772                         // TODO
3773                 }
3774
3775                 [Test]
3776                 public void DataType_Timestamp ()
3777                 {
3778                         cmd.CommandText = "SELECT type_timestamp FROM binary_family WHERE id = 1";
3779
3780                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3781                                 DataTable schemaTable = rdr.GetSchemaTable ();
3782                                 DataRow row = schemaTable.Rows [0];
3783                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3784                                 Assert.AreEqual (typeof (byte []), row ["DataType"], "Value");
3785                         }
3786                 }
3787
3788                 [Test]
3789                 public void DataType_TinyInt ()
3790                 {
3791                         cmd.CommandText = "SELECT type_tinyint FROM numeric_family WHERE id = 1";
3792
3793                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3794                                 DataTable schemaTable = rdr.GetSchemaTable ();
3795                                 DataRow row = schemaTable.Rows [0];
3796                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3797                                 Assert.AreEqual (typeof (byte), row ["DataType"], "Value");
3798                         }
3799                 }
3800
3801                 [Test]
3802                 public void DataType_Udt ()
3803                 {
3804                         // TODO
3805                 }
3806
3807                 [Test]
3808                 public void DataType_UniqueIdentifier ()
3809                 {
3810                         cmd.CommandText = "SELECT type_guid FROM string_family WHERE id = 1";
3811
3812                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3813                                 DataTable schemaTable = rdr.GetSchemaTable ();
3814                                 DataRow row = schemaTable.Rows [0];
3815                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3816                                 Assert.AreEqual (typeof (Guid), row ["DataType"], "Value");
3817                         }
3818                 }
3819
3820                 [Test]
3821                 public void DataType_VarBinary ()
3822                 {
3823                         cmd.CommandText = "SELECT type_varbinary FROM binary_family WHERE id = 1";
3824
3825                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3826                                 DataTable schemaTable = rdr.GetSchemaTable ();
3827                                 DataRow row = schemaTable.Rows [0];
3828                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3829                                 Assert.AreEqual (typeof (byte []), row ["DataType"], "Value");
3830                         }
3831                 }
3832
3833                 [Test]
3834                 public void DataType_VarChar ()
3835                 {
3836                         cmd.CommandText = "SELECT type_varchar FROM string_family WHERE id = 1";
3837
3838                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3839                                 DataTable schemaTable = rdr.GetSchemaTable ();
3840                                 DataRow row = schemaTable.Rows [0];
3841                                 Assert.IsFalse (row.IsNull ("DataType"), "IsNull");
3842                                 Assert.AreEqual (typeof (string), row ["DataType"], "Value");
3843                         }
3844                 }
3845
3846                 [Test]
3847                 public void IsLong_BigInt ()
3848                 {
3849                         if (ClientVersion <= 7)
3850                                 Assert.Ignore ("BigInt data type is not supported.");
3851
3852                         cmd.CommandText = "SELECT type_bigint FROM numeric_family WHERE id = 1";
3853
3854                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3855                                 DataTable schemaTable = rdr.GetSchemaTable ();
3856                                 DataRow row = schemaTable.Rows [0];
3857                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
3858                                 Assert.AreEqual (false, row ["IsLong"], "Value");
3859                         }
3860                 }
3861
3862                 [Test]
3863                 public void IsLong_Binary ()
3864                 {
3865                         cmd.CommandText = "SELECT type_binary FROM binary_family WHERE id = 1";
3866
3867                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3868                                 DataTable schemaTable = rdr.GetSchemaTable ();
3869                                 DataRow row = schemaTable.Rows [0];
3870                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
3871                                 Assert.AreEqual (false, row ["IsLong"], "Value");
3872                         }
3873                 }
3874
3875                 [Test]
3876                 public void IsLong_Bit ()
3877                 {
3878                         cmd.CommandText = "SELECT type_bit FROM numeric_family WHERE id = 1";
3879
3880                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3881                                 DataTable schemaTable = rdr.GetSchemaTable ();
3882                                 DataRow row = schemaTable.Rows [0];
3883                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
3884                                 Assert.AreEqual (false, row ["IsLong"], "Value");
3885                         }
3886                 }
3887
3888                 [Test]
3889                 public void IsLong_Char ()
3890                 {
3891                         cmd.CommandText = "SELECT type_char FROM string_family WHERE id = 1";
3892
3893                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3894                                 DataTable schemaTable = rdr.GetSchemaTable ();
3895                                 DataRow row = schemaTable.Rows [0];
3896                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
3897                                 Assert.AreEqual (false, row ["IsLong"], "Value");
3898                         }
3899                 }
3900
3901                 [Test]
3902                 public void IsLong_Date ()
3903                 {
3904                         // TODO
3905                 }
3906
3907                 [Test]
3908                 public void IsLong_DateTime ()
3909                 {
3910                         cmd.CommandText = "SELECT type_datetime FROM datetime_family WHERE id = 1";
3911
3912                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3913                                 DataTable schemaTable = rdr.GetSchemaTable ();
3914                                 DataRow row = schemaTable.Rows [0];
3915                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
3916                                 Assert.AreEqual (false, row ["IsLong"], "Value");
3917                         }
3918                 }
3919
3920                 [Test]
3921                 public void IsLong_Decimal ()
3922                 {
3923                         cmd.CommandText = "SELECT type_decimal1 FROM numeric_family WHERE id = 1";
3924
3925                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3926                                 DataTable schemaTable = rdr.GetSchemaTable ();
3927                                 DataRow row = schemaTable.Rows [0];
3928                                 Assert.IsFalse (row.IsNull ("IsLong"), "#A:IsNull");
3929                                 Assert.AreEqual (false, row ["IsLong"], "#A:Value");
3930                         }
3931
3932                         cmd.CommandText = "SELECT type_decimal2 FROM numeric_family WHERE id = 1";
3933
3934                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3935                                 DataTable schemaTable = rdr.GetSchemaTable ();
3936                                 DataRow row = schemaTable.Rows [0];
3937                                 Assert.IsFalse (row.IsNull ("IsLong"), "#B:IsNull");
3938                                 Assert.AreEqual (false, row ["IsLong"], "#B:Value");
3939                         }
3940
3941                         cmd.CommandText = "SELECT type_numeric1 FROM numeric_family WHERE id = 1";
3942
3943                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3944                                 DataTable schemaTable = rdr.GetSchemaTable ();
3945                                 DataRow row = schemaTable.Rows [0];
3946                                 Assert.IsFalse (row.IsNull ("IsLong"), "#C:IsNull");
3947                                 Assert.AreEqual (false, row ["IsLong"], "#C:Value");
3948                         }
3949
3950                         cmd.CommandText = "SELECT type_numeric2 FROM numeric_family WHERE id = 1";
3951
3952                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3953                                 DataTable schemaTable = rdr.GetSchemaTable ();
3954                                 DataRow row = schemaTable.Rows [0];
3955                                 Assert.IsFalse (row.IsNull ("IsLong"), "#D:IsNull");
3956                                 Assert.AreEqual (false, row ["IsLong"], "#D:Value");
3957                         }
3958                 }
3959
3960                 [Test]
3961                 public void IsLong_Float ()
3962                 {
3963                         cmd.CommandText = "SELECT type_double FROM numeric_family WHERE id = 1";
3964
3965                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3966                                 DataTable schemaTable = rdr.GetSchemaTable ();
3967                                 DataRow row = schemaTable.Rows [0];
3968                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
3969                                 Assert.AreEqual (false, row ["IsLong"], "Value");
3970                         }
3971                 }
3972
3973                 [Test]
3974                 public void IsLong_Image ()
3975                 {
3976                         cmd.CommandText = "SELECT type_tinyblob FROM binary_family WHERE id = 1";
3977
3978                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3979                                 DataTable schemaTable = rdr.GetSchemaTable ();
3980                                 DataRow row = schemaTable.Rows [0];
3981                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
3982                                 Assert.AreEqual (true, row ["IsLong"], "Value");
3983                         }
3984                 }
3985
3986                 [Test]
3987                 public void IsLong_Int ()
3988                 {
3989                         cmd.CommandText = "SELECT type_int FROM numeric_family WHERE id = 1";
3990
3991                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
3992                                 DataTable schemaTable = rdr.GetSchemaTable ();
3993                                 DataRow row = schemaTable.Rows [0];
3994                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
3995                                 Assert.AreEqual (false, row ["IsLong"], "Value");
3996                         }
3997                 }
3998
3999                 [Test]
4000                 public void IsLong_Money ()
4001                 {
4002                         cmd.CommandText = "SELECT type_money FROM numeric_family WHERE id = 1";
4003
4004                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4005                                 DataTable schemaTable = rdr.GetSchemaTable ();
4006                                 DataRow row = schemaTable.Rows [0];
4007                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
4008                                 Assert.AreEqual (false, row ["IsLong"], "Value");
4009                         }
4010                 }
4011
4012                 [Test]
4013                 public void IsLong_NChar ()
4014                 {
4015                         cmd.CommandText = "SELECT type_nchar FROM string_family WHERE id = 1";
4016
4017                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4018                                 DataTable schemaTable = rdr.GetSchemaTable ();
4019                                 DataRow row = schemaTable.Rows [0];
4020                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
4021                                 Assert.AreEqual (false, row ["IsLong"], "Value");
4022                         }
4023                 }
4024
4025                 [Test]
4026                 public void IsLong_NText ()
4027                 {
4028                         cmd.CommandText = "SELECT type_ntext FROM string_family WHERE id = 1";
4029
4030                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4031                                 DataTable schemaTable = rdr.GetSchemaTable ();
4032                                 DataRow row = schemaTable.Rows [0];
4033                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
4034                                 Assert.AreEqual (true, row ["IsLong"], "Value");
4035                         }
4036                 }
4037
4038                 [Test]
4039                 public void IsLong_NVarChar ()
4040                 {
4041                         cmd.CommandText = "SELECT type_nvarchar FROM string_family WHERE id = 1";
4042
4043                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4044                                 DataTable schemaTable = rdr.GetSchemaTable ();
4045                                 DataRow row = schemaTable.Rows [0];
4046                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
4047                                 Assert.AreEqual (false, row ["IsLong"], "Value");
4048                         }
4049                 }
4050
4051                 [Test]
4052                 public void IsLong_Real ()
4053                 {
4054                         cmd.CommandText = "SELECT type_float FROM numeric_family WHERE id = 1";
4055
4056                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4057                                 DataTable schemaTable = rdr.GetSchemaTable ();
4058                                 DataRow row = schemaTable.Rows [0];
4059                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
4060                                 Assert.AreEqual (false, row ["IsLong"], "Value");
4061                         }
4062
4063                 }
4064
4065                 [Test]
4066                 public void IsLong_SmallDateTime ()
4067                 {
4068                         cmd.CommandText = "SELECT type_smalldatetime FROM datetime_family WHERE id = 1";
4069
4070                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4071                                 DataTable schemaTable = rdr.GetSchemaTable ();
4072                                 DataRow row = schemaTable.Rows [0];
4073                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
4074                                 Assert.AreEqual (false, row ["IsLong"], "Value");
4075                         }
4076                 }
4077
4078                 [Test]
4079                 public void IsLong_SmallInt ()
4080                 {
4081                         cmd.CommandText = "SELECT type_smallint FROM numeric_family WHERE id = 1";
4082
4083                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4084                                 DataTable schemaTable = rdr.GetSchemaTable ();
4085                                 DataRow row = schemaTable.Rows [0];
4086                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
4087                                 Assert.AreEqual (false, row ["IsLong"], "Value");
4088                         }
4089                 }
4090
4091                 [Test]
4092                 public void IsLong_SmallMoney ()
4093                 {
4094                         cmd.CommandText = "SELECT type_smallmoney FROM numeric_family WHERE id = 1";
4095
4096                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4097                                 DataTable schemaTable = rdr.GetSchemaTable ();
4098                                 DataRow row = schemaTable.Rows [0];
4099                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
4100                                 Assert.AreEqual (false, row ["IsLong"], "Value");
4101                         }
4102                 }
4103
4104                 [Test]
4105                 public void IsLong_Text ()
4106                 {
4107                         cmd.CommandText = "SELECT type_text FROM string_family WHERE id = 1";
4108
4109                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4110                                 DataTable schemaTable = rdr.GetSchemaTable ();
4111                                 DataRow row = schemaTable.Rows [0];
4112                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
4113                                 Assert.AreEqual (true, row ["IsLong"], "Value");
4114                         }
4115                 }
4116
4117                 [Test]
4118                 public void IsLong_Time ()
4119                 {
4120                         // TODO
4121                 }
4122
4123                 [Test]
4124                 public void IsLong_Timestamp ()
4125                 {
4126                         cmd.CommandText = "SELECT type_timestamp FROM binary_family WHERE id = 1";
4127
4128                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4129                                 DataTable schemaTable = rdr.GetSchemaTable ();
4130                                 DataRow row = schemaTable.Rows [0];
4131                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
4132                                 Assert.AreEqual (false, row ["IsLong"], "Value");
4133                         }
4134                 }
4135
4136                 [Test]
4137                 public void IsLong_TinyInt ()
4138                 {
4139                         cmd.CommandText = "SELECT type_tinyint FROM numeric_family WHERE id = 1";
4140
4141                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4142                                 DataTable schemaTable = rdr.GetSchemaTable ();
4143                                 DataRow row = schemaTable.Rows [0];
4144                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
4145                                 Assert.AreEqual (false, row ["IsLong"], "Value");
4146                         }
4147                 }
4148
4149                 [Test]
4150                 public void IsLong_Udt ()
4151                 {
4152                         // TODO
4153                 }
4154
4155                 [Test]
4156                 public void IsLong_UniqueIdentifier ()
4157                 {
4158                         cmd.CommandText = "SELECT type_guid FROM string_family WHERE id = 1";
4159
4160                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4161                                 DataTable schemaTable = rdr.GetSchemaTable ();
4162                                 DataRow row = schemaTable.Rows [0];
4163                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
4164                                 Assert.AreEqual (false, row ["IsLong"], "Value");
4165                         }
4166                 }
4167
4168                 [Test]
4169                 public void IsLong_VarBinary ()
4170                 {
4171                         cmd.CommandText = "SELECT type_varbinary FROM binary_family WHERE id = 1";
4172
4173                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4174                                 DataTable schemaTable = rdr.GetSchemaTable ();
4175                                 DataRow row = schemaTable.Rows [0];
4176                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
4177                                 Assert.AreEqual (false, row ["IsLong"], "Value");
4178                         }
4179                 }
4180
4181                 [Test]
4182                 public void IsLong_VarChar ()
4183                 {
4184                         cmd.CommandText = "SELECT type_varchar FROM string_family WHERE id = 1";
4185
4186                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4187                                 DataTable schemaTable = rdr.GetSchemaTable ();
4188                                 DataRow row = schemaTable.Rows [0];
4189                                 Assert.IsFalse (row.IsNull ("IsLong"), "IsNull");
4190                                 Assert.AreEqual (false, row ["IsLong"], "Value");
4191                         }
4192                 }
4193
4194                 [Test]
4195                 public void NumericPrecision_BigInt ()
4196                 {
4197                         if (ClientVersion <= 7)
4198                                 Assert.Ignore ("BigInt data type is not supported.");
4199
4200                         cmd.CommandText = "SELECT type_bigint FROM numeric_family WHERE id = 1";
4201
4202                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4203                                 DataTable schemaTable = rdr.GetSchemaTable ();
4204                                 DataRow row = schemaTable.Rows [0];
4205                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4206                                 if (ClientVersion > 7)
4207                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4208                                 else
4209                                         Assert.AreEqual (19, row ["NumericPrecision"], "Value");
4210                         }
4211                 }
4212
4213                 [Test]
4214                 public void NumericPrecision_Binary ()
4215                 {
4216                         cmd.CommandText = "SELECT type_binary FROM binary_family WHERE id = 1";
4217
4218                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4219                                 DataTable schemaTable = rdr.GetSchemaTable ();
4220                                 DataRow row = schemaTable.Rows [0];
4221                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4222                                 if (ClientVersion > 7)
4223                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4224                                 else
4225                                         Assert.AreEqual (255, row ["NumericPrecision"], "Value");
4226                         }
4227                 }
4228
4229                 [Test]
4230                 public void NumericPrecision_Bit ()
4231                 {
4232                         cmd.CommandText = "SELECT type_bit FROM numeric_family WHERE id = 1";
4233
4234                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4235                                 DataTable schemaTable = rdr.GetSchemaTable ();
4236                                 DataRow row = schemaTable.Rows [0];
4237                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4238                                 if (ClientVersion > 7)
4239                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4240                                 else
4241                                         Assert.AreEqual (255, row ["NumericPrecision"], "Value");
4242                         }
4243                 }
4244
4245                 [Test]
4246                 public void NumericPrecision_Char ()
4247                 {
4248                         cmd.CommandText = "SELECT type_char FROM string_family WHERE id = 1";
4249
4250                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4251                                 DataTable schemaTable = rdr.GetSchemaTable ();
4252                                 DataRow row = schemaTable.Rows [0];
4253                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4254                                 if (ClientVersion > 7)
4255                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4256                                 else
4257                                         Assert.AreEqual (255, row ["NumericPrecision"], "Value");
4258                         }
4259                 }
4260
4261                 [Test]
4262                 public void NumericPrecision_Date ()
4263                 {
4264                         // TODO
4265                 }
4266
4267                 [Test]
4268                 public void NumericPrecision_DateTime ()
4269                 {
4270                         cmd.CommandText = "SELECT type_datetime FROM datetime_family WHERE id = 1";
4271
4272                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4273                                 DataTable schemaTable = rdr.GetSchemaTable ();
4274                                 DataRow row = schemaTable.Rows [0];
4275                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4276                                 if (ClientVersion > 7)
4277                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4278                                 else
4279                                         Assert.AreEqual (23, row ["NumericPrecision"], "Value");
4280                         }
4281                 }
4282
4283                 [Test]
4284                 public void NumericPrecision_Decimal ()
4285                 {
4286                         cmd.CommandText = "SELECT type_decimal1 FROM numeric_family WHERE id = 1";
4287
4288                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4289                                 DataTable schemaTable = rdr.GetSchemaTable ();
4290                                 DataRow row = schemaTable.Rows [0];
4291                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "#A:IsNull");
4292                                 if (ClientVersion == 7)
4293                                         Assert.AreEqual (28, row ["NumericPrecision"], "#A:Value");
4294                                 else
4295                                         Assert.AreEqual (38, row ["NumericPrecision"], "#A:Value");
4296                         }
4297
4298                         cmd.CommandText = "SELECT type_decimal2 FROM numeric_family WHERE id = 1";
4299
4300                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4301                                 DataTable schemaTable = rdr.GetSchemaTable ();
4302                                 DataRow row = schemaTable.Rows [0];
4303                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "#B:IsNull");
4304                                 Assert.AreEqual (10, row ["NumericPrecision"], "#B:Value");
4305                         }
4306
4307                         cmd.CommandText = "SELECT type_numeric1 FROM numeric_family WHERE id = 1";
4308
4309                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4310                                 DataTable schemaTable = rdr.GetSchemaTable ();
4311                                 DataRow row = schemaTable.Rows [0];
4312                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "#C:IsNull");
4313                                 if (ClientVersion == 7)
4314                                         Assert.AreEqual (28, row ["NumericPrecision"], "#C:Value");
4315                                 else
4316                                         Assert.AreEqual (38, row ["NumericPrecision"], "#C:Value");
4317                         }
4318
4319                         cmd.CommandText = "SELECT type_numeric2 FROM numeric_family WHERE id = 1";
4320
4321                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4322                                 DataTable schemaTable = rdr.GetSchemaTable ();
4323                                 DataRow row = schemaTable.Rows [0];
4324                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "#D:IsNull");
4325                                 Assert.AreEqual (10, row ["NumericPrecision"], "#D:Value");
4326                         }
4327                 }
4328
4329                 [Test]
4330                 public void NumericPrecision_Float ()
4331                 {
4332                         cmd.CommandText = "SELECT type_double FROM numeric_family WHERE id = 1";
4333
4334                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4335                                 DataTable schemaTable = rdr.GetSchemaTable ();
4336                                 DataRow row = schemaTable.Rows [0];
4337                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4338                                 if (ClientVersion > 7)
4339                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4340                                 else
4341                                         Assert.AreEqual (15, row ["NumericPrecision"], "Value");
4342                         }
4343                 }
4344
4345                 [Test]
4346                 public void NumericPrecision_Image ()
4347                 {
4348                         cmd.CommandText = "SELECT type_tinyblob FROM binary_family WHERE id = 1";
4349
4350                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4351                                 DataTable schemaTable = rdr.GetSchemaTable ();
4352                                 DataRow row = schemaTable.Rows [0];
4353                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4354                                 if (ClientVersion > 7)
4355                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4356                                 else
4357                                         Assert.AreEqual (255, row ["NumericPrecision"], "Value");
4358                         }
4359                 }
4360
4361                 [Test]
4362                 public void NumericPrecision_Int ()
4363                 {
4364                         cmd.CommandText = "SELECT type_int FROM numeric_family WHERE id = 1";
4365
4366                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4367                                 DataTable schemaTable = rdr.GetSchemaTable ();
4368                                 DataRow row = schemaTable.Rows [0];
4369                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4370                                 if (ClientVersion > 7)
4371                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4372                                 else
4373                                         Assert.AreEqual (10, row ["NumericPrecision"], "Value");
4374                         }
4375                 }
4376
4377                 [Test]
4378                 public void NumericPrecision_Money ()
4379                 {
4380                         cmd.CommandText = "SELECT type_money FROM numeric_family WHERE id = 1";
4381
4382                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4383                                 DataTable schemaTable = rdr.GetSchemaTable ();
4384                                 DataRow row = schemaTable.Rows [0];
4385                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4386                                 if (ClientVersion > 7)
4387                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4388                                 else
4389                                         Assert.AreEqual (19, row ["NumericPrecision"], "Value");
4390                         }
4391                 }
4392
4393                 [Test]
4394                 public void NumericPrecision_NChar ()
4395                 {
4396                         cmd.CommandText = "SELECT type_nchar FROM string_family WHERE id = 1";
4397
4398                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4399                                 DataTable schemaTable = rdr.GetSchemaTable ();
4400                                 DataRow row = schemaTable.Rows [0];
4401                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4402                                 if (ClientVersion > 7)
4403                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4404                                 else
4405                                         Assert.AreEqual (255, row ["NumericPrecision"], "Value");
4406                         }
4407                 }
4408
4409                 [Test]
4410                 public void NumericPrecision_NText ()
4411                 {
4412                         cmd.CommandText = "SELECT type_ntext FROM string_family WHERE id = 1";
4413
4414                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4415                                 DataTable schemaTable = rdr.GetSchemaTable ();
4416                                 DataRow row = schemaTable.Rows [0];
4417                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4418                                 if (ClientVersion > 7)
4419                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4420                                 else
4421                                         Assert.AreEqual (255, row ["NumericPrecision"], "Value");
4422                         }
4423                 }
4424
4425                 [Test]
4426                 public void NumericPrecision_NVarChar ()
4427                 {
4428                         cmd.CommandText = "SELECT type_nvarchar FROM string_family WHERE id = 1";
4429
4430                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4431                                 DataTable schemaTable = rdr.GetSchemaTable ();
4432                                 DataRow row = schemaTable.Rows [0];
4433                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4434                                 if (ClientVersion > 7)
4435                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4436                                 else
4437                                         Assert.AreEqual (255, row ["NumericPrecision"], "Value");
4438                         }
4439                 }
4440
4441                 [Test]
4442                 public void NumericPrecision_Real ()
4443                 {
4444                         cmd.CommandText = "SELECT type_float FROM numeric_family WHERE id = 1";
4445
4446                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4447                                 DataTable schemaTable = rdr.GetSchemaTable ();
4448                                 DataRow row = schemaTable.Rows [0];
4449                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4450                                 if (ClientVersion > 7)
4451                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4452                                 else
4453                                         Assert.AreEqual (7, row ["NumericPrecision"], "Value");
4454                         }
4455
4456                 }
4457
4458                 [Test]
4459                 public void NumericPrecision_SmallDateTime ()
4460                 {
4461                         cmd.CommandText = "SELECT type_smalldatetime FROM datetime_family WHERE id = 1";
4462
4463                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4464                                 DataTable schemaTable = rdr.GetSchemaTable ();
4465                                 DataRow row = schemaTable.Rows [0];
4466                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4467                                 if (ClientVersion > 7)
4468                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4469                                 else
4470                                         Assert.AreEqual (16, row ["NumericPrecision"], "Value");
4471                         }
4472                 }
4473
4474                 [Test]
4475                 public void NumericPrecision_SmallInt ()
4476                 {
4477                         cmd.CommandText = "SELECT type_smallint FROM numeric_family WHERE id = 1";
4478
4479                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4480                                 DataTable schemaTable = rdr.GetSchemaTable ();
4481                                 DataRow row = schemaTable.Rows [0];
4482                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4483                                 if (ClientVersion > 7)
4484                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4485                                 else
4486                                         Assert.AreEqual (5, row ["NumericPrecision"], "Value");
4487                         }
4488                 }
4489
4490                 [Test]
4491                 public void NumericPrecision_SmallMoney ()
4492                 {
4493                         cmd.CommandText = "SELECT type_smallmoney FROM numeric_family WHERE id = 1";
4494
4495                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4496                                 DataTable schemaTable = rdr.GetSchemaTable ();
4497                                 DataRow row = schemaTable.Rows [0];
4498                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4499                                 if (ClientVersion > 7)
4500                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4501                                 else
4502                                         Assert.AreEqual (10, row ["NumericPrecision"], "Value");
4503                         }
4504                 }
4505
4506                 [Test]
4507                 public void NumericPrecision_Text ()
4508                 {
4509                         cmd.CommandText = "SELECT type_text FROM string_family WHERE id = 1";
4510
4511                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4512                                 DataTable schemaTable = rdr.GetSchemaTable ();
4513                                 DataRow row = schemaTable.Rows [0];
4514                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4515                                 if (ClientVersion > 7)
4516                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4517                                 else
4518                                         Assert.AreEqual (255, row ["NumericPrecision"], "Value");
4519                         }
4520                 }
4521
4522                 [Test]
4523                 public void NumericPrecision_Time ()
4524                 {
4525                         // TODO
4526                 }
4527
4528                 [Test]
4529                 public void NumericPrecision_Timestamp ()
4530                 {
4531                         cmd.CommandText = "SELECT type_timestamp FROM binary_family WHERE id = 1";
4532
4533                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4534                                 DataTable schemaTable = rdr.GetSchemaTable ();
4535                                 DataRow row = schemaTable.Rows [0];
4536                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4537                                 if (ClientVersion > 7)
4538                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4539                                 else
4540                                         Assert.AreEqual (255, row ["NumericPrecision"], "Value");
4541                         }
4542                 }
4543
4544                 [Test]
4545                 public void NumericPrecision_TinyInt ()
4546                 {
4547                         cmd.CommandText = "SELECT type_tinyint FROM numeric_family WHERE id = 1";
4548
4549                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4550                                 DataTable schemaTable = rdr.GetSchemaTable ();
4551                                 DataRow row = schemaTable.Rows [0];
4552                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4553                                 if (ClientVersion > 7)
4554                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4555                                 else
4556                                         Assert.AreEqual (3, row ["NumericPrecision"], "Value");
4557                         }
4558                 }
4559
4560                 [Test]
4561                 public void NumericPrecision_Udt ()
4562                 {
4563                         // TODO
4564                 }
4565
4566                 [Test]
4567                 public void NumericPrecision_UniqueIdentifier ()
4568                 {
4569                         cmd.CommandText = "SELECT type_guid FROM string_family WHERE id = 1";
4570
4571                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4572                                 DataTable schemaTable = rdr.GetSchemaTable ();
4573                                 DataRow row = schemaTable.Rows [0];
4574                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4575                                 if (ClientVersion > 7)
4576                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4577                                 else
4578                                         Assert.AreEqual (255, row ["NumericPrecision"], "Value");
4579                         }
4580                 }
4581
4582                 [Test]
4583                 public void NumericPrecision_VarBinary ()
4584                 {
4585                         cmd.CommandText = "SELECT type_varbinary FROM binary_family WHERE id = 1";
4586
4587                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4588                                 DataTable schemaTable = rdr.GetSchemaTable ();
4589                                 DataRow row = schemaTable.Rows [0];
4590                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4591                                 if (ClientVersion > 7)
4592                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4593                                 else
4594                                         Assert.AreEqual (255, row ["NumericPrecision"], "Value");
4595                         }
4596                 }
4597
4598                 [Test]
4599                 public void NumericPrecision_VarChar ()
4600                 {
4601                         cmd.CommandText = "SELECT type_varchar FROM string_family WHERE id = 1";
4602
4603                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4604                                 DataTable schemaTable = rdr.GetSchemaTable ();
4605                                 DataRow row = schemaTable.Rows [0];
4606                                 Assert.IsFalse (row.IsNull ("NumericPrecision"), "IsNull");
4607                                 if (ClientVersion > 7)
4608                                         Assert.AreEqual (0, row ["NumericPrecision"], "Value");
4609                                 else
4610                                         Assert.AreEqual (255, row ["NumericPrecision"], "Value");
4611                         }
4612                 }
4613
4614                 [Test]
4615                 public void NumericPrecision_Variant ()
4616                 {
4617                         // TODO
4618                 }
4619
4620                 [Test]
4621                 public void NumericPrecision_Xml ()
4622                 {
4623                         // TODO
4624                 }
4625
4626                 [Test]
4627                 public void NumericScale_BigInt ()
4628                 {
4629                         if (ClientVersion <= 7)
4630                                 Assert.Ignore ("BigInt data type is not supported.");
4631
4632                         cmd.CommandText = "SELECT type_bigint FROM numeric_family WHERE id = 1";
4633
4634                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4635                                 DataTable schemaTable = rdr.GetSchemaTable ();
4636                                 DataRow row = schemaTable.Rows [0];
4637                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4638                                 if (ClientVersion > 7)
4639                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
4640                                 else
4641                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
4642                         }
4643                 }
4644
4645                 [Test]
4646                 public void NumericScale_Binary ()
4647                 {
4648                         cmd.CommandText = "SELECT type_binary FROM binary_family WHERE id = 1";
4649
4650                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4651                                 DataTable schemaTable = rdr.GetSchemaTable ();
4652                                 DataRow row = schemaTable.Rows [0];
4653                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4654                                 if (ClientVersion > 7)
4655                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
4656                                 else
4657                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
4658                         }
4659                 }
4660
4661                 [Test]
4662                 public void NumericScale_Bit ()
4663                 {
4664                         cmd.CommandText = "SELECT type_bit FROM numeric_family WHERE id = 1";
4665
4666                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4667                                 DataTable schemaTable = rdr.GetSchemaTable ();
4668                                 DataRow row = schemaTable.Rows [0];
4669                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4670                                 if (ClientVersion > 7)
4671                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
4672                                 else
4673                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
4674                         }
4675                 }
4676
4677                 [Test]
4678                 public void NumericScale_Char ()
4679                 {
4680                         cmd.CommandText = "SELECT type_char FROM string_family WHERE id = 1";
4681
4682                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4683                                 DataTable schemaTable = rdr.GetSchemaTable ();
4684                                 DataRow row = schemaTable.Rows [0];
4685                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4686                                 if (ClientVersion > 7)
4687                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
4688                                 else
4689                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
4690                         }
4691                 }
4692
4693                 [Test]
4694                 public void NumericScale_Date ()
4695                 {
4696                         // TODO
4697                 }
4698
4699                 [Test]
4700                 public void NumericScale_DateTime ()
4701                 {
4702                         cmd.CommandText = "SELECT type_datetime FROM datetime_family WHERE id = 1";
4703
4704                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4705                                 DataTable schemaTable = rdr.GetSchemaTable ();
4706                                 DataRow row = schemaTable.Rows [0];
4707                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4708                                 if (ClientVersion > 7)
4709                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
4710                                 else
4711                                         Assert.AreEqual (3, row ["NumericScale"], "Value");
4712                         }
4713                 }
4714
4715                 [Test]
4716                 public void NumericScale_Decimal ()
4717                 {
4718                         cmd.CommandText = "SELECT type_decimal1 FROM numeric_family WHERE id = 1";
4719
4720                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4721                                 DataTable schemaTable = rdr.GetSchemaTable ();
4722                                 DataRow row = schemaTable.Rows [0];
4723                                 Assert.IsFalse (row.IsNull ("NumericScale"), "#A:IsNull");
4724                                 Assert.AreEqual (0, row ["NumericScale"], "#A:Value");
4725                         }
4726
4727                         cmd.CommandText = "SELECT type_decimal2 FROM numeric_family WHERE id = 1";
4728
4729                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4730                                 DataTable schemaTable = rdr.GetSchemaTable ();
4731                                 DataRow row = schemaTable.Rows [0];
4732                                 Assert.IsFalse (row.IsNull ("NumericScale"), "#B:IsNull");
4733                                 Assert.AreEqual (3, row ["NumericScale"], "#B:Value");
4734                         }
4735
4736                         cmd.CommandText = "SELECT type_numeric1 FROM numeric_family WHERE id = 1";
4737
4738                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4739                                 DataTable schemaTable = rdr.GetSchemaTable ();
4740                                 DataRow row = schemaTable.Rows [0];
4741                                 Assert.IsFalse (row.IsNull ("NumericScale"), "#C:IsNull");
4742                                 Assert.AreEqual (0, row ["NumericScale"], "#C:Value");
4743                         }
4744
4745                         cmd.CommandText = "SELECT type_numeric2 FROM numeric_family WHERE id = 1";
4746
4747                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4748                                 DataTable schemaTable = rdr.GetSchemaTable ();
4749                                 DataRow row = schemaTable.Rows [0];
4750                                 Assert.IsFalse (row.IsNull ("NumericScale"), "#D:IsNull");
4751                                 Assert.AreEqual (3, row ["NumericScale"], "#D:Value");
4752                         }
4753                 }
4754
4755                 [Test]
4756                 public void NumericScale_Float ()
4757                 {
4758                         cmd.CommandText = "SELECT type_double FROM numeric_family WHERE id = 1";
4759
4760                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4761                                 DataTable schemaTable = rdr.GetSchemaTable ();
4762                                 DataRow row = schemaTable.Rows [0];
4763                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4764                                 if (ClientVersion > 7)
4765                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
4766                                 else
4767                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
4768                         }
4769                 }
4770
4771                 [Test]
4772                 public void NumericScale_Image ()
4773                 {
4774                         cmd.CommandText = "SELECT type_tinyblob FROM binary_family WHERE id = 1";
4775
4776                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4777                                 DataTable schemaTable = rdr.GetSchemaTable ();
4778                                 DataRow row = schemaTable.Rows [0];
4779                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4780                                 if (ClientVersion > 7)
4781                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
4782                                 else
4783                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
4784                         }
4785                 }
4786
4787                 [Test]
4788                 public void NumericScale_Int ()
4789                 {
4790                         cmd.CommandText = "SELECT type_int FROM numeric_family WHERE id = 1";
4791
4792                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4793                                 DataTable schemaTable = rdr.GetSchemaTable ();
4794                                 DataRow row = schemaTable.Rows [0];
4795                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4796                                 if (ClientVersion > 7)
4797                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
4798                                 else
4799                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
4800                         }
4801                 }
4802
4803                 [Test]
4804                 public void NumericScale_Money ()
4805                 {
4806                         cmd.CommandText = "SELECT type_money FROM numeric_family WHERE id = 1";
4807
4808                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4809                                 DataTable schemaTable = rdr.GetSchemaTable ();
4810                                 DataRow row = schemaTable.Rows [0];
4811                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4812                                 if (ClientVersion > 7)
4813                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
4814                                 else
4815                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
4816                         }
4817                 }
4818
4819                 [Test]
4820                 public void NumericScale_NChar ()
4821                 {
4822                         cmd.CommandText = "SELECT type_nchar FROM string_family WHERE id = 1";
4823
4824                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4825                                 DataTable schemaTable = rdr.GetSchemaTable ();
4826                                 DataRow row = schemaTable.Rows [0];
4827                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4828                                 if (ClientVersion > 7)
4829                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
4830                                 else
4831                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
4832                         }
4833                 }
4834
4835                 [Test]
4836                 public void NumericScale_NText ()
4837                 {
4838                         cmd.CommandText = "SELECT type_ntext FROM string_family WHERE id = 1";
4839
4840                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4841                                 DataTable schemaTable = rdr.GetSchemaTable ();
4842                                 DataRow row = schemaTable.Rows [0];
4843                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4844                                 if (ClientVersion > 7)
4845                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
4846                                 else
4847                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
4848                         }
4849                 }
4850
4851                 [Test]
4852                 public void NumericScale_NVarChar ()
4853                 {
4854                         cmd.CommandText = "SELECT type_nvarchar FROM string_family WHERE id = 1";
4855
4856                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4857                                 DataTable schemaTable = rdr.GetSchemaTable ();
4858                                 DataRow row = schemaTable.Rows [0];
4859                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4860                                 if (ClientVersion > 7)
4861                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
4862                                 else
4863                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
4864                         }
4865                 }
4866
4867                 [Test]
4868                 public void NumericScale_Real ()
4869                 {
4870                         cmd.CommandText = "SELECT type_float FROM numeric_family WHERE id = 1";
4871
4872                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4873                                 DataTable schemaTable = rdr.GetSchemaTable ();
4874                                 DataRow row = schemaTable.Rows [0];
4875                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4876                                 if (ClientVersion > 7)
4877                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
4878                                 else
4879                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
4880                         }
4881
4882                 }
4883
4884                 [Test]
4885                 public void NumericScale_SmallDateTime ()
4886                 {
4887                         cmd.CommandText = "SELECT type_smalldatetime FROM datetime_family WHERE id = 1";
4888
4889                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4890                                 DataTable schemaTable = rdr.GetSchemaTable ();
4891                                 DataRow row = schemaTable.Rows [0];
4892                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4893                                 Assert.AreEqual (0, row ["NumericScale"], "Value");
4894                         }
4895                 }
4896
4897                 [Test]
4898                 public void NumericScale_SmallInt ()
4899                 {
4900                         cmd.CommandText = "SELECT type_smallint FROM numeric_family WHERE id = 1";
4901
4902                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4903                                 DataTable schemaTable = rdr.GetSchemaTable ();
4904                                 DataRow row = schemaTable.Rows [0];
4905                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4906                                 if (ClientVersion > 7)
4907                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
4908                                 else
4909                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
4910                         }
4911                 }
4912
4913                 [Test]
4914                 public void NumericScale_SmallMoney ()
4915                 {
4916                         cmd.CommandText = "SELECT type_smallmoney FROM numeric_family WHERE id = 1";
4917
4918                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4919                                 DataTable schemaTable = rdr.GetSchemaTable ();
4920                                 DataRow row = schemaTable.Rows [0];
4921                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4922                                 if (ClientVersion > 7)
4923                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
4924                                 else
4925                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
4926                         }
4927                 }
4928
4929                 [Test]
4930                 public void NumericScale_Text ()
4931                 {
4932                         cmd.CommandText = "SELECT type_text FROM string_family WHERE id = 1";
4933
4934                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4935                                 DataTable schemaTable = rdr.GetSchemaTable ();
4936                                 DataRow row = schemaTable.Rows [0];
4937                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4938                                 if (ClientVersion > 7)
4939                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
4940                                 else
4941                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
4942                         }
4943                 }
4944
4945                 [Test]
4946                 public void NumericScale_Time ()
4947                 {
4948                         // TODO
4949                 }
4950
4951                 [Test]
4952                 public void NumericScale_Timestamp ()
4953                 {
4954                         cmd.CommandText = "SELECT type_timestamp FROM binary_family WHERE id = 1";
4955
4956                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4957                                 DataTable schemaTable = rdr.GetSchemaTable ();
4958                                 DataRow row = schemaTable.Rows [0];
4959                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4960                                 if (ClientVersion > 7)
4961                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
4962                                 else
4963                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
4964                         }
4965                 }
4966
4967                 [Test]
4968                 public void NumericScale_TinyInt ()
4969                 {
4970                         cmd.CommandText = "SELECT type_tinyint FROM numeric_family WHERE id = 1";
4971
4972                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4973                                 DataTable schemaTable = rdr.GetSchemaTable ();
4974                                 DataRow row = schemaTable.Rows [0];
4975                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4976                                 if (ClientVersion > 7)
4977                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
4978                                 else
4979                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
4980                         }
4981                 }
4982
4983                 [Test]
4984                 public void NumericScale_Udt ()
4985                 {
4986                         // TODO
4987                 }
4988
4989                 [Test]
4990                 public void NumericScale_UniqueIdentifier ()
4991                 {
4992                         cmd.CommandText = "SELECT type_guid FROM string_family WHERE id = 1";
4993
4994                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
4995                                 DataTable schemaTable = rdr.GetSchemaTable ();
4996                                 DataRow row = schemaTable.Rows [0];
4997                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
4998                                 if (ClientVersion > 7)
4999                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
5000                                 else
5001                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
5002                         }
5003                 }
5004
5005                 [Test]
5006                 public void NumericScale_VarBinary ()
5007                 {
5008                         cmd.CommandText = "SELECT type_varbinary FROM binary_family WHERE id = 1";
5009
5010                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5011                                 DataTable schemaTable = rdr.GetSchemaTable ();
5012                                 DataRow row = schemaTable.Rows [0];
5013                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
5014                                 if (ClientVersion > 7)
5015                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
5016                                 else
5017                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
5018                         }
5019                 }
5020
5021                 [Test]
5022                 public void NumericScale_VarChar ()
5023                 {
5024                         cmd.CommandText = "SELECT type_varchar FROM string_family WHERE id = 1";
5025
5026                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5027                                 DataTable schemaTable = rdr.GetSchemaTable ();
5028                                 DataRow row = schemaTable.Rows [0];
5029                                 Assert.IsFalse (row.IsNull ("NumericScale"), "IsNull");
5030                                 if (ClientVersion > 7)
5031                                         Assert.AreEqual (0, row ["NumericScale"], "Value");
5032                                 else
5033                                         Assert.AreEqual (255, row ["NumericScale"], "Value");
5034                         }
5035                 }
5036
5037                 [Test]
5038                 public void NumericScale_Variant ()
5039                 {
5040                         // TODO
5041                 }
5042
5043                 [Test]
5044                 public void NumericScale_Xml ()
5045                 {
5046                         // TODO
5047                 }
5048
5049                 [Test]
5050                 public void ProviderType_BigInt ()
5051                 {
5052                         if (ClientVersion <= 7)
5053                                 Assert.Ignore ("BigInt data type is not supported.");
5054
5055                         cmd.CommandText = "SELECT type_bigint FROM numeric_family WHERE id = 1";
5056
5057                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5058                                 DataTable schemaTable = rdr.GetSchemaTable ();
5059                                 DataRow row = schemaTable.Rows [0];
5060                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5061                                 Assert.AreEqual (0, row ["ProviderType"], "Value");
5062                         }
5063                 }
5064
5065                 [Test]
5066                 public void ProviderType_Binary ()
5067                 {
5068                         cmd.CommandText = "SELECT type_binary FROM binary_family WHERE id = 1";
5069
5070                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5071                                 DataTable schemaTable = rdr.GetSchemaTable ();
5072                                 DataRow row = schemaTable.Rows [0];
5073                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5074                                 Assert.AreEqual (1, row ["ProviderType"], "Value");
5075                         }
5076                 }
5077
5078                 [Test]
5079                 public void ProviderType_Bit ()
5080                 {
5081                         cmd.CommandText = "SELECT type_bit FROM numeric_family WHERE id = 1";
5082
5083                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5084                                 DataTable schemaTable = rdr.GetSchemaTable ();
5085                                 DataRow row = schemaTable.Rows [0];
5086                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5087                                 Assert.AreEqual (2, row ["ProviderType"], "Value");
5088                         }
5089                 }
5090
5091                 [Test]
5092                 public void ProviderType_Char ()
5093                 {
5094                         cmd.CommandText = "SELECT type_char FROM string_family WHERE id = 1";
5095
5096                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5097                                 DataTable schemaTable = rdr.GetSchemaTable ();
5098                                 DataRow row = schemaTable.Rows [0];
5099                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5100                                 Assert.AreEqual (3, row ["ProviderType"], "Value");
5101                         }
5102                 }
5103
5104                 [Test]
5105                 public void ProviderType_Date ()
5106                 {
5107                         // TODO
5108                 }
5109
5110                 [Test]
5111                 public void ProviderType_DateTime ()
5112                 {
5113                         cmd.CommandText = "SELECT type_datetime FROM datetime_family WHERE id = 1";
5114
5115                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5116                                 DataTable schemaTable = rdr.GetSchemaTable ();
5117                                 DataRow row = schemaTable.Rows [0];
5118                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5119                                 Assert.AreEqual (4, row ["ProviderType"], "Value");
5120                         }
5121                 }
5122
5123                 [Test]
5124                 public void ProviderType_Decimal ()
5125                 {
5126                         cmd.CommandText = "SELECT type_decimal1 FROM numeric_family WHERE id = 1";
5127
5128                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5129                                 DataTable schemaTable = rdr.GetSchemaTable ();
5130                                 DataRow row = schemaTable.Rows [0];
5131                                 Assert.IsFalse (row.IsNull ("ProviderType"), "#A:IsNull");
5132                                 Assert.AreEqual (5, row ["ProviderType"], "#A:Value");
5133                         }
5134
5135                         cmd.CommandText = "SELECT type_decimal2 FROM numeric_family WHERE id = 1";
5136
5137                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5138                                 DataTable schemaTable = rdr.GetSchemaTable ();
5139                                 DataRow row = schemaTable.Rows [0];
5140                                 Assert.IsFalse (row.IsNull ("ProviderType"), "#B:IsNull");
5141                                 Assert.AreEqual (5, row ["ProviderType"], "#B:Value");
5142                         }
5143
5144                         cmd.CommandText = "SELECT type_numeric1 FROM numeric_family WHERE id = 1";
5145
5146                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5147                                 DataTable schemaTable = rdr.GetSchemaTable ();
5148                                 DataRow row = schemaTable.Rows [0];
5149                                 Assert.IsFalse (row.IsNull ("ProviderType"), "#C:IsNull");
5150                                 Assert.AreEqual (5, row ["ProviderType"], "#C:Value");
5151                         }
5152
5153                         cmd.CommandText = "SELECT type_numeric2 FROM numeric_family WHERE id = 1";
5154
5155                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5156                                 DataTable schemaTable = rdr.GetSchemaTable ();
5157                                 DataRow row = schemaTable.Rows [0];
5158                                 Assert.IsFalse (row.IsNull ("ProviderType"), "#D:IsNull");
5159                                 Assert.AreEqual (5, row ["ProviderType"], "#D:Value");
5160                         }
5161                 }
5162
5163                 [Test]
5164                 public void ProviderType_Float ()
5165                 {
5166                         cmd.CommandText = "SELECT type_double FROM numeric_family WHERE id = 1";
5167
5168                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5169                                 DataTable schemaTable = rdr.GetSchemaTable ();
5170                                 DataRow row = schemaTable.Rows [0];
5171                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5172                                 Assert.AreEqual (6, row ["ProviderType"], "Value");
5173                         }
5174                 }
5175
5176                 [Test]
5177                 public void ProviderType_Image ()
5178                 {
5179                         cmd.CommandText = "SELECT type_tinyblob FROM binary_family WHERE id = 1";
5180
5181                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5182                                 DataTable schemaTable = rdr.GetSchemaTable ();
5183                                 DataRow row = schemaTable.Rows [0];
5184                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5185                                 Assert.AreEqual (7, row ["ProviderType"], "Value");
5186                         }
5187                 }
5188
5189                 [Test]
5190                 public void ProviderType_Int ()
5191                 {
5192                         cmd.CommandText = "SELECT type_int FROM numeric_family WHERE id = 1";
5193
5194                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5195                                 DataTable schemaTable = rdr.GetSchemaTable ();
5196                                 DataRow row = schemaTable.Rows [0];
5197                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5198                                 Assert.AreEqual (8, row ["ProviderType"], "Value");
5199                         }
5200                 }
5201
5202                 [Test]
5203                 public void ProviderType_Money ()
5204                 {
5205                         cmd.CommandText = "SELECT type_money FROM numeric_family WHERE id = 1";
5206
5207                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5208                                 DataTable schemaTable = rdr.GetSchemaTable ();
5209                                 DataRow row = schemaTable.Rows [0];
5210                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5211                                 Assert.AreEqual (9, row ["ProviderType"], "Value");
5212                         }
5213                 }
5214
5215                 [Test]
5216                 public void ProviderType_NChar ()
5217                 {
5218                         cmd.CommandText = "SELECT type_nchar FROM string_family WHERE id = 1";
5219
5220                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5221                                 DataTable schemaTable = rdr.GetSchemaTable ();
5222                                 DataRow row = schemaTable.Rows [0];
5223                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5224                                 Assert.AreEqual (10, row ["ProviderType"], "Value");
5225                         }
5226                 }
5227
5228                 [Test]
5229                 public void ProviderType_NText ()
5230                 {
5231                         cmd.CommandText = "SELECT type_ntext FROM string_family WHERE id = 1";
5232
5233                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5234                                 DataTable schemaTable = rdr.GetSchemaTable ();
5235                                 DataRow row = schemaTable.Rows [0];
5236                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5237                                 Assert.AreEqual (11, row ["ProviderType"], "Value");
5238                         }
5239                 }
5240
5241                 [Test]
5242                 public void ProviderType_NVarChar ()
5243                 {
5244                         cmd.CommandText = "SELECT type_nvarchar FROM string_family WHERE id = 1";
5245
5246                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5247                                 DataTable schemaTable = rdr.GetSchemaTable ();
5248                                 DataRow row = schemaTable.Rows [0];
5249                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5250                                 Assert.AreEqual (12, row ["ProviderType"], "Value");
5251                         }
5252                 }
5253
5254                 [Test]
5255                 public void ProviderType_Real ()
5256                 {
5257                         cmd.CommandText = "SELECT type_float FROM numeric_family WHERE id = 1";
5258
5259                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5260                                 DataTable schemaTable = rdr.GetSchemaTable ();
5261                                 DataRow row = schemaTable.Rows [0];
5262                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5263                                 Assert.AreEqual (13, row ["ProviderType"], "Value");
5264                         }
5265
5266                 }
5267
5268                 [Test]
5269                 public void ProviderType_SmallDateTime ()
5270                 {
5271                         cmd.CommandText = "SELECT type_smalldatetime FROM datetime_family WHERE id = 1";
5272
5273                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5274                                 DataTable schemaTable = rdr.GetSchemaTable ();
5275                                 DataRow row = schemaTable.Rows [0];
5276                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5277                                 Assert.AreEqual (15, row ["ProviderType"], "Value");
5278                         }
5279                 }
5280
5281                 [Test]
5282                 public void ProviderType_SmallInt ()
5283                 {
5284                         cmd.CommandText = "SELECT type_smallint FROM numeric_family WHERE id = 1";
5285
5286                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5287                                 DataTable schemaTable = rdr.GetSchemaTable ();
5288                                 DataRow row = schemaTable.Rows [0];
5289                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5290                                 Assert.AreEqual (16, row ["ProviderType"], "Value");
5291                         }
5292                 }
5293
5294                 [Test]
5295                 public void ProviderType_SmallMoney ()
5296                 {
5297                         cmd.CommandText = "SELECT type_smallmoney FROM numeric_family WHERE id = 1";
5298
5299                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5300                                 DataTable schemaTable = rdr.GetSchemaTable ();
5301                                 DataRow row = schemaTable.Rows [0];
5302                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5303                                 Assert.AreEqual (17, row ["ProviderType"], "Value");
5304                         }
5305                 }
5306
5307                 [Test]
5308                 public void ProviderType_Text ()
5309                 {
5310                         cmd.CommandText = "SELECT type_text FROM string_family WHERE id = 1";
5311
5312                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5313                                 DataTable schemaTable = rdr.GetSchemaTable ();
5314                                 DataRow row = schemaTable.Rows [0];
5315                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5316                                 Assert.AreEqual (18, row ["ProviderType"], "Value");
5317                         }
5318                 }
5319
5320                 [Test]
5321                 public void ProviderType_Time ()
5322                 {
5323                         // TODO
5324                 }
5325
5326                 [Test]
5327                 public void ProviderType_Timestamp ()
5328                 {
5329                         cmd.CommandText = "SELECT type_timestamp FROM binary_family WHERE id = 1";
5330
5331                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5332                                 DataTable schemaTable = rdr.GetSchemaTable ();
5333                                 DataRow row = schemaTable.Rows [0];
5334                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5335                                 // we currently consider timestamp as binary (due to TDS 7.0?)
5336                                 if (ClientVersion > 7)
5337                                         Assert.AreEqual (1, row ["ProviderType"], "Value");
5338                                 else
5339                                         Assert.AreEqual (19, row ["ProviderType"], "Value");
5340                         }
5341                 }
5342
5343                 [Test]
5344                 public void ProviderType_TinyInt ()
5345                 {
5346                         cmd.CommandText = "SELECT type_tinyint FROM numeric_family WHERE id = 1";
5347
5348                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5349                                 DataTable schemaTable = rdr.GetSchemaTable ();
5350                                 DataRow row = schemaTable.Rows [0];
5351                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5352                                 Assert.AreEqual (20, row ["ProviderType"], "Value");
5353                         }
5354                 }
5355
5356                 [Test]
5357                 public void ProviderType_Udt ()
5358                 {
5359                         // TODO
5360                 }
5361
5362                 [Test]
5363                 public void ProviderType_UniqueIdentifier ()
5364                 {
5365                         cmd.CommandText = "SELECT type_guid FROM string_family WHERE id = 1";
5366
5367                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5368                                 DataTable schemaTable = rdr.GetSchemaTable ();
5369                                 DataRow row = schemaTable.Rows [0];
5370                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5371                                 Assert.AreEqual (14, row ["ProviderType"], "Value");
5372                         }
5373                 }
5374
5375                 [Test]
5376                 public void ProviderType_VarBinary ()
5377                 {
5378                         cmd.CommandText = "SELECT type_varbinary FROM binary_family WHERE id = 1";
5379
5380                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5381                                 DataTable schemaTable = rdr.GetSchemaTable ();
5382                                 DataRow row = schemaTable.Rows [0];
5383                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5384                                 Assert.AreEqual (21, row ["ProviderType"], "Value");
5385                         }
5386                 }
5387
5388                 [Test]
5389                 public void ProviderType_VarChar ()
5390                 {
5391                         cmd.CommandText = "SELECT type_varchar FROM string_family WHERE id = 1";
5392
5393                         using (SqlDataReader rdr = cmd.ExecuteReader (CommandBehavior.KeyInfo)) {
5394                                 DataTable schemaTable = rdr.GetSchemaTable ();
5395                                 DataRow row = schemaTable.Rows [0];
5396                                 Assert.IsFalse (row.IsNull ("ProviderType"), "IsNull");
5397                                 Assert.AreEqual (22, row ["ProviderType"], "Value");
5398                         }
5399                 }
5400
5401                 [Test]
5402                 public void ProviderType_Variant ()
5403                 {
5404                         // TODO
5405                 }
5406
5407                 [Test]
5408                 public void ProviderType_Xml ()
5409                 {
5410                         // TODO
5411                 }
5412
5413                 private int ClientVersion {
5414                         get {
5415                                 return (engine.ClientVersion);
5416                         }
5417                 }
5418         }
5419 }