(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Data.OracleClient / System.Data.OracleClient / OciGlue.cs
blob5c7f31e26a74411a1eec871d6dc3c90e28980dd0
1 //
2 // ociglue.cs - provides glue between
3 // managed C#/.NET System.Data.OracleClient.dll and
4 // unmanaged native c library oci.dll
5 // to be used in Mono System.Data.OracleClient as
6 // the Oracle 8i data provider.
7 //
8 // Part of managed C#/.NET library System.Data.OracleClient.dll
9 //
10 // Part of the Mono class libraries at
11 // mcs/class/System.Data.OracleClient/System.Data.OracleClient.OCI
13 // Assembly: System.Data.OracleClient.dll
14 // Namespace: System.Data.OracleClient.Oci
15 //
16 // Authors:
17 // Daniel Morgan <danmorg@sc.rr.com>
18 // Tim Coleman <tim@timcoleman.com>
19 //
20 // Copyright (C) Daniel Morgan, 2002
21 // Copyright (C) Tim Coleman, 2002
22 //
24 using System;
25 using System.Runtime.InteropServices;
26 using System.Text;
28 namespace System.Data.OracleClient.Oci {
29 internal sealed class OciGlue
31 #region Fields
33 bool connected;
34 OciEnvironmentHandle environment;
35 OciErrorHandle error;
36 OciServerHandle server;
37 OciServiceHandle service;
38 OciSessionHandle session;
40 // other codes
41 public const int OCI_DEFAULT = 0;
42 public const int OCI_SUCCESS = 0;
43 public const int OCI_SUCCESS_WITH_INFO = 1;
44 public const int OCI_RESERVED_FOR_INT_USE = 200;
45 public const int OCI_NO_DATA = 100;
46 public const int OCI_ERROR = -1;
47 public const int OCI_INVALID_HANDLE = -2;
48 public const int OCI_NEED_DATA = 99;
49 public const int OCI_STILL_EXECUTING = -3123;
50 public const int OCI_CONTINUE = -24200;
52 #endregion // Fields
54 #region Properties
56 public bool Connected {
57 get { return connected; }
60 public OciEnvironmentHandle Environment {
61 get { return environment; }
64 public OciErrorHandle ErrorHandle {
65 get { return error; }
68 public OciServiceHandle ServiceContext {
69 get { return service; }
72 #endregion // Properties
74 #region Methods
76 public void CreateConnection (OracleConnectionInfo conInfo)
78 environment = new OciEnvironmentHandle (OciEnvironmentMode.Threaded | OciEnvironmentMode.NoUserCallback);
80 if (environment.Handle == IntPtr.Zero)
81 throw new OracleException (0, "Could not allocate the Oracle environment.");
83 service = (OciServiceHandle) environment.Allocate (OciHandleType.Service);
84 if (service == null) {
85 OciErrorInfo info = environment.HandleError ();
86 Disconnect ();
87 throw new OracleException (info.ErrorCode, info.ErrorMessage);
90 error = (OciErrorHandle) environment.Allocate (OciHandleType.Error);
91 if (error == null) {
92 OciErrorInfo info = environment.HandleError ();
93 Disconnect ();
94 throw new OracleException (info.ErrorCode, info.ErrorMessage);
96 service.ErrorHandle = error;
98 server = (OciServerHandle) environment.Allocate (OciHandleType.Server);
99 if (server == null) {
100 OciErrorInfo info = environment.HandleError ();
101 Disconnect ();
102 throw new OracleException (info.ErrorCode, info.ErrorMessage);
105 session = (OciSessionHandle) environment.Allocate (OciHandleType.Session);
106 if (session == null) {
107 OciErrorInfo info = environment.HandleError ();
108 Disconnect ();
109 throw new OracleException (info.ErrorCode, info.ErrorMessage);
111 session.Username = conInfo.Username;
112 session.Password = conInfo.Password;
113 session.Service = service;
115 if (!server.Attach (conInfo.Database, ErrorHandle)) {
116 OciErrorInfo info = error.HandleError ();
117 Disconnect ();
118 throw new OracleException (info.ErrorCode, info.ErrorMessage);
121 if (!service.SetServer (server)) {
122 OciErrorInfo info = error.HandleError ();
123 Disconnect ();
124 throw new OracleException (info.ErrorCode, info.ErrorMessage);
127 if (!session.BeginSession (OciCredentialType.RDBMS, OciSessionMode.Default, ErrorHandle)) {
128 OciErrorInfo info = error.HandleError ();
129 Disconnect ();
130 throw new OracleException (info.ErrorCode, info.ErrorMessage);
134 if (!service.SetSession (session)) {
135 OciErrorInfo info = error.HandleError ();
136 Disconnect ();
137 throw new OracleException (info.ErrorCode, info.ErrorMessage);
140 connected = true;
143 public OciStatementHandle CreateStatement ()
145 OciStatementHandle statement = (OciStatementHandle) environment.Allocate (OciHandleType.Statement);
146 if (statement == null) {
147 OciErrorInfo info = environment.HandleError ();
148 throw new OracleException (info.ErrorCode, info.ErrorMessage);
150 statement.ErrorHandle = error;
151 statement.Service = service;
153 return statement;
156 public OciTransactionHandle CreateTransaction ()
158 OciTransactionHandle transaction = (OciTransactionHandle) environment.Allocate (OciHandleType.Transaction);
159 if (transaction == null) {
160 OciErrorInfo info = environment.HandleError ();
161 throw new OracleException (info.ErrorCode, info.ErrorMessage);
163 transaction.ErrorHandle = error;
164 transaction.Service = service;
166 return transaction;
169 public void Disconnect()
171 if (session != null)
172 session.Dispose ();
173 if (server != null)
174 server.Dispose ();
175 if (error != null)
176 error.Dispose ();
177 if (service != null)
178 service.Dispose ();
179 if (environment != null)
180 environment.Dispose ();
183 #endregion // Methods