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