Bug #33755 MySQL.Data.dll handles results differently
Submitted: 9 Jan 2008 2:52 Modified: 9 Jan 2008 19:31
Reporter: Jared S (Silver Quality Contributor) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:5.1.4 OS:Windows (Any)
Assigned to: CPU Architecture:Any
Tags: BINARY, results, system.byte

[9 Jan 2008 2:52] Jared S
Description:
[formal bug report]

MySQL Query Browser and mysql.exe are returning what I want to see(1Abc), but c\NET is not.

I find it hard to believe that *both* QB & mysql.exe are misinterpeting results.

How to repeat:
private MySql.Data.MySqlClient.MySqlDataReader DTR0; //handles NULLs alot better
private MySql.Data.MySqlClient.MySqlConnection CON0;
private MySql.Data.MySqlClient.MySqlCommand CMD0;

try
{
CON0 = new MySql.Data.MySqlClient.MySqlConnection();
CON0.ConnectionString = "server=localhost;database=classic;uid=root;pwd=;port=3306";
CON0.Open();
}
catch (Exception ex)
{
System.Diagnostics.Debugger.Break();
}

CMD0 = new MySql.Data.MySqlClient.MySqlCommand("SELECT concat(1, 'Abc') As Ex1 ", CON0);
DTR0 = CMD0.ExecuteReader();

DTR0.Read();
Trace.WriteLine(DTR0["Ex1"].ToString()); //Errors here
DTR0.Close();
[9 Jan 2008 14:54] Reggie Burnett
Jared

This is not a bug.  I double checked with the maintainer of our java connector and it does the same thing.  If you start your command line client with the --column-type-info option you will see the metadata.  Here it is for your query.  You'll see that the type is VAR_STRING but the charset is 63 (binary) and the binary flag is set.  By definition this means the server is telling me that this result is VAR_BINARY not VAR_STRING.  This is wrong but it is what the server is telling me.  We have been trying to get the server team to fix this but they won't.  The command line client and WB are both C apps and therefore treat byte[] and string as the same thing.  In Java and .NET they are not the same at all.  My connector has no choice but to respect the server metadata.  The Java connector has an option where the user can indicate that the results of functions should never be treated as byte[].  With that option, this result would be returned as string.  If you like, you can change this bug report to be a feature request for such an option.  

Hope this helps.

mysql> select concat(1,'Abc');
Field   1:  `concat(1,'Abc')`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       VAR_STRING
Collation:  binary (63)
Length:     4
Max_length: 4
Decimals:   31
Flags:      NOT_NULL BINARY
+-----------------+
| concat(1,'Abc') |
+-----------------+
| 1Abc            |
+-----------------+
1 row in set (0.00 sec)
[9 Jan 2008 19:31] Jared S
Thank you.  Can you give further advice on using --column-type-info

C:\>mysql --user=root --column-type-info
mysql: unknown option '--column-type-info'

C:\>mysql --help
mysql  Ver 14.12 Distrib 5.0.44sp1, for Win32 (ia32)
[9 Jan 2008 20:08] Reggie Burnett
Jared,

The --column-type-info option first became available in the 5.1 products.