Author: senga
Date: 2006-06-27 15:10:14 -0400 (Tue, 27 Jun 2006)
New Revision: 62091

Modified:
   trunk/mcs/class/System.Data/System.Data/ChangeLog
   trunk/mcs/class/System.Data/System.Data/DataSet.cs
   trunk/mcs/class/System.Data/System.Data/DataTable.cs
   trunk/mcs/class/System.Data/System.Data/DataTableReader.cs
   trunk/mcs/class/System.Data/System.Data/InternalDataCollectionBase.cs
   trunk/mcs/class/System.Data/Test/System.Data/ChangeLog
   trunk/mcs/class/System.Data/Test/System.Data/DataTableReaderTest.cs
Log:
2006-06-27  Senganal T <[EMAIL PROTECTED]>

        * Test/System.Data/DataTableReaderTest.cs :
                - Tests for Schema verification.
                - Test if GetName returns the ColumnName.
                - Tests for Provider Specific types/values
                - Tests for GetChars 
                - Test if Schema changes are caught and appropriate errors
                are raised.
        * System.Data/DataSet.cs, DataTable.cs : implement CreateDataReader 
methods 
        * System.Data/InternalDataCollectionBase.cs
                - ToArray () : helper method
        * System.Data/DataTableReader.cs : 
                - GetSchemaTable : set the schema info correctly
                - GetProvider*, GetChars, GetBytes, GetValues :
                        Implemented the methods
                - GetName : return the name of corresponding schema.
                - ValidateSchemaIntact, OnColumnCollectionChanged, 
                OnColumnChanged :
                        Listen and raise expception if schema changes



Modified: trunk/mcs/class/System.Data/System.Data/ChangeLog
===================================================================
--- trunk/mcs/class/System.Data/System.Data/ChangeLog   2006-06-27 18:56:43 UTC 
(rev 62090)
+++ trunk/mcs/class/System.Data/System.Data/ChangeLog   2006-06-27 19:10:14 UTC 
(rev 62091)
@@ -1,3 +1,17 @@
+2006-06-27  Senganal T  <[EMAIL PROTECTED]>
+
+       * DataSet.cs, DataTable.cs : implement CreateDataReader methods 
+       * InternalDataCollectionBase.cs
+               - ToArray () : helper method
+       * DataTableReader.cs : 
+               - GetSchemaTable : set the schema info correctly
+               - GetProvider*, GetChars, GetBytes, GetValues :
+                       Implemented the methods
+               - GetName : return the name of corresponding schema.
+               - ValidateSchemaIntact, OnColumnCollectionChanged, 
+               OnColumnChanged :
+                       Listen and raise expception if schema changes
+
 2006-06-21  Chris Toshok  <[EMAIL PROTECTED]>
 
        * DataView.cs: update the index after we successfully add the new

Modified: trunk/mcs/class/System.Data/System.Data/DataSet.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data/DataSet.cs  2006-06-27 18:56:43 UTC 
(rev 62090)
+++ trunk/mcs/class/System.Data/System.Data/DataSet.cs  2006-06-27 19:10:14 UTC 
(rev 62091)
@@ -600,13 +600,13 @@
                [MonoTODO]
                public DataTableReader CreateDataReader (DataTable[] dataTables)
                {
-                       throw new NotImplementedException ();
+                       return new DataTableReader (dataTables);
                }
 
                [MonoTODO]
                public DataTableReader CreateDataReader ()
                {
-                       throw new NotImplementedException ();
+                       return new DataTableReader ((DataTable[])Tables.ToArray 
(typeof (DataTable)));
                }
 #endif
                

Modified: trunk/mcs/class/System.Data/System.Data/DataTable.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data/DataTable.cs        2006-06-27 
18:56:43 UTC (rev 62090)
+++ trunk/mcs/class/System.Data/System.Data/DataTable.cs        2006-06-27 
19:10:14 UTC (rev 62091)
@@ -1030,9 +1030,9 @@
 
 #if NET_2_0
                [MonoTODO]
-               public DataTableReader GetDataReader ()
+               public DataTableReader CreateDataReader ()
                {
-                       throw new NotImplementedException ();
+                       return new DataTableReader (this);
                }
 #endif
 

Modified: trunk/mcs/class/System.Data/System.Data/DataTableReader.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data/DataTableReader.cs  2006-06-27 
18:56:43 UTC (rev 62090)
+++ trunk/mcs/class/System.Data/System.Data/DataTableReader.cs  2006-06-27 
19:10:14 UTC (rev 62091)
@@ -35,6 +35,8 @@
 
 using System.Collections;
 using System.Data.Common;
+using System.ComponentModel;
+using System.Text.RegularExpressions;
 
 namespace System.Data {
         public sealed class DataTableReader : DbDataReader
@@ -47,6 +49,7 @@
                 bool            _tableCleared = false;
                 bool            _subscribed = false;
                 DataRow         _rowRef;
+               bool            _schemaChanged = false;
 
                 #region Constructors
                 
@@ -99,10 +102,7 @@
                         get { 
                                 Validate ();
                                 if (index < 0 || index >= FieldCount)
-                                        throw new ArgumentOutOfRangeException 
(String.Format ("index {0} is not" +
-                                                                               
            "in the range",
-                                                                               
            index)
-                                                                            );
+                                        throw new ArgumentOutOfRangeException 
("index " + index + " is not in the range");
                                 DataRow row = CurrentRow;
                                 if (row.RowState == DataRowState.Deleted)
                                         throw new InvalidOperationException 
("Deleted Row's information cannot be accessed!");
@@ -145,7 +145,11 @@
                                 return;
                         CurrentTable.TableCleared += new 
DataTableClearEventHandler (OnTableCleared);
                         CurrentTable.RowChanged += new 
DataRowChangeEventHandler (OnRowChanged);
+                       CurrentTable.Columns.CollectionChanged += new 
CollectionChangeEventHandler (OnColumnCollectionChanged);
+                       for (int i=0; i < CurrentTable.Columns.Count; ++i)
+                               CurrentTable.Columns [i].PropertyChanged += new 
PropertyChangedEventHandler (OnColumnChanged);
                         _subscribed = true;
+                       _schemaChanged = false;
                 }
 
                 private void UnsubscribeEvents ()
@@ -154,7 +158,11 @@
                                 return;
                         CurrentTable.TableCleared -= new 
DataTableClearEventHandler (OnTableCleared);
                         CurrentTable.RowChanged -= new 
DataRowChangeEventHandler (OnRowChanged);
+                       CurrentTable.Columns.CollectionChanged -= new 
CollectionChangeEventHandler (OnColumnCollectionChanged);
+                       for (int i=0; i < CurrentTable.Columns.Count; ++i)
+                               CurrentTable.Columns [i].PropertyChanged -= new 
PropertyChangedEventHandler (OnColumnChanged);
                         _subscribed = false;
+                       _schemaChanged = false;
                 }
                 
                 public override void Close ()
@@ -182,10 +190,16 @@
                         return (byte) GetValue (i);
                 }
 
-                [MonoTODO]
                 public override long GetBytes (int i, long dataIndex, byte[] 
buffer, int bufferIndex, int length)
                 {
-                        throw new NotImplementedException ();
+                       byte[] value = this [i] as byte[];
+                       if (value == null)
+                               ThrowInvalidCastException (this [i].GetType (), 
typeof (byte[]));
+                       if (buffer == null)
+                               return value.Length;
+                       int copylen = length > value.Length ? value.Length : 
length;
+                       Array.Copy (value, dataIndex, buffer, bufferIndex, 
copylen);
+                       return copylen;
                 }
                 
                 public override char GetChar (int i)
@@ -193,10 +207,16 @@
                         return (char) GetValue (i);
                 }
 
-                [MonoTODO]
                 public override long GetChars (int i, long dataIndex, char[] 
buffer, int bufferIndex, int length)
                 {
-                        throw new NotImplementedException ();
+                       char[] value = this [i] as char[];
+                       if (value == null)
+                               ThrowInvalidCastException (this [i].GetType (), 
typeof (char[]));
+                       if (buffer == null)
+                               return value.Length;
+                       int copylen = length > value.Length ? value.Length : 
length;
+                       Array.Copy (value, dataIndex, buffer, bufferIndex, 
copylen);
+                       return copylen;
                 }
                 
                 public override string GetDataTypeName (int i)
@@ -219,16 +239,14 @@
                         return (double) GetValue (i);
                 }
 
-                [MonoTODO]
                 public override IEnumerator GetEnumerator ()
                 {
-                        throw new NotImplementedException ();
+                       return new DbEnumerator (this);
                 }
 
-                [MonoTODO]
                 public override Type GetProviderSpecificFieldType (int i)
                 {
-                        throw new NotImplementedException ();
+                       return GetFieldType (i);
                 }
                 
                 public override Type GetFieldType (int i)
@@ -264,29 +282,28 @@
                 
                 public override string GetName (int i)
                 {
-                        return (string) GetValue (i);
+                       ValidateClosed ();
+                       return CurrentTable.Columns [i].ColumnName;
                 }
                 
                 public override int GetOrdinal (string name)
                 {
-                        ValidateClosed ();
-                        DataColumn column = CurrentTable.Columns [name];
-                        if (column == null)
-                                throw new ArgumentException (String.Format 
("Column {0} is not found in the schema",
-                                                                             
name));
-                        return column.Ordinal;
+                       ValidateClosed ();
+                       int index = CurrentTable.Columns.IndexOf (name);
+                       if (index == -1)
+                               throw new ArgumentException (String.Format 
("Column {0} is not found in the schema",
+                                                                       name));
+                       return index;
                 }
 
-                [MonoTODO]
                 public override object GetProviderSpecificValue (int i)
                 {
-                        throw new NotImplementedException ();
+                       return GetValue (i);
                 }
 
-                [MonoTODO]
                 public override int GetProviderSpecificValues (object[] values)
                 {
-                        throw new NotImplementedException ();
+                       return GetValues (values);
                 }
                 
                 public override string GetString (int i)
@@ -299,10 +316,16 @@
                         return this [i];
                 }
 
-                [MonoTODO]
                 public override int GetValues (object[] values)
                 {
-                        throw new NotImplementedException ();
+                       Validate ();
+                       if (CurrentRow.RowState == DataRowState.Deleted)
+                               throw new DeletedRowInaccessibleException ("");
+
+                       int count = (FieldCount < values.Length ? FieldCount : 
values.Length);
+                       for (int i=0; i < count; ++i)
+                               values [i] = CurrentRow [i];
+                       return count;
                 }
                 
                 public override bool IsDBNull (int i)
@@ -312,33 +335,88 @@
                 
                 public override DataTable GetSchemaTable ()
                 {
+                       ValidateClosed ();
+                       ValidateSchemaIntact ();
+
                         if (_schemaTable != null)
                                 return _schemaTable;
-                        
-                        DataTable dt = DbDataReader.GetSchemaTableTemplate ();
-                        foreach (DataColumn column in CurrentTable.Columns) {
-                                DataRow row = dt.NewRow ();
+                       
+                       DataTable dt = new DataTable ();
+                       DataColumn[] cols = new DataColumn [25];
+                       dt.Columns.Add ("ColumnName", typeof (string));
+                       dt.Columns.Add ("ColumnOrdinal", typeof (int));
+                       dt.Columns.Add ("ColumnSize", typeof (int));
+                       dt.Columns.Add ("NumericPrecision", typeof (short));
+                       dt.Columns.Add ("NumericScale", typeof (short));
+                       dt.Columns.Add ("DataType", typeof (Type));
+                       dt.Columns.Add ("ProviderType", typeof (int));
+                       dt.Columns.Add ("IsLong", typeof (bool));
+                       dt.Columns.Add ("AllowDBNull", typeof (bool));
+                       dt.Columns.Add ("IsReadOnly", typeof (bool));
+                       dt.Columns.Add ("IsRowVersion", typeof (bool));
+                       dt.Columns.Add ("IsUnique", typeof (bool));
+                       dt.Columns.Add ("IsKey", typeof (bool));
+                       dt.Columns.Add ("IsAutoIncrement", typeof (bool));
+                       dt.Columns.Add ("BaseCatalogName", typeof (string));
+                       dt.Columns.Add ("BaseSchemaName", typeof (string));
+                       dt.Columns.Add ("BaseTableName", typeof (string));
+                       dt.Columns.Add ("BaseColumnName", typeof (string));
+                       dt.Columns.Add ("AutoIncrementSeed", typeof (Int64));
+                       dt.Columns.Add ("AutoIncrementStep", typeof (Int64));
+                       dt.Columns.Add ("DefaultValue", typeof (object));
+                       dt.Columns.Add ("Expression", typeof (string));
+                       dt.Columns.Add ("ColumnMapping", typeof (MappingType));
+                       dt.Columns.Add ("BaseTableNamespace", typeof (string));
+                       dt.Columns.Add ("BaseColumnNamespace", typeof (string));
 
-                                row ["ColumnName"]      = column.ColumnName;
-                                row ["ColumnOrdinal"]   = column.Ordinal;
-                                row ["ColumnSize"]      = column.MaxLength;
-                                row ["NumericPrecision"]= DBNull.Value;
-                                row ["NumericScale"]    = DBNull.Value;
-                                row ["IsUnique"]        = DBNull.Value;
-                                row ["IsKey"]           = DBNull.Value;
-                                row ["DataType"]        = column.DataType;
-                                row ["AllowDBNull"]     = column.AllowDBNull;
-                                row ["IsAliased"]       = DBNull.Value;
-                                row ["IsExpression"]    = DBNull.Value;
-                                row ["IsIdentity"]      = DBNull.Value;
-                                row ["IsAutoIncrement"] = DBNull.Value;
-                                row ["IsRowVersion"]    = DBNull.Value;
-                                row ["IsHidden"]        = DBNull.Value;
-                                row ["IsLong"]          = DBNull.Value;
-                                row ["IsReadOnly"]      = column.ReadOnly;
+                       DataRow row;
+                       DataColumn col;
+                       for (int i=0; i < CurrentTable.Columns.Count; ++i) {
+                               row = dt.NewRow ();
+                               col = CurrentTable.Columns [i];
+                               row ["ColumnName"] = col.ColumnName;
+                               row ["BaseColumnName"] = col.ColumnName;
+                               row ["ColumnOrdinal"] = col.Ordinal;
+                               row ["ColumnSize"] = col.MaxLength;
+                               // ms.net doesent set precision and scale even 
for Decimal values
+                               // when are these set ?
+                               row ["NumericPrecision"] = DBNull.Value;
+                               row ["NumericScale"] = DBNull.Value;
+                               row ["DataType"] = col.DataType;
+                               row ["ProviderType"] = DBNull.Value; 
//col.ProviderType;
+                               // ms.net doesent set this when datatype is 
string and maxlength = -1
+                               // when is this set ? 
+                               row ["IsLong"] = false;
+                               row ["AllowDBNull"] = col.AllowDBNull;
+                               row ["IsReadOnly"] = col.ReadOnly;
+                               row ["IsRowVersion"] = false; //this is always 
false
+                               row ["IsUnique"] = col.Unique;
+                               row ["IsKey"] = (Array.IndexOf 
(CurrentTable.PrimaryKey, col) != -1) ;
+                               row ["IsAutoIncrement"]= col.AutoIncrement;
+                               row ["AutoIncrementSeed"] = 
col.AutoIncrementSeed;
+                               row ["AutoIncrementStep"] = 
col.AutoIncrementStep;
+                               row ["BaseCatalogName"] = (CurrentTable.DataSet 
!= null ? CurrentTable.DataSet.DataSetName : null);
+                               row ["BaseSchemaName"] = DBNull.Value; // this 
is always null
+                               row ["BaseTableName"] = CurrentTable.TableName;
+                               row ["DefaultValue"] = col.DefaultValue;
+                               // If col expression depends on any external 
table , then the
+                               // Expression value is set to empty string in 
the schematable.
+                               if (col.Expression == "")
+                                       row ["Expression"] = col.Expression;
+                               else {
+                                       Regex reg = new Regex 
("((Parent|Child)( )*[.(])", RegexOptions.IgnoreCase);
+                                       if (reg.IsMatch (col.Expression, 0))
+                                               row ["Expression"] = 
DBNull.Value;
+                                       else
+                                               row ["Expression"] = 
col.Expression;
+                               }
 
-                                dt.Rows.Add (row);
-                        }
+                               row ["ColumnMapping"] = col.ColumnMapping;
+                               row ["BaseTableNamespace"] = 
CurrentTable.Namespace;
+                               row ["BaseColumnNamespace"] = col.Namespace;
+                               dt.Rows.Add (row);
+                       }
+
                         return _schemaTable = dt;
                 }
 
@@ -349,14 +427,13 @@
                         if (_index >= _tables.Length)
                                 throw new InvalidOperationException ("Invalid 
attempt to read when " + 
                                                                      "no data 
is present");
-
                         if (_tableCleared)
                                 throw new RowNotInTableException ("The table 
is cleared, no rows are " +
                                                                   
"accessible");
-                        
                        if (_current == -1)
                                 throw new InvalidOperationException 
("DataReader is invalid " + 
                                                                      "for the 
DataTable");
+                       ValidateSchemaIntact ();
                 }
 
                 private void ValidateClosed ()
@@ -365,8 +442,20 @@
                                 throw new InvalidOperationException ("Invalid 
attempt to read when " + 
                                                                      "the 
reader is closed");
                 }
+
+               private void ValidateSchemaIntact ()
+               {
+                       if (_schemaChanged)
+                               throw new InvalidOperationException ("Schema of 
current DataTable '" + CurrentTable.TableName +
+                                               "' in DataTableReader has 
changed, DataTableReader is invalid.");
+               }
+
+               void ThrowInvalidCastException (Type sourceType, Type destType)
+               {
+                       throw new InvalidCastException (String.Format ("Unable 
to cast object of type '{0}' to type '{1}'.", 
+                                                               sourceType, 
destType));
+               }
                 
-                
                 private bool MoveNext ()
                 {
                         if (_index >= _tables.Length || _tableCleared)
@@ -410,7 +499,17 @@
                 #endregion // Methods
 
                 #region // Event Handlers
+               
+               private void OnColumnChanged (object sender, 
PropertyChangedEventArgs args)
+               {
+                       _schemaChanged = true;
+               }
 
+               private void OnColumnCollectionChanged (object sender, 
CollectionChangeEventArgs args) 
+               {
+                       _schemaChanged = true;
+               }
+
                 private void OnRowChanged (object src, DataRowChangeEventArgs 
args)
                 {
                         DataRowAction action = args.Action;
@@ -453,7 +552,6 @@
                                         _rowRef = CurrentRow;
                                         return;
                                 }
-                                
                         }
                 }
 

Modified: trunk/mcs/class/System.Data/System.Data/InternalDataCollectionBase.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data/InternalDataCollectionBase.cs       
2006-06-27 18:56:43 UTC (rev 62090)
+++ trunk/mcs/class/System.Data/System.Data/InternalDataCollectionBase.cs       
2006-06-27 19:10:14 UTC (rev 62091)
@@ -137,6 +137,11 @@
                        return list.GetEnumerator ();
                }
 
+               internal Array ToArray (Type type)
+               {
+                       return list.ToArray (type);
+               }
+
                #endregion
        }
 }

Modified: trunk/mcs/class/System.Data/Test/System.Data/ChangeLog
===================================================================
--- trunk/mcs/class/System.Data/Test/System.Data/ChangeLog      2006-06-27 
18:56:43 UTC (rev 62090)
+++ trunk/mcs/class/System.Data/Test/System.Data/ChangeLog      2006-06-27 
19:10:14 UTC (rev 62091)
@@ -1,3 +1,13 @@
+2006-06-27  Senganal T <[EMAIL PROTECTED]>
+
+       * DataTableReaderTest.cs :
+               - Tests for Schema verification.
+               - Test if GetName returns the ColumnName.
+               - Tests for Provider Specific types/values
+               - Tests for GetChars 
+               - Test if Schema changes are caught and appropriate errors
+               are raised.
+               
 2006-06-15  Senganal T <[EMAIL PROTECTED]>
 
        * DataTableTest2.cs :

Modified: trunk/mcs/class/System.Data/Test/System.Data/DataTableReaderTest.cs
===================================================================
--- trunk/mcs/class/System.Data/Test/System.Data/DataTableReaderTest.cs 
2006-06-27 18:56:43 UTC (rev 62090)
+++ trunk/mcs/class/System.Data/Test/System.Data/DataTableReaderTest.cs 
2006-06-27 19:10:14 UTC (rev 62091)
@@ -33,6 +33,8 @@
 
 using System;
 using System.Data;
+using System.Data.Common;
+using System.Collections;
 
 using NUnit.Framework;
 
@@ -526,7 +528,267 @@
                         }
                 }
                 #endregion // Negative Tests
+               
+               [Test]
+               public void TestSchemaTable()
+               {
+                       DataSet ds = new DataSet();
+                       DataTable testTable = new DataTable ("TestTable1");
+                       DataTable testTable1 = new DataTable ();
+                       
+                       testTable.Namespace = "TableNamespace";
+                       
+                       testTable1.Columns.Add ("col1", typeof(int));
+                       testTable1.Columns.Add ("col2", typeof(int));
+                       ds.Tables.Add (testTable);
+                       ds.Tables.Add (testTable1);
+                       
+                       //create a col for standard datatype
+                       
+                       testTable.Columns.Add ("col_string");
+                       testTable.Columns.Add ("col_string_fixed");
+                       testTable.Columns ["col_string_fixed"].MaxLength = 10;
+                       testTable.Columns.Add ("col_int", typeof(int));
+                       testTable.Columns.Add ("col_decimal", typeof(decimal));
+                       testTable.Columns.Add ("col_datetime", 
typeof(DateTime));
+                       testTable.Columns.Add ("col_float", typeof (float));
+                       
+                       // Check for col constraints/properties
+                       testTable.Columns.Add ("col_readonly").ReadOnly = true;
+                       
+                       testTable.Columns.Add ("col_autoincrement", 
typeof(Int64)).AutoIncrement = true;
+                       testTable.Columns 
["col_autoincrement"].AutoIncrementStep = 5;
+                       testTable.Columns 
["col_autoincrement"].AutoIncrementSeed = 10;
+                       
+                       testTable.Columns.Add ("col_pk");
+                       testTable.PrimaryKey = new DataColumn[] 
{testTable.Columns ["col_pk"]};
+                       
+                       testTable.Columns.Add ("col_unique");
+                       testTable.Columns ["col_unique"].Unique = true;
+                       
+                       testTable.Columns.Add ("col_defaultvalue");
+                       testTable.Columns ["col_defaultvalue"].DefaultValue = 
"DefaultValue";
+                       
+                       testTable.Columns.Add ("col_expression_local", 
typeof(int));
+                       testTable.Columns ["col_expression_local"].Expression = 
"col_int*5";
+                       
+                       ds.Relations.Add ("rel", new DataColumn[] 
{testTable1.Columns ["col1"]}, 
+                                       new DataColumn[] {testTable.Columns 
["col_int"]}, false);
+                       testTable.Columns.Add ("col_expression_ext");
+                       testTable.Columns ["col_expression_ext"].Expression = 
"parent.col2";
+                       
+                       testTable.Columns.Add ("col_namespace");
+                       testTable.Columns ["col_namespace"].Namespace = 
"ColumnNamespace";
+                       
+                       testTable.Columns.Add ("col_mapping");
+                       testTable.Columns ["col_mapping"].ColumnMapping = 
MappingType.Attribute;
+                       
+                       DataTable schemaTable = testTable.CreateDataReader 
().GetSchemaTable ();
+                       
+                       Assert.AreEqual (25, schemaTable.Columns.Count, "#1");
+                       Assert.AreEqual (testTable.Columns.Count, 
schemaTable.Rows.Count, "#2");
+                       
+                       //True for all rows
+                       for (int i = 0; i < schemaTable.Rows.Count; ++i) {
+                               Assert.AreEqual (testTable.TableName, 
schemaTable.Rows [i]["BaseTableName"], i+"_#3");
+                               Assert.AreEqual (ds.DataSetName, 
schemaTable.Rows [i]["BaseCatalogName"], i+"_#4");
+                               Assert.AreEqual (DBNull.Value, schemaTable.Rows 
[i]["BaseSchemaName"], i+"_#5");
+                               Assert.AreEqual (schemaTable.Rows 
[i]["BaseColumnName"], schemaTable.Rows [i]["ColumnName"], i+"_#6");
+                               Assert.IsFalse ((bool)schemaTable.Rows 
[i]["IsRowVersion"], i+"_#7");
+                       }
+                       
+                       Assert.AreEqual ("col_string", schemaTable.Rows 
[0]["ColumnName"], "#8");
+                       Assert.AreEqual (typeof(string), schemaTable.Rows 
[0]["DataType"], "#9");
+                       Assert.AreEqual (-1, schemaTable.Rows 
[0]["ColumnSize"], "#10");
+                       Assert.AreEqual (0, schemaTable.Rows 
[0]["ColumnOrdinal"], "#11");
+                       // ms.net contradicts documented behavior
+                       Assert.IsFalse ((bool)schemaTable.Rows [0]["IsLong"], 
"#12");
+                       
+                       Assert.AreEqual ("col_string_fixed", schemaTable.Rows 
[1]["ColumnName"], "#13");
+                       Assert.AreEqual (typeof(string), schemaTable.Rows 
[1]["DataType"], "#14");
+                       Assert.AreEqual (10, schemaTable.Rows 
[1]["ColumnSize"], "#15");
+                       Assert.AreEqual (1, schemaTable.Rows 
[1]["ColumnOrdinal"], "#16");
+                       Assert.IsFalse ((bool)schemaTable.Rows [1]["IsLong"], 
"#17");
+                       
+                       Assert.AreEqual ("col_int", schemaTable.Rows 
[2]["ColumnName"], "#18");
+                       Assert.AreEqual (typeof(int), schemaTable.Rows 
[2]["DataType"], "#19");
+                       Assert.AreEqual (DBNull.Value, schemaTable.Rows 
[2]["NumericPrecision"], "#20");
+                       Assert.AreEqual (DBNull.Value, schemaTable.Rows 
[2]["NumericScale"], "#21");
+                       Assert.AreEqual (-1, schemaTable.Rows 
[2]["ColumnSize"], "#22");
+                       Assert.AreEqual (2, schemaTable.Rows 
[2]["ColumnOrdinal"], "#23");
+                       
+                       Assert.AreEqual ("col_decimal", schemaTable.Rows 
[3]["ColumnName"], "#24");
+                       Assert.AreEqual (typeof(decimal), schemaTable.Rows 
[3]["DataType"], "#25");
+                       // When are the Precision and Scale Values set ? 
+                       Assert.AreEqual (DBNull.Value, schemaTable.Rows 
[3]["NumericPrecision"], "#26");
+                       Assert.AreEqual (DBNull.Value, schemaTable.Rows 
[3]["NumericScale"], "#27");
+                       Assert.AreEqual (-1, schemaTable.Rows 
[3]["ColumnSize"], "#28");
+                       Assert.AreEqual (3, schemaTable.Rows 
[3]["ColumnOrdinal"], "#29");
+                       
+                       Assert.AreEqual ("col_datetime", schemaTable.Rows 
[4]["ColumnName"], "#30");
+                       Assert.AreEqual (typeof(DateTime), schemaTable.Rows 
[4]["DataType"], "#31");
+                       Assert.AreEqual (4, schemaTable.Rows 
[4]["ColumnOrdinal"], "#32");
+                       
+                       Assert.AreEqual ("col_float", schemaTable.Rows 
[5]["ColumnName"], "#33");
+                       Assert.AreEqual (typeof(float), schemaTable.Rows 
[5]["DataType"], "#34");
+                       Assert.AreEqual (5, schemaTable.Rows 
[5]["ColumnOrdinal"], "#35");
+                       Assert.AreEqual (DBNull.Value, schemaTable.Rows 
[5]["NumericPrecision"], "#36");
+                       Assert.AreEqual (DBNull.Value, schemaTable.Rows 
[5]["NumericScale"], "#37");
+                       Assert.AreEqual (-1, schemaTable.Rows 
[5]["ColumnSize"], "#38");
+                       
+                       Assert.AreEqual ("col_readonly", schemaTable.Rows 
[6]["ColumnName"], "#39");
+                       Assert.IsTrue ((bool)schemaTable.Rows 
[6]["IsReadOnly"], "#40");
+                       
+                       Assert.AreEqual ("col_autoincrement", schemaTable.Rows 
[7]["ColumnName"], "#9");
+                       Assert.IsTrue ((bool)schemaTable.Rows 
[7]["IsAutoIncrement"], "#41");
+                       Assert.AreEqual (10, schemaTable.Rows 
[7]["AutoIncrementSeed"], "#42");
+                       Assert.AreEqual (5, schemaTable.Rows 
[7]["AutoIncrementStep"], "#43");
+                       Assert.IsFalse ((bool)schemaTable.Rows 
[7]["IsReadOnly"], "#44");
+                       
+                       Assert.AreEqual ("col_pk", schemaTable.Rows 
[8]["ColumnName"], "#45");
+                       Assert.IsTrue ((bool)schemaTable.Rows [8]["IsKey"], 
"#46");
+                       Assert.IsTrue ((bool)schemaTable.Rows [8]["IsUnique"], 
"#47");
+                       
+                       Assert.AreEqual ("col_unique", schemaTable.Rows 
[9]["ColumnName"], "#48");
+                       Assert.IsTrue ((bool)schemaTable.Rows [9]["IsUnique"], 
"#49");
+                       
+                       Assert.AreEqual ("col_defaultvalue", schemaTable.Rows 
[10]["ColumnName"], "#50");
+                       Assert.AreEqual ("DefaultValue", schemaTable.Rows 
[10]["DefaultValue"], "#51");
+                       
+                       Assert.AreEqual ("col_expression_local", 
schemaTable.Rows [11]["ColumnName"], "#52");
+                       Assert.AreEqual ("col_int*5", schemaTable.Rows 
[11]["Expression"], "#53");
+                       Assert.IsTrue ((bool)schemaTable.Rows 
[11]["IsReadOnly"], "#54");
+                       
+                       // if expression depends on a external col, then set 
Expression as null..
+                       Assert.AreEqual ("col_expression_ext", schemaTable.Rows 
[12]["ColumnName"], "#55");
+                       Assert.AreEqual (DBNull.Value, schemaTable.Rows 
[12]["Expression"], "#56");
+                       Assert.IsTrue ((bool)schemaTable.Rows 
[12]["IsReadOnly"], "#57");
+                       
+                       Assert.AreEqual ("col_namespace", schemaTable.Rows 
[13]["ColumnName"], "#58");
+                       Assert.AreEqual ("TableNamespace", schemaTable.Rows 
[13]["BaseTableNamespace"], "#59");
+                       Assert.AreEqual ("TableNamespace", schemaTable.Rows 
[12]["BaseColumnNamespace"], "#60");
+                       Assert.AreEqual ("ColumnNamespace", schemaTable.Rows 
[13]["BaseColumnNamespace"], "#61");
+                       
+                       Assert.AreEqual ("col_mapping", schemaTable.Rows 
[14]["ColumnName"], "#62");
+                       Assert.AreEqual (MappingType.Element, 
(MappingType)schemaTable.Rows [13]["ColumnMapping"], "#63");
+                       Assert.AreEqual (MappingType.Attribute, 
(MappingType)schemaTable.Rows [14]["ColumnMapping"], "#64");
+               }
 
+               [Test]
+               public void TestExceptionIfSchemaChanges ()
+               {
+                       DataTable table = new DataTable ();
+                       table.Columns.Add ("col1");
+                       DataTableReader rdr = table.CreateDataReader ();
+                       Assert.AreEqual (1, rdr.GetSchemaTable().Rows.Count, 
"#1");
+
+                       table.Columns [0].ColumnName = "newcol1";
+                       try {
+                               rdr.GetSchemaTable ();
+                               Assert.Fail ("#0");
+                       } catch (InvalidOperationException e) {
+                               Assert.AreEqual ("Schema of current DataTable 
'" + table.TableName + 
+                                               "' in DataTableReader has 
changed, DataTableReader is invalid.", e.Message, "#1");
+                       }
+                       
+                       rdr = table.CreateDataReader ();
+                       rdr.GetSchemaTable (); //no exception
+                       table.Columns.Add ("col2");
+                       try {
+                               rdr.GetSchemaTable ();
+                               Assert.Fail ("#1");
+                       } catch (InvalidOperationException e) {
+                               Assert.AreEqual ("Schema of current DataTable 
'" + table.TableName + 
+                                               "' in DataTableReader has 
changed, DataTableReader is invalid.", e.Message, "#1");
+                       }
+               }
+       
+               [Test]
+               public void EnumeratorTest ()
+               {
+                       DataTable table = new DataTable ();
+                       table.Columns.Add ("col1", typeof(int));
+                       table.Rows.Add (new object[] {0});
+                       table.Rows.Add (new object[] {1});
+                       
+                       DataTableReader rdr = table.CreateDataReader ();
+                       IEnumerator enmr = rdr.GetEnumerator ();
+                       
+                       table.Rows.Add (new object[] {2});
+                       table.Rows.RemoveAt (0);
+                                               
+                       //Test if the Enumerator is stable
+                       int i = 1;
+                       while (enmr.MoveNext ()) {
+                               DbDataRecord rec = (DbDataRecord)enmr.Current;
+                               Assert.AreEqual (i, rec.GetInt32 (0), "#2_" + 
i);
+                               i++;
+                       }
+               }
+               
+               [Test]
+               public void GetCharsTest()
+               {
+                       dt.Columns.Add ("col2", typeof (char[]));
+                       
+                       dt.Rows.Clear ();
+                       dt.Rows.Add (new object[] {1, "string", 
"string".ToCharArray()}); 
+                       dt.Rows.Add (new object[] {2, "string1", null}); 
+                       DataTableReader rdr = dt.CreateDataReader ();
+                       
+                       rdr.Read ();
+                       
+                       try {
+                               rdr.GetChars (1, 0, null, 0, 10);
+                               Assert.Fail ("#1");
+                       } catch (InvalidCastException e) {
+                               Assert.AreEqual ("Unable to cast object of type 
'System.String'" +
+                                       " to type 'System.Char[]'.", e.Message, 
"#1");
+                       }
+                       char[] char_arr = null;
+                       long len = 0;
+                       
+                       len =  rdr.GetChars (2, 0, null, 0, 0);
+                       Assert.AreEqual(6, len, "#2");
+                       
+                       char_arr = new char [len];
+                       len = rdr.GetChars (2, 0, char_arr, 0, 0);
+                       Assert.AreEqual(0, len, "#3");
+                       
+                       len = rdr.GetChars (2, 0, null, 0, 0);
+                       char_arr = new char [len+2];
+                       len = rdr.GetChars (2, 0, char_arr, 2, 100);
+                       Assert.AreEqual (6, len, "#4");
+                       char[] val = (char[])rdr.GetValue (2);
+                       for (int i = 0; i < len; ++i)
+                               Assert.AreEqual (val[i], char_arr[i+2], 
"#5_"+i);
+               }
+               
+               [Test]
+               public void GetProviderSpecificTests()
+               {
+                       DataTableReader rdr = dt.CreateDataReader ();
+                       while (rdr.Read ()) {
+                               object[] values = new object [rdr.FieldCount];
+                               object[] pvalues = new object [rdr.FieldCount];
+                               rdr.GetValues (values);
+                               rdr.GetProviderSpecificValues (pvalues);
+                               
+                               for (int i = 0; i < rdr.FieldCount; ++i) {
+                                       Assert.AreEqual(values [i], pvalues 
[i], "#1");
+                                       Assert.AreEqual(rdr.GetValue (i), 
rdr.GetProviderSpecificValue (i), "#2");
+                                       Assert.AreEqual(rdr.GetFieldType (i), 
rdr.GetProviderSpecificFieldType (i), "#3");
+                               }
+                       }
+               }
+               
+               [Test]
+               public void GetNameTest()
+               {
+                       DataTableReader rdr = dt.CreateDataReader();
+                       for (int i = 0; i < dt.Columns.Count; ++i)
+                               Assert.AreEqual(dt.Columns[i].ColumnName, 
rdr.GetName(i), "#1_" + i);
+               }
         }
 }
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to