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 ();
155 internal void CloseDataReader ()
157 Connection.DataReader = null;
158 if ((behavior & CommandBehavior.CloseConnection) != 0)
162 public OracleParameter CreateParameter ()
164 return new OracleParameter ();
167 public int ExecuteNonQuery ()
169 int rowsAffected = -1;
171 ValidateCommand ("ExecuteNonQuery");
172 statementHandle = Connection.Oci.PrepareStatement (CommandText);
173 statementType = Connection.Oci.GetStatementType (statementHandle);
174 Connection.Oci.ExecuteStatement (statementHandle, statementType);
178 status = connection.Oci.PrepareAndExecuteNonQuerySimple (commandText);
181 statusText = connection.Oci.CheckStatus(status);
186 throw new Exception(msg);
194 public int ExecuteOracleNonQuery (out OracleString rowid)
196 throw new NotImplementedException ();
200 public object ExecuteOracleScalar ()
202 throw new NotImplementedException ();
205 public OracleDataReader ExecuteReader ()
207 return ExecuteReader (CommandBehavior.Default);
211 public OracleDataReader ExecuteReader (CommandBehavior behavior)
213 throw new NotImplementedException ();
217 public object ExecuteScalar ()
219 throw new NotImplementedException ();
222 IDbDataParameter IDbCommand.CreateParameter ()
224 return CreateParameter ();
227 IDataReader IDbCommand.ExecuteReader ()
229 return ExecuteReader ();
232 IDataReader IDbCommand.ExecuteReader (CommandBehavior behavior)
234 return ExecuteReader (behavior);
238 public void Prepare ()
240 throw new NotImplementedException ();
243 private void ValidateCommand (string method)
245 if (Connection == null)
246 throw new InvalidOperationException (String.Format ("{0} requires a Connection object to continue.", method));
247 if (Connection.Transaction != null && Transaction != Connection.Transaction)
248 throw new InvalidOperationException ("The Connection object does not have the same transaction as the command object.");
249 if (Connection.State != ConnectionState.Open)
250 throw new InvalidOperationException (String.Format ("{0} requires an open Connection object to continue. This connection is closed.", method));
251 if (CommandText == String.Empty || CommandText == null)
252 throw new InvalidOperationException ("The command text for this Command has not been set.");
253 if (Connection.DataReader != null)
254 throw new InvalidOperationException ("There is already an open DataReader associated with this Connection which must be closed first.");
257 #endregion // Methods