private void SetFieldEncoding() { Dictionary <int, string> characterSets = this.driver.CharacterSets; DBVersion version = this.driver.Version; if (characterSets == null || characterSets.Count == 0 || this.CharacterSetIndex == -1) { return; } if (characterSets[this.CharacterSetIndex] == null) { return; } CharacterSet characterSet = CharSetMap.GetCharacterSet(version, characterSets[this.CharacterSetIndex]); if (characterSet.name.ToLower(CultureInfo.InvariantCulture) == "utf-8" && version.Major >= 6) { this.MaxLength = 4; } else { this.MaxLength = characterSet.byteCount; } this.Encoding = CharSetMap.GetEncoding(version, characterSets[this.CharacterSetIndex]); }
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.ToLowerInvariant() == "utf-8" && version.Major >= 6) { MaxLength = 4; } else { MaxLength = cs.byteCount; } Encoding = CharSetMap.GetEncoding(version, (string)charSets[CharacterSetIndex]); }
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]); }
private MySqlField GetFieldMetaData41() { MySqlField field = new MySqlField(connection); stream.OpenPacket(); field.Encoding = encoding; field.CatalogName = stream.ReadLenString(); field.DatabaseName = stream.ReadLenString(); field.TableName = stream.ReadLenString(); field.RealTableName = stream.ReadLenString(); field.ColumnName = stream.ReadLenString(); field.OriginalColumnName = stream.ReadLenString(); stream.ReadByte(); field.CharacterSetIndex = stream.ReadInteger(2); field.ColumnLength = stream.ReadInteger(4); MySqlDbType type = (MySqlDbType)stream.ReadByte(); ColumnFlags colFlags; if ((Flags & ClientFlags.LONG_FLAG) != 0) { colFlags = (ColumnFlags)stream.ReadInteger(2); } else { colFlags = (ColumnFlags)stream.ReadByte(); } field.SetTypeAndFlags(type, colFlags); field.Scale = (byte)stream.ReadByte(); if (stream.HasMoreData) { stream.ReadInteger(2); // reserved } if (charSets != null && field.CharacterSetIndex != -1) { CharacterSet cs = CharSetMap.GetCharacterSet(Version, (string)charSets[field.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) { field.MaxLength = 4; } else { field.MaxLength = cs.byteCount; } field.Encoding = CharSetMap.GetEncoding(version, (string)charSets[field.CharacterSetIndex]); } return(field); }
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("utf-8")); } }
public static CharacterSet GetCharacterSet(DBVersion version, string CharSetName) { CharacterSet characterSet = null; if (CharSetMap.mapping.ContainsKey(CharSetName)) { characterSet = CharSetMap.mapping[CharSetName]; } if (characterSet == null) { throw new MySqlException("Character set '" + CharSetName + "' is not supported by .Net Framework."); } return(characterSet); }
public static Encoding GetEncoding(DBVersion version, string CharSetName) { Encoding encoding; try { CharacterSet characterSet = CharSetMap.GetCharacterSet(version, CharSetName); encoding = Encoding.GetEncoding(characterSet.name); } catch (NotSupportedException) { encoding = Encoding.GetEncoding("utf-8"); } return(encoding); }
private MySqlField GetFieldMetaData41() { MySqlField field = new MySqlField(this.connection); stream.OpenPacket(); field.Encoding = encoding; field.CatalogName = stream.ReadLenString(); field.DatabaseName = stream.ReadLenString(); field.TableName = stream.ReadLenString(); field.RealTableName = stream.ReadLenString(); field.ColumnName = stream.ReadLenString(); field.OriginalColumnName = stream.ReadLenString(); byte b = (byte)stream.ReadByte(); field.CharacterSetIndex = stream.ReadInteger(2); field.ColumnLength = stream.ReadInteger(4); MySqlDbType type = (MySqlDbType)stream.ReadByte(); ColumnFlags colFlags; if ((Flags & ClientFlags.LONG_FLAG) != 0) { colFlags = (ColumnFlags)stream.ReadInteger(2); } else { colFlags = (ColumnFlags)stream.ReadByte(); } field.SetTypeAndFlags(type, colFlags); field.Scale = (byte)stream.ReadByte(); if (stream.HasMoreData) { int reserved = stream.ReadInteger(2); // reserved } if (charSets != null) { CharacterSet cs = CharSetMap.GetChararcterSet(this.Version, (string)charSets[field.CharacterSetIndex]); field.MaxLength = cs.byteCount; field.Encoding = CharSetMap.GetEncoding(this.version, (string)charSets[field.CharacterSetIndex]); } return(field); }
public static CharacterSet GetCharacterSet(DBVersion version, string charSetName) { if (charSetName == null) { throw new ArgumentNullException("CharSetName is null"); } CharacterSet cs = null; if (_mapping.ContainsKey(charSetName)) { cs = _mapping[charSetName]; } if (cs == null) { throw new NotSupportedException("Character set '" + charSetName + "' is not supported by .Net Framework."); } return(cs); }
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]); MaxLength = cs.byteCount; Encoding = CharSetMap.GetEncoding(version, (string)charSets[CharacterSetIndex]); }
/// <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); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); return(Encoding.GetEncoding(cs.name)); } catch (ArgumentException) { return(Encoding.GetEncoding("utf-8")); } catch (NotSupportedException) { return(Encoding.GetEncoding("utf-8")); } }
private MySqlField GetFieldMetaData41() { MySqlField mySqlField = new MySqlField(base.Version); this.reader.OpenPacket(); mySqlField.Encoding = this.encoding; mySqlField.CatalogName = this.reader.ReadLenString(); mySqlField.DatabaseName = this.reader.ReadLenString(); mySqlField.TableName = this.reader.ReadLenString(); mySqlField.RealTableName = this.reader.ReadLenString(); mySqlField.ColumnName = this.reader.ReadLenString(); mySqlField.OriginalColumnName = this.reader.ReadLenString(); this.reader.ReadByte(); mySqlField.CharacterSetIndex = this.reader.ReadInteger(2); mySqlField.ColumnLength = this.reader.ReadInteger(4); MySqlDbType type = (MySqlDbType)this.reader.ReadByte(); ColumnFlags flags; if ((this.Flags & ClientFlags.LONG_FLAG) != (ClientFlags)0) { flags = (ColumnFlags)this.reader.ReadInteger(2); } else { flags = (ColumnFlags)this.reader.ReadByte(); } mySqlField.SetTypeAndFlags(type, flags); mySqlField.Scale = (byte)this.reader.ReadByte(); if (this.charSets != null) { CharacterSet chararcterSet = CharSetMap.GetChararcterSet(base.Version, (string)this.charSets[mySqlField.CharacterSetIndex]); mySqlField.MaxLength = chararcterSet.byteCount; mySqlField.Encoding = CharSetMap.GetEncoding(this.version, (string)this.charSets[mySqlField.CharacterSetIndex]); } return(mySqlField); }