ODBC connector support for utf8mb4 in MYSQL

戏子无情 提交于 2019-12-11 23:55:26

问题


I have been stuck up in this scenario.

My application is in C++ which connects to MySQL database 5.5.34 through MySQL odbc connector v5.2 Unicode Driver.

My tables were using the character set and collation properties 'utf-8'. To insert supplementary unicode characters, i changed it via

My table was initially created:

CREATE TABLE mytable (SAMPLECOLUMN text) ENGINE=InnoDB DEFAULTCHARSET=utf8;

changed to,
ALTER TABLE mytable CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

After this, I am able to directly (not through my app) insert the supplementary characters into the column holding 'TEXT' data type.

The odbc connector crashes when it encounters supplementary characters.

The following are some of my my.ini configurations.

[mysql]
default-character-set=utf8

[mysqld]
character-set-server=utf8
default-storage-engine=INNODB

The query that i am trying to insert:

INSERT INTO mytable (SAMPLECOLUMN) VALUES ("乕乭𠁄𠁉乺丕");

any pointers/heads up would be great.

Also, tried using v5.3 Unicode MYSQL odbc connector and v1.0.5 MariaDB ODBC connector, still the same.

Thanks in advance.


回答1:


The workaround here is to use MariaDB odbc connector to connect to MySQL database. https://mariadb.com/my_portal/download/connector-odbc/1.0

Make sure you set this in ODBC dsn and keep Connection Character Set empty

Starting v5.2 of MyODBC, SET NAMES has been deprecated. Hence the need to use MariaDB connector. Hope the supplementary character issue is fixed in MySQL odbc connector.




回答2:


You need to issue SET NAMES utf8mb4 after connecting to MySQL. Otherwise, the connection cannot handle the 4-byte characters.

If that is not sufficient, then chase down SQLExecDirectW -- see if there is an update to it.



来源:https://stackoverflow.com/questions/34715346/odbc-connector-support-for-utf8mb4-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!