Bug #11991 ExecuteScalar
Submitted: 17 Jul 2005 23:15 Modified: 29 Oct 2006 5:17
Reporter: NAU Nathan Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:1.0.4.20163 OS:Any (All)
Assigned to: Reggie Burnett CPU Architecture:Any

[17 Jul 2005 23:15] NAU Nathan
Description:
When I the return of "ExecuteScalar" function is DateTime and the value is "0000-00-00 00:00:00" an exception "MySqlConversionExecption" is throw but the reader is not close, so can't create new transaction.

How to repeat:
Dim lu As DateTime
Try
	lu = comm1.ExecuteScalar()
Catch ex As Exception
	lu = DateTime.MinValue
End Try

Dim trans As IDbTransaction = conn.BeginTransaction()

Suggested fix:
in file "command.cs"
replace
	public object ExecuteScalar()
	{
		// ExecuteReader will check out state
	
		updateCount = -1;
	
		object val = null;
		MySqlDataReader reader = ExecuteReader();
		if (reader.Read())
			val = reader.GetValue(0);
		reader.Close();
	
		return val;
	}
By
	public object ExecuteScalar()
	{
		// ExecuteReader will check out state
	
		updateCount = -1;
	
		object val = null;
		MySqlDataReader reader = ExecuteReader();
		if (reader.Read())
		
		try
		{
			val = reader.GetValue(0);
		}
		catch (Exception ex)
		{
			reader.Close();
			throw ex;
		}
		reader.Close();
	
		return val;
	}
[18 Jul 2005 7:43] NAU Nathan
Sorry. This is :

		
		try
		{
			if (reader.Read())
				val = reader.GetValue(0);
		}
		catch (Exception ex)
		{
			reader.Close();
			throw ex;
		}
[11 Oct 2005 9:03] Vasily Kishkin
I was able to reproduce the bug and catch exception "Unable to convert MySQL date/time value to System.DateTime". MySqlDateTime.op_Explicit() does't help.

Test case is attached.
[11 Oct 2005 9:03] Vasily Kishkin
Test case

Attachment: 11991.zip (application/force-download, text), 5.52 KiB.

[26 Sep 2006 15:01] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/12545
[26 Sep 2006 15:02] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/12546
[26 Sep 2006 15:03] Reggie Burnett
fixed in 1.0.8 and 5.0.1
[29 Oct 2006 5:17] MC Brown
A note has been added to the 1.0.8 and 5.0.1 changelogs.