**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Data / System.Data.Odbc / OdbcDataAdapter.cs
blob8423ac6041e5869ad7089faf5f11d707e6ce1f83
1 //
2 // System.Data.Odbc.OdbcDataAdapter.cs
3 //
4 // Author:
5 // Rodrigo Moya (rodrigo@ximian.com)
6 // Daniel Morgan (danmorg@sc.rr.com)
7 // Tim Coleman (tim@timcoleman.com)
8 //
9 // (C) Ximian, Inc 2002
10 // Copyright (C) 2002 Tim Coleman
14 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
16 // Permission is hereby granted, free of charge, to any person obtaining
17 // a copy of this software and associated documentation files (the
18 // "Software"), to deal in the Software without restriction, including
19 // without limitation the rights to use, copy, modify, merge, publish,
20 // distribute, sublicense, and/or sell copies of the Software, and to
21 // permit persons to whom the Software is furnished to do so, subject to
22 // the following conditions:
23 //
24 // The above copyright notice and this permission notice shall be
25 // included in all copies or substantial portions of the Software.
26 //
27 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System;
37 using System.ComponentModel;
38 using System.Data;
39 using System.Data.Common;
41 namespace System.Data.Odbc {
42 [DefaultEvent ("RowUpdated")]
43 [DesignerAttribute ("Microsoft.VSDesigner.Data.VS.OdbcDataAdapterDesigner, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.IDesigner")]
44 [ToolboxItemAttribute ("Microsoft.VSDesigner.Data.VS.OdbcDataAdapterToolboxItem, "+ Consts.AssemblyMicrosoft_VSDesigner)]
45 public sealed class OdbcDataAdapter : DbDataAdapter, IDbDataAdapter
47 #region Fields
49 bool disposed = false;
50 OdbcCommand deleteCommand;
51 OdbcCommand insertCommand;
52 OdbcCommand selectCommand;
53 OdbcCommand updateCommand;
55 #endregion
57 #region Constructors
59 public OdbcDataAdapter ()
60 : this (new OdbcCommand ())
64 public OdbcDataAdapter (OdbcCommand selectCommand)
66 DeleteCommand = null;
67 InsertCommand = null;
68 SelectCommand = selectCommand;
69 UpdateCommand = null;
72 public OdbcDataAdapter (string selectCommandText, OdbcConnection selectConnection)
73 : this (new OdbcCommand (selectCommandText, selectConnection))
77 public OdbcDataAdapter (string selectCommandText, string selectConnectionString)
78 : this (selectCommandText, new OdbcConnection (selectConnectionString))
82 #endregion
84 #region Properties
86 [OdbcCategory ("Update")]
87 [OdbcDescription ("Used during Update for deleted rows in DataSet.")]
88 [DefaultValue (null)]
89 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
90 public OdbcCommand DeleteCommand {
91 get { return deleteCommand; }
92 set { deleteCommand = value; }
95 [OdbcCategory ("Update")]
96 [OdbcDescription ("Used during Update for new rows in DataSet.")]
97 [DefaultValue (null)]
98 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
99 public OdbcCommand InsertCommand {
100 get { return insertCommand; }
101 set { insertCommand = value; }
104 [OdbcCategory ("Fill")]
105 [OdbcDescription ("Used during Fill/FillSchema.")]
106 [DefaultValue (null)]
107 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
108 public OdbcCommand SelectCommand {
109 get { return selectCommand; }
110 set { selectCommand = value; }
113 [OdbcCategory ("Update")]
114 [OdbcDescription ("Used during Update for modified rows in DataSet.")]
115 [DefaultValue (null)]
116 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
117 public OdbcCommand UpdateCommand {
118 get { return updateCommand; }
119 set { updateCommand = value; }
122 IDbCommand IDbDataAdapter.DeleteCommand {
123 get { return DeleteCommand; }
124 set {
125 if (!(value is OdbcCommand))
126 throw new ArgumentException ();
127 DeleteCommand = (OdbcCommand)value;
131 IDbCommand IDbDataAdapter.InsertCommand {
132 get { return InsertCommand; }
133 set {
134 if (!(value is OdbcCommand))
135 throw new ArgumentException ();
136 InsertCommand = (OdbcCommand)value;
140 IDbCommand IDbDataAdapter.SelectCommand {
141 get { return SelectCommand; }
142 set {
143 if (!(value is OdbcCommand))
144 throw new ArgumentException ();
145 SelectCommand = (OdbcCommand)value;
149 IDbCommand IDbDataAdapter.UpdateCommand {
150 get { return UpdateCommand; }
151 set {
152 if (!(value is OdbcCommand))
153 throw new ArgumentException ();
154 UpdateCommand = (OdbcCommand)value;
159 ITableMappingCollection IDataAdapter.TableMappings {
160 get { return TableMappings; }
163 #endregion // Properties
165 #region Methods
167 protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
169 return new OdbcRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
173 protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
175 return new OdbcRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
178 protected override void Dispose (bool disposing)
180 if (!disposed) {
181 if (disposing) {
182 // Release managed resources
184 // Release unmanaged resources
185 disposed = true;
189 protected override void OnRowUpdated (RowUpdatedEventArgs value)
191 if (RowUpdated != null)
192 RowUpdated (this, (OdbcRowUpdatedEventArgs) value);
195 protected override void OnRowUpdating (RowUpdatingEventArgs value)
197 if (RowUpdating != null)
198 RowUpdating (this, (OdbcRowUpdatingEventArgs) value);
201 #endregion // Methods
203 #region Events and Delegates
205 public event OdbcRowUpdatedEventHandler RowUpdated;
206 public event OdbcRowUpdatingEventHandler RowUpdating;
208 #endregion // Events and Delegates