Bug #101253 Default value for MySqlParameter.Value changed from null to 0

Submitted: 20 Oct 2020 22:16 Modified: 23 Nov 2021 18:59
Reporter: Bradley Grainger (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:8.0.22 OS:Windows (10)
Assigned to: CPU Architecture:Any

[20 Oct 2020 22:16] Bradley Grainger
Description:
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("..."))
{
    connection.Open();

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

    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
        command.ExecuteNonQuery();
    }

    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.

regards,
Umesh
[23 Nov 2021 18:59] 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:

Connector/NET now uses the C# language’s implicit conversion to an
enumeration when it creates a parameter with a value equal to zero.

Thank you for the bug report.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.053 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.