Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode support: Value 'πŸ‘¨πŸΏβ€πŸ‘©πŸΏβ€πŸ‘§πŸΏβ€πŸ‘¦πŸΏ' can't be stored to database column because exceeds length #743

Closed
ezhaka opened this issue Dec 27, 2019 · 0 comments Β· Fixed by #745

Comments

@ezhaka
Copy link

ezhaka commented Dec 27, 2019

Let say we have MySQL >= 5.0 and a column val emoji = varchar(16).

Starting from MySQL 5.0 a varchar column requires to define its size in symbols. If we consider 'πŸ‘¨πŸΏβ€πŸ‘©πŸΏβ€πŸ‘§πŸΏβ€πŸ‘¦πŸΏ' emoji, we found that it has 11 symbols: man emoji, skin modifier, ZWJ (zero-width joiner), woman emoji, skin modifier, ZWJ, girl emoji, skin modifier, ZWJ, boy emoji, skin modifier.

Thus, this emoji can be inserted to val emoji = varchar(16).

However, if we try to insert 'πŸ‘¨πŸΏβ€πŸ‘©πŸΏβ€πŸ‘§πŸΏβ€πŸ‘¦πŸΏ' there via exposed, we'll get java.lang.IllegalStateException: Value 'πŸ‘¨πŸΏβ€πŸ‘©πŸΏβ€πŸ‘§πŸΏβ€πŸ‘¦πŸΏ' can't be stored to database column because exceeds length circlet.stickers.server.DBStickers$Sticker.symbol.columnType.colLength

if (column.columnType is VarCharColumnType && value is String && value.length > column.columnType.colLength) {

The reason for this behavior is that in Java "πŸ‘¨πŸΏβ€πŸ‘©πŸΏβ€πŸ‘§πŸΏβ€πŸ‘¦πŸΏ".lenght == 19, because every emoji and skin modifier is considered as a pair of symbols (https://docs.oracle.com/javase/tutorial/i18n/text/unicode.html)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants