OciCalls.cs 30 KB

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