From a5ff23f2df09af499093e56a0d51ff030afce255 Mon Sep 17 00:00:00 2001 From: Jeremy Daer Date: Wed, 2 Aug 2023 18:23:36 -0700 Subject: [PATCH] Support utf8mb3 charset naming for MySQL 8 and MariaDB 10.6 (#1323) MySQL and MariaDB have long aliased the `utf8` charset to the underlying `utf8mb3`. They both switched to report the underlying charset name instead of the alias name, allowing `utf8` to target `utf8mb4` in the future. That means we need to explicitly map `utf8mb3` for folks running newer MySQL/MariaDB with older `utf8` dbs. --- ext/mysql2/mysql_enc_name_to_ruby.h | 7 ++++--- ext/mysql2/mysql_enc_to_ruby.h | 15 +++++++++++++++ support/mysql_enc_to_ruby.rb | 1 + support/ruby_enc_to_mysql.rb | 1 + 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/ext/mysql2/mysql_enc_name_to_ruby.h b/ext/mysql2/mysql_enc_name_to_ruby.h index b50146d36..95609a7fe 100644 --- a/ext/mysql2/mysql_enc_name_to_ruby.h +++ b/ext/mysql2/mysql_enc_name_to_ruby.h @@ -51,7 +51,7 @@ mysql2_mysql_enc_name_to_rb_hash (str, len) 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 15, 5, - 0, 74, 5, 25, 40, 10, 20, 50, 74, 74, + 0, 30, 5, 25, 40, 10, 20, 50, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, 74, @@ -89,7 +89,7 @@ mysql2_mysql_enc_name_to_rb (str, len) { enum { - TOTAL_KEYWORDS = 41, + TOTAL_KEYWORDS = 42, MIN_WORD_LENGTH = 3, MAX_WORD_LENGTH = 8, MIN_HASH_VALUE = 3, @@ -133,7 +133,8 @@ mysql2_mysql_enc_name_to_rb (str, len) {"big5", "Big5"}, {"euckr", "EUC-KR"}, {"latin2", "ISO-8859-2"}, - {""}, {""}, + {"utf8mb3", "UTF-8"}, + {""}, {"dec8", NULL}, {"cp850", "CP850"}, {"latin1", "ISO-8859-1"}, diff --git a/ext/mysql2/mysql_enc_to_ruby.h b/ext/mysql2/mysql_enc_to_ruby.h index 4c36e4a42..915d9db03 100644 --- a/ext/mysql2/mysql_enc_to_ruby.h +++ b/ext/mysql2/mysql_enc_to_ruby.h @@ -306,5 +306,20 @@ static const char *mysql2_mysql_enc_to_rb[] = { "UTF-8", "UTF-8", "UTF-8", + "UTF-8", + "UTF-8", + "UTF-8", + "UTF-8", + "UTF-8", + "UTF-8", + "UTF-8", + "UTF-8", + "UTF-8", + "UTF-8", + "UTF-8", + "UTF-8", + "UTF-8", + "UTF-8", + "UTF-8", "UTF-8" }; diff --git a/support/mysql_enc_to_ruby.rb b/support/mysql_enc_to_ruby.rb index 4db703409..7207981b9 100644 --- a/support/mysql_enc_to_ruby.rb +++ b/support/mysql_enc_to_ruby.rb @@ -33,6 +33,7 @@ "macroman" => "macRoman", "cp852" => "CP852", "latin7" => "ISO-8859-13", + "utf8mb3" => "UTF-8", "utf8mb4" => "UTF-8", "cp1251" => "Windows-1251", "utf16" => "UTF-16", diff --git a/support/ruby_enc_to_mysql.rb b/support/ruby_enc_to_mysql.rb index 72b68eb25..30dfe2651 100644 --- a/support/ruby_enc_to_mysql.rb +++ b/support/ruby_enc_to_mysql.rb @@ -28,6 +28,7 @@ "macroman" => "macRoman", "cp852" => "CP852", "latin7" => "ISO-8859-13", + "utf8mb3" => "UTF-8", "utf8mb4" => "UTF-8", "cp1251" => "Windows-1251", "utf16" => "UTF-16",