public virtual void Configure(MySqlConnection connection) { bool firstConfigure = false; // if we have not already configured our server variables // then do so now if (serverProps == null) { firstConfigure = true; // if we are in a pool and the user has said it's ok to cache the // properties, then grab it from the pool if (Pool != null && Settings.CacheServerProperties) { if (Pool.ServerProperties == null) { Pool.ServerProperties = LoadServerProperties(connection); } serverProps = Pool.ServerProperties; } else { serverProps = LoadServerProperties(connection); } LoadCharacterSets(connection); } #if AUTHENTICATED string licenseType = serverProps["license"]; if (licenseType == null || licenseType.Length == 0 || licenseType != "commercial") { throw new MySqlException("This client library licensed only for use with commercially-licensed MySQL servers."); } #endif // if the user has indicated that we are not to reset // the connection and this is not our first time through, // then we are done. if (!Settings.ConnectionReset && !firstConfigure) { return; } string charSet = connectionString.CharacterSet; if (charSet == null || charSet.Length == 0) { if (serverCharSetIndex >= 0) { charSet = (string)charSets[serverCharSetIndex]; } else { charSet = serverCharSet; } } // now tell the server which character set we will send queries in and which charset we // want results in MySqlCommand charSetCmd = new MySqlCommand("SET character_set_results=NULL", connection); charSetCmd.InternallyCreated = true; object clientCharSet = serverProps["character_set_client"]; object connCharSet = serverProps["character_set_connection"]; if ((clientCharSet != null && clientCharSet.ToString() != charSet) || (connCharSet != null && connCharSet.ToString() != charSet)) { MySqlCommand setNamesCmd = new MySqlCommand("SET NAMES " + charSet, connection); setNamesCmd.InternallyCreated = true; setNamesCmd.ExecuteNonQuery(); } charSetCmd.ExecuteNonQuery(); if (charSet != null) { Encoding = CharSetMap.GetEncoding(Version, charSet); } else { Encoding = CharSetMap.GetEncoding(Version, "latin1"); } handler.Configure(); }
/// <summary> /// Parses out the elements of a procedure parameter data type. /// </summary> private string ParseDataType(DataRow row, SqlTokenizer tokenizer) { StringBuilder dtd = new StringBuilder( tokenizer.NextToken().ToUpper(CultureInfo.InvariantCulture)); row["DATA_TYPE"] = dtd.ToString(); string type = row["DATA_TYPE"].ToString(); string token = tokenizer.NextToken(); if (tokenizer.IsSize) { dtd.AppendFormat(CultureInfo.InvariantCulture, "({0})", token); if (type != "ENUM" && type != "SET") { ParseDataTypeSize(row, token); } token = tokenizer.NextToken(); } else { dtd.Append(GetDataTypeDefaults(type, row)); } while (token != ")" && token != "," && String.Compare(token, "begin", true) != 0) { if (String.Compare(token, "CHARACTER", true) == 0 || String.Compare(token, "BINARY", true) == 0) { } // we don't need to do anything with this else if (String.Compare(token, "SET", true) == 0 || String.Compare(token, "CHARSET", true) == 0) { row["CHARACTER_SET_NAME"] = tokenizer.NextToken(); } else if (String.Compare(token, "ASCII", true) == 0) { row["CHARACTER_SET_NAME"] = "latin1"; } else if (String.Compare(token, "UNICODE", true) == 0) { row["CHARACTER_SET_NAME"] = "ucs2"; } else if (String.Compare(token, "COLLATE", true) == 0) { row["COLLATION_NAME"] = tokenizer.NextToken(); } else { dtd.AppendFormat(CultureInfo.InvariantCulture, " {0}", token); } token = tokenizer.NextToken(); } if (dtd.Length > 0) { row["DTD_IDENTIFIER"] = dtd.ToString(); } // now default the collation if one wasn't given if (row["COLLATION_NAME"].ToString().Length == 0) { row["COLLATION_NAME"] = CharSetMap.GetDefaultCollation( row["CHARACTER_SET_NAME"].ToString(), connection); } // now set the octet length if (row["CHARACTER_MAXIMUM_LENGTH"] != DBNull.Value) { row["CHARACTER_OCTET_LENGTH"] = CharSetMap.GetMaxLength(row["CHARACTER_SET_NAME"].ToString(), connection) * (int)row["CHARACTER_MAXIMUM_LENGTH"]; } return(token); }
/// <summary> /// Parses out the elements of a procedure parameter data type. /// </summary> private string ParseDataType(MySqlSchemaRow row, MySqlTokenizer tokenizer) { StringBuilder dtd = new StringBuilder( tokenizer.NextToken().ToUpper()); row["DATA_TYPE"] = dtd.ToString(); string type = row["DATA_TYPE"].ToString(); string token = tokenizer.NextToken(); if (token == "(") { token = tokenizer.ReadParenthesis(); dtd.AppendFormat(CultureInfo.InvariantCulture, "{0}", token); if (type != "ENUM" && type != "SET") { ParseDataTypeSize(row, token); } token = tokenizer.NextToken(); } else { dtd.Append(GetDataTypeDefaults(type, row)); } while (token != ")" && token != "," && String.Compare(token, "begin", StringComparison.OrdinalIgnoreCase) != 0 && String.Compare(token, "return", StringComparison.OrdinalIgnoreCase) != 0) { if (String.Compare(token, "CHARACTER", StringComparison.OrdinalIgnoreCase) == 0 || String.Compare(token, "BINARY", StringComparison.OrdinalIgnoreCase) == 0) { } // we don't need to do anything with this else if (String.Compare(token, "SET", StringComparison.OrdinalIgnoreCase) == 0 || String.Compare(token, "CHARSET", StringComparison.OrdinalIgnoreCase) == 0) { row["CHARACTER_SET_NAME"] = tokenizer.NextToken(); } else if (String.Compare(token, "ASCII", StringComparison.OrdinalIgnoreCase) == 0) { row["CHARACTER_SET_NAME"] = "latin1"; } else if (String.Compare(token, "UNICODE", StringComparison.OrdinalIgnoreCase) == 0) { row["CHARACTER_SET_NAME"] = "ucs2"; } else if (String.Compare(token, "COLLATE", StringComparison.OrdinalIgnoreCase) == 0) { row["COLLATION_NAME"] = tokenizer.NextToken(); } else { dtd.AppendFormat(CultureInfo.InvariantCulture, " {0}", token); } token = tokenizer.NextToken(); } if (dtd.Length > 0) { row["DTD_IDENTIFIER"] = dtd.ToString(); } // now default the collation if one wasn't given if (string.IsNullOrEmpty((string)row["COLLATION_NAME"]) && !string.IsNullOrEmpty((string)row["CHARACTER_SET_NAME"])) { row["COLLATION_NAME"] = CharSetMap.GetDefaultCollation( row["CHARACTER_SET_NAME"].ToString(), connection); } // now set the octet length if (row["CHARACTER_MAXIMUM_LENGTH"] != null) { if (row["CHARACTER_SET_NAME"] == null) { row["CHARACTER_SET_NAME"] = ""; } row["CHARACTER_OCTET_LENGTH"] = CharSetMap.GetMaxLength((string)row["CHARACTER_SET_NAME"], connection) * (int)row["CHARACTER_MAXIMUM_LENGTH"]; } return(token); }
public virtual void Configure(MySqlConnection connection) { this.connection = connection; bool firstConfigure = false; // if we have not already configured our server variables // then do so now if (serverProps == null) { firstConfigure = true; // load server properties serverProps = new Hashtable(); MySqlCommand cmd = new MySqlCommand("SHOW VARIABLES", connection); using (MySqlDataReader reader = cmd.ExecuteReader()) { try { while (reader.Read()) { string key = reader.GetString(0); string value = reader.GetString(1); serverProps[key] = value; } } catch (Exception ex) { Logger.LogException(ex); throw; } } if (serverProps.Contains("max_allowed_packet")) { maxPacketSize = Convert.ToInt64(serverProps["max_allowed_packet"]); } LoadCharacterSets(); } #if AUTHENTICATED string licenseType = serverProps["license"]; if (licenseType == null || licenseType.Length == 0 || licenseType != "commercial") { throw new MySqlException("This client library licensed only for use with commercially-licensed MySQL servers."); } #endif // if the user has indicated that we are not to reset // the connection and this is not our first time through, // then we are done. if (!Settings.ConnectionReset && !firstConfigure) { return; } string charSet = connectionString.CharacterSet; if (charSet == null || charSet.Length == 0) { if (!version.isAtLeast(4, 1, 0)) { if (serverProps.Contains("character_set")) { charSet = serverProps["character_set"].ToString(); } } else { if (serverCharSetIndex >= 0) { charSet = (string)charSets[serverCharSetIndex]; } else { charSet = serverCharSet; } } } // now tell the server which character set we will send queries in and which charset we // want results in if (version.isAtLeast(4, 1, 0)) { MySqlCommand cmd = new MySqlCommand("SET character_set_results=NULL", connection); object clientCharSet = serverProps["character_set_client"]; object connCharSet = serverProps["character_set_connection"]; if ((clientCharSet != null && clientCharSet.ToString() != charSet) || (connCharSet != null && connCharSet.ToString() != charSet)) { cmd.CommandText = "SET NAMES " + charSet + ";" + cmd.CommandText; } cmd.ExecuteNonQuery(); } if (charSet != null) { Encoding = CharSetMap.GetEncoding(version, charSet); } else { Encoding = CharSetMap.GetEncoding(version, "latin1"); } }
public virtual void Configure(MySqlConnection connection) { bool firstConfigure = false; // if we have not already configured our server variables // then do so now if (serverProps == null) { firstConfigure = true; // if we are in a pool and the user has said it's ok to cache the // properties, then grab it from the pool try { if (Pool != null && Settings.CacheServerProperties) { if (Pool.ServerProperties == null) { Pool.ServerProperties = LoadServerProperties(connection); } serverProps = Pool.ServerProperties; } else { serverProps = LoadServerProperties(connection); } LoadCharacterSets(connection); } catch (MySqlException ex) { // expired password capability if (ex.Number == 1820) { IsPasswordExpired = true; return; } throw; } } #if AUTHENTICATED string licenseType = serverProps["license"]; if (licenseType == null || licenseType.Length == 0 || licenseType != "commercial") { throw new MySqlException("This client library licensed only for use with commercially-licensed MySQL servers."); } #endif // if the user has indicated that we are not to reset // the connection and this is not our first time through, // then we are done. if (!Settings.ConnectionReset && !firstConfigure) { return; } string charSet = ConnectionString.CharacterSet; if (string.IsNullOrEmpty(charSet)) { if (ConnectionCharSetIndex >= 0 && CharacterSets.ContainsKey(ConnectionCharSetIndex)) { charSet = CharacterSets[ConnectionCharSetIndex]; } else { charSet = serverCharSet; } } if (serverProps.ContainsKey("max_allowed_packet")) { MaxPacketSize = Convert.ToInt64(serverProps["max_allowed_packet"]); } // now tell the server which character set we will send queries in and which charset we // want results in MySqlCommand charSetCmd = new MySqlCommand("SET character_set_results=NULL", connection) { InternallyCreated = true }; string clientCharSet; serverProps.TryGetValue("character_set_client", out clientCharSet); string connCharSet; serverProps.TryGetValue("character_set_connection", out connCharSet); if ((clientCharSet != null && clientCharSet.ToString() != charSet) || (connCharSet != null && connCharSet.ToString() != charSet)) { MySqlCommand setNamesCmd = new MySqlCommand("SET NAMES " + charSet, connection); setNamesCmd.InternallyCreated = true; setNamesCmd.ExecuteNonQuery(); } // sets character_set_results to null to return values in their original character set charSetCmd.ExecuteNonQuery(); Encoding = CharSetMap.GetEncoding(Version, charSet ?? "utf-8"); handler.Configure(); }
private string ParseDataType(MySqlSchemaRow row, MySqlTokenizer tokenizer) { StringBuilder stringBuilder = new StringBuilder(StringUtility.ToUpperInvariant(tokenizer.NextToken())); row["DATA_TYPE"] = stringBuilder.ToString(); string text = row["DATA_TYPE"].ToString(); string text2 = tokenizer.NextToken(); if (text2 == "(") { text2 = tokenizer.ReadParenthesis(); stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}", new object[] { text2 }); if (text != "ENUM" && text != "SET") { ISSchemaProvider.ParseDataTypeSize(row, text2); } text2 = tokenizer.NextToken(); } else { stringBuilder.Append(ISSchemaProvider.GetDataTypeDefaults(text, row)); } while (text2 != ")" && text2 != "," && string.Compare(text2, "begin", StringComparison.OrdinalIgnoreCase) != 0 && string.Compare(text2, "return", StringComparison.OrdinalIgnoreCase) != 0) { if (string.Compare(text2, "CHARACTER", StringComparison.OrdinalIgnoreCase) != 0 && string.Compare(text2, "BINARY", StringComparison.OrdinalIgnoreCase) != 0) { if (string.Compare(text2, "SET", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(text2, "CHARSET", StringComparison.OrdinalIgnoreCase) == 0) { row["CHARACTER_SET_NAME"] = tokenizer.NextToken(); } else if (string.Compare(text2, "ASCII", StringComparison.OrdinalIgnoreCase) == 0) { row["CHARACTER_SET_NAME"] = "latin1"; } else if (string.Compare(text2, "UNICODE", StringComparison.OrdinalIgnoreCase) == 0) { row["CHARACTER_SET_NAME"] = "ucs2"; } else if (string.Compare(text2, "COLLATE", StringComparison.OrdinalIgnoreCase) == 0) { row["COLLATION_NAME"] = tokenizer.NextToken(); } else { stringBuilder.AppendFormat(CultureInfo.InvariantCulture, " {0}", new object[] { text2 }); } } text2 = tokenizer.NextToken(); } if (stringBuilder.Length > 0) { row["DTD_IDENTIFIER"] = stringBuilder.ToString(); } if (string.IsNullOrEmpty((string)row["COLLATION_NAME"]) && !string.IsNullOrEmpty((string)row["CHARACTER_SET_NAME"])) { row["COLLATION_NAME"] = CharSetMap.GetDefaultCollation(row["CHARACTER_SET_NAME"].ToString(), this.connection); } if (row["CHARACTER_MAXIMUM_LENGTH"] != null) { if (row["CHARACTER_SET_NAME"] == null) { row["CHARACTER_SET_NAME"] = ""; } row["CHARACTER_OCTET_LENGTH"] = CharSetMap.GetMaxLength((string)row["CHARACTER_SET_NAME"], this.connection) * (int)row["CHARACTER_MAXIMUM_LENGTH"]; } return(text2); }
private static void InitializeMapping() { CharSetMap.LoadCharsetMap(); }
static CharSetMap() { CharSetMap.lockObject = new object(); CharSetMap.InitializeMapping(); }
public virtual void Configure(MySqlConnection connection) { bool flag = false; if (this.serverProps == null) { flag = true; try { if (this.Pool != null && this.Settings.CacheServerProperties) { if (this.Pool.ServerProperties == null) { this.Pool.ServerProperties = this.LoadServerProperties(connection); } this.serverProps = this.Pool.ServerProperties; } else { this.serverProps = this.LoadServerProperties(connection); } this.LoadCharacterSets(connection); } catch (MySqlException arg_69_0) { if (arg_69_0.Number == 1820) { this.IsPasswordExpired = true; return; } throw; } } if (!this.Settings.ConnectionReset && !flag) { return; } string text = this.connectionString.CharacterSet; if (text == null || text.Length == 0) { if (this.serverCharSetIndex >= 0 && this.charSets.ContainsKey(this.serverCharSetIndex)) { text = this.charSets[this.serverCharSetIndex]; } else { text = this.serverCharSet; } } if (this.serverProps.ContainsKey("max_allowed_packet")) { this.maxPacketSize = Convert.ToInt64(this.serverProps["max_allowed_packet"]); } MySqlCommand expr_11A = new MySqlCommand("SET character_set_results=gbk", connection); expr_11A.InternallyCreated = true; string text2; this.serverProps.TryGetValue("character_set_client", out text2); string text3; this.serverProps.TryGetValue("character_set_connection", out text3); if ((text2 != null && text2.ToString() != text) || (text3 != null && text3.ToString() != text)) { new MySqlCommand("SET NAMES " + text, connection) { InternallyCreated = true }.ExecuteNonQuery(); } expr_11A.ExecuteNonQuery(); if (text != null) { this.Encoding = CharSetMap.GetEncoding(this.Version, text); } else { this.Encoding = CharSetMap.GetEncoding(this.Version, "gbk"); } this.handler.Configure(); }