Bug #27166 Can't use chinese as table name normally
Submitted: 15 Mar 2007 8:30 Modified: 16 Mar 2007 21:21
Reporter: [ name withheld ] Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server: MyISAM storage engine Severity:S2 (Serious)
Version:5.0.27 OS:Windows (Windows XP SP2 Chinese version)
Assigned to: CPU Architecture:Any
Tags: Chinese, CREATE TABLE, table name

[15 Mar 2007 8:30] [ name withheld ]
Description:
Can't use chinese as table name normally

How to repeat:
SQL script

set names 'gbk';
CREATE TABLE `test`.`一` (  `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,  PRIMARY KEY(`id`))ENGINE = MYISAM;
ALTER TABLE `test`.`一` RENAME TO `test`.`二`;
CREATE TABLE `test`.`点` (  `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,  PRIMARY KEY(`id`))ENGINE = MYISAM;
CREATE TABLE `test`.`GPS点` (  `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,  PRIMARY KEY(`id`))ENGINE = MYISAM;
CREATE TABLE `test`.`控制` (  `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,  PRIMARY KEY(`id`))ENGINE = MYISAM;
CREATE TABLE `test`.`控制点` (  `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,  PRIMARY KEY(`id`))ENGINE = MYISAM;
[15 Mar 2007 13:32] MySQL Verification Team
Chinese Table Name using QB

Attachment: chinese-table.png (image/x-png, text), 72.44 KiB.

[15 Mar 2007 13:34] MySQL Verification Team
Thank you for the bug report. Looks to me that is a limitation of
the DOS command prompt of Windows not supporting a correct encoding.
I was able to create a table using MySQL Query Browser, please see
picture I attached. Thanks in advance.
[16 Mar 2007 11:11] [ name withheld ]
I can't create it with mysql command line client and C API.

The code snippet like these:

mysql_real_escape_string(m_mysql, str, tableName, (unsigned long)length);
......
mysql_real_query(...)

var "tableName" is included Chinese charaters.

And also failed with Query Browser 1.2.10
[16 Mar 2007 11:12] [ name withheld ]
query browser 1

Attachment: 1.jpg (image/pjpeg, text), 70.77 KiB.

[16 Mar 2007 11:12] [ name withheld ]
query browser 2

Attachment: 2.jpg (image/pjpeg, text), 69.10 KiB.

[16 Mar 2007 21:21] Sergei Golubchik
It does not work in 5.0.
What happens here is -
- MySQL converts your table name from gbk to utf-8, as all metadata internally are in utf8
- it tries to create a filename with the resulting string
- chinese windows interprets the filename as gbk (or some other chinese charset that chinese windows uses for filenames - I don't know which)
- but filename is in utf-8, and is not valid gdb string
- as a result filename is garbled somehow, it does not match tablename anymore.

this cannot be fixed in 5.0, but it's already fixed in 5.1