コード例 #1
0
ファイル: MySqlHelper.cs プロジェクト: GodLesZ/svn-dump
		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;
		}
コード例 #2
0
ファイル: Driver.cs プロジェクト: GodLesZ/svn-dump
		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");
				}
			}
		}
コード例 #3
0
ファイル: MySqlScript.cs プロジェクト: GodLesZ/svn-dump
		public int Execute() {
			int num2;
			bool flag = false;
			if (this.connection == null) {
				throw new InvalidOperationException(Resources.ConnectionNotSet);
			}
			if ((this.query == null) || (this.query.Length == 0)) {
				return 0;
			}
			if (this.connection.State != ConnectionState.Open) {
				flag = true;
				this.connection.Open();
			}
			bool allowUserVariables = this.connection.Settings.AllowUserVariables;
			this.connection.Settings.AllowUserVariables = true;
			try {
				string str = this.connection.driver.Property("sql_mode").ToLower(CultureInfo.InvariantCulture);
				bool ansiQuotes = str.IndexOf("ansi_quotes") != -1;
				bool noBackslashEscapes = str.IndexOf("no_backslash_escpaes") != -1;
				List<ScriptStatement> list = this.BreakIntoStatements(ansiQuotes, noBackslashEscapes);
				int num = 0;
				MySqlCommand command = new MySqlCommand(null, this.connection);
				foreach (ScriptStatement statement in list) {
					command.CommandText = statement.text;
					try {
						command.ExecuteNonQuery();
						num++;
						this.OnQueryExecuted(statement);
						continue;
					} catch (Exception exception) {
						if (this.Error == null) {
							throw;
						}
						if (this.OnScriptError(exception)) {
							continue;
						}
						break;
					}
				}
				this.OnScriptCompleted();
				num2 = num;
			} finally {
				this.connection.Settings.AllowUserVariables = allowUserVariables;
				if (flag) {
					this.connection.Close();
				}
			}
			return num2;
		}
コード例 #4
0
ファイル: MySqlBulkLoader.cs プロジェクト: GodLesZ/svn-dump
		public int Load() {
			int num;
			bool flag = false;
			if (this.Connection == null) {
				throw new InvalidOperationException(Resources.ConnectionNotSet);
			}
			if (this.connection.State != ConnectionState.Open) {
				flag = true;
				this.connection.Open();
			}
			try {
				MySqlCommand command = new MySqlCommand(this.BuildSqlCommand(), this.Connection);
				command.CommandTimeout = this.Timeout;
				num = command.ExecuteNonQuery();
			} finally {
				if (flag) {
					this.connection.Close();
				}
			}
			return num;
		}
コード例 #5
0
ファイル: MySqlConnection.cs プロジェクト: GodLesZ/svn-dump
		new public MySqlTransaction BeginTransaction(System.Data.IsolationLevel iso) {
			if (this.State != ConnectionState.Open) {
				throw new InvalidOperationException(Resources.ConnectionNotOpen);
			}
			if ((this.driver.ServerStatus & ServerStatusFlags.InTransaction) != 0) {
				throw new InvalidOperationException(Resources.NoNestedTransactions);
			}
			MySqlTransaction transaction = new MySqlTransaction(this, iso);
			MySqlCommand command = new MySqlCommand("", this);
			command.CommandText = "SET SESSION TRANSACTION ISOLATION LEVEL ";
			switch (iso) {
				case System.Data.IsolationLevel.Chaos:
					throw new NotSupportedException(Resources.ChaosNotSupported);

				case System.Data.IsolationLevel.ReadUncommitted:
					command.CommandText = command.CommandText + "READ UNCOMMITTED";
					goto Label_00F1;

				case System.Data.IsolationLevel.ReadCommitted:
					command.CommandText = command.CommandText + "READ COMMITTED";
					break;

				case System.Data.IsolationLevel.RepeatableRead:
					command.CommandText = command.CommandText + "REPEATABLE READ";
					break;

				case System.Data.IsolationLevel.Serializable:
					command.CommandText = command.CommandText + "SERIALIZABLE";
					break;
			}
		Label_00F1:
			command.ExecuteNonQuery();
			command.CommandText = "BEGIN";
			command.ExecuteNonQuery();
			return transaction;
		}