Bug #101253 Default value for MySqlParameter.Value changed from null to 0
Submitted: 20 Oct 2020 22:16 Modified: 21 Oct 2020 6:22
Reporter: Bradley Grainger (OCA) Email Updates:
Status: Verified Impact on me:
Category:Connector / NET Severity:S2 (Serious)
Version:8.0.22 OS:Microsoft Windows (10)
Assigned to: CPU Architecture:Any

[20 Oct 2020 22:16] Bradley Grainger
The default value of MySqlParameter.Value (for integral types) changed from null to 0 in 8.0.22. This is a breaking change, because it changes the meaning of existing code.

In the attached example, the code inserts the value NULL into the table with 8.0.21, but 0 when using 8.0.22. Updating the MySql.Data library should not cause a change in the behaviour of previously-working application code.

This regression was probably introduced by the fix for bug #85027.

How to repeat:
using (var connection = new MySqlConnection("..."))

    using (var command = new MySqlCommand(@"drop table if exists int_test;
    create table int_test(data int null);", connection))

    using (var command = new MySqlCommand("insert into int_test(data) values(@Data)", connection))
        command.Parameters.Add(new MySqlParameter("@Data", MySqlDbType.Int32));

        // this inserts NULL with 8.0.21, 0 with 8.0.22

    using (var command = new MySqlCommand("select data from int_test;", connection))
    using (var reader = command.ExecuteReader())
        while (reader.Read())
            Console.WriteLine(reader.IsDBNull(0)); // 8.0.21 prints True, 8.0.22 prints False

Suggested fix:
Revert the fix for bug #85027.
[21 Oct 2020 6:22] MySQL Verification Team
Hello Bradley,

Thank you for the report and test case.
Verified as described.