Class: Mysql::Charset

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql/charset.rb

Constant Summary collapse

CHARSETS =
[charset_number, charset_name, collation_name, default], …
[
  [  1, "big5",     "big5_chinese_ci",             true ],
  [  2, "latin2",   "latin2_czech_cs",             false],
  [  3, "dec8",     "dec8_swedish_ci",             true ],
  [  4, "cp850",    "cp850_general_ci",            true ],
  [  5, "latin1",   "latin1_german1_ci",           false],
  [  6, "hp8",      "hp8_english_ci",              true ],
  [  7, "koi8r",    "koi8r_general_ci",            true ],
  [  8, "latin1",   "latin1_swedish_ci",           true ],
  [  9, "latin2",   "latin2_general_ci",           true ],
  [ 10, "swe7",     "swe7_swedish_ci",             true ],
  [ 11, "ascii",    "ascii_general_ci",            true ],
  [ 12, "ujis",     "ujis_japanese_ci",            true ],
  [ 13, "sjis",     "sjis_japanese_ci",            true ],
  [ 14, "cp1251",   "cp1251_bulgarian_ci",         false],
  [ 15, "latin1",   "latin1_danish_ci",            false],
  [ 16, "hebrew",   "hebrew_general_ci",           true ],
  [ 17, "filename", "filename",                    true ],
  [ 18, "tis620",   "tis620_thai_ci",              true ],
  [ 19, "euckr",    "euckr_korean_ci",             true ],
  [ 20, "latin7",   "latin7_estonian_cs",          false],
  [ 21, "latin2",   "latin2_hungarian_ci",         false],
  [ 22, "koi8u",    "koi8u_general_ci",            true ],
  [ 23, "cp1251",   "cp1251_ukrainian_ci",         false],
  [ 24, "gb2312",   "gb2312_chinese_ci",           true ],
  [ 25, "greek",    "greek_general_ci",            true ],
  [ 26, "cp1250",   "cp1250_general_ci",           true ],
  [ 27, "latin2",   "latin2_croatian_ci",          false],
  [ 28, "gbk",      "gbk_chinese_ci",              true ],
  [ 29, "cp1257",   "cp1257_lithuanian_ci",        false],
  [ 30, "latin5",   "latin5_turkish_ci",           true ],
  [ 31, "latin1",   "latin1_german2_ci",           false],
  [ 32, "armscii8", "armscii8_general_ci",         true ],
  [ 33, "utf8",     "utf8_general_ci",             true ],
  [ 33, "utf8mb3",  "utf8mb3_general_ci",          true ],
  [ 34, "cp1250",   "cp1250_czech_cs",             false],
  [ 35, "ucs2",     "ucs2_general_ci",             true ],
  [ 36, "cp866",    "cp866_general_ci",            true ],
  [ 37, "keybcs2",  "keybcs2_general_ci",          true ],
  [ 38, "macce",    "macce_general_ci",            true ],
  [ 39, "macroman", "macroman_general_ci",         true ],
  [ 40, "cp852",    "cp852_general_ci",            true ],
  [ 41, "latin7",   "latin7_general_ci",           true ],
  [ 42, "latin7",   "latin7_general_cs",           false],
  [ 43, "macce",    "macce_bin",                   false],
  [ 44, "cp1250",   "cp1250_croatian_ci",          false],
  [ 45, "utf8mb4",  "utf8mb4_general_ci",          false],
  [ 46, "utf8mb4",  "utf8mb4_bin",                 false],
  [ 47, "latin1",   "latin1_bin",                  false],
  [ 48, "latin1",   "latin1_general_ci",           false],
  [ 49, "latin1",   "latin1_general_cs",           false],
  [ 50, "cp1251",   "cp1251_bin",                  false],
  [ 51, "cp1251",   "cp1251_general_ci",           true ],
  [ 52, "cp1251",   "cp1251_general_cs",           false],
  [ 53, "macroman", "macroman_bin",                false],
  [ 54, "utf16",    "utf16_general_ci",            true ],
  [ 55, "utf16",    "utf16_bin",                   false],
  [ 56, "utf16le",  "utf16le_general_ci",          true ],
  [ 57, "cp1256",   "cp1256_general_ci",           true ],
  [ 58, "cp1257",   "cp1257_bin",                  false],
  [ 59, "cp1257",   "cp1257_general_ci",           true ],
  [ 60, "utf32",    "utf32_general_ci",            true ],
  [ 61, "utf32",    "utf32_bin",                   false],
  [ 62, "utf16le",  "utf16le_bin",                 false],
  [ 63, "binary",   "binary",                      true ],
  [ 64, "armscii8", "armscii8_bin",                false],
  [ 65, "ascii",    "ascii_bin",                   false],
  [ 66, "cp1250",   "cp1250_bin",                  false],
  [ 67, "cp1256",   "cp1256_bin",                  false],
  [ 68, "cp866",    "cp866_bin",                   false],
  [ 69, "dec8",     "dec8_bin",                    false],
  [ 70, "greek",    "greek_bin",                   false],
  [ 71, "hebrew",   "hebrew_bin",                  false],
  [ 72, "hp8",      "hp8_bin",                     false],
  [ 73, "keybcs2",  "keybcs2_bin",                 false],
  [ 74, "koi8r",    "koi8r_bin",                   false],
  [ 75, "koi8u",    "koi8u_bin",                   false],
  [ 76, "utf8",     "utf8_tolower_ci",             false],
  [ 76, "utf8mb3",  "utf8mb3_tolower_ci",          false],
  [ 77, "latin2",   "latin2_bin",                  false],
  [ 78, "latin5",   "latin5_bin",                  false],
  [ 79, "latin7",   "latin7_bin",                  false],
  [ 80, "cp850",    "cp850_bin",                   false],
  [ 81, "cp852",    "cp852_bin",                   false],
  [ 82, "swe7",     "swe7_bin",                    false],
  [ 83, "utf8",     "utf8_bin",                    false],
  [ 83, "utf8mb3",  "utf8mb3_bin",                 false],
  [ 84, "big5",     "big5_bin",                    false],
  [ 85, "euckr",    "euckr_bin",                   false],
  [ 86, "gb2312",   "gb2312_bin",                  false],
  [ 87, "gbk",      "gbk_bin",                     false],
  [ 88, "sjis",     "sjis_bin",                    false],
  [ 89, "tis620",   "tis620_bin",                  false],
  [ 90, "ucs2",     "ucs2_bin",                    false],
  [ 91, "ujis",     "ujis_bin",                    false],
  [ 92, "geostd8",  "geostd8_general_ci",          true ],
  [ 93, "geostd8",  "geostd8_bin",                 false],
  [ 94, "latin1",   "latin1_spanish_ci",           false],
  [ 95, "cp932",    "cp932_japanese_ci",           true ],
  [ 96, "cp932",    "cp932_bin",                   false],
  [ 97, "eucjpms",  "eucjpms_japanese_ci",         true ],
  [ 98, "eucjpms",  "eucjpms_bin",                 false],
  [ 99, "cp1250",   "cp1250_polish_ci",            false],
  [101, "utf16",    "utf16_unicode_ci",            false],
  [102, "utf16",    "utf16_icelandic_ci",          false],
  [103, "utf16",    "utf16_latvian_ci",            false],
  [104, "utf16",    "utf16_romanian_ci",           false],
  [105, "utf16",    "utf16_slovenian_ci",          false],
  [106, "utf16",    "utf16_polish_ci",             false],
  [107, "utf16",    "utf16_estonian_ci",           false],
  [108, "utf16",    "utf16_spanish_ci",            false],
  [109, "utf16",    "utf16_swedish_ci",            false],
  [110, "utf16",    "utf16_turkish_ci",            false],
  [111, "utf16",    "utf16_czech_ci",              false],
  [112, "utf16",    "utf16_danish_ci",             false],
  [113, "utf16",    "utf16_lithuanian_ci",         false],
  [114, "utf16",    "utf16_slovak_ci",             false],
  [115, "utf16",    "utf16_spanish2_ci",           false],
  [116, "utf16",    "utf16_roman_ci",              false],
  [117, "utf16",    "utf16_persian_ci",            false],
  [118, "utf16",    "utf16_esperanto_ci",          false],
  [119, "utf16",    "utf16_hungarian_ci",          false],
  [120, "utf16",    "utf16_sinhala_ci",            false],
  [121, "utf16",    "utf16_german2_ci",            false],
  [122, "utf16",    "utf16_croatian_ci",           false],
  [123, "utf16",    "utf16_unicode_520_ci",        false],
  [124, "utf16",    "utf16_vietnamese_ci",         false],
  [128, "ucs2",     "ucs2_unicode_ci",             false],
  [129, "ucs2",     "ucs2_icelandic_ci",           false],
  [130, "ucs2",     "ucs2_latvian_ci",             false],
  [131, "ucs2",     "ucs2_romanian_ci",            false],
  [132, "ucs2",     "ucs2_slovenian_ci",           false],
  [133, "ucs2",     "ucs2_polish_ci",              false],
  [134, "ucs2",     "ucs2_estonian_ci",            false],
  [135, "ucs2",     "ucs2_spanish_ci",             false],
  [136, "ucs2",     "ucs2_swedish_ci",             false],
  [137, "ucs2",     "ucs2_turkish_ci",             false],
  [138, "ucs2",     "ucs2_czech_ci",               false],
  [139, "ucs2",     "ucs2_danish_ci",              false],
  [140, "ucs2",     "ucs2_lithuanian_ci",          false],
  [141, "ucs2",     "ucs2_slovak_ci",              false],
  [142, "ucs2",     "ucs2_spanish2_ci",            false],
  [143, "ucs2",     "ucs2_roman_ci",               false],
  [144, "ucs2",     "ucs2_persian_ci",             false],
  [145, "ucs2",     "ucs2_esperanto_ci",           false],
  [146, "ucs2",     "ucs2_hungarian_ci",           false],
  [147, "ucs2",     "ucs2_sinhala_ci",             false],
  [148, "ucs2",     "ucs2_german2_ci",             false],
  [149, "ucs2",     "ucs2_croatian_ci",            false],
  [150, "ucs2",     "ucs2_unicode_520_ci",         false],
  [151, "ucs2",     "ucs2_vietnamese_ci",          false],
  [159, "ucs2",     "ucs2_general_mysql500_ci",    false],
  [160, "utf32",    "utf32_unicode_ci",            false],
  [161, "utf32",    "utf32_icelandic_ci",          false],
  [162, "utf32",    "utf32_latvian_ci",            false],
  [163, "utf32",    "utf32_romanian_ci",           false],
  [164, "utf32",    "utf32_slovenian_ci",          false],
  [165, "utf32",    "utf32_polish_ci",             false],
  [166, "utf32",    "utf32_estonian_ci",           false],
  [167, "utf32",    "utf32_spanish_ci",            false],
  [168, "utf32",    "utf32_swedish_ci",            false],
  [169, "utf32",    "utf32_turkish_ci",            false],
  [170, "utf32",    "utf32_czech_ci",              false],
  [171, "utf32",    "utf32_danish_ci",             false],
  [172, "utf32",    "utf32_lithuanian_ci",         false],
  [173, "utf32",    "utf32_slovak_ci",             false],
  [174, "utf32",    "utf32_spanish2_ci",           false],
  [175, "utf32",    "utf32_roman_ci",              false],
  [176, "utf32",    "utf32_persian_ci",            false],
  [177, "utf32",    "utf32_esperanto_ci",          false],
  [178, "utf32",    "utf32_hungarian_ci",          false],
  [179, "utf32",    "utf32_sinhala_ci",            false],
  [180, "utf32",    "utf32_german2_ci",            false],
  [181, "utf32",    "utf32_croatian_ci",           false],
  [182, "utf32",    "utf32_unicode_520_ci",        false],
  [183, "utf32",    "utf32_vietnamese_ci",         false],
  [192, "utf8",     "utf8_unicode_ci",             false],
  [193, "utf8",     "utf8_icelandic_ci",           false],
  [194, "utf8",     "utf8_latvian_ci",             false],
  [195, "utf8",     "utf8_romanian_ci",            false],
  [196, "utf8",     "utf8_slovenian_ci",           false],
  [197, "utf8",     "utf8_polish_ci",              false],
  [198, "utf8",     "utf8_estonian_ci",            false],
  [199, "utf8",     "utf8_spanish_ci",             false],
  [200, "utf8",     "utf8_swedish_ci",             false],
  [201, "utf8",     "utf8_turkish_ci",             false],
  [202, "utf8",     "utf8_czech_ci",               false],
  [203, "utf8",     "utf8_danish_ci",              false],
  [204, "utf8",     "utf8_lithuanian_ci",          false],
  [205, "utf8",     "utf8_slovak_ci",              false],
  [206, "utf8",     "utf8_spanish2_ci",            false],
  [207, "utf8",     "utf8_roman_ci",               false],
  [208, "utf8",     "utf8_persian_ci",             false],
  [209, "utf8",     "utf8_esperanto_ci",           false],
  [210, "utf8",     "utf8_hungarian_ci",           false],
  [211, "utf8",     "utf8_sinhala_ci",             false],
  [212, "utf8",     "utf8_german2_ci",             false],
  [213, "utf8",     "utf8_croatian_ci",            false],
  [214, "utf8",     "utf8_unicode_520_ci",         false],
  [215, "utf8",     "utf8_vietnamese_ci",          false],
  [223, "utf8",     "utf8_general_mysql500_ci",    false],
  [192, "utf8mb3",  "utf8mb3_unicode_ci",          false],
  [193, "utf8mb3",  "utf8mb3_icelandic_ci",        false],
  [194, "utf8mb3",  "utf8mb3_latvian_ci",          false],
  [195, "utf8mb3",  "utf8mb3_romanian_ci",         false],
  [196, "utf8mb3",  "utf8mb3_slovenian_ci",        false],
  [197, "utf8mb3",  "utf8mb3_polish_ci",           false],
  [198, "utf8mb3",  "utf8mb3_estonian_ci",         false],
  [199, "utf8mb3",  "utf8mb3_spanish_ci",          false],
  [200, "utf8mb3",  "utf8mb3_swedish_ci",          false],
  [201, "utf8mb3",  "utf8mb3_turkish_ci",          false],
  [202, "utf8mb3",  "utf8mb3_czech_ci",            false],
  [203, "utf8mb3",  "utf8mb3_danish_ci",           false],
  [204, "utf8mb3",  "utf8mb3_lithuanian_ci",       false],
  [205, "utf8mb3",  "utf8mb3_slovak_ci",           false],
  [206, "utf8mb3",  "utf8mb3_spanish2_ci",         false],
  [207, "utf8mb3",  "utf8mb3_roman_ci",            false],
  [208, "utf8mb3",  "utf8mb3_persian_ci",          false],
  [209, "utf8mb3",  "utf8mb3_esperanto_ci",        false],
  [210, "utf8mb3",  "utf8mb3_hungarian_ci",        false],
  [211, "utf8mb3",  "utf8mb3_sinhala_ci",          false],
  [212, "utf8mb3",  "utf8mb3_german2_ci",          false],
  [213, "utf8mb3",  "utf8mb3_croatian_ci",         false],
  [214, "utf8mb3",  "utf8mb3_unicode_520_ci",      false],
  [215, "utf8mb3",  "utf8mb3_vietnamese_ci",       false],
  [223, "utf8mb3",  "utf8mb3_general_mysql500_ci", false],
  [224, "utf8mb4",  "utf8mb4_unicode_ci",          false],
  [225, "utf8mb4",  "utf8mb4_icelandic_ci",        false],
  [226, "utf8mb4",  "utf8mb4_latvian_ci",          false],
  [227, "utf8mb4",  "utf8mb4_romanian_ci",         false],
  [228, "utf8mb4",  "utf8mb4_slovenian_ci",        false],
  [229, "utf8mb4",  "utf8mb4_polish_ci",           false],
  [230, "utf8mb4",  "utf8mb4_estonian_ci",         false],
  [231, "utf8mb4",  "utf8mb4_spanish_ci",          false],
  [232, "utf8mb4",  "utf8mb4_swedish_ci",          false],
  [233, "utf8mb4",  "utf8mb4_turkish_ci",          false],
  [234, "utf8mb4",  "utf8mb4_czech_ci",            false],
  [235, "utf8mb4",  "utf8mb4_danish_ci",           false],
  [236, "utf8mb4",  "utf8mb4_lithuanian_ci",       false],
  [237, "utf8mb4",  "utf8mb4_slovak_ci",           false],
  [238, "utf8mb4",  "utf8mb4_spanish2_ci",         false],
  [239, "utf8mb4",  "utf8mb4_roman_ci",            false],
  [240, "utf8mb4",  "utf8mb4_persian_ci",          false],
  [241, "utf8mb4",  "utf8mb4_esperanto_ci",        false],
  [242, "utf8mb4",  "utf8mb4_hungarian_ci",        false],
  [243, "utf8mb4",  "utf8mb4_sinhala_ci",          false],
  [244, "utf8mb4",  "utf8mb4_german2_ci",          false],
  [245, "utf8mb4",  "utf8mb4_croatian_ci",         false],
  [246, "utf8mb4",  "utf8mb4_unicode_520_ci",      false],
  [247, "utf8mb4",  "utf8mb4_vietnamese_ci",       false],
  [248, "gb18030",  "gb18030_chinese_ci",          true ],
  [249, "gb18030",  "gb18030_bin",                 false],
  [250, "gb18030",  "gb18030_unicode_520_ci",      false],
  [254, "utf8",     "utf8mb3_general_cs",          false],
  [254, "utf8mb3",  "utf8mb3_general_cs",          false],
  [255, "utf8mb4",  "utf8mb4_0900_ai_ci",          true ],
  [256, "utf8mb4",  "utf8mb4_de_pb_0900_ai_ci",    false],
  [257, "utf8mb4",  "utf8mb4_is_0900_ai_ci",       false],
  [258, "utf8mb4",  "utf8mb4_lv_0900_ai_ci",       false],
  [259, "utf8mb4",  "utf8mb4_ro_0900_ai_ci",       false],
  [260, "utf8mb4",  "utf8mb4_sl_0900_ai_ci",       false],
  [261, "utf8mb4",  "utf8mb4_pl_0900_ai_ci",       false],
  [262, "utf8mb4",  "utf8mb4_et_0900_ai_ci",       false],
  [263, "utf8mb4",  "utf8mb4_es_0900_ai_ci",       false],
  [264, "utf8mb4",  "utf8mb4_sv_0900_ai_ci",       false],
  [265, "utf8mb4",  "utf8mb4_tr_0900_ai_ci",       false],
  [266, "utf8mb4",  "utf8mb4_cs_0900_ai_ci",       false],
  [267, "utf8mb4",  "utf8mb4_da_0900_ai_ci",       false],
  [268, "utf8mb4",  "utf8mb4_lt_0900_ai_ci",       false],
  [269, "utf8mb4",  "utf8mb4_sk_0900_ai_ci",       false],
  [270, "utf8mb4",  "utf8mb4_es_trad_0900_ai_ci",  false],
  [271, "utf8mb4",  "utf8mb4_la_0900_ai_ci",       false],
  [273, "utf8mb4",  "utf8mb4_eo_0900_ai_ci",       false],
  [274, "utf8mb4",  "utf8mb4_hu_0900_ai_ci",       false],
  [275, "utf8mb4",  "utf8mb4_hr_0900_ai_ci",       false],
  [277, "utf8mb4",  "utf8mb4_vi_0900_ai_ci",       false],
  [278, "utf8mb4",  "utf8mb4_0900_as_cs",          false],
  [279, "utf8mb4",  "utf8mb4_de_pb_0900_as_cs",    false],
  [280, "utf8mb4",  "utf8mb4_is_0900_as_cs",       false],
  [281, "utf8mb4",  "utf8mb4_lv_0900_as_cs",       false],
  [282, "utf8mb4",  "utf8mb4_ro_0900_as_cs",       false],
  [283, "utf8mb4",  "utf8mb4_sl_0900_as_cs",       false],
  [284, "utf8mb4",  "utf8mb4_pl_0900_as_cs",       false],
  [285, "utf8mb4",  "utf8mb4_et_0900_as_cs",       false],
  [286, "utf8mb4",  "utf8mb4_es_0900_as_cs",       false],
  [287, "utf8mb4",  "utf8mb4_sv_0900_as_cs",       false],
  [288, "utf8mb4",  "utf8mb4_tr_0900_as_cs",       false],
  [289, "utf8mb4",  "utf8mb4_cs_0900_as_cs",       false],
  [290, "utf8mb4",  "utf8mb4_da_0900_as_cs",       false],
  [291, "utf8mb4",  "utf8mb4_lt_0900_as_cs",       false],
  [292, "utf8mb4",  "utf8mb4_sk_0900_as_cs",       false],
  [293, "utf8mb4",  "utf8mb4_es_trad_0900_as_cs",  false],
  [294, "utf8mb4",  "utf8mb4_la_0900_as_cs",       false],
  [296, "utf8mb4",  "utf8mb4_eo_0900_as_cs",       false],
  [297, "utf8mb4",  "utf8mb4_hu_0900_as_cs",       false],
  [298, "utf8mb4",  "utf8mb4_hr_0900_as_cs",       false],
  [300, "utf8mb4",  "utf8mb4_vi_0900_as_cs",       false],
  [303, "utf8mb4",  "utf8mb4_ja_0900_as_cs",       false],
  [304, "utf8mb4",  "utf8mb4_ja_0900_as_cs_ks",    false],
  [305, "utf8mb4",  "utf8mb4_0900_as_ci",          false],
  [306, "utf8mb4",  "utf8mb4_ru_0900_ai_ci",       false],
  [307, "utf8mb4",  "utf8mb4_ru_0900_as_cs",       false],
  [308, "utf8mb4",  "utf8mb4_zh_0900_as_cs",       false],
  [309, "utf8mb4",  "utf8mb4_0900_bin",            false],
].freeze
NUMBER_TO_CHARSET =
{}
COLLATION_TO_CHARSET =
{}
CHARSET_DEFAULT =
{}
BINARY_CHARSET_NUMBER =
CHARSET_DEFAULT['binary'].number
CHARSET_ENCODING =

MySQL Charset -> Ruby’s Encoding

{
  "armscii8" => nil,
  "ascii"    => Encoding::US_ASCII,
  "big5"     => Encoding::Big5,
  "binary"   => Encoding::ASCII_8BIT,
  "cp1250"   => Encoding::Windows_1250,
  "cp1251"   => Encoding::Windows_1251,
  "cp1256"   => Encoding::Windows_1256,
  "cp1257"   => Encoding::Windows_1257,
  "cp850"    => Encoding::CP850,
  "cp852"    => Encoding::CP852,
  "cp866"    => Encoding::IBM866,
  "cp932"    => Encoding::Windows_31J,
  "dec8"     => nil,
  "eucjpms"  => Encoding::EucJP_ms,
  "euckr"    => Encoding::EUC_KR,
  "gb18030"  => Encoding::GB18030,
  "gb2312"   => Encoding::EUC_CN,
  "gbk"      => Encoding::GBK,
  "geostd8"  => nil,
  "greek"    => Encoding::ISO_8859_7,
  "hebrew"   => Encoding::ISO_8859_8,
  "hp8"      => nil,
  "keybcs2"  => nil,
  "koi8r"    => Encoding::KOI8_R,
  "koi8u"    => Encoding::KOI8_U,
  "latin1"   => Encoding::ISO_8859_1,
  "latin2"   => Encoding::ISO_8859_2,
  "latin5"   => Encoding::ISO_8859_9,
  "latin7"   => Encoding::ISO_8859_13,
  "macce"    => Encoding::MacCentEuro,
  "macroman" => Encoding::MacRoman,
  "sjis"     => Encoding::SHIFT_JIS,
  "swe7"     => nil,
  "tis620"   => Encoding::TIS_620,
  "ucs2"     => Encoding::UTF_16BE,
  "ujis"     => Encoding::EucJP_ms,
  "utf16"    => Encoding::UTF_16BE,
  "utf16le"  => Encoding::UTF_16LE,
  "utf32"    => Encoding::UTF_32BE,
  "utf8"     => Encoding::UTF_8,
  "utf8mb3"  => Encoding::UTF_8,
  "utf8mb4"  => Encoding::UTF_8,
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number, name, csname) ⇒ Charset

Returns a new instance of Charset.

Parameters:

  • number (Integer)
  • name (String)
  • csname (String)


18
19
20
# File 'lib/mysql/charset.rb', line 18

def initialize(number, name, csname)
  @number, @name, @csname = number, name, csname
end

Instance Attribute Details

#csnameString (readonly)

Returns collation name.

Returns:

  • (String)

    collation name



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# File 'lib/mysql/charset.rb', line 13

class Charset
  # @private
  # @param [Integer] number
  # @param [String] name
  # @param [String] csname
  def initialize(number, name, csname)
    @number, @name, @csname = number, name, csname
  end

  attr_reader :number, :name, :csname

  # [[charset_number, charset_name, collation_name, default], ...]
  # @private
  CHARSETS = [
    [  1, "big5",     "big5_chinese_ci",             true ],
    [  2, "latin2",   "latin2_czech_cs",             false],
    [  3, "dec8",     "dec8_swedish_ci",             true ],
    [  4, "cp850",    "cp850_general_ci",            true ],
    [  5, "latin1",   "latin1_german1_ci",           false],
    [  6, "hp8",      "hp8_english_ci",              true ],
    [  7, "koi8r",    "koi8r_general_ci",            true ],
    [  8, "latin1",   "latin1_swedish_ci",           true ],
    [  9, "latin2",   "latin2_general_ci",           true ],
    [ 10, "swe7",     "swe7_swedish_ci",             true ],
    [ 11, "ascii",    "ascii_general_ci",            true ],
    [ 12, "ujis",     "ujis_japanese_ci",            true ],
    [ 13, "sjis",     "sjis_japanese_ci",            true ],
    [ 14, "cp1251",   "cp1251_bulgarian_ci",         false],
    [ 15, "latin1",   "latin1_danish_ci",            false],
    [ 16, "hebrew",   "hebrew_general_ci",           true ],
    [ 17, "filename", "filename",                    true ],
    [ 18, "tis620",   "tis620_thai_ci",              true ],
    [ 19, "euckr",    "euckr_korean_ci",             true ],
    [ 20, "latin7",   "latin7_estonian_cs",          false],
    [ 21, "latin2",   "latin2_hungarian_ci",         false],
    [ 22, "koi8u",    "koi8u_general_ci",            true ],
    [ 23, "cp1251",   "cp1251_ukrainian_ci",         false],
    [ 24, "gb2312",   "gb2312_chinese_ci",           true ],
    [ 25, "greek",    "greek_general_ci",            true ],
    [ 26, "cp1250",   "cp1250_general_ci",           true ],
    [ 27, "latin2",   "latin2_croatian_ci",          false],
    [ 28, "gbk",      "gbk_chinese_ci",              true ],
    [ 29, "cp1257",   "cp1257_lithuanian_ci",        false],
    [ 30, "latin5",   "latin5_turkish_ci",           true ],
    [ 31, "latin1",   "latin1_german2_ci",           false],
    [ 32, "armscii8", "armscii8_general_ci",         true ],
    [ 33, "utf8",     "utf8_general_ci",             true ],
    [ 33, "utf8mb3",  "utf8mb3_general_ci",          true ],
    [ 34, "cp1250",   "cp1250_czech_cs",             false],
    [ 35, "ucs2",     "ucs2_general_ci",             true ],
    [ 36, "cp866",    "cp866_general_ci",            true ],
    [ 37, "keybcs2",  "keybcs2_general_ci",          true ],
    [ 38, "macce",    "macce_general_ci",            true ],
    [ 39, "macroman", "macroman_general_ci",         true ],
    [ 40, "cp852",    "cp852_general_ci",            true ],
    [ 41, "latin7",   "latin7_general_ci",           true ],
    [ 42, "latin7",   "latin7_general_cs",           false],
    [ 43, "macce",    "macce_bin",                   false],
    [ 44, "cp1250",   "cp1250_croatian_ci",          false],
    [ 45, "utf8mb4",  "utf8mb4_general_ci",          false],
    [ 46, "utf8mb4",  "utf8mb4_bin",                 false],
    [ 47, "latin1",   "latin1_bin",                  false],
    [ 48, "latin1",   "latin1_general_ci",           false],
    [ 49, "latin1",   "latin1_general_cs",           false],
    [ 50, "cp1251",   "cp1251_bin",                  false],
    [ 51, "cp1251",   "cp1251_general_ci",           true ],
    [ 52, "cp1251",   "cp1251_general_cs",           false],
    [ 53, "macroman", "macroman_bin",                false],
    [ 54, "utf16",    "utf16_general_ci",            true ],
    [ 55, "utf16",    "utf16_bin",                   false],
    [ 56, "utf16le",  "utf16le_general_ci",          true ],
    [ 57, "cp1256",   "cp1256_general_ci",           true ],
    [ 58, "cp1257",   "cp1257_bin",                  false],
    [ 59, "cp1257",   "cp1257_general_ci",           true ],
    [ 60, "utf32",    "utf32_general_ci",            true ],
    [ 61, "utf32",    "utf32_bin",                   false],
    [ 62, "utf16le",  "utf16le_bin",                 false],
    [ 63, "binary",   "binary",                      true ],
    [ 64, "armscii8", "armscii8_bin",                false],
    [ 65, "ascii",    "ascii_bin",                   false],
    [ 66, "cp1250",   "cp1250_bin",                  false],
    [ 67, "cp1256",   "cp1256_bin",                  false],
    [ 68, "cp866",    "cp866_bin",                   false],
    [ 69, "dec8",     "dec8_bin",                    false],
    [ 70, "greek",    "greek_bin",                   false],
    [ 71, "hebrew",   "hebrew_bin",                  false],
    [ 72, "hp8",      "hp8_bin",                     false],
    [ 73, "keybcs2",  "keybcs2_bin",                 false],
    [ 74, "koi8r",    "koi8r_bin",                   false],
    [ 75, "koi8u",    "koi8u_bin",                   false],
    [ 76, "utf8",     "utf8_tolower_ci",             false],
    [ 76, "utf8mb3",  "utf8mb3_tolower_ci",          false],
    [ 77, "latin2",   "latin2_bin",                  false],
    [ 78, "latin5",   "latin5_bin",                  false],
    [ 79, "latin7",   "latin7_bin",                  false],
    [ 80, "cp850",    "cp850_bin",                   false],
    [ 81, "cp852",    "cp852_bin",                   false],
    [ 82, "swe7",     "swe7_bin",                    false],
    [ 83, "utf8",     "utf8_bin",                    false],
    [ 83, "utf8mb3",  "utf8mb3_bin",                 false],
    [ 84, "big5",     "big5_bin",                    false],
    [ 85, "euckr",    "euckr_bin",                   false],
    [ 86, "gb2312",   "gb2312_bin",                  false],
    [ 87, "gbk",      "gbk_bin",                     false],
    [ 88, "sjis",     "sjis_bin",                    false],
    [ 89, "tis620",   "tis620_bin",                  false],
    [ 90, "ucs2",     "ucs2_bin",                    false],
    [ 91, "ujis",     "ujis_bin",                    false],
    [ 92, "geostd8",  "geostd8_general_ci",          true ],
    [ 93, "geostd8",  "geostd8_bin",                 false],
    [ 94, "latin1",   "latin1_spanish_ci",           false],
    [ 95, "cp932",    "cp932_japanese_ci",           true ],
    [ 96, "cp932",    "cp932_bin",                   false],
    [ 97, "eucjpms",  "eucjpms_japanese_ci",         true ],
    [ 98, "eucjpms",  "eucjpms_bin",                 false],
    [ 99, "cp1250",   "cp1250_polish_ci",            false],
    [101, "utf16",    "utf16_unicode_ci",            false],
    [102, "utf16",    "utf16_icelandic_ci",          false],
    [103, "utf16",    "utf16_latvian_ci",            false],
    [104, "utf16",    "utf16_romanian_ci",           false],
    [105, "utf16",    "utf16_slovenian_ci",          false],
    [106, "utf16",    "utf16_polish_ci",             false],
    [107, "utf16",    "utf16_estonian_ci",           false],
    [108, "utf16",    "utf16_spanish_ci",            false],
    [109, "utf16",    "utf16_swedish_ci",            false],
    [110, "utf16",    "utf16_turkish_ci",            false],
    [111, "utf16",    "utf16_czech_ci",              false],
    [112, "utf16",    "utf16_danish_ci",             false],
    [113, "utf16",    "utf16_lithuanian_ci",         false],
    [114, "utf16",    "utf16_slovak_ci",             false],
    [115, "utf16",    "utf16_spanish2_ci",           false],
    [116, "utf16",    "utf16_roman_ci",              false],
    [117, "utf16",    "utf16_persian_ci",            false],
    [118, "utf16",    "utf16_esperanto_ci",          false],
    [119, "utf16",    "utf16_hungarian_ci",          false],
    [120, "utf16",    "utf16_sinhala_ci",            false],
    [121, "utf16",    "utf16_german2_ci",            false],
    [122, "utf16",    "utf16_croatian_ci",           false],
    [123, "utf16",    "utf16_unicode_520_ci",        false],
    [124, "utf16",    "utf16_vietnamese_ci",         false],
    [128, "ucs2",     "ucs2_unicode_ci",             false],
    [129, "ucs2",     "ucs2_icelandic_ci",           false],
    [130, "ucs2",     "ucs2_latvian_ci",             false],
    [131, "ucs2",     "ucs2_romanian_ci",            false],
    [132, "ucs2",     "ucs2_slovenian_ci",           false],
    [133, "ucs2",     "ucs2_polish_ci",              false],
    [134, "ucs2",     "ucs2_estonian_ci",            false],
    [135, "ucs2",     "ucs2_spanish_ci",             false],
    [136, "ucs2",     "ucs2_swedish_ci",             false],
    [137, "ucs2",     "ucs2_turkish_ci",             false],
    [138, "ucs2",     "ucs2_czech_ci",               false],
    [139, "ucs2",     "ucs2_danish_ci",              false],
    [140, "ucs2",     "ucs2_lithuanian_ci",          false],
    [141, "ucs2",     "ucs2_slovak_ci",              false],
    [142, "ucs2",     "ucs2_spanish2_ci",            false],
    [143, "ucs2",     "ucs2_roman_ci",               false],
    [144, "ucs2",     "ucs2_persian_ci",             false],
    [145, "ucs2",     "ucs2_esperanto_ci",           false],
    [146, "ucs2",     "ucs2_hungarian_ci",           false],
    [147, "ucs2",     "ucs2_sinhala_ci",             false],
    [148, "ucs2",     "ucs2_german2_ci",             false],
    [149, "ucs2",     "ucs2_croatian_ci",            false],
    [150, "ucs2",     "ucs2_unicode_520_ci",         false],
    [151, "ucs2",     "ucs2_vietnamese_ci",          false],
    [159, "ucs2",     "ucs2_general_mysql500_ci",    false],
    [160, "utf32",    "utf32_unicode_ci",            false],
    [161, "utf32",    "utf32_icelandic_ci",          false],
    [162, "utf32",    "utf32_latvian_ci",            false],
    [163, "utf32",    "utf32_romanian_ci",           false],
    [164, "utf32",    "utf32_slovenian_ci",          false],
    [165, "utf32",    "utf32_polish_ci",             false],
    [166, "utf32",    "utf32_estonian_ci",           false],
    [167, "utf32",    "utf32_spanish_ci",            false],
    [168, "utf32",    "utf32_swedish_ci",            false],
    [169, "utf32",    "utf32_turkish_ci",            false],
    [170, "utf32",    "utf32_czech_ci",              false],
    [171, "utf32",    "utf32_danish_ci",             false],
    [172, "utf32",    "utf32_lithuanian_ci",         false],
    [173, "utf32",    "utf32_slovak_ci",             false],
    [174, "utf32",    "utf32_spanish2_ci",           false],
    [175, "utf32",    "utf32_roman_ci",              false],
    [176, "utf32",    "utf32_persian_ci",            false],
    [177, "utf32",    "utf32_esperanto_ci",          false],
    [178, "utf32",    "utf32_hungarian_ci",          false],
    [179, "utf32",    "utf32_sinhala_ci",            false],
    [180, "utf32",    "utf32_german2_ci",            false],
    [181, "utf32",    "utf32_croatian_ci",           false],
    [182, "utf32",    "utf32_unicode_520_ci",        false],
    [183, "utf32",    "utf32_vietnamese_ci",         false],
    [192, "utf8",     "utf8_unicode_ci",             false],
    [193, "utf8",     "utf8_icelandic_ci",           false],
    [194, "utf8",     "utf8_latvian_ci",             false],
    [195, "utf8",     "utf8_romanian_ci",            false],
    [196, "utf8",     "utf8_slovenian_ci",           false],
    [197, "utf8",     "utf8_polish_ci",              false],
    [198, "utf8",     "utf8_estonian_ci",            false],
    [199, "utf8",     "utf8_spanish_ci",             false],
    [200, "utf8",     "utf8_swedish_ci",             false],
    [201, "utf8",     "utf8_turkish_ci",             false],
    [202, "utf8",     "utf8_czech_ci",               false],
    [203, "utf8",     "utf8_danish_ci",              false],
    [204, "utf8",     "utf8_lithuanian_ci",          false],
    [205, "utf8",     "utf8_slovak_ci",              false],
    [206, "utf8",     "utf8_spanish2_ci",            false],
    [207, "utf8",     "utf8_roman_ci",               false],
    [208, "utf8",     "utf8_persian_ci",             false],
    [209, "utf8",     "utf8_esperanto_ci",           false],
    [210, "utf8",     "utf8_hungarian_ci",           false],
    [211, "utf8",     "utf8_sinhala_ci",             false],
    [212, "utf8",     "utf8_german2_ci",             false],
    [213, "utf8",     "utf8_croatian_ci",            false],
    [214, "utf8",     "utf8_unicode_520_ci",         false],
    [215, "utf8",     "utf8_vietnamese_ci",          false],
    [223, "utf8",     "utf8_general_mysql500_ci",    false],
    [192, "utf8mb3",  "utf8mb3_unicode_ci",          false],
    [193, "utf8mb3",  "utf8mb3_icelandic_ci",        false],
    [194, "utf8mb3",  "utf8mb3_latvian_ci",          false],
    [195, "utf8mb3",  "utf8mb3_romanian_ci",         false],
    [196, "utf8mb3",  "utf8mb3_slovenian_ci",        false],
    [197, "utf8mb3",  "utf8mb3_polish_ci",           false],
    [198, "utf8mb3",  "utf8mb3_estonian_ci",         false],
    [199, "utf8mb3",  "utf8mb3_spanish_ci",          false],
    [200, "utf8mb3",  "utf8mb3_swedish_ci",          false],
    [201, "utf8mb3",  "utf8mb3_turkish_ci",          false],
    [202, "utf8mb3",  "utf8mb3_czech_ci",            false],
    [203, "utf8mb3",  "utf8mb3_danish_ci",           false],
    [204, "utf8mb3",  "utf8mb3_lithuanian_ci",       false],
    [205, "utf8mb3",  "utf8mb3_slovak_ci",           false],
    [206, "utf8mb3",  "utf8mb3_spanish2_ci",         false],
    [207, "utf8mb3",  "utf8mb3_roman_ci",            false],
    [208, "utf8mb3",  "utf8mb3_persian_ci",          false],
    [209, "utf8mb3",  "utf8mb3_esperanto_ci",        false],
    [210, "utf8mb3",  "utf8mb3_hungarian_ci",        false],
    [211, "utf8mb3",  "utf8mb3_sinhala_ci",          false],
    [212, "utf8mb3",  "utf8mb3_german2_ci",          false],
    [213, "utf8mb3",  "utf8mb3_croatian_ci",         false],
    [214, "utf8mb3",  "utf8mb3_unicode_520_ci",      false],
    [215, "utf8mb3",  "utf8mb3_vietnamese_ci",       false],
    [223, "utf8mb3",  "utf8mb3_general_mysql500_ci", false],
    [224, "utf8mb4",  "utf8mb4_unicode_ci",          false],
    [225, "utf8mb4",  "utf8mb4_icelandic_ci",        false],
    [226, "utf8mb4",  "utf8mb4_latvian_ci",          false],
    [227, "utf8mb4",  "utf8mb4_romanian_ci",         false],
    [228, "utf8mb4",  "utf8mb4_slovenian_ci",        false],
    [229, "utf8mb4",  "utf8mb4_polish_ci",           false],
    [230, "utf8mb4",  "utf8mb4_estonian_ci",         false],
    [231, "utf8mb4",  "utf8mb4_spanish_ci",          false],
    [232, "utf8mb4",  "utf8mb4_swedish_ci",          false],
    [233, "utf8mb4",  "utf8mb4_turkish_ci",          false],
    [234, "utf8mb4",  "utf8mb4_czech_ci",            false],
    [235, "utf8mb4",  "utf8mb4_danish_ci",           false],
    [236, "utf8mb4",  "utf8mb4_lithuanian_ci",       false],
    [237, "utf8mb4",  "utf8mb4_slovak_ci",           false],
    [238, "utf8mb4",  "utf8mb4_spanish2_ci",         false],
    [239, "utf8mb4",  "utf8mb4_roman_ci",            false],
    [240, "utf8mb4",  "utf8mb4_persian_ci",          false],
    [241, "utf8mb4",  "utf8mb4_esperanto_ci",        false],
    [242, "utf8mb4",  "utf8mb4_hungarian_ci",        false],
    [243, "utf8mb4",  "utf8mb4_sinhala_ci",          false],
    [244, "utf8mb4",  "utf8mb4_german2_ci",          false],
    [245, "utf8mb4",  "utf8mb4_croatian_ci",         false],
    [246, "utf8mb4",  "utf8mb4_unicode_520_ci",      false],
    [247, "utf8mb4",  "utf8mb4_vietnamese_ci",       false],
    [248, "gb18030",  "gb18030_chinese_ci",          true ],
    [249, "gb18030",  "gb18030_bin",                 false],
    [250, "gb18030",  "gb18030_unicode_520_ci",      false],
    [254, "utf8",     "utf8mb3_general_cs",          false],
    [254, "utf8mb3",  "utf8mb3_general_cs",          false],
    [255, "utf8mb4",  "utf8mb4_0900_ai_ci",          true ],
    [256, "utf8mb4",  "utf8mb4_de_pb_0900_ai_ci",    false],
    [257, "utf8mb4",  "utf8mb4_is_0900_ai_ci",       false],
    [258, "utf8mb4",  "utf8mb4_lv_0900_ai_ci",       false],
    [259, "utf8mb4",  "utf8mb4_ro_0900_ai_ci",       false],
    [260, "utf8mb4",  "utf8mb4_sl_0900_ai_ci",       false],
    [261, "utf8mb4",  "utf8mb4_pl_0900_ai_ci",       false],
    [262, "utf8mb4",  "utf8mb4_et_0900_ai_ci",       false],
    [263, "utf8mb4",  "utf8mb4_es_0900_ai_ci",       false],
    [264, "utf8mb4",  "utf8mb4_sv_0900_ai_ci",       false],
    [265, "utf8mb4",  "utf8mb4_tr_0900_ai_ci",       false],
    [266, "utf8mb4",  "utf8mb4_cs_0900_ai_ci",       false],
    [267, "utf8mb4",  "utf8mb4_da_0900_ai_ci",       false],
    [268, "utf8mb4",  "utf8mb4_lt_0900_ai_ci",       false],
    [269, "utf8mb4",  "utf8mb4_sk_0900_ai_ci",       false],
    [270, "utf8mb4",  "utf8mb4_es_trad_0900_ai_ci",  false],
    [271, "utf8mb4",  "utf8mb4_la_0900_ai_ci",       false],
    [273, "utf8mb4",  "utf8mb4_eo_0900_ai_ci",       false],
    [274, "utf8mb4",  "utf8mb4_hu_0900_ai_ci",       false],
    [275, "utf8mb4",  "utf8mb4_hr_0900_ai_ci",       false],
    [277, "utf8mb4",  "utf8mb4_vi_0900_ai_ci",       false],
    [278, "utf8mb4",  "utf8mb4_0900_as_cs",          false],
    [279, "utf8mb4",  "utf8mb4_de_pb_0900_as_cs",    false],
    [280, "utf8mb4",  "utf8mb4_is_0900_as_cs",       false],
    [281, "utf8mb4",  "utf8mb4_lv_0900_as_cs",       false],
    [282, "utf8mb4",  "utf8mb4_ro_0900_as_cs",       false],
    [283, "utf8mb4",  "utf8mb4_sl_0900_as_cs",       false],
    [284, "utf8mb4",  "utf8mb4_pl_0900_as_cs",       false],
    [285, "utf8mb4",  "utf8mb4_et_0900_as_cs",       false],
    [286, "utf8mb4",  "utf8mb4_es_0900_as_cs",       false],
    [287, "utf8mb4",  "utf8mb4_sv_0900_as_cs",       false],
    [288, "utf8mb4",  "utf8mb4_tr_0900_as_cs",       false],
    [289, "utf8mb4",  "utf8mb4_cs_0900_as_cs",       false],
    [290, "utf8mb4",  "utf8mb4_da_0900_as_cs",       false],
    [291, "utf8mb4",  "utf8mb4_lt_0900_as_cs",       false],
    [292, "utf8mb4",  "utf8mb4_sk_0900_as_cs",       false],
    [293, "utf8mb4",  "utf8mb4_es_trad_0900_as_cs",  false],
    [294, "utf8mb4",  "utf8mb4_la_0900_as_cs",       false],
    [296, "utf8mb4",  "utf8mb4_eo_0900_as_cs",       false],
    [297, "utf8mb4",  "utf8mb4_hu_0900_as_cs",       false],
    [298, "utf8mb4",  "utf8mb4_hr_0900_as_cs",       false],
    [300, "utf8mb4",  "utf8mb4_vi_0900_as_cs",       false],
    [303, "utf8mb4",  "utf8mb4_ja_0900_as_cs",       false],
    [304, "utf8mb4",  "utf8mb4_ja_0900_as_cs_ks",    false],
    [305, "utf8mb4",  "utf8mb4_0900_as_ci",          false],
    [306, "utf8mb4",  "utf8mb4_ru_0900_ai_ci",       false],
    [307, "utf8mb4",  "utf8mb4_ru_0900_as_cs",       false],
    [308, "utf8mb4",  "utf8mb4_zh_0900_as_cs",       false],
    [309, "utf8mb4",  "utf8mb4_0900_bin",            false],
  ].freeze

  # @private
  NUMBER_TO_CHARSET = {}  # rubocop:disable Style/MutableConstant
  # @private
  COLLATION_TO_CHARSET = {}  # rubocop:disable Style/MutableConstant
  # @private
  CHARSET_DEFAULT = {}  # rubocop:disable Style/MutableConstant
  CHARSETS.each do |number, csname, clname, default|
    cs = Charset.new number, csname, clname
    NUMBER_TO_CHARSET[number] = cs
    COLLATION_TO_CHARSET[clname] = cs
    CHARSET_DEFAULT[csname] = cs if default
  end

  # @private
  BINARY_CHARSET_NUMBER = CHARSET_DEFAULT['binary'].number

  # @private
  # @param [Integer] n
  # @return [Mysql::Charset]
  def self.by_number(n)
    raise ClientError, "unknown charset number: #{n}" unless NUMBER_TO_CHARSET.key? n
    NUMBER_TO_CHARSET[n]
  end

  # @private
  # @param [String] str
  # @return [Mysql::Charset]
  def self.by_name(str)
    ret = COLLATION_TO_CHARSET[str] || CHARSET_DEFAULT[str]
    raise ClientError, "unknown charset: #{str}" unless ret
    ret
  end

  # @private
  # MySQL Charset -> Ruby's Encoding
  CHARSET_ENCODING = {
    "armscii8" => nil,
    "ascii"    => Encoding::US_ASCII,
    "big5"     => Encoding::Big5,
    "binary"   => Encoding::ASCII_8BIT,
    "cp1250"   => Encoding::Windows_1250,
    "cp1251"   => Encoding::Windows_1251,
    "cp1256"   => Encoding::Windows_1256,
    "cp1257"   => Encoding::Windows_1257,
    "cp850"    => Encoding::CP850,
    "cp852"    => Encoding::CP852,
    "cp866"    => Encoding::IBM866,
    "cp932"    => Encoding::Windows_31J,
    "dec8"     => nil,
    "eucjpms"  => Encoding::EucJP_ms,
    "euckr"    => Encoding::EUC_KR,
    "gb18030"  => Encoding::GB18030,
    "gb2312"   => Encoding::EUC_CN,
    "gbk"      => Encoding::GBK,
    "geostd8"  => nil,
    "greek"    => Encoding::ISO_8859_7,
    "hebrew"   => Encoding::ISO_8859_8,
    "hp8"      => nil,
    "keybcs2"  => nil,
    "koi8r"    => Encoding::KOI8_R,
    "koi8u"    => Encoding::KOI8_U,
    "latin1"   => Encoding::ISO_8859_1,
    "latin2"   => Encoding::ISO_8859_2,
    "latin5"   => Encoding::ISO_8859_9,
    "latin7"   => Encoding::ISO_8859_13,
    "macce"    => Encoding::MacCentEuro,
    "macroman" => Encoding::MacRoman,
    "sjis"     => Encoding::SHIFT_JIS,
    "swe7"     => nil,
    "tis620"   => Encoding::TIS_620,
    "ucs2"     => Encoding::UTF_16BE,
    "ujis"     => Encoding::EucJP_ms,
    "utf16"    => Encoding::UTF_16BE,
    "utf16le"  => Encoding::UTF_16LE,
    "utf32"    => Encoding::UTF_32BE,
    "utf8"     => Encoding::UTF_8,
    "utf8mb3"  => Encoding::UTF_8,
    "utf8mb4"  => Encoding::UTF_8,
  }.freeze

  # @private
  # @param [String] value
  # @return [String]
  def self.to_binary(value)
    value.force_encoding Encoding::ASCII_8BIT
  end

  # @private
  # convert raw to encoding and convert to Encoding.default_internal
  # @param [String] raw
  # @param [Encoding] encoding
  # @return [String] result
  def self.convert_encoding(raw, encoding)
    raw.force_encoding(encoding).encode
  end

  # @private
  # retrun corresponding Ruby encoding
  # @return [Encoding] encoding
  def encoding
    enc = CHARSET_ENCODING[@name.downcase]
    raise Mysql::ClientError, "unsupported charset: #{@name}" unless enc
    enc
  end

  # @private
  # convert encoding to corrensponding to MySQL charset
  # @param [String] value
  # @return [String]
  def convert(value)
    if value.is_a? String and value.encoding != Encoding::ASCII_8BIT
      value = value.encode encoding
    end
    value
  end
end

#nameString (readonly)

Returns charset name.

Returns:

  • (String)

    charset name



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# File 'lib/mysql/charset.rb', line 13

class Charset
  # @private
  # @param [Integer] number
  # @param [String] name
  # @param [String] csname
  def initialize(number, name, csname)
    @number, @name, @csname = number, name, csname
  end

  attr_reader :number, :name, :csname

  # [[charset_number, charset_name, collation_name, default], ...]
  # @private
  CHARSETS = [
    [  1, "big5",     "big5_chinese_ci",             true ],
    [  2, "latin2",   "latin2_czech_cs",             false],
    [  3, "dec8",     "dec8_swedish_ci",             true ],
    [  4, "cp850",    "cp850_general_ci",            true ],
    [  5, "latin1",   "latin1_german1_ci",           false],
    [  6, "hp8",      "hp8_english_ci",              true ],
    [  7, "koi8r",    "koi8r_general_ci",            true ],
    [  8, "latin1",   "latin1_swedish_ci",           true ],
    [  9, "latin2",   "latin2_general_ci",           true ],
    [ 10, "swe7",     "swe7_swedish_ci",             true ],
    [ 11, "ascii",    "ascii_general_ci",            true ],
    [ 12, "ujis",     "ujis_japanese_ci",            true ],
    [ 13, "sjis",     "sjis_japanese_ci",            true ],
    [ 14, "cp1251",   "cp1251_bulgarian_ci",         false],
    [ 15, "latin1",   "latin1_danish_ci",            false],
    [ 16, "hebrew",   "hebrew_general_ci",           true ],
    [ 17, "filename", "filename",                    true ],
    [ 18, "tis620",   "tis620_thai_ci",              true ],
    [ 19, "euckr",    "euckr_korean_ci",             true ],
    [ 20, "latin7",   "latin7_estonian_cs",          false],
    [ 21, "latin2",   "latin2_hungarian_ci",         false],
    [ 22, "koi8u",    "koi8u_general_ci",            true ],
    [ 23, "cp1251",   "cp1251_ukrainian_ci",         false],
    [ 24, "gb2312",   "gb2312_chinese_ci",           true ],
    [ 25, "greek",    "greek_general_ci",            true ],
    [ 26, "cp1250",   "cp1250_general_ci",           true ],
    [ 27, "latin2",   "latin2_croatian_ci",          false],
    [ 28, "gbk",      "gbk_chinese_ci",              true ],
    [ 29, "cp1257",   "cp1257_lithuanian_ci",        false],
    [ 30, "latin5",   "latin5_turkish_ci",           true ],
    [ 31, "latin1",   "latin1_german2_ci",           false],
    [ 32, "armscii8", "armscii8_general_ci",         true ],
    [ 33, "utf8",     "utf8_general_ci",             true ],
    [ 33, "utf8mb3",  "utf8mb3_general_ci",          true ],
    [ 34, "cp1250",   "cp1250_czech_cs",             false],
    [ 35, "ucs2",     "ucs2_general_ci",             true ],
    [ 36, "cp866",    "cp866_general_ci",            true ],
    [ 37, "keybcs2",  "keybcs2_general_ci",          true ],
    [ 38, "macce",    "macce_general_ci",            true ],
    [ 39, "macroman", "macroman_general_ci",         true ],
    [ 40, "cp852",    "cp852_general_ci",            true ],
    [ 41, "latin7",   "latin7_general_ci",           true ],
    [ 42, "latin7",   "latin7_general_cs",           false],
    [ 43, "macce",    "macce_bin",                   false],
    [ 44, "cp1250",   "cp1250_croatian_ci",          false],
    [ 45, "utf8mb4",  "utf8mb4_general_ci",          false],
    [ 46, "utf8mb4",  "utf8mb4_bin",                 false],
    [ 47, "latin1",   "latin1_bin",                  false],
    [ 48, "latin1",   "latin1_general_ci",           false],
    [ 49, "latin1",   "latin1_general_cs",           false],
    [ 50, "cp1251",   "cp1251_bin",                  false],
    [ 51, "cp1251",   "cp1251_general_ci",           true ],
    [ 52, "cp1251",   "cp1251_general_cs",           false],
    [ 53, "macroman", "macroman_bin",                false],
    [ 54, "utf16",    "utf16_general_ci",            true ],
    [ 55, "utf16",    "utf16_bin",                   false],
    [ 56, "utf16le",  "utf16le_general_ci",          true ],
    [ 57, "cp1256",   "cp1256_general_ci",           true ],
    [ 58, "cp1257",   "cp1257_bin",                  false],
    [ 59, "cp1257",   "cp1257_general_ci",           true ],
    [ 60, "utf32",    "utf32_general_ci",            true ],
    [ 61, "utf32",    "utf32_bin",                   false],
    [ 62, "utf16le",  "utf16le_bin",                 false],
    [ 63, "binary",   "binary",                      true ],
    [ 64, "armscii8", "armscii8_bin",                false],
    [ 65, "ascii",    "ascii_bin",                   false],
    [ 66, "cp1250",   "cp1250_bin",                  false],
    [ 67, "cp1256",   "cp1256_bin",                  false],
    [ 68, "cp866",    "cp866_bin",                   false],
    [ 69, "dec8",     "dec8_bin",                    false],
    [ 70, "greek",    "greek_bin",                   false],
    [ 71, "hebrew",   "hebrew_bin",                  false],
    [ 72, "hp8",      "hp8_bin",                     false],
    [ 73, "keybcs2",  "keybcs2_bin",                 false],
    [ 74, "koi8r",    "koi8r_bin",                   false],
    [ 75, "koi8u",    "koi8u_bin",                   false],
    [ 76, "utf8",     "utf8_tolower_ci",             false],
    [ 76, "utf8mb3",  "utf8mb3_tolower_ci",          false],
    [ 77, "latin2",   "latin2_bin",                  false],
    [ 78, "latin5",   "latin5_bin",                  false],
    [ 79, "latin7",   "latin7_bin",                  false],
    [ 80, "cp850",    "cp850_bin",                   false],
    [ 81, "cp852",    "cp852_bin",                   false],
    [ 82, "swe7",     "swe7_bin",                    false],
    [ 83, "utf8",     "utf8_bin",                    false],
    [ 83, "utf8mb3",  "utf8mb3_bin",                 false],
    [ 84, "big5",     "big5_bin",                    false],
    [ 85, "euckr",    "euckr_bin",                   false],
    [ 86, "gb2312",   "gb2312_bin",                  false],
    [ 87, "gbk",      "gbk_bin",                     false],
    [ 88, "sjis",     "sjis_bin",                    false],
    [ 89, "tis620",   "tis620_bin",                  false],
    [ 90, "ucs2",     "ucs2_bin",                    false],
    [ 91, "ujis",     "ujis_bin",                    false],
    [ 92, "geostd8",  "geostd8_general_ci",          true ],
    [ 93, "geostd8",  "geostd8_bin",                 false],
    [ 94, "latin1",   "latin1_spanish_ci",           false],
    [ 95, "cp932",    "cp932_japanese_ci",           true ],
    [ 96, "cp932",    "cp932_bin",                   false],
    [ 97, "eucjpms",  "eucjpms_japanese_ci",         true ],
    [ 98, "eucjpms",  "eucjpms_bin",                 false],
    [ 99, "cp1250",   "cp1250_polish_ci",            false],
    [101, "utf16",    "utf16_unicode_ci",            false],
    [102, "utf16",    "utf16_icelandic_ci",          false],
    [103, "utf16",    "utf16_latvian_ci",            false],
    [104, "utf16",    "utf16_romanian_ci",           false],
    [105, "utf16",    "utf16_slovenian_ci",          false],
    [106, "utf16",    "utf16_polish_ci",             false],
    [107, "utf16",    "utf16_estonian_ci",           false],
    [108, "utf16",    "utf16_spanish_ci",            false],
    [109, "utf16",    "utf16_swedish_ci",            false],
    [110, "utf16",    "utf16_turkish_ci",            false],
    [111, "utf16",    "utf16_czech_ci",              false],
    [112, "utf16",    "utf16_danish_ci",             false],
    [113, "utf16",    "utf16_lithuanian_ci",         false],
    [114, "utf16",    "utf16_slovak_ci",             false],
    [115, "utf16",    "utf16_spanish2_ci",           false],
    [116, "utf16",    "utf16_roman_ci",              false],
    [117, "utf16",    "utf16_persian_ci",            false],
    [118, "utf16",    "utf16_esperanto_ci",          false],
    [119, "utf16",    "utf16_hungarian_ci",          false],
    [120, "utf16",    "utf16_sinhala_ci",            false],
    [121, "utf16",    "utf16_german2_ci",            false],
    [122, "utf16",    "utf16_croatian_ci",           false],
    [123, "utf16",    "utf16_unicode_520_ci",        false],
    [124, "utf16",    "utf16_vietnamese_ci",         false],
    [128, "ucs2",     "ucs2_unicode_ci",             false],
    [129, "ucs2",     "ucs2_icelandic_ci",           false],
    [130, "ucs2",     "ucs2_latvian_ci",             false],
    [131, "ucs2",     "ucs2_romanian_ci",            false],
    [132, "ucs2",     "ucs2_slovenian_ci",           false],
    [133, "ucs2",     "ucs2_polish_ci",              false],
    [134, "ucs2",     "ucs2_estonian_ci",            false],
    [135, "ucs2",     "ucs2_spanish_ci",             false],
    [136, "ucs2",     "ucs2_swedish_ci",             false],
    [137, "ucs2",     "ucs2_turkish_ci",             false],
    [138, "ucs2",     "ucs2_czech_ci",               false],
    [139, "ucs2",     "ucs2_danish_ci",              false],
    [140, "ucs2",     "ucs2_lithuanian_ci",          false],
    [141, "ucs2",     "ucs2_slovak_ci",              false],
    [142, "ucs2",     "ucs2_spanish2_ci",            false],
    [143, "ucs2",     "ucs2_roman_ci",               false],
    [144, "ucs2",     "ucs2_persian_ci",             false],
    [145, "ucs2",     "ucs2_esperanto_ci",           false],
    [146, "ucs2",     "ucs2_hungarian_ci",           false],
    [147, "ucs2",     "ucs2_sinhala_ci",             false],
    [148, "ucs2",     "ucs2_german2_ci",             false],
    [149, "ucs2",     "ucs2_croatian_ci",            false],
    [150, "ucs2",     "ucs2_unicode_520_ci",         false],
    [151, "ucs2",     "ucs2_vietnamese_ci",          false],
    [159, "ucs2",     "ucs2_general_mysql500_ci",    false],
    [160, "utf32",    "utf32_unicode_ci",            false],
    [161, "utf32",    "utf32_icelandic_ci",          false],
    [162, "utf32",    "utf32_latvian_ci",            false],
    [163, "utf32",    "utf32_romanian_ci",           false],
    [164, "utf32",    "utf32_slovenian_ci",          false],
    [165, "utf32",    "utf32_polish_ci",             false],
    [166, "utf32",    "utf32_estonian_ci",           false],
    [167, "utf32",    "utf32_spanish_ci",            false],
    [168, "utf32",    "utf32_swedish_ci",            false],
    [169, "utf32",    "utf32_turkish_ci",            false],
    [170, "utf32",    "utf32_czech_ci",              false],
    [171, "utf32",    "utf32_danish_ci",             false],
    [172, "utf32",    "utf32_lithuanian_ci",         false],
    [173, "utf32",    "utf32_slovak_ci",             false],
    [174, "utf32",    "utf32_spanish2_ci",           false],
    [175, "utf32",    "utf32_roman_ci",              false],
    [176, "utf32",    "utf32_persian_ci",            false],
    [177, "utf32",    "utf32_esperanto_ci",          false],
    [178, "utf32",    "utf32_hungarian_ci",          false],
    [179, "utf32",    "utf32_sinhala_ci",            false],
    [180, "utf32",    "utf32_german2_ci",            false],
    [181, "utf32",    "utf32_croatian_ci",           false],
    [182, "utf32",    "utf32_unicode_520_ci",        false],
    [183, "utf32",    "utf32_vietnamese_ci",         false],
    [192, "utf8",     "utf8_unicode_ci",             false],
    [193, "utf8",     "utf8_icelandic_ci",           false],
    [194, "utf8",     "utf8_latvian_ci",             false],
    [195, "utf8",     "utf8_romanian_ci",            false],
    [196, "utf8",     "utf8_slovenian_ci",           false],
    [197, "utf8",     "utf8_polish_ci",              false],
    [198, "utf8",     "utf8_estonian_ci",            false],
    [199, "utf8",     "utf8_spanish_ci",             false],
    [200, "utf8",     "utf8_swedish_ci",             false],
    [201, "utf8",     "utf8_turkish_ci",             false],
    [202, "utf8",     "utf8_czech_ci",               false],
    [203, "utf8",     "utf8_danish_ci",              false],
    [204, "utf8",     "utf8_lithuanian_ci",          false],
    [205, "utf8",     "utf8_slovak_ci",              false],
    [206, "utf8",     "utf8_spanish2_ci",            false],
    [207, "utf8",     "utf8_roman_ci",               false],
    [208, "utf8",     "utf8_persian_ci",             false],
    [209, "utf8",     "utf8_esperanto_ci",           false],
    [210, "utf8",     "utf8_hungarian_ci",           false],
    [211, "utf8",     "utf8_sinhala_ci",             false],
    [212, "utf8",     "utf8_german2_ci",             false],
    [213, "utf8",     "utf8_croatian_ci",            false],
    [214, "utf8",     "utf8_unicode_520_ci",         false],
    [215, "utf8",     "utf8_vietnamese_ci",          false],
    [223, "utf8",     "utf8_general_mysql500_ci",    false],
    [192, "utf8mb3",  "utf8mb3_unicode_ci",          false],
    [193, "utf8mb3",  "utf8mb3_icelandic_ci",        false],
    [194, "utf8mb3",  "utf8mb3_latvian_ci",          false],
    [195, "utf8mb3",  "utf8mb3_romanian_ci",         false],
    [196, "utf8mb3",  "utf8mb3_slovenian_ci",        false],
    [197, "utf8mb3",  "utf8mb3_polish_ci",           false],
    [198, "utf8mb3",  "utf8mb3_estonian_ci",         false],
    [199, "utf8mb3",  "utf8mb3_spanish_ci",          false],
    [200, "utf8mb3",  "utf8mb3_swedish_ci",          false],
    [201, "utf8mb3",  "utf8mb3_turkish_ci",          false],
    [202, "utf8mb3",  "utf8mb3_czech_ci",            false],
    [203, "utf8mb3",  "utf8mb3_danish_ci",           false],
    [204, "utf8mb3",  "utf8mb3_lithuanian_ci",       false],
    [205, "utf8mb3",  "utf8mb3_slovak_ci",           false],
    [206, "utf8mb3",  "utf8mb3_spanish2_ci",         false],
    [207, "utf8mb3",  "utf8mb3_roman_ci",            false],
    [208, "utf8mb3",  "utf8mb3_persian_ci",          false],
    [209, "utf8mb3",  "utf8mb3_esperanto_ci",        false],
    [210, "utf8mb3",  "utf8mb3_hungarian_ci",        false],
    [211, "utf8mb3",  "utf8mb3_sinhala_ci",          false],
    [212, "utf8mb3",  "utf8mb3_german2_ci",          false],
    [213, "utf8mb3",  "utf8mb3_croatian_ci",         false],
    [214, "utf8mb3",  "utf8mb3_unicode_520_ci",      false],
    [215, "utf8mb3",  "utf8mb3_vietnamese_ci",       false],
    [223, "utf8mb3",  "utf8mb3_general_mysql500_ci", false],
    [224, "utf8mb4",  "utf8mb4_unicode_ci",          false],
    [225, "utf8mb4",  "utf8mb4_icelandic_ci",        false],
    [226, "utf8mb4",  "utf8mb4_latvian_ci",          false],
    [227, "utf8mb4",  "utf8mb4_romanian_ci",         false],
    [228, "utf8mb4",  "utf8mb4_slovenian_ci",        false],
    [229, "utf8mb4",  "utf8mb4_polish_ci",           false],
    [230, "utf8mb4",  "utf8mb4_estonian_ci",         false],
    [231, "utf8mb4",  "utf8mb4_spanish_ci",          false],
    [232, "utf8mb4",  "utf8mb4_swedish_ci",          false],
    [233, "utf8mb4",  "utf8mb4_turkish_ci",          false],
    [234, "utf8mb4",  "utf8mb4_czech_ci",            false],
    [235, "utf8mb4",  "utf8mb4_danish_ci",           false],
    [236, "utf8mb4",  "utf8mb4_lithuanian_ci",       false],
    [237, "utf8mb4",  "utf8mb4_slovak_ci",           false],
    [238, "utf8mb4",  "utf8mb4_spanish2_ci",         false],
    [239, "utf8mb4",  "utf8mb4_roman_ci",            false],
    [240, "utf8mb4",  "utf8mb4_persian_ci",          false],
    [241, "utf8mb4",  "utf8mb4_esperanto_ci",        false],
    [242, "utf8mb4",  "utf8mb4_hungarian_ci",        false],
    [243, "utf8mb4",  "utf8mb4_sinhala_ci",          false],
    [244, "utf8mb4",  "utf8mb4_german2_ci",          false],
    [245, "utf8mb4",  "utf8mb4_croatian_ci",         false],
    [246, "utf8mb4",  "utf8mb4_unicode_520_ci",      false],
    [247, "utf8mb4",  "utf8mb4_vietnamese_ci",       false],
    [248, "gb18030",  "gb18030_chinese_ci",          true ],
    [249, "gb18030",  "gb18030_bin",                 false],
    [250, "gb18030",  "gb18030_unicode_520_ci",      false],
    [254, "utf8",     "utf8mb3_general_cs",          false],
    [254, "utf8mb3",  "utf8mb3_general_cs",          false],
    [255, "utf8mb4",  "utf8mb4_0900_ai_ci",          true ],
    [256, "utf8mb4",  "utf8mb4_de_pb_0900_ai_ci",    false],
    [257, "utf8mb4",  "utf8mb4_is_0900_ai_ci",       false],
    [258, "utf8mb4",  "utf8mb4_lv_0900_ai_ci",       false],
    [259, "utf8mb4",  "utf8mb4_ro_0900_ai_ci",       false],
    [260, "utf8mb4",  "utf8mb4_sl_0900_ai_ci",       false],
    [261, "utf8mb4",  "utf8mb4_pl_0900_ai_ci",       false],
    [262, "utf8mb4",  "utf8mb4_et_0900_ai_ci",       false],
    [263, "utf8mb4",  "utf8mb4_es_0900_ai_ci",       false],
    [264, "utf8mb4",  "utf8mb4_sv_0900_ai_ci",       false],
    [265, "utf8mb4",  "utf8mb4_tr_0900_ai_ci",       false],
    [266, "utf8mb4",  "utf8mb4_cs_0900_ai_ci",       false],
    [267, "utf8mb4",  "utf8mb4_da_0900_ai_ci",       false],
    [268, "utf8mb4",  "utf8mb4_lt_0900_ai_ci",       false],
    [269, "utf8mb4",  "utf8mb4_sk_0900_ai_ci",       false],
    [270, "utf8mb4",  "utf8mb4_es_trad_0900_ai_ci",  false],
    [271, "utf8mb4",  "utf8mb4_la_0900_ai_ci",       false],
    [273, "utf8mb4",  "utf8mb4_eo_0900_ai_ci",       false],
    [274, "utf8mb4",  "utf8mb4_hu_0900_ai_ci",       false],
    [275, "utf8mb4",  "utf8mb4_hr_0900_ai_ci",       false],
    [277, "utf8mb4",  "utf8mb4_vi_0900_ai_ci",       false],
    [278, "utf8mb4",  "utf8mb4_0900_as_cs",          false],
    [279, "utf8mb4",  "utf8mb4_de_pb_0900_as_cs",    false],
    [280, "utf8mb4",  "utf8mb4_is_0900_as_cs",       false],
    [281, "utf8mb4",  "utf8mb4_lv_0900_as_cs",       false],
    [282, "utf8mb4",  "utf8mb4_ro_0900_as_cs",       false],
    [283, "utf8mb4",  "utf8mb4_sl_0900_as_cs",       false],
    [284, "utf8mb4",  "utf8mb4_pl_0900_as_cs",       false],
    [285, "utf8mb4",  "utf8mb4_et_0900_as_cs",       false],
    [286, "utf8mb4",  "utf8mb4_es_0900_as_cs",       false],
    [287, "utf8mb4",  "utf8mb4_sv_0900_as_cs",       false],
    [288, "utf8mb4",  "utf8mb4_tr_0900_as_cs",       false],
    [289, "utf8mb4",  "utf8mb4_cs_0900_as_cs",       false],
    [290, "utf8mb4",  "utf8mb4_da_0900_as_cs",       false],
    [291, "utf8mb4",  "utf8mb4_lt_0900_as_cs",       false],
    [292, "utf8mb4",  "utf8mb4_sk_0900_as_cs",       false],
    [293, "utf8mb4",  "utf8mb4_es_trad_0900_as_cs",  false],
    [294, "utf8mb4",  "utf8mb4_la_0900_as_cs",       false],
    [296, "utf8mb4",  "utf8mb4_eo_0900_as_cs",       false],
    [297, "utf8mb4",  "utf8mb4_hu_0900_as_cs",       false],
    [298, "utf8mb4",  "utf8mb4_hr_0900_as_cs",       false],
    [300, "utf8mb4",  "utf8mb4_vi_0900_as_cs",       false],
    [303, "utf8mb4",  "utf8mb4_ja_0900_as_cs",       false],
    [304, "utf8mb4",  "utf8mb4_ja_0900_as_cs_ks",    false],
    [305, "utf8mb4",  "utf8mb4_0900_as_ci",          false],
    [306, "utf8mb4",  "utf8mb4_ru_0900_ai_ci",       false],
    [307, "utf8mb4",  "utf8mb4_ru_0900_as_cs",       false],
    [308, "utf8mb4",  "utf8mb4_zh_0900_as_cs",       false],
    [309, "utf8mb4",  "utf8mb4_0900_bin",            false],
  ].freeze

  # @private
  NUMBER_TO_CHARSET = {}  # rubocop:disable Style/MutableConstant
  # @private
  COLLATION_TO_CHARSET = {}  # rubocop:disable Style/MutableConstant
  # @private
  CHARSET_DEFAULT = {}  # rubocop:disable Style/MutableConstant
  CHARSETS.each do |number, csname, clname, default|
    cs = Charset.new number, csname, clname
    NUMBER_TO_CHARSET[number] = cs
    COLLATION_TO_CHARSET[clname] = cs
    CHARSET_DEFAULT[csname] = cs if default
  end

  # @private
  BINARY_CHARSET_NUMBER = CHARSET_DEFAULT['binary'].number

  # @private
  # @param [Integer] n
  # @return [Mysql::Charset]
  def self.by_number(n)
    raise ClientError, "unknown charset number: #{n}" unless NUMBER_TO_CHARSET.key? n
    NUMBER_TO_CHARSET[n]
  end

  # @private
  # @param [String] str
  # @return [Mysql::Charset]
  def self.by_name(str)
    ret = COLLATION_TO_CHARSET[str] || CHARSET_DEFAULT[str]
    raise ClientError, "unknown charset: #{str}" unless ret
    ret
  end

  # @private
  # MySQL Charset -> Ruby's Encoding
  CHARSET_ENCODING = {
    "armscii8" => nil,
    "ascii"    => Encoding::US_ASCII,
    "big5"     => Encoding::Big5,
    "binary"   => Encoding::ASCII_8BIT,
    "cp1250"   => Encoding::Windows_1250,
    "cp1251"   => Encoding::Windows_1251,
    "cp1256"   => Encoding::Windows_1256,
    "cp1257"   => Encoding::Windows_1257,
    "cp850"    => Encoding::CP850,
    "cp852"    => Encoding::CP852,
    "cp866"    => Encoding::IBM866,
    "cp932"    => Encoding::Windows_31J,
    "dec8"     => nil,
    "eucjpms"  => Encoding::EucJP_ms,
    "euckr"    => Encoding::EUC_KR,
    "gb18030"  => Encoding::GB18030,
    "gb2312"   => Encoding::EUC_CN,
    "gbk"      => Encoding::GBK,
    "geostd8"  => nil,
    "greek"    => Encoding::ISO_8859_7,
    "hebrew"   => Encoding::ISO_8859_8,
    "hp8"      => nil,
    "keybcs2"  => nil,
    "koi8r"    => Encoding::KOI8_R,
    "koi8u"    => Encoding::KOI8_U,
    "latin1"   => Encoding::ISO_8859_1,
    "latin2"   => Encoding::ISO_8859_2,
    "latin5"   => Encoding::ISO_8859_9,
    "latin7"   => Encoding::ISO_8859_13,
    "macce"    => Encoding::MacCentEuro,
    "macroman" => Encoding::MacRoman,
    "sjis"     => Encoding::SHIFT_JIS,
    "swe7"     => nil,
    "tis620"   => Encoding::TIS_620,
    "ucs2"     => Encoding::UTF_16BE,
    "ujis"     => Encoding::EucJP_ms,
    "utf16"    => Encoding::UTF_16BE,
    "utf16le"  => Encoding::UTF_16LE,
    "utf32"    => Encoding::UTF_32BE,
    "utf8"     => Encoding::UTF_8,
    "utf8mb3"  => Encoding::UTF_8,
    "utf8mb4"  => Encoding::UTF_8,
  }.freeze

  # @private
  # @param [String] value
  # @return [String]
  def self.to_binary(value)
    value.force_encoding Encoding::ASCII_8BIT
  end

  # @private
  # convert raw to encoding and convert to Encoding.default_internal
  # @param [String] raw
  # @param [Encoding] encoding
  # @return [String] result
  def self.convert_encoding(raw, encoding)
    raw.force_encoding(encoding).encode
  end

  # @private
  # retrun corresponding Ruby encoding
  # @return [Encoding] encoding
  def encoding
    enc = CHARSET_ENCODING[@name.downcase]
    raise Mysql::ClientError, "unsupported charset: #{@name}" unless enc
    enc
  end

  # @private
  # convert encoding to corrensponding to MySQL charset
  # @param [String] value
  # @return [String]
  def convert(value)
    if value.is_a? String and value.encoding != Encoding::ASCII_8BIT
      value = value.encode encoding
    end
    value
  end
end

#numberObject (readonly)



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# File 'lib/mysql/charset.rb', line 13

class Charset
  # @private
  # @param [Integer] number
  # @param [String] name
  # @param [String] csname
  def initialize(number, name, csname)
    @number, @name, @csname = number, name, csname
  end

  attr_reader :number, :name, :csname

  # [[charset_number, charset_name, collation_name, default], ...]
  # @private
  CHARSETS = [
    [  1, "big5",     "big5_chinese_ci",             true ],
    [  2, "latin2",   "latin2_czech_cs",             false],
    [  3, "dec8",     "dec8_swedish_ci",             true ],
    [  4, "cp850",    "cp850_general_ci",            true ],
    [  5, "latin1",   "latin1_german1_ci",           false],
    [  6, "hp8",      "hp8_english_ci",              true ],
    [  7, "koi8r",    "koi8r_general_ci",            true ],
    [  8, "latin1",   "latin1_swedish_ci",           true ],
    [  9, "latin2",   "latin2_general_ci",           true ],
    [ 10, "swe7",     "swe7_swedish_ci",             true ],
    [ 11, "ascii",    "ascii_general_ci",            true ],
    [ 12, "ujis",     "ujis_japanese_ci",            true ],
    [ 13, "sjis",     "sjis_japanese_ci",            true ],
    [ 14, "cp1251",   "cp1251_bulgarian_ci",         false],
    [ 15, "latin1",   "latin1_danish_ci",            false],
    [ 16, "hebrew",   "hebrew_general_ci",           true ],
    [ 17, "filename", "filename",                    true ],
    [ 18, "tis620",   "tis620_thai_ci",              true ],
    [ 19, "euckr",    "euckr_korean_ci",             true ],
    [ 20, "latin7",   "latin7_estonian_cs",          false],
    [ 21, "latin2",   "latin2_hungarian_ci",         false],
    [ 22, "koi8u",    "koi8u_general_ci",            true ],
    [ 23, "cp1251",   "cp1251_ukrainian_ci",         false],
    [ 24, "gb2312",   "gb2312_chinese_ci",           true ],
    [ 25, "greek",    "greek_general_ci",            true ],
    [ 26, "cp1250",   "cp1250_general_ci",           true ],
    [ 27, "latin2",   "latin2_croatian_ci",          false],
    [ 28, "gbk",      "gbk_chinese_ci",              true ],
    [ 29, "cp1257",   "cp1257_lithuanian_ci",        false],
    [ 30, "latin5",   "latin5_turkish_ci",           true ],
    [ 31, "latin1",   "latin1_german2_ci",           false],
    [ 32, "armscii8", "armscii8_general_ci",         true ],
    [ 33, "utf8",     "utf8_general_ci",             true ],
    [ 33, "utf8mb3",  "utf8mb3_general_ci",          true ],
    [ 34, "cp1250",   "cp1250_czech_cs",             false],
    [ 35, "ucs2",     "ucs2_general_ci",             true ],
    [ 36, "cp866",    "cp866_general_ci",            true ],
    [ 37, "keybcs2",  "keybcs2_general_ci",          true ],
    [ 38, "macce",    "macce_general_ci",            true ],
    [ 39, "macroman", "macroman_general_ci",         true ],
    [ 40, "cp852",    "cp852_general_ci",            true ],
    [ 41, "latin7",   "latin7_general_ci",           true ],
    [ 42, "latin7",   "latin7_general_cs",           false],
    [ 43, "macce",    "macce_bin",                   false],
    [ 44, "cp1250",   "cp1250_croatian_ci",          false],
    [ 45, "utf8mb4",  "utf8mb4_general_ci",          false],
    [ 46, "utf8mb4",  "utf8mb4_bin",                 false],
    [ 47, "latin1",   "latin1_bin",                  false],
    [ 48, "latin1",   "latin1_general_ci",           false],
    [ 49, "latin1",   "latin1_general_cs",           false],
    [ 50, "cp1251",   "cp1251_bin",                  false],
    [ 51, "cp1251",   "cp1251_general_ci",           true ],
    [ 52, "cp1251",   "cp1251_general_cs",           false],
    [ 53, "macroman", "macroman_bin",                false],
    [ 54, "utf16",    "utf16_general_ci",            true ],
    [ 55, "utf16",    "utf16_bin",                   false],
    [ 56, "utf16le",  "utf16le_general_ci",          true ],
    [ 57, "cp1256",   "cp1256_general_ci",           true ],
    [ 58, "cp1257",   "cp1257_bin",                  false],
    [ 59, "cp1257",   "cp1257_general_ci",           true ],
    [ 60, "utf32",    "utf32_general_ci",            true ],
    [ 61, "utf32",    "utf32_bin",                   false],
    [ 62, "utf16le",  "utf16le_bin",                 false],
    [ 63, "binary",   "binary",                      true ],
    [ 64, "armscii8", "armscii8_bin",                false],
    [ 65, "ascii",    "ascii_bin",                   false],
    [ 66, "cp1250",   "cp1250_bin",                  false],
    [ 67, "cp1256",   "cp1256_bin",                  false],
    [ 68, "cp866",    "cp866_bin",                   false],
    [ 69, "dec8",     "dec8_bin",                    false],
    [ 70, "greek",    "greek_bin",                   false],
    [ 71, "hebrew",   "hebrew_bin",                  false],
    [ 72, "hp8",      "hp8_bin",                     false],
    [ 73, "keybcs2",  "keybcs2_bin",                 false],
    [ 74, "koi8r",    "koi8r_bin",                   false],
    [ 75, "koi8u",    "koi8u_bin",                   false],
    [ 76, "utf8",     "utf8_tolower_ci",             false],
    [ 76, "utf8mb3",  "utf8mb3_tolower_ci",          false],
    [ 77, "latin2",   "latin2_bin",                  false],
    [ 78, "latin5",   "latin5_bin",                  false],
    [ 79, "latin7",   "latin7_bin",                  false],
    [ 80, "cp850",    "cp850_bin",                   false],
    [ 81, "cp852",    "cp852_bin",                   false],
    [ 82, "swe7",     "swe7_bin",                    false],
    [ 83, "utf8",     "utf8_bin",                    false],
    [ 83, "utf8mb3",  "utf8mb3_bin",                 false],
    [ 84, "big5",     "big5_bin",                    false],
    [ 85, "euckr",    "euckr_bin",                   false],
    [ 86, "gb2312",   "gb2312_bin",                  false],
    [ 87, "gbk",      "gbk_bin",                     false],
    [ 88, "sjis",     "sjis_bin",                    false],
    [ 89, "tis620",   "tis620_bin",                  false],
    [ 90, "ucs2",     "ucs2_bin",                    false],
    [ 91, "ujis",     "ujis_bin",                    false],
    [ 92, "geostd8",  "geostd8_general_ci",          true ],
    [ 93, "geostd8",  "geostd8_bin",                 false],
    [ 94, "latin1",   "latin1_spanish_ci",           false],
    [ 95, "cp932",    "cp932_japanese_ci",           true ],
    [ 96, "cp932",    "cp932_bin",                   false],
    [ 97, "eucjpms",  "eucjpms_japanese_ci",         true ],
    [ 98, "eucjpms",  "eucjpms_bin",                 false],
    [ 99, "cp1250",   "cp1250_polish_ci",            false],
    [101, "utf16",    "utf16_unicode_ci",            false],
    [102, "utf16",    "utf16_icelandic_ci",          false],
    [103, "utf16",    "utf16_latvian_ci",            false],
    [104, "utf16",    "utf16_romanian_ci",           false],
    [105, "utf16",    "utf16_slovenian_ci",          false],
    [106, "utf16",    "utf16_polish_ci",             false],
    [107, "utf16",    "utf16_estonian_ci",           false],
    [108, "utf16",    "utf16_spanish_ci",            false],
    [109, "utf16",    "utf16_swedish_ci",            false],
    [110, "utf16",    "utf16_turkish_ci",            false],
    [111, "utf16",    "utf16_czech_ci",              false],
    [112, "utf16",    "utf16_danish_ci",             false],
    [113, "utf16",    "utf16_lithuanian_ci",         false],
    [114, "utf16",    "utf16_slovak_ci",             false],
    [115, "utf16",    "utf16_spanish2_ci",           false],
    [116, "utf16",    "utf16_roman_ci",              false],
    [117, "utf16",    "utf16_persian_ci",            false],
    [118, "utf16",    "utf16_esperanto_ci",          false],
    [119, "utf16",    "utf16_hungarian_ci",          false],
    [120, "utf16",    "utf16_sinhala_ci",            false],
    [121, "utf16",    "utf16_german2_ci",            false],
    [122, "utf16",    "utf16_croatian_ci",           false],
    [123, "utf16",    "utf16_unicode_520_ci",        false],
    [124, "utf16",    "utf16_vietnamese_ci",         false],
    [128, "ucs2",     "ucs2_unicode_ci",             false],
    [129, "ucs2",     "ucs2_icelandic_ci",           false],
    [130, "ucs2",     "ucs2_latvian_ci",             false],
    [131, "ucs2",     "ucs2_romanian_ci",            false],
    [132, "ucs2",     "ucs2_slovenian_ci",           false],
    [133, "ucs2",     "ucs2_polish_ci",              false],
    [134, "ucs2",     "ucs2_estonian_ci",            false],
    [135, "ucs2",     "ucs2_spanish_ci",             false],
    [136, "ucs2",     "ucs2_swedish_ci",             false],
    [137, "ucs2",     "ucs2_turkish_ci",             false],
    [138, "ucs2",     "ucs2_czech_ci",               false],
    [139, "ucs2",     "ucs2_danish_ci",              false],
    [140, "ucs2",     "ucs2_lithuanian_ci",          false],
    [141, "ucs2",     "ucs2_slovak_ci",              false],
    [142, "ucs2",     "ucs2_spanish2_ci",            false],
    [143, "ucs2",     "ucs2_roman_ci",               false],
    [144, "ucs2",     "ucs2_persian_ci",             false],
    [145, "ucs2",     "ucs2_esperanto_ci",           false],
    [146, "ucs2",     "ucs2_hungarian_ci",           false],
    [147, "ucs2",     "ucs2_sinhala_ci",             false],
    [148, "ucs2",     "ucs2_german2_ci",             false],
    [149, "ucs2",     "ucs2_croatian_ci",            false],
    [150, "ucs2",     "ucs2_unicode_520_ci",         false],
    [151, "ucs2",     "ucs2_vietnamese_ci",          false],
    [159, "ucs2",     "ucs2_general_mysql500_ci",    false],
    [160, "utf32",    "utf32_unicode_ci",            false],
    [161, "utf32",    "utf32_icelandic_ci",          false],
    [162, "utf32",    "utf32_latvian_ci",            false],
    [163, "utf32",    "utf32_romanian_ci",           false],
    [164, "utf32",    "utf32_slovenian_ci",          false],
    [165, "utf32",    "utf32_polish_ci",             false],
    [166, "utf32",    "utf32_estonian_ci",           false],
    [167, "utf32",    "utf32_spanish_ci",            false],
    [168, "utf32",    "utf32_swedish_ci",            false],
    [169, "utf32",    "utf32_turkish_ci",            false],
    [170, "utf32",    "utf32_czech_ci",              false],
    [171, "utf32",    "utf32_danish_ci",             false],
    [172, "utf32",    "utf32_lithuanian_ci",         false],
    [173, "utf32",    "utf32_slovak_ci",             false],
    [174, "utf32",    "utf32_spanish2_ci",           false],
    [175, "utf32",    "utf32_roman_ci",              false],
    [176, "utf32",    "utf32_persian_ci",            false],
    [177, "utf32",    "utf32_esperanto_ci",          false],
    [178, "utf32",    "utf32_hungarian_ci",          false],
    [179, "utf32",    "utf32_sinhala_ci",            false],
    [180, "utf32",    "utf32_german2_ci",            false],
    [181, "utf32",    "utf32_croatian_ci",           false],
    [182, "utf32",    "utf32_unicode_520_ci",        false],
    [183, "utf32",    "utf32_vietnamese_ci",         false],
    [192, "utf8",     "utf8_unicode_ci",             false],
    [193, "utf8",     "utf8_icelandic_ci",           false],
    [194, "utf8",     "utf8_latvian_ci",             false],
    [195, "utf8",     "utf8_romanian_ci",            false],
    [196, "utf8",     "utf8_slovenian_ci",           false],
    [197, "utf8",     "utf8_polish_ci",              false],
    [198, "utf8",     "utf8_estonian_ci",            false],
    [199, "utf8",     "utf8_spanish_ci",             false],
    [200, "utf8",     "utf8_swedish_ci",             false],
    [201, "utf8",     "utf8_turkish_ci",             false],
    [202, "utf8",     "utf8_czech_ci",               false],
    [203, "utf8",     "utf8_danish_ci",              false],
    [204, "utf8",     "utf8_lithuanian_ci",          false],
    [205, "utf8",     "utf8_slovak_ci",              false],
    [206, "utf8",     "utf8_spanish2_ci",            false],
    [207, "utf8",     "utf8_roman_ci",               false],
    [208, "utf8",     "utf8_persian_ci",             false],
    [209, "utf8",     "utf8_esperanto_ci",           false],
    [210, "utf8",     "utf8_hungarian_ci",           false],
    [211, "utf8",     "utf8_sinhala_ci",             false],
    [212, "utf8",     "utf8_german2_ci",             false],
    [213, "utf8",     "utf8_croatian_ci",            false],
    [214, "utf8",     "utf8_unicode_520_ci",         false],
    [215, "utf8",     "utf8_vietnamese_ci",          false],
    [223, "utf8",     "utf8_general_mysql500_ci",    false],
    [192, "utf8mb3",  "utf8mb3_unicode_ci",          false],
    [193, "utf8mb3",  "utf8mb3_icelandic_ci",        false],
    [194, "utf8mb3",  "utf8mb3_latvian_ci",          false],
    [195, "utf8mb3",  "utf8mb3_romanian_ci",         false],
    [196, "utf8mb3",  "utf8mb3_slovenian_ci",        false],
    [197, "utf8mb3",  "utf8mb3_polish_ci",           false],
    [198, "utf8mb3",  "utf8mb3_estonian_ci",         false],
    [199, "utf8mb3",  "utf8mb3_spanish_ci",          false],
    [200, "utf8mb3",  "utf8mb3_swedish_ci",          false],
    [201, "utf8mb3",  "utf8mb3_turkish_ci",          false],
    [202, "utf8mb3",  "utf8mb3_czech_ci",            false],
    [203, "utf8mb3",  "utf8mb3_danish_ci",           false],
    [204, "utf8mb3",  "utf8mb3_lithuanian_ci",       false],
    [205, "utf8mb3",  "utf8mb3_slovak_ci",           false],
    [206, "utf8mb3",  "utf8mb3_spanish2_ci",         false],
    [207, "utf8mb3",  "utf8mb3_roman_ci",            false],
    [208, "utf8mb3",  "utf8mb3_persian_ci",          false],
    [209, "utf8mb3",  "utf8mb3_esperanto_ci",        false],
    [210, "utf8mb3",  "utf8mb3_hungarian_ci",        false],
    [211, "utf8mb3",  "utf8mb3_sinhala_ci",          false],
    [212, "utf8mb3",  "utf8mb3_german2_ci",          false],
    [213, "utf8mb3",  "utf8mb3_croatian_ci",         false],
    [214, "utf8mb3",  "utf8mb3_unicode_520_ci",      false],
    [215, "utf8mb3",  "utf8mb3_vietnamese_ci",       false],
    [223, "utf8mb3",  "utf8mb3_general_mysql500_ci", false],
    [224, "utf8mb4",  "utf8mb4_unicode_ci",          false],
    [225, "utf8mb4",  "utf8mb4_icelandic_ci",        false],
    [226, "utf8mb4",  "utf8mb4_latvian_ci",          false],
    [227, "utf8mb4",  "utf8mb4_romanian_ci",         false],
    [228, "utf8mb4",  "utf8mb4_slovenian_ci",        false],
    [229, "utf8mb4",  "utf8mb4_polish_ci",           false],
    [230, "utf8mb4",  "utf8mb4_estonian_ci",         false],
    [231, "utf8mb4",  "utf8mb4_spanish_ci",          false],
    [232, "utf8mb4",  "utf8mb4_swedish_ci",          false],
    [233, "utf8mb4",  "utf8mb4_turkish_ci",          false],
    [234, "utf8mb4",  "utf8mb4_czech_ci",            false],
    [235, "utf8mb4",  "utf8mb4_danish_ci",           false],
    [236, "utf8mb4",  "utf8mb4_lithuanian_ci",       false],
    [237, "utf8mb4",  "utf8mb4_slovak_ci",           false],
    [238, "utf8mb4",  "utf8mb4_spanish2_ci",         false],
    [239, "utf8mb4",  "utf8mb4_roman_ci",            false],
    [240, "utf8mb4",  "utf8mb4_persian_ci",          false],
    [241, "utf8mb4",  "utf8mb4_esperanto_ci",        false],
    [242, "utf8mb4",  "utf8mb4_hungarian_ci",        false],
    [243, "utf8mb4",  "utf8mb4_sinhala_ci",          false],
    [244, "utf8mb4",  "utf8mb4_german2_ci",          false],
    [245, "utf8mb4",  "utf8mb4_croatian_ci",         false],
    [246, "utf8mb4",  "utf8mb4_unicode_520_ci",      false],
    [247, "utf8mb4",  "utf8mb4_vietnamese_ci",       false],
    [248, "gb18030",  "gb18030_chinese_ci",          true ],
    [249, "gb18030",  "gb18030_bin",                 false],
    [250, "gb18030",  "gb18030_unicode_520_ci",      false],
    [254, "utf8",     "utf8mb3_general_cs",          false],
    [254, "utf8mb3",  "utf8mb3_general_cs",          false],
    [255, "utf8mb4",  "utf8mb4_0900_ai_ci",          true ],
    [256, "utf8mb4",  "utf8mb4_de_pb_0900_ai_ci",    false],
    [257, "utf8mb4",  "utf8mb4_is_0900_ai_ci",       false],
    [258, "utf8mb4",  "utf8mb4_lv_0900_ai_ci",       false],
    [259, "utf8mb4",  "utf8mb4_ro_0900_ai_ci",       false],
    [260, "utf8mb4",  "utf8mb4_sl_0900_ai_ci",       false],
    [261, "utf8mb4",  "utf8mb4_pl_0900_ai_ci",       false],
    [262, "utf8mb4",  "utf8mb4_et_0900_ai_ci",       false],
    [263, "utf8mb4",  "utf8mb4_es_0900_ai_ci",       false],
    [264, "utf8mb4",  "utf8mb4_sv_0900_ai_ci",       false],
    [265, "utf8mb4",  "utf8mb4_tr_0900_ai_ci",       false],
    [266, "utf8mb4",  "utf8mb4_cs_0900_ai_ci",       false],
    [267, "utf8mb4",  "utf8mb4_da_0900_ai_ci",       false],
    [268, "utf8mb4",  "utf8mb4_lt_0900_ai_ci",       false],
    [269, "utf8mb4",  "utf8mb4_sk_0900_ai_ci",       false],
    [270, "utf8mb4",  "utf8mb4_es_trad_0900_ai_ci",  false],
    [271, "utf8mb4",  "utf8mb4_la_0900_ai_ci",       false],
    [273, "utf8mb4",  "utf8mb4_eo_0900_ai_ci",       false],
    [274, "utf8mb4",  "utf8mb4_hu_0900_ai_ci",       false],
    [275, "utf8mb4",  "utf8mb4_hr_0900_ai_ci",       false],
    [277, "utf8mb4",  "utf8mb4_vi_0900_ai_ci",       false],
    [278, "utf8mb4",  "utf8mb4_0900_as_cs",          false],
    [279, "utf8mb4",  "utf8mb4_de_pb_0900_as_cs",    false],
    [280, "utf8mb4",  "utf8mb4_is_0900_as_cs",       false],
    [281, "utf8mb4",  "utf8mb4_lv_0900_as_cs",       false],
    [282, "utf8mb4",  "utf8mb4_ro_0900_as_cs",       false],
    [283, "utf8mb4",  "utf8mb4_sl_0900_as_cs",       false],
    [284, "utf8mb4",  "utf8mb4_pl_0900_as_cs",       false],
    [285, "utf8mb4",  "utf8mb4_et_0900_as_cs",       false],
    [286, "utf8mb4",  "utf8mb4_es_0900_as_cs",       false],
    [287, "utf8mb4",  "utf8mb4_sv_0900_as_cs",       false],
    [288, "utf8mb4",  "utf8mb4_tr_0900_as_cs",       false],
    [289, "utf8mb4",  "utf8mb4_cs_0900_as_cs",       false],
    [290, "utf8mb4",  "utf8mb4_da_0900_as_cs",       false],
    [291, "utf8mb4",  "utf8mb4_lt_0900_as_cs",       false],
    [292, "utf8mb4",  "utf8mb4_sk_0900_as_cs",       false],
    [293, "utf8mb4",  "utf8mb4_es_trad_0900_as_cs",  false],
    [294, "utf8mb4",  "utf8mb4_la_0900_as_cs",       false],
    [296, "utf8mb4",  "utf8mb4_eo_0900_as_cs",       false],
    [297, "utf8mb4",  "utf8mb4_hu_0900_as_cs",       false],
    [298, "utf8mb4",  "utf8mb4_hr_0900_as_cs",       false],
    [300, "utf8mb4",  "utf8mb4_vi_0900_as_cs",       false],
    [303, "utf8mb4",  "utf8mb4_ja_0900_as_cs",       false],
    [304, "utf8mb4",  "utf8mb4_ja_0900_as_cs_ks",    false],
    [305, "utf8mb4",  "utf8mb4_0900_as_ci",          false],
    [306, "utf8mb4",  "utf8mb4_ru_0900_ai_ci",       false],
    [307, "utf8mb4",  "utf8mb4_ru_0900_as_cs",       false],
    [308, "utf8mb4",  "utf8mb4_zh_0900_as_cs",       false],
    [309, "utf8mb4",  "utf8mb4_0900_bin",            false],
  ].freeze

  # @private
  NUMBER_TO_CHARSET = {}  # rubocop:disable Style/MutableConstant
  # @private
  COLLATION_TO_CHARSET = {}  # rubocop:disable Style/MutableConstant
  # @private
  CHARSET_DEFAULT = {}  # rubocop:disable Style/MutableConstant
  CHARSETS.each do |number, csname, clname, default|
    cs = Charset.new number, csname, clname
    NUMBER_TO_CHARSET[number] = cs
    COLLATION_TO_CHARSET[clname] = cs
    CHARSET_DEFAULT[csname] = cs if default
  end

  # @private
  BINARY_CHARSET_NUMBER = CHARSET_DEFAULT['binary'].number

  # @private
  # @param [Integer] n
  # @return [Mysql::Charset]
  def self.by_number(n)
    raise ClientError, "unknown charset number: #{n}" unless NUMBER_TO_CHARSET.key? n
    NUMBER_TO_CHARSET[n]
  end

  # @private
  # @param [String] str
  # @return [Mysql::Charset]
  def self.by_name(str)
    ret = COLLATION_TO_CHARSET[str] || CHARSET_DEFAULT[str]
    raise ClientError, "unknown charset: #{str}" unless ret
    ret
  end

  # @private
  # MySQL Charset -> Ruby's Encoding
  CHARSET_ENCODING = {
    "armscii8" => nil,
    "ascii"    => Encoding::US_ASCII,
    "big5"     => Encoding::Big5,
    "binary"   => Encoding::ASCII_8BIT,
    "cp1250"   => Encoding::Windows_1250,
    "cp1251"   => Encoding::Windows_1251,
    "cp1256"   => Encoding::Windows_1256,
    "cp1257"   => Encoding::Windows_1257,
    "cp850"    => Encoding::CP850,
    "cp852"    => Encoding::CP852,
    "cp866"    => Encoding::IBM866,
    "cp932"    => Encoding::Windows_31J,
    "dec8"     => nil,
    "eucjpms"  => Encoding::EucJP_ms,
    "euckr"    => Encoding::EUC_KR,
    "gb18030"  => Encoding::GB18030,
    "gb2312"   => Encoding::EUC_CN,
    "gbk"      => Encoding::GBK,
    "geostd8"  => nil,
    "greek"    => Encoding::ISO_8859_7,
    "hebrew"   => Encoding::ISO_8859_8,
    "hp8"      => nil,
    "keybcs2"  => nil,
    "koi8r"    => Encoding::KOI8_R,
    "koi8u"    => Encoding::KOI8_U,
    "latin1"   => Encoding::ISO_8859_1,
    "latin2"   => Encoding::ISO_8859_2,
    "latin5"   => Encoding::ISO_8859_9,
    "latin7"   => Encoding::ISO_8859_13,
    "macce"    => Encoding::MacCentEuro,
    "macroman" => Encoding::MacRoman,
    "sjis"     => Encoding::SHIFT_JIS,
    "swe7"     => nil,
    "tis620"   => Encoding::TIS_620,
    "ucs2"     => Encoding::UTF_16BE,
    "ujis"     => Encoding::EucJP_ms,
    "utf16"    => Encoding::UTF_16BE,
    "utf16le"  => Encoding::UTF_16LE,
    "utf32"    => Encoding::UTF_32BE,
    "utf8"     => Encoding::UTF_8,
    "utf8mb3"  => Encoding::UTF_8,
    "utf8mb4"  => Encoding::UTF_8,
  }.freeze

  # @private
  # @param [String] value
  # @return [String]
  def self.to_binary(value)
    value.force_encoding Encoding::ASCII_8BIT
  end

  # @private
  # convert raw to encoding and convert to Encoding.default_internal
  # @param [String] raw
  # @param [Encoding] encoding
  # @return [String] result
  def self.convert_encoding(raw, encoding)
    raw.force_encoding(encoding).encode
  end

  # @private
  # retrun corresponding Ruby encoding
  # @return [Encoding] encoding
  def encoding
    enc = CHARSET_ENCODING[@name.downcase]
    raise Mysql::ClientError, "unsupported charset: #{@name}" unless enc
    enc
  end

  # @private
  # convert encoding to corrensponding to MySQL charset
  # @param [String] value
  # @return [String]
  def convert(value)
    if value.is_a? String and value.encoding != Encoding::ASCII_8BIT
      value = value.encode encoding
    end
    value
  end
end

Class Method Details

.by_name(str) ⇒ Mysql::Charset

Parameters:

  • str (String)

Returns:

Raises:



359
360
361
362
363
# File 'lib/mysql/charset.rb', line 359

def self.by_name(str)
  ret = COLLATION_TO_CHARSET[str] || CHARSET_DEFAULT[str]
  raise ClientError, "unknown charset: #{str}" unless ret
  ret
end

.by_number(n) ⇒ Mysql::Charset

Parameters:

  • n (Integer)

Returns:

Raises:



351
352
353
354
# File 'lib/mysql/charset.rb', line 351

def self.by_number(n)
  raise ClientError, "unknown charset number: #{n}" unless NUMBER_TO_CHARSET.key? n
  NUMBER_TO_CHARSET[n]
end

.convert_encoding(raw, encoding) ⇒ String

convert raw to encoding and convert to Encoding.default_internal

Parameters:

  • raw (String)
  • encoding (Encoding)

Returns:

  • (String)

    result



424
425
426
# File 'lib/mysql/charset.rb', line 424

def self.convert_encoding(raw, encoding)
  raw.force_encoding(encoding).encode
end

.to_binary(value) ⇒ String

Parameters:

  • value (String)

Returns:

  • (String)


415
416
417
# File 'lib/mysql/charset.rb', line 415

def self.to_binary(value)
  value.force_encoding Encoding::ASCII_8BIT
end

Instance Method Details

#convert(value) ⇒ String

convert encoding to corrensponding to MySQL charset

Parameters:

  • value (String)

Returns:

  • (String)


441
442
443
444
445
446
# File 'lib/mysql/charset.rb', line 441

def convert(value)
  if value.is_a? String and value.encoding != Encoding::ASCII_8BIT
    value = value.encode encoding
  end
  value
end

#encodingEncoding

retrun corresponding Ruby encoding

Returns:

  • (Encoding)

    encoding

Raises:



431
432
433
434
435
# File 'lib/mysql/charset.rb', line 431

def encoding
  enc = CHARSET_ENCODING[@name.downcase]
  raise Mysql::ClientError, "unsupported charset: #{@name}" unless enc
  enc
end