Bug #74533 MySqlParameter.Clone missed assign value to property SourceColumnNullMapping
Submitted: 24 Oct 2014 2:32 Modified: 22 Nov 2021 20:39
Reporter: yao yao Email Updates:
Status: Closed Impact on me:
Category:Connector / NET Severity:S2 (Serious)
Version:6.9.3, 6.9.5 OS:Any
Assigned to: CPU Architecture:Any
Tags: MySqlParameter, SourceColumnNullMapping

[24 Oct 2014 2:32] yao yao
In function MySqlParameter.Clone didn't set SourceColumnNullMapping to correct value. 
If current parameter's SourceColumnNullMapping property is true; the cloned object will have SourceColumnNullMapping = false.
This will cause later use of cloned parameter can't be treated as right.

DbParameter dbParameter = dataParameter as DbParameter;
if (dbParameter != null && dbParameter.SourceColumnNullMapping)
dataParameter.Value = (ADP.IsNull(dataParameter.Value) ? DbDataAdapter.ParameterValueNullValue : DbDataAdapter.ParameterValueNonNullValue);

How to repeat:
MySqlCommand cmd = new MySqlCommand("CREATE TABLE `nullable` (`id` INT AUTO_INCREMENT,`name` VARCHAR(10) NULL, PRIMARY KEY(`id`))", connection);

cmd.CommandText = "INSERT INTO `nullable` VALUES (1, null)";
MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM `nullable`", connection);
MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
da.DeleteCommand = cb.GetDeleteCommand().Clone();
cb.DataAdapter = null;
DataTable dt = new DataTable();

exception caught:
System.Data.DBConcurrencyException: Concurrency violation: the DeleteCommand affected 0 of the expected 1 records.
[22 Nov 2021 20:39] Christine Cole
Posted by developer:
Fixed as of the upcoming MySQL Connector/NET 8.0.28 release, and here's the proposed changelog entry from the documentation team:

When Connector/NET cloned a parameter, the SourceColumnNullMapping
property was copied with the wrong value.

Thank you for the bug report.