OciCalls.cs 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  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. [DllImport ("oci")]
  593. internal static extern int OCIIntervalFromText (IntPtr hndl,
  594. IntPtr err,
  595. string inpstring,
  596. long inplen,
  597. out IntPtr ret);
  598. internal static int OCIDefineByPos (IntPtr stmtp,
  599. out IntPtr defnpp,
  600. IntPtr errhp,
  601. int position,
  602. IntPtr valuep,
  603. int value_sz,
  604. OciDataType dty,
  605. ref short indp,
  606. ref short rlenp,
  607. IntPtr rcodep,
  608. uint mode)
  609. {
  610. #if TRACE
  611. Trace.WriteLineIf(traceOci, "OCIDefineByPos", "OCI");
  612. #endif
  613. return OciNativeCalls.OCIDefineByPos (stmtp, out defnpp, errhp, position, valuep,
  614. value_sz, dty, ref indp, ref rlenp, rcodep, mode);
  615. }
  616. internal static int OCIDefineByPosPtr (IntPtr stmtp,
  617. out IntPtr defnpp,
  618. IntPtr errhp,
  619. int position,
  620. ref IntPtr valuep,
  621. int value_sz,
  622. OciDataType dty,
  623. ref short indp,
  624. ref short rlenp,
  625. IntPtr rcodep,
  626. uint mode)
  627. {
  628. #if TRACE
  629. Trace.WriteLineIf(traceOci, "OCIDefineByPosPtr", "OCI");
  630. #endif
  631. return OciNativeCalls.OCIDefineByPosPtr (stmtp, out defnpp, errhp, position, ref valuep,
  632. value_sz, dty, ref indp, ref rlenp, rcodep, mode);
  633. }
  634. internal static int OCIDescriptorFree (IntPtr hndlp,
  635. OciHandleType type)
  636. {
  637. #if TRACE
  638. Trace.WriteLineIf(traceOci, string.Format("OCIDescriptorFree ({0})", type), "OCI");
  639. #endif
  640. return OciNativeCalls.OCIDescriptorFree (hndlp, type);
  641. }
  642. internal static int OCIEnvCreate (out IntPtr envhpp,
  643. OciEnvironmentMode mode,
  644. IntPtr ctxp,
  645. IntPtr malocfp,
  646. IntPtr ralocfp,
  647. IntPtr mfreep,
  648. int xtramem_sz,
  649. IntPtr usrmempp)
  650. {
  651. #if TRACE
  652. Trace.WriteLineIf(traceOci, "OCIEnvCreate", "OCI");
  653. #endif
  654. return OciNativeCalls.OCIEnvCreate (out envhpp, mode, ctxp, malocfp, ralocfp, mfreep,
  655. xtramem_sz, usrmempp);
  656. }
  657. internal static int OCIAttrGet (IntPtr trgthndlp,
  658. OciHandleType trghndltyp,
  659. out IntPtr attributep,
  660. out int sizep,
  661. OciAttributeType attrtype,
  662. IntPtr errhp)
  663. {
  664. #if TRACE
  665. Trace.WriteLineIf(traceOci, "OCIAttrGet", "OCI");
  666. #endif
  667. return OciNativeCalls.OCIAttrGet (trgthndlp, trghndltyp, out attributep, out sizep, attrtype, errhp);
  668. }
  669. internal static int OCIAttrGetSByte (IntPtr trgthndlp,
  670. OciHandleType trghndltyp,
  671. out sbyte attributep,
  672. IntPtr sizep,
  673. OciAttributeType attrtype,
  674. IntPtr errhp)
  675. {
  676. #if TRACE
  677. Trace.WriteLineIf(traceOci, "OCIAttrGetSByte", "OCI");
  678. #endif
  679. return OciNativeCalls.OCIAttrGetSByte (trgthndlp, trghndltyp, out attributep, sizep, attrtype, errhp);
  680. }
  681. internal static int OCIAttrGetByte (IntPtr trgthndlp,
  682. OciHandleType trghndltyp,
  683. out byte attributep,
  684. IntPtr sizep,
  685. OciAttributeType attrtype,
  686. IntPtr errhp)
  687. {
  688. #if TRACE
  689. Trace.WriteLineIf(traceOci, "OCIAttrGetByte", "OCI");
  690. #endif
  691. return OciNativeCalls.OCIAttrGetByte (trgthndlp, trghndltyp, out attributep, sizep, attrtype, errhp);
  692. }
  693. internal static int OCIAttrGetUInt16 (IntPtr trgthndlp,
  694. OciHandleType trghndltyp,
  695. out ushort attributep,
  696. IntPtr sizep,
  697. OciAttributeType attrtype,
  698. IntPtr errhp)
  699. {
  700. #if TRACE
  701. Trace.WriteLineIf(traceOci, "OCIAttrGetUInt16", "OCI");
  702. #endif
  703. return OciNativeCalls.OCIAttrGetUInt16 (trgthndlp, trghndltyp, out attributep, sizep, attrtype, errhp);
  704. }
  705. internal static int OCIAttrGetInt32 (IntPtr trgthndlp,
  706. OciHandleType trghndltyp,
  707. out int attributep,
  708. IntPtr sizep,
  709. OciAttributeType attrtype,
  710. IntPtr errhp)
  711. {
  712. #if TRACE
  713. Trace.WriteLineIf(traceOci, "OCIAttrGetInt32", "OCI");
  714. #endif
  715. return OciNativeCalls.OCIAttrGetInt32 (trgthndlp, trghndltyp, out attributep, sizep, attrtype, errhp);
  716. }
  717. internal static int OCIAttrGetIntPtr (IntPtr trgthndlp,
  718. OciHandleType trghndltyp,
  719. out IntPtr attributep,
  720. IntPtr sizep,
  721. OciAttributeType attrtype,
  722. IntPtr errhp)
  723. {
  724. #if TRACE
  725. Trace.WriteLineIf(traceOci, "OCIAttrGetIntPtr", "OCI");
  726. #endif
  727. return OciNativeCalls.OCIAttrGetIntPtr (trgthndlp, trghndltyp, out attributep, sizep, attrtype, errhp);
  728. }
  729. internal static int OCIDescriptorAlloc (IntPtr parenth,
  730. out IntPtr hndlpp,
  731. OciHandleType type,
  732. int xtramem_sz,
  733. IntPtr usrmempp)
  734. {
  735. #if TRACE
  736. Trace.WriteLineIf(traceOci, "OCIDescriptorAlloc", "OCI");
  737. #endif
  738. return OciNativeCalls.OCIDescriptorAlloc (parenth, out hndlpp, type, xtramem_sz, usrmempp);
  739. }
  740. internal static int OCIHandleAlloc (IntPtr parenth,
  741. out IntPtr descpp,
  742. OciHandleType type,
  743. int xtramem_sz,
  744. IntPtr usrmempp)
  745. {
  746. #if TRACE
  747. Trace.WriteLineIf(traceOci, string.Format("OCIHandleAlloc ({0})", type), "OCI");
  748. #endif
  749. return OciNativeCalls.OCIHandleAlloc (parenth, out descpp, type, xtramem_sz, usrmempp);
  750. }
  751. internal static int OCIHandleFree (IntPtr hndlp,
  752. OciHandleType type)
  753. {
  754. #if TRACE
  755. Trace.WriteLineIf(traceOci, string.Format("OCIHandleFree ({0})", type), "OCI");
  756. #endif
  757. return OciNativeCalls.OCIHandleFree (hndlp, type);
  758. }
  759. internal static int OCILobClose (IntPtr svchp,
  760. IntPtr errhp,
  761. IntPtr locp)
  762. {
  763. #if TRACE
  764. Trace.WriteLineIf(traceOci, "OCILobClose", "OCI");
  765. #endif
  766. return OciNativeCalls.OCILobClose (svchp, errhp, locp);
  767. }
  768. internal static int OCILobCopy (IntPtr svchp,
  769. IntPtr errhp,
  770. IntPtr dst_locp,
  771. IntPtr src_locp,
  772. uint amount,
  773. uint dst_offset,
  774. uint src_offset)
  775. {
  776. #if TRACE
  777. Trace.WriteLineIf(traceOci, "OCILobCopy", "OCI");
  778. #endif
  779. return OciNativeCalls.OCILobCopy (svchp, errhp, dst_locp, src_locp, amount, dst_offset, src_offset);
  780. }
  781. internal static int OCILobErase (IntPtr svchp,
  782. IntPtr errhp,
  783. IntPtr locp,
  784. ref uint amount,
  785. uint offset)
  786. {
  787. #if TRACE
  788. Trace.WriteLineIf(traceOci, "OCILobErase", "OCI");
  789. #endif
  790. return OciNativeCalls.OCILobErase (svchp, errhp, locp, ref amount, offset);
  791. }
  792. internal static int OCILobGetChunkSize (IntPtr svchp,
  793. IntPtr errhp,
  794. IntPtr locp,
  795. out uint chunk_size)
  796. {
  797. #if TRACE
  798. Trace.WriteLineIf(traceOci, "OCILobGetChunkSize", "OCI");
  799. #endif
  800. return OciNativeCalls.OCILobGetChunkSize (svchp, errhp, locp, out chunk_size);
  801. }
  802. internal static int OCILobGetLength (IntPtr svchp,
  803. IntPtr errhp,
  804. IntPtr locp,
  805. out uint lenp)
  806. {
  807. #if TRACE
  808. Trace.WriteLineIf(traceOci, "OCILobGetLength", "OCI");
  809. #endif
  810. return OciNativeCalls.OCILobGetLength (svchp, errhp, locp, out lenp);
  811. }
  812. internal static int OCILobOpen (IntPtr svchp,
  813. IntPtr errhp,
  814. IntPtr locp,
  815. byte mode)
  816. {
  817. #if TRACE
  818. Trace.WriteLineIf(traceOci, "OCILobOpen", "OCI");
  819. #endif
  820. return OciNativeCalls.OCILobOpen (svchp, errhp, locp, mode);
  821. }
  822. internal static int OCILobRead (IntPtr svchp,
  823. IntPtr errhp,
  824. IntPtr locp,
  825. ref uint amtp,
  826. uint offset,
  827. byte[] bufp,
  828. uint bufl,
  829. IntPtr ctxp,
  830. IntPtr cbfp,
  831. ushort csid,
  832. byte csfrm)
  833. {
  834. #if TRACE
  835. Trace.WriteLineIf(traceOci, "OCILobRead", "OCI");
  836. #endif
  837. return OciNativeCalls.OCILobRead (svchp, errhp, locp, ref amtp, offset, bufp, bufl,
  838. ctxp, cbfp, csid, csfrm);
  839. }
  840. internal static int OCILobTrim (IntPtr svchp,
  841. IntPtr errhp,
  842. IntPtr locp,
  843. uint newlen)
  844. {
  845. #if TRACE
  846. Trace.WriteLineIf(traceOci, "OCILobTrim", "OCI");
  847. #endif
  848. return OciNativeCalls.OCILobTrim (svchp, errhp, locp, newlen);
  849. }
  850. internal static int OCILobWrite (IntPtr svchp,
  851. IntPtr errhp,
  852. IntPtr locp,
  853. ref uint amtp,
  854. uint offset,
  855. byte[] bufp,
  856. uint bufl,
  857. byte piece,
  858. IntPtr ctxp,
  859. IntPtr cbfp,
  860. ushort csid,
  861. byte csfrm)
  862. {
  863. #if TRACE
  864. Trace.WriteLineIf(traceOci, "OCILobWrite", "OCI");
  865. #endif
  866. return OciNativeCalls.OCILobWrite (svchp, errhp, locp, ref amtp, offset, bufp, bufl,
  867. piece, ctxp, cbfp, csid, csfrm);
  868. }
  869. internal static int OCINlsGetInfo (IntPtr hndl,
  870. IntPtr errhp,
  871. ref byte[] bufp,
  872. uint buflen,
  873. ushort item)
  874. {
  875. #if TRACE
  876. Trace.WriteLineIf(traceOci, "OCINlsGetInfo", "OCI");
  877. #endif
  878. return OciNativeCalls.OCINlsGetInfo (hndl, errhp, bufp, buflen, item);
  879. }
  880. internal static int OCIServerAttach (IntPtr srvhp,
  881. IntPtr errhp,
  882. string dblink,
  883. int dblink_len,
  884. uint mode)
  885. {
  886. #if TRACE
  887. Trace.WriteLineIf(traceOci, "OCIServerAttach", "OCI");
  888. #endif
  889. return OciNativeCalls.OCIServerAttach (srvhp, errhp, dblink, dblink_len, mode);
  890. }
  891. internal static int OCIServerDetach (IntPtr srvhp,
  892. IntPtr errhp,
  893. uint mode)
  894. {
  895. #if TRACE
  896. Trace.WriteLineIf(traceOci, "OCIServerDetach", "OCI");
  897. #endif
  898. return OciNativeCalls.OCIServerDetach (srvhp, errhp, mode);
  899. }
  900. internal static int OCIServerVersion (IntPtr hndlp,
  901. IntPtr errhp,
  902. ref byte[] bufp,
  903. uint bufsz,
  904. OciHandleType hndltype)
  905. {
  906. #if TRACE
  907. Trace.WriteLineIf(traceOci, "OCIServerVersion", "OCI");
  908. #endif
  909. return OciNativeCalls.OCIServerVersion (hndlp,
  910. errhp,
  911. bufp,
  912. bufsz,
  913. hndltype);
  914. }
  915. internal static int OCISessionBegin (IntPtr svchp,
  916. IntPtr errhp,
  917. IntPtr usrhp,
  918. OciCredentialType credt,
  919. OciSessionMode mode)
  920. {
  921. #if TRACE
  922. Trace.WriteLineIf(traceOci, "OCISessionBegin", "OCI");
  923. #endif
  924. return OciNativeCalls.OCISessionBegin (svchp, errhp, usrhp, credt, mode);
  925. }
  926. internal static int OCISessionEnd (IntPtr svchp,
  927. IntPtr errhp,
  928. IntPtr usrhp,
  929. uint mode)
  930. {
  931. #if TRACE
  932. Trace.WriteLineIf(traceOci, "OCISessionEnd", "OCI");
  933. #endif
  934. return OciNativeCalls.OCISessionEnd (svchp, errhp, usrhp, mode);
  935. }
  936. internal static int OCIParamGet (IntPtr hndlp,
  937. OciHandleType htype,
  938. IntPtr errhp,
  939. out IntPtr parmdpp,
  940. int pos)
  941. {
  942. #if TRACE
  943. Trace.WriteLineIf(traceOci, "OCIParamGet", "OCI");
  944. #endif
  945. return OciNativeCalls.OCIParamGet (hndlp, htype, errhp, out parmdpp, pos);
  946. }
  947. internal static int OCIStmtExecute (IntPtr svchp,
  948. IntPtr stmthp,
  949. IntPtr errhp,
  950. bool iters,
  951. uint rowoff,
  952. IntPtr snap_in,
  953. IntPtr snap_out,
  954. OciExecuteMode mode)
  955. {
  956. #if TRACE
  957. Trace.WriteLineIf(traceOci, "OCIStmtExecute", "OCI");
  958. #endif
  959. uint it = 0;
  960. if (iters == true)
  961. it = 1;
  962. return OciNativeCalls.OCIStmtExecute (svchp, stmthp, errhp, it, rowoff,
  963. snap_in, snap_out, mode);
  964. }
  965. internal static int OCIStmtFetch (IntPtr stmtp,
  966. IntPtr errhp,
  967. uint nrows,
  968. ushort orientation,
  969. uint mode)
  970. {
  971. #if TRACE
  972. Trace.WriteLineIf(traceOci, "OCIStmtFetch", "OCI");
  973. #endif
  974. return OciNativeCalls.OCIStmtFetch (stmtp, errhp, nrows, orientation, mode);
  975. }
  976. internal static int OCIStmtPrepare (IntPtr stmthp,
  977. IntPtr errhp,
  978. byte [] stmt,
  979. int stmt_length,
  980. OciStatementLanguage language,
  981. OciStatementMode mode)
  982. {
  983. #if TRACE
  984. Trace.WriteLineIf(traceOci, string.Format("OCIStmtPrepare ({0})", System.Text.Encoding.UTF8.GetString(stmt)), "OCI");
  985. #endif
  986. return OciNativeCalls.OCIStmtPrepare (stmthp, errhp, stmt, stmt_length, language, mode);
  987. }
  988. internal static int OCITransCommit (IntPtr svchp,
  989. IntPtr errhp,
  990. uint flags)
  991. {
  992. #if TRACE
  993. Trace.WriteLineIf(traceOci, "OCITransCommit", "OCI");
  994. #endif
  995. return OciNativeCalls.OCITransCommit (svchp, errhp, flags);
  996. }
  997. internal static int OCITransRollback (IntPtr svchp,
  998. IntPtr errhp,
  999. uint flags)
  1000. {
  1001. #if TRACE
  1002. Trace.WriteLineIf(traceOci, "OCITransRollback", "OCI");
  1003. #endif
  1004. return OciNativeCalls.OCITransRollback (svchp, errhp, flags);
  1005. }
  1006. internal static int OCITransStart (IntPtr svchp,
  1007. IntPtr errhp,
  1008. uint timeout,
  1009. OciTransactionFlags flags)
  1010. {
  1011. #if TRACE
  1012. Trace.WriteLineIf(traceOci, "OCITransStart", "OCI");
  1013. #endif
  1014. return OciNativeCalls.OCITransStart (svchp, errhp, timeout, flags);
  1015. }
  1016. internal static int OCICharSetToUnicode (
  1017. IntPtr svchp,
  1018. StringBuilder dst,
  1019. byte [] src,
  1020. out int rsize)
  1021. {
  1022. #if TRACE
  1023. Trace.WriteLineIf(traceOci, "OCICharSetToUnicode", "OCI");
  1024. #endif
  1025. return OciNativeCalls.OCICharSetToUnicode (svchp, dst, dst!=null ? dst.Capacity : 0, src, src.Length, out rsize);
  1026. }
  1027. internal static int OCIUnicodeToCharSet (
  1028. IntPtr svchp,
  1029. byte [] dst,
  1030. [MarshalAs (UnmanagedType.LPWStr)] string src,
  1031. [MarshalAs (UnmanagedType.U4)] out int rsize)
  1032. {
  1033. #if TRACE
  1034. Trace.WriteLineIf(traceOci, "OCICharSetToUnicode", "OCI");
  1035. #endif
  1036. return OciNativeCalls.OCIUnicodeToCharSet (svchp, dst, dst!=null ? dst.Length : 0, src, src.Length, out rsize);
  1037. }
  1038. [DllImport ("oci")]
  1039. internal static extern int OCIDateTimeCheck (IntPtr hndl,
  1040. IntPtr err, IntPtr date, out uint valid);
  1041. #endregion
  1042. #region AllocateClear
  1043. private static bool IsUnix =
  1044. (int) Environment.OSVersion.Platform == 4 || (int) Environment.OSVersion.Platform == 128 || (int) Environment.OSVersion.Platform == 6;
  1045. [DllImport("libc")]
  1046. private static extern IntPtr calloc (int nmemb, int size);
  1047. private const int GMEM_ZEROINIT = 0x40;
  1048. [DllImport("kernel32")]
  1049. private static extern IntPtr GlobalAlloc (int flags, int bytes);
  1050. //http://download-uk.oracle.com/docs/cd/B14117_01/appdev.101/b10779/oci05bnd.htm#423147
  1051. internal static IntPtr AllocateClear (int cb)
  1052. {
  1053. if (IsUnix) {
  1054. return calloc (1, cb);
  1055. } else {
  1056. return GlobalAlloc (GMEM_ZEROINIT, cb);
  1057. }
  1058. }
  1059. #endregion AllocateClear
  1060. }
  1061. }