1 // created on 1/8/2002 at 23:02
3 // Npgsql.NpgsqlDataAdapter.cs
6 // Francisco Jr. (fxjrlists@yahoo.com.br)
8 // Copyright (C) 2002 The Npgsql Development Team
9 // npgsql-general@gborg.postgresql.org
10 // http://gborg.postgresql.org/project/npgsql/projdisplay.php
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2.1 of the License, or (at your option) any later version.
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 using System
.Data
.Common
;
30 using System
.Resources
;
35 /// Represents the method that handles the <see cref="Npgsql.NpgsqlDataAdapter.RowUpdated">RowUpdated</see> events.
37 /// <param name="sender">The source of the event.</param>
38 /// <param name="e">A <see cref="Npgsql.NpgsqlRowUpdatedEventArgs">NpgsqlRowUpdatedEventArgs</see> that contains the event data.</param>
39 public delegate void NpgsqlRowUpdatedEventHandler(Object sender
, NpgsqlRowUpdatedEventArgs e
);
42 /// Represents the method that handles the <see cref="Npgsql.NpgsqlDataAdapter.RowUpdating">RowUpdating</see> events.
44 /// <param name="sender">The source of the event.</param>
45 /// <param name="e">A <see cref="Npgsql.NpgsqlRowUpdatingEventArgs">NpgsqlRowUpdatingEventArgs</see> that contains the event data.</param>
46 public delegate void NpgsqlRowUpdatingEventHandler(Object sender
, NpgsqlRowUpdatingEventArgs e
);
50 /// This class represents an adapter from many commands: select, update, insert and delete to fill <see cref="System.Data.DataSet">Datasets.</see>
52 public sealed class NpgsqlDataAdapter
: DbDataAdapter
, IDbDataAdapter
55 private NpgsqlCommand _selectCommand
;
56 private NpgsqlCommand _updateCommand
;
57 private NpgsqlCommand _deleteCommand
;
58 private NpgsqlCommand _insertCommand
;
61 private static readonly String CLASSNAME
= "NpgsqlDataAdapter";
64 public event NpgsqlRowUpdatedEventHandler RowUpdated
;
65 public event NpgsqlRowUpdatingEventHandler RowUpdating
;
67 public NpgsqlDataAdapter()
70 public NpgsqlDataAdapter(NpgsqlCommand selectCommand
)
72 NpgsqlEventLog
.LogMethodEnter(LogLevel
.Debug
, CLASSNAME
, CLASSNAME
);
73 _selectCommand
= selectCommand
;
76 public NpgsqlDataAdapter(String selectCommandText
, NpgsqlConnection selectConnection
) : this(new NpgsqlCommand(selectCommandText
, selectConnection
))
79 public NpgsqlDataAdapter(String selectCommandText
, String selectConnectionString
) : this(selectCommandText
, new NpgsqlConnection(selectConnectionString
))
83 protected override RowUpdatedEventArgs
CreateRowUpdatedEvent(
86 StatementType statementType
,
87 DataTableMapping tableMapping
90 NpgsqlEventLog
.LogMethodEnter(LogLevel
.Debug
, CLASSNAME
, "CreateRowUpdatedEvent");
91 return new NpgsqlRowUpdatedEventArgs(dataRow
, command
, statementType
, tableMapping
);
97 protected override RowUpdatingEventArgs
CreateRowUpdatingEvent(
100 StatementType statementType
,
101 DataTableMapping tableMapping
104 NpgsqlEventLog
.LogMethodEnter(LogLevel
.Debug
, CLASSNAME
, "CreateRowUpdatingEvent");
105 return new NpgsqlRowUpdatingEventArgs(dataRow
, command
, statementType
, tableMapping
);
108 protected override void OnRowUpdated(
109 RowUpdatedEventArgs
value
112 NpgsqlEventLog
.LogMethodEnter(LogLevel
.Debug
, CLASSNAME
, "OnRowUpdated");
113 //base.OnRowUpdated(value);
114 if ((RowUpdated
!= null) && (value is NpgsqlRowUpdatedEventArgs
))
115 RowUpdated(this, (NpgsqlRowUpdatedEventArgs
) value);
119 protected override void OnRowUpdating(
120 RowUpdatingEventArgs
value
123 NpgsqlEventLog
.LogMethodEnter(LogLevel
.Debug
, CLASSNAME
, "OnRowUpdating");
124 if ((RowUpdating
!= null) && (value is NpgsqlRowUpdatingEventArgs
))
125 RowUpdating(this, (NpgsqlRowUpdatingEventArgs
) value);
128 ITableMappingCollection IDataAdapter
.TableMappings
132 return TableMappings
;
136 IDbCommand IDbDataAdapter
.DeleteCommand
140 NpgsqlEventLog
.LogPropertyGet(LogLevel
.Debug
, CLASSNAME
, "IDbDataAdapter.DeleteCommand");
141 return (NpgsqlCommand
) DeleteCommand
;
146 DeleteCommand
= (NpgsqlCommand
) value;
151 public NpgsqlCommand DeleteCommand
155 return _deleteCommand
;
160 _deleteCommand
= value;
164 IDbCommand IDbDataAdapter
.SelectCommand
168 return (NpgsqlCommand
) SelectCommand
;
173 SelectCommand
= (NpgsqlCommand
) value;
178 public NpgsqlCommand SelectCommand
182 return _selectCommand
;
187 _selectCommand
= value;
191 IDbCommand IDbDataAdapter
.UpdateCommand
195 NpgsqlEventLog
.LogPropertyGet(LogLevel
.Debug
, CLASSNAME
, "IDbDataAdapter.UpdateCommand");
196 return (NpgsqlCommand
) UpdateCommand
;
201 UpdateCommand
= (NpgsqlCommand
) value;
206 public NpgsqlCommand UpdateCommand
210 return _updateCommand
;
215 _updateCommand
= value;
219 IDbCommand IDbDataAdapter
.InsertCommand
223 return (NpgsqlCommand
) InsertCommand
;
228 InsertCommand
= (NpgsqlCommand
) value;
233 public NpgsqlCommand InsertCommand
237 NpgsqlEventLog
.LogPropertyGet(LogLevel
.Debug
, CLASSNAME
, "InsertCommand");
238 return _insertCommand
;
243 _insertCommand
= value;
252 public class NpgsqlRowUpdatingEventArgs
: RowUpdatingEventArgs
254 public NpgsqlRowUpdatingEventArgs (
257 StatementType statementType
,
258 DataTableMapping tableMapping
259 ) : base(dataRow
, command
, statementType
, tableMapping
)
265 public class NpgsqlRowUpdatedEventArgs
: RowUpdatedEventArgs
267 public NpgsqlRowUpdatedEventArgs (
270 StatementType statementType
,
271 DataTableMapping tableMapping
272 ) : base(dataRow
, command
, statementType
, tableMapping
)