**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Data.OracleClient / System.Data.OracleClient.Oci / OciLobLocator.cs
blobe51c79e360f15497fbc939a9e7f9da802d8f9cdc
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 OciDataType type;
32 #endregion // Fields
34 #region Constructors
36 public OciLobLocator (OciHandle parent, IntPtr handle)
37 : base (OciHandleType.LobLocator, parent, handle)
41 #endregion // Constructors
43 #region Properties
45 public OciErrorHandle ErrorHandle {
46 get { return errorHandle; }
47 set { errorHandle = value; }
50 public OciServiceHandle Service {
51 get { return service; }
52 set { service = value; }
55 public OciDataType LobType {
56 get { return type; }
57 set { type = value; }
60 #endregion // Properties
62 #region Methods
64 public void BeginBatch (OracleLobOpenMode mode)
66 int status = 0;
67 status = OciCalls.OCILobOpen (Service,
68 ErrorHandle,
69 Handle,
70 (byte) mode);
72 if (status != 0) {
73 OciErrorInfo info = ErrorHandle.HandleError ();
74 throw new OracleException (info.ErrorCode, info.ErrorMessage);
78 public uint Copy (OciLobLocator destination, uint amount, uint destinationOffset, uint sourceOffset)
80 OciCalls.OCILobCopy (Service,
81 ErrorHandle,
82 destination,
83 Handle,
84 amount,
85 destinationOffset,
86 sourceOffset);
87 return amount;
90 protected override void Dispose (bool disposing)
92 if (!disposed) {
93 disposed = true;
94 base.Dispose ();
98 public void EndBatch ()
100 int status = 0;
101 status = OciCalls.OCILobClose (Service, ErrorHandle, this);
103 if (status != 0) {
104 OciErrorInfo info = ErrorHandle.HandleError ();
105 throw new OracleException (info.ErrorCode, info.ErrorMessage);
109 public uint Erase (uint offset, uint amount)
111 int status = 0;
112 uint output = amount;
113 status = OciCalls.OCILobErase (Service,
114 ErrorHandle,
115 this,
116 ref output,
117 (uint) offset);
119 if (status != 0) {
120 OciErrorInfo info = ErrorHandle.HandleError ();
121 throw new OracleException (info.ErrorCode, info.ErrorMessage);
124 return output;
127 public int GetChunkSize ()
129 int status = 0;
130 uint output;
131 status = OciCalls.OCILobGetChunkSize (Service,
132 ErrorHandle,
133 this,
134 out output);
136 if (status != 0) {
137 OciErrorInfo info = ErrorHandle.HandleError ();
138 throw new OracleException (info.ErrorCode, info.ErrorMessage);
141 return (int) output;
144 public long GetLength (bool binary)
146 int status = 0;
147 uint output;
148 status = OciCalls.OCILobGetLength (Service,
149 ErrorHandle,
150 this,
151 out output);
152 if (status != 0) {
153 OciErrorInfo info = ErrorHandle.HandleError ();
154 throw new OracleException (info.ErrorCode, info.ErrorMessage);
157 if (!binary)
158 output *= 2;
160 return (long) output;
163 public int Read (byte[] buffer, uint offset, uint count, bool binary)
165 int status = 0;
166 uint amount = count;
168 // Character types are UTF-16, so amount of characters is 1/2
169 // the amount of bytes
170 if (!binary)
171 amount /= 2;
173 status = OciCalls.OCILobRead (Service,
174 ErrorHandle,
175 this,
176 ref amount,
177 offset,
178 buffer,
179 count,
180 IntPtr.Zero,
181 IntPtr.Zero,
182 1000, // OCI_UCS2ID
183 0); // Ignored if csid is specified as above
185 if (status != 0) {
186 OciErrorInfo info = ErrorHandle.HandleError ();
187 throw new OracleException (info.ErrorCode, info.ErrorMessage);
190 return (int) amount;
193 public void Trim (uint newlen)
195 int status = 0;
196 status = OciCalls.OCILobTrim (Service,
197 ErrorHandle,
198 this,
199 newlen);
201 if (status != 0) {
202 OciErrorInfo info = ErrorHandle.HandleError ();
203 throw new OracleException (info.ErrorCode, info.ErrorMessage);
208 public int Write (byte[] buffer, uint offset, uint count, OracleType type)
210 int status = 0;
211 uint amount = count;
213 if (type == OracleType.Clob)
214 amount /= 2;
216 status = OciCalls.OCILobWrite (Service,
217 ErrorHandle,
218 this,
219 ref amount,
220 offset,
221 buffer,
222 count,
223 0, // OCI_ONE_PIECE
224 IntPtr.Zero,
225 IntPtr.Zero,
226 1000, // OCI_UCS2ID
229 if (status != 0) {
230 OciErrorInfo info = ErrorHandle.HandleError ();
231 throw new OracleException (info.ErrorCode, info.ErrorMessage);
234 return (int) amount;
237 #endregion // Methods