Chinese garbled characters

2024-01-12 07:05:42  Updated

What should I do if Chinese garbled characters appear when a Windows-based client is used to call OceanBase Connector/ODBC for queries and GBK is used as the system's default encoding?

The reason is that when OceanBase Connector/ODBC establishes a connection, if no encoding is specified, it will obtain the system's default encoding, that is, MARIADB_CHARSET_INFO *cs= mariadb_get_charset_by_name("auto");

If your system uses UTF-8 encoding for queries, there is no problem. However, if your system uses GBK encoding, UTF-8-encoded data cannot be displayed.

The solution is to add the following code after the connection is established:

/*Set encoding*/
MDBUG_C_PRINT(Connection, "--cs_name:%s", Connection->Charset.cs_info->csname);
if (mysql_set_character_set(Connection->mariadb, Connection->Charset.cs_info->csname))
goto err;

Contact Us