Exemple #1
0
        private void SetFieldEncoding()
        {
            Dictionary <int, string> charSets = driver.CharacterSets;
            DBVersion version = driver.Version;

            if (charSets == null || charSets.Count == 0 || 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]);
        }
Exemple #2
0
 /// <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("utf-8"));
     }
 }
Exemple #3
0
        public static CharacterSet GetCharacterSet(DBVersion version, string CharSetName)
        {
            CharacterSet cs = null;

            if (mapping.ContainsKey(CharSetName))
            {
                cs = (CharacterSet)mapping[CharSetName];
            }

            if (cs == null)
            {
                throw new MySqlException("Character set '" + CharSetName + "' is not supported by .Net Framework.");
            }
            return(cs);
        }