Bug #6386 Doesn't support Chinese
Submitted: 2 Nov 2004 14:45 Modified: 30 Nov 2004 22:03
Reporter: Juliau Gong Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:1.0.2 gamma OS:Windows (WinXP Pro SP2)
Assigned to: Reggie Burnett CPU Architecture:Any

[2 Nov 2004 14:45] Juliau Gong
Description:
can't display Chinese correctly.

How to repeat:
if the result has Chinese, it can't be displayed correctly.
[2 Nov 2004 19:50] Reggie Burnett
Can you give me more details?  What version of MySQL are you using?  What character set are you running on the server?  What is the output of SHOW CREATE TABLE on the table that you are inserting data into?
[26 Nov 2004 6:04] Juliau Gong
I am using MySQL Server 4.1.7, the server's default character set is latin1, but I have tried set it to utf-8, then all record in the database is uncorrect.

the table is:

CREATE TABLE `adsl` (
  `custid` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
  `custname` VARCHAR(45) NOT NULL,
  PRIMARY KEY(`custid`)
)
TYPE = InnoDB;

thanks.
[30 Nov 2004 5:51] Juliau Gong
tested with the latest version, the bug is still here.
[30 Nov 2004 6:03] Juliau Gong
Perhaps, it must be added the properties like JDBC URL, such as useUnicode and characterEncodeing.

I think this will help to solve the problem.
[30 Nov 2004 16:11] Reggie Burnett
Here is some code that works for me with Chinese.

MySqlConnection c = new MySqlConnection( myconnstr + ";charset=utf8" );
c.Open();

execSQL("DROP TABLE IF EXISTS Test");
execSQL("CREATE TABLE Test (id int, name VARCHAR(200) CHAR SET big5, name2 VARCHAR(200) CHAR SET gb2312)");

MySqlCommand cmd = new MySqlCommand( "INSERT INTO Test VALUES(1, '困巫忘否役', '涝搞谷侪魍' )", c);
cmd.ExecuteNonQuery();

cmd.CommandText = "SELECT * FROM Test";
MySqlDataReader reader = null;
try 
{
	reader = cmd.ExecuteReader();
	reader.Read();
	Assert.AreEqual( "困巫忘否役", reader.GetString(1) );
	Assert.AreEqual( "涝搞谷侪魍", reader.GetString(2) );
}
catch (Exception ex) 
{
	Assert.Fail( ex.Message );
}
finally 
{
	if (reader != null) reader.Close();
	c.Close();
}
[30 Nov 2004 22:03] Reggie Burnett
Thank you for taking the time to report a problem.  Unfortunately
you are not using a current version of the product your reported a
problem with -- the problem might already be fixed. Please download
a new version from http://www.mysql.com/downloads/

If you are able to reproduce the bug with one of the latest versions,
please change the version on this bug report to the version you
tested and change the status back to "Open".  Again, thank you for
your continued support of MySQL.

Additional info:

Please use the charset property on the connection string to set the character to be used for queries.    You'll also want the table to be either the character set you want to use or utf8.
[1 Dec 2004 2:24] Juliau Gong
Reggie,

Thanks very much, it can display the Chinese inserted by the Connector, but it still can't display those inserted by other programs, I thinks those doesn't use utf8. but the other driver on the mysql website such as MySQLDriverCS can do that.

Will the .Net Connector can do that in the future.
[1 Dec 2004 2:39] Juliau Gong
when I edit the content use the MS C# control such as DataGrid, the Chinese can't saved correct, I think that is because when I input the Chinese in the DataGrid the content is not inputed as UTF8, it use the locale of my OS. So, how can I solve this problem.
[1 Dec 2004 2:50] Juliau Gong
I am sorry, I have make a mistake, it can be edited with the C# correctly, thanks very much.

By the way, the MySQLAdapter:Update() method doesn't Open the Connection when the Connection is Closed auto. Can you let it open the connection automatic when the connection is closed and then close the connection after it finish the updating, like the Fill() method. And the Microsoft Class does that automatic.
[1 Dec 2004 3:41] Juliau Gong
I found that the Connector doesn't support the CharSet gbk, but the MySQL Server supports it.
[1 Dec 2004 3:52] Juliau Gong
one more thing, I found that the table's Character Set doesn't affect anything about displaying Chinese.

After the modified the Charater set to other not utf8, the .Net connector can still display the Chinese inserted by the connector correctly. When I set the Connector's charset wrong, Chinese can be displayed correctly, but can't update them correctly, it will throw a exception.