2006-11-15 Nagappan A <anagappan@novell.com>
authorNagappan Alagappan <nagappan@gmail.com>
Wed, 15 Nov 2006 12:13:18 +0000 (12:13 -0000)
committerNagappan Alagappan <nagappan@gmail.com>
Wed, 15 Nov 2006 12:13:18 +0000 (12:13 -0000)
* DbDataAdapter.cs (FillFromReader): Implemented missing API to
handle FillErrorEventHandler
(DataAdapter): Implemented missing .NET 2.0 function
(GetDeleteCommand): Returns DbDataAdapter deleteCommand internal
variable.
(GetInsertCommand): Returns DbDataAdapter insertCommand internal
variable.
(GetUpdateCommand): Returns DbDataAdapter updateCommand internal
variable.

svn path=/trunk/mcs/; revision=67900

mcs/class/System.Data/System.Data.Common/ChangeLog
mcs/class/System.Data/System.Data.Common/DbCommandBuilder.cs
mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs

index b6288a7bf48917e85a155c596cc4eb5496a44510..3aecfdd55920c906be8a06fe2c588c457fc6e630 100644 (file)
@@ -1,3 +1,15 @@
+2006-11-15  Nagappan A  <anagappan@novell.com>
+
+       * DbDataAdapter.cs (FillFromReader): Implemented missing API to
+       handle FillErrorEventHandler
+       (DataAdapter): Implemented missing .NET 2.0 function
+       (GetDeleteCommand): Returns DbDataAdapter deleteCommand internal
+       variable.
+       (GetInsertCommand): Returns DbDataAdapter insertCommand internal
+       variable.
+       (GetUpdateCommand): Returns DbDataAdapter updateCommand internal
+       variable.
+
 2006-09-06  Konstantin Triger <kostat@mainsoft.com>
 
        * DbDataAdapter.cs: added basic implementation for some 2.0 features.
index fdb3da894b2f6e3f4696fecab4fbfa0a3069b38c..4442a4ae2afe2870e2dfb3ee996490fd864334e2 100644 (file)
@@ -39,6 +39,7 @@ namespace System.Data.Common {
        public abstract class DbCommandBuilder : Component
        {
                bool _setAllValues = false;
+               DbDataAdapter _dbDataAdapter;
 
                #region Constructors
 
@@ -72,12 +73,11 @@ namespace System.Data.Common {
                        set { throw new NotImplementedException (); }
                }
 
-               [MonoTODO]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                [Browsable (false)]
                public DbDataAdapter DataAdapter {
-                       get { throw new NotImplementedException (); }
-                       set { throw new NotImplementedException (); }
+                       get { return _dbDataAdapter; }
+                       set { _dbDataAdapter = value; }
                }
 
                [MonoTODO]
@@ -125,7 +125,7 @@ namespace System.Data.Common {
                [MonoTODO]
                public DbCommand GetDeleteCommand ()
                {
-                       throw new NotImplementedException ();
+                       return (DbCommand) _dbDataAdapter._deleteCommand;
                }
 
                [MonoTODO]
@@ -137,7 +137,7 @@ namespace System.Data.Common {
                [MonoTODO]
                public DbCommand GetInsertCommand ()
                {
-                       throw new NotImplementedException ();
+                       return (DbCommand) _dbDataAdapter._insertCommand;
                }
 
                [MonoTODO]
@@ -153,7 +153,7 @@ namespace System.Data.Common {
                [MonoTODO]
                public DbCommand GetUpdateCommand ()
                {
-                       throw new NotImplementedException ();
+                       return (DbCommand) _dbDataAdapter._updateCommand;
                }
 
                [MonoTODO]
index 82b719c0ca4e1fd132e4340ddbcea7895f419e15..5f77ea58da2bed41e8e1a98a68871313a8965569 100644 (file)
@@ -53,9 +53,9 @@ namespace System.Data.Common {
 
 #if NET_2_0
                IDbCommand _selectCommand;
-               IDbCommand _updateCommand;
-               IDbCommand _deleteCommand;
-               IDbCommand _insertCommand;
+               internal IDbCommand _updateCommand;
+               internal IDbCommand _deleteCommand;
+               internal IDbCommand _insertCommand;
 #endif
 
                #endregion // Fields
@@ -81,31 +81,26 @@ namespace System.Data.Common {
                        set { throw new NotImplementedException (); }
                }
 
-               [MonoTODO]
                IDbCommand IDbDataAdapter.SelectCommand {
                        get { return _selectCommand; }
                        set { _selectCommand = value; }
                }
 
-               [MonoTODO]
                IDbCommand IDbDataAdapter.UpdateCommand{
                        get { return _updateCommand; }
                        set { _updateCommand = value; }
                }
 
-               [MonoTODO]
                IDbCommand IDbDataAdapter.DeleteCommand{
                        get { return _deleteCommand; }
                        set { _deleteCommand = value; }
                }
 
-               [MonoTODO]
                IDbCommand IDbDataAdapter.InsertCommand{
                        get { return _insertCommand; }
                        set { _insertCommand = value; }
                }
                
-               [MonoTODO]
                [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public DbCommand SelectCommand {
@@ -113,7 +108,6 @@ namespace System.Data.Common {
                        set { ((IDbDataAdapter) this).SelectCommand = value; }
                }
 
-               [MonoTODO]
                [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public DbCommand DeleteCommand {
@@ -121,7 +115,6 @@ namespace System.Data.Common {
                        set { ((IDbDataAdapter) this).DeleteCommand = value; }
                }
 
-               [MonoTODO]
                [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public DbCommand InsertCommand {
@@ -129,7 +122,6 @@ namespace System.Data.Common {
                        set { ((IDbDataAdapter) this).InsertCommand = value; }
                }
 
-               [MonoTODO]
                [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public DbCommand UpdateCommand {
@@ -194,11 +186,13 @@ namespace System.Data.Common {
                [MonoTODO]
                protected virtual void OnRowUpdated (RowUpdatedEventArgs value)
                {
+                       throw new NotImplementedException ();
                }
 
                [MonoTODO]
                protected virtual void OnRowUpdating (RowUpdatingEventArgs value)
                {
+                       throw new NotImplementedException ();
                }
 #else
                protected abstract RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command,
@@ -483,6 +477,46 @@ namespace System.Data.Common {
                         return counter;
                 }
 
+               internal static int FillFromReader (DataTable table,
+                                                    IDataReader reader,
+                                                    int start, 
+                                                    int length,
+                                                    int [] mapping,
+                                                    LoadOption loadOption,
+                                                    FillErrorEventHandler errorHandler)
+                {
+                        if (reader.FieldCount == 0)
+                               return 0 ;
+
+                        for (int i = 0; i < start; i++)
+                                reader.Read ();
+
+                        int counter = 0;
+                        object [] values = new object [mapping.Length];
+                        while (reader.Read () &&
+                               (length == 0 || counter < length)) {
+                                
+                                for (int i = 0 ; i < mapping.Length; i++)
+                                        values [i] = mapping [i] < 0 ? null : reader [mapping [i]];
+                                        
+                                table.BeginLoadData ();
+                               try {
+                                       table.LoadDataRow (values, loadOption);
+                               } catch (Exception e) {
+                                       FillErrorEventArgs args = new FillErrorEventArgs (table, values);
+                                       args.Errors = e;
+                                       args.Continue = false;
+                                       errorHandler (table, args);
+                                       // if args.Continue is not set to true or if a handler is not set, rethrow the error..
+                                       if(!args.Continue)
+                                               throw e;
+                               }
+                                table.EndLoadData ();
+                                counter++;
+                        }
+                        return counter;
+                }
+
 #endif // NET_2_0
 
                public override DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType)