public MySqlTransactionScope(MySqlConnection con, Transaction trans, MySqlTransaction simpleTransaction) { connection = con; baseTransaction = trans; this.simpleTransaction = simpleTransaction; }
public MySqlBulkLoader(MySqlConnection connection) { Connection = connection; Local = true; FieldTerminator = defaultFieldTerminator; LineTerminator = defaultLineTerminator; FieldQuotationCharacter = Char.MinValue; ConflictOption = MySqlBulkLoaderConflictOption.None; columns = new StringCollection(); expressions = new StringCollection(); }
public PerformanceMonitor(MySqlConnection connection) { this.connection = connection; string categoryName = Resources.PerfMonCategoryName; if (connection.Settings.UsePerformanceMonitor && procedureHardQueries == null) { procedureHardQueries = new PerformanceCounter(categoryName, "HardProcedureQueries", false); procedureSoftQueries = new PerformanceCounter(categoryName, "SoftProcedureQueries", false); } }
/* * Because the user should not be able to directly create a * DataReader object, the constructors are * marked as internal. */ internal MySqlDataReader(MySqlCommand cmd, PreparableStatement statement, CommandBehavior behavior) { this.command = cmd; connection = (MySqlConnection)command.Connection; commandBehavior = behavior; driver = connection.driver; affectedRows = -1; this.statement = statement; if (cmd.CommandType == CommandType.StoredProcedure && cmd.UpdatedRowSource == UpdateRowSource.FirstReturnedRecord) { disableZeroAffectedRows = true; } }
public DataSet GetProcedure(MySqlConnection conn, string spName, string cacheKey) { DataSet ds = null; if (cacheKey != null) { int hash = cacheKey.GetHashCode(); lock (procHash.SyncRoot) { ds = (DataSet)procHash[hash]; } } if (ds == null) ds = AddNew(conn, spName); return ds; }
/// <summary> /// Executes a single command against a MySQL database. The <see cref="MySqlConnection"/> is assumed to be /// open when the method is called and remains open after the method completes. /// </summary> /// <param name="connection"><see cref="MySqlConnection"/> object to use</param> /// <param name="commandText">SQL command to be executed</param> /// <param name="commandParameters">Array of <see cref="MySqlParameter"/> objects to use with the command.</param> /// <returns></returns> public static int ExecuteNonQuery(MySqlConnection connection, string commandText, params MySqlParameter[] commandParameters) { //create a command and prepare it for execution MySqlCommand cmd = new MySqlCommand(); cmd.Connection = connection; cmd.CommandText = commandText; cmd.CommandType = CommandType.Text; if (commandParameters != null) foreach (MySqlParameter p in commandParameters) cmd.Parameters.Add(p); int result = cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); return result; }
/// <summary> /// Executes a single command against a MySQL database. /// </summary> /// <param name="connection"><see cref="MySqlConnection"/> object to use for the command</param> /// <param name="commandText">Command text to use</param> /// <returns><see cref="MySqlDataReader"/> object ready to read the results of the command</returns> public static MySqlDataReader ExecuteReader(MySqlConnection connection, string commandText) { //pass through the call providing null for the set of SqlParameters return ExecuteReader(connection, null, commandText, (MySqlParameter[])null, true); }
/// <summary> /// Executes a single command against a MySQL database, possibly inside an existing transaction. /// </summary> /// <param name="connection"><see cref="MySqlConnection"/> object to use for the command</param> /// <param name="transaction"><see cref="MySqlTransaction"/> object to use for the command</param> /// <param name="commandText">Command text to use</param> /// <param name="commandParameters">Array of <see cref="MySqlParameter"/> objects to use with the command</param> /// <param name="ExternalConn">True if the connection should be preserved, false if not</param> /// <returns><see cref="MySqlDataReader"/> object ready to read the results of the command</returns> private static MySqlDataReader ExecuteReader(MySqlConnection connection, MySqlTransaction transaction, string commandText, MySqlParameter[] commandParameters, bool ExternalConn) { //create a command and prepare it for execution MySqlCommand cmd = new MySqlCommand(); cmd.Connection = connection; cmd.Transaction = transaction; cmd.CommandText = commandText; cmd.CommandType = CommandType.Text; if (commandParameters != null) foreach (MySqlParameter p in commandParameters) cmd.Parameters.Add(p); //create a reader MySqlDataReader dr; // call ExecuteReader with the appropriate CommandBehavior if (ExternalConn) { dr = cmd.ExecuteReader(); } else { dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); } // detach the SqlParameters from the command object, so they can be used again. cmd.Parameters.Clear(); return dr; }
public SchemaProvider(MySqlConnection connectionToUse) { connection = connectionToUse; }
/// <summary> /// Execute a single command against a MySQL database. /// </summary> /// <param name="connection"><see cref="MySqlConnection"/> object to use</param> /// <param name="commandText">Command text to use for the command</param> /// <returns>The first column of the first row in the result set, or a null reference if the result set is empty.</returns> public static object ExecuteScalar(MySqlConnection connection, string commandText) { //pass through the call providing null for the set of MySqlParameters return ExecuteScalar(connection, commandText, (MySqlParameter[])null); }
/// <summary> /// Initializes a new instance of the /// <see cref="MySqlScript"/> class. /// </summary> /// <param name="connection">The connection.</param> /// <param name="query">The query.</param> public MySqlScript(MySqlConnection connection, string query) : this() { this.connection = connection; this.query = query; }
/// <summary> /// Initializes a new instance of the /// <see cref="MySqlScript"/> class. /// </summary> /// <param name="connection">The connection.</param> public MySqlScript(MySqlConnection connection) : this() { this.connection = connection; }
public MySqlDataAdapter(string selectCommandText, MySqlConnection connection) : this() { SelectCommand = new MySqlCommand(selectCommandText, connection); }
public MySqlClient(DatabaseManager dbManager, int id) { this.dbManager = dbManager; this.connection = new MySqlConnection(); }
public static MySqlDbType NameToType(string typeName, bool unsigned, bool realAsFloat, MySqlConnection connection) { switch (typeName.ToUpper(CultureInfo.InvariantCulture)) { case "CHAR": return MySqlDbType.String; case "VARCHAR": return MySqlDbType.VarChar; case "DATE": return MySqlDbType.Date; case "DATETIME": return MySqlDbType.DateTime; case "NUMERIC": case "DECIMAL": case "DEC": case "FIXED": if (connection.driver.Version.isAtLeast(5, 0, 3)) return MySqlDbType.NewDecimal; else return MySqlDbType.Decimal; case "YEAR": return MySqlDbType.Year; case "TIME": return MySqlDbType.Time; case "TIMESTAMP": return MySqlDbType.Timestamp; case "SET": return MySqlDbType.Set; case "ENUM": return MySqlDbType.Enum; case "BIT": return MySqlDbType.Bit; case "TINYINT": return unsigned ? MySqlDbType.UByte : MySqlDbType.Byte; case "BOOL": case "BOOLEAN": return MySqlDbType.Byte; case "SMALLINT": return unsigned ? MySqlDbType.UInt16 : MySqlDbType.Int16; case "MEDIUMINT": return unsigned ? MySqlDbType.UInt24 : MySqlDbType.Int24; case "INT": case "INTEGER": return unsigned ? MySqlDbType.UInt32 : MySqlDbType.Int32; case "SERIAL": return MySqlDbType.UInt64; case "BIGINT": return unsigned ? MySqlDbType.UInt64 : MySqlDbType.Int64; case "FLOAT": return MySqlDbType.Float; case "DOUBLE": return MySqlDbType.Double; case "REAL": return realAsFloat ? MySqlDbType.Float : MySqlDbType.Double; case "TEXT": return MySqlDbType.Text; case "BLOB": return MySqlDbType.Blob; case "LONGBLOB": return MySqlDbType.LongBlob; case "LONGTEXT": return MySqlDbType.LongText; case "MEDIUMBLOB": return MySqlDbType.MediumBlob; case "MEDIUMTEXT": return MySqlDbType.MediumText; case "TINYBLOB": return MySqlDbType.TinyBlob; case "TINYTEXT": return MySqlDbType.TinyText; case "BINARY": return MySqlDbType.Binary; case "VARBINARY": return MySqlDbType.VarBinary; } throw new MySqlException("Unhandled type encountered"); }
public override void CloseQuery(MySqlConnection connection, int statementId) { base.CloseQuery(connection, statementId); }
public override List<MySqlError> ReportWarnings(MySqlConnection connection) { return base.ReportWarnings(connection); }
/// <summary> /// Executes a single command against a MySQL database. /// </summary> /// <param name="connectionString">Settings to use for this command</param> /// <param name="commandText">Command text to use</param> /// <param name="commandParameters">Array of <see cref="MySqlParameter"/> objects to use with the command</param> /// <returns><see cref="MySqlDataReader"/> object ready to read the results of the command</returns> public static MySqlDataReader ExecuteReader(string connectionString, string commandText, params MySqlParameter[] commandParameters) { //create & open a SqlConnection MySqlConnection cn = new MySqlConnection(); cn.Open(); //call the private overload that takes an internally owned connection in place of the connection string return ExecuteReader(cn, null, commandText, commandParameters, false); }
/// <summary> /// Executes a single command against a MySQL database. /// </summary> /// <param name="connection">Connection to use for the command</param> /// <param name="commandText">Command text to use</param> /// <param name="commandParameters">Array of <see cref="MySqlParameter"/> objects to use with the command</param> /// <returns><see cref="MySqlDataReader"/> object ready to read the results of the command</returns> public static MySqlDataReader ExecuteReader(MySqlConnection connection, string commandText, params MySqlParameter[] commandParameters) { //call the private overload that takes an internally owned connection in place of the connection string return ExecuteReader(connection, null, commandText, commandParameters, true); }
public MySqlCommand(string cmdText, MySqlConnection connection, MySqlTransaction transaction) : this(cmdText, connection) { curTransaction = transaction; }
/// <summary> /// Execute a single command against a MySQL database. /// </summary> /// <param name="connection"><see cref="MySqlConnection"/> object to use</param> /// <param name="commandText">Command text to use for the command</param> /// <param name="commandParameters">Parameters to use for the command</param> /// <returns>The first column of the first row in the result set, or a null reference if the result set is empty.</returns> public static object ExecuteScalar(MySqlConnection connection, string commandText, params MySqlParameter[] commandParameters) { //create a command and prepare it for execution MySqlCommand cmd = new MySqlCommand(); cmd.Connection = connection; cmd.CommandText = commandText; cmd.CommandType = CommandType.Text; if (commandParameters != null) foreach (MySqlParameter p in commandParameters) cmd.Parameters.Add(p); //execute the command & return the results object retval = cmd.ExecuteScalar(); // detach the SqlParameters from the command object, so they can be used again. cmd.Parameters.Clear(); return retval; }
public MySqlCommand(string cmdText, MySqlConnection connection) : this(cmdText) { Connection = connection; }
/// <summary> /// Executes a single command against a MySQL database. A new <see cref="MySqlConnection"/> is created /// using the <see cref="MySqlConnection.ConnectionString"/> given. /// </summary> /// <param name="connectionString"><see cref="MySqlConnection.ConnectionString"/> to use</param> /// <param name="commandText">SQL command to be executed</param> /// <param name="parms">Array of <see cref="MySqlParameter"/> objects to use with the command.</param> /// <returns></returns> public static int ExecuteNonQuery(string connectionString, string commandText, params MySqlParameter[] parms) { //create & open a SqlConnection, and dispose of it after we are done. using (MySqlConnection cn = new MySqlConnection()) { cn.Open(); //call the overload that takes a connection in place of the connection string return ExecuteNonQuery(cn, commandText, parms); } }
public MySqlPromotableTransaction(MySqlConnection connection, Transaction baseTransaction) { this.connection = connection; this.baseTransaction = baseTransaction; }
/// <summary> /// Executes a single SQL command and returns the resultset in a <see cref="DataSet"/>. /// The state of the <see cref="MySqlConnection"/> object remains unchanged after execution /// of this method. /// </summary> /// <param name="connection"><see cref="MySqlConnection"/> object to use</param> /// <param name="commandText">Command to execute</param> /// <returns><see cref="DataSet"/> containing the resultset</returns> public static DataSet ExecuteDataset(MySqlConnection connection, string commandText) { //pass through the call providing null for the set of SqlParameters return ExecuteDataset(connection, commandText, (MySqlParameter[])null); }
internal static string GetDefaultCollation(string charset, MySqlConnection connection) { lock (lockObject) { if (defaultCollations == null) InitCollections(connection); } if (!defaultCollations.ContainsKey(charset)) return null; return defaultCollations[charset]; }
internal static void InitCollections(MySqlConnection connection) { defaultCollations = new Dictionary<string, string>(); maxLengths = new Dictionary<string, int>(); MySqlCommand cmd = new MySqlCommand("SHOW CHARSET", connection); using (MySqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { defaultCollations.Add(reader.GetString(0), reader.GetString(2)); maxLengths.Add(reader.GetString(0), Convert.ToInt32(reader.GetValue(3))); } } }
/// <summary> /// Executes a single SQL command and returns the resultset in a <see cref="DataSet"/>. /// The state of the <see cref="MySqlConnection"/> object remains unchanged after execution /// of this method. /// </summary> /// <param name="connection"><see cref="MySqlConnection"/> object to use</param> /// <param name="commandText">Command to execute</param> /// <param name="commandParameters">Parameters to use for the command</param> /// <returns><see cref="DataSet"/> containing the resultset</returns> public static DataSet ExecuteDataset(MySqlConnection connection, string commandText, params MySqlParameter[] commandParameters) { //create a command and prepare it for execution MySqlCommand cmd = new MySqlCommand(); cmd.Connection = connection; cmd.CommandText = commandText; cmd.CommandType = CommandType.Text; if (commandParameters != null) foreach (MySqlParameter p in commandParameters) cmd.Parameters.Add(p); //create the DataAdapter & DataSet MySqlDataAdapter da = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); //fill the DataSet using default values for DataTable names, etc. da.Fill(ds); // detach the MySqlParameters from the command object, so they can be used again. cmd.Parameters.Clear(); //return the dataset return ds; }
internal static int GetMaxLength(string charset, MySqlConnection connection) { lock (lockObject) { if (maxLengths == null) InitCollections(connection); } if (!maxLengths.ContainsKey(charset)) return 1; return maxLengths[charset]; }
/// <summary> /// Updates the given table with data from the given <see cref="DataSet"/> /// </summary> /// <param name="connectionString">Settings to use for the update</param> /// <param name="commandText">Command text to use for the update</param> /// <param name="ds"><see cref="DataSet"/> containing the new data to use in the update</param> /// <param name="tablename">Tablename in the dataset to update</param> public static void UpdateDataSet(string connectionString, string commandText, DataSet ds, string tablename) { MySqlConnection cn = new MySqlConnection(); cn.Open(); MySqlDataAdapter da = new MySqlDataAdapter(commandText, cn); MySqlCommandBuilder cb = new MySqlCommandBuilder(da); cb.ToString(); da.Update(ds, tablename); cn.Close(); }