Files to build with the mono runtime.
[mono.git] / mcs / class / Mono.Data.PostgreSqlClient / PgSqlDataAdapter.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 using System;
14 using System.ComponentModel;
15 using System.Data;
16 using System.Data.Common;
17
18 namespace System.Data.SqlClient
19 {
20         /// <summary>
21         /// Represents a set of command-related properties that are used 
22         /// to fill the DataSet and update a data source, all this 
23         /// from a SQL database.
24         /// </summary>
25         public sealed class SqlDataAdapter : DbDataAdapter, IDbDataAdapter 
26         {
27                 #region Fields
28         
29                 SqlCommand deleteCommand;
30                 SqlCommand insertCommand;
31                 SqlCommand selectCommand;
32                 SqlCommand updateCommand;
33
34                 static readonly object EventRowUpdated = new object(); 
35                 static readonly object EventRowUpdating = new object(); 
36
37                 #endregion
38
39                 #region Constructors
40                 
41                 public SqlDataAdapter ()        
42                         : this (new SqlCommand ())
43                 {
44                 }
45
46                 public SqlDataAdapter (SqlCommand selectCommand) 
47                 {
48                         DeleteCommand = new SqlCommand ();
49                         InsertCommand = new SqlCommand ();
50                         SelectCommand = selectCommand;
51                         UpdateCommand = new SqlCommand ();
52                 }
53
54                 public SqlDataAdapter (string selectCommandText, SqlConnection selectConnection) 
55                         : this (new SqlCommand (selectCommandText, selectConnection))
56                 { 
57                 }
58
59                 public SqlDataAdapter (string selectCommandText, string selectConnectionString)
60                         : this (selectCommandText, new SqlConnection (selectConnectionString))
61                 {
62                 }
63
64                 #endregion
65
66                 #region Properties
67
68                 public new SqlCommand DeleteCommand {
69                         get { return deleteCommand; }
70                         set { deleteCommand = value; }
71                 }
72
73                 public new SqlCommand InsertCommand {
74                         get { return insertCommand; }
75                         set { insertCommand = value; }
76                 }
77
78                 public new SqlCommand SelectCommand {
79                         get { return selectCommand; }
80                         set { selectCommand = value; }
81                 }
82
83                 public new SqlCommand UpdateCommand {
84                         get { return updateCommand; }
85                         set { updateCommand = value; }
86                 }
87
88                 IDbCommand IDbDataAdapter.DeleteCommand {
89                         get { return DeleteCommand; }
90                         set { 
91                                 if (!(value is SqlCommand)) 
92                                         throw new ArgumentException ();
93                                 DeleteCommand = (SqlCommand)value;
94                         }
95                 }
96
97                 IDbCommand IDbDataAdapter.InsertCommand {
98                         get { return InsertCommand; }
99                         set { 
100                                 if (!(value is SqlCommand)) 
101                                         throw new ArgumentException ();
102                                 InsertCommand = (SqlCommand)value;
103                         }
104                 }
105
106                 IDbCommand IDbDataAdapter.SelectCommand {
107                         get { return SelectCommand; }
108                         set { 
109                                 if (!(value is SqlCommand)) 
110                                         throw new ArgumentException ();
111                                 SelectCommand = (SqlCommand)value;
112                         }
113                 }
114
115                 IDbCommand IDbDataAdapter.UpdateCommand {
116                         get { return UpdateCommand; }
117                         set { 
118                                 if (!(value is SqlCommand)) 
119                                         throw new ArgumentException ();
120                                 UpdateCommand = (SqlCommand)value;
121                         }
122                 }
123
124
125                 ITableMappingCollection IDataAdapter.TableMappings {
126                         get { return TableMappings; }
127                 }
128
129                 #endregion // Properties
130
131                 #region Methods
132
133                 protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
134                 {
135                         return new SqlRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
136                 }
137
138
139                 protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) 
140                 {
141                         return new SqlRowUpdatingEventArgs (dataRow, command, statementType, tableMapping);
142                 }
143
144                 protected override void OnRowUpdated (RowUpdatedEventArgs value) 
145                 {
146                         SqlRowUpdatedEventHandler handler = (SqlRowUpdatedEventHandler) Events[EventRowUpdated];
147                         if ((handler != null) && (value is SqlRowUpdatedEventArgs))
148                                 handler(this, (SqlRowUpdatedEventArgs) value);
149                 }
150
151                 protected override void OnRowUpdating (RowUpdatingEventArgs value) 
152                 {
153                         SqlRowUpdatingEventHandler handler = (SqlRowUpdatingEventHandler) Events[EventRowUpdating];
154                         if ((handler != null) && (value is SqlRowUpdatingEventArgs))
155                                 handler(this, (SqlRowUpdatingEventArgs) value);
156                 }
157
158                 #endregion // Methods
159
160                 #region Events and Delegates
161
162                 public event SqlRowUpdatedEventHandler RowUpdated {
163                         add { Events.AddHandler (EventRowUpdated, value); }
164                         remove { Events.RemoveHandler (EventRowUpdated, value); }
165                 }
166
167                 public event SqlRowUpdatingEventHandler RowUpdating {
168                         add { Events.AddHandler (EventRowUpdating, value); }
169                         remove { Events.RemoveHandler (EventRowUpdating, value); }
170                 }
171
172                 #endregion // Events and Delegates
173
174         }
175 }