Author: anagappan
Date: 2006-12-20 12:17:24 -0500 (Wed, 20 Dec 2006)
New Revision: 69818

Modified:
   trunk/mcs/class/System.Data/System.Data.Common/ChangeLog
   trunk/mcs/class/System.Data/System.Data.Common/DataAdapter.cs
   trunk/mcs/class/System.Data/System.Data.Common/DataColumnMapping.cs
   trunk/mcs/class/System.Data/System.Data.Common/DbCommandBuilder.cs
   trunk/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs
   trunk/mcs/class/System.Data/System.Data.Common/DbDataReader.cs
   trunk/mcs/class/System.Data/System.Data.Common/RowUpdatedEventArgs.cs
Log:
2006-12-20  Nagappan A  <[EMAIL PROTECTED]>

        * DataColumnMapping.cs (GetDataColumnBySchemaAction): Implemented
        2.0 profile method.

        * DbDataReader.cs: Removed TODO's where ever the implementation is
        available.

        * RowUpdatedEventArgs.cs: Removed TODO's where ever the
        implementation is available.

        * DataAdapter.cs (FillInternal): Moved from DbDataAdapater.cs to
        here.
        (BuildSchema): Moved from DbDataAdapter.cs.
        (FillTable): Moved from DbDataAdapter.cs.
        (OnFillErrorInternal): Implemented new internal method to raise an
        event.
        (SetupSchema): Moved from DbDataAdapter.cs.
        (FillInterl): Moved common implementation from DbDataAdapter.cs.
        Removed TODO's where ever the implementation is available.

        * DbDataAdapter.cs (OnRowUpdated): Implemented protected method.
        (OnRowUpdating): Implemented protected method.
        (CreateFillErrorEvent): Moved to DataAdapter.cs.
        (Fill): Moved common implementation to DataAdapter.cs.
        (FillTable): Moved to DataAdapter.cs.
        (BuildSchema): Moved to DataAdapter.cs.
        (SetupSchema): Moved to DataAdapter.cs.



Modified: trunk/mcs/class/System.Data/System.Data.Common/ChangeLog
===================================================================
--- trunk/mcs/class/System.Data/System.Data.Common/ChangeLog    2006-12-20 
17:16:37 UTC (rev 69817)
+++ trunk/mcs/class/System.Data/System.Data.Common/ChangeLog    2006-12-20 
17:17:24 UTC (rev 69818)
@@ -1,3 +1,32 @@
+2006-12-20  Nagappan A  <[EMAIL PROTECTED]>
+
+       * DataColumnMapping.cs (GetDataColumnBySchemaAction): Implemented
+       2.0 profile method.
+
+       * DbDataReader.cs: Removed TODO's where ever the implementation is
+       available.
+
+       * RowUpdatedEventArgs.cs: Removed TODO's where ever the
+       implementation is available.
+
+       * DataAdapter.cs (FillInternal): Moved from DbDataAdapater.cs to
+       here.
+       (BuildSchema): Moved from DbDataAdapter.cs.
+       (FillTable): Moved from DbDataAdapter.cs.
+       (OnFillErrorInternal): Implemented new internal method to raise an
+       event.
+       (SetupSchema): Moved from DbDataAdapter.cs.
+       (FillInterl): Moved common implementation from DbDataAdapter.cs.
+       Removed TODO's where ever the implementation is available.
+
+       * DbDataAdapter.cs (OnRowUpdated): Implemented protected method.
+       (OnRowUpdating): Implemented protected method.
+       (CreateFillErrorEvent): Moved to DataAdapter.cs.
+       (Fill): Moved common implementation to DataAdapter.cs.
+       (FillTable): Moved to DataAdapter.cs.
+       (BuildSchema): Moved to DataAdapter.cs.
+       (SetupSchema): Moved to DataAdapter.cs.
+
 2006-12-11  Miguel de Icaza  <[EMAIL PROTECTED]>
 
        * DataAdapter.cs: Removed TODO, NotSupportedException was the

Modified: trunk/mcs/class/System.Data/System.Data.Common/DataAdapter.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data.Common/DataAdapter.cs       
2006-12-20 17:16:37 UTC (rev 69817)
+++ trunk/mcs/class/System.Data/System.Data.Common/DataAdapter.cs       
2006-12-20 17:17:24 UTC (rev 69818)
@@ -32,8 +32,10 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System;
+using System.Data;
+using System.Collections;
 using System.ComponentModel;
-using System.Data;
 
 namespace System.Data.Common
 {
@@ -53,13 +55,14 @@
                private MissingMappingAction missingMappingAction;
                private MissingSchemaAction missingSchemaAction;
                private DataTableMappingCollection tableMappings;
+               private const string DefaultSourceTableName = "Table";
+               private const string DefaultSourceColumnName = "Column";
 
 #if NET_2_0
                private bool acceptChangesDuringUpdate;
                private LoadOption fillLoadOption;
                private bool returnProviderSpecificTypes;
 #endif
-
                #endregion
 
                #region Constructors
@@ -222,16 +225,350 @@
                }
 
 
+               internal int FillInternal (DataTable dataTable, IDataReader 
dataReader)
+               {
+                       if (dataReader.FieldCount == 0) {
+                               dataReader.Close ();
+                               return 0;
+                       }
+                       
+                       int count = 0;
+
+                       try {
+                               string tableName = SetupSchema 
(SchemaType.Mapped, dataTable.TableName);
+                               if (tableName != null) {
+                                       dataTable.TableName = tableName;
+                                       FillTable (dataTable, dataReader, 0, 0, 
ref count);
+                               }
+                       } finally {
+                               dataReader.Close ();
+                       }
+
+                       return count;
+               }
+
+               // this method builds the schema for a given datatable. it 
returns a int array with 
+               // "array[ordinal of datatable column] == index of source 
column in data reader".
+               // each column in the datatable has a mapping to a specific 
column in the datareader,
+               // the int array represents this match.
+               internal int[] BuildSchema (IDataReader reader, DataTable 
table, SchemaType schemaType)
+               {
+                       return BuildSchema (reader, table, schemaType, 
MissingSchemaAction,
+                                           MissingMappingAction, 
TableMappings);
+                }
+
+                /// <summary>
+                ///     Creates or Modifies the schema of the given DataTable 
based on the schema of
+                ///     the reader and the arguments passed.
+                /// </summary>
+                internal static int[] BuildSchema (IDataReader reader,
+                                                   DataTable table,
+                                                   SchemaType schemaType,
+                                                   MissingSchemaAction 
missingSchAction,
+                                                   MissingMappingAction 
missingMapAction,
+                                                   DataTableMappingCollection 
dtMapping
+                                                   )
+               {
+                       int readerIndex = 0;
+                       // FIXME : this fails if query has fewer columns than a 
table
+                       int[] mapping = new int[table.Columns.Count]; // 
mapping the reader indexes to the datatable indexes
+                       
+                       for(int i=0; i < mapping.Length; i++) {
+                               mapping[i] = -1;
+                       }
+                       
+                       ArrayList primaryKey = new ArrayList ();
+                       ArrayList sourceColumns = new ArrayList ();
+                       bool createPrimaryKey = true;
+                       
+                       DataTable schemaTable = reader.GetSchemaTable ();
+
+                       DataColumn ColumnNameCol =  
schemaTable.Columns["ColumnName"];
+                       DataColumn DataTypeCol = 
schemaTable.Columns["DataType"];
+                       DataColumn IsAutoIncrementCol = 
schemaTable.Columns["IsAutoIncrement"];
+                       DataColumn AllowDBNullCol = 
schemaTable.Columns["AllowDBNull"];
+                       DataColumn IsReadOnlyCol = 
schemaTable.Columns["IsReadOnly"];
+                       DataColumn IsKeyCol = schemaTable.Columns["IsKey"];
+                       DataColumn IsUniqueCol = 
schemaTable.Columns["IsUnique"];
+                       DataColumn ColumnSizeCol = 
schemaTable.Columns["ColumnSize"];
+
+                       foreach (DataRow schemaRow in schemaTable.Rows) {
+                               // generate a unique column name in the source 
table.
+                               string sourceColumnName;
+                               string realSourceColumnName ;
+                               if (ColumnNameCol == null || 
schemaRow.IsNull(ColumnNameCol) ||
+                                   (string)schemaRow [ColumnNameCol] == 
String.Empty) {
+                                       sourceColumnName = 
DefaultSourceColumnName;
+                                       realSourceColumnName = 
DefaultSourceColumnName + "1";
+                               }
+                               else {
+                                       sourceColumnName = (string) schemaRow 
[ColumnNameCol];
+                                       realSourceColumnName = sourceColumnName;
+                               }
+
+                               for (int i = 1; sourceColumns.Contains 
(realSourceColumnName); i += 1) 
+                                       realSourceColumnName = String.Format 
("{0}{1}", sourceColumnName, i);
+                               sourceColumns.Add(realSourceColumnName);
+
+                               // generate DataSetColumnName from 
DataTableMapping, if any
+                               string dsColumnName = realSourceColumnName;
+                               DataTableMapping tableMapping = null;
+
+                               //FIXME : The sourcetable name shud get passed 
as a parameter.. 
+                               int index = dtMapping.IndexOfDataSetTable 
(table.TableName);
+                               string srcTable = (index != -1 ? 
dtMapping[index].SourceTable : table.TableName);
+                               tableMapping = 
DataTableMappingCollection.GetTableMappingBySchemaAction (dtMapping, srcTable, 
table.TableName, missingMapAction); 
+                               if (tableMapping != null)
+                               {
+                                       table.TableName = 
tableMapping.DataSetTable;
+                                       // check to see if the column mapping 
exists
+                                       DataColumnMapping columnMapping = 
DataColumnMappingCollection.GetColumnMappingBySchemaAction(tableMapping.ColumnMappings,
 realSourceColumnName, missingMapAction);
+                                       if (columnMapping != null)
+                                       {
+                                               Type columnType = 
(Type)schemaRow[DataTypeCol];
+                                               DataColumn col =
+                                                       
columnMapping.GetDataColumnBySchemaAction(
+                                                                               
                  table ,
+                                                                               
                  columnType,
+                                                                               
                  missingSchAction);
+
+                                               if (col != null)
+                                               {
+                                                       // if the column is not 
in the table - add it.
+                                                       if 
(table.Columns.IndexOf(col) == -1)
+                                                       {
+                                                               if 
(missingSchAction == MissingSchemaAction.Add 
+                                                                   || 
missingSchAction == MissingSchemaAction.AddWithKey)
+                                                                       
table.Columns.Add(col);
+
+                                                               int[] tmp = new 
int[mapping.Length + 1];
+                                                               
Array.Copy(mapping,0,tmp,0,col.Ordinal);
+                                                               
Array.Copy(mapping,col.Ordinal,tmp,col.Ordinal + 1,mapping.Length - 
col.Ordinal);
+                                                               mapping = tmp;
+                                                       }                       
        
+
+
+                                                       if (missingSchAction == 
MissingSchemaAction.AddWithKey) {
+                                   
+                                                               object value = 
(AllowDBNullCol != null) ? schemaRow[AllowDBNullCol] : null;
+                                                               bool 
allowDBNull = value is bool ? (bool)value : true;
+
+                                                               value = 
(IsKeyCol != null) ? schemaRow[IsKeyCol] : null;
+                                                               bool isKey = 
value is bool ? (bool)value : false;
+
+                                                               value = 
(IsAutoIncrementCol != null) ? schemaRow[IsAutoIncrementCol] : null;
+                                                               bool 
isAutoIncrement = value is bool ? (bool)value : false;
+
+                                                               value = 
(IsReadOnlyCol != null) ? schemaRow[IsReadOnlyCol] : null;
+                                                               bool isReadOnly 
= value is bool ? (bool)value : false;
+
+                                                               value = 
(IsUniqueCol != null) ? schemaRow[IsUniqueCol] : null;
+                                                               bool isUnique = 
value is bool ? (bool)value : false;
+                                                               
+                                                               col.AllowDBNull 
= allowDBNull;
+                                                               // fill woth 
key info                                                           
+                                                               if 
(isAutoIncrement && DataColumn.CanAutoIncrement(columnType)) {
+                                                                       
col.AutoIncrement = true;
+                                                                       if 
(!allowDBNull)
+                                                                               
col.AllowDBNull = false;
+                                                               }
+
+                                                               if (columnType 
== DbTypes.TypeOfString) {
+                                                                       
col.MaxLength = (ColumnSizeCol != null) ? (int)schemaRow[ColumnSizeCol] : 0;
+                                                               }
+
+                                                               if (isReadOnly)
+                                                                       
col.ReadOnly = true;
+                                                                       
+                                                               if 
(!allowDBNull && (!isReadOnly || isKey))
+                                                                       
col.AllowDBNull = false;
+                                                               if (isUnique && 
!isKey && !columnType.IsArray) {
+                                                                       
col.Unique = true;
+                                                                       if 
(!allowDBNull)
+                                                                               
col.AllowDBNull = false;
+                                                               }
+                                                               
+                                                               // This might 
not be set by all DataProviders
+                                                               bool isHidden = 
false;
+                                                               if 
(schemaTable.Columns.Contains ("IsHidden")) {
+                                                                       value = 
schemaRow["IsHidden"];
+                                                                       
isHidden = ((value is bool) ? (bool)value : false);
+                                                               }
+
+                                                               if (isKey && 
!isHidden) {
+                                                                       
primaryKey.Add (col);
+                                                                       if 
(allowDBNull)
+                                                                               
createPrimaryKey = false;
+                                                               }
+                                                       }
+                                                       // add the ordinal of 
the column as a key and the index of the column in the datareader as a value.
+                                                       mapping[col.Ordinal] = 
readerIndex++;
+                                               }
+                                       }
+                               }
+                       }
+                       if (primaryKey.Count > 0) {
+                               DataColumn[] colKey = 
(DataColumn[])(primaryKey.ToArray(typeof (DataColumn)));
+                               if (createPrimaryKey)
+                                       table.PrimaryKey = colKey;
+                               else {
+                                       UniqueConstraint uConstraint = new 
UniqueConstraint(colKey);
+                                       for (int i = 0; i < 
table.Constraints.Count; i++) {
+                                               if 
(table.Constraints[i].Equals(uConstraint)) {
+                                                       uConstraint = null;
+                                                       break;
+                                               }
+                                       }
+
+                                       if (uConstraint != null)
+                                               
table.Constraints.Add(uConstraint);
+                               }
+                       }
+                       return mapping;
+                }
+
+               internal bool FillTable (DataTable dataTable, IDataReader 
dataReader, int startRecord, int maxRecords, ref int counter)
+               {
+                       if (dataReader.FieldCount == 0)
+                               return false;
+
+                       int counterStart = counter;
+
+                       int[] mapping = BuildSchema (dataReader, dataTable, 
SchemaType.Mapped);
+                       
+                       int[] sortedMapping = new int[mapping.Length];
+                       int length = sortedMapping.Length;
+                       for(int i=0; i < sortedMapping.Length; i++) {
+                               if (mapping[i] >= 0)
+                                       sortedMapping[mapping[i]] = i;
+                               else
+                                       sortedMapping[--length] = i;
+                       }
+
+                       for (int i = 0; i < startRecord; i++) {
+                               dataReader.Read ();
+                       }
+
+                       dataTable.BeginLoadData ();
+                       while (dataReader.Read () && (maxRecords == 0 || 
(counter - counterStart) < maxRecords)) {
+                               try {
+                                       dataTable.LoadDataRow (dataReader, 
sortedMapping, length, AcceptChangesDuringFill);
+                                       counter++;
+                               }
+                               catch (Exception e) {
+                                       object[] readerArray = new 
object[dataReader.FieldCount];
+                                       object[] tableArray = new 
object[mapping.Length];
+                                       // we get the values from the datareader
+                                       dataReader.GetValues (readerArray);
+                                       // copy from datareader columns to 
table columns according to given mapping
+                                       for (int i = 0; i < mapping.Length; 
i++) {
+                                               if (mapping[i] >= 0) {
+                                                       tableArray[i] = 
readerArray[mapping[i]];
+                                               }
+                                       }
+                                       FillErrorEventArgs args = 
CreateFillErrorEvent (dataTable, tableArray, e);
+                                       OnFillErrorInternal (args);
+
+                                       // if args.Continue is not set to true 
or if a handler is not set, rethrow the error..
+                                       if(!args.Continue)
+                                               throw e;
+                               }
+                       }
+                       dataTable.EndLoadData ();
+                       return true;
+               }
+
+               internal virtual void OnFillErrorInternal (FillErrorEventArgs 
value)
+               {
 #if NET_2_0
+                       OnFillError (value);
+#endif
+               }
+
+               internal FillErrorEventArgs CreateFillErrorEvent (DataTable 
dataTable, object[] values, Exception e)
+               {
+                       FillErrorEventArgs args = new FillErrorEventArgs 
(dataTable, values);
+                       args.Errors = e;
+                       args.Continue = false;
+                       return args;
+               }
+
+               internal string SetupSchema (SchemaType schemaType, string 
sourceTableName)
+               {
+                       DataTableMapping tableMapping = null;
+
+                       if (schemaType == SchemaType.Mapped) 
+                       {
+                               tableMapping = 
DataTableMappingCollection.GetTableMappingBySchemaAction (TableMappings, 
sourceTableName, sourceTableName, MissingMappingAction);
+                               if (tableMapping != null)
+                                       return tableMapping.DataSetTable;
+                               return null;
+                       }
+                       else
+                               return sourceTableName;
+               }
+
+               internal int FillInternal (DataSet dataSet, string srcTable, 
IDataReader dataReader, int startRecord, int maxRecords)
+               {
+                       if (dataSet == null)
+                               throw new ArgumentNullException ("DataSet");
+
+                       if (startRecord < 0)
+                               throw new ArgumentException ("The startRecord 
parameter was less than 0.");
+                       if (maxRecords < 0)
+                               throw new ArgumentException ("The maxRecords 
parameter was less than 0.");
+
+                       DataTable dataTable = null;
+                       int resultIndex = 0;
+                       int count = 0;
+                       
+                       try {
+                               string tableName = srcTable;
+                               do {
+                                       // Non-resultset queries like insert, 
delete or update aren't processed.
+                                       if (dataReader.FieldCount != -1) {
+                                               tableName = SetupSchema 
(SchemaType.Mapped, tableName);
+                                               if (tableName != null) {
+                                                       
+                                                       // check if the table 
exists in the dataset
+                                                       if 
(dataSet.Tables.Contains (tableName)) 
+                                                               // get the 
table from the dataset
+                                                               dataTable = 
dataSet.Tables [tableName];
+                                                       else {
+                                                               // Do not 
create schema if MissingSchemAction is set to Ignore
+                                                               if 
(this.MissingSchemaAction == MissingSchemaAction.Ignore)
+                                                                       
continue;
+                                                               dataTable = 
dataSet.Tables.Add (tableName);
+                                                       }
+       
+                                                       if (!FillTable 
(dataTable, dataReader, startRecord, maxRecords, ref count)) {
+                                                               continue;
+                                                       }
+       
+                                                       tableName = 
String.Format ("{0}{1}", srcTable, ++resultIndex);
+       
+                                                       startRecord = 0;
+                                                       maxRecords = 0;
+                                               }
+                                       }
+                               } while (dataReader.NextResult ());
+                       } 
+                       finally {
+                               dataReader.Close ();
+                       }
+
+                        return count;
+               }
+
+#if NET_2_0
                public virtual int Fill (DataSet dataSet)
                {
-                       throw new NotSupportedException ();
+                       throw new NotSupportedException();
                }
 
-               [MonoTODO]
                protected virtual int Fill (DataTable dataTable, IDataReader 
dataReader)
                {
-                       throw new NotImplementedException ();
+                       return FillInternal (dataTable, dataReader);
                }
 
                [MonoTODO]
@@ -240,10 +577,9 @@
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                protected virtual int Fill (DataSet dataSet, string srcTable, 
IDataReader dataReader, int startRecord, int maxRecords)
                {
-                       throw new NotImplementedException ();
+                       return FillInternal (dataSet, srcTable, dataReader, 
startRecord, maxRecords);
                }
 
                [MonoTODO]
@@ -279,7 +615,6 @@
                {
                        if (FillError != null)
                                FillError (this, value);
-
                }
 
                [EditorBrowsable (EditorBrowsableState.Never)]

Modified: trunk/mcs/class/System.Data/System.Data.Common/DataColumnMapping.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data.Common/DataColumnMapping.cs 
2006-12-20 17:16:37 UTC (rev 69817)
+++ trunk/mcs/class/System.Data/System.Data.Common/DataColumnMapping.cs 
2006-12-20 17:17:24 UTC (rev 69818)
@@ -99,11 +99,16 @@
                }
 
 #if NET_2_0
-               [MonoTODO]
                [EditorBrowsable (EditorBrowsableState.Advanced)]
                public static DataColumn GetDataColumnBySchemaAction (string 
sourceColumn, string dataSetColumn, DataTable dataTable, Type dataType, 
MissingSchemaAction schemaAction)
                {
-                       throw new NotImplementedException ();
+                       if (dataTable.Columns.Contains (dataSetColumn))
+                               return dataTable.Columns [dataSetColumn];
+                       if (schemaAction == MissingSchemaAction.Ignore)
+                               return null;
+                       if (schemaAction == MissingSchemaAction.Error)
+                               throw new InvalidOperationException 
(String.Format ("Missing the DataColumn '{0}' in the DataTable '{1}' for the 
SourceColumn '{2}'", dataSetColumn, dataTable.TableName, sourceColumn));
+                       return new DataColumn (dataSetColumn, dataType);
                }
 #endif
 

Modified: trunk/mcs/class/System.Data/System.Data.Common/DbCommandBuilder.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data.Common/DbCommandBuilder.cs  
2006-12-20 17:16:37 UTC (rev 69817)
+++ trunk/mcs/class/System.Data/System.Data.Common/DbCommandBuilder.cs  
2006-12-20 17:17:24 UTC (rev 69818)
@@ -122,10 +122,9 @@
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public DbCommand GetDeleteCommand ()
                {
-                       return (DbCommand) _dbDataAdapter._deleteCommand;
+                       return (DbCommand) _dbDataAdapter.DeleteCommand;
                }
 
                [MonoTODO]
@@ -134,10 +133,9 @@
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public DbCommand GetInsertCommand ()
                {
-                       return (DbCommand) _dbDataAdapter._insertCommand;
+                       return (DbCommand) _dbDataAdapter.InsertCommand;
                }
 
                [MonoTODO]
@@ -150,10 +148,9 @@
                protected abstract string GetParameterName (String 
parameterName);
                protected abstract string GetParameterPlaceholder (int 
parameterOrdinal);
 
-               [MonoTODO]
                public DbCommand GetUpdateCommand ()
                {
-                       return (DbCommand) _dbDataAdapter._updateCommand;
+                       return (DbCommand) _dbDataAdapter.UpdateCommand;
                }
 
                [MonoTODO]

Modified: trunk/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs     
2006-12-20 17:16:37 UTC (rev 69817)
+++ trunk/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs     
2006-12-20 17:17:24 UTC (rev 69818)
@@ -37,6 +37,7 @@
 using System.Collections;
 using System.ComponentModel;
 using System.Data;
+using System.Reflection;
 using System.Runtime.InteropServices;
 
 namespace System.Data.Common {
@@ -53,9 +54,9 @@
 
 #if NET_2_0
                IDbCommand _selectCommand;
-               internal IDbCommand _updateCommand;
-               internal IDbCommand _deleteCommand;
-               internal IDbCommand _insertCommand;
+               IDbCommand _updateCommand;
+               IDbCommand _deleteCommand;
+               IDbCommand _insertCommand;
 #endif
 
                #endregion // Fields
@@ -182,16 +183,26 @@
                        return new RowUpdatingEventArgs (dataRow, command, 
statementType, tableMapping);
                }
 
-               [MonoTODO]
                protected virtual void OnRowUpdated (RowUpdatedEventArgs value)
                {
-                       throw new NotImplementedException ();
+                       if (Events ["RowUpdated"] != null) {
+                               Delegate [] rowUpdatedList = Events 
["RowUpdated"].GetInvocationList ();
+                               foreach (Delegate rowUpdated in rowUpdatedList) 
{
+                                       MethodInfo rowUpdatedMethod = 
rowUpdated.Method;
+                                       rowUpdatedMethod.Invoke (value, null);
+                               }
+                       }
                }
 
-               [MonoTODO]
                protected virtual void OnRowUpdating (RowUpdatingEventArgs 
value)
                {
-                       throw new NotImplementedException ();
+                       if (Events ["RowUpdating"] != null) {
+                               Delegate [] rowUpdatingList = Events 
["RowUpdating"].GetInvocationList ();
+                               foreach (Delegate rowUpdating in 
rowUpdatingList) {
+                                       MethodInfo rowUpdatingMethod = 
rowUpdating.Method;
+                                       rowUpdatingMethod.Invoke (value, null);
+                               }
+                       }
                }
 #else
                protected abstract RowUpdatedEventArgs CreateRowUpdatedEvent 
(DataRow dataRow, IDbCommand command,
@@ -206,15 +217,6 @@
                protected abstract void OnRowUpdating (RowUpdatingEventArgs 
value);
 #endif
 
-
-               private FillErrorEventArgs CreateFillErrorEvent (DataTable 
dataTable, object[] values, Exception e)
-               {
-                       FillErrorEventArgs args = new FillErrorEventArgs 
(dataTable, values);
-                       args.Errors = e;
-                       args.Continue = false;
-                       return args;
-               }
-
                protected override void Dispose (bool disposing)
                {
                        if (disposing) {
@@ -256,33 +258,12 @@
                        return Fill (dataSet, 0, 0, srcTable, ((IDbDataAdapter) 
this).SelectCommand, CommandBehavior.Default);
                }
 
-#if NET_2_0
-               [MonoTODO ("This needs to be moved to DataAdapter.For now, just 
override")]
-               protected override
-#else
-               protected virtual 
-#endif
-               int Fill (DataTable dataTable, IDataReader dataReader) 
+#if !NET_2_0
+               protected virtual int Fill (DataTable dataTable, IDataReader 
dataReader) 
                {
-                       if (dataReader.FieldCount == 0) {
-                               dataReader.Close ();
-                               return 0;
-                       }
-                       
-                       int count = 0;
-
-                       try {
-                               string tableName = SetupSchema 
(SchemaType.Mapped, dataTable.TableName);
-                               if (tableName != null) {
-                                       dataTable.TableName = tableName;
-                                       FillTable (dataTable, dataReader, 0, 0, 
ref count);
-                               }
-                       } finally {
-                               dataReader.Close ();
-                       }
-
-                       return count;
+                       return base.FillInternal (dataTable, dataReader);
                }
+#endif
 
                protected virtual int Fill (DataTable dataTable, IDbCommand 
command, CommandBehavior behavior) 
                {
@@ -317,67 +298,18 @@
 #endif
                
                
-#if NET_2_0
-               [MonoTODO ("This needs to be moved to DataAdapter.For now, just 
override")]
-               protected override
-#else
-               protected virtual
-#endif
-               int Fill (DataSet dataSet, string srcTable, IDataReader 
dataReader, int startRecord, int maxRecords) 
+#if !NET_2_0
+               protected virtual int Fill (DataSet dataSet, string srcTable, 
IDataReader dataReader, int startRecord, int maxRecords) 
                {
-                       if (dataSet == null)
-                               throw new ArgumentNullException ("DataSet");
-
-                       if (startRecord < 0)
-                               throw new ArgumentException ("The startRecord 
parameter was less than 0.");
-                       if (maxRecords < 0)
-                               throw new ArgumentException ("The maxRecords 
parameter was less than 0.");
-
-                       DataTable dataTable = null;
-                       int resultIndex = 0;
-                       int count = 0;
-                       
-                       try {
-                               string tableName = srcTable;
-                               do {
-                                       // Non-resultset queries like insert, 
delete or update aren't processed.
-                                       if (dataReader.FieldCount != -1)
-                                       {
-                                               tableName = SetupSchema 
(SchemaType.Mapped, tableName);
-                                               if (tableName != null) {
-                                                       
-                                                       // check if the table 
exists in the dataset
-                                                       if 
(dataSet.Tables.Contains (tableName)) 
-                                                               // get the 
table from the dataset
-                                                               dataTable = 
dataSet.Tables [tableName];
-                                                       else {
-                                                               // Do not 
create schema if MissingSchemAction is set to Ignore
-                                                               if 
(this.MissingSchemaAction == MissingSchemaAction.Ignore)
-                                                                       
continue;
-                                                               dataTable = 
dataSet.Tables.Add (tableName);
-                                                       }
-       
-                                                       if (!FillTable 
(dataTable, dataReader, startRecord, maxRecords, ref count)) {
-                                                               continue;
-                                                       }
-       
-                                                       tableName = 
String.Format ("{0}{1}", srcTable, ++resultIndex);
-       
-                                                       startRecord = 0;
-                                                       maxRecords = 0;
-                                               }
-                                       }
-                               } while (dataReader.NextResult ());
-                       } 
-                       finally {
-                               dataReader.Close ();
-                       }
-
-                        return count;
+                       return base.FillInternal (dataSet, srcTable, 
dataReader, startRecord, maxRecords);
                }
+#endif
                
                protected virtual int Fill (DataSet dataSet, int startRecord, 
int maxRecords, string srcTable, IDbCommand command, CommandBehavior behavior) 
                {
+                       if (command.Connection == null) {
+                               throw new InvalidOperationException 
("Connection state is closed");
+                       }
                        if (MissingSchemaAction == 
MissingSchemaAction.AddWithKey)
                                behavior |= CommandBehavior.KeyInfo;
                        CommandBehavior commandBehavior = behavior;
@@ -389,57 +321,6 @@
                        return Fill (dataSet, srcTable, command.ExecuteReader 
(commandBehavior), startRecord, maxRecords);
                }
 
-               private bool FillTable (DataTable dataTable, IDataReader 
dataReader, int startRecord, int maxRecords, ref int counter)
-               {
-                       if (dataReader.FieldCount == 0)
-                               return false;
-
-                       int counterStart = counter;
-
-                       int[] mapping = BuildSchema (dataReader, dataTable, 
SchemaType.Mapped);
-                       
-                       int[] sortedMapping = new int[mapping.Length];
-                       int length = sortedMapping.Length;
-                       for(int i=0; i < sortedMapping.Length; i++) {
-                               if (mapping[i] >= 0)
-                                       sortedMapping[mapping[i]] = i;
-                               else
-                                       sortedMapping[--length] = i;
-                       }
-
-                       for (int i = 0; i < startRecord; i++) {
-                               dataReader.Read ();
-                       }
-
-                       dataTable.BeginLoadData ();
-                       while (dataReader.Read () && (maxRecords == 0 || 
(counter - counterStart) < maxRecords)) {
-                               try {
-                                       dataTable.LoadDataRow (dataReader, 
sortedMapping, length, AcceptChangesDuringFill);
-                                       counter++;
-                               }
-                               catch (Exception e) {
-                                       object[] readerArray = new 
object[dataReader.FieldCount];
-                                       object[] tableArray = new 
object[mapping.Length];
-                                       // we get the values from the datareader
-                                       dataReader.GetValues (readerArray);
-                                       // copy from datareader columns to 
table columns according to given mapping
-                                       for (int i = 0; i < mapping.Length; 
i++) {
-                                               if (mapping[i] >= 0) {
-                                                       tableArray[i] = 
readerArray[mapping[i]];
-                                               }
-                                       }
-                                       FillErrorEventArgs args = 
CreateFillErrorEvent (dataTable, tableArray, e);
-                                       OnFillError (args);
-
-                                       // if args.Continue is not set to true 
or if a handler is not set, rethrow the error..
-                                       if(!args.Continue)
-                                               throw e;
-                               }
-                       }
-                       dataTable.EndLoadData ();
-                       return true;
-               }
-
 #if NET_2_0
                /// <summary>
                ///     Fills the given datatable using values from reader. if 
a value 
@@ -621,20 +502,19 @@
                        return (DataTable[]) output.ToArray (typeof 
(DataTable));
                }
 
-               private string SetupSchema (SchemaType schemaType, string 
sourceTableName)
+#if NET_2_0
+               [MonoTODO]
+               protected override DataTable FillSchema (DataTable dataTable, 
SchemaType schemaType, IDataReader dataReader)
                {
-                       DataTableMapping tableMapping = null;
+                       throw new NotImplementedException ();
+               }
 
-                       if (schemaType == SchemaType.Mapped) 
-                       {
-                               tableMapping = 
DataTableMappingCollection.GetTableMappingBySchemaAction (TableMappings, 
sourceTableName, sourceTableName, MissingMappingAction);
-                               if (tableMapping != null)
-                                       return tableMapping.DataSetTable;
-                               return null;
-                       }
-                       else
-                               return sourceTableName;
+               [MonoTODO]
+               protected override DataTable[] FillSchema (DataSet dataSet, 
SchemaType schemaType, string srcTable, IDataReader dataReader)
+               {
+                       throw new NotImplementedException ();
                }
+#endif
 
                [EditorBrowsable (EditorBrowsableState.Advanced)]
                public override IDataParameter[] GetFillParameters () 
@@ -644,185 +524,6 @@
                        return parameters;
                }
                
-               // this method builds the schema for a given datatable. it 
returns a int array with 
-               // "array[ordinal of datatable column] == index of source 
column in data reader".
-               // each column in the datatable has a mapping to a specific 
column in the datareader,
-               // the int array represents this match.
-               private int[] BuildSchema (IDataReader reader, DataTable table, 
SchemaType schemaType)
-               {
-                       return BuildSchema (reader, table, schemaType, 
MissingSchemaAction,
-                                           MissingMappingAction, 
TableMappings);
-                }
-
-                /// <summary>
-                ///     Creates or Modifies the schema of the given DataTable 
based on the schema of
-                ///     the reader and the arguments passed.
-                /// </summary>
-                internal static int[] BuildSchema (IDataReader reader,
-                                                   DataTable table,
-                                                   SchemaType schemaType,
-                                                   MissingSchemaAction 
missingSchAction,
-                                                   MissingMappingAction 
missingMapAction,
-                                                   DataTableMappingCollection 
dtMapping
-                                                   )
-               {
-                       int readerIndex = 0;
-                       // FIXME : this fails if query has fewer columns than a 
table
-                       int[] mapping = new int[table.Columns.Count]; // 
mapping the reader indexes to the datatable indexes
-                       
-                       for(int i=0; i < mapping.Length; i++) {
-                               mapping[i] = -1;
-                       }
-                       
-                       ArrayList primaryKey = new ArrayList ();
-                       ArrayList sourceColumns = new ArrayList ();
-                       bool createPrimaryKey = true;
-                       
-                       DataTable schemaTable = reader.GetSchemaTable ();
-
-                       DataColumn ColumnNameCol =  
schemaTable.Columns["ColumnName"];
-                       DataColumn DataTypeCol = 
schemaTable.Columns["DataType"];
-                       DataColumn IsAutoIncrementCol = 
schemaTable.Columns["IsAutoIncrement"];
-                       DataColumn AllowDBNullCol = 
schemaTable.Columns["AllowDBNull"];
-                       DataColumn IsReadOnlyCol = 
schemaTable.Columns["IsReadOnly"];
-                       DataColumn IsKeyCol = schemaTable.Columns["IsKey"];
-                       DataColumn IsUniqueCol = 
schemaTable.Columns["IsUnique"];
-                       DataColumn ColumnSizeCol = 
schemaTable.Columns["ColumnSize"];
-
-                       foreach (DataRow schemaRow in schemaTable.Rows) {
-                               // generate a unique column name in the source 
table.
-                               string sourceColumnName;
-                               string realSourceColumnName ;
-                               if (ColumnNameCol == null || 
schemaRow.IsNull(ColumnNameCol) || (string)schemaRow [ColumnNameCol] == 
String.Empty) {
-                                       sourceColumnName = 
DefaultSourceColumnName;
-                                       realSourceColumnName = 
DefaultSourceColumnName + "1";
-                               }
-                               else {
-                                       sourceColumnName = (string) schemaRow 
[ColumnNameCol];
-                                       realSourceColumnName = sourceColumnName;
-                               }
-
-                               for (int i = 1; sourceColumns.Contains 
(realSourceColumnName); i += 1) 
-                                       realSourceColumnName = String.Format 
("{0}{1}", sourceColumnName, i);
-                               sourceColumns.Add(realSourceColumnName);
-
-                               // generate DataSetColumnName from 
DataTableMapping, if any
-                               string dsColumnName = realSourceColumnName;
-                               DataTableMapping tableMapping = null;
-
-                               //FIXME : The sourcetable name shud get passed 
as a parameter.. 
-                               int index = dtMapping.IndexOfDataSetTable 
(table.TableName);
-                               string srcTable = (index != -1 ? 
dtMapping[index].SourceTable : table.TableName);
-                               tableMapping = 
DataTableMappingCollection.GetTableMappingBySchemaAction (dtMapping, srcTable, 
table.TableName, missingMapAction); 
-                               if (tableMapping != null)
-                               {
-                                       table.TableName = 
tableMapping.DataSetTable;
-                                       // check to see if the column mapping 
exists
-                                       DataColumnMapping columnMapping = 
DataColumnMappingCollection.GetColumnMappingBySchemaAction(tableMapping.ColumnMappings,
 realSourceColumnName, missingMapAction);
-                                       if (columnMapping != null)
-                                       {
-                                               Type columnType = 
(Type)schemaRow[DataTypeCol];
-                                               DataColumn col =
-                                                       
columnMapping.GetDataColumnBySchemaAction(
-                                                                               
                  table ,
-                                                                               
                  columnType,
-                                                                               
                  missingSchAction);
-
-                                               if (col != null)
-                                               {
-                                                       // if the column is not 
in the table - add it.
-                                                       if 
(table.Columns.IndexOf(col) == -1)
-                                                       {
-                                                               if 
(missingSchAction == MissingSchemaAction.Add 
-                                                                   || 
missingSchAction == MissingSchemaAction.AddWithKey)
-                                                                       
table.Columns.Add(col);
-
-                                                               int[] tmp = new 
int[mapping.Length + 1];
-                                                               
Array.Copy(mapping,0,tmp,0,col.Ordinal);
-                                                               
Array.Copy(mapping,col.Ordinal,tmp,col.Ordinal + 1,mapping.Length - 
col.Ordinal);
-                                                               mapping = tmp;
-                                                       }                       
        
-
-
-                                                       if (missingSchAction == 
MissingSchemaAction.AddWithKey) {
-                                   
-                                                               object value = 
(AllowDBNullCol != null) ? schemaRow[AllowDBNullCol] : null;
-                                                               bool 
allowDBNull = value is bool ? (bool)value : true;
-
-                                                               value = 
(IsKeyCol != null) ? schemaRow[IsKeyCol] : null;
-                                                               bool isKey = 
value is bool ? (bool)value : false;
-
-                                                               value = 
(IsAutoIncrementCol != null) ? schemaRow[IsAutoIncrementCol] : null;
-                                                               bool 
isAutoIncrement = value is bool ? (bool)value : false;
-
-                                                               value = 
(IsReadOnlyCol != null) ? schemaRow[IsReadOnlyCol] : null;
-                                                               bool isReadOnly 
= value is bool ? (bool)value : false;
-
-                                                               value = 
(IsUniqueCol != null) ? schemaRow[IsUniqueCol] : null;
-                                                               bool isUnique = 
value is bool ? (bool)value : false;
-                                                               
-                                                               col.AllowDBNull 
= allowDBNull;
-                                                               // fill woth 
key info                                                           
-                                                               if 
(isAutoIncrement && DataColumn.CanAutoIncrement(columnType)) {
-                                                                       
col.AutoIncrement = true;
-                                                                       if 
(!allowDBNull)
-                                                                               
col.AllowDBNull = false;
-                                                               }
-
-                                                               if (columnType 
== DbTypes.TypeOfString) {
-                                                                       
col.MaxLength = (ColumnSizeCol != null) ? (int)schemaRow[ColumnSizeCol] : 0;
-                                                               }
-
-                                                               if (isReadOnly)
-                                                                       
col.ReadOnly = true;
-                                                                       
-                                                               if 
(!allowDBNull && (!isReadOnly || isKey))
-                                                                       
col.AllowDBNull = false;
-                                                               if (isUnique && 
!isKey && !columnType.IsArray) {
-                                                                       
col.Unique = true;
-                                                                       if 
(!allowDBNull)
-                                                                               
col.AllowDBNull = false;
-                                                               }
-                                                               
-                                                               // This might 
not be set by all DataProviders
-                                                               bool isHidden = 
false;
-                                                               if 
(schemaTable.Columns.Contains ("IsHidden")) {
-                                                                       value = 
schemaRow["IsHidden"];
-                                                                       
isHidden = ((value is bool) ? (bool)value : false);
-                                                               }
-
-                                                               if (isKey && 
!isHidden) {
-                                                                       
primaryKey.Add (col);
-                                                                       if 
(allowDBNull)
-                                                                               
createPrimaryKey = false;
-                                                               }
-                                                       }
-                                                       // add the ordinal of 
the column as a key and the index of the column in the datareader as a value.
-                                                       mapping[col.Ordinal] = 
readerIndex++;
-                                               }
-                                       }
-                               }
-                       }
-                       if (primaryKey.Count > 0) {
-                               DataColumn[] colKey = 
(DataColumn[])(primaryKey.ToArray(typeof (DataColumn)));
-                               if (createPrimaryKey)
-                                       table.PrimaryKey = colKey;
-                               else {
-                                       UniqueConstraint uConstraint = new 
UniqueConstraint(colKey);
-                                       for (int i = 0; i < 
table.Constraints.Count; i++) {
-                                               if 
(table.Constraints[i].Equals(uConstraint)) {
-                                                       uConstraint = null;
-                                                       break;
-                                               }
-                                       }
-
-                                       if (uConstraint != null)
-                                               
table.Constraints.Add(uConstraint);
-                               }
-                       }
-                       return mapping;
-                }
-
                [MonoTODO]
                object ICloneable.Clone ()
                {
@@ -973,8 +674,8 @@
 
                                RowUpdatingEventArgs argsUpdating = 
CreateRowUpdatingEvent (row, command, statementType, tableMapping);
                                row.RowError = null;
-                               OnRowUpdating(argsUpdating);
-                               switch(argsUpdating.Status) {
+                               OnRowUpdating (argsUpdating);
+                               switch (argsUpdating.Status) {
                                case UpdateStatus.Continue :
                                        //continue in update operation
                                        break;
@@ -993,9 +694,9 @@
                                        updateCount++;
                                        continue;
                                default :
-                                       throw 
ExceptionHelper.InvalidUpdateStatus(argsUpdating.Status);
+                                       throw 
ExceptionHelper.InvalidUpdateStatus (argsUpdating.Status);
                                }
-                               command = argsUpdating.Command;                 
                
+                               command = argsUpdating.Command;
                                try {
                                        if (command != null) {
                                                DataColumnMappingCollection 
columnMappings = tableMapping.ColumnMappings;
@@ -1034,7 +735,7 @@
                                IDataReader reader = null;
                                try {                                           
                
                                        if (command == null) {
-                                               throw 
ExceptionHelper.UpdateRequiresCommand(commandName);
+                                               throw 
ExceptionHelper.UpdateRequiresCommand (commandName);
                                        }                               
                                
                                        CommandBehavior commandBehavior = 
CommandBehavior.Default;
@@ -1117,9 +818,9 @@
                                                }
                                        }
                     
-                                       RowUpdatedEventArgs updatedArgs = 
CreateRowUpdatedEvent(row, command, statementType, tableMapping);
-                                       OnRowUpdated(updatedArgs);
-                                       switch(updatedArgs.Status) {
+                                       RowUpdatedEventArgs updatedArgs = 
CreateRowUpdatedEvent (row, command, statementType, tableMapping);
+                                       OnRowUpdated (updatedArgs);
+                                       switch (updatedArgs.Status) {
                                        case UpdateStatus.Continue:
                                                break;
                                        case UpdateStatus.ErrorsOccurred:
@@ -1207,6 +908,11 @@
 #endif
 
 #if ONLY_1_0 || ONLY_1_1
+               internal override void OnFillErrorInternal (FillErrorEventArgs 
value)
+               {
+                       OnFillError (value);
+               }
+
                protected virtual void OnFillError (FillErrorEventArgs value) 
                {
                        if (FillError != null)

Modified: trunk/mcs/class/System.Data/System.Data.Common/DbDataReader.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data.Common/DbDataReader.cs      
2006-12-20 17:16:37 UTC (rev 69817)
+++ trunk/mcs/class/System.Data/System.Data.Common/DbDataReader.cs      
2006-12-20 17:17:24 UTC (rev 69818)
@@ -58,7 +58,6 @@
                public abstract int RecordsAffected { get; }
 
 #if NET_2_0
-               [MonoTODO]
                public virtual int VisibleFieldCount {
                        get { return FieldCount; }
                }
@@ -112,21 +111,18 @@
                public abstract int GetOrdinal (string name);
 
 #if NET_2_0
-               [MonoTODO]
                [EditorBrowsable (EditorBrowsableState.Never)]
                public virtual Type GetProviderSpecificFieldType (int i)
                {
                        return GetFieldType (i);
                }
 
-               [MonoTODO]
                [EditorBrowsable (EditorBrowsableState.Never)]
                public virtual object GetProviderSpecificValue (int i)
                {
                        return GetValue (i);
                }
 
-               [MonoTODO]
                [EditorBrowsable (EditorBrowsableState.Never)]
                public virtual int GetProviderSpecificValues (object[] values)
                {

Modified: trunk/mcs/class/System.Data/System.Data.Common/RowUpdatedEventArgs.cs
===================================================================
--- trunk/mcs/class/System.Data/System.Data.Common/RowUpdatedEventArgs.cs       
2006-12-20 17:16:37 UTC (rev 69817)
+++ trunk/mcs/class/System.Data/System.Data.Common/RowUpdatedEventArgs.cs       
2006-12-20 17:17:24 UTC (rev 69818)
@@ -55,7 +55,6 @@
 
                #region Constructors
 
-               [MonoTODO]
 #if NET_2_0
                public
 #else

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

Reply via email to