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 //
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.SqlClient {
42         [DefaultEvent ("RowUpdated")]
43         [DesignerAttribute ("Microsoft.VSDesigner.Data.VS.SqlDataAdapterDesigner, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.IDesigner")]
44         [ToolboxItemAttribute ("Microsoft.VSDesigner.Data.VS.SqlDataAdapterToolboxItem, "+ Consts.AssemblyMicrosoft_VSDesigner)] 
45         public sealed class SqlDataAdapter : DbDataAdapter, IDbDataAdapter 
46         {
47                 #region Fields
48
49                 bool disposed = false;  
50                 SqlCommand deleteCommand;
51                 SqlCommand insertCommand;
52                 SqlCommand selectCommand;
53                 SqlCommand updateCommand;
54
55                 #endregion
56
57                 #region Constructors
58                 
59                 public SqlDataAdapter ()        
60                         : this (new SqlCommand ())
61                 {
62                 }
63
64                 public SqlDataAdapter (SqlCommand selectCommand) 
65                 {
66                         DeleteCommand = null;
67                         InsertCommand = null;
68                         SelectCommand = selectCommand;
69                         UpdateCommand = null;
70                 }
71
72                 public SqlDataAdapter (string selectCommandText, SqlConnection selectConnection) 
73                         : this (new SqlCommand (selectCommandText, selectConnection))
74                 { 
75                 }
76
77                 public SqlDataAdapter (string selectCommandText, string selectConnectionString)
78                         : this (selectCommandText, new SqlConnection (selectConnectionString))
79                 {
80                 }
81
82                 #endregion
83
84                 #region Properties
85
86                 [DataCategory ("Update")]
87 #if !NET_2_0
88                 [DataSysDescription ("Used during Update for deleted rows in DataSet.")]
89 #endif
90                 [DefaultValue (null)]
91                 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
92                 public new SqlCommand DeleteCommand {
93                         get { return deleteCommand; }
94                         set { deleteCommand = value; }
95                 }
96
97                 [DataCategory ("Update")]
98 #if !NET_2_0
99                 [DataSysDescription ("Used during Update for new rows in DataSet.")]
100 #endif
101                 [DefaultValue (null)]
102                 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
103                 public new SqlCommand InsertCommand {
104                         get { return insertCommand; }
105                         set { insertCommand = value; }
106                 }
107
108                 [DataCategory ("Fill")]
109 #if !NET_2_0
110                 [DataSysDescription ("Used during Fill/FillSchema.")]
111 #endif
112                 [DefaultValue (null)]
113                 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
114                 public new SqlCommand SelectCommand {
115                         get { return selectCommand; }
116                         set { selectCommand = value; }
117                 }
118
119                 [DataCategory ("Update")]
120 #if !NET_2_0
121                 [DataSysDescription ("Used during Update for modified rows in DataSet.")]
122 #endif
123                 [DefaultValue (null)]
124                 [EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
125                 public new SqlCommand UpdateCommand {
126                         get { return updateCommand; }
127                         set { updateCommand = value; }
128                 }
129
130                 IDbCommand IDbDataAdapter.DeleteCommand {
131                         get { return DeleteCommand; }
132                         set { 
133                                 if (!(value is SqlCommand)) 
134                                         throw new ArgumentException ();
135                                 DeleteCommand = (SqlCommand)value;
136                         }
137                 }
138
139                 IDbCommand IDbDataAdapter.InsertCommand {
140                         get { return InsertCommand; }
141                         set { 
142                                 if (!(value is SqlCommand)) 
143                                         throw new ArgumentException ();
144                                 InsertCommand = (SqlCommand)value;
145                         }
146                 }
147
148                 IDbCommand IDbDataAdapter.SelectCommand {
149                         get { return SelectCommand; }
150                         set { 
151                                 if (!(value is SqlCommand)) 
152                                         throw new ArgumentException ();
153                                 SelectCommand = (SqlCommand)value;
154                         }
155                 }
156
157                 IDbCommand IDbDataAdapter.UpdateCommand {
158                         get { return UpdateCommand; }
159                         set { 
160                                 if (!(value is SqlCommand)) 
161                                         throw new ArgumentException ();
162                                 UpdateCommand = (SqlCommand)value;
163                         }
164                 }
165
166
167                 ITableMappingCollection IDataAdapter.TableMappings {
168                         get { return TableMappings; }
169                 }
170
171                 #endregion // Properties
172
173                 #region Methods
174
175                 protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
176                 {
177                         return new SqlRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
178                 }
179
180
181                 protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
182                 {
183                         return new SqlRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
184                 }
185
186                 protected override void Dispose (bool disposing)
187                 {
188                         if (!disposed) {
189                                 if (disposing) {
190                                         // Release managed resources
191                                 }
192                                 // Release unmanaged resources
193                                 disposed = true;
194                         }
195                 }
196
197                 protected override void OnRowUpdated (RowUpdatedEventArgs value) 
198                 {
199                         if (RowUpdated != null)
200                                 RowUpdated (this, (SqlRowUpdatedEventArgs) value);
201                 }
202
203                 protected override void OnRowUpdating (RowUpdatingEventArgs value) 
204                 {
205                         if (RowUpdating != null)
206                                 RowUpdating (this, (SqlRowUpdatingEventArgs) value);
207                 }
208
209                 #endregion // Methods
210
211                 #region Events and Delegates
212
213                 [DataCategory ("Update")]
214 #if !NET_2_0
215                 [DataSysDescription ("Event triggered before every DataRow during Update.")]
216 #endif
217                 public event SqlRowUpdatedEventHandler RowUpdated;
218
219                 [DataCategory ("Update")]
220 #if !NET_2_0
221                 [DataSysDescription ("Event triggered after every DataRow during Update.")]
222 #endif
223                 public event SqlRowUpdatingEventHandler RowUpdating;
224
225                 #endregion // Events and Delegates
226
227         }
228 }