Browse Source

2009-07-24 Veerapuram Varadhan <[email protected]>

	* DbCommandBuilder.cs (CreateDeleteCommand, CreateUpdateCommand): Add the
	nullcheck-param into the respective command's parameter list.  Fixes
	build breaks.  Individual provider's CommandBuilder classes from 2.0
	profile onwards use the base version of methods to maintain these commands.
	(Get*Command): Cleanup code duplication
	* DbDataAdapter (Update): Use SourceColumnNullMapping property to handle
	nullcheckparams.  Fixes #522624.  Patch by
	Gert Driesen  <[email protected]>.

svn path=/trunk/mcs/; revision=138678
Veerapuram Varadhan 16 năm trước cách đây
mục cha
commit
5ec22cbe2f

+ 12 - 1
mcs/class/System.Data/System.Data.Common/ChangeLog

@@ -1,4 +1,15 @@
-2009-07-15  Veerapuram Varadhan
+2009-07-24  Veerapuram Varadhan  <[email protected]>
+	
+	* DbCommandBuilder.cs (CreateDeleteCommand, CreateUpdateCommand): Add the 
+	nullcheck-param into the respective command's parameter list.  Fixes 
+	build breaks.  Individual provider's CommandBuilder classes from 2.0 
+	profile onwards use the base version of methods to maintain these commands.
+	(Get*Command): Cleanup code duplication
+	* DbDataAdapter (Update): Use SourceColumnNullMapping property to handle 
+	nullcheckparams.  Fixes #522624.  Patch by 
+	Gert Driesen  <[email protected]>.
+	
+2009-07-15  Veerapuram Varadhan  <[email protected]>
 
 	** Part of fix for #325464
 	* DbParameter.cs (FrameworkDbType, DbTypeMapping, SystemType): New internal properties 

+ 15 - 16
mcs/class/System.Data/System.Data.Common/DbCommandBuilder.cs

@@ -181,7 +181,7 @@ namespace System.Data.Common {
 			// If no table was found, then we can't do an delete
 			if (QuotedTableName == String.Empty)
 				return null;
-
+			
 			CreateNewCommand (ref _deleteCommand);
 
 			string command = String.Format ("DELETE FROM {0}", QuotedTableName);
@@ -211,14 +211,18 @@ namespace System.Data.Common {
 				if (!isKey && allowNull) {
 					parameter = _deleteCommand.CreateParameter ();
 					if (option) {
-						parameter.ParameterName = String.Format ("@{0}",
+						parameter.ParameterName = String.Format ("@IsNull_{0}",
 											 schemaRow ["BaseColumnName"]);
 					} else {
 						parameter.ParameterName = String.Format ("@p{0}", parmIndex++);
 					}
 					String sourceColumnName = (string) schemaRow ["BaseColumnName"];
 					parameter.Value = 1;
-
+					parameter.DbType = DbType.Int32;
+					// This should be set for nullcheckparam
+					parameter.SourceColumnNullMapping = true;
+					_deleteCommand.Parameters.Add (parameter);
+					
 					whereClause.Append ("(");
 					whereClause.Append (String.Format (clause1, parameter.ParameterName, 
 									   GetQuotedString (sourceColumnName)));
@@ -343,16 +347,20 @@ namespace System.Data.Common {
 				if (!isKey && allowNull) {
 					parameter = _updateCommand.CreateParameter ();
 					if (option) {
-						parameter.ParameterName = String.Format ("@{0} IS NULL",
+						parameter.ParameterName = String.Format ("@IsNull_{0}",
 											 schemaRow ["BaseColumnName"]);
 					} else {
 						parameter.ParameterName = String.Format ("@p{0}", parmIndex++);
 					}
+					parameter.DbType = DbType.Int32;
 					parameter.Value = 1;
+					// This should be set for nullcheckparam
+					parameter.SourceColumnNullMapping = true;
 					whereClause.Append ("(");
 					whereClause.Append (String.Format (clause1, parameter.ParameterName,
 									   GetQuotedString ((string) schemaRow ["BaseColumnName"])));
 					whereClause.Append (" OR ");
+					_updateCommand.Parameters.Add (parameter);
 				}
 
 				if (option)
@@ -505,10 +513,7 @@ namespace System.Data.Common {
 
 		public DbCommand GetDeleteCommand ()
 		{
-			BuildCache (true);
-			if (_deleteCommand == null)
-				return CreateDeleteCommand (false);
-			return _deleteCommand;
+			return GetDeleteCommand (false);
 		}
 
 		public DbCommand GetDeleteCommand (bool option)
@@ -521,10 +526,7 @@ namespace System.Data.Common {
 
 		public DbCommand GetInsertCommand ()
 		{
-			BuildCache (true);
-			if (_insertCommand == null)
-				return CreateInsertCommand (false);
-			return _insertCommand;
+			return GetInsertCommand (false);
 		}
 
 		public DbCommand GetInsertCommand (bool option)
@@ -537,10 +539,7 @@ namespace System.Data.Common {
 
 		public DbCommand GetUpdateCommand ()
 		{
-			BuildCache (true);
-			if (_updateCommand == null)
-				return CreateUpdateCommand (false);
-			return _updateCommand;
+			return GetUpdateCommand (false);
 		}
 
 		public DbCommand GetUpdateCommand (bool option)

+ 51 - 19
mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs

@@ -143,6 +143,18 @@ namespace System.Data.Common
 		IDbCommand SelectCommand {
 			get { return ((IDbDataAdapter) this).SelectCommand; }
 		}
+
+		IDbCommand DeleteCommand {
+			get { return ((IDbDataAdapter) this).DeleteCommand; }
+		}
+
+		IDbCommand InsertCommand {
+			get { return ((IDbDataAdapter) this).InsertCommand; }
+		}
+
+		IDbCommand UpdateCommand {
+			get { return ((IDbDataAdapter) this).UpdateCommand; }
+		}
 #endif
 
 		#endregion // Properties
@@ -610,17 +622,17 @@ namespace System.Data.Common
 				switch (row.RowState) {
 				case DataRowState.Added:
 					statementType = StatementType.Insert;
-					command = ((IDbDataAdapter) this).InsertCommand;
+					command = InsertCommand;
 					commandName = "Insert";
 					break;
 				case DataRowState.Deleted:
 					statementType = StatementType.Delete;
-					command = ((IDbDataAdapter) this).DeleteCommand;
+					command = DeleteCommand;
 					commandName = "Delete";
 					break;
 				case DataRowState.Modified:
 					statementType = StatementType.Update;
-					command = ((IDbDataAdapter) this).UpdateCommand;
+					command = UpdateCommand;
 					commandName = "Update";
 					break;
 				case DataRowState.Unchanged:
@@ -654,28 +666,48 @@ namespace System.Data.Common
 				try {
 					if (command != null) {
 						DataColumnMappingCollection columnMappings = tableMapping.ColumnMappings;
+#if ONLY_1_1
 						IDataParameter nullCheckParam = null;
+#endif
 						foreach (IDataParameter parameter in command.Parameters) {
-							if ((parameter.Direction & ParameterDirection.Input) != 0) {
-								string dsColumnName = parameter.SourceColumn;
-								if (columnMappings.Contains(parameter.SourceColumn))
-									dsColumnName = columnMappings [parameter.SourceColumn].DataSetColumn;
-								if (dsColumnName == null || dsColumnName.Length <= 0) {
-									nullCheckParam = parameter;
-									continue;
-								}
+							if ((parameter.Direction & ParameterDirection.Input) == 0)
+								continue;
 
-								DataRowVersion rowVersion = parameter.SourceVersion;
-								// Parameter version is ignored for non-update commands
-								if (statementType == StatementType.Delete) 
-									rowVersion = DataRowVersion.Original;
+							DataRowVersion rowVersion = parameter.SourceVersion;
+							// Parameter version is ignored for non-update commands
+							if (statementType == StatementType.Delete)
+								rowVersion = DataRowVersion.Original;
 
+							string dsColumnName = parameter.SourceColumn;
+#if NET_2_0
+							if (columnMappings.Contains(dsColumnName)) {
+								dsColumnName = columnMappings [dsColumnName].DataSetColumn;
 								parameter.Value = row [dsColumnName, rowVersion];
-								if (nullCheckParam != null && (parameter.Value != null
-									&& parameter.Value != DBNull.Value)) {
+							} else {
+								parameter.Value = null;
+							}
+
+							DbParameter nullCheckParam = parameter as DbParameter;
+#else
+							if (columnMappings.Contains(dsColumnName))
+								dsColumnName = columnMappings [dsColumnName].DataSetColumn;
+							if (dsColumnName == null || dsColumnName.Length == 0) {
+								nullCheckParam = parameter;
+								continue;
+							}
+							parameter.Value = row [dsColumnName, rowVersion];
+#endif
+
+#if NET_2_0
+							if (nullCheckParam != null && nullCheckParam.SourceColumnNullMapping) {
+#else
+							if (nullCheckParam != null) {
+#endif
+								if (parameter.Value != null && parameter.Value != DBNull.Value)
 									nullCheckParam.Value = 0;
-									nullCheckParam = null;
-								}
+								else
+									nullCheckParam.Value = 1;
+								nullCheckParam = null;
 							}
 						}
 					}