2007-09-11 AMC <amc1999@gmail.com>
[mono.git] / mcs / class / System.Data / System.Data.Odbc / OdbcDataAdapter.cs
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
11 //
12
13 //
14 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
15 //
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.
34 //
35
36 using System;
37 using System.ComponentModel;
38 using System.Data;
39 using System.Data.Common;
40
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, ICloneable
46         {
47                 #region Fields
48
49 #if ONLY_1_1
50                 bool disposed = false;
51 #endif
52                 OdbcCommand deleteCommand;
53                 OdbcCommand insertCommand;
54                 OdbcCommand selectCommand;
55                 OdbcCommand updateCommand;
56
57                 #endregion
58
59                 #region Constructors
60                 
61                 public OdbcDataAdapter () : this (new OdbcCommand ())
62                 {
63                 }
64
65                 public OdbcDataAdapter (OdbcCommand selectCommand) 
66                 {
67                         DeleteCommand = null;
68                         InsertCommand = null;
69                         SelectCommand = selectCommand;
70                         UpdateCommand = null;
71                 }
72
73                 public OdbcDataAdapter (string selectCommandText, OdbcConnection selectConnection) 
74                         : this (new OdbcCommand (selectCommandText, selectConnection))
75                 { 
76                 }
77
78                 public OdbcDataAdapter (string selectCommandText, string selectConnectionString)
79                         : this (selectCommandText, new OdbcConnection (selectConnectionString))
80                 {
81                 }
82
83                 #endregion
84
85                 #region Properties
86
87                 [OdbcCategory ("Update")]
88                 [OdbcDescription ("Used during Update for deleted rows in DataSet.")]
89                 [DefaultValue (null)]
90                 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
91                 public new OdbcCommand DeleteCommand {
92                         get { return deleteCommand; }
93                         set { deleteCommand = value; }
94                 }
95
96                 [OdbcCategory ("Update")]
97                 [OdbcDescription ("Used during Update for new rows in DataSet.")]
98                 [DefaultValue (null)]
99                 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
100                 public new OdbcCommand InsertCommand {
101                         get { return insertCommand; }
102                         set { insertCommand = value; }
103                 }
104
105                 [OdbcCategory ("Fill")]
106                 [OdbcDescription ("Used during Fill/FillSchema.")]
107                 [DefaultValue (null)]
108                 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
109                 public new OdbcCommand SelectCommand {
110                         get { return selectCommand; }
111                         set { selectCommand = value; }
112                 }
113
114                 [OdbcCategory ("Update")]
115                 [OdbcDescription ("Used during Update for modified rows in DataSet.")]
116                 [DefaultValue (null)]
117                 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
118                 public new OdbcCommand UpdateCommand {
119                         get { return updateCommand; }
120                         set { updateCommand = value; }
121                 }
122
123                 IDbCommand IDbDataAdapter.DeleteCommand {
124                         get { return DeleteCommand; }
125                         set { 
126                                 if (!(value is OdbcCommand)) 
127                                         throw new ArgumentException ();
128                                 DeleteCommand = (OdbcCommand)value;
129                         }
130                 }
131
132                 IDbCommand IDbDataAdapter.InsertCommand {
133                         get { return InsertCommand; }
134                         set { 
135                                 if (!(value is OdbcCommand)) 
136                                         throw new ArgumentException ();
137                                 InsertCommand = (OdbcCommand)value;
138                         }
139                 }
140
141                 IDbCommand IDbDataAdapter.SelectCommand {
142                         get { return SelectCommand; }
143                         set { 
144                                 if (!(value is OdbcCommand)) 
145                                         throw new ArgumentException ();
146                                 SelectCommand = (OdbcCommand)value;
147                         }
148                 }
149
150                 IDbCommand IDbDataAdapter.UpdateCommand {
151                         get { return UpdateCommand; }
152                         set { 
153                                 if (!(value is OdbcCommand)) 
154                                         throw new ArgumentException ();
155                                 UpdateCommand = (OdbcCommand)value;
156                         }
157                 }
158
159
160                 ITableMappingCollection IDataAdapter.TableMappings {
161                         get { return TableMappings; }
162                 }
163
164                 #endregion // Properties
165
166                 #region Methods
167
168                 protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
169                 {
170                         return new OdbcRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
171                 }
172
173
174                 protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
175                 {
176                         return new OdbcRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
177                 }
178
179 #if ONLY_1_1
180                 protected override void Dispose (bool disposing)
181                 {
182                         if (!disposed) {
183                                 if (disposing) {
184                                         // Release managed resources
185                                 }
186                                 // Release unmanaged resources
187                                 disposed = true;
188                         }
189                 }
190 #endif
191
192                 protected override void OnRowUpdated (RowUpdatedEventArgs value) 
193                 {
194                         if (RowUpdated != null)
195                                 RowUpdated (this, (OdbcRowUpdatedEventArgs) value);
196                 }
197
198                 protected override void OnRowUpdating (RowUpdatingEventArgs value) 
199                 {
200                         if (RowUpdating != null)
201                                 RowUpdating (this, (OdbcRowUpdatingEventArgs) value);
202                 }
203
204                 [MonoTODO]
205                 object ICloneable.Clone ()
206                 {
207                         throw new NotImplementedException ();
208                 }
209
210                 #endregion // Methods
211
212                 #region Events and Delegates
213
214                 public event OdbcRowUpdatedEventHandler RowUpdated;
215                 public event OdbcRowUpdatingEventHandler RowUpdating;
216
217                 #endregion // Events and Delegates
218
219         }
220 }