Ejemplo n.º 1
0
		public virtual void Configure(MySqlConnection connection) {
			this.connection = connection;
			bool flag = false;
			if (this.serverProps == null) {
				flag = true;
				this.serverProps = new Hashtable();
				MySqlDataReader reader = new MySqlCommand("SHOW VARIABLES", connection).ExecuteReader();
				try {
					while (reader.Read()) {
						string str = reader.GetString(0);
						string str2 = reader.GetString(1);
						this.serverProps[str] = str2;
					}
				} catch (Exception exception) {
					Logger.LogException(exception);
					throw;
				} finally {
					if (reader != null) {
						reader.Dispose();
					}
				}
				if (this.serverProps.Contains("max_allowed_packet")) {
					this.maxPacketSize = Convert.ToInt64(this.serverProps["max_allowed_packet"]);
				}
				this.LoadCharacterSets();
			}
			if (this.Settings.ConnectionReset || flag) {
				string characterSet = this.connectionString.CharacterSet;
				if ((characterSet == null) || (characterSet.Length == 0)) {
					if (!this.version.isAtLeast(4, 1, 0)) {
						if (this.serverProps.Contains("character_set")) {
							characterSet = this.serverProps["character_set"].ToString();
						}
					} else if (this.serverCharSetIndex >= 0) {
						characterSet = (string)this.charSets[this.serverCharSetIndex];
					} else {
						characterSet = this.serverCharSet;
					}
				}
				if (this.version.isAtLeast(4, 1, 0)) {
					MySqlCommand command2 = new MySqlCommand("SET character_set_results=NULL", connection);
					object obj2 = this.serverProps["character_set_client"];
					object obj3 = this.serverProps["character_set_connection"];
					if (((obj2 != null) && (obj2.ToString() != characterSet)) || ((obj3 != null) && (obj3.ToString() != characterSet))) {
						command2.CommandText = "SET NAMES " + characterSet + ";" + command2.CommandText;
					}
					command2.ExecuteNonQuery();
				}
				if (characterSet != null) {
					this.Encoding = CharSetMap.GetEncoding(this.version, characterSet);
				} else {
					this.Encoding = CharSetMap.GetEncoding(this.version, "latin1");
				}
			}
		}
Ejemplo n.º 2
0
        public virtual void Configure(MySqlConnection connection)
        {
            this.connection = connection;
            bool flag = false;

            if (this.serverProps == null)
            {
                flag             = true;
                this.serverProps = new Hashtable();
                MySqlDataReader reader = new MySqlCommand("SHOW VARIABLES", connection).ExecuteReader();
                try {
                    while (reader.Read())
                    {
                        string str  = reader.GetString(0);
                        string str2 = reader.GetString(1);
                        this.serverProps[str] = str2;
                    }
                } catch (Exception exception) {
                    Logger.LogException(exception);
                    throw;
                } finally {
                    if (reader != null)
                    {
                        reader.Dispose();
                    }
                }
                if (this.serverProps.Contains("max_allowed_packet"))
                {
                    this.maxPacketSize = Convert.ToInt64(this.serverProps["max_allowed_packet"]);
                }
                this.LoadCharacterSets();
            }
            if (this.Settings.ConnectionReset || flag)
            {
                string characterSet = this.connectionString.CharacterSet;
                if ((characterSet == null) || (characterSet.Length == 0))
                {
                    if (!this.version.isAtLeast(4, 1, 0))
                    {
                        if (this.serverProps.Contains("character_set"))
                        {
                            characterSet = this.serverProps["character_set"].ToString();
                        }
                    }
                    else if (this.serverCharSetIndex >= 0)
                    {
                        characterSet = (string)this.charSets[this.serverCharSetIndex];
                    }
                    else
                    {
                        characterSet = this.serverCharSet;
                    }
                }
                if (this.version.isAtLeast(4, 1, 0))
                {
                    MySqlCommand command2 = new MySqlCommand("SET character_set_results=NULL", connection);
                    object       obj2     = this.serverProps["character_set_client"];
                    object       obj3     = this.serverProps["character_set_connection"];
                    if (((obj2 != null) && (obj2.ToString() != characterSet)) || ((obj3 != null) && (obj3.ToString() != characterSet)))
                    {
                        command2.CommandText = "SET NAMES " + characterSet + ";" + command2.CommandText;
                    }
                    command2.ExecuteNonQuery();
                }
                if (characterSet != null)
                {
                    this.Encoding = CharSetMap.GetEncoding(this.version, characterSet);
                }
                else
                {
                    this.Encoding = CharSetMap.GetEncoding(this.version, "latin1");
                }
            }
        }