Example #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)));
				}
			}
		}
Example #2
0
		public override void Close() {
			base.Close();
			if (this.outSelect.Length != 0) {
				MySqlCommand command = new MySqlCommand("SELECT " + this.outSelect, base.Connection);
				string parameterHash = base.command.parameterHash;
				command.parameterHash = parameterHash;
				using (MySqlDataReader reader = command.ExecuteReader()) {
					for (int i = 0; i < reader.FieldCount; i++) {
						string parameterName = reader.GetName(i).Remove(0, parameterHash.Length + 1);
						MySqlParameter parameterFlexible = base.Parameters.GetParameterFlexible(parameterName, true);
						reader.values[i] = MySqlField.GetIMySqlValue(parameterFlexible.MySqlDbType);
					}
					if (reader.Read()) {
						for (int j = 0; j < reader.FieldCount; j++) {
							string str3 = reader.GetName(j).Remove(0, parameterHash.Length + 1);
							base.Parameters.GetParameterFlexible(str3, true).Value = reader.GetValue(j);
						}
					}
				}
			}
		}
Example #3
0
		private void FindTables(DataTable schemaTable, string[] restrictions) {
			StringBuilder builder = new StringBuilder();
			StringBuilder builder2 = new StringBuilder();
			builder.AppendFormat(CultureInfo.InvariantCulture, "SHOW TABLE STATUS FROM `{0}`", new object[] { restrictions[1] });
			if (((restrictions != null) && (restrictions.Length >= 3)) && (restrictions[2] != null)) {
				builder2.AppendFormat(CultureInfo.InvariantCulture, " LIKE '{0}'", new object[] { restrictions[2] });
			}
			builder.Append(builder2.ToString());
			string str = (restrictions[1].ToLower() == "information_schema") ? "SYSTEM VIEW" : "BASE TABLE";
			MySqlCommand command = new MySqlCommand(builder.ToString(), this.connection);
			using (MySqlDataReader reader = command.ExecuteReader()) {
				while (reader.Read()) {
					DataRow row = schemaTable.NewRow();
					row["TABLE_CATALOG"] = null;
					row["TABLE_SCHEMA"] = restrictions[1];
					row["TABLE_NAME"] = reader.GetString(0);
					row["TABLE_TYPE"] = str;
					row["ENGINE"] = GetString(reader, 1);
					row["VERSION"] = reader.GetValue(2);
					row["ROW_FORMAT"] = GetString(reader, 3);
					row["TABLE_ROWS"] = reader.GetValue(4);
					row["AVG_ROW_LENGTH"] = reader.GetValue(5);
					row["DATA_LENGTH"] = reader.GetValue(6);
					row["MAX_DATA_LENGTH"] = reader.GetValue(7);
					row["INDEX_LENGTH"] = reader.GetValue(8);
					row["DATA_FREE"] = reader.GetValue(9);
					row["AUTO_INCREMENT"] = reader.GetValue(10);
					row["CREATE_TIME"] = reader.GetValue(11);
					row["UPDATE_TIME"] = reader.GetValue(12);
					row["CHECK_TIME"] = reader.GetValue(13);
					row["TABLE_COLLATION"] = GetString(reader, 14);
					row["CHECKSUM"] = reader.GetValue(15);
					row["CREATE_OPTIONS"] = GetString(reader, 0x10);
					row["TABLE_COMMENT"] = GetString(reader, 0x11);
					schemaTable.Rows.Add(row);
				}
			}
		}
Example #4
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;
		}
Example #5
0
		public void ReportWarnings() {
			ArrayList list = new ArrayList();
			MySqlCommand command = new MySqlCommand("SHOW WARNINGS", this.connection);
			using (MySqlDataReader reader = command.ExecuteReader()) {
				while (reader.Read()) {
					list.Add(new MySqlError(reader.GetString(0), reader.GetInt32(1), reader.GetString(2)));
				}
				this.hasWarnings = false;
				if (list.Count != 0) {
					MySqlInfoMessageEventArgs args = new MySqlInfoMessageEventArgs();
					args.errors = (MySqlError[])list.ToArray(typeof(MySqlError));
					if (this.connection != null) {
						this.connection.OnInfoMessage(args);
					}
				}
			}
		}
Example #6
0
		private void LoadCharacterSets() {
			if (this.version.isAtLeast(4, 1, 0)) {
				MySqlCommand command = new MySqlCommand("SHOW COLLATION", this.connection);
				try {
					using (MySqlDataReader reader = command.ExecuteReader()) {
						this.charSets = new Hashtable();
						while (reader.Read()) {
							this.charSets[Convert.ToInt32(reader["id"], NumberFormatInfo.InvariantInfo)] = reader.GetString(reader.GetOrdinal("charset"));
						}
					}
				} catch (Exception exception) {
					Logger.LogException(exception);
					throw;
				}
			}
		}
Example #7
0
		private void LoadTableColumns(DataTable dt, string schema, string tableName, string columnRestriction) {
			MySqlCommand command = new MySqlCommand(string.Format("SHOW FULL COLUMNS FROM `{0}`.`{1}`", schema, tableName), this.connection);
			int num = 1;
			using (MySqlDataReader reader = command.ExecuteReader()) {
				while (reader.Read()) {
					string str2 = reader.GetString(0);
					if ((columnRestriction == null) || (str2 == columnRestriction)) {
						DataRow row = dt.NewRow();
						row["TABLE_CATALOG"] = DBNull.Value;
						row["TABLE_SCHEMA"] = schema;
						row["TABLE_NAME"] = tableName;
						row["COLUMN_NAME"] = str2;
						row["ORDINAL_POSITION"] = num++;
						row["COLUMN_DEFAULT"] = reader.GetValue(5);
						row["IS_NULLABLE"] = reader.GetString(3);
						row["DATA_TYPE"] = reader.GetString(1);
						row["CHARACTER_MAXIMUM_LENGTH"] = DBNull.Value;
						row["NUMERIC_PRECISION"] = DBNull.Value;
						row["NUMERIC_SCALE"] = DBNull.Value;
						row["CHARACTER_SET_NAME"] = reader.GetValue(2);
						row["COLLATION_NAME"] = row["CHARACTER_SET_NAME"];
						row["COLUMN_TYPE"] = reader.GetString(1);
						row["COLUMN_KEY"] = reader.GetString(4);
						row["EXTRA"] = reader.GetString(6);
						row["PRIVILEGES"] = reader.GetString(7);
						row["COLUMN_COMMENT"] = reader.GetString(8);
						ParseColumnRow(row);
						dt.Rows.Add(row);
					}
				}
			}
		}
Example #8
0
		public virtual DataTable GetProcedures(string[] restrictions) {
			DataTable table = new DataTable("Procedures");
			table.Columns.Add(new DataColumn("SPECIFIC_NAME", typeof(string)));
			table.Columns.Add(new DataColumn("ROUTINE_CATALOG", typeof(string)));
			table.Columns.Add(new DataColumn("ROUTINE_SCHEMA", typeof(string)));
			table.Columns.Add(new DataColumn("ROUTINE_NAME", typeof(string)));
			table.Columns.Add(new DataColumn("ROUTINE_TYPE", typeof(string)));
			table.Columns.Add(new DataColumn("DTD_IDENTIFIER", typeof(string)));
			table.Columns.Add(new DataColumn("ROUTINE_BODY", typeof(string)));
			table.Columns.Add(new DataColumn("ROUTINE_DEFINITION", typeof(string)));
			table.Columns.Add(new DataColumn("EXTERNAL_NAME", typeof(string)));
			table.Columns.Add(new DataColumn("EXTERNAL_LANGUAGE", typeof(string)));
			table.Columns.Add(new DataColumn("PARAMETER_STYLE", typeof(string)));
			table.Columns.Add(new DataColumn("IS_DETERMINISTIC", typeof(string)));
			table.Columns.Add(new DataColumn("SQL_DATA_ACCESS", typeof(string)));
			table.Columns.Add(new DataColumn("SQL_PATH", typeof(string)));
			table.Columns.Add(new DataColumn("SECURITY_TYPE", typeof(string)));
			table.Columns.Add(new DataColumn("CREATED", typeof(DateTime)));
			table.Columns.Add(new DataColumn("LAST_ALTERED", typeof(DateTime)));
			table.Columns.Add(new DataColumn("SQL_MODE", typeof(string)));
			table.Columns.Add(new DataColumn("ROUTINE_COMMENT", typeof(string)));
			table.Columns.Add(new DataColumn("DEFINER", typeof(string)));
			StringBuilder builder = new StringBuilder("SELECT * FROM mysql.proc WHERE 1=1");
			if (restrictions != null) {
				if ((restrictions.Length >= 2) && (restrictions[1] != null)) {
					builder.AppendFormat(CultureInfo.InvariantCulture, " AND db LIKE '{0}'", new object[] { restrictions[1] });
				}
				if ((restrictions.Length >= 3) && (restrictions[2] != null)) {
					builder.AppendFormat(CultureInfo.InvariantCulture, " AND name LIKE '{0}'", new object[] { restrictions[2] });
				}
				if ((restrictions.Length >= 4) && (restrictions[3] != null)) {
					builder.AppendFormat(CultureInfo.InvariantCulture, " AND type LIKE '{0}'", new object[] { restrictions[3] });
				}
			}
			MySqlCommand command = new MySqlCommand(builder.ToString(), this.connection);
			using (MySqlDataReader reader = command.ExecuteReader()) {
				while (reader.Read()) {
					DataRow row = table.NewRow();
					row["SPECIFIC_NAME"] = reader.GetString("specific_name");
					row["ROUTINE_CATALOG"] = DBNull.Value;
					row["ROUTINE_SCHEMA"] = reader.GetString("db");
					row["ROUTINE_NAME"] = reader.GetString("name");
					string str = reader.GetString("type");
					row["ROUTINE_TYPE"] = str;
					row["DTD_IDENTIFIER"] = (str.ToLower(CultureInfo.InvariantCulture) == "function") ? ((object)reader.GetString("returns")) : ((object)DBNull.Value);
					row["ROUTINE_BODY"] = "SQL";
					row["ROUTINE_DEFINITION"] = reader.GetString("body");
					row["EXTERNAL_NAME"] = DBNull.Value;
					row["EXTERNAL_LANGUAGE"] = DBNull.Value;
					row["PARAMETER_STYLE"] = "SQL";
					row["IS_DETERMINISTIC"] = reader.GetString("is_deterministic");
					row["SQL_DATA_ACCESS"] = reader.GetString("sql_data_access");
					row["SQL_PATH"] = DBNull.Value;
					row["SECURITY_TYPE"] = reader.GetString("security_type");
					row["CREATED"] = reader.GetDateTime("created");
					row["LAST_ALTERED"] = reader.GetDateTime("modified");
					row["SQL_MODE"] = reader.GetString("sql_mode");
					row["ROUTINE_COMMENT"] = reader.GetString("comment");
					row["DEFINER"] = reader.GetString("definer");
					table.Rows.Add(row);
				}
			}
			return table;
		}
Example #9
0
		public virtual DataTable GetIndexColumns(string[] restrictions) {
			DataTable table = new DataTable("IndexColumns");
			table.Columns.Add("INDEX_CATALOG", typeof(string));
			table.Columns.Add("INDEX_SCHEMA", typeof(string));
			table.Columns.Add("INDEX_NAME", typeof(string));
			table.Columns.Add("TABLE_NAME", typeof(string));
			table.Columns.Add("COLUMN_NAME", typeof(string));
			table.Columns.Add("ORDINAL_POSITION", typeof(int));
			string[] array = new string[Math.Max(restrictions.Length, 4)];
			restrictions.CopyTo(array, 0);
			array[3] = "BASE TABLE";
			foreach (DataRow row in this.GetTables(array).Rows) {
				MySqlCommand command = new MySqlCommand(string.Format("SHOW INDEX FROM `{0}`.`{1}`", row["TABLE_SCHEMA"], row["TABLE_NAME"]), this.connection);
				using (MySqlDataReader reader = command.ExecuteReader()) {
					while (reader.Read()) {
						string str2 = GetString(reader, reader.GetOrdinal("KEY_NAME"));
						string str3 = GetString(reader, reader.GetOrdinal("COLUMN_NAME"));
						if ((restrictions == null) || ((((restrictions.Length != 4) || (restrictions[3] == null)) || (str2 == restrictions[3])) && (((restrictions.Length != 5) || (restrictions[4] == null)) || (str3 == restrictions[4])))) {
							DataRow row2 = table.NewRow();
							row2["INDEX_CATALOG"] = null;
							row2["INDEX_SCHEMA"] = row["TABLE_SCHEMA"];
							row2["INDEX_NAME"] = str2;
							row2["TABLE_NAME"] = GetString(reader, reader.GetOrdinal("TABLE"));
							row2["COLUMN_NAME"] = str3;
							row2["ORDINAL_POSITION"] = reader.GetValue(reader.GetOrdinal("SEQ_IN_INDEX"));
							table.Rows.Add(row2);
						}
					}
					continue;
				}
			}
			return table;
		}
Example #10
0
		private void GetForeignKeysOnTable(DataTable fkTable, DataRow tableToParse, string filterName, bool includeColumns) {
			string sqlMode = this.GetSqlMode();
			if (filterName != null) {
				filterName = filterName.ToLower(CultureInfo.InvariantCulture);
			}
			string cmdText = string.Format("SHOW CREATE TABLE `{0}`.`{1}`", tableToParse["TABLE_SCHEMA"], tableToParse["TABLE_NAME"]);
			string input = null;
			MySqlCommand command = new MySqlCommand(cmdText, this.connection);
			using (MySqlDataReader reader = command.ExecuteReader()) {
				reader.Read();
				input = reader.GetString(1).ToLower(CultureInfo.InvariantCulture);
			}
			SqlTokenizer tokenizer = new SqlTokenizer(input);
			tokenizer.AnsiQuotes = sqlMode.IndexOf("ANSI_QUOTES") != -1;
			tokenizer.BackslashEscapes = sqlMode.IndexOf("NO_BACKSLASH_ESCAPES") != -1;
			while (true) {
				string str5 = tokenizer.NextToken();
				while ((str5 != null) && ((str5 != "constraint") || tokenizer.Quoted)) {
					str5 = tokenizer.NextToken();
				}
				if (str5 == null) {
					return;
				}
				this.ParseConstraint(fkTable, tableToParse, tokenizer, includeColumns);
			}
		}
Example #11
0
		private string GetProcedureParameterLine(DataRow isRow) {
			string format = "SHOW CREATE {0} `{1}`.`{2}`";
			MySqlCommand command = new MySqlCommand(string.Format(format, isRow["ROUTINE_TYPE"], isRow["ROUTINE_SCHEMA"], isRow["ROUTINE_NAME"]), base.connection);
			using (MySqlDataReader reader = command.ExecuteReader()) {
				string str4;
				reader.Read();
				if (reader.IsDBNull(2)) {
					return null;
				}
				string str2 = reader.GetString(1);
				string input = reader.GetString(2);
				SqlTokenizer tokenizer = new SqlTokenizer(input);
				tokenizer.AnsiQuotes = str2.IndexOf("ANSI_QUOTES") != -1;
				tokenizer.BackslashEscapes = str2.IndexOf("NO_BACKSLASH_ESCAPES") == -1;
				for (str4 = tokenizer.NextToken(); str4 != "("; str4 = tokenizer.NextToken()) {
				}
				int startIndex = tokenizer.Index + 1;
				str4 = tokenizer.NextToken();
				while ((str4 != ")") || tokenizer.Quoted) {
					str4 = tokenizer.NextToken();
					if ((str4 == "(") && !tokenizer.Quoted) {
						while ((str4 != ")") || tokenizer.Quoted) {
							str4 = tokenizer.NextToken();
						}
						str4 = tokenizer.NextToken();
					}
				}
				return input.Substring(startIndex, tokenizer.Index - startIndex);
			}
		}