collations.go 8.5 KB

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