New test.
[mono.git] / mcs / class / System.Data / System.Data.Common / DbDataAdapter.cs
index 82b719c0ca4e1fd132e4340ddbcea7895f419e15..9e98ef92d97a5e6efc2cfd8738d734ced793260f 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
@@ -66,7 +66,6 @@ namespace System.Data.Common {
                {
                }
 
-               [MonoTODO]
                protected DbDataAdapter(DbDataAdapter adapter) : base(adapter)
                {
                }
@@ -81,31 +80,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 +107,6 @@ namespace System.Data.Common {
                        set { ((IDbDataAdapter) this).SelectCommand = value; }
                }
 
-               [MonoTODO]
                [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public DbCommand DeleteCommand {
@@ -121,7 +114,6 @@ namespace System.Data.Common {
                        set { ((IDbDataAdapter) this).DeleteCommand = value; }
                }
 
-               [MonoTODO]
                [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public DbCommand InsertCommand {
@@ -129,7 +121,6 @@ namespace System.Data.Common {
                        set { ((IDbDataAdapter) this).InsertCommand = value; }
                }
 
-               [MonoTODO]
                [Browsable (false)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                public DbCommand UpdateCommand {
@@ -194,11 +185,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 +476,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) 
@@ -500,7 +533,6 @@ namespace System.Data.Common {
                        return FillSchema (dataSet, schemaType, ((IDbDataAdapter) this).SelectCommand, srcTable, CommandBehavior.Default);
                }
 
-               [MonoTODO ("Verify")]
                protected virtual DataTable FillSchema (DataTable dataTable, SchemaType schemaType, IDbCommand command, CommandBehavior behavior) 
                {
                        if (dataTable == null)
@@ -536,7 +568,6 @@ namespace System.Data.Common {
                        return dataTable;
                }
 
-               [MonoTODO ("Verify")]
                protected virtual DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType, IDbCommand command, string srcTable, CommandBehavior behavior) 
                {
                        if (dataSet == null)
@@ -617,7 +648,6 @@ namespace System.Data.Common {
                // "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.
-               [MonoTODO ("Test")]
                private int[] BuildSchema (IDataReader reader, DataTable table, SchemaType schemaType)
                {
                        return BuildSchema (reader, table, schemaType, MissingSchemaAction,
@@ -799,7 +829,6 @@ namespace System.Data.Common {
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                public int Update (DataRow[] dataRows) 
                {
                        if (dataRows == null)
@@ -913,7 +942,6 @@ namespace System.Data.Common {
                        return Update (rows, tableMapping);
                }
 
-               [MonoTODO]
                protected virtual int Update (DataRow[] dataRows, DataTableMapping tableMapping) 
                {
                        int updateCount = 0;