New test.
[mono.git] / mcs / tools / sqlsharp / gui / gtk-sharp / SqlSharpDataAdapter.cs
1 //
2 // SqlSharpDataAdapter.cs - data adapter for SQL#
3 //                          but uses a data reader 
4 //                          as the source of data
5 //
6 // based on
7 // System.Data.SqlSharpClient.SqlSharpDataAdapter.cs
8 // in Mono http://www.go-mono.com/
9 //
10 // Author:
11 //   Rodrigo Moya (rodrigo@ximian.com)
12 //   Daniel Morgan (danielmorgan@verizon.net)
13 //   Tim Coleman (tim@timcoleman.com)
14 //
15 // (C) Ximian, Inc 2002
16 // Copyright (C) 2002 Tim Coleman
17 // Copyright (C) 2002, 2003 Daniel Morgan
18 //
19
20 using System;
21 using System.ComponentModel;
22 using System.Data;
23 using System.Data.Common;
24
25 namespace Mono.Data.SqlSharp 
26 {
27         [DefaultEvent ("RowUpdated")]
28         public sealed class SqlSharpDataAdapter : DbDataAdapter, IDbDataAdapter 
29         {
30                 #region Fields
31
32                 bool disposed = false;  
33                 IDbCommand deleteCommand;
34                 IDbCommand insertCommand;
35                 IDbCommand selectCommand;
36                 IDbCommand updateCommand;
37
38                 #endregion
39
40                 #region Constructors
41                 
42                 public SqlSharpDataAdapter ()   
43                 {
44                 }
45
46                 public SqlSharpDataAdapter (IDbCommand selectCommand) 
47                 {
48                         DeleteCommand = null;
49                         InsertCommand = null;
50                         SelectCommand = selectCommand;
51                         UpdateCommand = null;
52                 }
53
54                 #endregion
55
56                 #region Properties
57
58 //              [DataCategory ("Update")]
59                 [DataSysDescription ("Used during Update for deleted rows in DataSet.")]
60                 [DefaultValue (null)]
61                 public IDbCommand DeleteCommand {
62                         get { return deleteCommand; }
63                         set { deleteCommand = value; }
64                 }
65
66 //              [DataCategory ("Update")]
67                 [DataSysDescription ("Used during Update for new rows in DataSet.")]
68                 [DefaultValue (null)]
69                 public IDbCommand InsertCommand {
70                         get { return insertCommand; }
71                         set { insertCommand = value; }
72                 }
73
74 //              [DataCategory ("Fill")]
75                 [DataSysDescription ("Used during Fill/FillSchema.")]
76                 [DefaultValue (null)]
77                 public IDbCommand SelectCommand {
78                         get { return selectCommand; }
79                         set { selectCommand = value; }
80                 }
81
82 //              [DataCategory ("Update")]
83                 [DataSysDescription ("Used during Update for modified rows in DataSet.")]
84                 [DefaultValue (null)]
85                 public IDbCommand UpdateCommand {
86                         get { return updateCommand; }
87                         set { updateCommand = value; }
88                 }
89
90                 IDbCommand IDbDataAdapter.DeleteCommand {
91                         get { return DeleteCommand; }
92                         set { 
93                                 DeleteCommand = value;
94                         }
95                 }
96
97                 IDbCommand IDbDataAdapter.InsertCommand {
98                         get { return InsertCommand; }
99                         set { 
100                                 InsertCommand = value;
101                         }
102                 }
103
104                 IDbCommand IDbDataAdapter.SelectCommand {
105                         get { return SelectCommand; }
106                         set { 
107                                 SelectCommand = value;
108                         }
109                 }
110
111                 IDbCommand IDbDataAdapter.UpdateCommand {
112                         get { return UpdateCommand; }
113                         set { 
114                                 UpdateCommand = value;
115                         }
116                 }
117
118
119                 ITableMappingCollection IDataAdapter.TableMappings {
120                         get { return TableMappings; }
121                 }
122
123                 #endregion // Properties
124
125                 #region Methods
126
127                 protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
128                 {
129                         return new SqlSharpRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
130                 }
131
132
133                 protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
134                 {
135                         return new SqlSharpRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
136                 }
137
138                 protected override void Dispose (bool disposing)
139                 {
140                         if (!disposed) {
141                                 if (disposing) {
142                                         // Release managed resources
143                                 }
144                                 // Release unmanaged resources
145                                 disposed = true;
146                         }
147                 }
148
149                 protected override void OnRowUpdated (RowUpdatedEventArgs value) 
150                 {
151                         if (RowUpdated != null)
152                                 RowUpdated (this, (SqlSharpRowUpdatedEventArgs) value);
153                 }
154
155                 protected override void OnRowUpdating (RowUpdatingEventArgs value) 
156                 {
157                         if (RowUpdating != null)
158                                 RowUpdating (this, (SqlSharpRowUpdatingEventArgs) value);
159                 }
160                 
161                 public int FillTable (DataTable dataTable, IDataReader dataReader) 
162                 {
163                         return base.Fill (dataTable, dataReader);
164                 }
165
166                 #endregion // Methods
167
168                 #region Events and Delegates
169
170 //              [DataCategory ("Update")]
171                 [DataSysDescription ("Event triggered before every DataRow during Update.")]
172                 public event SqlSharpRowUpdatedEventHandler RowUpdated;
173
174 //              [DataCategory ("Update")]
175                 [DataSysDescription ("Event triggered after every DataRow during Update.")]
176                 public event SqlSharpRowUpdatingEventHandler RowUpdating;
177
178                 #endregion // Events and Delegates
179         }
180
181         public sealed class SqlSharpRowUpdatedEventArgs : RowUpdatedEventArgs {
182                 #region Constructors
183
184                 public SqlSharpRowUpdatedEventArgs (DataRow row, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
185                         : base (row, command, statementType, tableMapping) {
186                 }
187
188                 #endregion // Constructors
189
190                 #region Properties
191
192                 public new IDbCommand Command {
193                         get { return base.Command; }
194                 }
195
196                 #endregion // Properties
197         }
198
199         public delegate void SqlSharpRowUpdatedEventHandler (object sender, SqlSharpRowUpdatedEventArgs e);
200
201         public sealed class SqlSharpRowUpdatingEventArgs : RowUpdatingEventArgs {
202                 #region Constructors
203
204                 public SqlSharpRowUpdatingEventArgs (DataRow row, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
205                         : base (row, command, statementType, tableMapping) {
206                 }
207
208                 #endregion // Constructors
209
210                 #region Properties
211
212                 public new IDbCommand Command {
213                         get { return base.Command; }
214                         set { base.Command = value; }
215                 }
216
217                 #endregion // Properties
218         }
219
220         public delegate void SqlSharpRowUpdatingEventHandler(object sender, SqlSharpRowUpdatingEventArgs e);
221
222 }
223