Bug #6036 System.OverflowException when using YEAR datatype
Submitted: 11 Oct 2004 19:30 Modified: 13 Oct 2004 16:25
Reporter: Ben Reichelt Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:1.0.0.22708 OS:Microsoft Windows (WinXP Pro)
Assigned to: Reggie Burnett CPU Architecture:Any

[11 Oct 2004 19:30] Ben Reichelt
Description:
When I open a DataTable, or a MySqlDataReader, with a table that has a year field, I get a System.OverflowException.

How to repeat:
Create a table, and create a year field in that table.  Setup a MySqlConnection, and call the ExecuteReader() method from a MySqlCommand.  When the data reader attempts to read the year field, the exception is thrown.  See the attached NUnit tests to repeat the behavior.

Suggested fix:
Since the problem occurs in the data reader, as well as the System.Data.DataTable, I would think the problem resides in the MySqlConnection class.
[11 Oct 2004 19:31] Ben Reichelt
NUnit test to replicate this bug.

Attachment: YearDatatypeFixture.zip (application/x-zip-compressed, text), 949 bytes.

[13 Oct 2004 16:25] Reggie Burnett
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

The following nunit test case now passes. 

		[Test()]
		public void YearType() 
		{
			execSQL("DROP TABLE IF EXISTS Test");
			execSQL("CREATE TABLE Test (yr YEAR)");
			execSQL("INSERT INTO Test VALUES (98)");
			execSQL("INSERT INTO Test VALUES (1990)");
			execSQL("INSERT INTO Test VALUES (2004)");

			MySqlCommand cmd = new MySqlCommand("SELECT * FROM Test", conn);
			MySqlDataReader reader = null;
			try 
			{
				reader = cmd.ExecuteReader();
				reader.Read();
				Assert.AreEqual( 1998, reader.GetUInt32(0) );
				reader.Read();
				Assert.AreEqual( 1990, reader.GetUInt32(0) );
				reader.Read();
				Assert.AreEqual( 2004, reader.GetUInt32(0) );
			}
			catch (Exception ex) 
			{
				Assert.Fail( ex.Message );
			}
			finally 
			{
				if (reader != null) reader.Close();
			}
		}