private void SetFieldEncoding() { Hashtable charSets = driver.CharacterSets; DBVersion version = driver.Version; if (charSets == null || CharacterSetIndex == -1) { return; } if (charSets[CharacterSetIndex] == null) { return; } CharacterSet cs = CharSetMap.GetCharacterSet(version, (string)charSets[CharacterSetIndex]); // starting with 6.0.4 utf8 has a maxlen of 4 instead of 3. The old // 3 byte utf8 is utf8mb3 if (cs.name.ToLower(System.Globalization.CultureInfo.InvariantCulture) == "utf-8" && version.Major >= 6) { MaxLength = 4; } else { MaxLength = cs.byteCount; } Encoding = CharSetMap.GetEncoding(version, (string)charSets[CharacterSetIndex]); }
public static CharacterSet GetCharacterSet(DBVersion version, string CharSetName) { CharacterSet cs = (CharacterSet)mapping[CharSetName]; if (cs == null) { throw new MySqlException("Character set '" + CharSetName + "' is not supported"); } return(cs); }
/// <summary> /// Returns the text encoding for a given MySQL character set name /// </summary> /// <param name="version">Version of the connection requesting the encoding</param> /// <param name="CharSetName">Name of the character set to get the encoding for</param> /// <returns>Encoding object for the given character set name</returns> public static Encoding GetEncoding(DBVersion version, string CharSetName) { try { CharacterSet cs = GetCharacterSet(version, CharSetName); return(Encoding.GetEncoding(cs.name)); } catch (NotSupportedException) { return(Encoding.GetEncoding(0)); } }