New test.
[mono.git] / mcs / class / Mono.Data.SqliteClient / Mono.Data.SqliteClient / SqliteDataAdapter.cs
1 //
2 // Mono.Data.SqliteClient.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
10 //
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.
29 //
30
31 using System;
32 using System.Data;
33 using System.Data.Common;
34 using System.Collections;
35 using System.Text;
36
37 namespace Mono.Data.SqliteClient
38 {
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
44         {
45                 #region Fields
46                 
47                 private IDbCommand _deleteCommand;
48                 private IDbCommand _insertCommand;
49                 private IDbCommand _selectCommand;
50                 private IDbCommand _updateCommand;
51                 
52                 #endregion
53
54                 #region Public Events
55                 
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;
62                 
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;
69                 
70                 #endregion
71
72                 #region Contructors
73                 
74                 /// <summary>
75                 /// Initializes a new instance of the <see cref="SqliteDataAdapter">SqliteDataAdapter</see> class.
76                 /// </summary>
77                 public SqliteDataAdapter() 
78                 {
79                 }
80                 
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) 
87                 {
88                         SelectCommand = selectCommand;
89                 }
90                 
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)
98                 {
99                         IDbCommand cmd = connection.CreateCommand();
100                         cmd.CommandText = selectCommandText;
101                         SelectCommand = cmd;
102                 }
103                 
104                 /// <summary>
105                 /// Initializes a new instance of the <see cref="SqliteDataAdapter">SqliteDataAdapter</see> class 
106                 /// with a SelectCommand and a connection string.
107                 /// </summary>
108                 /// <param name="selectCommandText"></param>
109                 /// <param name="connectionString"></param>
110                 public SqliteDataAdapter(string selectCommandText, string connectionString) : this(selectCommandText ,new SqliteConnection(connectionString))
111                 {
112                 }
113                 
114                 #endregion
115
116                 #region Public Properties
117                 
118                 /// <summary>
119                 /// Gets or sets a Transact-SQL statement or stored procedure to delete 
120                 /// records from the data set.
121                 /// </summary>
122                 public IDbCommand DeleteCommand {
123                         get { return _deleteCommand; }
124                         set { _deleteCommand = value; }
125                 }
126                 
127                 /// <summary>
128                 /// Gets or sets a Transact-SQL statement or stored procedure to insert 
129                 /// new records into the data source.
130                 /// </summary>
131                 public IDbCommand InsertCommand {
132                         get { return _insertCommand; }
133                         set { _insertCommand = value; }
134                 }
135                 
136                 /// <summary>
137                 /// Gets or sets a Transact-SQL statement or stored procedure used to 
138                 /// select records in the data source.
139                 /// </summary>
140                 public IDbCommand SelectCommand {
141                         get { return _selectCommand; }
142                         set { _selectCommand = value; }
143                 }
144                 
145                 /// <summary>
146                 /// Gets or sets a Transact-SQL statement or stored procedure used to 
147                 /// update records in the data source.
148                 /// </summary>
149                 public IDbCommand UpdateCommand {
150                         get { return _updateCommand; }
151                         set { _updateCommand = value; }
152                 }
153                 
154                 #endregion
155
156                 #region Protected Methods
157                 
158                 /// <summary>
159                 /// Initializes a new instance of the <see cref="RowUpdatedEventArgs">RowUpdatedEventArgs</see> class.
160                 /// </summary>
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)
167                 {
168                         return new SqliteRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
169                 }
170                 
171                 /// <summary>
172                 /// 
173                 /// </summary>
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)
180                 {
181                         return new SqliteRowUpdatingEventArgs(dataRow, command, statementType, tableMapping);
182                 }
183                 
184                 /// <summary>
185                 /// Raises the RowUpdated event of a Sqlite data provider.
186                 /// </summary>
187                 /// <param name="args">A RowUpdatedEventArgs that contains the event data.</param>
188                 protected override void OnRowUpdating (RowUpdatingEventArgs args)
189                 {
190                         if (RowUpdating != null)
191                                 RowUpdating(this, args);
192                 }
193                 
194                 /// <summary>
195                 /// Raises the RowUpdating event of Sqlite data provider.
196                 /// </summary>
197                 /// <param name="args">An RowUpdatingEventArgs that contains the event data.</param>
198                 protected override void OnRowUpdated (RowUpdatedEventArgs args)
199                 {
200                         if (RowUpdated != null)
201                                 RowUpdated(this, args);
202                 }
203                 
204                 #endregion
205         }
206 }