* DataRelationCollection.cs (BinarySerialize): New. Carved out of ...
[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 {
43         [DefaultEvent ("RowUpdated")]
44         [DesignerAttribute ("Microsoft.VSDesigner.Data.VS.OdbcDataAdapterDesigner, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.IDesigner")]
45         [ToolboxItemAttribute ("Microsoft.VSDesigner.Data.VS.OdbcDataAdapterToolboxItem, "+ Consts.AssemblyMicrosoft_VSDesigner)]
46         public sealed class OdbcDataAdapter : DbDataAdapter, IDbDataAdapter, ICloneable
47         {
48                 #region Fields
49
50 #if ONLY_1_1
51                 bool disposed;
52 #endif
53                 OdbcCommand deleteCommand;
54                 OdbcCommand insertCommand;
55                 OdbcCommand selectCommand;
56                 OdbcCommand updateCommand;
57
58                 #endregion
59
60                 #region Constructors
61                 
62                 public OdbcDataAdapter () : this ((OdbcCommand) null)
63                 {
64                 }
65
66                 public OdbcDataAdapter (OdbcCommand selectCommand) 
67                 {
68                         SelectCommand = selectCommand;
69                 }
70
71                 public OdbcDataAdapter (string selectCommandText, OdbcConnection selectConnection) 
72                         : this (new OdbcCommand (selectCommandText, selectConnection))
73                 { 
74                 }
75
76                 public OdbcDataAdapter (string selectCommandText, string selectConnectionString)
77                         : this (selectCommandText, new OdbcConnection (selectConnectionString))
78                 {
79                 }
80
81                 #endregion
82
83                 #region Properties
84
85                 [OdbcCategory ("Update")]
86                 [OdbcDescription ("Used during Update for deleted rows in DataSet.")]
87                 [DefaultValue (null)]
88                 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
89                 public new OdbcCommand DeleteCommand {
90                         get { return deleteCommand; }
91                         set { deleteCommand = value; }
92                 }
93
94                 [OdbcCategory ("Update")]
95                 [OdbcDescription ("Used during Update for new rows in DataSet.")]
96                 [DefaultValue (null)]
97                 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
98                 public new OdbcCommand InsertCommand {
99                         get { return insertCommand; }
100                         set { insertCommand = value; }
101                 }
102
103                 [OdbcCategory ("Fill")]
104                 [OdbcDescription ("Used during Fill/FillSchema.")]
105                 [DefaultValue (null)]
106                 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
107                 public new OdbcCommand SelectCommand {
108                         get { return selectCommand; }
109                         set { selectCommand = value; }
110                 }
111
112                 [OdbcCategory ("Update")]
113                 [OdbcDescription ("Used during Update for modified rows in DataSet.")]
114                 [DefaultValue (null)]
115                 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
116                 public new OdbcCommand UpdateCommand {
117                         get { return updateCommand; }
118                         set { updateCommand = value; }
119                 }
120
121                 IDbCommand IDbDataAdapter.DeleteCommand {
122                         get { return DeleteCommand; }
123                         set { DeleteCommand = (OdbcCommand) value; }
124                 }
125
126                 IDbCommand IDbDataAdapter.InsertCommand {
127                         get { return InsertCommand; }
128                         set { InsertCommand = (OdbcCommand) value; }
129                 }
130
131                 IDbCommand IDbDataAdapter.SelectCommand {
132                         get { return SelectCommand; }
133                         set { SelectCommand = (OdbcCommand) value; }
134                 }
135
136                 IDbCommand IDbDataAdapter.UpdateCommand {
137                         get { return UpdateCommand; }
138                         set { UpdateCommand = (OdbcCommand) value; }
139                 }
140
141                 #endregion // Properties
142
143                 #region Methods
144
145                 protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
146                 {
147                         return new OdbcRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
148                 }
149
150
151                 protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
152                 {
153                         return new OdbcRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
154                 }
155
156 #if ONLY_1_1
157                 protected override void Dispose (bool disposing)
158                 {
159                         if (!disposed) {
160                                 if (disposing) {
161                                         // Release managed resources
162                                 }
163                                 // Release unmanaged resources
164                                 disposed = true;
165                         }
166                         base.Dispose (true);
167                 }
168 #endif
169
170                 protected override void OnRowUpdated (RowUpdatedEventArgs value)
171                 {
172                         if (RowUpdated != null)
173                                 RowUpdated (this, (OdbcRowUpdatedEventArgs) value);
174                 }
175
176                 protected override void OnRowUpdating (RowUpdatingEventArgs value)
177                 {
178                         if (RowUpdating != null)
179                                 RowUpdating (this, (OdbcRowUpdatingEventArgs) value);
180                 }
181
182                 [MonoTODO]
183                 object ICloneable.Clone ()
184                 {
185                         throw new NotImplementedException ();
186                 }
187
188                 #endregion // Methods
189
190                 #region Events and Delegates
191
192                 public event OdbcRowUpdatedEventHandler RowUpdated;
193                 public event OdbcRowUpdatingEventHandler RowUpdating;
194
195                 #endregion // Events and Delegates
196         }
197 }