New test.
[mono.git] / mcs / class / System.Data / System.Data.SqlClient / SqlDataAdapter.cs
1 //
2 // System.Data.SqlClient.SqlDataAdapter.cs
3 //
4 // Author:
5 //   Rodrigo Moya (rodrigo@ximian.com)
6 //   Daniel Morgan (danmorg@sc.rr.com)
7 //   Tim Coleman (tim@timcoleman.com)
8 //       Veerapuram Varadhan  (vvaradhan@novell.com)
9 //
10 // (C) Ximian, Inc 2002
11 // Copyright (C) 2002 Tim Coleman
12 //
13 // Copyright (C) 2004, 2009 Novell, Inc (http://www.novell.com)
14 //
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 // 
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 // 
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 //
34
35 using System;
36 using System.ComponentModel;
37 using System.Data;
38 using System.Data.Common;
39
40 namespace System.Data.SqlClient {
41         [DefaultEvent ("RowUpdated")]
42         [DesignerAttribute ("Microsoft.VSDesigner.Data.VS.SqlDataAdapterDesigner, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.IDesigner")]
43         [ToolboxItemAttribute ("Microsoft.VSDesigner.Data.VS.SqlDataAdapterToolboxItem, "+ Consts.AssemblyMicrosoft_VSDesigner)]
44
45 #if NET_2_0     
46         public sealed class SqlDataAdapter : DbDataAdapter, IDbDataAdapter, IDataAdapter, ICloneable
47 #else
48         public sealed class SqlDataAdapter :  DbDataAdapter, IDbDataAdapter
49 #endif
50         {
51                 #region Fields
52
53 #if !NET_2_0
54                 bool disposed;
55 #endif
56 #if ONLY_1_0 || ONLY_1_1
57                 SqlCommand _selectCommand;
58                 SqlCommand _insertCommand;
59                 SqlCommand _updateCommand;
60                 SqlCommand _deleteCommand;              
61 #endif
62 #if NET_2_0
63                 int updateBatchSize;
64 #endif
65                 #endregion
66
67                 #region Constructors
68                 
69                 public SqlDataAdapter () : this ((SqlCommand) null)
70                 {
71                 }
72
73                 public SqlDataAdapter (SqlCommand selectCommand) 
74                 {
75                         SelectCommand = selectCommand;
76 #if NET_2_0
77                         UpdateBatchSize = 1;
78 #endif
79                 }
80
81                 public SqlDataAdapter (string selectCommandText, SqlConnection selectConnection) 
82                         : this (new SqlCommand (selectCommandText, selectConnection))
83                 {
84                 }
85
86                 public SqlDataAdapter (string selectCommandText, string selectConnectionString)
87                         : this (selectCommandText, new SqlConnection (selectConnectionString))
88                 {
89                 }
90
91                 #endregion
92
93                 #region Properties
94
95 #if !NET_2_0
96                 [DataSysDescription ("Used during Update for deleted rows in DataSet.")]
97 #endif
98                 [DefaultValue (null)]
99                 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
100                 public new SqlCommand DeleteCommand {
101                         get { 
102 #if NET_2_0
103                                 return (SqlCommand)base.DeleteCommand; 
104 #else
105                                 return _deleteCommand;
106 #endif
107                         }
108                         set { 
109 #if NET_2_0
110                                 base.DeleteCommand = value; 
111 #else
112                                 _deleteCommand = value;
113 #endif
114                         }
115                 }
116
117 #if !NET_2_0
118                 [DataSysDescription ("Used during Update for new rows in DataSet.")]
119 #endif
120                 [DefaultValue (null)]
121                 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
122                 public new SqlCommand InsertCommand {
123                         get { 
124 #if NET_2_0                             
125                                 return (SqlCommand)base.InsertCommand; 
126 #else
127                                 return _insertCommand;
128 #endif
129                         }
130                         set { 
131 #if NET_2_0                             
132                                 base.InsertCommand = value; 
133 #else
134                                 _insertCommand = value;
135 #endif
136                         }
137                 }
138
139 #if !NET_2_0
140                 [DataSysDescription ("Used during Fill/FillSchema.")]
141 #endif
142                 [DefaultValue (null)]
143                 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
144                 public new SqlCommand SelectCommand {
145                         get { 
146 #if NET_2_0
147                                 return (SqlCommand)base.SelectCommand; 
148 #else
149                                 return _selectCommand;
150 #endif
151                         }
152                         set { 
153 #if NET_2_0
154                                 base.SelectCommand = value; 
155 #else
156                                 _selectCommand = value;
157 #endif
158                         }
159                 }
160
161 #if !NET_2_0
162                 [DataSysDescription ("Used during Update for modified rows in DataSet.")]
163 #endif
164                 [DefaultValue (null)]
165                 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
166                 public new  SqlCommand UpdateCommand {
167                         get { 
168 #if NET_2_0
169                                 return (SqlCommand)base.UpdateCommand; 
170 #else
171                                 return _updateCommand;
172 #endif
173                         }
174                         set { 
175 #if NET_2_0
176                                 base.UpdateCommand = value; 
177 #else
178                                 _updateCommand = value;
179 #endif
180                         }
181                 }
182                 
183                 IDbCommand IDbDataAdapter.SelectCommand {
184                         get { return SelectCommand; }
185                         set { SelectCommand = (SqlCommand) value; }
186                 }
187                 
188                 IDbCommand IDbDataAdapter.InsertCommand {
189                         get { return InsertCommand; }
190                         set { InsertCommand = (SqlCommand) value; }
191                 }
192                 
193                 IDbCommand IDbDataAdapter.UpdateCommand {
194                         get { return UpdateCommand; }
195                         set { UpdateCommand = (SqlCommand) value; }
196                 }
197                 IDbCommand IDbDataAdapter.DeleteCommand {
198                         get { return DeleteCommand; }
199                         set { DeleteCommand = (SqlCommand) value; }
200                 }
201
202 #if NET_2_0
203                 public override int UpdateBatchSize {
204                         get { return updateBatchSize; }
205                         set {
206                                 if (value < 0)
207                                         throw new ArgumentOutOfRangeException ("UpdateBatchSize");
208                                 updateBatchSize = value; 
209                         }
210                 }
211 #endif
212
213                 #endregion // Properties
214
215                 #region Methods
216
217                 protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
218                 {
219                         return new SqlRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
220                 }
221
222
223                 protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
224                 {
225                         return new SqlRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
226                 }
227
228 #if !NET_2_0
229                 protected override void Dispose (bool disposing)
230                 {
231                         if (!disposed) {
232                                 if (disposing) {
233                                         // Release managed resources
234                                 }
235                                 // Release unmanaged resources
236                                 disposed = true;
237                         }
238                         base.Dispose (disposing);
239                 }
240 #endif
241
242                 protected override void OnRowUpdated (RowUpdatedEventArgs value) 
243                 {
244                         if (RowUpdated != null)
245                                 RowUpdated (this, (SqlRowUpdatedEventArgs) value);
246                 }
247
248                 protected override void OnRowUpdating (RowUpdatingEventArgs value) 
249                 {
250                         if (RowUpdating != null)
251                                 RowUpdating (this, (SqlRowUpdatingEventArgs) value);
252                 }
253
254 #if NET_2_0             
255                 [MonoTODO]
256                 object ICloneable.Clone()
257                 {
258                         throw new NotImplementedException ();
259                 }
260 #endif
261
262 #if NET_2_0
263                 // All the batch methods, should be implemented, if supported,
264                 // by individual providers 
265
266                 [MonoTODO]
267                 protected override int AddToBatch (IDbCommand command)
268                 {
269                         throw new NotImplementedException ();
270                 }
271
272                 [MonoTODO]
273                 protected override void ClearBatch ()
274                 {
275                         throw new NotImplementedException ();
276                 }
277
278                 [MonoTODO]
279                 protected override int ExecuteBatch ()
280                 {
281                         throw new NotImplementedException ();
282                 }
283
284                 [MonoTODO]
285                 protected override IDataParameter GetBatchedParameter (int commandIdentifier, int  parameterIndex)
286                 {
287                         throw new NotImplementedException ();
288                 }
289
290                 [MonoTODO]
291                 protected override void InitializeBatching ()
292                 {
293                         throw new NotImplementedException ();
294                 }
295
296                 [MonoTODO]
297                 protected override void TerminateBatching ()
298                 {
299                         throw new NotImplementedException ();
300                 }
301 #endif
302                 #endregion // Methods
303
304                 #region Events and Delegates
305
306 #if ONLY_1_1
307                 [DataSysDescription ("Event triggered before every DataRow during Update.")]
308 #endif
309                 public event SqlRowUpdatedEventHandler RowUpdated;
310
311 #if ONLY_1_1
312                 [DataSysDescription ("Event triggered after every DataRow during Update.")]
313 #endif
314                 public event SqlRowUpdatingEventHandler RowUpdating;
315
316                 #endregion // Events and Delegates
317         }
318 }