2 // Mono.Data.SqliteClient.SqliteDataAdapter.cs
4 // Represents a set of data commands and a database connection that are used
5 // to fill the DataSet and update the data source.
7 // Author(s): Everaldo Canuto <everaldo_canuto@yahoo.com.br>
9 // Copyright (C) 2004 Everaldo Canuto
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System
.Data
.Common
;
34 using System
.Collections
;
37 namespace Mono
.Data
.SqliteClient
40 /// Represents a set of data commands and a database connection that are used
41 /// to fill the <see cref="DataSet">DataSet</see> and update the data source.
43 public class SqliteDataAdapter
: DbDataAdapter
, IDbDataAdapter
47 private IDbCommand _deleteCommand
;
48 private IDbCommand _insertCommand
;
49 private IDbCommand _selectCommand
;
50 private IDbCommand _updateCommand
;
57 /// Occurs during <see cref="DbDataAdapter.Update">Update</see> after a
58 /// command is executed against the data source. The attempt to update
59 /// is made, so the event fires.
61 public event SqliteRowUpdatedEventHandler RowUpdated
;
64 /// Occurs during <see cref="DbDataAdapter.Update">Update</see> before a
65 /// command is executed against the data source. The attempt to update
66 /// is made, so the event fires.
68 public event SqliteRowUpdatingEventHandler RowUpdating
;
75 /// Initializes a new instance of the <see cref="SqliteDataAdapter">SqliteDataAdapter</see> class.
77 public SqliteDataAdapter()
82 /// Initializes a new instance of the <see cref="SqliteDataAdapter">SqliteDataAdapter</see> class
83 /// with the specified SqliteCommand as the SelectCommand property.
85 /// <param name="selectCommand"></param>
86 public SqliteDataAdapter(IDbCommand selectCommand
)
88 SelectCommand
= selectCommand
;
92 /// Initializes a new instance of the <see cref="SqliteDataAdapter">SqliteDataAdapter</see> class
93 /// with a SelectCommand and a SqliteConnection object.
95 /// <param name="selectCommandText"></param>
96 /// <param name="connection"></param>
97 public SqliteDataAdapter(string selectCommandText
, SqliteConnection connection
)
99 IDbCommand cmd
= connection
.CreateCommand();
100 cmd
.CommandText
= selectCommandText
;
105 /// Initializes a new instance of the <see cref="SqliteDataAdapter">SqliteDataAdapter</see> class
106 /// with a SelectCommand and a connection string.
108 /// <param name="selectCommandText"></param>
109 /// <param name="connectionString"></param>
110 public SqliteDataAdapter(string selectCommandText
, string connectionString
) : this(selectCommandText
,new SqliteConnection(connectionString
))
116 #region Public Properties
119 /// Gets or sets a Transact-SQL statement or stored procedure to delete
120 /// records from the data set.
122 public IDbCommand DeleteCommand
{
123 get { return _deleteCommand; }
124 set { _deleteCommand = value; }
128 /// Gets or sets a Transact-SQL statement or stored procedure to insert
129 /// new records into the data source.
131 public IDbCommand InsertCommand
{
132 get { return _insertCommand; }
133 set { _insertCommand = value; }
137 /// Gets or sets a Transact-SQL statement or stored procedure used to
138 /// select records in the data source.
140 public IDbCommand SelectCommand
{
141 get { return _selectCommand; }
142 set { _selectCommand = value; }
146 /// Gets or sets a Transact-SQL statement or stored procedure used to
147 /// update records in the data source.
149 public IDbCommand UpdateCommand
{
150 get { return _updateCommand; }
151 set { _updateCommand = value; }
156 #region Protected Methods
159 /// Initializes a new instance of the <see cref="RowUpdatedEventArgs">RowUpdatedEventArgs</see> class.
161 /// <param name="dataRow">The DataRow used to update the data source.</param>
162 /// <param name="command">The IDbCommand executed during the Update.</param>
163 /// <param name="statementType">Whether the command is an UPDATE, INSERT, DELETE, or SELECT statement.</param>
164 /// <param name="tableMapping">A DataTableMapping object.</param>
165 /// <returns></returns>
166 protected override RowUpdatedEventArgs
CreateRowUpdatedEvent(DataRow dataRow
, IDbCommand command
, StatementType statementType
, DataTableMapping tableMapping
)
168 return new SqliteRowUpdatedEventArgs (dataRow
, command
, statementType
, tableMapping
);
174 /// <param name="dataRow">The DataRow used to update the data source.</param>
175 /// <param name="command">The IDbCommand executed during the Update.</param>
176 /// <param name="statementType">Whether the command is an UPDATE, INSERT, DELETE, or SELECT statement.</param>
177 /// <param name="tableMapping">A DataTableMapping object.</param>
178 /// <returns></returns>
179 protected override RowUpdatingEventArgs
CreateRowUpdatingEvent(DataRow dataRow
, IDbCommand command
, StatementType statementType
, DataTableMapping tableMapping
)
181 return new SqliteRowUpdatingEventArgs(dataRow
, command
, statementType
, tableMapping
);
185 /// Raises the RowUpdated event of a Sqlite data provider.
187 /// <param name="args">A RowUpdatedEventArgs that contains the event data.</param>
188 protected override void OnRowUpdating (RowUpdatingEventArgs args
)
190 if (RowUpdating
!= null)
191 RowUpdating(this, args
);
195 /// Raises the RowUpdating event of Sqlite data provider.
197 /// <param name="args">An RowUpdatingEventArgs that contains the event data.</param>
198 protected override void OnRowUpdated (RowUpdatedEventArgs args
)
200 if (RowUpdated
!= null)
201 RowUpdated(this, args
);