Bug #52227 Different behavior with 1.0.11x and 6.2.2x, with charset problem
Submitted: 19 Mar 2010 16:32 Modified: 22 Apr 2010 13:20
Reporter: Jorge Bastos Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: CPU Architecture:Any

[19 Mar 2010 16:32] Jorge Bastos
Description:
Howdy,

I have different behavior, with the 1.0.11x driver and 6.2.2x driver.

How to repeat:
I do normally this:

"select *,(select descricao as cen_distnome from tab_distritos where emp='01' and codigo=7) as cen_distnome from param_com where emp='01'"

but, the result of the alias column "cen_distnome", will be wrong values, i even can do a convert() to UTF8, but it doesn't work, like:

"select *,convert((select descricao as cen_distnome from tab_distritos where emp='01' and codigo=7) using utf8) as cen_distnome from param_com where emp='01'"

--
if i use the query standalone that is on the subquery(), it works OK:
"select descricao as cen_distnome from tab_distritos where emp='01' and codigo=7"
--

Could this be a bug, or its needed to insert something on the connectionstring?

the tab_distritos table has the structure:

CREATE TABLE tab_distritos (
  emp varchar(2) NOT NULL,
  codigo int(6) NOT NULL DEFAULT '0',
  descricao varchar(50) NOT NULL DEFAULT '',
  PRIMARY KEY (emp,codigo)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Tabela de Distritos';
[26 Mar 2010 12:26] Jorge Bastos
Hi Toncy,

Were you able to reproduce this?
[6 Apr 2010 12:45] Tonci Grgin
Jorge, I do not quite follow... Please try using CAST AS CHAR (or what ever suits you) instead of CONVERT. Also, you might wish to add "respect binary flags=false" to your connection string.

For both of your reports, I think you changed more than just c/NET. Probably you changed MySQL server, maybe even OS...

However, we do not maintain backward compatibility for now! Rather think of c/NET (N+1) in respect of c/NET(N) as "we had to release (N+1) because changes were so deep that we could not put them in version (N)".
[6 Apr 2010 16:48] Jorge Bastos
Hi Toncy,
For this bug and for #52187, i'm going to try with the CS option "respect binary flags=false" to se if i can resolve both problems.
You mentioned that i changed OS and mysql server version but did not, only changes the .net connector and jumped from vs2003 to vs2008.

I'm on trip now and I'm going to test this and let you know if it resolves my problem.
[7 Apr 2010 7:38] Tonci Grgin
Jorge, I'll be waiting on your tests. If they fail, I'll need a complete test case from you, not just a query and table structure for 1 table used.
[13 Apr 2010 16:07] Jorge Bastos
Hi Toncy,

I'm back :)
Not working with that extra CS parameter.
Going to attach a sample. I've tested it with 5.1.44.
[13 Apr 2010 16:10] Jorge Bastos
VS2008 test project

Attachment: Bug 52227.zip (application/octet-stream, text), 196.11 KiB.

[14 Apr 2010 6:47] Tonci Grgin
Jorge, I still don't get it... What do you mean by "wrong" result? I get the same result from any of the queries in your test case...

I added HEX(...) around "problematic" SELECT and got this for field Ok in all 3 of your queries:
1. 4A6FC383C2A36F
2. 4A6FC383C2A36F
3. 4A6FC383C2A36F

which is exactly what is in table:
mysql> select HEX(descricao) from tab_distritos;

+----------------+
| HEX(descricao) |
+----------------+
| 4A6FC383C2A36F |
+----------------+

So I'd say c/NET is working as expected but if that is what you want I can't tell.
[14 Apr 2010 6:52] Tonci Grgin
Works...

Attachment: Bug52227.png (image/png, text), 22.19 KiB.

[14 Apr 2010 6:57] Tonci Grgin
Jorge, I think I see what's wrong...

You were using windows terminal and wrong connection charset to *insert* the data (see attached image). Please check on your settings:
mysql> show variables like "%char%";
+--------------------------+----------------------------------+
| Variable_name            | Value                            |
+--------------------------+----------------------------------+
| character_set_client     | utf8                             | 
| character_set_connection | utf8                             | 
| character_set_database   | utf8                             | 
| character_set_filesystem | binary                           | 
| character_set_results    | utf8                             | 
| character_set_server     | utf8                             | 
| character_set_system     | utf8                             | 
| character_sets_dir       | /opt/mysql/mysql/share/charsets/ | 
+--------------------------+----------------------------------+

mysql> select HEX(descricao) from tab_distritos;
+----------------+
| HEX(descricao) |
+----------------+
| 4A6FC3A36F     | 
+----------------+
1 row in set (0.00 sec)

mysql> select descricao from tab_distritos;
+-----------+
| descricao |
+-----------+
| João     | 
+-----------+
1 row in set (0.00 sec)

-----------

This does *NOT* work and is probably what happened to you:
mysql> show variables like "%char%";
+--------------------------+----------------------------------+
| Variable_name            | Value                            |
+--------------------------+----------------------------------+
| character_set_client     | latin1                           | 
| character_set_connection | latin1                           | 
| character_set_database   | utf8                             | 
| character_set_filesystem | binary                           | 
| character_set_results    | latin1                           | 
| character_set_server     | utf8                             | 
| character_set_system     | utf8                             | 
| character_sets_dir       | /opt/mysql/mysql/share/charsets/ | 
+--------------------------+----------------------------------+
8 rows in set (0.00 sec)

Do the INSERT (after insert, set names utf8 or similar does not help).

mysql> select * from tab_distritos;
+-----+--------+-----------+
| emp | codigo | descricao |
+-----+--------+-----------+
| 01  |      1 | João   | 
+-----+--------+-----------+
[14 Apr 2010 10:08] Jorge Bastos
Toncy,
I may messed the example, sorry.

insert into tab_distritos values ('01','1','João');
insert into tab_x values ('1','Olá');

sql = "select *,(select descricao from tab_distritos where emp='01' and codigo=1) as ok from tab_x;"

The value from the subquery on the alias "ok" that should be "João" is wrong displayed.
Check the attached pic. If I move to the old 1.0.11x it works OK.
[14 Apr 2010 10:08] Jorge Bastos
Pic1

Attachment: bug 52227, pic1.JPG (image/jpeg, text), 152.79 KiB.

[14 Apr 2010 10:11] Jorge Bastos
Wait...after this, I've found the source of the problem.
Now it's mandatory to use the CS parameter:

FunctionsReturnString=true

'cause of the functions like LEFT() RIGHT() and others, correct?
If I just set this to FALSE, I get the correct value, for the subquery output!
The problem must be this, and it's what is affection bug #52187 also for sure, going to test and let you know.
[14 Apr 2010 10:12] Jorge Bastos
With:

FunctionsReturnString=true

It may not be respecting charset defenitions.
[14 Apr 2010 10:21] Tonci Grgin
Jorge, your picture is *exactly* what I'm talking about... You inserted " João " with LATIN1 connection (as Bytes) and you are trying to read UTF8 stream back. Check your MySQL server and connection settings regarding various charset settings.

FunctionsReturnString might be a second part of problem (you understood correctly how it works) but I thought you were in trouble even when not using it. If data is *inserted* correctly (ie. as UTF-8 stream and not LATIN1 bytes), there should be no problem regarding FunctionsReturnString setting.
[14 Apr 2010 10:21] Tonci Grgin
And sure, I get the same picture as you do when inserting via latin1 connection.
[14 Apr 2010 10:28] Jorge Bastos
I understood the part of being inserting stuff in latin1, and retrieving in UTF8.
But that's something that worked before, and still works if not using subquery's.
Anyway, everything works OK if I just don't use the FunctionsReturnString=true.

My CS has "character set=utf8;" on it anyway.

Anyway the problem is really in here on this parameter, am I correct?
[14 Apr 2010 10:30] Tonci Grgin
Yes Jorge, I would say so.
[14 Apr 2010 10:43] Jorge Bastos
Great!
I'll wait for the resolution then... and for the #52187 the problem is the same, when guys go to fix this, they could fix also the #52187 bug.
[14 Apr 2010 10:56] Tonci Grgin
Jorge, I do not think there is anything to fix in this report. FunctionsReturnString option was introduced for a good reason described in Bug#10491. In short, I'll quote myself:
This problem represents grave issue for connectors. They can't work around it, at least not reliably. Ad hoc user queries like this do not allow connector to distinguish between "SHOW CREATE TABLE", where it should treat BIANRY as UTF8, and "SELECT varbinary_col FROM some_table", where it really should be binary...

The other report I'll set to "verified" now.
[14 Apr 2010 12:25] Jorge Bastos
Toncy,
I understand that FunctionsReturnString is a good option, but:

The value should be correct on the output.

"what works on the console has to work with the connector"

That's what Reggie always said :-)

There's really no way to make it work OK when this function is set to TRUE?
[14 Apr 2010 13:27] Tonci Grgin
Jorge, as opposed to the other report, this one has nothing to do with said option so I do not understand what we're discussing now.
If the value is correctly *stored* "Function always return strings" has no bearing on result (ie. it's always correct).

As for "works in console..." the option was introduces just for that case! Otherwise you would have got 0xJoão in connector (*any* connector).
[14 Apr 2010 18:48] Jorge Bastos
Toncy,
Sorry to say the same again, but the values are being inserted as UTF8, so they should have the output as they were inserted, just like you said.
Just try this, values are going to be inserted as UTF8, and the value that is retrived from the subquery is going to be wrong displayed anyway.
What can you say about this?

-----------
        Dim mycon As New MySqlConnection("FunctionsReturnString=true;character set=utf8;pooling=false;compress=false;Persist Security Info=False;Connect Timeout=30;Data Source=127.0.0.1;Database=test;User ID=root;Password=123456;Port=3306")
        mycon.Open()
        Dim mycmd As New MySqlCommand
        mycmd.Connection = mycon
        sql = "delete from tab_distritos;insert into tab_distritos values ('01','1','João');"
        mycmd.CommandText = sql
        mycmd.ExecuteNonQuery()
        sql = "delete from tab_x;insert into tab_x values ('1','Olá');"
        mycmd.CommandText = sql
        mycmd.ExecuteNonQuery()
        sql = "select *,(select descricao from tab_distritos where emp='01' and codigo=1) as ok from tab_x;"
        mycmd.CommandText = sql
        Dim myrd As MySqlDataReader
        myrd = mycmd.ExecuteReader
        myrd.Read()
        TextBox1.Text = myrd("ok")
        TextBox2.Text = myrd("descricao")
[15 Apr 2010 8:09] Tonci Grgin
Results

Attachment: 2ndQuery.png (image/png, text), 19.49 KiB.

[15 Apr 2010 8:12] Tonci Grgin
Jorge, you should really concentrate on what I told you about environment... Your test case works perfectly here (all 3 queries). Did you check "File/Advanced Save Options"? Wlad seems to think it might be related to Bug#52494 but I do not. There is a bug in your environment. You might also check the general query log from your MySQL server.

        Dim sql As String
        ' i've tried with and without both:
        ' respect binary flags=false or true
        ' FunctionsReturnString=true or true

        Dim mycon As New MySqlConnection("respect binary flags=false;FunctionsReturnString=true;character set=utf8;pooling=false;compress=false;Persist Security Info=False;Connect Timeout=30;Data Source=**;Database=test;User ID=**;Password=**;Port=3306")
        mycon.Open()
        Dim mycmdsetup As New MySqlCommand()
        mycmdsetup.Connection = mycon
        mycmdsetup.CommandText = "TRUNCATE tab_distritos"
        mycmdsetup.ExecuteNonQuery()
        mycmdsetup.CommandText = "TRUNCATE tab_x"
        mycmdsetup.ExecuteNonQuery()
        mycmdsetup.CommandText = "insert into tab_distritos values ('01','1','João')"
        mycmdsetup.ExecuteNonQuery()
        mycmdsetup.CommandText = "insert into tab_x values ('1','Olá')"
        mycmdsetup.ExecuteNonQuery()

        'sql = "select *,convert((select descricao from tab_distritos where emp='01' and codigo=1) using utf8) as ok from tab_x;"
        sql = "select *,cast((select descricao from tab_distritos where emp='01' and codigo=1) as char) as ok from tab_x;"
        'sql = "select *,(select descricao from tab_distritos where emp='01' and codigo=1) as ok from tab_x;"
        Dim mycmd As New MySqlCommand(sql, mycon)
        Dim myrd As MySqlDataReader

        myrd = mycmd.ExecuteReader
        myrd.Read()
        TextBox1.Text = myrd("ok")
        TextBox2.Text = myrd("descricao")
        myrd.Close()
        mycmdsetup.Dispose()
        mycmd.Dispose()
        mycon.Close()
[15 Apr 2010 8:38] Vladislav Vaintroub
Jorge,
Can you verify that simple "select 'João'" works as you expect.
Maybe you save the source file with UTF8 with BOM (File/Advanced save options) to prevent misinterpretation by VS,
Also good idea to look in the debugger that the string passed to server and returned from server look correct (Debugger  has good Unicode support).
[15 Apr 2010 10:02] Jorge Bastos
Tonci/Vladislav,

Sorry, but, If we are talking about environment, and the file save options, the file is saved as UTF8, so that's not the problem.
Even if the file wasn't coded as UTF8, the connector shouldn't rely on it, my opinion.

Anyway, the file is coded as UTF8, so it should work, correct?

Vladislav, the test you asked me to do, also doesn't work, check it on the attached PIC.

Any more ideas?
[15 Apr 2010 10:03] Jorge Bastos
Direct select

Attachment: bug 52227, pic2.JPG (image/jpeg, text), 190.37 KiB.

[15 Apr 2010 10:03] Jorge Bastos
File save options, always UTF8

Attachment: bug 52227, pic3.JPG (image/jpeg, text), 199.15 KiB.

[15 Apr 2010 10:15] Tonci Grgin
Jorge, there is now TWO of us unable to repeat your problem but in ONE case (which I already described but will do again)...

You have a mess in your environment! UTF8 stream is transferred to server as LATIN1 bytes! That is what you see in your pictures, an attempt of server/connector to represent in UTF8 stream what is stored as LATIN1 bytes. Why is this conversion happening I can not tell (unless you have support contract) as you need to do your homework too. So please check server variables that have "char" in them, check DB and TABLE/FIELDS actual charset, check your connection and results charset etc... You can find more in http://forge.mysql.com/wiki/How_to_Use_Charsets_and_Collations_Properly
[15 Apr 2010 10:33] Jorge Bastos
Tonci,

I have the DB as UTF8, tables and fields in UTF8, all confirmed.
I just don't understand why this doesn't work OK when i retrieve values using a subquery or a direct select like "SELECT 'Olá' as ok", i mean:

select descricao from tab_x;

works as expected, but a subquery in the middle or a direct input:

select descricao,'Olá' as ok from tab_x;

the field OK is going to wrong displayed.
[15 Apr 2010 10:39] Tonci Grgin
SB dec 227, hex E3 (http://www.ascii.cl/htmlcodes.htm), UTF8 C3A3 (http://www.utf8-chartable.de/).
[15 Apr 2010 10:50] Tonci Grgin
Jorge, I don't know... You might be using MySQl server with old UTF handling (<4.1), there might be something in your setup that's causing this and so on but it all goes well beyond the scope of BugDB. In BugsDB, we need a reliable way to reproduce the problem before I can declare anything verified (can't fix what can't see). So it is your job now to do as much digging as possible to find out what's causing this on your box and only then report it back to me. So far you have attached problematic test case (that fails for you) but it works for all of us. After that it's only been "it does not work" indefinitely... That is not helpful nor usable.
[15 Apr 2010 11:06] Jorge Bastos
Tonci,
I know the work to find the source is on my side, but right now i can't think on anything else.
MySQL server is 5.1.44 as i said before.
Let me think more, and i'll give more feedback in the next days.

Or someone will hit this problem also till then.
[15 Apr 2010 11:17] Tonci Grgin
Jorge, it is hardly possible for someone to hit this... Anyways, I've consulted Susanne (have you checked her presentation?) on this too.
[15 Apr 2010 16:52] Jorge Bastos
Haven't, but allow me to confirm one thing.

You know that this works OK if FunctionReturnString is set to FALSE, right?
That's why i keep hitting on the same, it's not a charset difference between server and client... etc...
[16 Apr 2010 8:13] Susanne Ebrecht
Many thanks for writing a bug report.
I made lots of test here ... but we really don't have a bug here.

Character set/Encoding is a very difficult topic.

You took 'João' and 'Olá' here as example and so will I.

First you need to make sure that data are stored correct in your database.

You need two steps for this:

SHOW CREATE TABLE <your_table>;

This will show you which character encoding is expected to be in the column.

Either you will see the keyword CHARACTER SET directly at the column definition.
If there is not explicit given a CHARACTER SET at the column then it is the
DEFAULT CHARSET from the table.

You will find the DEFAULT CHARSET at the end of the table description.

My guess is that your column either is using utf8 or latin1.

I will explain the next step for both charsets.

After you figured out which character set the column wants to store the values you need to look up if the values are really stored in that character set.

Therefor you will do:

SELECT <your_column>, HEX(<your_column>) FROM <your_table>;

If column is UTF8 you should get:

 | João | 4A6FC3A36F |
| Olá  | 4F6CC3A1   |

Only if you will get exactly this hex values the data are stored correct.

If column is LATIN1 you should get:

| João | 4A6FE36F   |
| Olá  | 4F6CE1     |

Same here, the data are only stored correct when you will get exact this hex values.

How you will import/export data correct I will write in my next email.
[16 Apr 2010 9:07] Susanne Ebrecht
How to do INSERT/UPDATE and SELECT correct:

Computers only work with bits and bytes ....

When you type a key on your keyboard then the keyboard driver will tell the operating system which key you hit. This transfer already is bits and bytes.

The operating system know will look to which encoding these bits and bytes need to be encoded so that the monitor will be able to display it in human readable form.

The expert is calling this "environment encoding".

The environment encoding either is the default encoding the operating system is using or it is e.g. what you set in your browser or what you set in your editor or whatever else tool.

When you will use an editor for creating programming code then these editor has a default encoding. Ususally, you can change this encoding in the preferences or options.

Even when you are using plane command line ... this command line has an encoding.
You easily can figure it out by typing:
CHCP

The result should be something like codepage 850.

MySQL is not able to know which encoding your environment is using.
So you need to tell MySQL which encoding is used.
But MySQL is not supporting all encodings that exist in the world.

To figure out which encodings are supported ... you will get a list of all when you ask MySQL:
SHOW CHARSET;

Now you have to look if the encoding of your environment is in the list.

If it is not in the list then you need to change your environment encoding to a supported encoding.

It is recommended to always use utf8 as environment encoding.

If it is supported then you need to tell MySQL which encoding your environment has.

Usually, you are doing it with:
SET NAMES <character_set>;

By using .NET you will do it via the connection string e.g. when your editor is utf8:

MySqlConnection("...;character set=utf8;...")

Now MySQL expect that all incoming data are e.g. utf8 and also will convert all outgoing data (SELECT) to utf8 for displaying.

When you have data stored in files then of course you need to figure out in which encoding the data are stored in the file and you need to use character set here from the encoding of the files.

When you want to store data that you get from SELECT then it will be stored by taking the encoding you told that the environment has.

Let me give you an example by taking plane MySQL CLI and the letter 'ã'.

CHCP => codepage 850

means, when you type 'ã' then it has hex value 0xC6

mysql> SET NAMES cp850;
mysql> CREATE TABLE tutf8(v varchar(100) CHARACTER SET utf8);
mysql> CREATE TABLE tlatin1(v varchar(100) CHARACTER SET latin1);
mysql> CREATE TABLE tucs2(v varchar(100) CHARACTER SET ucs2);

mysql> INSERT INTO tutf8 VALUES('ã');

What happens here?
Client: Hey server, all data you will get will be cp850 encoded.
Server: ok
Client: hey server, insert into table tutf8 the value 0xC6
Server: ok

What is the server now doing?
First it will look in which character set it should store the data in the column.
It will figure out it is utf8.
It knows from client that data are cp850 encoded.
It will look up which is the right utf8 encoding for 0x4F6CA0 and will figure out that cp850  0xC6 is similar to utf8 0xC3A3
Then it will store 0xC3A3 into the the table column.

This happens totally automatic and transparent.

mysql> INSERT INTO tlatin1 VALUES('ã');
mysql> INSERT INTO tucs2 VALUES('ã');

Here will happen the same as above. For latin1 column server will look up what is similar latin1 encoding for cp850 encoding and will figure out that
cp850 0xC6 is similar to latin1 0xE3.
It will store 0xE3 in the latin1 column.

cp850 0xC6 is similar to ucs 0x00E3 and will store 0x00E3 in the ucs2 column.

Same procedure of course for UPDATE.

What happens on select I will write in next email.
[16 Apr 2010 9:23] Susanne Ebrecht
What happens on SELECT?

We take the INSERT example here. Codepage 850 is environment encoding and you did SET NAMES cp850.

mysql> SELECT * FROM tutf8;

Client: server, please search * from tutf8
Server: found, in which charset to you need them?
Client: cp850
Server: ok, will convert to cp850 ....

Server will find 0xC3A3 in the column.The column information is that the data are stored in utf8. Now server will look up that utf8 0xC3A3 is similar to CP850 0xC6 and will forward 0xC6 to the client.

Server: hey client, here are your data
Client: ok
Client: environment please diplay this data
environment: ok

You will see on your display:
ã

Same of course by comverting from latin1 to cp850 and ucs2 to cp850 when you do:

mysql> SELECT * from tlatin1;
mysql> SELECT * from tucs2;

You always will get displayed correct 'ã'.

More complex is something like:

mysql> SELECT * FROM tutf8 WHERE v LIKE 'ã';

Client: Server, select * from tutf8 where v like 0xc6
Server: what charset is it?
client: cp850
Server: ok

Server know will look up which charset the column is using.
It will figure out it is using utf8.

Server will convert 0xC6 that it get from client into utf8 and then will compare it.

Server found results ....

Server: Client I found results
Client: ok
Server: which charset do you need the results?
Client: cp850
Server: ok, let me convert .... here you are
Client: thanks
Client: environment here are data that you need to display
environment: ok, will do

Consider, this only works correct when you told the client correct charset that is used from your environment.

If you forgot it then you either will get displayed question marks or gibberish.

More worse on INSERT/UPDATE because when you not set the correct charset on inserts then your data will get stored wrong in your database.
[16 Apr 2010 9:43] Jorge Bastos
Susanne,
All correct, explain me:

Why does all works OK with FunctionsReturnString set to FALSE?
Just like the simple:

SELECT descricao,'Olá' from tab_x;
[16 Apr 2010 10:27] Tonci Grgin
Jorge, as I explained numerous times, if value is properly stored I get correct result in any case.
I am using *your* test case so that there is no misunderstanding, and I did test all 3 queries and my (actually your) connstring does have respect binary flags=false;FunctionsReturnString=true in it.

More on this in Bug#52718.

To be absolutely clear, here is your test case I rewrote and toggled all the options indefinitely... ALL works.

        Dim sql As String
        ' i've tried with and without both:
        ' respect binary flags=false or true
        ' FunctionsReturnString=true or true

        Dim mycon As New MySqlConnection("respect binary flags=false;FunctionsReturnString=true;character set=utf8;pooling=false;compress=false;Persist Security Info=False;Connect Timeout=30;Data Source=**;Database=**;User ID=**;Password=**;Port=**")
        mycon.Open()
        Dim mycmdsetup As New MySqlCommand()
        mycmdsetup.Connection = mycon
        mycmdsetup.CommandText = "TRUNCATE tab_distritos"
        mycmdsetup.ExecuteNonQuery()
        mycmdsetup.CommandText = "TRUNCATE tab_x"
        mycmdsetup.ExecuteNonQuery()
        mycmdsetup.CommandText = "insert into tab_distritos values ('01','1','João')"
        mycmdsetup.ExecuteNonQuery()
        mycmdsetup.CommandText = "insert into tab_x values ('1','Olá')"
        mycmdsetup.ExecuteNonQuery()
        mycmdsetup.Dispose()

        sql = "select *,convert((select descricao from tab_distritos where emp='01' and codigo=1) using utf8) as ok from tab_x;"
        Dim mycmd As New MySqlCommand(sql, mycon)
        Dim myrd As MySqlDataReader

        myrd = mycmd.ExecuteReader
        myrd.Read()
        TextBox1.Text = myrd("ok")
        TextBox2.Text = myrd("descricao")
        myrd.Close()

        sql = "select *,cast((select descricao from tab_distritos where emp='01' and codigo=1) as char) as ok from tab_x;"
        mycmd.CommandText = sql
        myrd = mycmd.ExecuteReader
        myrd.Read()
        TextBox3.Text = myrd("ok")
        TextBox4.Text = myrd("descricao")
        myrd.Close()

        sql = "select *,(select descricao from tab_distritos where emp='01' and codigo=1) as ok from tab_x;"
        mycmd.CommandText = sql
        myrd = mycmd.ExecuteReader
        myrd.Read()
        TextBox5.Text = myrd("ok")
        TextBox6.Text = myrd("descricao")
        myrd.Close()

        mycmd.Dispose()
        mycon.Close()

        MessageBox.Show("Done test 1")
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        '------------
        Dim mycon1 As New MySqlConnection("respect binary flags=true;FunctionsReturnString=false;character set=utf8;pooling=false;compress=false;Persist Security Info=False;Connect Timeout=30;Data Source=**;Database=**;User ID=**;Password=**;Port=**")
        mycon1.Open()

        Dim mycmdsetup1 As New MySqlCommand()
        mycmdsetup1.Connection = mycon1
        mycmdsetup1.CommandText = "TRUNCATE tab_distritos"
        mycmdsetup1.ExecuteNonQuery()
        mycmdsetup1.CommandText = "TRUNCATE tab_x"
        mycmdsetup1.ExecuteNonQuery()
        mycmdsetup1.CommandText = "insert into tab_distritos values ('01','1','João')"
        mycmdsetup1.ExecuteNonQuery()
        mycmdsetup1.CommandText = "insert into tab_x values ('1','Olá')"
        mycmdsetup1.ExecuteNonQuery()
        mycmdsetup1.Dispose()

        sql = "select *,convert((select descricao from tab_distritos where emp='01' and codigo=1) using utf8) as ok from tab_x;"
        Dim mycmd1 As New MySqlCommand(sql, mycon1)
        Dim myrd1 As MySqlDataReader

        myrd1 = mycmd1.ExecuteReader
        myrd1.Read()
        TextBox1.Text = myrd1("ok")
        TextBox2.Text = myrd1("descricao")
        myrd1.Close()

        sql = "select *,cast((select descricao from tab_distritos where emp='01' and codigo=1) as char) as ok from tab_x;"
        mycmd1.CommandText = sql
        myrd1 = mycmd1.ExecuteReader
        myrd1.Read()
        TextBox3.Text = myrd1("ok")
        TextBox4.Text = myrd1("descricao")
        myrd1.Close()

        sql = "select *,(select descricao from tab_distritos where emp='01' and codigo=1) as ok from tab_x;"
        mycmd1.CommandText = sql
        myrd1 = mycmd1.ExecuteReader
        myrd1.Read()
        TextBox5.Text = myrd1("ok")
        TextBox6.Text = myrd1("descricao")
        myrd1.Close()

        mycmd1.Dispose()
        mycon1.Close()
        MessageBox.Show("Done test 2")
[16 Apr 2010 10:56] Jorge Bastos
Forgive me Tonci,
Check this now, can you tell me if there's any charset missmatch? Everything's UTF8 now.

Which version of the Connector are you using? Even if it is 6.2.2 can you send it to me? maybe they have differences.

---
Dim mycon As New MySqlConnection("respect binary flags=false;FunctionsReturnString=true;character set=utf8;pooling=false;compress=false;Persist Security Info=False;Connect Timeout=30;Data Source=127.0.0.1;Database=test;User ID=root;Password=bastos;Port=3306")
        mycon.Open()
        Dim mycmd As New MySqlCommand
        mycmd.Connection = mycon
        sql = "drop database if exists xxx;CREATE DATABASE `xxx` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
        mycmd.CommandText = sql
        mycmd.ExecuteNonQuery()
        sql = "CREATE TABLE xxx.tab_distritos (`emp` varchar(2) NOT NULL, `codigo` int(6) NOT NULL DEFAULT '0', `descricao` varchar(50) NOT NULL DEFAULT '',PRIMARY KEY (`emp`,`codigo`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Tabela de Distritos'; "
        mycmd.CommandText = sql
        mycmd.ExecuteNonQuery()
        sql = "CREATE TABLE xxx.tab_x (`codigo` int(6) NOT NULL DEFAULT '0', `descricao` varchar(50) NOT NULL DEFAULT '', PRIMARY KEY (`codigo`)) ENGINE=MyISAM DEFAULT CHARSET=utf8; "
        mycmd.CommandText = sql
        mycmd.ExecuteNonQuery()
        sql = "delete from xxx.tab_distritos;insert into xxx.tab_distritos values ('01','1','João');"
        mycmd.CommandText = sql
        mycmd.ExecuteNonQuery()
        sql = "delete from xxx.tab_x;insert into xxx.tab_x values ('1','Olá');"
        mycmd.CommandText = sql
        mycmd.ExecuteNonQuery()
        sql = "select *,(select descricao from xxx.tab_distritos where emp='01' and codigo=1) as ok from xxx.tab_x;"
        mycmd.CommandText = sql
        Dim myrd As MySqlDataReader
        myrd = mycmd.ExecuteReader
        myrd.Read()
        TextBox1.Text = myrd("ok")
        TextBox2.Text = myrd("descricao")
[16 Apr 2010 11:04] Tonci Grgin
Jorge, I do not know why you fail to understand:
  o I run your *exact* case with driver in your Bin folder, not against latest branch or something.
  o The display problem you're seeing is *NOT* in the code itself! Susanne tried to explain to you how to properly debug charset conversions but you still paste the same VB code. Please do read her presentation, check all server variables, logs and such and try to understand that there is some Latin1 <-> UTF-8 conversion lurking somewhere in your environment.

I have no future intention to continue this discussion. However, you are free to use forums.
[16 Apr 2010 12:05] Jorge Bastos
I'm sorry,

My fault! You both are completlly right, server was with latin1.
I'm sorry for all the trouble and work on this.
I admit, my error :)

I just set the server charset to utf8 on my.ini/cnf conf file with:

set-variable=character_set_server=utf8
[16 Apr 2010 17:42] Tonci Grgin
Jorge, we do not dismiss reports easily. Also, you are free to make more mistakes. Just bare in mind we are all very knowledgeable here (although we also make mistakes) :-)

Be sure to check on Susanne's presentation.
[16 Apr 2010 19:13] Jorge Bastos
Tonci,
Anyway i have one last question that come to my mind.

Why should this rely on server charset, and not JUST on the DATABASE charset?

Imagine that you have a server that HAS to be in LATIN1 for other reasons/db's, and you have to use a DB for this in UTF8, but with the FunctionsReturnString=true will not work, but if this was just rely on the DB charset would be server independent.
Just an idea... in my small opinion would be better this way.
[19 Apr 2010 6:00] Tonci Grgin
Jorge, please do read Susanne's presentation.
[21 Apr 2010 17:54] Reggie Burnett
Jorge

I just commited a fix for 52187 that will likely affect this bug as well. That will appear in 6.0.6, 6.1.4, 6.2.4, and 6.3.2.  Or you can build from source to check it out immediately.
[21 Apr 2010 21:11] Jorge Bastos
Hi Reggie,
Thank you!

Can I ask for a small help on howto get the sources from the repo?
Since it now used something different than SVN, I'm completly new at it.
[22 Apr 2010 13:04] Jorge Bastos
Tonci,

Can you give a hand on how to get the trunk sources?
I have no problem on build them, only on how to retrieve. I work with svn & git, but, this bazaar... is really wierd!!
[22 Apr 2010 13:20] Jorge Bastos
Ok got the trunk sources, and compiled.

Works perfect now, even without setting the server charset to utf8.

Thank you Reggie!