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