[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / class / System.Data.OracleClient / System.Data.OracleClient.Oci / OciLobLocator.cs
bloba5d12551fad49f73b4ed98880c6e7b468b784b06
1 //
2 // OciLobLocator.cs
3 //
4 // Part of managed C#/.NET library System.Data.OracleClient.dll
5 //
6 // Part of the Mono class libraries at
7 // mcs/class/System.Data.OracleClient/System.Data.OracleClient.Oci
8 //
9 // Assembly: System.Data.OracleClient.dll
10 // Namespace: System.Data.OracleClient.Oci
11 //
12 // Author:
13 // Tim Coleman <tim@timcoleman.com>
14 //
15 // Copyright (C) Tim Coleman, 2003
16 //
18 using System;
19 using System.Data.OracleClient;
20 using System.Runtime.InteropServices;
22 namespace System.Data.OracleClient.Oci {
23 internal sealed class OciLobLocator : OciDescriptorHandle, IDisposable
25 #region Fields
27 bool disposed = false;
28 OciErrorHandle errorHandle;
29 OciServiceHandle service;
30 OciEnvironmentHandle environment;
31 OciDataType type;
33 #endregion // Fields
35 #region Constructors
37 public OciLobLocator (OciHandle parent, IntPtr handle)
38 : base (OciHandleType.LobLocator, parent, handle)
42 #endregion // Constructors
44 #region Properties
46 public OciErrorHandle ErrorHandle {
47 get { return errorHandle; }
48 set { errorHandle = value; }
51 public OciServiceHandle Service {
52 get { return service; }
53 set { service = value; }
56 public OciDataType LobType {
57 get { return type; }
58 set { type = value; }
61 public OciEnvironmentHandle Environment {
62 get { return environment; }
63 set { environment = value; }
66 #endregion // Properties
68 #region Methods
70 public void BeginBatch (OracleLobOpenMode mode)
72 int status = 0;
73 status = OciCalls.OCILobOpen (Service,
74 ErrorHandle,
75 Handle,
76 (byte) mode);
78 if (status != 0) {
79 OciErrorInfo info = ErrorHandle.HandleError ();
80 throw new OracleException (info.ErrorCode, info.ErrorMessage);
84 public uint Copy (OciLobLocator destination, uint amount, uint destinationOffset, uint sourceOffset)
86 OciCalls.OCILobCopy (Service,
87 ErrorHandle,
88 destination,
89 Handle,
90 amount,
91 destinationOffset,
92 sourceOffset);
93 return amount;
96 protected override void Dispose (bool disposing)
98 if (!disposed) {
99 disposed = true;
100 base.Dispose ();
104 public void EndBatch ()
106 int status = 0;
107 status = OciCalls.OCILobClose (Service, ErrorHandle, this);
109 if (status != 0) {
110 OciErrorInfo info = ErrorHandle.HandleError ();
111 throw new OracleException (info.ErrorCode, info.ErrorMessage);
115 public uint Erase (uint offset, uint amount)
117 int status = 0;
118 uint output = amount;
119 status = OciCalls.OCILobErase (Service,
120 ErrorHandle,
121 this,
122 ref output,
123 (uint) offset);
125 if (status != 0) {
126 OciErrorInfo info = ErrorHandle.HandleError ();
127 throw new OracleException (info.ErrorCode, info.ErrorMessage);
130 return output;
133 public int GetChunkSize ()
135 int status = 0;
136 uint output;
137 status = OciCalls.OCILobGetChunkSize (Service,
138 ErrorHandle,
139 this,
140 out output);
142 if (status != 0) {
143 OciErrorInfo info = ErrorHandle.HandleError ();
144 throw new OracleException (info.ErrorCode, info.ErrorMessage);
147 return (int) output;
150 public long GetLength (bool binary)
152 int status = 0;
153 uint output;
154 status = OciCalls.OCILobGetLength (Service,
155 ErrorHandle,
156 this,
157 out output);
158 if (status != 0) {
159 OciErrorInfo info = ErrorHandle.HandleError ();
160 throw new OracleException (info.ErrorCode, info.ErrorMessage);
163 if (!binary)
164 output *= 2;
166 return (long) output;
169 public int Read (byte[] buffer, uint offset, uint count, bool binary)
171 int status = 0;
172 uint amount = count;
173 byte csfrm = 0;
175 // Character types are UTF-16, so amount of characters is 1/2
176 // the amount of bytes
177 if (!binary) {
178 amount /= 2;
179 status = OciCalls.OCILobCharSetForm (environment,
180 ErrorHandle,
181 this,
182 out csfrm);
183 if (status != 0) {
184 OciErrorInfo info = ErrorHandle.HandleError ();
185 throw new OracleException (info.ErrorCode, info.ErrorMessage);
189 status = OciCalls.OCILobRead (Service,
190 ErrorHandle,
191 this,
192 ref amount,
193 offset,
194 buffer,
195 count,
196 IntPtr.Zero,
197 IntPtr.Zero,
198 1000, // OCI_UCS2ID
199 csfrm);
201 if (status != 0) {
202 OciErrorInfo info = ErrorHandle.HandleError ();
203 throw new OracleException (info.ErrorCode, info.ErrorMessage);
206 return (int) amount;
209 public void Trim (uint newlen)
211 int status = 0;
212 status = OciCalls.OCILobTrim (Service,
213 ErrorHandle,
214 this,
215 newlen);
217 if (status != 0) {
218 OciErrorInfo info = ErrorHandle.HandleError ();
219 throw new OracleException (info.ErrorCode, info.ErrorMessage);
224 public int Write (byte[] buffer, uint offset, uint count, OracleType type)
226 int status = 0;
227 uint amount = count;
229 if (type == OracleType.Clob)
230 amount /= 2;
232 status = OciCalls.OCILobWrite (Service,
233 ErrorHandle,
234 this,
235 ref amount,
236 offset,
237 buffer,
238 count,
239 0, // OCI_ONE_PIECE
240 IntPtr.Zero,
241 IntPtr.Zero,
242 1000, // OCI_UCS2ID
245 if (status != 0) {
246 OciErrorInfo info = ErrorHandle.HandleError ();
247 throw new OracleException (info.ErrorCode, info.ErrorMessage);
250 return (int) amount;
253 #endregion // Methods