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 IntPtr statementHandle;
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);
74 #endregion // Constructors
78 public string CommandText {
79 get { return commandText; }
80 set { commandText = value; }
83 public CommandType CommandType {
84 get { return commandType; }
85 set { commandType = value; }
88 public OracleConnection Connection {
89 get { return connection; }
90 set { connection = value; }
93 public bool DesignTimeVisible {
94 get { return designTimeVisible; }
95 set { designTimeVisible = value; }
98 int IDbCommand.CommandTimeout {
99 get { throw new InvalidOperationException (); }
100 set { throw new InvalidOperationException (); }
103 IDbConnection IDbCommand.Connection {
104 get { return Connection; }
106 if (!(value is OracleConnection))
107 throw new InvalidCastException ("The value was not a valid OracleConnection.");
108 Connection = (OracleConnection) value;
112 IDataParameterCollection IDbCommand.Parameters {
113 get { return Parameters; }
116 IDbTransaction IDbCommand.Transaction {
117 get { return Transaction; }
119 if (!(value is OracleTransaction))
120 throw new ArgumentException ();
121 Transaction = (OracleTransaction) value;
125 public OracleParameterCollection Parameters {
126 get { return parameters; }
129 public OracleTransaction Transaction {
130 get { return transaction; }
131 set { transaction = value; }
134 public UpdateRowSource UpdatedRowSource {
135 get { return updatedRowSource; }
136 set { updatedRowSource = value; }
144 public void Cancel ()
146 throw new NotImplementedException ();
150 public object Clone ()
152 throw new NotImplementedException ();
156 [MonoTODO("Still need to Dispose correctly")]
157 public new void Dispose ()
160 if (statementHandle != IntPtr.Zero) {
161 OciGlue.OCIHandleFree (statementHandle, OciHandleType.Statement);
162 statementHandle = IntPtr.Zero;
168 [MonoTODO("still need to Finalize correctly")]
174 internal void CloseDataReader ()
176 Connection.DataReader = null;
177 if ((behavior & CommandBehavior.CloseConnection) != 0)
181 public OracleParameter CreateParameter ()
183 return new OracleParameter ();
186 public int ExecuteNonQuery ()
188 int rowsAffected = -1;
190 ValidateCommand ("ExecuteNonQuery");
191 statementHandle = Connection.Oci.PrepareStatement (CommandText);
192 statementType = Connection.Oci.GetStatementType (statementHandle);
193 Connection.Oci.ExecuteStatement (statementHandle, statementType);
199 public int ExecuteOracleNonQuery (out OracleString rowid)
201 throw new NotImplementedException ();
205 public object ExecuteOracleScalar ()
207 throw new NotImplementedException ();
210 public OracleDataReader ExecuteReader ()
212 return ExecuteReader (CommandBehavior.Default);
216 public OracleDataReader ExecuteReader (CommandBehavior behavior)
218 throw new NotImplementedException ();
222 public object ExecuteScalar ()
224 throw new NotImplementedException ();
227 IDbDataParameter IDbCommand.CreateParameter ()
229 return CreateParameter ();
232 IDataReader IDbCommand.ExecuteReader ()
234 return ExecuteReader ();
237 IDataReader IDbCommand.ExecuteReader (CommandBehavior behavior)
239 return ExecuteReader (behavior);
243 public void Prepare ()
245 throw new NotImplementedException ();
248 private void ValidateCommand (string method)
250 if (Connection == null)
251 throw new InvalidOperationException (String.Format ("{0} requires a Connection object to continue.", method));
252 if (Connection.Transaction != null && Transaction != Connection.Transaction)
253 throw new InvalidOperationException ("The Connection object does not have the same transaction as the command object.");
254 if (Connection.State != ConnectionState.Open)
255 throw new InvalidOperationException (String.Format ("{0} requires an open Connection object to continue. This connection is closed.", method));
256 if (CommandText == String.Empty || CommandText == null)
257 throw new InvalidOperationException ("The command text for this Command has not been set.");
258 if (Connection.DataReader != null)
259 throw new InvalidOperationException ("There is already an open DataReader associated with this Connection which must be closed first.");
262 #endregion // Methods