github.com/XiaoMi/Gaea@v1.2.5/mysql/charset.go (about) 1 // Copyright 2016 The kingshard Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 // not use this file except in compliance with the License. You may obtain 5 // a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations 13 // under the License. 14 15 package mysql 16 17 import ( 18 "errors" 19 "strings" 20 ) 21 22 // CollationID means collation type 23 type CollationID uint16 24 25 // CharsetIds maps charset name to its default collation ID. 26 var CharsetIds = map[string]CollationID{ 27 "big5": 1, 28 "dec8": 3, 29 "cp850": 4, 30 "hp8": 6, 31 "koi8r": 7, 32 "latin1": 8, 33 "latin2": 9, 34 "swe7": 10, 35 "ascii": 11, 36 "ujis": 12, 37 "sjis": 13, 38 "hebrew": 16, 39 "tis620": 18, 40 "euckr": 19, 41 "koi8u": 22, 42 "gb2312": 24, 43 "greek": 25, 44 "cp1250": 26, 45 "gbk": 28, 46 "latin5": 30, 47 "armscii8": 32, 48 "utf8": 33, 49 "ucs2": 35, 50 "cp866": 36, 51 "keybcs2": 37, 52 "macce": 38, 53 "macroman": 39, 54 "cp852": 40, 55 "latin7": 41, 56 "utf8mb4": 45, 57 "cp1251": 51, 58 "utf16": 54, 59 "utf16le": 56, 60 "cp1256": 57, 61 "cp1257": 59, 62 "utf32": 60, 63 "binary": 63, 64 "geostd8": 92, 65 "cp932": 95, 66 "eucjpms": 97, 67 "gb18030": 248, 68 } 69 70 // Charsets maps charset name to its default collation name. 71 var Charsets = map[string]string{ 72 "big5": "big5_chinese_ci", 73 "dec8": "dec8_swedish_ci", 74 "cp850": "cp850_general_ci", 75 "hp8": "hp8_english_ci", 76 "koi8r": "koi8r_general_ci", 77 "latin1": "latin1_swedish_ci", 78 "latin2": "latin2_general_ci", 79 "swe7": "swe7_swedish_ci", 80 "ascii": "ascii_general_ci", 81 "ujis": "ujis_japanese_ci", 82 "sjis": "sjis_japanese_ci", 83 "hebrew": "hebrew_general_ci", 84 "tis620": "tis620_thai_ci", 85 "euckr": "euckr_korean_ci", 86 "koi8u": "koi8u_general_ci", 87 "gb2312": "gb2312_chinese_ci", 88 "greek": "greek_general_ci", 89 "cp1250": "cp1250_general_ci", 90 "gbk": "gbk_chinese_ci", 91 "latin5": "latin5_turkish_ci", 92 "armscii8": "armscii8_general_ci", 93 "utf8": "utf8_general_ci", 94 "ucs2": "ucs2_general_ci", 95 "cp866": "cp866_general_ci", 96 "keybcs2": "keybcs2_general_ci", 97 "macce": "macce_general_ci", 98 "macroman": "macroman_general_ci", 99 "cp852": "cp852_general_ci", 100 "latin7": "latin7_general_ci", 101 "utf8mb4": "utf8mb4_general_ci", 102 "cp1251": "cp1251_general_ci", 103 "utf16": "utf16_general_ci", 104 "utf16le": "utf16le_general_ci", 105 "cp1256": "cp1256_general_ci", 106 "cp1257": "cp1257_general_ci", 107 "utf32": "utf32_general_ci", 108 "binary": "binary", 109 "geostd8": "geostd8_general_ci", 110 "cp932": "cp932_japanese_ci", 111 "eucjpms": "eucjpms_japanese_ci", 112 } 113 114 // Collations maps MySQL default collation ID to its name. 115 var Collations = map[CollationID]string{ 116 1: "big5_chinese_ci", 117 2: "latin2_czech_cs", 118 3: "dec8_swedish_ci", 119 4: "cp850_general_ci", 120 5: "latin1_german1_ci", 121 6: "hp8_english_ci", 122 7: "koi8r_general_ci", 123 8: "latin1_swedish_ci", 124 9: "latin2_general_ci", 125 10: "swe7_swedish_ci", 126 11: "ascii_general_ci", 127 12: "ujis_japanese_ci", 128 13: "sjis_japanese_ci", 129 14: "cp1251_bulgarian_ci", 130 15: "latin1_danish_ci", 131 16: "hebrew_general_ci", 132 18: "tis620_thai_ci", 133 19: "euckr_korean_ci", 134 20: "latin7_estonian_cs", 135 21: "latin2_hungarian_ci", 136 22: "koi8u_general_ci", 137 23: "cp1251_ukrainian_ci", 138 24: "gb2312_chinese_ci", 139 25: "greek_general_ci", 140 26: "cp1250_general_ci", 141 27: "latin2_croatian_ci", 142 28: "gbk_chinese_ci", 143 29: "cp1257_lithuanian_ci", 144 30: "latin5_turkish_ci", 145 31: "latin1_german2_ci", 146 32: "armscii8_general_ci", 147 33: "utf8_general_ci", 148 34: "cp1250_czech_cs", 149 35: "ucs2_general_ci", 150 36: "cp866_general_ci", 151 37: "keybcs2_general_ci", 152 38: "macce_general_ci", 153 39: "macroman_general_ci", 154 40: "cp852_general_ci", 155 41: "latin7_general_ci", 156 42: "latin7_general_cs", 157 43: "macce_bin", 158 44: "cp1250_croatian_ci", 159 45: "utf8mb4_general_ci", 160 46: "utf8mb4_bin", 161 47: "latin1_bin", 162 48: "latin1_general_ci", 163 49: "latin1_general_cs", 164 50: "cp1251_bin", 165 51: "cp1251_general_ci", 166 52: "cp1251_general_cs", 167 53: "macroman_bin", 168 54: "utf16_general_ci", 169 55: "utf16_bin", 170 56: "utf16le_general_ci", 171 57: "cp1256_general_ci", 172 58: "cp1257_bin", 173 59: "cp1257_general_ci", 174 60: "utf32_general_ci", 175 61: "utf32_bin", 176 62: "utf16le_bin", 177 63: "binary", 178 64: "armscii8_bin", 179 65: "ascii_bin", 180 66: "cp1250_bin", 181 67: "cp1256_bin", 182 68: "cp866_bin", 183 69: "dec8_bin", 184 70: "greek_bin", 185 71: "hebrew_bin", 186 72: "hp8_bin", 187 73: "keybcs2_bin", 188 74: "koi8r_bin", 189 75: "koi8u_bin", 190 76: "utf8_tolower_ci", 191 77: "latin2_bin", 192 78: "latin5_bin", 193 79: "latin7_bin", 194 80: "cp850_bin", 195 81: "cp852_bin", 196 82: "swe7_bin", 197 83: "utf8_bin", 198 84: "big5_bin", 199 85: "euckr_bin", 200 86: "gb2312_bin", 201 87: "gbk_bin", 202 88: "sjis_bin", 203 89: "tis620_bin", 204 90: "ucs2_bin", 205 91: "ujis_bin", 206 92: "geostd8_general_ci", 207 93: "geostd8_bin", 208 94: "latin1_spanish_ci", 209 95: "cp932_japanese_ci", 210 96: "cp932_bin", 211 97: "eucjpms_japanese_ci", 212 98: "eucjpms_bin", 213 99: "cp1250_polish_ci", 214 101: "utf16_unicode_ci", 215 102: "utf16_icelandic_ci", 216 103: "utf16_latvian_ci", 217 104: "utf16_romanian_ci", 218 105: "utf16_slovenian_ci", 219 106: "utf16_polish_ci", 220 107: "utf16_estonian_ci", 221 108: "utf16_spanish_ci", 222 109: "utf16_swedish_ci", 223 110: "utf16_turkish_ci", 224 111: "utf16_czech_ci", 225 112: "utf16_danish_ci", 226 113: "utf16_lithuanian_ci", 227 114: "utf16_slovak_ci", 228 115: "utf16_spanish2_ci", 229 116: "utf16_roman_ci", 230 117: "utf16_persian_ci", 231 118: "utf16_esperanto_ci", 232 119: "utf16_hungarian_ci", 233 120: "utf16_sinhala_ci", 234 121: "utf16_german2_ci", 235 122: "utf16_croatian_ci", 236 123: "utf16_unicode_520_ci", 237 124: "utf16_vietnamese_ci", 238 128: "ucs2_unicode_ci", 239 129: "ucs2_icelandic_ci", 240 130: "ucs2_latvian_ci", 241 131: "ucs2_romanian_ci", 242 132: "ucs2_slovenian_ci", 243 133: "ucs2_polish_ci", 244 134: "ucs2_estonian_ci", 245 135: "ucs2_spanish_ci", 246 136: "ucs2_swedish_ci", 247 137: "ucs2_turkish_ci", 248 138: "ucs2_czech_ci", 249 139: "ucs2_danish_ci", 250 140: "ucs2_lithuanian_ci", 251 141: "ucs2_slovak_ci", 252 142: "ucs2_spanish2_ci", 253 143: "ucs2_roman_ci", 254 144: "ucs2_persian_ci", 255 145: "ucs2_esperanto_ci", 256 146: "ucs2_hungarian_ci", 257 147: "ucs2_sinhala_ci", 258 148: "ucs2_german2_ci", 259 149: "ucs2_croatian_ci", 260 150: "ucs2_unicode_520_ci", 261 151: "ucs2_vietnamese_ci", 262 159: "ucs2_general_mysql500_ci", 263 160: "utf32_unicode_ci", 264 161: "utf32_icelandic_ci", 265 162: "utf32_latvian_ci", 266 163: "utf32_romanian_ci", 267 164: "utf32_slovenian_ci", 268 165: "utf32_polish_ci", 269 166: "utf32_estonian_ci", 270 167: "utf32_spanish_ci", 271 168: "utf32_swedish_ci", 272 169: "utf32_turkish_ci", 273 170: "utf32_czech_ci", 274 171: "utf32_danish_ci", 275 172: "utf32_lithuanian_ci", 276 173: "utf32_slovak_ci", 277 174: "utf32_spanish2_ci", 278 175: "utf32_roman_ci", 279 176: "utf32_persian_ci", 280 177: "utf32_esperanto_ci", 281 178: "utf32_hungarian_ci", 282 179: "utf32_sinhala_ci", 283 180: "utf32_german2_ci", 284 181: "utf32_croatian_ci", 285 182: "utf32_unicode_520_ci", 286 183: "utf32_vietnamese_ci", 287 192: "utf8_unicode_ci", 288 193: "utf8_icelandic_ci", 289 194: "utf8_latvian_ci", 290 195: "utf8_romanian_ci", 291 196: "utf8_slovenian_ci", 292 197: "utf8_polish_ci", 293 198: "utf8_estonian_ci", 294 199: "utf8_spanish_ci", 295 200: "utf8_swedish_ci", 296 201: "utf8_turkish_ci", 297 202: "utf8_czech_ci", 298 203: "utf8_danish_ci", 299 204: "utf8_lithuanian_ci", 300 205: "utf8_slovak_ci", 301 206: "utf8_spanish2_ci", 302 207: "utf8_roman_ci", 303 208: "utf8_persian_ci", 304 209: "utf8_esperanto_ci", 305 210: "utf8_hungarian_ci", 306 211: "utf8_sinhala_ci", 307 212: "utf8_german2_ci", 308 213: "utf8_croatian_ci", 309 214: "utf8_unicode_520_ci", 310 215: "utf8_vietnamese_ci", 311 223: "utf8_general_mysql500_ci", 312 224: "utf8mb4_unicode_ci", 313 225: "utf8mb4_icelandic_ci", 314 226: "utf8mb4_latvian_ci", 315 227: "utf8mb4_romanian_ci", 316 228: "utf8mb4_slovenian_ci", 317 229: "utf8mb4_polish_ci", 318 230: "utf8mb4_estonian_ci", 319 231: "utf8mb4_spanish_ci", 320 232: "utf8mb4_swedish_ci", 321 233: "utf8mb4_turkish_ci", 322 234: "utf8mb4_czech_ci", 323 235: "utf8mb4_danish_ci", 324 236: "utf8mb4_lithuanian_ci", 325 237: "utf8mb4_slovak_ci", 326 238: "utf8mb4_spanish2_ci", 327 239: "utf8mb4_roman_ci", 328 240: "utf8mb4_persian_ci", 329 241: "utf8mb4_esperanto_ci", 330 242: "utf8mb4_hungarian_ci", 331 243: "utf8mb4_sinhala_ci", 332 244: "utf8mb4_german2_ci", 333 245: "utf8mb4_croatian_ci", 334 246: "utf8mb4_unicode_520_ci", 335 247: "utf8mb4_vietnamese_ci", 336 337 248: "gb18030_chinese_ci", 338 249: "gb18030_bin", 339 250: "gb18030_unicode_520_ci", 340 255: "utf8mb4_0900_ai_ci", 341 256: "utf8mb4_de_pb_0900_ai_ci", 342 257: "utf8mb4_is_0900_ai_ci", 343 258: "utf8mb4_lv_0900_ai_ci", 344 259: "utf8mb4_ro_0900_ai_ci", 345 260: "utf8mb4_sl_0900_ai_ci", 346 261: "utf8mb4_pl_0900_ai_ci", 347 262: "utf8mb4_et_0900_ai_ci", 348 263: "utf8mb4_es_0900_ai_ci", 349 264: "utf8mb4_sv_0900_ai_ci", 350 265: "utf8mb4_tr_0900_ai_ci", 351 266: "utf8mb4_cs_0900_ai_ci", 352 267: "utf8mb4_da_0900_ai_ci", 353 268: "utf8mb4_lt_0900_ai_ci", 354 269: "utf8mb4_sk_0900_ai_ci", 355 270: "utf8mb4_es_trad_0900_ai_ci", 356 271: "utf8mb4_la_0900_ai_ci", 357 273: "utf8mb4_eo_0900_ai_ci", 358 274: "utf8mb4_hu_0900_ai_ci", 359 275: "utf8mb4_hr_0900_ai_ci", 360 277: "utf8mb4_vi_0900_ai_ci", 361 278: "utf8mb4_0900_as_cs", 362 279: "utf8mb4_de_pb_0900_as_cs", 363 280: "utf8mb4_is_0900_as_cs", 364 281: "utf8mb4_lv_0900_as_cs", 365 282: "utf8mb4_ro_0900_as_cs", 366 283: "utf8mb4_sl_0900_as_cs", 367 284: "utf8mb4_pl_0900_as_cs", 368 285: "utf8mb4_et_0900_as_cs", 369 286: "utf8mb4_es_0900_as_cs", 370 287: "utf8mb4_sv_0900_as_cs", 371 288: "utf8mb4_tr_0900_as_cs", 372 289: "utf8mb4_cs_0900_as_cs", 373 290: "utf8mb4_da_0900_as_cs", 374 291: "utf8mb4_lt_0900_as_cs", 375 292: "utf8mb4_sk_0900_as_cs", 376 293: "utf8mb4_es_trad_0900_as_cs", 377 294: "utf8mb4_la_0900_as_cs", 378 296: "utf8mb4_eo_0900_as_cs", 379 297: "utf8mb4_hu_0900_as_cs", 380 298: "utf8mb4_hr_0900_as_cs", 381 300: "utf8mb4_vi_0900_as_cs", 382 303: "utf8mb4_ja_0900_as_cs", 383 304: "utf8mb4_ja_0900_as_cs_ks", 384 305: "utf8mb4_0900_as_ci", 385 306: "utf8mb4_ru_0900_ai_ci", 386 307: "utf8mb4_ru_0900_as_cs", 387 308: "utf8mb4_zh_0900_as_cs", 388 309: "utf8mb4_0900_bin", 389 } 390 391 // CollationNames maps MySQL default collation name to its ID 392 var CollationNames = map[string]CollationID{ 393 "big5_chinese_ci": 1, 394 "latin2_czech_cs": 2, 395 "dec8_swedish_ci": 3, 396 "cp850_general_ci": 4, 397 "latin1_german1_ci": 5, 398 "hp8_english_ci": 6, 399 "koi8r_general_ci": 7, 400 "latin1_swedish_ci": 8, 401 "latin2_general_ci": 9, 402 "swe7_swedish_ci": 10, 403 "ascii_general_ci": 11, 404 "ujis_japanese_ci": 12, 405 "sjis_japanese_ci": 13, 406 "cp1251_bulgarian_ci": 14, 407 "latin1_danish_ci": 15, 408 "hebrew_general_ci": 16, 409 "tis620_thai_ci": 18, 410 "euckr_korean_ci": 19, 411 "latin7_estonian_cs": 20, 412 "latin2_hungarian_ci": 21, 413 "koi8u_general_ci": 22, 414 "cp1251_ukrainian_ci": 23, 415 "gb2312_chinese_ci": 24, 416 "greek_general_ci": 25, 417 "cp1250_general_ci": 26, 418 "latin2_croatian_ci": 27, 419 "gbk_chinese_ci": 28, 420 "cp1257_lithuanian_ci": 29, 421 "latin5_turkish_ci": 30, 422 "latin1_german2_ci": 31, 423 "armscii8_general_ci": 32, 424 "utf8_general_ci": 33, 425 "cp1250_czech_cs": 34, 426 "ucs2_general_ci": 35, 427 "cp866_general_ci": 36, 428 "keybcs2_general_ci": 37, 429 "macce_general_ci": 38, 430 "macroman_general_ci": 39, 431 "cp852_general_ci": 40, 432 "latin7_general_ci": 41, 433 "latin7_general_cs": 42, 434 "macce_bin": 43, 435 "cp1250_croatian_ci": 44, 436 "utf8mb4_general_ci": 45, 437 "utf8mb4_bin": 46, 438 "latin1_bin": 47, 439 "latin1_general_ci": 48, 440 "latin1_general_cs": 49, 441 "cp1251_bin": 50, 442 "cp1251_general_ci": 51, 443 "cp1251_general_cs": 52, 444 "macroman_bin": 53, 445 "utf16_general_ci": 54, 446 "utf16_bin": 55, 447 "utf16le_general_ci": 56, 448 "cp1256_general_ci": 57, 449 "cp1257_bin": 58, 450 "cp1257_general_ci": 59, 451 "utf32_general_ci": 60, 452 "utf32_bin": 61, 453 "utf16le_bin": 62, 454 "binary": 63, 455 "armscii8_bin": 64, 456 "ascii_bin": 65, 457 "cp1250_bin": 66, 458 "cp1256_bin": 67, 459 "cp866_bin": 68, 460 "dec8_bin": 69, 461 "greek_bin": 70, 462 "hebrew_bin": 71, 463 "hp8_bin": 72, 464 "keybcs2_bin": 73, 465 "koi8r_bin": 74, 466 "koi8u_bin": 75, 467 "latin2_bin": 77, 468 "latin5_bin": 78, 469 "latin7_bin": 79, 470 "cp850_bin": 80, 471 "cp852_bin": 81, 472 "swe7_bin": 82, 473 "utf8_bin": 83, 474 "big5_bin": 84, 475 "euckr_bin": 85, 476 "gb2312_bin": 86, 477 "gbk_bin": 87, 478 "sjis_bin": 88, 479 "tis620_bin": 89, 480 "ucs2_bin": 90, 481 "ujis_bin": 91, 482 "geostd8_general_ci": 92, 483 "geostd8_bin": 93, 484 "latin1_spanish_ci": 94, 485 "cp932_japanese_ci": 95, 486 "cp932_bin": 96, 487 "eucjpms_japanese_ci": 97, 488 "eucjpms_bin": 98, 489 "cp1250_polish_ci": 99, 490 "utf16_unicode_ci": 101, 491 "utf16_icelandic_ci": 102, 492 "utf16_latvian_ci": 103, 493 "utf16_romanian_ci": 104, 494 "utf16_slovenian_ci": 105, 495 "utf16_polish_ci": 106, 496 "utf16_estonian_ci": 107, 497 "utf16_spanish_ci": 108, 498 "utf16_swedish_ci": 109, 499 "utf16_turkish_ci": 110, 500 "utf16_czech_ci": 111, 501 "utf16_danish_ci": 112, 502 "utf16_lithuanian_ci": 113, 503 "utf16_slovak_ci": 114, 504 "utf16_spanish2_ci": 115, 505 "utf16_roman_ci": 116, 506 "utf16_persian_ci": 117, 507 "utf16_esperanto_ci": 118, 508 "utf16_hungarian_ci": 119, 509 "utf16_sinhala_ci": 120, 510 "utf16_german2_ci": 121, 511 "utf16_croatian_ci": 122, 512 "utf16_unicode_520_ci": 123, 513 "utf16_vietnamese_ci": 124, 514 "ucs2_unicode_ci": 128, 515 "ucs2_icelandic_ci": 129, 516 "ucs2_latvian_ci": 130, 517 "ucs2_romanian_ci": 131, 518 "ucs2_slovenian_ci": 132, 519 "ucs2_polish_ci": 133, 520 "ucs2_estonian_ci": 134, 521 "ucs2_spanish_ci": 135, 522 "ucs2_swedish_ci": 136, 523 "ucs2_turkish_ci": 137, 524 "ucs2_czech_ci": 138, 525 "ucs2_danish_ci": 139, 526 "ucs2_lithuanian_ci": 140, 527 "ucs2_slovak_ci": 141, 528 "ucs2_spanish2_ci": 142, 529 "ucs2_roman_ci": 143, 530 "ucs2_persian_ci": 144, 531 "ucs2_esperanto_ci": 145, 532 "ucs2_hungarian_ci": 146, 533 "ucs2_sinhala_ci": 147, 534 "ucs2_german2_ci": 148, 535 "ucs2_croatian_ci": 149, 536 "ucs2_unicode_520_ci": 150, 537 "ucs2_vietnamese_ci": 151, 538 "ucs2_general_mysql500_ci": 159, 539 "utf32_unicode_ci": 160, 540 "utf32_icelandic_ci": 161, 541 "utf32_latvian_ci": 162, 542 "utf32_romanian_ci": 163, 543 "utf32_slovenian_ci": 164, 544 "utf32_polish_ci": 165, 545 "utf32_estonian_ci": 166, 546 "utf32_spanish_ci": 167, 547 "utf32_swedish_ci": 168, 548 "utf32_turkish_ci": 169, 549 "utf32_czech_ci": 170, 550 "utf32_danish_ci": 171, 551 "utf32_lithuanian_ci": 172, 552 "utf32_slovak_ci": 173, 553 "utf32_spanish2_ci": 174, 554 "utf32_roman_ci": 175, 555 "utf32_persian_ci": 176, 556 "utf32_esperanto_ci": 177, 557 "utf32_hungarian_ci": 178, 558 "utf32_sinhala_ci": 179, 559 "utf32_german2_ci": 180, 560 "utf32_croatian_ci": 181, 561 "utf32_unicode_520_ci": 182, 562 "utf32_vietnamese_ci": 183, 563 "utf8_unicode_ci": 192, 564 "utf8_icelandic_ci": 193, 565 "utf8_latvian_ci": 194, 566 "utf8_romanian_ci": 195, 567 "utf8_slovenian_ci": 196, 568 "utf8_polish_ci": 197, 569 "utf8_estonian_ci": 198, 570 "utf8_spanish_ci": 199, 571 "utf8_swedish_ci": 200, 572 "utf8_turkish_ci": 201, 573 "utf8_czech_ci": 202, 574 "utf8_danish_ci": 203, 575 "utf8_lithuanian_ci": 204, 576 "utf8_slovak_ci": 205, 577 "utf8_spanish2_ci": 206, 578 "utf8_roman_ci": 207, 579 "utf8_persian_ci": 208, 580 "utf8_esperanto_ci": 209, 581 "utf8_hungarian_ci": 210, 582 "utf8_sinhala_ci": 211, 583 "utf8_german2_ci": 212, 584 "utf8_croatian_ci": 213, 585 "utf8_unicode_520_ci": 214, 586 "utf8_vietnamese_ci": 215, 587 "utf8_general_mysql500_ci": 223, 588 "utf8mb4_unicode_ci": 224, 589 "utf8mb4_icelandic_ci": 225, 590 "utf8mb4_latvian_ci": 226, 591 "utf8mb4_romanian_ci": 227, 592 "utf8mb4_slovenian_ci": 228, 593 "utf8mb4_polish_ci": 229, 594 "utf8mb4_estonian_ci": 230, 595 "utf8mb4_spanish_ci": 231, 596 "utf8mb4_swedish_ci": 232, 597 "utf8mb4_turkish_ci": 233, 598 "utf8mb4_czech_ci": 234, 599 "utf8mb4_danish_ci": 235, 600 "utf8mb4_lithuanian_ci": 236, 601 "utf8mb4_slovak_ci": 237, 602 "utf8mb4_spanish2_ci": 238, 603 "utf8mb4_roman_ci": 239, 604 "utf8mb4_persian_ci": 240, 605 "utf8mb4_esperanto_ci": 241, 606 "utf8mb4_hungarian_ci": 242, 607 "utf8mb4_sinhala_ci": 243, 608 "utf8mb4_german2_ci": 244, 609 "utf8mb4_croatian_ci": 245, 610 "utf8mb4_unicode_520_ci": 246, 611 "utf8mb4_vietnamese_ci": 247, 612 613 "gb18030_chinese_ci": 248, 614 "gb18030_bin": 249, 615 "gb18030_unicode_520_ci": 250, 616 "utf8mb4_0900_ai_ci": 255, 617 } 618 619 // CollationNameToCharset collation name to charset 620 var CollationNameToCharset = map[string]string{ 621 "big5_chinese_ci": "big5", 622 "latin2_czech_cs": "latin2", 623 "dec8_swedish_ci": "dec8", 624 "cp850_general_ci": "cp850", 625 "latin1_german1_ci": "latin1", 626 "hp8_english_ci": "hp8", 627 "koi8r_general_ci": "koi8r", 628 "latin1_swedish_ci": "latin1", 629 "latin2_general_ci": "latin2", 630 "swe7_swedish_ci": "swe7", 631 "ascii_general_ci": "ascii", 632 "ujis_japanese_ci": "ujis", 633 "sjis_japanese_ci": "sjis", 634 "cp1251_bulgarian_ci": "cp1251", 635 "latin1_danish_ci": "latin1", 636 "hebrew_general_ci": "hebrew", 637 "tis620_thai_ci": "tis620", 638 "euckr_korean_ci": "euckr", 639 "latin7_estonian_cs": "latin7", 640 "latin2_hungarian_ci": "latin2", 641 "koi8u_general_ci": "koi8u", 642 "cp1251_ukrainian_ci": "cp1251", 643 "gb2312_chinese_ci": "gb2312", 644 "greek_general_ci": "greek", 645 "cp1250_general_ci": "cp1250", 646 "latin2_croatian_ci": "latin2", 647 "gbk_chinese_ci": "gbk", 648 "cp1257_lithuanian_ci": "cp1257", 649 "latin5_turkish_ci": "latin5", 650 "latin1_german2_ci": "latin1", 651 "armscii8_general_ci": "armscii8", 652 "utf8_general_ci": "utf8", 653 "cp1250_czech_cs": "cp1250", 654 "ucs2_general_ci": "ucs2", 655 "cp866_general_ci": "cp866", 656 "keybcs2_general_ci": "keybcs2", 657 "macce_general_ci": "macce", 658 "macroman_general_ci": "macroman", 659 "cp852_general_ci": "cp852", 660 "latin7_general_ci": "latin7", 661 "latin7_general_cs": "latin7", 662 "macce_bin": "macce", 663 "cp1250_croatian_ci": "cp1250", 664 "utf8mb4_general_ci": "utf8mb4", 665 "utf8mb4_bin": "utf8mb4", 666 "latin1_bin": "latin1", 667 "latin1_general_ci": "latin1", 668 "latin1_general_cs": "latin1", 669 "cp1251_bin": "cp1251", 670 "cp1251_general_ci": "cp1251", 671 "cp1251_general_cs": "cp1251", 672 "macroman_bin": "macroman", 673 "utf16_general_ci": "utf16", 674 "utf16_bin": "utf16", 675 "utf16le_general_ci": "utf16le", 676 "cp1256_general_ci": "cp1256", 677 "cp1257_bin": "cp1257", 678 "cp1257_general_ci": "cp1257", 679 "utf32_general_ci": "utf32", 680 "utf32_bin": "utf32", 681 "utf16le_bin": "utf16le", 682 "binary": "binary", 683 "armscii8_bin": "armscii8", 684 "ascii_bin": "ascii", 685 "cp1250_bin": "cp1250", 686 "cp1256_bin": "cp1256", 687 "cp866_bin": "cp866", 688 "dec8_bin": "dec8", 689 "greek_bin": "greek", 690 "hebrew_bin": "hebrew", 691 "hp8_bin": "hp8", 692 "keybcs2_bin": "keybcs2", 693 "koi8r_bin": "koi8r", 694 "koi8u_bin": "koi8u", 695 "latin2_bin": "latin2", 696 "latin5_bin": "latin5", 697 "latin7_bin": "latin7", 698 "cp850_bin": "cp850", 699 "cp852_bin": "cp852", 700 "swe7_bin": "swe7", 701 "utf8_bin": "utf8", 702 "big5_bin": "big5", 703 "euckr_bin": "euckr", 704 "gb2312_bin": "gb2312", 705 "gbk_bin": "gbk", 706 "sjis_bin": "sjis", 707 "tis620_bin": "tis620", 708 "ucs2_bin": "ucs2", 709 "ujis_bin": "ujis", 710 "geostd8_general_ci": "geostd8", 711 "geostd8_bin": "geostd8", 712 "latin1_spanish_ci": "latin1", 713 "cp932_japanese_ci": "cp932", 714 "cp932_bin": "cp932", 715 "eucjpms_japanese_ci": "eucjpms", 716 "eucjpms_bin": "eucjpms", 717 "cp1250_polish_ci": "cp1250", 718 "utf16_unicode_ci": "utf16", 719 "utf16_icelandic_ci": "utf16", 720 "utf16_latvian_ci": "utf16", 721 "utf16_romanian_ci": "utf16", 722 "utf16_slovenian_ci": "utf16", 723 "utf16_polish_ci": "utf16", 724 "utf16_estonian_ci": "utf16", 725 "utf16_spanish_ci": "utf16", 726 "utf16_swedish_ci": "utf16", 727 "utf16_turkish_ci": "utf16", 728 "utf16_czech_ci": "utf16", 729 "utf16_danish_ci": "utf16", 730 "utf16_lithuanian_ci": "utf16", 731 "utf16_slovak_ci": "utf16", 732 "utf16_spanish2_ci": "utf16", 733 "utf16_roman_ci": "utf16", 734 "utf16_persian_ci": "utf16", 735 "utf16_esperanto_ci": "utf16", 736 "utf16_hungarian_ci": "utf16", 737 "utf16_sinhala_ci": "utf16", 738 "utf16_german2_ci": "utf16", 739 "utf16_croatian_ci": "utf16", 740 "utf16_unicode_520_ci": "utf16", 741 "utf16_vietnamese_ci": "utf16", 742 "ucs2_unicode_ci": "ucs2", 743 "ucs2_icelandic_ci": "ucs2", 744 "ucs2_latvian_ci": "ucs2", 745 "ucs2_romanian_ci": "ucs2", 746 "ucs2_slovenian_ci": "ucs2", 747 "ucs2_polish_ci": "ucs2", 748 "ucs2_estonian_ci": "ucs2", 749 "ucs2_spanish_ci": "ucs2", 750 "ucs2_swedish_ci": "ucs2", 751 "ucs2_turkish_ci": "ucs2", 752 "ucs2_czech_ci": "ucs2", 753 "ucs2_danish_ci": "ucs2", 754 "ucs2_lithuanian_ci": "ucs2", 755 "ucs2_slovak_ci": "ucs2", 756 "ucs2_spanish2_ci": "ucs2", 757 "ucs2_roman_ci": "ucs2", 758 "ucs2_persian_ci": "ucs2", 759 "ucs2_esperanto_ci": "ucs2", 760 "ucs2_hungarian_ci": "ucs2", 761 "ucs2_sinhala_ci": "ucs2", 762 "ucs2_german2_ci": "ucs2", 763 "ucs2_croatian_ci": "ucs2", 764 "ucs2_unicode_520_ci": "ucs2", 765 "ucs2_vietnamese_ci": "ucs2", 766 "ucs2_general_mysql500_ci": "ucs2", 767 "utf32_unicode_ci": "utf32", 768 "utf32_icelandic_ci": "utf32", 769 "utf32_latvian_ci": "utf32", 770 "utf32_romanian_ci": "utf32", 771 "utf32_slovenian_ci": "utf32", 772 "utf32_polish_ci": "utf32", 773 "utf32_estonian_ci": "utf32", 774 "utf32_spanish_ci": "utf32", 775 "utf32_swedish_ci": "utf32", 776 "utf32_turkish_ci": "utf32", 777 "utf32_czech_ci": "utf32", 778 "utf32_danish_ci": "utf32", 779 "utf32_lithuanian_ci": "utf32", 780 "utf32_slovak_ci": "utf32", 781 "utf32_spanish2_ci": "utf32", 782 "utf32_roman_ci": "utf32", 783 "utf32_persian_ci": "utf32", 784 "utf32_esperanto_ci": "utf32", 785 "utf32_hungarian_ci": "utf32", 786 "utf32_sinhala_ci": "utf32", 787 "utf32_german2_ci": "utf32", 788 "utf32_croatian_ci": "utf32", 789 "utf32_unicode_520_ci": "utf32", 790 "utf32_vietnamese_ci": "utf32", 791 "utf8_unicode_ci": "utf8", 792 "utf8_icelandic_ci": "utf8", 793 "utf8_latvian_ci": "utf8", 794 "utf8_romanian_ci": "utf8", 795 "utf8_slovenian_ci": "utf8", 796 "utf8_polish_ci": "utf8", 797 "utf8_estonian_ci": "utf8", 798 "utf8_spanish_ci": "utf8", 799 "utf8_swedish_ci": "utf8", 800 "utf8_turkish_ci": "utf8", 801 "utf8_czech_ci": "utf8", 802 "utf8_danish_ci": "utf8", 803 "utf8_lithuanian_ci": "utf8", 804 "utf8_slovak_ci": "utf8", 805 "utf8_spanish2_ci": "utf8", 806 "utf8_roman_ci": "utf8", 807 "utf8_persian_ci": "utf8", 808 "utf8_esperanto_ci": "utf8", 809 "utf8_hungarian_ci": "utf8", 810 "utf8_sinhala_ci": "utf8", 811 "utf8_german2_ci": "utf8", 812 "utf8_croatian_ci": "utf8", 813 "utf8_unicode_520_ci": "utf8", 814 "utf8_vietnamese_ci": "utf8", 815 "utf8_general_mysql500_ci": "utf8", 816 "utf8mb4_unicode_ci": "utf8mb4", 817 "utf8mb4_icelandic_ci": "utf8mb4", 818 "utf8mb4_latvian_ci": "utf8mb4", 819 "utf8mb4_romanian_ci": "utf8mb4", 820 "utf8mb4_slovenian_ci": "utf8mb4", 821 "utf8mb4_polish_ci": "utf8mb4", 822 "utf8mb4_estonian_ci": "utf8mb4", 823 "utf8mb4_spanish_ci": "utf8mb4", 824 "utf8mb4_swedish_ci": "utf8mb4", 825 "utf8mb4_turkish_ci": "utf8mb4", 826 "utf8mb4_czech_ci": "utf8mb4", 827 "utf8mb4_danish_ci": "utf8mb4", 828 "utf8mb4_lithuanian_ci": "utf8mb4", 829 "utf8mb4_slovak_ci": "utf8mb4", 830 "utf8mb4_spanish2_ci": "utf8mb4", 831 "utf8mb4_roman_ci": "utf8mb4", 832 "utf8mb4_persian_ci": "utf8mb4", 833 "utf8mb4_esperanto_ci": "utf8mb4", 834 "utf8mb4_hungarian_ci": "utf8mb4", 835 "utf8mb4_sinhala_ci": "utf8mb4", 836 "utf8mb4_german2_ci": "utf8mb4", 837 "utf8mb4_croatian_ci": "utf8mb4", 838 "utf8mb4_unicode_520_ci": "utf8mb4", 839 "utf8mb4_vietnamese_ci": "utf8mb4", 840 841 "gb18030_chinese_ci": "gb18030", 842 "gb18030_bin": "gb18030", 843 "gb18030_unicode_520_ci": "gb18030", 844 "utf8mb4_0900_ai_ci": "utf8mb4", 845 "utf8mb4_de_pb_0900_ai_ci": "utf8mb4", 846 "utf8mb4_is_0900_ai_ci": "utf8mb4", 847 "utf8mb4_lv_0900_ai_ci": "utf8mb4", 848 "utf8mb4_ro_0900_ai_ci": "utf8mb4", 849 "utf8mb4_sl_0900_ai_ci": "utf8mb4", 850 "utf8mb4_pl_0900_ai_ci": "utf8mb4", 851 "utf8mb4_et_0900_ai_ci": "utf8mb4", 852 "utf8mb4_es_0900_ai_ci": "utf8mb4", 853 "utf8mb4_sv_0900_ai_ci": "utf8mb4", 854 "utf8mb4_tr_0900_ai_ci": "utf8mb4", 855 "utf8mb4_cs_0900_ai_ci": "utf8mb4", 856 "utf8mb4_da_0900_ai_ci": "utf8mb4", 857 "utf8mb4_lt_0900_ai_ci": "utf8mb4", 858 "utf8mb4_sk_0900_ai_ci": "utf8mb4", 859 "utf8mb4_es_trad_0900_ai_ci": "utf8mb4", 860 "utf8mb4_la_0900_ai_ci": "utf8mb4", 861 "utf8mb4_eo_0900_ai_ci": "utf8mb4", 862 "utf8mb4_hu_0900_ai_ci": "utf8mb4", 863 "utf8mb4_hr_0900_ai_ci": "utf8mb4", 864 "utf8mb4_vi_0900_ai_ci": "utf8mb4", 865 "utf8mb4_0900_as_cs": "utf8mb4", 866 "utf8mb4_de_pb_0900_as_cs": "utf8mb4", 867 "utf8mb4_is_0900_as_cs": "utf8mb4", 868 "utf8mb4_lv_0900_as_cs": "utf8mb4", 869 "utf8mb4_ro_0900_as_cs": "utf8mb4", 870 "utf8mb4_sl_0900_as_cs": "utf8mb4", 871 "utf8mb4_pl_0900_as_cs": "utf8mb4", 872 "utf8mb4_et_0900_as_cs": "utf8mb4", 873 "utf8mb4_es_0900_as_cs": "utf8mb4", 874 "utf8mb4_sv_0900_as_cs": "utf8mb4", 875 "utf8mb4_tr_0900_as_cs": "utf8mb4", 876 "utf8mb4_cs_0900_as_cs": "utf8mb4", 877 "utf8mb4_da_0900_as_cs": "utf8mb4", 878 "utf8mb4_lt_0900_as_cs": "utf8mb4", 879 "utf8mb4_sk_0900_as_cs": "utf8mb4", 880 "utf8mb4_es_trad_0900_as_cs": "utf8mb4", 881 "utf8mb4_la_0900_as_cs": "utf8mb4", 882 "utf8mb4_eo_0900_as_cs": "utf8mb4", 883 "utf8mb4_hu_0900_as_cs": "utf8mb4", 884 "utf8mb4_hr_0900_as_cs": "utf8mb4", 885 "utf8mb4_vi_0900_as_cs": "utf8mb4", 886 "utf8mb4_ja_0900_as_cs": "utf8mb4", 887 "utf8mb4_ja_0900_as_cs_ks": "utf8mb4", 888 "utf8mb4_0900_as_ci": "utf8mb4", 889 "utf8mb4_ru_0900_ai_ci": "utf8mb4", 890 "utf8mb4_ru_0900_as_cs": "utf8mb4", 891 "utf8mb4_zh_0900_as_cs": "utf8mb4", 892 "utf8mb4_0900_bin": "utf8mb4", 893 } 894 895 // MySQL collation information. 896 const ( 897 // KeywordDefault means default 898 KeywordDefault = "default" 899 900 UTF8Charset = "utf8" 901 UTF8MB4Charset = "utf8mb4" 902 DefaultCharset = UTF8MB4Charset 903 // DefaultCollationID is utf8mb4_bin(46) 904 DefaultCollationID = 46 905 BinaryCollationID = 63 906 UTF8DefaultCollation = "utf8_bin" 907 UTF8MB4DefaultCollation = "utf8mb4_bin" 908 DefaultCollationName = UTF8MB4DefaultCollation 909 ) 910 911 // IsValidCharset check if is valid charset 912 func IsValidCharset(charset string) bool { 913 _, ok := CharsetIds[strings.ToLower(charset)] 914 return ok 915 } 916 917 // VerifyCharset verify charset 918 func VerifyCharset(charset, collation string) error { 919 if charset == "" && collation == "" { 920 return nil 921 } 922 if charset == "" && collation != "" { 923 return errors.New("cannot set collation without charset") 924 } 925 926 if _, ok := Charsets[charset]; !ok { 927 return errors.New("invalid charset") 928 } 929 930 if collation == "" { 931 return nil 932 } 933 relativeCharset, ok := CollationNameToCharset[collation] 934 if !ok { 935 return errors.New("invalid collation") 936 } 937 if charset != relativeCharset { 938 return errors.New("charset and collation does not match") 939 } 940 941 return nil 942 }