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;
35 OracleCommand command;
41 public OciStatementHandle (OciHandle parent, IntPtr handle)
42 : base (OciHandleType.Statement, parent, handle)
47 #endregion // Constructors
51 public int ColumnCount {
52 get { return columnCount; }
55 public OciErrorHandle ErrorHandle {
56 get { return errorHandle; }
57 set { errorHandle = value; }
60 public OciServiceHandle Service {
61 get { return serviceHandle; }
62 set { serviceHandle = value; }
65 public ArrayList Values {
66 get { return values; }
69 public OracleCommand Command {
70 get { return command; }
71 set { command = value; }
74 #endregion // Properties
78 protected override void Dispose (bool disposing)
85 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;
116 public OciDefineHandle GetDefineHandle (int position)
118 OciDefineHandle defineHandle = new OciDefineHandle (this, IntPtr.Zero);
119 defineHandle.ErrorHandle = ErrorHandle;
120 defineHandle.DefineByPosition (position);
127 values = new ArrayList ();
128 for (int i = 0; i < columnCount; i += 1)
129 values.Add (GetDefineHandle (i));
132 public bool ExecuteQuery (bool schemaOnly)
134 return Execute (false, false, schemaOnly);
137 public bool ExecuteNonQuery (bool useAutoCommit)
139 return Execute (true, useAutoCommit, false);
142 public bool Execute (bool nonQuery, bool useAutoCommit, bool schemaOnly)
150 executeMode = (int)OciExecuteMode.CommitOnSuccess;
153 executeMode = (int)OciExecuteMode.DescribeOnly;
155 executeMode = (int)OciExecuteMode.Default;
158 if (this.disposed)
\r
160 throw new InvalidOperationException ("StatementHandle is already disposed.");
163 status = OciCalls.OCIStmtExecute (Service,
170 (OciExecuteMode)executeMode);
173 case OciGlue.OCI_DEFAULT:
180 case OciGlue.OCI_NO_DATA:
182 case OciGlue.OCI_INVALID_HANDLE:
183 throw new OracleException (0, "Invalid handle.");
185 OciErrorInfo info = ErrorHandle.HandleError ();
186 throw new OracleException (info.ErrorCode, info.ErrorMessage);
191 internal void SetupRefCursorResult ()
198 void GetColumnCount ()
200 columnCount = GetAttributeInt32 (OciAttributeType.ParameterCount, ErrorHandle);
203 public OciStatementType GetStatementType ()
205 return (OciStatementType) GetAttributeUInt16 (OciAttributeType.StatementType, ErrorHandle);
212 if (this.disposed)
\r
214 throw new InvalidOperationException ("StatementHandle is already disposed.");
217 status = OciCalls.OCIStmtFetch (Handle,
224 case OciGlue.OCI_NO_DATA:
227 case OciGlue.OCI_DEFAULT:
230 case OciGlue.OCI_SUCCESS_WITH_INFO:
\r
231 //OciErrorInfo ei = ErrorHandle.HandleError ();
\r
232 //command.Connection.CreateInfoMessage (ei);
\r
233 moreResults = true;
\r
236 OciErrorInfo info = ErrorHandle.HandleError ();
237 throw new OracleException (info.ErrorCode, info.ErrorMessage);
243 public void Prepare (string commandText)
248 throw new InvalidOperationException ("StatementHandle is already disposed.");
254 // Get size of buffer
255 OciCalls.OCIUnicodeToCharSet (Parent, null, commandText, out rsize);
258 buffer = new byte[rsize];
259 OciCalls.OCIUnicodeToCharSet (Parent, buffer, commandText, out rsize);
262 status = OciCalls.OCIStmtPrepare (this,
266 OciStatementLanguage.NTV,
267 OciStatementMode.Default);
270 OciErrorInfo info = ErrorHandle.HandleError ();
271 throw new OracleException (info.ErrorCode, info.ErrorMessage);
275 #endregion // Methods