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
, OracleConnection connection
)
118 OciDefineHandle defineHandle
= new OciDefineHandle (this, IntPtr
.Zero
);
119 defineHandle
.ErrorHandle
= ErrorHandle
;
120 defineHandle
.DefineByPosition (position
, connection
);
127 Define (command
.Connection
);
130 void Define (OracleConnection connection
)
132 values
= new ArrayList ();
133 for (int i
= 0; i
< columnCount
; i
+= 1)
134 values
.Add (GetDefineHandle (i
, connection
));
137 public bool ExecuteQuery (bool schemaOnly
)
139 return Execute (false, false, schemaOnly
);
142 public bool ExecuteNonQuery (bool useAutoCommit
)
144 return Execute (true, useAutoCommit
, false);
147 public bool Execute (bool nonQuery
, bool useAutoCommit
, bool schemaOnly
)
155 executeMode
= (int)OciExecuteMode
.CommitOnSuccess
;
158 executeMode
= (int)OciExecuteMode
.DescribeOnly
;
160 executeMode
= (int)OciExecuteMode
.Default
;
165 throw new InvalidOperationException ("StatementHandle is already disposed.");
168 status
= OciCalls
.OCIStmtExecute (Service
,
175 (OciExecuteMode
)executeMode
);
178 case OciGlue
.OCI_DEFAULT
:
185 case OciGlue
.OCI_NO_DATA
:
187 case OciGlue
.OCI_INVALID_HANDLE
:
188 throw new OracleException (0, "Invalid handle.");
190 OciErrorInfo info
= ErrorHandle
.HandleError ();
191 throw new OracleException (info
.ErrorCode
, info
.ErrorMessage
);
196 internal void SetupRefCursorResult (OracleConnection connection
)
203 void GetColumnCount ()
205 columnCount
= GetAttributeInt32 (OciAttributeType
.ParameterCount
, ErrorHandle
);
208 public OciStatementType
GetStatementType ()
210 return (OciStatementType
) GetAttributeUInt16 (OciAttributeType
.StatementType
, ErrorHandle
);
219 throw new InvalidOperationException ("StatementHandle is already disposed.");
222 status
= OciCalls
.OCIStmtFetch (Handle
,
229 case OciGlue
.OCI_NO_DATA
:
232 case OciGlue
.OCI_DEFAULT
:
235 case OciGlue
.OCI_SUCCESS_WITH_INFO
:
236 //OciErrorInfo ei = ErrorHandle.HandleError ();
237 //command.Connection.CreateInfoMessage (ei);
241 OciErrorInfo info
= ErrorHandle
.HandleError ();
242 throw new OracleException (info
.ErrorCode
, info
.ErrorMessage
);
248 public void Prepare (string commandText
)
253 throw new InvalidOperationException ("StatementHandle is already disposed.");
259 // Get size of buffer
260 OciCalls
.OCIUnicodeToCharSet (Parent
, null, commandText
, out rsize
);
263 buffer
= new byte[rsize
];
264 OciCalls
.OCIUnicodeToCharSet (Parent
, buffer
, commandText
, out rsize
);
267 status
= OciCalls
.OCIStmtPrepare (this,
271 OciStatementLanguage
.NTV
,
272 OciStatementMode
.Default
);
275 OciErrorInfo info
= ErrorHandle
.HandleError ();
276 throw new OracleException (info
.ErrorCode
, info
.ErrorMessage
);
280 #endregion // Methods