Open
Description
Hi,
I was debugging a bug in my application and stumbled across something in mysql2
that looks odd to me and would like to clarify.
The bug:
- Context: I am using typeorm and cannot save an emoji (4 unicode bytes) in a string field.
mysql2
version 2.2.5 - The server (MySQL 5.7) has the collation set to utf8mb4_unicode_ci, as does the table/column.
- I supply the connection option
charset: "utf8mb4_unicode_ci"
tomysql2
, but I still get an error when trying to save the string - Only when I manually execute the query
SET NAMES 'utf8mb4';
andSET CHARACTER SET utf8mb4;
after connecting, it works.
Now, what I found odd in mysql2
(when the connection is configured and instantiated):
- in
charsets.js
, the stringUTF8MB4_UNICODE_CI
is mapped to charset number 224 - However, this number is later then mapped to
this.clientEncoding = "utf8"
viacharset_encoding.js
, which looks strange to me, ascharset_encoding.js
states that is "basically the result of SHOW COLLATION query" (in which case the encoding should beutf8mb4
, notutf8
)
I see that there is special mapping code in generate-charset-mapping.js
to map utf8mb4
onto utf8
so this is probably deliberate(?),
but in the end, there still seems to be a bug, as I cannot use the utf8mb4 charsets without "manual patching" after the connection is already established.
Metadata
Metadata
Assignees
Labels
No labels