2010-06-21 Marek Habersack <mhabersack@novell.com>
[mcs.git] / class / Mono.Data.Sqlite / Mono.Data.Sqlite / SqliteDataAdapter.cs
blobea21ed9ca099c711712528c0e1d504bdfe053514
1 //
2 // Mono.Data.Sqlite.SqliteDataAdapter.cs
3 //
4 // Represents a set of data commands and a database connection that are used
5 // to fill the DataSet and update the data source.
6 //
7 // Author(s): Everaldo Canuto <everaldo_canuto@yahoo.com.br>
8 //
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:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
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.
30 #if !NET_2_0
31 using System;
32 using System.Data;
33 using System.Data.Common;
34 using System.Collections;
35 using System.Text;
37 namespace Mono.Data.Sqlite
39 /// <summary>
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.
42 /// </summary>
43 public class SqliteDataAdapter : DbDataAdapter, IDbDataAdapter
45 #region Fields
47 private IDbCommand _deleteCommand;
48 private IDbCommand _insertCommand;
49 private IDbCommand _selectCommand;
50 private IDbCommand _updateCommand;
52 #endregion
54 #region Public Events
56 /// <summary>
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.
60 /// </summary>
61 public event SqliteRowUpdatedEventHandler RowUpdated;
63 /// <summary>
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.
67 /// </summary>
68 public event SqliteRowUpdatingEventHandler RowUpdating;
70 #endregion
72 #region Contructors
74 /// <summary>
75 /// Initializes a new instance of the <see cref="SqliteDataAdapter">SqliteDataAdapter</see> class.
76 /// </summary>
77 public SqliteDataAdapter()
81 /// <summary>
82 /// Initializes a new instance of the <see cref="SqliteDataAdapter">SqliteDataAdapter</see> class
83 /// with the specified SqliteCommand as the SelectCommand property.
84 /// </summary>
85 /// <param name="selectCommand"></param>
86 public SqliteDataAdapter(IDbCommand selectCommand)
88 SelectCommand = selectCommand;
91 /// <summary>
92 /// Initializes a new instance of the <see cref="SqliteDataAdapter">SqliteDataAdapter</see> class
93 /// with a SelectCommand and a SqliteConnection object.
94 /// </summary>
95 /// <param name="selectCommandText"></param>
96 /// <param name="connection"></param>
97 public SqliteDataAdapter(string selectCommandText, SqliteConnection connection)
99 IDbCommand cmd;
101 cmd = connection.CreateCommand();
102 cmd.CommandText = selectCommandText;
103 SelectCommand = cmd;
106 /// <summary>
107 /// Initializes a new instance of the <see cref="SqliteDataAdapter">SqliteDataAdapter</see> class
108 /// with a SelectCommand and a connection string.
109 /// </summary>
110 /// <param name="selectCommandText"></param>
111 /// <param name="connectionString"></param>
112 public SqliteDataAdapter(string selectCommandText, string connectionString) : this(selectCommandText ,new SqliteConnection(connectionString))
116 #endregion
118 #region Public Properties
120 /// <summary>
121 /// Gets or sets a Transact-SQL statement or stored procedure to delete
122 /// records from the data set.
123 /// </summary>
124 public IDbCommand DeleteCommand {
125 get { return _deleteCommand; }
126 set { _deleteCommand = value; }
129 /// <summary>
130 /// Gets or sets a Transact-SQL statement or stored procedure to insert
131 /// new records into the data source.
132 /// </summary>
133 public IDbCommand InsertCommand {
134 get { return _insertCommand; }
135 set { _insertCommand = value; }
138 /// <summary>
139 /// Gets or sets a Transact-SQL statement or stored procedure used to
140 /// select records in the data source.
141 /// </summary>
142 public IDbCommand SelectCommand {
143 get { return _selectCommand; }
144 set { _selectCommand = value; }
147 /// <summary>
148 /// Gets or sets a Transact-SQL statement or stored procedure used to
149 /// update records in the data source.
150 /// </summary>
151 public IDbCommand UpdateCommand {
152 get { return _updateCommand; }
153 set { _updateCommand = value; }
156 #endregion
158 #region Protected Methods
160 /// <summary>
161 /// Initializes a new instance of the <see cref="RowUpdatedEventArgs">RowUpdatedEventArgs</see> class.
162 /// </summary>
163 /// <param name="dataRow">The DataRow used to update the data source.</param>
164 /// <param name="command">The IDbCommand executed during the Update.</param>
165 /// <param name="statementType">Whether the command is an UPDATE, INSERT, DELETE, or SELECT statement.</param>
166 /// <param name="tableMapping">A DataTableMapping object.</param>
167 /// <returns></returns>
168 protected override RowUpdatedEventArgs CreateRowUpdatedEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
170 return new SqliteRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
173 /// <summary>
174 ///
175 /// </summary>
176 /// <param name="dataRow">The DataRow used to update the data source.</param>
177 /// <param name="command">The IDbCommand executed during the Update.</param>
178 /// <param name="statementType">Whether the command is an UPDATE, INSERT, DELETE, or SELECT statement.</param>
179 /// <param name="tableMapping">A DataTableMapping object.</param>
180 /// <returns></returns>
181 protected override RowUpdatingEventArgs CreateRowUpdatingEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping)
183 return new SqliteRowUpdatingEventArgs(dataRow, command, statementType, tableMapping);
186 /// <summary>
187 /// Raises the RowUpdated event of a Sqlite data provider.
188 /// </summary>
189 /// <param name="args">A RowUpdatedEventArgs that contains the event data.</param>
190 protected override void OnRowUpdating (RowUpdatingEventArgs args)
192 if (RowUpdating != null)
193 RowUpdating(this, args);
196 /// <summary>
197 /// Raises the RowUpdating event of Sqlite data provider.
198 /// </summary>
199 /// <param name="args">An RowUpdatingEventArgs that contains the event data.</param>
200 protected override void OnRowUpdated (RowUpdatedEventArgs args)
202 if (RowUpdated != null)
203 RowUpdated(this, args);
206 #endregion
209 #endif