Copied remotely
[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 
46         {
47                 #region Fields
48
49                 bool disposed = false;  
50                 OdbcCommand deleteCommand;
51                 OdbcCommand insertCommand;
52                 OdbcCommand selectCommand;
53                 OdbcCommand updateCommand;
54
55                 #endregion
56
57                 #region Constructors
58                 
59                 public OdbcDataAdapter ()       
60                         : this (new OdbcCommand ())
61                 {
62                 }
63
64                 public OdbcDataAdapter (OdbcCommand selectCommand) 
65                 {
66                         DeleteCommand = null;
67                         InsertCommand = null;
68                         SelectCommand = selectCommand;
69                         UpdateCommand = null;
70                 }
71
72                 public OdbcDataAdapter (string selectCommandText, OdbcConnection selectConnection) 
73                         : this (new OdbcCommand (selectCommandText, selectConnection))
74                 { 
75                 }
76
77                 public OdbcDataAdapter (string selectCommandText, string selectConnectionString)
78                         : this (selectCommandText, new OdbcConnection (selectConnectionString))
79                 {
80                 }
81
82                 #endregion
83
84                 #region Properties
85
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; }
93                 }
94
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; }
102                 }
103
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; }
111                 }
112
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; }
120                 }
121
122                 IDbCommand IDbDataAdapter.DeleteCommand {
123                         get { return DeleteCommand; }
124                         set { 
125                                 if (!(value is OdbcCommand)) 
126                                         throw new ArgumentException ();
127                                 DeleteCommand = (OdbcCommand)value;
128                         }
129                 }
130
131                 IDbCommand IDbDataAdapter.InsertCommand {
132                         get { return InsertCommand; }
133                         set { 
134                                 if (!(value is OdbcCommand)) 
135                                         throw new ArgumentException ();
136                                 InsertCommand = (OdbcCommand)value;
137                         }
138                 }
139
140                 IDbCommand IDbDataAdapter.SelectCommand {
141                         get { return SelectCommand; }
142                         set { 
143                                 if (!(value is OdbcCommand)) 
144                                         throw new ArgumentException ();
145                                 SelectCommand = (OdbcCommand)value;
146                         }
147                 }
148
149                 IDbCommand IDbDataAdapter.UpdateCommand {
150                         get { return UpdateCommand; }
151                         set { 
152                                 if (!(value is OdbcCommand)) 
153                                         throw new ArgumentException ();
154                                 UpdateCommand = (OdbcCommand)value;
155                         }
156                 }
157
158
159                 ITableMappingCollection IDataAdapter.TableMappings {
160                         get { return TableMappings; }
161                 }
162
163                 #endregion // Properties
164
165                 #region Methods
166
167                 protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
168                 {
169                         return new OdbcRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
170                 }
171
172
173                 protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
174                 {
175                         return new OdbcRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
176                 }
177
178                 protected override void Dispose (bool disposing)
179                 {
180                         if (!disposed) {
181                                 if (disposing) {
182                                         // Release managed resources
183                                 }
184                                 // Release unmanaged resources
185                                 disposed = true;
186                         }
187                 }
188
189                 protected override void OnRowUpdated (RowUpdatedEventArgs value) 
190                 {
191                         if (RowUpdated != null)
192                                 RowUpdated (this, (OdbcRowUpdatedEventArgs) value);
193                 }
194
195                 protected override void OnRowUpdating (RowUpdatingEventArgs value) 
196                 {
197                         if (RowUpdating != null)
198                                 RowUpdating (this, (OdbcRowUpdatingEventArgs) value);
199                 }
200
201                 #endregion // Methods
202
203                 #region Events and Delegates
204
205                 public event OdbcRowUpdatedEventHandler RowUpdated;
206                 public event OdbcRowUpdatingEventHandler RowUpdating;
207
208                 #endregion // Events and Delegates
209
210         }
211 }