Exemple #1
0
		internal static void InitCollections(MySqlConnection connection) {
			MySqlCommand command = new MySqlCommand("SHOW CHARSET", connection);
			using (MySqlDataReader reader = command.ExecuteReader()) {
				while (reader.Read()) {
					defaultCollations.Add(reader.GetString(0), reader.GetString(2));
					maxLengths.Add(reader.GetString(0), Convert.ToInt32(reader.GetValue(3)));
				}
			}
		}
Exemple #2
0
		public MySqlBulkLoader(MySqlConnection connection) {
			this.Connection = connection;
			this.Local = true;
			this.FieldTerminator = "\t";
			this.LineTerminator = "\n";
			this.FieldQuotationCharacter = '\0';
			this.ConflictOption = MySqlBulkLoaderConflictOption.None;
			this.columns = new StringCollection();
			this.expressions = new StringCollection();
		}
Exemple #3
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");
				}
			}
		}
Exemple #4
0
		internal static int GetMaxLength(string charset, MySqlConnection connection) {
			lock (defaultCollations) {
				if (maxLengths.Count == 0) {
					InitCollections(connection);
				}
			}
			if (!maxLengths.ContainsKey(charset)) {
				return 1;
			}
			return maxLengths[charset];
		}
Exemple #5
0
		internal static string GetDefaultCollation(string charset, MySqlConnection connection) {
			lock (defaultCollations) {
				if (defaultCollations.Count == 0) {
					InitCollections(connection);
				}
			}
			if (!defaultCollations.ContainsKey(charset)) {
				return null;
			}
			return defaultCollations[charset];
		}
Exemple #6
0
		internal MySqlDataReader(MySqlCommand cmd, PreparableStatement statement, CommandBehavior behavior) {
			this.command = cmd;
			this.connection = this.command.Connection;
			this.commandBehavior = behavior;
			this.driver = this.connection.driver;
			this.affectedRows = -1L;
			this.statement = statement;
			this.nextResultDone = false;
			this.fieldHashCS = new Hashtable();
			this.fieldHashCI = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
		}
		public PerformanceMonitor(MySqlConnection connection) {
			this.connection = connection;
			string perfMonCategoryName = Resources.PerfMonCategoryName;
			if (connection.Settings.UsePerformanceMonitor && (procedureHardQueries == null)) {
				try {
					procedureHardQueries = new PerformanceCounter(perfMonCategoryName, "HardProcedureQueries", false);
					procedureSoftQueries = new PerformanceCounter(perfMonCategoryName, "SoftProcedureQueries", false);
				} catch (Exception exception) {
					Logger.LogException(exception);
				}
			}
		}
Exemple #8
0
		public static int ExecuteNonQuery(MySqlConnection connection, string commandText, params MySqlParameter[] commandParameters) {
			MySqlCommand command = new MySqlCommand();
			command.Connection = connection;
			command.CommandText = commandText;
			command.CommandType = CommandType.Text;
			if (commandParameters != null) {
				foreach (MySqlParameter parameter in commandParameters) {
					command.Parameters.Add(parameter);
				}
			}
			int num = command.ExecuteNonQuery();
			command.Parameters.Clear();
			return num;
		}
Exemple #9
0
		private DataSet AddNew(MySqlConnection connection, string spName) {
			DataSet procData = GetProcData(connection, spName);
			if (this.maxSize > 0) {
				int hashCode = spName.GetHashCode();
				lock (this.procHash.SyncRoot) {
					if (this.procHash.Keys.Count >= this.maxSize) {
						this.TrimHash();
					}
					if (!this.procHash.ContainsKey(hashCode)) {
						this.procHash[hashCode] = procData;
						this.hashQueue.Enqueue(hashCode);
					}
				}
			}
			return procData;
		}
Exemple #10
0
		public static DataSet ExecuteDataset(MySqlConnection connection, string commandText, params MySqlParameter[] commandParameters) {
			MySqlCommand selectCommand = new MySqlCommand();
			selectCommand.Connection = connection;
			selectCommand.CommandText = commandText;
			selectCommand.CommandType = CommandType.Text;
			if (commandParameters != null) {
				foreach (MySqlParameter parameter in commandParameters) {
					selectCommand.Parameters.Add(parameter);
				}
			}
			MySqlDataAdapter adapter = new MySqlDataAdapter(selectCommand);
			DataSet dataSet = new DataSet();
			adapter.Fill(dataSet);
			selectCommand.Parameters.Clear();
			return dataSet;
		}
Exemple #11
0
		public override void Close() {
			if (this.isOpen) {
				bool flag = (this.commandBehavior & CommandBehavior.CloseConnection) != CommandBehavior.Default;
				this.commandBehavior = CommandBehavior.Default;
				this.connection.Reader = null;
				if (!this.nextResultDone) {
					while (this.NextResult()) {
					}
				}
				this.command.Close();
				if (flag) {
					this.connection.Close();
				}
				this.command = null;
				this.connection = null;
				this.isOpen = false;
			}
		}
Exemple #12
0
		private static DataSet GetProcData(MySqlConnection connection, string spName) {
			int index = spName.IndexOf(".");
			string str = spName.Substring(0, index);
			string str2 = spName.Substring(index + 1, (spName.Length - index) - 1);
			string[] restrictionValues = new string[4];
			restrictionValues[1] = (str.Length > 0) ? str : connection.CurrentDatabase();
			restrictionValues[2] = str2;
			DataTable schema = connection.GetSchema("procedures", restrictionValues);
			if (schema.Rows.Count > 1) {
				throw new MySqlException(Resources.ProcAndFuncSameName);
			}
			if (schema.Rows.Count == 0) {
				throw new MySqlException(string.Format(Resources.InvalidProcName, str2, str));
			}
			DataTable procedureParameters = new ISSchemaProvider(connection).GetProcedureParameters(restrictionValues, schema);
			DataSet set = new DataSet();
			set.Tables.Add(schema);
			set.Tables.Add(procedureParameters);
			return set;
		}
Exemple #13
0
		public DataSet GetProcedure(MySqlConnection conn, string spName) {
			int hashCode = spName.GetHashCode();
			DataSet set = null;
			lock (this.procHash.SyncRoot) {
				set = (DataSet)this.procHash[hashCode];
			}
			if (set == null) {
				set = this.AddNew(conn, spName);
				conn.PerfMonitor.AddHardProcedureQuery();
				if (conn.Settings.Logging) {
					Logger.LogInformation(string.Format(Resources.HardProcQuery, spName));
				}
				return set;
			}
			conn.PerfMonitor.AddSoftProcedureQuery();
			if (conn.Settings.Logging) {
				Logger.LogInformation(string.Format(Resources.SoftProcQuery, spName));
			}
			return set;
		}
Exemple #14
0
		public static DataSet ExecuteDataset(MySqlConnection connection, string commandText) {
			return ExecuteDataset(connection, commandText, null);
		}
Exemple #15
0
		public static void UpdateDataSet(string connectionString, string commandText, DataSet ds, string tablename) {
			MySqlConnection connection = new MySqlConnection(connectionString);
			connection.Open();
			MySqlDataAdapter adapter = new MySqlDataAdapter(commandText, connection);
			new MySqlCommandBuilder(adapter).ToString();
			adapter.Update(ds, tablename);
			connection.Close();
		}
Exemple #16
0
		public static object ExecuteScalar(string connectionString, string commandText, params MySqlParameter[] commandParameters) {
			using (MySqlConnection connection = new MySqlConnection(connectionString)) {
				connection.Open();
				return ExecuteScalar(connection, commandText, commandParameters);
			}
		}
Exemple #17
0
		public static object ExecuteScalar(MySqlConnection connection, string commandText, params MySqlParameter[] commandParameters) {
			MySqlCommand command = new MySqlCommand();
			command.Connection = connection;
			command.CommandText = commandText;
			command.CommandType = CommandType.Text;
			if (commandParameters != null) {
				foreach (MySqlParameter parameter in commandParameters) {
					command.Parameters.Add(parameter);
				}
			}
			object obj2 = command.ExecuteScalar();
			command.Parameters.Clear();
			return obj2;
		}
Exemple #18
0
		public MySqlCommand(string cmdText, MySqlConnection connection)
			: this(cmdText) {
			this.Connection = connection;
		}
Exemple #19
0
		private static MySqlDataReader ExecuteReader(MySqlConnection connection, MySqlTransaction transaction, string commandText, MySqlParameter[] commandParameters, bool ExternalConn) {
			MySqlDataReader reader;
			MySqlCommand command = new MySqlCommand();
			command.Connection = connection;
			command.Transaction = transaction;
			command.CommandText = commandText;
			command.CommandType = CommandType.Text;
			if (commandParameters != null) {
				foreach (MySqlParameter parameter in commandParameters) {
					command.Parameters.Add(parameter);
				}
			}
			if (ExternalConn) {
				reader = command.ExecuteReader();
			} else {
				reader = command.ExecuteReader(CommandBehavior.CloseConnection);
			}
			command.Parameters.Clear();
			return reader;
		}
Exemple #20
0
		public MySqlDataAdapter(string selectCommandText, MySqlConnection connection)
			: this() {
			this.SelectCommand = new MySqlCommand(selectCommandText, connection);
		}
Exemple #21
0
		/// <summary>
		/// Tests the connection details and try to open a <see cref="MySqlConnection"/>
		/// <para>If opened successfully, its closed afterwards</para>
		/// <para>Also, if opened, the returned value will be the return from <see cref="Close"/> method</para>
		/// </summary>
		public EMysqlConnectionError Prepare() {
			ConnectionString = String.Format("SERVER={0};PORT={1};UID={2};PASSWORD={3};DATABASE={4};", mServer, mPort, mUser, mPassword, mDatabase);
			if (AdditionalSettings != "") {
				ConnectionString += ";" + AdditionalSettings;
			}
			Connection = new MySqlConnection(ConnectionString);

			EMysqlConnectionError result = Open();
			if (result == EMysqlConnectionError.None) {
				result = Close(false);
			}

			return result;
		}
Exemple #22
0
		public UsageAdvisor(MySqlConnection conn) {
			this.conn = conn;
		}
Exemple #23
0
		public MySqlCommand(string cmdText, MySqlConnection connection, MySqlTransaction transaction)
			: this(cmdText, connection) {
			this.curTransaction = transaction;
		}
Exemple #24
0
		public static DataSet ExecuteDataset(string connectionString, string commandText, params MySqlParameter[] commandParameters) {
			using (MySqlConnection connection = new MySqlConnection(connectionString)) {
				connection.Open();
				return ExecuteDataset(connection, commandText, commandParameters);
			}
		}
Exemple #25
0
		public static object ExecuteScalar(MySqlConnection connection, string commandText) {
			return ExecuteScalar(connection, commandText, null);
		}
Exemple #26
0
		public MySqlField(MySqlConnection connection) {
			this.connection = connection;
			this.connVersion = connection.driver.Version;
			this.maxLength = 1;
			this.binaryOk = true;
		}
Exemple #27
0
		public override void Cancel() {
			if (!this.connection.driver.Version.isAtLeast(5, 0, 0)) {
				throw new NotSupportedException(Resources.CancelNotSupported);
			}
			MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder(this.connection.Settings.GetConnectionString(true));
			builder.Pooling = false;
			using (MySqlConnection connection = new MySqlConnection(builder.ConnectionString)) {
				connection.Open();
				new MySqlCommand(string.Format("KILL QUERY {0}", this.connection.ServerThread), connection).ExecuteNonQuery();
			}
		}
Exemple #28
0
		public static int ExecuteNonQuery(string connectionString, string commandText, params MySqlParameter[] parms) {
			using (MySqlConnection connection = new MySqlConnection(connectionString)) {
				connection.Open();
				return ExecuteNonQuery(connection, commandText, parms);
			}
		}
Exemple #29
0
		public static MySqlDataReader ExecuteReader(string connectionString, string commandText, params MySqlParameter[] commandParameters) {
			MySqlDataReader reader;
			MySqlConnection connection = new MySqlConnection(connectionString);
			connection.Open();
			try {
				reader = ExecuteReader(connection, null, commandText, commandParameters, false);
			} catch {
				connection.Close();
				throw;
			}
			return reader;
		}
Exemple #30
-1
		internal MySqlTransaction(MySqlConnection c, System.Data.IsolationLevel il) {
			this.conn = c;
			this.level = il;
			this.open = true;
		}