Bug #30746 Can not use reader.GetBytes when the column is binary / varbinary
Submitted: 31 Aug 2007 10:13 Modified: 28 Oct 2009 17:36
Reporter: xu ziyan Email Updates:
Status: Unsupported Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:1.0.10.1 OS:Windows (Xp sp2)
Assigned to: CPU Architecture:Any

[31 Aug 2007 10:13] xu ziyan
Description:
I got the latest version of MySql connector 1.0.10.1 and knew that it'd been fixed the bug #25605. But when I use MySqlDataReader.GetBytes to get the byte array from a column with is defined as varbinary, these's a exception.

How to repeat:
Use this codes:
			this.m_netConn = new MySql.Data.MySqlClient.MySqlConnection("Database=mydb;Data Source=localhost;User Id=root;Password=ethos;pooling=false;charset=utf8");
			this.m_netConn.Open();

			MySqlCommand cmd = new MySqlCommand("SELECT BINARY 'something' AS BinaryData", this.m_netConn);
			using (MySqlDataReader reader = cmd.ExecuteReader())
			{
				reader.Read();
				byte[] buffer = new byte[2];
				long read = reader.GetBytes(0, 0, buffer, 0, 2);
				string s = reader.GetString(0);
			}

			this.m_netConn.Close();

Suggested fix:
Get the byte array from binary / varbinary column uses reader.getbytes.
[31 Aug 2007 10:22] xu ziyan
I traced the source code of reader.cs, in GetBytes function, I found that if the column is defined as binary / varbinary, the variant 'val' is MySqlString type, not MySqlBinary type. So that it throws an exception of "GetBytes can only be called on binary columns".
[6 Sep 2007 3:37] xu ziyan
How about this issue?
[21 Sep 2007 22:31] Reggie Burnett
This is a tough issue since so many operations with mysql return string data as binary.  Sorry this has taken so long but so often we have to work around server issues.
[24 Sep 2007 1:56] xu ziyan
I know this might be a issue very difficult to resolve. And I can change the column type to Bolb. That is OK.
But what make me angry is you (I mean MySQL AB, not you, Reggie.) said you've fixed the issue 25605 and submitted some test codes, but it seems can not pass. Did you really run this test? Should I believe your product? :(
[28 Oct 2009 17:36] Reggie Burnett
We no longer support our connector product on .net 1.0 or 1.1.  Please use one of our 5.x or 6.x products.