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;
42 public OleDbCommand ()
44 commandText = String.Empty;
45 timeout = 30; // default timeout per .NET
46 commandType = CommandType.Text;
48 parameters = new OleDbParameterCollection ();
50 designTimeVisible = false;
52 behavior = CommandBehavior.Default;
53 gdaCommand = IntPtr.Zero;
54 gdaResults = new ArrayList ();
57 public OleDbCommand (string cmdText)
60 CommandText = cmdText;
63 public OleDbCommand (string cmdText, OleDbConnection connection)
66 Connection = connection;
69 public OleDbCommand (string cmdText, OleDbConnection connection, OleDbTransaction transaction)
70 : this (cmdText, connection)
72 this.transaction = transaction;
75 #endregion // Constructors
79 public string CommandText
81 get { return commandText; }
87 public int CommandTimeout {
88 get { return timeout; }
89 set { timeout = value; }
92 public CommandType CommandType {
93 get { return commandType; }
94 set { commandType = value; }
97 public OleDbConnection Connection {
98 get { return connection; }
99 set { connection = value; }
102 public bool DesignTimeVisible {
103 get { return designTimeVisible; }
104 set { designTimeVisible = value; }
107 public OleDbParameterCollection Parameters {
108 get { return parameters; }
109 set { parameters = value; }
112 public OleDbTransaction Transaction {
113 get { return transaction; }
114 set { transaction = value; }
117 public UpdateRowSource UpdatedRowSource {
119 get { throw new NotImplementedException (); }
121 set { throw new NotImplementedException (); }
124 IDbConnection IDbCommand.Connection {
125 get { return Connection; }
126 set { Connection = (OleDbConnection) value; }
129 IDataParameterCollection IDbCommand.Parameters {
130 get { return Parameters; }
133 IDbTransaction IDbCommand.Transaction {
134 get { return Transaction; }
135 set { Transaction = (OleDbTransaction) value; }
138 internal ArrayList GdaResults {
139 get { return gdaResults; }
142 #endregion // Properties
147 public void Cancel ()
149 throw new NotImplementedException ();
152 public OleDbParameter CreateParameter ()
154 return new OleDbParameter ();
157 IDbDataParameter IDbCommand.CreateParameter ()
159 return CreateParameter ();
163 protected override void Dispose (bool disposing)
165 throw new NotImplementedException ();
168 private void SetupGdaCommand ()
172 switch (commandType) {
173 case CommandType.TableDirect :
174 type = GdaCommandType.Table;
176 case CommandType.StoredProcedure :
177 type = GdaCommandType.Procedure;
179 case CommandType.Text :
181 type = GdaCommandType.Sql;
185 if (gdaCommand != IntPtr.Zero) {
186 libgda.gda_command_set_text (gdaCommand, commandText);
187 libgda.gda_command_set_command_type (gdaCommand, type);
189 gdaCommand = libgda.gda_command_new (commandText, type, 0);
192 //libgda.gda_command_set_transaction
195 public int ExecuteNonQuery ()
197 if (connection == null)
198 throw new InvalidOperationException ();
199 if (connection.State == ConnectionState.Closed)
200 throw new InvalidOperationException ();
201 // FIXME: a third check is mentioned in .NET docs
203 IntPtr gdaConnection = connection.GdaConnection;
204 IntPtr gdaParameterList = parameters.GdaParameterList;
207 return libgda.gda_connection_execute_non_query (gdaConnection, (IntPtr) gdaCommand, gdaParameterList);
210 public OleDbDataReader ExecuteReader ()
212 return ExecuteReader (CommandBehavior.Default);
215 IDataReader IDbCommand.ExecuteReader ()
217 return ExecuteReader ();
220 public OleDbDataReader ExecuteReader (CommandBehavior behavior)
222 if (connection.State != ConnectionState.Open)
223 throw new InvalidOperationException ();
225 this.behavior = behavior;
227 IntPtr gdaConnection = connection.GdaConnection;
228 IntPtr gdaParameterList = parameters.GdaParameterList;
230 /* FIXME: split all returned resultsets into
231 our internal GdaResults */
232 GdaResults.Add (libgda.gda_connection_execute_command (
237 dataReader = new OleDbDataReader (this);
238 dataReader.NextResult ();
243 IDataReader IDbCommand.ExecuteReader (CommandBehavior behavior)
245 return ExecuteReader (behavior);
249 public object ExecuteScalar ()
251 throw new NotImplementedException ();
255 object ICloneable.Clone ()
257 throw new NotImplementedException ();
261 public void Prepare ()
263 throw new NotImplementedException ();
266 public void ResetCommandTimeout ()
273 #region Internal Methods
275 // only meant to be used between OleDbConnection,
276 // OleDbCommand, and OleDbDataReader
277 internal void OpenReader (OleDbDataReader reader)
279 connection.OpenReader (reader);