[Mono-list] DbDataAdapter.Fill patch

Aleksey Demakov avd@openlinksw.com
Wed, 22 Jan 2003 02:37:13 +0600


This is a multi-part message in MIME format.
--------------010208020903020601060304
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

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

--------------010208020903020601060304
Content-Type: text/plain;
 name="DbDataAdapter.cs.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="DbDataAdapter.cs.patch"

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) 

--------------010208020903020601060304--