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;
44 public OracleCommand ()
45 : this (String.Empty, null, null)
49 public OracleCommand (string commandText)
50 : this (commandText, null, null)
54 public OracleCommand (string commandText, OracleConnection connection)
55 : this (commandText, connection, null)
59 public OracleCommand (string commandText, OracleConnection connection, OracleTransaction tx)
61 this.commandText = commandText;
62 this.connection = connection;
63 this.transaction = tx;
64 this.commandType = CommandType.Text;
65 this.updatedRowSource = UpdateRowSource.Both;
66 this.designTimeVisible = false;
67 parameters = new OracleParameterCollection (this);
71 #endregion // Constructors
75 public string CommandText {
76 get { return commandText; }
77 set { commandText = value; }
80 public CommandType CommandType {
81 get { return commandType; }
82 set { commandType = value; }
85 public OracleConnection Connection {
86 get { return connection; }
87 set { connection = value; }
90 public bool DesignTimeVisible {
91 get { return designTimeVisible; }
92 set { designTimeVisible = value; }
95 int IDbCommand.CommandTimeout {
96 get { throw new InvalidOperationException (); }
97 set { throw new InvalidOperationException (); }
100 IDbConnection IDbCommand.Connection {
101 get { return Connection; }
103 if (!(value is OracleConnection))
104 throw new InvalidCastException ("The value was not a valid OracleConnection.");
105 Connection = (OracleConnection) value;
109 IDataParameterCollection IDbCommand.Parameters {
110 get { return Parameters; }
113 IDbTransaction IDbCommand.Transaction {
114 get { return Transaction; }
116 if (!(value is OracleTransaction))
117 throw new ArgumentException ();
118 Transaction = (OracleTransaction) value;
122 public OracleParameterCollection Parameters {
123 get { return parameters; }
126 public OracleTransaction Transaction {
127 get { return transaction; }
128 set { transaction = value; }
131 public UpdateRowSource UpdatedRowSource {
132 get { return updatedRowSource; }
133 set { updatedRowSource = value; }
141 public void Cancel ()
143 throw new NotImplementedException ();
147 public object Clone ()
149 throw new NotImplementedException ();
152 internal void CloseDataReader ()
154 Connection.DataReader = null;
155 if ((behavior & CommandBehavior.CloseConnection) != 0)
159 public OracleParameter CreateParameter ()
161 return new OracleParameter ();
164 public int ExecuteNonQuery ()
166 int rowsAffected = -1;
168 ValidateCommand ("ExecuteNonQuery");
171 status = connection.Oci.PrepareAndExecuteNonQuerySimple (commandText);
174 statusText = connection.Oci.CheckStatus(status);
179 throw new Exception(msg);
186 public int ExecuteOracleNonQuery (out OracleString rowid)
188 throw new NotImplementedException ();
192 public object ExecuteOracleScalar ()
194 throw new NotImplementedException ();
197 public OracleDataReader ExecuteReader ()
199 return ExecuteReader (CommandBehavior.Default);
203 public OracleDataReader ExecuteReader (CommandBehavior behavior)
205 throw new NotImplementedException ();
209 public object ExecuteScalar ()
211 throw new NotImplementedException ();
214 IDbDataParameter IDbCommand.CreateParameter ()
216 return CreateParameter ();
219 IDataReader IDbCommand.ExecuteReader ()
221 return ExecuteReader ();
224 IDataReader IDbCommand.ExecuteReader (CommandBehavior behavior)
226 return ExecuteReader (behavior);
230 public void Prepare ()
232 throw new NotImplementedException ();
235 private void ValidateCommand (string method)
237 if (Connection == null)
238 throw new InvalidOperationException (String.Format ("{0} requires a Connection object to continue.", method));
239 if (Connection.Transaction != null && Transaction != Connection.Transaction)
240 throw new InvalidOperationException ("The Connection object does not have the same transaction as the command object.");
241 if (Connection.State != ConnectionState.Open)
242 throw new InvalidOperationException (String.Format ("{0} requires an open Connection object to continue. This connection is closed.", method));
243 if (CommandText == String.Empty || CommandText == null)
244 throw new InvalidOperationException ("The command text for this Command has not been set.");
245 if (Connection.DataReader != null)
246 throw new InvalidOperationException ("There is already an open DataReader associated with this Connection which must be closed first.");
249 #endregion // Methods