github.com/hellobchain/third_party@v0.0.0-20230331131523-deb0478a2e52/go-sql-driver/mysql/collations.go (about)

     1  // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
     2  //
     3  // Copyright 2014 The Go-MySQL-Driver Authors. All rights reserved.
     4  //
     5  // This Source Code Form is subject to the terms of the Mozilla Public
     6  // License, v. 2.0. If a copy of the MPL was not distributed with this file,
     7  // You can obtain one at http://mozilla.org/MPL/2.0/.
     8  
     9  package mysql
    10  
    11  const defaultCollation = "utf8mb4_general_ci"
    12  const binaryCollation = "binary"
    13  
    14  // A list of available collations mapped to the internal ID.
    15  // To update this map use the following MySQL query:
    16  //     SELECT COLLATION_NAME, ID FROM information_schema.COLLATIONS WHERE ID<256 ORDER BY ID
    17  //
    18  // Handshake packet have only 1 byte for collation_id.  So we can't use collations with ID > 255.
    19  //
    20  // ucs2, utf16, and utf32 can't be used for connection charset.
    21  // https://dev.mysql.com/doc/refman/5.7/en/charset-connection.html#charset-connection-impermissible-client-charset
    22  // They are commented out to reduce this map.
    23  var collations = map[string]byte{
    24  	"big5_chinese_ci":      1,
    25  	"latin2_czech_cs":      2,
    26  	"dec8_swedish_ci":      3,
    27  	"cp850_general_ci":     4,
    28  	"latin1_german1_ci":    5,
    29  	"hp8_english_ci":       6,
    30  	"koi8r_general_ci":     7,
    31  	"latin1_swedish_ci":    8,
    32  	"latin2_general_ci":    9,
    33  	"swe7_swedish_ci":      10,
    34  	"ascii_general_ci":     11,
    35  	"ujis_japanese_ci":     12,
    36  	"sjis_japanese_ci":     13,
    37  	"cp1251_bulgarian_ci":  14,
    38  	"latin1_danish_ci":     15,
    39  	"hebrew_general_ci":    16,
    40  	"tis620_thai_ci":       18,
    41  	"euckr_korean_ci":      19,
    42  	"latin7_estonian_cs":   20,
    43  	"latin2_hungarian_ci":  21,
    44  	"koi8u_general_ci":     22,
    45  	"cp1251_ukrainian_ci":  23,
    46  	"gb2312_chinese_ci":    24,
    47  	"greek_general_ci":     25,
    48  	"cp1250_general_ci":    26,
    49  	"latin2_croatian_ci":   27,
    50  	"gbk_chinese_ci":       28,
    51  	"cp1257_lithuanian_ci": 29,
    52  	"latin5_turkish_ci":    30,
    53  	"latin1_german2_ci":    31,
    54  	"armscii8_general_ci":  32,
    55  	"utf8_general_ci":      33,
    56  	"cp1250_czech_cs":      34,
    57  	//"ucs2_general_ci":          35,
    58  	"cp866_general_ci":    36,
    59  	"keybcs2_general_ci":  37,
    60  	"macce_general_ci":    38,
    61  	"macroman_general_ci": 39,
    62  	"cp852_general_ci":    40,
    63  	"latin7_general_ci":   41,
    64  	"latin7_general_cs":   42,
    65  	"macce_bin":           43,
    66  	"cp1250_croatian_ci":  44,
    67  	"utf8mb4_general_ci":  45,
    68  	"utf8mb4_bin":         46,
    69  	"latin1_bin":          47,
    70  	"latin1_general_ci":   48,
    71  	"latin1_general_cs":   49,
    72  	"cp1251_bin":          50,
    73  	"cp1251_general_ci":   51,
    74  	"cp1251_general_cs":   52,
    75  	"macroman_bin":        53,
    76  	//"utf16_general_ci":         54,
    77  	//"utf16_bin":                55,
    78  	//"utf16le_general_ci":       56,
    79  	"cp1256_general_ci": 57,
    80  	"cp1257_bin":        58,
    81  	"cp1257_general_ci": 59,
    82  	//"utf32_general_ci":         60,
    83  	//"utf32_bin":                61,
    84  	//"utf16le_bin":              62,
    85  	"binary":          63,
    86  	"armscii8_bin":    64,
    87  	"ascii_bin":       65,
    88  	"cp1250_bin":      66,
    89  	"cp1256_bin":      67,
    90  	"cp866_bin":       68,
    91  	"dec8_bin":        69,
    92  	"greek_bin":       70,
    93  	"hebrew_bin":      71,
    94  	"hp8_bin":         72,
    95  	"keybcs2_bin":     73,
    96  	"koi8r_bin":       74,
    97  	"koi8u_bin":       75,
    98  	"utf8_tolower_ci": 76,
    99  	"latin2_bin":      77,
   100  	"latin5_bin":      78,
   101  	"latin7_bin":      79,
   102  	"cp850_bin":       80,
   103  	"cp852_bin":       81,
   104  	"swe7_bin":        82,
   105  	"utf8_bin":        83,
   106  	"big5_bin":        84,
   107  	"euckr_bin":       85,
   108  	"gb2312_bin":      86,
   109  	"gbk_bin":         87,
   110  	"sjis_bin":        88,
   111  	"tis620_bin":      89,
   112  	//"ucs2_bin":                 90,
   113  	"ujis_bin":            91,
   114  	"geostd8_general_ci":  92,
   115  	"geostd8_bin":         93,
   116  	"latin1_spanish_ci":   94,
   117  	"cp932_japanese_ci":   95,
   118  	"cp932_bin":           96,
   119  	"eucjpms_japanese_ci": 97,
   120  	"eucjpms_bin":         98,
   121  	"cp1250_polish_ci":    99,
   122  	//"utf16_unicode_ci":         101,
   123  	//"utf16_icelandic_ci":       102,
   124  	//"utf16_latvian_ci":         103,
   125  	//"utf16_romanian_ci":        104,
   126  	//"utf16_slovenian_ci":       105,
   127  	//"utf16_polish_ci":          106,
   128  	//"utf16_estonian_ci":        107,
   129  	//"utf16_spanish_ci":         108,
   130  	//"utf16_swedish_ci":         109,
   131  	//"utf16_turkish_ci":         110,
   132  	//"utf16_czech_ci":           111,
   133  	//"utf16_danish_ci":          112,
   134  	//"utf16_lithuanian_ci":      113,
   135  	//"utf16_slovak_ci":          114,
   136  	//"utf16_spanish2_ci":        115,
   137  	//"utf16_roman_ci":           116,
   138  	//"utf16_persian_ci":         117,
   139  	//"utf16_esperanto_ci":       118,
   140  	//"utf16_hungarian_ci":       119,
   141  	//"utf16_sinhala_ci":         120,
   142  	//"utf16_german2_ci":         121,
   143  	//"utf16_croatian_ci":        122,
   144  	//"utf16_unicode_520_ci":     123,
   145  	//"utf16_vietnamese_ci":      124,
   146  	//"ucs2_unicode_ci":          128,
   147  	//"ucs2_icelandic_ci":        129,
   148  	//"ucs2_latvian_ci":          130,
   149  	//"ucs2_romanian_ci":         131,
   150  	//"ucs2_slovenian_ci":        132,
   151  	//"ucs2_polish_ci":           133,
   152  	//"ucs2_estonian_ci":         134,
   153  	//"ucs2_spanish_ci":          135,
   154  	//"ucs2_swedish_ci":          136,
   155  	//"ucs2_turkish_ci":          137,
   156  	//"ucs2_czech_ci":            138,
   157  	//"ucs2_danish_ci":           139,
   158  	//"ucs2_lithuanian_ci":       140,
   159  	//"ucs2_slovak_ci":           141,
   160  	//"ucs2_spanish2_ci":         142,
   161  	//"ucs2_roman_ci":            143,
   162  	//"ucs2_persian_ci":          144,
   163  	//"ucs2_esperanto_ci":        145,
   164  	//"ucs2_hungarian_ci":        146,
   165  	//"ucs2_sinhala_ci":          147,
   166  	//"ucs2_german2_ci":          148,
   167  	//"ucs2_croatian_ci":         149,
   168  	//"ucs2_unicode_520_ci":      150,
   169  	//"ucs2_vietnamese_ci":       151,
   170  	//"ucs2_general_mysql500_ci": 159,
   171  	//"utf32_unicode_ci":         160,
   172  	//"utf32_icelandic_ci":       161,
   173  	//"utf32_latvian_ci":         162,
   174  	//"utf32_romanian_ci":        163,
   175  	//"utf32_slovenian_ci":       164,
   176  	//"utf32_polish_ci":          165,
   177  	//"utf32_estonian_ci":        166,
   178  	//"utf32_spanish_ci":         167,
   179  	//"utf32_swedish_ci":         168,
   180  	//"utf32_turkish_ci":         169,
   181  	//"utf32_czech_ci":           170,
   182  	//"utf32_danish_ci":          171,
   183  	//"utf32_lithuanian_ci":      172,
   184  	//"utf32_slovak_ci":          173,
   185  	//"utf32_spanish2_ci":        174,
   186  	//"utf32_roman_ci":           175,
   187  	//"utf32_persian_ci":         176,
   188  	//"utf32_esperanto_ci":       177,
   189  	//"utf32_hungarian_ci":       178,
   190  	//"utf32_sinhala_ci":         179,
   191  	//"utf32_german2_ci":         180,
   192  	//"utf32_croatian_ci":        181,
   193  	//"utf32_unicode_520_ci":     182,
   194  	//"utf32_vietnamese_ci":      183,
   195  	"utf8_unicode_ci":          192,
   196  	"utf8_icelandic_ci":        193,
   197  	"utf8_latvian_ci":          194,
   198  	"utf8_romanian_ci":         195,
   199  	"utf8_slovenian_ci":        196,
   200  	"utf8_polish_ci":           197,
   201  	"utf8_estonian_ci":         198,
   202  	"utf8_spanish_ci":          199,
   203  	"utf8_swedish_ci":          200,
   204  	"utf8_turkish_ci":          201,
   205  	"utf8_czech_ci":            202,
   206  	"utf8_danish_ci":           203,
   207  	"utf8_lithuanian_ci":       204,
   208  	"utf8_slovak_ci":           205,
   209  	"utf8_spanish2_ci":         206,
   210  	"utf8_roman_ci":            207,
   211  	"utf8_persian_ci":          208,
   212  	"utf8_esperanto_ci":        209,
   213  	"utf8_hungarian_ci":        210,
   214  	"utf8_sinhala_ci":          211,
   215  	"utf8_german2_ci":          212,
   216  	"utf8_croatian_ci":         213,
   217  	"utf8_unicode_520_ci":      214,
   218  	"utf8_vietnamese_ci":       215,
   219  	"utf8_general_mysql500_ci": 223,
   220  	"utf8mb4_unicode_ci":       224,
   221  	"utf8mb4_icelandic_ci":     225,
   222  	"utf8mb4_latvian_ci":       226,
   223  	"utf8mb4_romanian_ci":      227,
   224  	"utf8mb4_slovenian_ci":     228,
   225  	"utf8mb4_polish_ci":        229,
   226  	"utf8mb4_estonian_ci":      230,
   227  	"utf8mb4_spanish_ci":       231,
   228  	"utf8mb4_swedish_ci":       232,
   229  	"utf8mb4_turkish_ci":       233,
   230  	"utf8mb4_czech_ci":         234,
   231  	"utf8mb4_danish_ci":        235,
   232  	"utf8mb4_lithuanian_ci":    236,
   233  	"utf8mb4_slovak_ci":        237,
   234  	"utf8mb4_spanish2_ci":      238,
   235  	"utf8mb4_roman_ci":         239,
   236  	"utf8mb4_persian_ci":       240,
   237  	"utf8mb4_esperanto_ci":     241,
   238  	"utf8mb4_hungarian_ci":     242,
   239  	"utf8mb4_sinhala_ci":       243,
   240  	"utf8mb4_german2_ci":       244,
   241  	"utf8mb4_croatian_ci":      245,
   242  	"utf8mb4_unicode_520_ci":   246,
   243  	"utf8mb4_vietnamese_ci":    247,
   244  	"gb18030_chinese_ci":       248,
   245  	"gb18030_bin":              249,
   246  	"gb18030_unicode_520_ci":   250,
   247  	"utf8mb4_0900_ai_ci":       255,
   248  }
   249  
   250  // A blacklist of collations which is unsafe to interpolate parameters.
   251  // These multibyte encodings may contains 0x5c (`\`) in their trailing bytes.
   252  var unsafeCollations = map[string]bool{
   253  	"big5_chinese_ci":        true,
   254  	"sjis_japanese_ci":       true,
   255  	"gbk_chinese_ci":         true,
   256  	"big5_bin":               true,
   257  	"gb2312_bin":             true,
   258  	"gbk_bin":                true,
   259  	"sjis_bin":               true,
   260  	"cp932_japanese_ci":      true,
   261  	"cp932_bin":              true,
   262  	"gb18030_chinese_ci":     true,
   263  	"gb18030_bin":            true,
   264  	"gb18030_unicode_520_ci": true,
   265  }