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