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;
35 ArrayList gdaCommands;
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 gdaCommands = new ArrayList ();
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; }
83 string[] queries = value.Split (new Char[] {';'});
86 foreach (string query in queries)
87 gdaCommands.Add (libgda.gda_command_new (query, 0, 0));
93 public int CommandTimeout {
94 get { return timeout; }
95 set { timeout = value; }
98 public CommandType CommandType {
99 get { return commandType; }
100 set { commandType = value; }
103 public OleDbConnection Connection {
104 get { return connection; }
105 set { connection = value; }
108 public bool DesignTimeVisible {
109 get { return designTimeVisible; }
110 set { designTimeVisible = value; }
113 public OleDbParameterCollection Parameters {
114 get { return parameters; }
115 set { parameters = value; }
118 public OleDbTransaction Transaction {
119 get { return transaction; }
120 set { transaction = value; }
123 public UpdateRowSource UpdatedRowSource {
125 get { throw new NotImplementedException (); }
127 set { throw new NotImplementedException (); }
130 IDbConnection IDbCommand.Connection {
131 get { return Connection; }
132 set { Connection = (OleDbConnection) value; }
135 IDataParameterCollection IDbCommand.Parameters {
136 get { return Parameters; }
139 IDbTransaction IDbCommand.Transaction {
140 get { return Transaction; }
141 set { Transaction = (OleDbTransaction) value; }
144 internal ArrayList GdaResults {
145 get { return gdaResults; }
148 #endregion // Properties
153 public void Cancel ()
155 throw new NotImplementedException ();
158 public OleDbParameter CreateParameter ()
160 return new OleDbParameter ();
164 protected override void Dispose (bool disposing)
166 throw new NotImplementedException ();
169 public int ExecuteNonQuery ()
171 if (connection == null)
172 throw new InvalidOperationException ();
173 if (connection.State == ConnectionState.Closed)
174 throw new InvalidOperationException ();
175 // FIXME: a third check is mentioned in .NET docs
177 IntPtr gdaConnection = connection.GdaConnection;
178 IntPtr gdaParameterList = parameters.GdaParameterList;
180 return libgda.gda_connection_execute_non_query (gdaConnection, (IntPtr) gdaCommands[0], gdaParameterList);
183 public OleDbDataReader ExecuteReader ()
185 return ExecuteReader (CommandBehavior.Default);
188 public OleDbDataReader ExecuteReader (CommandBehavior behavior)
190 if (connection.State != ConnectionState.Open)
191 throw new InvalidOperationException ();
193 this.behavior = behavior;
195 IntPtr gdaConnection = connection.GdaConnection;
196 IntPtr gdaParameterList = parameters.GdaParameterList;
198 foreach (IntPtr gdaCommand in gdaCommands)
199 GdaResults.Add (libgda.gda_connection_execute_single_command (gdaConnection, gdaCommand, gdaParameterList));
201 dataReader = new OleDbDataReader (this);
203 dataReader.NextResult ();
209 public object ExecuteScalar ()
211 throw new NotImplementedException ();
215 object ICloneable.Clone ()
217 throw new NotImplementedException ();
221 IDbDataParameter IDbCommand.CreateParameter ()
223 throw new NotImplementedException ();
227 IDataReader IDbCommand.ExecuteReader ()
229 throw new NotImplementedException ();
233 IDataReader IDbCommand.ExecuteReader (CommandBehavior behavior)
235 throw new NotImplementedException ();
239 public void Prepare ()
241 throw new NotImplementedException ();
244 public void ResetCommandTimeout ()
251 #region Internal Methods
253 // only meant to be used between OleDbConnectioin,
254 // OleDbCommand, and OleDbDataReader
255 internal void OpenReader (OleDbDataReader reader)
257 connection.OpenReader (reader);