1 // ByteFX.Data data access components for .Net
2 // Copyright (C) 2002-2003 ByteFX, Inc.
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.
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.
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
19 using System
.Data
.Common
;
20 using System
.ComponentModel
;
22 namespace ByteFX
.Data
.MySqlClient
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.
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();
49 /// Initializes a new instance of the MySqlDataAdapter class.
51 public MySqlDataAdapter()
56 /// Initializes a new instance of the MySqlDataAdapter class with the specified MySqlCommand as the SelectCommand property.
58 /// <param name="selectCommand"></param>
59 public MySqlDataAdapter( MySqlCommand selectCommand
)
61 SelectCommand
= selectCommand
;
65 /// Initializes a new instance of the MySqlDataAdapter class with a SelectCommand and a MySqlConnection object.
67 /// <param name="selectCommandText"></param>
68 /// <param name="conn"></param>
69 public MySqlDataAdapter( string selectCommandText
, MySqlConnection conn
)
71 SelectCommand
= new MySqlCommand( selectCommandText
, conn
);
75 /// Initializes a new instance of the MySqlDataAdapter class with a SelectCommand and a connection string.
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
) );
87 /// Gets or sets a SQL statement to delete records from the data set.
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; }
103 /// Gets or sets a SQL statement to insert new records into the data source.
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; }
119 /// Gets or sets a SQL statement used to select records in the data source.
121 [Description("Used during Fill/FillSchema")]
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; }
136 /// Gets or sets a SQL statement used to update records in the data source.
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; }
154 * Implement abstract methods inherited from DbDataAdapter.
157 /// Overridden. See <see cref="DbDataAdapter.CreateRowUpdatedEvent"/>.
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
);
170 /// Overridden. See <see cref="DbDataAdapter.CreateRowUpdatingEvent"/>.
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
);
183 /// Overridden. Raises the RowUpdating event.
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);
196 /// Overridden. Raises the RowUpdated event.
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);
209 /// Occurs during Update before a command is executed against the data source. The attempt to update is made, so the event fires.
211 public event MySqlRowUpdatingEventHandler RowUpdating
213 add { Events.AddHandler(EventRowUpdating, value); }
214 remove { Events.RemoveHandler(EventRowUpdating, value); }
218 /// Occurs during Update after a command is executed against the data source. The attempt to update is made, so the event fires.
220 public event MySqlRowUpdatedEventHandler RowUpdated
222 add { Events.AddHandler(EventRowUpdated, value); }
223 remove { Events.RemoveHandler(EventRowUpdated, value); }
228 /// Represents the method that will handle the <see cref="MySqlDataAdapter.RowUpdating"/> event of a <see cref="MySqlDataAdapter"/>.
230 public delegate void MySqlRowUpdatingEventHandler(object sender
, MySqlRowUpdatingEventArgs e
);
233 /// Represents the method that will handle the <see cref="MySqlDataAdapter.RowUpdated"/> event of a <see cref="MySqlDataAdapter"/>.
235 public delegate void MySqlRowUpdatedEventHandler(object sender
, MySqlRowUpdatedEventArgs e
);
238 /// Provides data for the RowUpdating event. This class cannot be inherited.
240 public sealed class MySqlRowUpdatingEventArgs
: RowUpdatingEventArgs
243 /// Initializes a new instance of the MySqlRowUpdatingEventArgs class.
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
)
255 /// Gets or sets the MySqlCommand to execute when performing the Update.
257 new public MySqlCommand Command
259 get { return (MySqlCommand)base.Command; }
260 set { base.Command = value; }
265 /// Provides data for the RowUpdated event. This class cannot be inherited.
267 public sealed class MySqlRowUpdatedEventArgs
: RowUpdatedEventArgs
270 /// Initializes a new instance of the MySqlRowUpdatedEventArgs class.
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
)
282 /// Gets or sets the MySqlCommand executed when Update is called.
284 new public MySqlCommand Command
286 get { return (MySqlCommand)base.Command; }