Bug #91751 YEAR column retrieved incorrectly with prepared command
Submitted: 22 Jul 2018 2:55 Modified: 27 Aug 2019 14:39
Reporter: Bradley Grainger (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:8.0.11 OS:Microsoft Windows (10.0.17134.167)
Assigned to: CPU Architecture:Any (x64)

[22 Jul 2018 2:55] Bradley Grainger
Description:
If MySqlCommand.Prepare() is called for a statement that SELECTs a YEAR column, an incorrect value is returned for that column.

How to repeat:
Run the following C# code:

// NOTE: MUST have IgnorePrepare=false in connection string
using (var connection = new MySqlConnection("...;IgnorePrepare=false"))
{
	connection.Open();
	using (var command = new MySqlCommand(@"
DROP TABLE IF EXISTS test_year;
CREATE TABLE test_year(yr YEAR NOT NULL);
INSERT INTO test_year VALUES(2018);
", connection))
		command.ExecuteNonQuery();
		
	using (var command = new MySqlCommand(@"SELECT yr FROM test_year", connection))
	{
		// *** this causes the bug ***
		command.Prepare();

		using (var reader = command.ExecuteReader())
		{
			while (reader.Read())
			{
				// prints 1828718562, expected 2018
				Console.WriteLine(reader.GetValue(0));
			}
		}
	}
}
[22 Jul 2018 14:03] MySQL Verification Team
Hello Bradley,

Thank you for the report and feedback.

Thanks,
Umesh
[27 Aug 2019 14:39] Christine Cole
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/NET  8.0.18 release, and here's the changelog entry:

Connector/NET returned an inaccurate value for the YEAR type when a
prepared command was used.

Thank you for the bug report.