2 // OciStatementHandle.cs
4 // Part of managed C#/.NET library System.Data.OracleClient.dll
6 // Part of the Mono class libraries at
7 // mcs/class/System.Data.OracleClient/System.Data.OracleClient.Oci
9 // Assembly: System.Data.OracleClient.dll
10 // Namespace: System.Data.OracleClient.Oci
13 // Tim Coleman <tim@timcoleman.com>
14 // Daniel Morgan <danielmorgan@verizon.net>
16 // Copyright (C) Tim Coleman, 2003
17 // Copyright (C) Daniel Morgan, 2005
21 using System.Collections;
22 using System.Runtime.InteropServices;
24 namespace System.Data.OracleClient.Oci {
25 internal sealed class OciStatementHandle : OciHandle, IDisposable
30 bool disposed = false;
31 OciErrorHandle errorHandle;
33 OciServiceHandle serviceHandle;
36 OracleCommand command;
42 public OciStatementHandle (OciHandle parent, IntPtr handle)
43 : base (OciHandleType.Statement, parent, handle)
48 #endregion // Constructors
52 public int ColumnCount {
53 get { return columnCount; }
56 public OciErrorHandle ErrorHandle {
57 get { return errorHandle; }
58 set { errorHandle = value; }
61 public OciServiceHandle Service {
62 get { return serviceHandle; }
63 set { serviceHandle = value; }
66 public ArrayList Values {
67 get { return values; }
70 public OracleCommand Command {
71 get { return command; }
72 set { command = value; }
75 #endregion // Properties
79 protected override void Dispose (bool disposing)
86 foreach (OciDefineHandle h in values)
91 base.Dispose (disposing);
95 public OciParameterDescriptor GetParameter (int position)
97 IntPtr handle = IntPtr.Zero;
100 status = OciCalls.OCIParamGet (this,
101 OciHandleType.Statement,
107 OciErrorInfo info = ErrorHandle.HandleError ();
108 throw new OracleException (info.ErrorCode, info.ErrorMessage);
111 OciParameterDescriptor output = new OciParameterDescriptor (this, handle);
112 output.ErrorHandle = ErrorHandle;
114 parm = new ArrayList();
119 public OciDefineHandle GetDefineHandle (int position, OracleConnection connection)
121 OciDefineHandle defineHandle = new OciDefineHandle (this, IntPtr.Zero);
122 defineHandle.ErrorHandle = ErrorHandle;
123 defineHandle.DefineByPosition (position, connection);
130 Define (command.Connection);
133 void Define (OracleConnection connection)
135 values = new ArrayList ();
136 for (int i = 0; i < columnCount; i += 1)
137 values.Add (GetDefineHandle (i, connection));
140 public bool ExecuteQuery (bool schemaOnly)
142 return Execute (false, false, schemaOnly);
145 public bool ExecuteNonQuery (bool useAutoCommit)
147 return Execute (true, useAutoCommit, false);
150 public bool Execute (bool nonQuery, bool useAutoCommit, bool schemaOnly)
158 executeMode = (int)OciExecuteMode.CommitOnSuccess;
161 executeMode = (int)OciExecuteMode.DescribeOnly;
163 executeMode = (int)OciExecuteMode.Default;
168 throw new InvalidOperationException ("StatementHandle is already disposed.");
171 status = OciCalls.OCIStmtExecute (Service,
178 (OciExecuteMode)executeMode);
181 case OciGlue.OCI_DEFAULT:
188 case OciGlue.OCI_NO_DATA:
190 case OciGlue.OCI_INVALID_HANDLE:
191 throw new OracleException (0, "Invalid handle.");
193 OciErrorInfo info = ErrorHandle.HandleError ();
194 throw new OracleException (info.ErrorCode, info.ErrorMessage);
199 internal void SetupRefCursorResult (OracleConnection connection)
206 void GetColumnCount ()
208 columnCount = GetAttributeInt32 (OciAttributeType.ParameterCount, ErrorHandle);
211 public OciStatementType GetStatementType ()
213 return (OciStatementType) GetAttributeUInt16 (OciAttributeType.StatementType, ErrorHandle);
222 throw new InvalidOperationException ("StatementHandle is already disposed.");
225 status = OciCalls.OCIStmtFetch (Handle,
232 case OciGlue.OCI_NO_DATA:
234 foreach (IntPtr h in parm)
235 OciCalls.OCIDescriptorFree(h, OciHandleType.Parameter);
237 case OciGlue.OCI_DEFAULT:
240 case OciGlue.OCI_SUCCESS_WITH_INFO:
241 //OciErrorInfo ei = ErrorHandle.HandleError ();
242 //command.Connection.CreateInfoMessage (ei);
246 OciErrorInfo info = ErrorHandle.HandleError ();
247 throw new OracleException (info.ErrorCode, info.ErrorMessage);
253 public void Prepare (string commandText)
258 throw new InvalidOperationException ("StatementHandle is already disposed.");
264 // Get size of buffer
265 OciCalls.OCIUnicodeToCharSet (Parent, null, commandText, out rsize);
268 buffer = new byte[rsize];
269 OciCalls.OCIUnicodeToCharSet (Parent, buffer, commandText, out rsize);
272 status = OciCalls.OCIStmtPrepare (this,
276 OciStatementLanguage.NTV,
277 OciStatementMode.Default);
280 OciErrorInfo info = ErrorHandle.HandleError ();
281 throw new OracleException (info.ErrorCode, info.ErrorMessage);
285 #endregion // Methods