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>
15 // Copyright (C) Tim Coleman, 2003
19 using System.Collections;
20 using System.Runtime.InteropServices;
22 namespace System.Data.OracleClient.Oci {
23 internal sealed class OciStatementHandle : OciHandle, IDisposable
28 bool disposed = false;
29 OciErrorHandle errorHandle;
31 OciServiceHandle serviceHandle;
33 OracleCommand command;
39 public OciStatementHandle (OciHandle parent, IntPtr handle)
40 : base (OciHandleType.Statement, parent, handle)
45 #endregion // Constructors
49 public int ColumnCount {
50 get { return columnCount; }
53 public OciErrorHandle ErrorHandle {
54 get { return errorHandle; }
55 set { errorHandle = value; }
58 public OciServiceHandle Service {
59 get { return serviceHandle; }
60 set { serviceHandle = value; }
63 public ArrayList Values {
64 get { return values; }
67 public OracleCommand Command {
68 get { return command; }
69 set { command = value; }
72 #endregion // Properties
76 protected override void Dispose (bool disposing)
83 foreach (OciDefineHandle h in values)
89 base.Dispose (disposing);
93 public OciParameterDescriptor GetParameter (int position)
95 IntPtr handle = IntPtr.Zero;
98 status = OciCalls.OCIParamGet (this,
99 OciHandleType.Statement,
105 OciErrorInfo info = ErrorHandle.HandleError ();
106 throw new OracleException (info.ErrorCode, info.ErrorMessage);
109 OciParameterDescriptor output = new OciParameterDescriptor (this, handle);
110 output.ErrorHandle = ErrorHandle;
114 public OciDefineHandle GetDefineHandle (int position)
116 OciDefineHandle defineHandle = new OciDefineHandle (this, IntPtr.Zero);
117 defineHandle.ErrorHandle = ErrorHandle;
118 defineHandle.DefineByPosition (position);
125 values = new ArrayList ();
126 for (int i = 0; i < columnCount; i += 1)
127 values.Add (GetDefineHandle (i));
130 public bool ExecuteQuery ()
132 return Execute (false,false);
135 public bool ExecuteNonQuery (bool useAutoCommit)
137 return Execute (true, useAutoCommit);
140 public bool Execute (bool nonQuery, bool useAutoCommit)
148 executeMode = (int)OciExecuteMode.CommitOnSuccess;
150 executeMode = (int)OciExecuteMode.Default;
152 if (this.disposed)
\r
154 throw new InvalidOperationException ("StatementHandle is already disposed.");
157 status = OciCalls.OCIStmtExecute (Service,
164 (OciExecuteMode)executeMode);
167 case OciGlue.OCI_DEFAULT:
174 case OciGlue.OCI_NO_DATA:
176 case OciGlue.OCI_INVALID_HANDLE:
177 throw new OracleException (0, "Invalid handle.");
179 OciErrorInfo info = ErrorHandle.HandleError ();
180 throw new OracleException (info.ErrorCode, info.ErrorMessage);
185 void GetColumnCount ()
187 columnCount = GetAttributeInt32 (OciAttributeType.ParameterCount, ErrorHandle);
190 public OciStatementType GetStatementType ()
192 return (OciStatementType) GetAttributeInt32 (OciAttributeType.StatementType, ErrorHandle);
199 if (this.disposed)
\r
201 throw new InvalidOperationException ("StatementHandle is already disposed.");
204 status = OciCalls.OCIStmtFetch (Handle,
211 case OciGlue.OCI_NO_DATA:
214 case OciGlue.OCI_DEFAULT:
217 case OciGlue.OCI_SUCCESS_WITH_INFO:
\r
218 //OciErrorInfo ei = ErrorHandle.HandleError ();
\r
219 //command.Connection.CreateInfoMessage (ei);
\r
220 moreResults = true;
\r
223 OciErrorInfo info = ErrorHandle.HandleError ();
224 throw new OracleException (info.ErrorCode, info.ErrorMessage);
230 public void Prepare (string commandText)
235 throw new InvalidOperationException ("StatementHandle is already disposed.");
241 // Get size of buffer
242 OciCalls.OCIUnicodeToCharSet (Parent, null, commandText, out rsize);
245 buffer = new byte[rsize];
246 OciCalls.OCIUnicodeToCharSet (Parent, buffer, commandText, out rsize);
249 status = OciCalls.OCIStmtPrepare (this,
253 OciStatementLanguage.NTV,
254 OciStatementMode.Default);
257 OciErrorInfo info = ErrorHandle.HandleError ();
258 throw new OracleException (info.ErrorCode, info.ErrorMessage);
262 #endregion // Methods