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
24 [System.Drawing.ToolboxBitmap( typeof(MySqlDataAdapter), "Designers.dataadapter.bmp")]
25 [System.ComponentModel.DesignerCategory("Code")]
26 public sealed class MySqlDataAdapter : DbDataAdapter, IDbDataAdapter
28 private MySqlCommand m_selectCommand;
29 private MySqlCommand m_insertCommand;
30 private MySqlCommand m_updateCommand;
31 private MySqlCommand m_deleteCommand;
34 * Inherit from Component through DbDataAdapter. The event
35 * mechanism is designed to work with the Component.Events
36 * property. These variables are the keys used to find the
37 * events in the components list of events.
39 static private readonly object EventRowUpdated = new object();
40 static private readonly object EventRowUpdating = new object();
43 public MySqlDataAdapter()
47 public MySqlDataAdapter( MySqlCommand selectCommand )
49 SelectCommand = selectCommand;
52 public MySqlDataAdapter( string selectCommandText, string selectConnString)
54 SelectCommand = new MySqlCommand( selectCommandText,
55 new MySqlConnection(selectConnString) );
58 public MySqlDataAdapter( string selectCommandText, MySqlConnection conn)
60 SelectCommand = new MySqlCommand( selectCommandText, conn );
64 [DataSysDescription("Used during Fill/FillSchema")]
66 public MySqlCommand SelectCommand
68 get { return m_selectCommand; }
69 set { m_selectCommand = value; }
72 IDbCommand IDbDataAdapter.SelectCommand
74 get { return m_selectCommand; }
75 set { m_selectCommand = (MySqlCommand)value; }
78 [DataSysDescription("Used during Update for new rows in Dataset.")]
79 public MySqlCommand InsertCommand
81 get { return m_insertCommand; }
82 set { m_insertCommand = value; }
85 IDbCommand IDbDataAdapter.InsertCommand
87 get { return m_insertCommand; }
88 set { m_insertCommand = (MySqlCommand)value; }
91 [DataSysDescription("Used during Update for modified rows in Dataset.")]
92 public MySqlCommand UpdateCommand
94 get { return m_updateCommand; }
95 set { m_updateCommand = value; }
98 IDbCommand IDbDataAdapter.UpdateCommand
100 get { return m_updateCommand; }
101 set { m_updateCommand = (MySqlCommand)value; }
104 [DataSysDescription("Used during Update for deleted rows in Dataset.")]
105 public MySqlCommand DeleteCommand
107 get { return m_deleteCommand; }
108 set { m_deleteCommand = value; }
111 IDbCommand IDbDataAdapter.DeleteCommand
113 get { return m_deleteCommand; }
114 set { m_deleteCommand = (MySqlCommand)value; }
119 * Implement abstract methods inherited from DbDataAdapter.
121 override protected RowUpdatedEventArgs CreateRowUpdatedEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
123 return new MySqlRowUpdatedEventArgs(dataRow, command, statementType, tableMapping);
126 override protected RowUpdatingEventArgs CreateRowUpdatingEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
128 return new MySqlRowUpdatingEventArgs(dataRow, command, statementType, tableMapping);
131 override protected void OnRowUpdating(RowUpdatingEventArgs value)
133 MySqlRowUpdatingEventHandler handler = (MySqlRowUpdatingEventHandler) Events[EventRowUpdating];
134 if ((null != handler) && (value is MySqlRowUpdatingEventArgs))
136 handler(this, (MySqlRowUpdatingEventArgs) value);
140 override protected void OnRowUpdated(RowUpdatedEventArgs value)
142 MySqlRowUpdatedEventHandler handler = (MySqlRowUpdatedEventHandler) Events[EventRowUpdated];
143 if ((null != handler) && (value is MySqlRowUpdatedEventArgs))
145 handler(this, (MySqlRowUpdatedEventArgs) value);
149 public event MySqlRowUpdatingEventHandler RowUpdating
151 add { Events.AddHandler(EventRowUpdating, value); }
152 remove { Events.RemoveHandler(EventRowUpdating, value); }
155 public event MySqlRowUpdatedEventHandler RowUpdated
157 add { Events.AddHandler(EventRowUpdated, value); }
158 remove { Events.RemoveHandler(EventRowUpdated, value); }
162 public delegate void MySqlRowUpdatingEventHandler(object sender, MySqlRowUpdatingEventArgs e);
163 public delegate void MySqlRowUpdatedEventHandler(object sender, MySqlRowUpdatedEventArgs e);
165 public class MySqlRowUpdatingEventArgs : RowUpdatingEventArgs
167 public MySqlRowUpdatingEventArgs(DataRow row, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
168 : base(row, command, statementType, tableMapping)
172 // Hide the inherited implementation of the command property.
173 new public MySqlCommand Command
175 get { return (MySqlCommand)base.Command; }
176 set { base.Command = value; }
180 public class MySqlRowUpdatedEventArgs : RowUpdatedEventArgs
182 public MySqlRowUpdatedEventArgs(DataRow row, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
183 : base(row, command, statementType, tableMapping)
187 // Hide the inherited implementation of the command property.
188 new public MySqlCommand Command
190 get { return (MySqlCommand)base.Command; }