[Mono-list] Re: [PATCH] Patch for SqlCommandBuilder.cs

Carlos Guzmán Álvarez carlosga@telefonica.net
Fri, 06 Dec 2002 13:40:21 +0100


This is a multi-part message in MIME format.
--------------060707080409040104050208
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit


Hello:


Sorry, the Patch file!!




Best regards
Carlos Guzmán Álvarez
Vigo-Spain

--------------060707080409040104050208
Content-Type: text/plain;
 name="SqlCommandBuilder_Patch.txt.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="SqlCommandBuilder_Patch.txt.txt"

Index: SqlCommandBuilder.cs
===================================================================
RCS file: /mono/mcs/class/System.Data/System.Data.SqlClient/SqlCommandBuilder.cs,v
retrieving revision 1.7
diff -u -r1.7 SqlCommandBuilder.cs
--- SqlCommandBuilder.cs	13 Nov 2002 17:32:22 -0000	1.7
+++ SqlCommandBuilder.cs	6 Dec 2002 12:21:02 -0000
@@ -174,9 +174,11 @@
 				if (!isKey) {
 					parameter = deleteCommand.Parameters.Add (CreateParameter (parmIndex++, schemaRow));
 
-					dsColumnName = tableMapping.ColumnMappings [parameter.SourceColumn].DataSetColumn;
-					if (row != null)
-						parameter.Value = row [dsColumnName, DataRowVersion.Current];
+					if (tableMapping != null) {
+						dsColumnName = tableMapping.ColumnMappings [parameter.SourceColumn].DataSetColumn;
+						if (row != null)
+							parameter.Value = row [dsColumnName, DataRowVersion.Current];
+					}
 					where.Append ("(");
 					where.Append (String.Format (clause1, GetQuotedString (parameter.SourceColumn), parameter.ParameterName));
 					where.Append (" OR ");
@@ -186,9 +188,11 @@
 					
 				parameter = deleteCommand.Parameters.Add (CreateParameter (parmIndex++, schemaRow));
 
-				dsColumnName = tableMapping.ColumnMappings [parameter.SourceColumn].DataSetColumn;
-				if (row != null)
-					parameter.Value = row [dsColumnName, DataRowVersion.Current];
+				if (tableMapping != null) {
+					dsColumnName = tableMapping.ColumnMappings [parameter.SourceColumn].DataSetColumn;
+					if (row != null)
+						parameter.Value = row [dsColumnName, DataRowVersion.Current];
+				}
 
 				where.Append (String.Format (clause2, GetQuotedString (parameter.SourceColumn), parameter.ParameterName));
 
@@ -229,9 +233,11 @@
 
 				SqlParameter parameter = insertCommand.Parameters.Add (CreateParameter (parmIndex++, schemaRow));
 
-				dsColumnName = tableMapping.ColumnMappings [parameter.SourceColumn].DataSetColumn;
-				if (row != null)
-					parameter.Value = row [dsColumnName];
+				if (tableMapping != null) {
+					dsColumnName = tableMapping.ColumnMappings [parameter.SourceColumn].DataSetColumn;
+					if (row != null)
+						parameter.Value = row [dsColumnName];
+				}
 
 				columns.Append (GetQuotedString (parameter.SourceColumn));
 				values.Append (parameter.ParameterName);
@@ -276,9 +282,11 @@
 
 				SqlParameter parameter = updateCommand.Parameters.Add (CreateParameter (parmIndex++, schemaRow));
 
-				dsColumnName = tableMapping.ColumnMappings [parameter.SourceColumn].DataSetColumn;
-				if (row != null)
-					parameter.Value = row [dsColumnName, DataRowVersion.Proposed];
+				if (tableMapping != null) {
+					dsColumnName = tableMapping.ColumnMappings [parameter.SourceColumn].DataSetColumn;
+					if (row != null)
+						parameter.Value = row [dsColumnName, DataRowVersion.Proposed];
+				}
 
 				columns.Append (String.Format ("{0} = {1}", GetQuotedString (parameter.SourceColumn), parameter.ParameterName));
 			}
@@ -312,9 +320,11 @@
 					
 				parameter = updateCommand.Parameters.Add (CreateParameter (parmIndex++, schemaRow));
 
-				dsColumnName = tableMapping.ColumnMappings [parameter.SourceColumn].DataSetColumn;
-				if (row != null)
-					parameter.Value = row [dsColumnName];
+				if (tableMapping != null) {
+					dsColumnName = tableMapping.ColumnMappings [parameter.SourceColumn].DataSetColumn;
+					if (row != null)
+						parameter.Value = row [dsColumnName];
+				}
 
 				where.Append (String.Format (clause2, GetQuotedString (parameter.SourceColumn), parameter.ParameterName));
 
@@ -409,14 +419,16 @@
 
 		private bool IncludedInUpdate (DataRow schemaRow)
 		{
-			// If the parameter has one of these properties, then we don't include it in the insert:
-			// AutoIncrement, Hidden, RowVersion
+			// If the parameter has one of these properties, then we don't include it in the update:
+			// AutoIncrement, Hidden, RowVersion, ReadOnly
 
 			if ((bool) schemaRow ["IsAutoIncrement"])
 				return false;
 			if ((bool) schemaRow ["IsHidden"])
 				return false;
 			if ((bool) schemaRow ["IsRowVersion"])
+				return false;
+			if ((bool) schemaRow ["IsReadOnly"])
 				return false;
 			return true;
 		}
--------------060707080409040104050208--