[Mono-list] DbDataAdapter.Fill patch

Aleksey Demakov avd@openlinksw.com
Tue, 25 Feb 2003 15:24:56 +0600


So what's wrong with it? I think that a DataAdapter at one time
should update only one table. It's absolutely wrong to iterate
through all the tables in the DataSet because the DataAdapter
contains only one set of update commands while different tables
require different commands.

Regards,
Aleksey

Alan Tam wrote:
> The bottom half of the patch has been applied. Thank you.
> 
> For the upper half, we may need more discussion. As far as I've observed, the
> patch changes the code to simulate Microsoft behavior, which seems to be a
> wrong behavior. I wonder if we should follow suit.
> 
> Regards,
> Alan
> 
> ----- Original Message -----
> From: "Aleksey Demakov" <avd@openlinksw.com>
> To: <mono-list@ximian.com>
> Sent: Wednesday, January 22, 2003 4:37 AM
> Subject: [Mono-list] DbDataAdapter.Fill patch
> 
> 
> 
>>Hi all,
>>
>>I've found that the DbDataAdapter.Update (DataTable dataTable)
>>and Update (DataSet dataSet, string sourceTable) methods
>>iterate through all tables of the given dataSet and try
>>to update them with this DataAdapter. I believe that
>>this is incorrect.
>>
>>The dataSet can contain multiple DataTables which are
>>Filled using different DataAdapters with different
>>select/insert/delete/update commans. Consequently
>>one DataAdapter cannot be be able to perform all the
>>needed updates.
>>
>>Unfortunately, the .NET docs are silent about this
>>issue. But I believe that DbDataAdapter.Update methods
>>should be symmetric to Fill methods. So as Fill (DataSet)
>>method fills only one DataSet table with default
>>name "Table", the Update (DataSet) method should
>>only update default table. And Update (DataSet, string)
>>method should only update the specified table.
>>
>>The attached patch fixes also another problem.
>>The original code might pass a null DataTableMapping
>>value which is then used to create a RowUpdatingEventArgs
>>instance. So RowUpdatingEvent handler (for instance
>>CommandBuilder) could get null DataTableMapping which
>>might be unexpected. The patch makes sure that a non-null
>>DataTableMapping is passed.
>>
>>Regards,
>>Aleksey
>>
> 
> 
> 
> -------------------------------------------------------------------------------
> -
> 
> 
> 
>>Index: DbDataAdapter.cs
>>===================================================================
>>RCS file: /mono/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs,v
>>retrieving revision 1.21
>>diff -u -r1.21 DbDataAdapter.cs
>>--- DbDataAdapter.cs 12 Nov 2002 13:47:37 -0000 1.21
>>+++ DbDataAdapter.cs 21 Jan 2003 10:05:50 -0000
>>@@ -356,10 +356,7 @@
>>
>>  public override int Update (DataSet dataSet)
>>  {
>>- int result = 0;
>>- foreach (DataTable table in dataSet.Tables)
>>- result += Update (table);
>>- return result;
>>+ return Update (dataSet, "Table");
>>  }
>>
>>  public int Update (DataTable dataTable)
>>@@ -447,11 +444,16 @@
>>
>>  public int Update (DataSet dataSet, string sourceTable)
>>  {
>>- int result = 0;
>>- DataTableMapping tableMapping = TableMappings [sourceTable];
>>- foreach (DataTable dataTable in dataSet.Tables)
>>- result += Update (dataTable, tableMapping);
>>- return result;
>>+ MissingMappingAction mappingAction = MissingMappingAction;
>>+ if (mappingAction == MissingMappingAction.Ignore)
>>+ mappingAction = MissingMappingAction.Error;
>>+ DataTableMapping tableMapping =
> 
> DataTableMappingCollection.GetTableMappingBySchemaAction (TableMappings,
> sourceTable, sourceTable, mappingAction);
> 
>>+
>>+ DataTable dataTable = dataSet.Tables[tableMapping.DataSetTable];
>>+ if (dataTable == null)
>>+     throw new ArgumentException ("sourceTable");
>>+
>>+ return Update (dataTable, tableMapping);
>>  }
>>
>>  protected virtual void OnFillError (FillErrorEventArgs value)
>>
> 
> 
>