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