4 // Part of the Mono class libraries at
5 // mcs/class/System.Data.OracleClient/System.Data.OracleClient
7 // Assembly: System.Data.OracleClient.dll
8 // Namespace: System.Data.OracleClient
11 // Daniel Morgan <danmorg@sc.rr.com>
12 // Tim Coleman <tim@timcoleman.com>
14 // Copyright (C) Daniel Morgan, 2002
15 // Copyright (C) Tim Coleman , 2003
17 // Licensed under the MIT/X11 License.
21 using System.ComponentModel;
23 using System.Data.OracleClient.Oci;
25 namespace System.Data.OracleClient {
26 public class OracleCommand : Component, ICloneable, IDbCommand
30 bool disposed = false;
31 CommandBehavior behavior;
33 CommandType commandType;
34 OracleConnection connection;
35 bool designTimeVisible;
36 OracleParameterCollection parameters;
37 OracleTransaction transaction;
38 UpdateRowSource updatedRowSource;
40 OciStatementHandle statement;
41 OciStatementType statementType;
47 public OracleCommand ()
48 : this (String.Empty, null, null)
52 public OracleCommand (string commandText)
53 : this (commandText, null, null)
57 public OracleCommand (string commandText, OracleConnection connection)
58 : this (commandText, connection, null)
62 public OracleCommand (string commandText, OracleConnection connection, OracleTransaction tx)
64 this.commandText = commandText;
65 this.connection = connection;
66 this.transaction = tx;
67 this.commandType = CommandType.Text;
68 this.updatedRowSource = UpdateRowSource.Both;
69 this.designTimeVisible = false;
70 parameters = new OracleParameterCollection (this);
73 #endregion // Constructors
77 public string CommandText {
78 get { return commandText; }
79 set { commandText = value; }
82 public CommandType CommandType {
83 get { return commandType; }
84 set { commandType = value; }
87 public OracleConnection Connection {
88 get { return connection; }
89 set { connection = value; }
92 public bool DesignTimeVisible {
93 get { return designTimeVisible; }
94 set { designTimeVisible = value; }
97 int IDbCommand.CommandTimeout {
98 get { throw new InvalidOperationException (); }
99 set { throw new InvalidOperationException (); }
102 IDbConnection IDbCommand.Connection {
103 get { return Connection; }
105 if (!(value is OracleConnection))
106 throw new InvalidCastException ("The value was not a valid OracleConnection.");
107 Connection = (OracleConnection) value;
111 IDataParameterCollection IDbCommand.Parameters {
112 get { return Parameters; }
115 IDbTransaction IDbCommand.Transaction {
116 get { return Transaction; }
118 if (!(value is OracleTransaction))
119 throw new ArgumentException ();
120 Transaction = (OracleTransaction) value;
124 public OracleParameterCollection Parameters {
125 get { return parameters; }
128 internal OciStatementHandle StatementHandle {
129 get { return statement; }
132 public OracleTransaction Transaction {
133 get { return transaction; }
134 set { transaction = value; }
137 public UpdateRowSource UpdatedRowSource {
138 get { return updatedRowSource; }
139 set { updatedRowSource = value; }
147 public void Cancel ()
149 throw new NotImplementedException ();
153 public object Clone ()
155 throw new NotImplementedException ();
159 [MonoTODO("Still need to Dispose correctly")]
160 public new void Dispose ()
163 if (statementHandle != IntPtr.Zero) {
164 OciGlue.OCIHandleFree (statementHandle, OciHandleType.Statement);
165 statementHandle = IntPtr.Zero;
171 [MonoTODO("still need to Finalize correctly")]
177 internal void CloseDataReader ()
179 Connection.DataReader = null;
180 if ((behavior & CommandBehavior.CloseConnection) != 0)
184 public OracleParameter CreateParameter ()
186 return new OracleParameter ();
189 public int ExecuteNonQuery ()
191 int rowsAffected = -1;
193 ValidateCommand ("ExecuteNonQuery");
194 statement = Connection.Oci.CreateStatement ();
195 statement.Prepare (CommandText);
196 statement.ExecuteNonQuery ();
202 public int ExecuteOracleNonQuery (out OracleString rowid)
204 throw new NotImplementedException ();
208 public object ExecuteOracleScalar ()
210 throw new NotImplementedException ();
213 public OracleDataReader ExecuteReader ()
215 return ExecuteReader (CommandBehavior.Default);
218 public OracleDataReader ExecuteReader (CommandBehavior behavior)
220 statement = Connection.Oci.CreateStatement ();
221 statement.Prepare (CommandText);
222 statement.ExecuteQuery ();
223 return new OracleDataReader (this);
227 public object ExecuteScalar ()
229 throw new NotImplementedException ();
232 IDbDataParameter IDbCommand.CreateParameter ()
234 return CreateParameter ();
237 IDataReader IDbCommand.ExecuteReader ()
239 return ExecuteReader ();
242 IDataReader IDbCommand.ExecuteReader (CommandBehavior behavior)
244 return ExecuteReader (behavior);
248 public void Prepare ()
250 throw new NotImplementedException ();
253 private void ValidateCommand (string method)
255 if (Connection == null)
256 throw new InvalidOperationException (String.Format ("{0} requires a Connection object to continue.", method));
257 if (Connection.Transaction != null && Transaction != Connection.Transaction)
258 throw new InvalidOperationException ("The Connection object does not have the same transaction as the command object.");
259 if (Connection.State != ConnectionState.Open)
260 throw new InvalidOperationException (String.Format ("{0} requires an open Connection object to continue. This connection is closed.", method));
261 if (CommandText == String.Empty || CommandText == null)
262 throw new InvalidOperationException ("The command text for this Command has not been set.");
263 if (Connection.DataReader != null)
264 throw new InvalidOperationException ("There is already an open DataReader associated with this Connection which must be closed first.");
267 #endregion // Methods