// ByteFX.Data data access components for .Net // Copyright (C) 2002-2003 ByteFX, Inc. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA using System.Data; using System.Data.Common; using System.ComponentModel; namespace ByteFX.Data.MySqlClient { /// /// Represents a set of data commands and a database connection that are used to fill a dataset and update a MySQL database. This class cannot be inherited. /// /// [System.Drawing.ToolboxBitmap( typeof(MySqlDataAdapter), "MySqlClient.resources.dataadapter.bmp")] [System.ComponentModel.DesignerCategory("Code")] [Designer("ByteFX.Data.MySqlClient.Design.MySqlDataAdapterDesigner,MySqlClient.Design")] public sealed class MySqlDataAdapter : DbDataAdapter, IDbDataAdapter { private MySqlCommand m_selectCommand; private MySqlCommand m_insertCommand; private MySqlCommand m_updateCommand; private MySqlCommand m_deleteCommand; /* * Inherit from Component through DbDataAdapter. The event * mechanism is designed to work with the Component.Events * property. These variables are the keys used to find the * events in the components list of events. */ static private readonly object EventRowUpdated = new object(); static private readonly object EventRowUpdating = new object(); /// /// Initializes a new instance of the MySqlDataAdapter class. /// public MySqlDataAdapter() { } /// /// Initializes a new instance of the MySqlDataAdapter class with the specified MySqlCommand as the SelectCommand property. /// /// public MySqlDataAdapter( MySqlCommand selectCommand ) { SelectCommand = selectCommand; } /// /// Initializes a new instance of the MySqlDataAdapter class with a SelectCommand and a MySqlConnection object. /// /// /// public MySqlDataAdapter( string selectCommandText, MySqlConnection conn) { SelectCommand = new MySqlCommand( selectCommandText, conn ); } /// /// Initializes a new instance of the MySqlDataAdapter class with a SelectCommand and a connection string. /// /// /// public MySqlDataAdapter( string selectCommandText, string selectConnString) { SelectCommand = new MySqlCommand( selectCommandText, new MySqlConnection(selectConnString) ); } #region Properties /// /// Gets or sets a SQL statement to delete records from the data set. /// [Description("Used during Update for deleted rows in Dataset.")] public MySqlCommand DeleteCommand { get { return m_deleteCommand; } set { m_deleteCommand = value; } } IDbCommand IDbDataAdapter.DeleteCommand { get { return m_deleteCommand; } set { m_deleteCommand = (MySqlCommand)value; } } /// /// Gets or sets a SQL statement to insert new records into the data source. /// [Description("Used during Update for new rows in Dataset.")] public MySqlCommand InsertCommand { get { return m_insertCommand; } set { m_insertCommand = value; } } IDbCommand IDbDataAdapter.InsertCommand { get { return m_insertCommand; } set { m_insertCommand = (MySqlCommand)value; } } /// /// Gets or sets a SQL statement used to select records in the data source. /// [Description("Used during Fill/FillSchema")] [Category("Fill")] public MySqlCommand SelectCommand { get { return m_selectCommand; } set { m_selectCommand = value; } } IDbCommand IDbDataAdapter.SelectCommand { get { return m_selectCommand; } set { m_selectCommand = (MySqlCommand)value; } } /// /// Gets or sets a SQL statement used to update records in the data source. /// [Description("Used during Update for modified rows in Dataset.")] public MySqlCommand UpdateCommand { get { return m_updateCommand; } set { m_updateCommand = value; } } IDbCommand IDbDataAdapter.UpdateCommand { get { return m_updateCommand; } set { m_updateCommand = (MySqlCommand)value; } } #endregion /* * Implement abstract methods inherited from DbDataAdapter. */ /// /// Overridden. See . /// /// /// /// /// /// override protected RowUpdatedEventArgs CreateRowUpdatedEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) { return new MySqlRowUpdatedEventArgs(dataRow, command, statementType, tableMapping); } /// /// Overridden. See . /// /// /// /// /// /// override protected RowUpdatingEventArgs CreateRowUpdatingEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) { return new MySqlRowUpdatingEventArgs(dataRow, command, statementType, tableMapping); } /// /// Overridden. Raises the RowUpdating event. /// /// A MySqlRowUpdatingEventArgs that contains the event data. override protected void OnRowUpdating(RowUpdatingEventArgs value) { MySqlRowUpdatingEventHandler handler = (MySqlRowUpdatingEventHandler) Events[EventRowUpdating]; if ((null != handler) && (value is MySqlRowUpdatingEventArgs)) { handler(this, (MySqlRowUpdatingEventArgs) value); } } /// /// Overridden. Raises the RowUpdated event. /// /// A MySqlRowUpdatedEventArgs that contains the event data. override protected void OnRowUpdated(RowUpdatedEventArgs value) { MySqlRowUpdatedEventHandler handler = (MySqlRowUpdatedEventHandler) Events[EventRowUpdated]; if ((null != handler) && (value is MySqlRowUpdatedEventArgs)) { handler(this, (MySqlRowUpdatedEventArgs) value); } } /// /// Occurs during Update before a command is executed against the data source. The attempt to update is made, so the event fires. /// public event MySqlRowUpdatingEventHandler RowUpdating { add { Events.AddHandler(EventRowUpdating, value); } remove { Events.RemoveHandler(EventRowUpdating, value); } } /// /// Occurs during Update after a command is executed against the data source. The attempt to update is made, so the event fires. /// public event MySqlRowUpdatedEventHandler RowUpdated { add { Events.AddHandler(EventRowUpdated, value); } remove { Events.RemoveHandler(EventRowUpdated, value); } } } /// /// Represents the method that will handle the event of a . /// public delegate void MySqlRowUpdatingEventHandler(object sender, MySqlRowUpdatingEventArgs e); /// /// Represents the method that will handle the event of a . /// public delegate void MySqlRowUpdatedEventHandler(object sender, MySqlRowUpdatedEventArgs e); /// /// Provides data for the RowUpdating event. This class cannot be inherited. /// public sealed class MySqlRowUpdatingEventArgs : RowUpdatingEventArgs { /// /// Initializes a new instance of the MySqlRowUpdatingEventArgs class. /// /// The to . /// The to execute during . /// One of the values that specifies the type of query executed. /// The sent through an . public MySqlRowUpdatingEventArgs(DataRow row, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) : base(row, command, statementType, tableMapping) { } /// /// Gets or sets the MySqlCommand to execute when performing the Update. /// new public MySqlCommand Command { get { return (MySqlCommand)base.Command; } set { base.Command = value; } } } /// /// Provides data for the RowUpdated event. This class cannot be inherited. /// public sealed class MySqlRowUpdatedEventArgs : RowUpdatedEventArgs { /// /// Initializes a new instance of the MySqlRowUpdatedEventArgs class. /// /// The sent through an . /// The executed when is called. /// One of the values that specifies the type of query executed. /// The sent through an . public MySqlRowUpdatedEventArgs(DataRow row, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) : base(row, command, statementType, tableMapping) { } /// /// Gets or sets the MySqlCommand executed when Update is called. /// new public MySqlCommand Command { get { return (MySqlCommand)base.Command; } } } }