2 // System.Data.OleDb.OleDbCommand
5 // Rodrigo Moya (rodrigo@ximian.com)
6 // Tim Coleman (tim@timcoleman.com)
8 // Copyright (C) Rodrigo Moya, 2002
9 // Copyright (C) Tim Coleman, 2002
12 using System.ComponentModel;
14 using System.Data.Common;
15 using System.Collections;
17 namespace System.Data.OleDb
20 /// Represents an SQL statement or stored procedure to execute against a data source.
22 public sealed class OleDbCommand : Component, ICloneable, IDbCommand
28 CommandType commandType;
29 OleDbConnection connection;
30 OleDbParameterCollection parameters;
31 OleDbTransaction transaction;
32 bool designTimeVisible;
33 OleDbDataReader dataReader;
34 CommandBehavior behavior;
41 public OleDbCommand ()
43 commandText = String.Empty;
44 timeout = 30; // default timeout per .NET
45 commandType = CommandType.Text;
47 parameters = new OleDbParameterCollection ();
49 designTimeVisible = false;
51 behavior = CommandBehavior.Default;
52 gdaCommand = IntPtr.Zero;
55 public OleDbCommand (string cmdText)
58 CommandText = cmdText;
61 public OleDbCommand (string cmdText, OleDbConnection connection)
64 Connection = connection;
67 public OleDbCommand (string cmdText, OleDbConnection connection, OleDbTransaction transaction)
68 : this (cmdText, connection)
70 this.transaction = transaction;
73 #endregion // Constructors
77 public string CommandText
87 public int CommandTimeout {
96 public CommandType CommandType {
105 public OleDbConnection Connection {
114 public bool DesignTimeVisible {
116 return designTimeVisible;
119 designTimeVisible = value;
123 public OleDbParameterCollection Parameters {
132 public OleDbTransaction Transaction {
141 public UpdateRowSource UpdatedRowSource {
144 throw new NotImplementedException ();
148 throw new NotImplementedException ();
152 IDbConnection IDbCommand.Connection {
157 Connection = (OleDbConnection) value;
161 IDataParameterCollection IDbCommand.Parameters {
167 IDbTransaction IDbCommand.Transaction {
172 Transaction = (OleDbTransaction) value;
176 #endregion // Properties
181 public void Cancel ()
183 throw new NotImplementedException ();
186 public OleDbParameter CreateParameter ()
188 return new OleDbParameter ();
191 IDbDataParameter IDbCommand.CreateParameter ()
193 return CreateParameter ();
197 protected override void Dispose (bool disposing)
199 throw new NotImplementedException ();
202 private void SetupGdaCommand ()
206 switch (commandType) {
207 case CommandType.TableDirect :
208 type = GdaCommandType.Table;
210 case CommandType.StoredProcedure :
211 type = GdaCommandType.Procedure;
213 case CommandType.Text :
215 type = GdaCommandType.Sql;
219 if (gdaCommand != IntPtr.Zero) {
220 libgda.gda_command_set_text (gdaCommand, commandText);
221 libgda.gda_command_set_command_type (gdaCommand, type);
223 gdaCommand = libgda.gda_command_new (commandText, type, 0);
226 //libgda.gda_command_set_transaction
229 public int ExecuteNonQuery ()
231 if (connection == null)
232 throw new InvalidOperationException ();
233 if (connection.State == ConnectionState.Closed)
234 throw new InvalidOperationException ();
235 // FIXME: a third check is mentioned in .NET docs
237 IntPtr gdaConnection = connection.GdaConnection;
238 IntPtr gdaParameterList = parameters.GdaParameterList;
241 return libgda.gda_connection_execute_non_query (gdaConnection,
246 public OleDbDataReader ExecuteReader ()
248 return ExecuteReader (CommandBehavior.Default);
251 IDataReader IDbCommand.ExecuteReader ()
253 return ExecuteReader ();
256 public OleDbDataReader ExecuteReader (CommandBehavior behavior)
258 ArrayList results = new ArrayList ();
260 if (connection.State != ConnectionState.Open)
261 throw new InvalidOperationException ();
263 this.behavior = behavior;
265 IntPtr gdaConnection = connection.GdaConnection;
266 IntPtr gdaParameterList = parameters.GdaParameterList;
269 /* FIXME: split all returned resultsets into the array
271 results.Add (libgda.gda_connection_execute_command (
276 dataReader = new OleDbDataReader (this, results);
277 dataReader.NextResult ();
282 IDataReader IDbCommand.ExecuteReader (CommandBehavior behavior)
284 return ExecuteReader (behavior);
287 public object ExecuteScalar ()
290 OleDbDataReader reader = ExecuteReader ();
291 return reader.GetValue (0);
295 object ICloneable.Clone ()
297 throw new NotImplementedException ();
301 public void Prepare ()
303 throw new NotImplementedException ();
306 public void ResetCommandTimeout ()