Merge pull request #799 from kebby/master
[mono.git] / mcs / class / System.Data.OracleClient / System.Data.OracleClient.Oci / OciCalls.cs
1 //
2 // OciCalls.cs
3 //
4 // Part of the Mono class libraries at
5 // mcs/class/System.Data.OracleClient/System.Data.OracleClient.Oci
6 //
7 // Assembly: System.Data.OracleClient.dll
8 // Namespace: System.Data.OracleClient.Oci
9 //
10 // Authors: Joerg Rosenkranz <joergr@voelcker.com>
11 //          Daniel Morgan <monodanmorg@yahoo.com>
12 //
13 // Copyright (C) Joerg Rosenkranz, 2004
14 // Copyright (C) Daniel Morgan, 2005, 2009
15 //
16 // Licensed under the MIT/X11 License.
17 //
18
19 //#define ORACLE_DATA_ACCESS
20
21 using System;
22 using System.Diagnostics;
23 using System.Runtime.InteropServices;
24 using System.Text;
25
26 namespace System.Data.OracleClient.Oci
27 {
28         internal sealed class OciCalls
29         {
30 #if TRACE
31                 private static bool traceOci;
32
33                 static OciCalls()
34                 {
35                         string env = Environment.GetEnvironmentVariable("OCI_TRACE");
36
37                         traceOci = (env != null && env.Length > 0);
38                 }
39 #endif
40
41                 private OciCalls ()
42                 {}
43
44                 #region OCI native calls
45
46                 private sealed class OciNativeCalls
47                 {
48                         private OciNativeCalls ()
49                         {}
50
51                         [DllImport ("oci", EntryPoint = "OCIAttrSet")]
52                         internal static extern int OCIAttrSet (IntPtr trgthndlp,
53                                 [MarshalAs (UnmanagedType.U4)] OciHandleType trghndltyp,
54                                 IntPtr attributep,
55                                 uint size,
56                                 [MarshalAs (UnmanagedType.U4)] OciAttributeType attrtype,
57                                 IntPtr errhp);
58
59                         [DllImport ("oci", EntryPoint = "OCIAttrSet")]
60                         internal static extern int OCIAttrSetString (IntPtr trgthndlp,
61                                 [MarshalAs (UnmanagedType.U4)] OciHandleType trghndltyp,
62                                 string attributep,
63                                 uint size,
64                                 [MarshalAs (UnmanagedType.U4)] OciAttributeType attrtype,
65                                 IntPtr errhp);
66
67 #if ORACLE_DATA_ACCESS
68                         [DllImport ("oci", EntryPoint = "OCIPasswordChange")]
69                         internal static extern int OCIPasswordChange (IntPtr svchp, 
70                                 IntPtr errhp,
71                                 byte [] user_name, 
72                                 [MarshalAs (UnmanagedType.U4)] int usernm_len,
73                                 byte [] opasswd,
74                                 [MarshalAs (UnmanagedType.U4)] int opasswd_len,
75                                 byte [] npasswd,
76                                 [MarshalAs (UnmanagedType.U4)] int npasswd_len,
77                                 [MarshalAs (UnmanagedType.U4)] uint mode);
78 #endif
79
80                         [DllImport ("oci")]
81                         internal static extern int OCIErrorGet (IntPtr hndlp,
82                                 uint recordno,
83                                 IntPtr sqlstate,
84                                 out int errcodep,
85                                 IntPtr bufp,
86                                 uint bufsize,
87                                 [MarshalAs (UnmanagedType.U4)] OciHandleType type);
88
89                         [DllImport ("oci", EntryPoint = "OCIBindByName")]
90                         internal static extern int OCIBindByName (IntPtr stmtp,
91                                 out IntPtr bindpp,
92                                 IntPtr errhp,
93                                 string placeholder,
94                                 int placeh_len,
95                                 IntPtr valuep,
96                                 int value_sz,
97                                 [MarshalAs (UnmanagedType.U2)] OciDataType dty,
98                                 ref short indp,
99                                 IntPtr alenp,
100                                 IntPtr rcodep,
101                                 uint maxarr_len,
102                                 IntPtr curelp,
103                                 uint mode);
104
105                         [DllImport ("oci", EntryPoint = "OCIBindByName")]
106                         internal static extern int OCIBindByNameRef (IntPtr stmtp,
107                                 out IntPtr bindpp,
108                                 IntPtr errhp,
109                                 string placeholder,
110                                 int placeh_len,
111                                 ref IntPtr valuep,
112                                 int value_sz,
113                                 [MarshalAs (UnmanagedType.U2)] OciDataType dty,
114                                 ref short indp,
115                                 IntPtr alenp,
116                                 IntPtr rcodep,
117                                 uint maxarr_len,
118                                 IntPtr curelp,
119                                 uint mode);
120
121                         [DllImport ("oci", EntryPoint = "OCIBindByName")]
122                         internal static extern int OCIBindByNameBytes (IntPtr stmtp,
123                                 out IntPtr bindpp,
124                                 IntPtr errhp,
125                                 string placeholder,
126                                 int placeh_len,
127                                 byte[] valuep,
128                                 int value_sz,
129                                 [MarshalAs (UnmanagedType.U2)] OciDataType dty,
130                                 ref short indp,
131                                 IntPtr alenp,
132                                 IntPtr rcodep,
133                                 uint maxarr_len,
134                                 IntPtr curelp,
135                                 uint mode);
136
137                         [DllImport ("oci", EntryPoint = "OCIBindByPos")]
138                         internal static extern int OCIBindByPos (IntPtr stmtp,
139                                 out IntPtr bindpp,
140                                 IntPtr errhp,
141                                 uint position,
142                                 IntPtr valuep,
143                                 int value_sz,
144                                 [MarshalAs (UnmanagedType.U2)] OciDataType dty,
145                                 ref short indp,
146                                 IntPtr alenp,
147                                 IntPtr rcodep,
148                                 uint maxarr_len,
149                                 IntPtr curelp,
150                                 uint mode);
151
152                         [DllImport ("oci", EntryPoint = "OCIBindByPos")]
153                         internal static extern int OCIBindByPosBytes (IntPtr stmtp,
154                                 out IntPtr bindpp,
155                                 IntPtr errhp,
156                                 uint position,
157                                 byte[] valuep,
158                                 int value_sz,
159                                 [MarshalAs (UnmanagedType.U2)] OciDataType dty,
160                                 ref short indp,
161                                 IntPtr alenp,
162                                 IntPtr rcodep,
163                                 uint maxarr_len,
164                                 IntPtr curelp,
165                                 uint mode);
166
167                         [DllImport ("oci", EntryPoint = "OCIBindByPos")]
168                         internal static extern int OCIBindByPosRef (IntPtr stmtp,
169                                 out IntPtr bindpp,
170                                 IntPtr errhp,
171                                 uint position,
172                                 ref IntPtr valuep,
173                                 int value_sz,
174                                 [MarshalAs (UnmanagedType.U2)] OciDataType dty,
175                                 ref short indp,
176                                 IntPtr alenp,
177                                 IntPtr rcodep,
178                                 uint maxarr_len,
179                                 IntPtr curelp,
180                                 uint mode);
181
182                         [DllImport ("oci")]
183                         internal static extern int OCIDateTimeFromText (IntPtr hndl,
184                                 IntPtr errhp, [In][Out] byte[] date_str, uint dstr_length,
185                                 [In][Out] byte[] fmt, uint fmt_length,
186                                 [In][Out] byte[] lang_name, uint lang_length, IntPtr datetime);
187
188                         [DllImport ("oci")]
189                         internal static extern int OCIDefineByPos (IntPtr stmtp,
190                                 out IntPtr defnpp,
191                                 IntPtr errhp,
192                                 [MarshalAs (UnmanagedType.U4)] int position,
193                                 IntPtr valuep,
194                                 int value_sz,
195                                 [MarshalAs (UnmanagedType.U4)] OciDataType dty,
196                                 ref short indp,
197                                 ref short rlenp,
198                                 IntPtr rcodep,
199                                 uint mode);
200
201                         [DllImport ("oci", EntryPoint="OCIDefineByPos")]
202                         internal static extern int OCIDefineByPosPtr (IntPtr stmtp,
203                                 out IntPtr defnpp,
204                                 IntPtr errhp,
205                                 [MarshalAs (UnmanagedType.U4)] int position,
206                                 ref IntPtr valuep,
207                                 int value_sz,
208                                 [MarshalAs (UnmanagedType.U4)] OciDataType dty,
209                                 ref short indp,
210                                 ref short rlenp,
211                                 IntPtr rcodep,
212                                 uint mode);
213
214                         [DllImport ("oci")]
215                         internal static extern int OCIDescriptorFree (IntPtr hndlp,
216                                 [MarshalAs (UnmanagedType.U4)] OciHandleType type);
217
218                         [DllImport ("oci")]
219                         internal static extern int OCIEnvCreate (out IntPtr envhpp,
220                                 [MarshalAs (UnmanagedType.U4)] OciEnvironmentMode mode,
221                                 IntPtr ctxp,
222                                 IntPtr malocfp,
223                                 IntPtr ralocfp,
224                                 IntPtr mfreep,
225                                 int xtramem_sz,
226                                 IntPtr usrmempp);
227
228                         [DllImport ("oci")]
229                         internal static extern int OCICacheFree (IntPtr envhp,
230                                 IntPtr errhp,
231                                 IntPtr stmthp);
232
233                         [DllImport ("oci")]
234                         internal static extern int OCIAttrGet (IntPtr trgthndlp,
235                                 [MarshalAs (UnmanagedType.U4)] OciHandleType trghndltyp,
236                                 out IntPtr attributep,
237                                 out int sizep,
238                                 [MarshalAs (UnmanagedType.U4)] OciAttributeType attrtype,
239                                 IntPtr errhp);
240
241                         [DllImport ("oci", EntryPoint = "OCIAttrGet")]
242                         internal static extern int OCIAttrGetSByte (IntPtr trgthndlp,
243                                 [MarshalAs (UnmanagedType.U4)] OciHandleType trghndltyp,
244                                 out sbyte attributep,
245                                 IntPtr sizep,
246                                 [MarshalAs (UnmanagedType.U4)] OciAttributeType attrtype,
247                                 IntPtr errhp);
248
249                         [DllImport ("oci", EntryPoint = "OCIAttrGet")]
250                         internal static extern int OCIAttrGetByte (IntPtr trgthndlp,
251                                 [MarshalAs (UnmanagedType.U4)] OciHandleType trghndltyp,
252                                 out byte attributep,
253                                 IntPtr sizep,
254                                 [MarshalAs (UnmanagedType.U4)] OciAttributeType attrtype,
255                                 IntPtr errhp);
256
257                         [DllImport ("oci", EntryPoint = "OCIAttrGet")]
258                         internal static extern int OCIAttrGetUInt16 (IntPtr trgthndlp,
259                                 [MarshalAs (UnmanagedType.U4)] OciHandleType trghndltyp,
260                                 out ushort attributep,
261                                 IntPtr sizep,
262                                 [MarshalAs (UnmanagedType.U4)] OciAttributeType attrtype,
263                                 IntPtr errhp);
264
265                         [DllImport ("oci", EntryPoint = "OCIAttrGet")]
266                         internal static extern int OCIAttrGetInt32 (IntPtr trgthndlp,
267                                 [MarshalAs (UnmanagedType.U4)] OciHandleType trghndltyp,
268                                 out int attributep,
269                                 IntPtr sizep,
270                                 [MarshalAs (UnmanagedType.U4)] OciAttributeType attrtype,
271                                 IntPtr errhp);
272
273                         [DllImport ("oci", EntryPoint = "OCIAttrGet")]
274                         internal static extern int OCIAttrGetIntPtr (IntPtr trgthndlp,
275                                 [MarshalAs (UnmanagedType.U4)] OciHandleType trghndltyp,
276                                 out IntPtr attributep,
277                                 IntPtr sizep,
278                                 [MarshalAs (UnmanagedType.U4)] OciAttributeType attrtype,
279                                 IntPtr errhp);
280
281                         [DllImport ("oci")]
282                         internal static extern int OCIDescriptorAlloc (IntPtr parenth,
283                                 out IntPtr hndlpp,
284                                 [MarshalAs (UnmanagedType.U4)] OciHandleType type,
285                                 int xtramem_sz,
286                                 IntPtr usrmempp);
287
288                         [DllImport ("oci")]
289                         internal static extern int OCIHandleAlloc (IntPtr parenth,
290                                 out IntPtr descpp,
291                                 [MarshalAs (UnmanagedType.U4)] OciHandleType type,
292                                 int xtramem_sz,
293                                 IntPtr usrmempp);
294
295                         [DllImport ("oci")]
296                         internal static extern int OCIHandleFree (IntPtr hndlp,
297                                 [MarshalAs (UnmanagedType.U4)] OciHandleType type);
298
299                         [DllImport ("oci")]
300                         internal static extern int OCILobClose (IntPtr svchp,
301                                 IntPtr errhp,
302                                 IntPtr locp);
303
304                         [DllImport ("oci")]
305                         internal static extern int OCILobCopy (IntPtr svchp,
306                                 IntPtr errhp,
307                                 IntPtr dst_locp,
308                                 IntPtr src_locp,
309                                 uint amount,
310                                 uint dst_offset,
311                                 uint src_offset);
312
313                         [DllImport ("oci")]
314                         internal static extern int OCILobErase (IntPtr svchp,
315                                 IntPtr errhp,
316                                 IntPtr locp,
317                                 ref uint amount,
318                                 uint offset);
319
320                         [DllImport ("oci")]
321                         internal static extern int OCILobGetChunkSize (IntPtr svchp,
322                                 IntPtr errhp,
323                                 IntPtr locp,
324                                 out uint chunk_size);
325
326                         [DllImport ("oci")]
327                         internal static extern int OCILobGetLength (IntPtr svchp,
328                                 IntPtr errhp,
329                                 IntPtr locp,
330                                 out uint lenp);
331
332                         [DllImport ("oci")]
333                         internal static extern int OCILobOpen (IntPtr svchp,
334                                 IntPtr errhp,
335                                 IntPtr locp,
336                                 byte mode);
337
338                         [DllImport ("oci")]
339                         internal static extern int OCILobRead (IntPtr svchp,
340                                 IntPtr errhp,
341                                 IntPtr locp,
342                                 ref uint amtp,
343                                 uint offset,
344                                 byte[] bufp,
345                                 uint bufl,
346                                 IntPtr ctxp,
347                                 IntPtr cbfp,
348                                 ushort csid,
349                                 byte csfrm);
350
351                         [DllImport ("oci")]
352                         internal static extern int OCILobTrim (IntPtr svchp,
353                                 IntPtr errhp,
354                                 IntPtr locp,
355                                 uint newlen);
356
357                         [DllImport ("oci")]
358                         internal static extern int OCILobWrite (IntPtr svchp,
359                                 IntPtr errhp,
360                                 IntPtr locp,
361                                 ref uint amtp,
362                                 uint offset,
363                                 byte[] bufp,
364                                 uint bufl,
365                                 byte piece,
366                                 IntPtr ctxp,
367                                 IntPtr cbfp,
368                                 ushort csid,
369                                 byte csfrm);
370
371                         [DllImport ("oci")]
372                         internal static extern int OCILobCharSetForm (IntPtr svchp, 
373                                 IntPtr errhp,
374                                 IntPtr locp,
375                                 out byte csfrm);
376                         
377                         [DllImport ("oci")]
378                         internal static extern int OCINlsGetInfo (IntPtr hndl,
379                                 IntPtr errhp,
380                                 [In][Out] byte[] bufp,
381                                 uint buflen,
382                                 ushort item);
383
384                         [DllImport ("oci")]
385                         internal static extern int OCIServerAttach (IntPtr srvhp,
386                                 IntPtr errhp,
387                                 string dblink,
388                                 [MarshalAs (UnmanagedType.U4)] int dblink_len,
389                                 uint mode);
390
391                         [DllImport ("oci")]
392                         internal static extern int OCIServerDetach (IntPtr srvhp,
393                                 IntPtr errhp,
394                                 uint mode);
395
396                         [DllImport ("oci")]
397                         internal static extern int OCIServerVersion (IntPtr hndlp,
398                                 IntPtr errhp,
399                                 [In][Out] byte[] bufp,
400                                 uint bufsz,
401                                 [MarshalAs (UnmanagedType.U4)] OciHandleType type);
402
403                         [DllImport ("oci")]
404                         internal static extern int OCISessionBegin (IntPtr svchp,
405                                 IntPtr errhp,
406                                 IntPtr usrhp,
407                                 [MarshalAs (UnmanagedType.U4)] OciCredentialType credt,
408                                 [MarshalAs (UnmanagedType.U4)] OciSessionMode mode);
409
410                         [DllImport ("oci")]
411                         internal static extern int OCISessionEnd (IntPtr svchp,
412                                 IntPtr errhp,
413                                 IntPtr usrhp,
414                                 uint mode);
415
416                         [DllImport ("oci")]
417                         internal static extern int OCIParamGet (IntPtr hndlp,
418                                 [MarshalAs (UnmanagedType.U4)] OciHandleType htype,
419                                 IntPtr errhp,
420                                 out IntPtr parmdpp,
421                                 [MarshalAs (UnmanagedType.U4)] int pos);
422
423                         [DllImport ("oci")]
424                         internal static extern int OCIStmtExecute (IntPtr svchp,
425                                 IntPtr stmthp,
426                                 IntPtr errhp,
427                                 [MarshalAs (UnmanagedType.U4)] uint iters,
428                                 uint rowoff,
429                                 IntPtr snap_in,
430                                 IntPtr snap_out,
431                                 [MarshalAs (UnmanagedType.U4)] OciExecuteMode mode);
432
433                         [DllImport ("oci")]
434                         internal static extern int OCIStmtFetch (IntPtr stmtp,
435                                 IntPtr errhp,
436                                 uint nrows,
437                                 ushort orientation,
438                                 uint mode);
439
440
441                         [DllImport ("oci")]
442                         internal static extern int OCIStmtPrepare (IntPtr stmthp,
443                                 IntPtr errhp,
444                                 byte [] stmt,
445                                 [MarshalAs (UnmanagedType.U4)] int stmt_length,
446                                 [MarshalAs (UnmanagedType.U4)] OciStatementLanguage language,
447                                 [MarshalAs (UnmanagedType.U4)] OciStatementMode mode);
448
449                         [DllImport ("oci")]
450                         internal static extern int OCITransCommit (IntPtr svchp,
451                                 IntPtr errhp,
452                                 uint flags);
453
454                         [DllImport ("oci")]
455                         internal static extern int OCITransRollback (IntPtr svchp,
456                                 IntPtr errhp,
457                                 uint flags);
458
459                         [DllImport ("oci")]
460                         internal static extern int OCITransStart (IntPtr svchp,
461                                 IntPtr errhp,
462                                 uint timeout,
463                                 [MarshalAs (UnmanagedType.U4)] OciTransactionFlags flags);
464
465                         [DllImport ("oci")]
466                         internal static extern int OCICharSetToUnicode (
467                                 IntPtr svchp,
468                                 [MarshalAs (UnmanagedType.LPWStr)] StringBuilder dst,
469                                 [MarshalAs (UnmanagedType.SysUInt)] int dstlen,
470                                 byte [] src,
471                                 [MarshalAs (UnmanagedType.SysUInt)] int srclen,
472                                 out long rsize);
473
474                         [DllImport ("oci")]
475                         internal static extern int OCIUnicodeToCharSet (
476                                 IntPtr svchp,
477                                 byte [] dst,
478                                 [MarshalAs (UnmanagedType.SysUInt)] int dstlen,
479                                 [MarshalAs (UnmanagedType.LPWStr)] string src,
480                                 [MarshalAs (UnmanagedType.SysUInt)] int srclen,
481                                 out long rsize);
482                 }
483
484                 #endregion
485
486                 #region OCI call wrappers
487
488                 internal static int OCIAttrSet (IntPtr trgthndlp,
489                         OciHandleType trghndltyp,
490                         IntPtr attributep,
491                         uint size,
492                         OciAttributeType attrtype,
493                         IntPtr errhp)
494                 {
495                         #if TRACE
496                         Trace.WriteLineIf(traceOci, string.Format("OCIAttrSet ({0}, {1})", trghndltyp, attrtype), "OCI");
497                         #endif
498                         return OciNativeCalls.OCIAttrSet (trgthndlp, trghndltyp, attributep, size, attrtype, errhp);
499                 }
500
501                 internal static int OCIAttrSetString (IntPtr trgthndlp,
502                         OciHandleType trghndltyp,
503                         string attributep,
504                         uint size,
505                         OciAttributeType attrtype,
506                         IntPtr errhp)
507                 {
508                         #if TRACE
509                         Trace.WriteLineIf(traceOci, string.Format("OCIAttrSetString ({0}, {1})", trghndltyp, attrtype), "OCI");
510                         #endif
511                         return OciNativeCalls.OCIAttrSetString (trgthndlp, trghndltyp, attributep, size, attrtype, errhp);
512                 }
513 #if ORACLE_DATA_ACCESS
514                 internal static int OCIPasswordChange (IntPtr svchp, IntPtr errhp,
515                                 int usernm_len,
516                                 byte [] opasswd,
517                                 int opasswd_len,
518                                 byte [] npasswd,
519                                 int npasswd_len,
520                                 uint mode)
521                 {
522                         #if TRACE
523                         Trace.WriteLineIf(traceOci, string.Format("OCIPasswordChange"), "OCI");
524                         #endif
525                         return OciNativeCalls.OCIPasswordChange (svchp, errhp, user_name, (uint) usernm_len, opasswd, (uint) opasswd_len, npasswd, (uint) npasswd_len, mode);
526                 }
527 #endif
528                 internal static int OCIErrorGet (IntPtr hndlp,
529                         uint recordno,
530                         IntPtr sqlstate,
531                         out int errcodep,
532                         IntPtr bufp,
533                         uint bufsize,
534                         OciHandleType type)
535                 {
536                         #if TRACE
537                         Trace.WriteLineIf(traceOci, "OCIErrorGet", "OCI");
538                         #endif
539                         return OciNativeCalls.OCIErrorGet (hndlp, recordno, sqlstate, out errcodep, bufp, bufsize, type);
540                 }
541
542                 internal static int OCIBindByName (IntPtr stmtp,
543                         out IntPtr bindpp,
544                         IntPtr errhp,
545                         string placeholder,
546                         int placeh_len,
547                         IntPtr valuep,
548                         int value_sz,
549                         OciDataType dty,
550                         ref short indp,
551                         IntPtr alenp,
552                         IntPtr rcodep,
553                         uint maxarr_len,
554                         IntPtr curelp,
555                         uint mode)
556                 {
557                         #if TRACE
558                         Trace.WriteLineIf(traceOci, "OCIBindByName", "OCI");
559                         #endif
560                         return OciNativeCalls.OCIBindByName (stmtp, out bindpp, errhp, placeholder, placeh_len, valuep,
561                                 value_sz, dty, ref indp, alenp, rcodep, maxarr_len, curelp, mode);
562                 }
563
564                 internal static int OCIBindByNameRef (IntPtr stmtp,
565                         out IntPtr bindpp,
566                         IntPtr errhp,
567                         string placeholder,
568                         int placeh_len,
569                         ref IntPtr valuep,
570                         int value_sz,
571                         OciDataType dty,
572                         ref short indp,
573                         IntPtr alenp,
574                         IntPtr rcodep,
575                         uint maxarr_len,
576                         IntPtr curelp,
577                         uint mode)
578                 {
579                         #if TRACE
580                         Trace.WriteLineIf(traceOci, "OCIBindByName", "OCI");
581                         #endif
582                         return OciNativeCalls.OCIBindByNameRef (stmtp, out bindpp, errhp, placeholder, placeh_len, ref valuep,
583                                 value_sz, dty, ref indp, alenp, rcodep, maxarr_len, curelp, mode);
584                 }
585
586                 internal static int OCIBindByNameBytes (IntPtr stmtp,
587                         out IntPtr bindpp,
588                         IntPtr errhp,
589                         string placeholder,
590                         int placeh_len,
591                         byte[] valuep,
592                         int value_sz,
593                         [MarshalAs (UnmanagedType.U2)] OciDataType dty,
594                         ref short indp,
595                         IntPtr alenp,
596                         IntPtr rcodep,
597                         uint maxarr_len,
598                         IntPtr curelp,
599                         uint mode)
600                 {
601                         #if TRACE
602                         Trace.WriteLineIf(traceOci, "OCIBindByName", "OCI");
603                         #endif
604                         return OciNativeCalls.OCIBindByNameBytes (stmtp, out bindpp, errhp, placeholder, placeh_len, valuep,
605                                 value_sz, dty, ref indp, alenp, rcodep, maxarr_len, curelp, mode);
606                 }
607
608                 internal static int OCIBindByPos (IntPtr stmtp,
609                         out IntPtr bindpp,
610                         IntPtr errhp,
611                         uint position,
612                         IntPtr valuep,
613                         int value_sz,
614                         [MarshalAs (UnmanagedType.U2)] OciDataType dty,
615                         ref short indp,
616                         IntPtr alenp,
617                         IntPtr rcodep,
618                         uint maxarr_len,
619                         IntPtr curelp,
620                         uint mode)
621                 {
622                         #if TRACE
623                         Trace.WriteLineIf(traceOci, "OCIBindByPos", "OCI");
624                         #endif
625                         return OciNativeCalls.OCIBindByPos (stmtp, out bindpp, errhp, position, valuep,
626                                 value_sz, dty, ref indp, alenp, rcodep, maxarr_len, curelp, mode);
627                 }
628
629                 internal static int OCIBindByPosRef (IntPtr stmtp,
630                         out IntPtr bindpp,
631                         IntPtr errhp,
632                         uint position,
633                         ref IntPtr valuep,
634                         int value_sz,
635                         [MarshalAs (UnmanagedType.U2)] OciDataType dty,
636                         ref short indp,
637                         IntPtr alenp,
638                         IntPtr rcodep,
639                         uint maxarr_len,
640                         IntPtr curelp,
641                         uint mode)
642                 {
643                         #if TRACE
644                         Trace.WriteLineIf(traceOci, "OCIBindByPos", "OCI");
645                         #endif
646                         return OciNativeCalls.OCIBindByPosRef (stmtp, out bindpp, errhp, position, ref valuep,
647                                 value_sz, dty, ref indp, alenp, rcodep, maxarr_len, curelp, mode);
648                 }
649
650                 internal static int OCIBindByPosBytes (IntPtr stmtp,
651                         out IntPtr bindpp,
652                         IntPtr errhp,
653                         uint position,
654                         byte[] valuep,
655                         int value_sz,
656                         [MarshalAs (UnmanagedType.U2)] OciDataType dty,
657                         ref short indp,
658                         IntPtr alenp,
659                         IntPtr rcodep,
660                         uint maxarr_len,
661                         IntPtr curelp,
662                         uint mode)
663                 {
664                         #if TRACE
665                         Trace.WriteLineIf(traceOci, "OCIBindByPos", "OCI");
666                         #endif
667                         return OciNativeCalls.OCIBindByPosBytes (stmtp, out bindpp, errhp, position, valuep,
668                                 value_sz, dty, ref indp, alenp, rcodep, maxarr_len, curelp, mode);
669                 }
670
671                 [DllImport ("oci")]
672                 internal static extern void OCIDateTimeConstruct (IntPtr hndl,
673                         IntPtr err,
674                         IntPtr datetime,
675                         short year,
676                         byte month,
677                         byte day,
678                         byte hour,
679                         byte min,
680                         byte sec,
681                         uint fsec,
682                         byte[] timezone,
683                         uint timezone_length);
684
685                 [DllImport ("oci")]
686                 internal static extern void OCIDateTimeGetDate (IntPtr hndl,
687                         IntPtr err,
688                         IntPtr datetime,
689                         out short year,
690                         out byte month,
691                         out byte day);
692
693                 [DllImport ("oci")]
694                 internal static extern void OCIDateTimeGetTime (IntPtr hndl,
695                         IntPtr err,
696                         IntPtr datetime,
697                         out byte hour,
698                         out byte min,
699                         out byte sec,
700                         out uint fsec);
701                                 
702                 [DllImport ("oci")]
703                 internal static extern int OCIIntervalGetDaySecond (IntPtr hndl,
704                         IntPtr err,
705                         out int days,
706                         out int hours,
707                         out int mins,
708                         out int secs,
709                         out int fsec,
710                         IntPtr interval);
711
712                 [DllImport ("oci")]
713                 internal static extern int OCIIntervalGetYearMonth (IntPtr hndl,
714                         IntPtr err,
715                         out int years,
716                         out int months,
717                         IntPtr interval);
718
719                 internal static int OCIDefineByPos (IntPtr stmtp,
720                         out IntPtr defnpp,
721                         IntPtr errhp,
722                         int position,
723                         IntPtr valuep,
724                         int value_sz,
725                         OciDataType dty,
726                         ref short indp,
727                         ref short rlenp,
728                         IntPtr rcodep,
729                         uint mode)
730                 {
731                         #if TRACE
732                         Trace.WriteLineIf(traceOci, "OCIDefineByPos", "OCI");
733                         #endif
734                         return OciNativeCalls.OCIDefineByPos (stmtp, out defnpp, errhp, position, valuep,
735                                 value_sz, dty, ref indp, ref rlenp, rcodep, mode);
736                 }
737
738                 internal static int OCIDefineByPosPtr (IntPtr stmtp,
739                         out IntPtr defnpp,
740                         IntPtr errhp,
741                         int position,
742                         ref IntPtr valuep,
743                         int value_sz,
744                         OciDataType dty,
745                         ref short indp,
746                         ref short rlenp,
747                         IntPtr rcodep,
748                         uint mode)
749                 {
750                         #if TRACE
751                         Trace.WriteLineIf(traceOci, "OCIDefineByPosPtr", "OCI");
752                         #endif
753                         return OciNativeCalls.OCIDefineByPosPtr (stmtp, out defnpp, errhp, position, ref valuep,
754                                 value_sz, dty, ref indp, ref rlenp, rcodep, mode);
755                 }
756
757                 internal static int OCIDescriptorFree (IntPtr hndlp,
758                         OciHandleType type)
759                 {
760                         #if TRACE
761                         Trace.WriteLineIf(traceOci, string.Format("OCIDescriptorFree ({0})", type), "OCI");
762                         #endif
763                         return OciNativeCalls.OCIDescriptorFree (hndlp, type);
764                 }
765
766                 internal static int OCIEnvCreate (out IntPtr envhpp,
767                         OciEnvironmentMode mode,
768                         IntPtr ctxp,
769                         IntPtr malocfp,
770                         IntPtr ralocfp,
771                         IntPtr mfreep,
772                         int xtramem_sz,
773                         IntPtr usrmempp)
774                 {
775                         #if TRACE
776                         Trace.WriteLineIf(traceOci, "OCIEnvCreate", "OCI");
777                         #endif
778                         return OciNativeCalls.OCIEnvCreate (out envhpp, mode, ctxp, malocfp, ralocfp, mfreep,
779                                 xtramem_sz, usrmempp);
780                 }
781
782                 internal static int OCICacheFree (IntPtr envhp,
783                         IntPtr svchp,
784                         IntPtr stmthp)
785                 {
786                         #if TRACE
787                         Trace.WriteLineIf(traceOci, "OCICacheFree", "OCI");
788                         #endif
789                         return OciNativeCalls.OCICacheFree (envhp, svchp, stmthp);
790                 }
791
792                 internal static int OCIAttrGet (IntPtr trgthndlp,
793                         OciHandleType trghndltyp,
794                         out IntPtr attributep,
795                         out int sizep,
796                         OciAttributeType attrtype,
797                         IntPtr errhp)
798                 {
799                         #if TRACE
800                         Trace.WriteLineIf(traceOci, "OCIAttrGet", "OCI");
801                         #endif
802                         return OciNativeCalls.OCIAttrGet (trgthndlp, trghndltyp, out attributep, out sizep, attrtype, errhp);
803                 }
804
805                 internal static int OCIAttrGetSByte (IntPtr trgthndlp,
806                         OciHandleType trghndltyp,
807                         out sbyte attributep,
808                         IntPtr sizep,
809                         OciAttributeType attrtype,
810                         IntPtr errhp)
811                 {
812                         #if TRACE
813                         Trace.WriteLineIf(traceOci, "OCIAttrGetSByte", "OCI");
814                         #endif
815                         return OciNativeCalls.OCIAttrGetSByte (trgthndlp, trghndltyp, out attributep, sizep, attrtype, errhp);
816                 }
817
818                 internal static int OCIAttrGetByte (IntPtr trgthndlp,
819                         OciHandleType trghndltyp,
820                         out byte attributep,
821                         IntPtr sizep,
822                         OciAttributeType attrtype,
823                         IntPtr errhp)
824                 {
825                         #if TRACE
826                         Trace.WriteLineIf(traceOci, "OCIAttrGetByte", "OCI");
827                         #endif
828                         return OciNativeCalls.OCIAttrGetByte (trgthndlp, trghndltyp, out attributep, sizep, attrtype, errhp);
829                 }
830
831                 internal static int OCIAttrGetUInt16 (IntPtr trgthndlp,
832                         OciHandleType trghndltyp,
833                         out ushort attributep,
834                         IntPtr sizep,
835                         OciAttributeType attrtype,
836                         IntPtr errhp)
837                 {
838                         #if TRACE
839                         Trace.WriteLineIf(traceOci, "OCIAttrGetUInt16", "OCI");
840                         #endif
841                         return OciNativeCalls.OCIAttrGetUInt16 (trgthndlp, trghndltyp, out attributep, sizep, attrtype, errhp);
842                 }
843
844                 internal static int OCIAttrGetInt32 (IntPtr trgthndlp,
845                         OciHandleType trghndltyp,
846                         out int attributep,
847                         IntPtr sizep,
848                         OciAttributeType attrtype,
849                         IntPtr errhp)
850                 {
851                         #if TRACE
852                         Trace.WriteLineIf(traceOci, "OCIAttrGetInt32", "OCI");
853                         #endif
854                         return OciNativeCalls.OCIAttrGetInt32 (trgthndlp, trghndltyp, out attributep, sizep, attrtype, errhp);
855                 }
856
857                 internal static int OCIAttrGetIntPtr (IntPtr trgthndlp,
858                         OciHandleType trghndltyp,
859                         out IntPtr attributep,
860                         IntPtr sizep,
861                         OciAttributeType attrtype,
862                         IntPtr errhp)
863                 {
864                         #if TRACE
865                         Trace.WriteLineIf(traceOci, "OCIAttrGetIntPtr", "OCI");
866                         #endif
867                         return OciNativeCalls.OCIAttrGetIntPtr (trgthndlp, trghndltyp, out attributep, sizep, attrtype, errhp);
868                 }
869
870                 internal static int OCIDescriptorAlloc (IntPtr parenth,
871                         out IntPtr hndlpp,
872                         OciHandleType type,
873                         int xtramem_sz,
874                         IntPtr usrmempp)
875                 {
876                         #if TRACE
877                         Trace.WriteLineIf(traceOci, "OCIDescriptorAlloc", "OCI");
878                         #endif
879                         return OciNativeCalls.OCIDescriptorAlloc (parenth, out hndlpp, type, xtramem_sz, usrmempp);
880                 }
881
882                 internal static int OCIHandleAlloc (IntPtr parenth,
883                         out IntPtr descpp,
884                         OciHandleType type,
885                         int xtramem_sz,
886                         IntPtr usrmempp)
887                 {
888                         #if TRACE
889                         Trace.WriteLineIf(traceOci, string.Format("OCIHandleAlloc ({0})", type), "OCI");
890                         #endif
891                         return OciNativeCalls.OCIHandleAlloc (parenth, out descpp, type, xtramem_sz, usrmempp);
892                 }
893
894                 internal static int OCIHandleFree (IntPtr hndlp,
895                         OciHandleType type)
896                 {
897                         #if TRACE
898                         Trace.WriteLineIf(traceOci, string.Format("OCIHandleFree ({0})", type), "OCI");
899                         #endif
900                         return OciNativeCalls.OCIHandleFree (hndlp, type);
901                 }
902
903                 internal static int OCILobClose (IntPtr svchp,
904                         IntPtr errhp,
905                         IntPtr locp)
906                 {
907                         #if TRACE
908                         Trace.WriteLineIf(traceOci, "OCILobClose", "OCI");
909                         #endif
910                         return OciNativeCalls.OCILobClose (svchp, errhp, locp);
911                 }
912
913                 internal static int OCILobCopy (IntPtr svchp,
914                         IntPtr errhp,
915                         IntPtr dst_locp,
916                         IntPtr src_locp,
917                         uint amount,
918                         uint dst_offset,
919                         uint src_offset)
920                 {
921                         #if TRACE
922                         Trace.WriteLineIf(traceOci, "OCILobCopy", "OCI");
923                         #endif
924                         return OciNativeCalls.OCILobCopy (svchp, errhp, dst_locp, src_locp, amount, dst_offset, src_offset);
925                 }
926
927                 internal static int OCILobErase (IntPtr svchp,
928                         IntPtr errhp,
929                         IntPtr locp,
930                         ref uint amount,
931                         uint offset)
932                 {
933                         #if TRACE
934                         Trace.WriteLineIf(traceOci, "OCILobErase", "OCI");
935                         #endif
936                         return OciNativeCalls.OCILobErase (svchp, errhp, locp, ref amount, offset);
937                 }
938
939                 internal static int OCILobGetChunkSize (IntPtr svchp,
940                         IntPtr errhp,
941                         IntPtr locp,
942                         out uint chunk_size)
943                 {
944                         #if TRACE
945                         Trace.WriteLineIf(traceOci, "OCILobGetChunkSize", "OCI");
946                         #endif
947                         return OciNativeCalls.OCILobGetChunkSize (svchp, errhp, locp, out chunk_size);
948                 }
949
950                 internal static int OCILobGetLength (IntPtr svchp,
951                         IntPtr errhp,
952                         IntPtr locp,
953                         out uint lenp)
954                 {
955                         #if TRACE
956                         Trace.WriteLineIf(traceOci, "OCILobGetLength", "OCI");
957                         #endif
958                         return OciNativeCalls.OCILobGetLength (svchp, errhp, locp, out lenp);
959                 }
960
961                 internal static int OCILobOpen (IntPtr svchp,
962                         IntPtr errhp,
963                         IntPtr locp,
964                         byte mode)
965                 {
966                         #if TRACE
967                         Trace.WriteLineIf(traceOci, "OCILobOpen", "OCI");
968                         #endif
969                         return OciNativeCalls.OCILobOpen (svchp, errhp, locp, mode);
970                 }
971
972                 internal static int OCILobRead (IntPtr svchp,
973                         IntPtr errhp,
974                         IntPtr locp,
975                         ref uint amtp,
976                         uint offset,
977                         byte[] bufp,
978                         uint bufl,
979                         IntPtr ctxp,
980                         IntPtr cbfp,
981                         ushort csid,
982                         byte csfrm)
983                 {
984                         #if TRACE
985                         Trace.WriteLineIf(traceOci, "OCILobRead", "OCI");
986                         #endif
987                         return OciNativeCalls.OCILobRead (svchp, errhp, locp, ref amtp, offset, bufp, bufl,
988                                 ctxp, cbfp, csid, csfrm);
989                 }
990
991                 internal static int OCILobTrim (IntPtr svchp,
992                         IntPtr errhp,
993                         IntPtr locp,
994                         uint newlen)
995                 {
996                         #if TRACE
997                         Trace.WriteLineIf(traceOci, "OCILobTrim", "OCI");
998                         #endif
999                         return OciNativeCalls.OCILobTrim (svchp, errhp, locp, newlen);
1000                 }
1001
1002                 internal static int OCILobWrite (IntPtr svchp,
1003                         IntPtr errhp,
1004                         IntPtr locp,
1005                         ref uint amtp,
1006                         uint offset,
1007                         byte[] bufp,
1008                         uint bufl,
1009                         byte piece,
1010                         IntPtr ctxp,
1011                         IntPtr cbfp,
1012                         ushort csid,
1013                         byte csfrm)
1014                 {
1015                         #if TRACE
1016                         Trace.WriteLineIf(traceOci, "OCILobWrite", "OCI");
1017                         #endif
1018                         return OciNativeCalls.OCILobWrite (svchp, errhp, locp, ref amtp, offset, bufp, bufl,
1019                                 piece, ctxp, cbfp, csid, csfrm);
1020                 }
1021
1022                 internal static int OCILobCharSetForm (IntPtr svchp, 
1023                         IntPtr errhp,
1024                         IntPtr locp,
1025                         out byte csfrm)
1026                 {
1027                         #if TRACE
1028                         Trace.WriteLineIf(traceOci, "OCILobCharSetForm", "OCI");
1029                         #endif
1030                         return OciNativeCalls.OCILobCharSetForm (svchp, errhp, locp, out csfrm);                        
1031                 }
1032                 
1033                 internal static int OCINlsGetInfo (IntPtr hndl,
1034                         IntPtr errhp,
1035                         ref byte[] bufp,
1036                         uint buflen,
1037                         ushort item)
1038                 {
1039                         #if TRACE
1040                         Trace.WriteLineIf(traceOci, "OCINlsGetInfo", "OCI");
1041                         #endif
1042                         return OciNativeCalls.OCINlsGetInfo (hndl, errhp, bufp, buflen, item);
1043                 }
1044
1045                 internal static int OCIServerAttach (IntPtr srvhp,
1046                         IntPtr errhp,
1047                         string dblink,
1048                         int dblink_len,
1049                         uint mode)
1050                 {
1051                         #if TRACE
1052                         Trace.WriteLineIf(traceOci, "OCIServerAttach", "OCI");
1053                         #endif
1054                         return OciNativeCalls.OCIServerAttach (srvhp, errhp, dblink, dblink_len, mode);
1055                 }
1056
1057                 internal static int OCIServerDetach (IntPtr srvhp,
1058                         IntPtr errhp,
1059                         uint mode)
1060                 {
1061                         #if TRACE
1062                         Trace.WriteLineIf(traceOci, "OCIServerDetach", "OCI");
1063                         #endif
1064                         return OciNativeCalls.OCIServerDetach (srvhp, errhp, mode);
1065                 }
1066
1067                 internal static int OCIServerVersion (IntPtr hndlp,
1068                         IntPtr errhp,
1069                         ref byte[] bufp,
1070                         uint bufsz,
1071                         OciHandleType hndltype)
1072                 {
1073                         #if TRACE
1074                         Trace.WriteLineIf(traceOci, "OCIServerVersion", "OCI");
1075                         #endif
1076                         return OciNativeCalls.OCIServerVersion (hndlp,
1077                                 errhp,
1078                                 bufp,
1079                                 bufsz,
1080                                 hndltype);
1081                 }
1082
1083                 internal static int OCISessionBegin (IntPtr svchp,
1084                         IntPtr errhp,
1085                         IntPtr usrhp,
1086                         OciCredentialType credt,
1087                         OciSessionMode mode)
1088                 {
1089                         #if TRACE
1090                         Trace.WriteLineIf(traceOci, "OCISessionBegin", "OCI");
1091                         #endif
1092                         return OciNativeCalls.OCISessionBegin (svchp, errhp, usrhp, credt, mode);
1093                 }
1094
1095                 internal static int OCISessionEnd (IntPtr svchp,
1096                         IntPtr errhp,
1097                         IntPtr usrhp,
1098                         uint mode)
1099                 {
1100                         #if TRACE
1101                         Trace.WriteLineIf(traceOci, "OCISessionEnd", "OCI");
1102                         #endif
1103                         return OciNativeCalls.OCISessionEnd (svchp, errhp, usrhp, mode);
1104                 }
1105
1106                 internal static int OCIParamGet (IntPtr hndlp,
1107                         OciHandleType htype,
1108                         IntPtr errhp,
1109                         out IntPtr parmdpp,
1110                         int pos)
1111                 {
1112                         #if TRACE
1113                         Trace.WriteLineIf(traceOci, "OCIParamGet", "OCI");
1114                         #endif
1115                         return OciNativeCalls.OCIParamGet (hndlp, htype, errhp, out parmdpp, pos);
1116                 }
1117
1118                 internal static int OCIStmtExecute (IntPtr svchp,
1119                         IntPtr stmthp,
1120                         IntPtr errhp,
1121                         bool iters,
1122                         uint rowoff,
1123                         IntPtr snap_in,
1124                         IntPtr snap_out,
1125                         OciExecuteMode mode)
1126                 {
1127                         #if TRACE
1128                         Trace.WriteLineIf(traceOci, "OCIStmtExecute", "OCI");
1129                         #endif
1130
1131                         uint it = 0;
1132                         if (iters == true)
1133                                 it = 1;
1134
1135                         return OciNativeCalls.OCIStmtExecute (svchp, stmthp, errhp, it, rowoff,
1136                                 snap_in, snap_out, mode);
1137                 }
1138
1139                 internal static int OCIStmtFetch (IntPtr stmtp,
1140                         IntPtr errhp,
1141                         uint nrows,
1142                         ushort orientation,
1143                         uint mode)
1144                 {
1145                         #if TRACE
1146                         Trace.WriteLineIf(traceOci, "OCIStmtFetch", "OCI");
1147                         #endif
1148                         return OciNativeCalls.OCIStmtFetch (stmtp, errhp, nrows, orientation, mode);
1149                 }
1150
1151
1152                 internal static int OCIStmtPrepare (IntPtr stmthp,
1153                         IntPtr errhp,
1154                         byte [] stmt,
1155                         int stmt_length,
1156                         OciStatementLanguage language,
1157                         OciStatementMode mode)
1158                 {
1159                         #if TRACE
1160                         Trace.WriteLineIf(traceOci, string.Format("OCIStmtPrepare ({0})", System.Text.Encoding.UTF8.GetString(stmt)), "OCI");
1161                         #endif
1162
1163                         return OciNativeCalls.OCIStmtPrepare (stmthp, errhp, stmt, stmt_length, language, mode);
1164                 }
1165
1166                 internal static int OCITransCommit (IntPtr svchp,
1167                         IntPtr errhp,
1168                         uint flags)
1169                 {
1170                         #if TRACE
1171                         Trace.WriteLineIf(traceOci, "OCITransCommit", "OCI");
1172                         #endif
1173                         return OciNativeCalls.OCITransCommit (svchp, errhp, flags);
1174                 }
1175
1176                 internal static int OCITransRollback (IntPtr svchp,
1177                         IntPtr errhp,
1178                         uint flags)
1179                 {
1180                         #if TRACE
1181                         Trace.WriteLineIf(traceOci, "OCITransRollback", "OCI");
1182                         #endif
1183                         return OciNativeCalls.OCITransRollback (svchp, errhp, flags);
1184                 }
1185
1186                 internal static int OCITransStart (IntPtr svchp,
1187                         IntPtr errhp,
1188                         uint timeout,
1189                         OciTransactionFlags flags)
1190                 {
1191                         #if TRACE
1192                         Trace.WriteLineIf(traceOci, "OCITransStart", "OCI");
1193                         #endif
1194                         return OciNativeCalls.OCITransStart (svchp, errhp, timeout, flags);
1195                 }
1196
1197                 internal static int OCICharSetToUnicode (
1198                         IntPtr svchp,
1199                         StringBuilder dst,
1200                         byte [] src,
1201                         out int rsize)
1202                 {
1203                         int rc;
1204                         long retSize;
1205
1206                         #if TRACE
1207                         Trace.WriteLineIf(traceOci, "OCICharSetToUnicode", "OCI");
1208                         #endif
1209                         rc = OciNativeCalls.OCICharSetToUnicode (svchp, dst,
1210                                                 (dst != null ? dst.Capacity : 0), 
1211                                                 src, src.Length, out retSize);
1212                         rsize = (int) retSize;
1213                         return(rc);
1214                 }
1215
1216                 internal static int OCIUnicodeToCharSet (
1217                         IntPtr svchp,
1218                         byte [] dst,
1219                         string src,
1220                         out int rsize)
1221                 {
1222                         int rc;
1223                         long retSize;
1224
1225                         #if TRACE
1226                         Trace.WriteLineIf(traceOci, "OCIUnicodeToCharSet", "OCI");
1227                         #endif
1228
1229                         rc = OciNativeCalls.OCIUnicodeToCharSet (svchp, dst,
1230                                         (dst != null ? dst.Length : 0), 
1231                                         src, src.Length, out retSize);
1232                         rsize = (int) retSize;
1233                         return(rc);
1234                 }
1235
1236                 [DllImport ("oci")]
1237                 internal static extern int OCIDateTimeCheck (IntPtr hndl,
1238                         IntPtr err, IntPtr date, out uint valid);
1239
1240                 #endregion
1241
1242                 #region AllocateClear
1243
1244                 private static bool IsUnix =
1245                         (int) Environment.OSVersion.Platform == 4 || (int) Environment.OSVersion.Platform == 128 || (int) Environment.OSVersion.Platform == 6;
1246
1247                 [DllImport("libc")]
1248                 private static extern IntPtr calloc (int nmemb, int size);
1249
1250                 private const int GMEM_ZEROINIT = 0x40;
1251
1252                 [DllImport("kernel32")]
1253                 private static extern IntPtr GlobalAlloc (int flags, int bytes);
1254
1255                 //http://download-uk.oracle.com/docs/cd/B14117_01/appdev.101/b10779/oci05bnd.htm#423147
1256                 internal static IntPtr AllocateClear (int cb)
1257                 {
1258                         if (IsUnix) {
1259                                 return calloc (1, cb);
1260                         } else {
1261                                 return GlobalAlloc (GMEM_ZEROINIT, cb);
1262                         }
1263                 }
1264
1265                 #endregion AllocateClear
1266         }
1267 }
1268