Replace SIZEOF_REGISTER with sizeof(mgreg_t) for consistency with sizeof(gpointer)
[mono.git] / mcs / class / Mono.Data.Sqlite / Mono.Data.Sqlite / SqliteDataAdapter.cs
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
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 #if !NET_2_0
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.Sqlite
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;
100
101                         cmd = connection.CreateCommand();
102                         cmd.CommandText = selectCommandText;
103                         SelectCommand = cmd;
104                 }
105                 
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))
113                 {
114                 }
115                 
116                 #endregion
117
118                 #region Public Properties
119                 
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; }
127                 }
128                 
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; }
136                 }
137                 
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; }
145                 }
146                 
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; }
154                 }
155
156                 #endregion
157
158                 #region Protected Methods
159                 
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)
169                 {
170                         return new SqliteRowUpdatedEventArgs (dataRow, command, statementType, tableMapping);
171                 }
172                 
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)
182                 {
183                         return new SqliteRowUpdatingEventArgs(dataRow, command, statementType, tableMapping);
184                 }
185                 
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)
191                 {
192                         if (RowUpdating != null)
193                                 RowUpdating(this, args);
194                 }
195                 
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)
201                 {
202                         if (RowUpdated != null)
203                                 RowUpdated(this, args);
204                 }
205                 
206                 #endregion
207         }
208 }
209 #endif