1 // ByteFX.Data data access components for .Net
\r
2 // Copyright (C) 2002-2003 ByteFX, Inc.
\r
4 // This library is free software; you can redistribute it and/or
\r
5 // modify it under the terms of the GNU Lesser General Public
\r
6 // License as published by the Free Software Foundation; either
\r
7 // version 2.1 of the License, or (at your option) any later version.
\r
9 // This library is distributed in the hope that it will be useful,
\r
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
12 // Lesser General Public License for more details.
\r
14 // You should have received a copy of the GNU Lesser General Public
\r
15 // License along with this library; if not, write to the Free Software
\r
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
19 using System.Data.Common;
\r
20 using System.ComponentModel;
\r
22 namespace ByteFX.Data.MySqlClient
\r
25 /// 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.
\r
27 /// <include file='docs/MySqlDataAdapter.xml' path='MyDocs/MyMembers[@name="Class"]/*'/>
\r
28 [System.Drawing.ToolboxBitmap( typeof(MySqlDataAdapter), "MySqlClient.resources.dataadapter.bmp")]
\r
29 [System.ComponentModel.DesignerCategory("Code")]
\r
30 [Designer("ByteFX.Data.MySqlClient.Design.MySqlDataAdapterDesigner,MySqlClient.Design")]
\r
31 public sealed class MySqlDataAdapter : DbDataAdapter, IDbDataAdapter
\r
33 private MySqlCommand m_selectCommand;
\r
34 private MySqlCommand m_insertCommand;
\r
35 private MySqlCommand m_updateCommand;
\r
36 private MySqlCommand m_deleteCommand;
\r
39 * Inherit from Component through DbDataAdapter. The event
\r
40 * mechanism is designed to work with the Component.Events
\r
41 * property. These variables are the keys used to find the
\r
42 * events in the components list of events.
\r
44 static private readonly object EventRowUpdated = new object();
\r
45 static private readonly object EventRowUpdating = new object();
\r
49 /// Initializes a new instance of the MySqlDataAdapter class.
\r
51 public MySqlDataAdapter()
\r
56 /// Initializes a new instance of the MySqlDataAdapter class with the specified MySqlCommand as the SelectCommand property.
\r
58 /// <param name="selectCommand"></param>
\r
59 public MySqlDataAdapter( MySqlCommand selectCommand )
\r
61 SelectCommand = selectCommand;
\r
65 /// Initializes a new instance of the MySqlDataAdapter class with a SelectCommand and a MySqlConnection object.
\r
67 /// <param name="selectCommandText"></param>
\r
68 /// <param name="conn"></param>
\r
69 public MySqlDataAdapter( string selectCommandText, MySqlConnection conn)
\r
71 SelectCommand = new MySqlCommand( selectCommandText, conn );
\r
75 /// Initializes a new instance of the MySqlDataAdapter class with a SelectCommand and a connection string.
\r
77 /// <param name="selectCommandText"></param>
\r
78 /// <param name="selectConnString"></param>
\r
79 public MySqlDataAdapter( string selectCommandText, string selectConnString)
\r
81 SelectCommand = new MySqlCommand( selectCommandText,
\r
82 new MySqlConnection(selectConnString) );
\r
87 /// Gets or sets a SQL statement to delete records from the data set.
\r
89 [Description("Used during Update for deleted rows in Dataset.")]
\r
90 public MySqlCommand DeleteCommand
\r
92 get { return m_deleteCommand; }
\r
93 set { m_deleteCommand = value; }
\r
96 IDbCommand IDbDataAdapter.DeleteCommand
\r
98 get { return m_deleteCommand; }
\r
99 set { m_deleteCommand = (MySqlCommand)value; }
\r
103 /// Gets or sets a SQL statement to insert new records into the data source.
\r
105 [Description("Used during Update for new rows in Dataset.")]
\r
106 public MySqlCommand InsertCommand
\r
108 get { return m_insertCommand; }
\r
109 set { m_insertCommand = value; }
\r
112 IDbCommand IDbDataAdapter.InsertCommand
\r
114 get { return m_insertCommand; }
\r
115 set { m_insertCommand = (MySqlCommand)value; }
\r
119 /// Gets or sets a SQL statement used to select records in the data source.
\r
121 [Description("Used during Fill/FillSchema")]
\r
123 public MySqlCommand SelectCommand
\r
125 get { return m_selectCommand; }
\r
126 set { m_selectCommand = value; }
\r
129 IDbCommand IDbDataAdapter.SelectCommand
\r
131 get { return m_selectCommand; }
\r
132 set { m_selectCommand = (MySqlCommand)value; }
\r
136 /// Gets or sets a SQL statement used to update records in the data source.
\r
138 [Description("Used during Update for modified rows in Dataset.")]
\r
139 public MySqlCommand UpdateCommand
\r
141 get { return m_updateCommand; }
\r
142 set { m_updateCommand = value; }
\r
145 IDbCommand IDbDataAdapter.UpdateCommand
\r
147 get { return m_updateCommand; }
\r
148 set { m_updateCommand = (MySqlCommand)value; }
\r
154 * Implement abstract methods inherited from DbDataAdapter.
\r
157 /// Overridden. See <see cref="DbDataAdapter.CreateRowUpdatedEvent"/>.
\r
159 /// <param name="dataRow"></param>
\r
160 /// <param name="command"></param>
\r
161 /// <param name="statementType"></param>
\r
162 /// <param name="tableMapping"></param>
\r
163 /// <returns></returns>
\r
164 override protected RowUpdatedEventArgs CreateRowUpdatedEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
\r
166 return new MySqlRowUpdatedEventArgs(dataRow, command, statementType, tableMapping);
\r
170 /// Overridden. See <see cref="DbDataAdapter.CreateRowUpdatingEvent"/>.
\r
172 /// <param name="dataRow"></param>
\r
173 /// <param name="command"></param>
\r
174 /// <param name="statementType"></param>
\r
175 /// <param name="tableMapping"></param>
\r
176 /// <returns></returns>
\r
177 override protected RowUpdatingEventArgs CreateRowUpdatingEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
\r
179 return new MySqlRowUpdatingEventArgs(dataRow, command, statementType, tableMapping);
\r
183 /// Overridden. Raises the RowUpdating event.
\r
185 /// <param name="value">A MySqlRowUpdatingEventArgs that contains the event data.</param>
\r
186 override protected void OnRowUpdating(RowUpdatingEventArgs value)
\r
188 MySqlRowUpdatingEventHandler handler = (MySqlRowUpdatingEventHandler) Events[EventRowUpdating];
\r
189 if ((null != handler) && (value is MySqlRowUpdatingEventArgs))
\r
191 handler(this, (MySqlRowUpdatingEventArgs) value);
\r
196 /// Overridden. Raises the RowUpdated event.
\r
198 /// <param name="value">A MySqlRowUpdatedEventArgs that contains the event data. </param>
\r
199 override protected void OnRowUpdated(RowUpdatedEventArgs value)
\r
201 MySqlRowUpdatedEventHandler handler = (MySqlRowUpdatedEventHandler) Events[EventRowUpdated];
\r
202 if ((null != handler) && (value is MySqlRowUpdatedEventArgs))
\r
204 handler(this, (MySqlRowUpdatedEventArgs) value);
\r
209 /// Occurs during Update before a command is executed against the data source. The attempt to update is made, so the event fires.
\r
211 public event MySqlRowUpdatingEventHandler RowUpdating
\r
213 add { Events.AddHandler(EventRowUpdating, value); }
\r
214 remove { Events.RemoveHandler(EventRowUpdating, value); }
\r
218 /// Occurs during Update after a command is executed against the data source. The attempt to update is made, so the event fires.
\r
220 public event MySqlRowUpdatedEventHandler RowUpdated
\r
222 add { Events.AddHandler(EventRowUpdated, value); }
\r
223 remove { Events.RemoveHandler(EventRowUpdated, value); }
\r
228 /// Represents the method that will handle the <see cref="MySqlDataAdapter.RowUpdating"/> event of a <see cref="MySqlDataAdapter"/>.
\r
230 public delegate void MySqlRowUpdatingEventHandler(object sender, MySqlRowUpdatingEventArgs e);
\r
233 /// Represents the method that will handle the <see cref="MySqlDataAdapter.RowUpdated"/> event of a <see cref="MySqlDataAdapter"/>.
\r
235 public delegate void MySqlRowUpdatedEventHandler(object sender, MySqlRowUpdatedEventArgs e);
\r
238 /// Provides data for the RowUpdating event. This class cannot be inherited.
\r
240 public sealed class MySqlRowUpdatingEventArgs : RowUpdatingEventArgs
\r
243 /// Initializes a new instance of the MySqlRowUpdatingEventArgs class.
\r
245 /// <param name="row">The <see cref="DataRow"/> to <see cref="DbDataAdapter.Update"/>.</param>
\r
246 /// <param name="command">The <see cref="IDbCommand"/> to execute during <see cref="DbDataAdapter.Update"/>.</param>
\r
247 /// <param name="statementType">One of the <see cref="StatementType"/> values that specifies the type of query executed.</param>
\r
248 /// <param name="tableMapping">The <see cref="DataTableMapping"/> sent through an <see cref="DbDataAdapter.Update"/>.</param>
\r
249 public MySqlRowUpdatingEventArgs(DataRow row, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
\r
250 : base(row, command, statementType, tableMapping)
\r
255 /// Gets or sets the MySqlCommand to execute when performing the Update.
\r
257 new public MySqlCommand Command
\r
259 get { return (MySqlCommand)base.Command; }
\r
260 set { base.Command = value; }
\r
265 /// Provides data for the RowUpdated event. This class cannot be inherited.
\r
267 public sealed class MySqlRowUpdatedEventArgs : RowUpdatedEventArgs
\r
270 /// Initializes a new instance of the MySqlRowUpdatedEventArgs class.
\r
272 /// <param name="row">The <see cref="DataRow"/> sent through an <see cref="DbDataAdapter.Update"/>.</param>
\r
273 /// <param name="command">The <see cref="IDbCommand"/> executed when <see cref="DbDataAdapter.Update"/> is called.</param>
\r
274 /// <param name="statementType">One of the <see cref="StatementType"/> values that specifies the type of query executed.</param>
\r
275 /// <param name="tableMapping">The <see cref="DataTableMapping"/> sent through an <see cref="DbDataAdapter.Update"/>.</param>
\r
276 public MySqlRowUpdatedEventArgs(DataRow row, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
\r
277 : base(row, command, statementType, tableMapping)
\r
282 /// Gets or sets the MySqlCommand executed when Update is called.
\r
284 new public MySqlCommand Command
\r
286 get { return (MySqlCommand)base.Command; }
\r