OciEnvironmentHandle.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // OciEnvironmentHandle.cs
  3. //
  4. // Part of managed C#/.NET library System.Data.OracleClient.dll
  5. //
  6. // Part of the Mono class libraries at
  7. // mcs/class/System.Data.OracleClient/System.Data.OracleClient.Oci
  8. //
  9. // Assembly: System.Data.OracleClient.dll
  10. // Namespace: System.Data.OracleClient.Oci
  11. //
  12. // Author:
  13. // Tim Coleman <[email protected]>
  14. //
  15. // Copyright (C) Tim Coleman, 2003
  16. //
  17. using System;
  18. using System.Runtime.InteropServices;
  19. namespace System.Data.OracleClient.Oci {
  20. internal class OciEnvironmentHandle : OciHandle, IDisposable
  21. {
  22. #region Constructors
  23. public OciEnvironmentHandle ()
  24. : this (OciEnvironmentMode.Default)
  25. {
  26. }
  27. public OciEnvironmentHandle (OciEnvironmentMode mode)
  28. : base (OciHandleType.Environment, null, IntPtr.Zero)
  29. {
  30. int status = 0;
  31. IntPtr newHandle = IntPtr.Zero;
  32. status = OCIEnvCreate (out newHandle,
  33. mode,
  34. IntPtr.Zero,
  35. IntPtr.Zero,
  36. IntPtr.Zero,
  37. IntPtr.Zero,
  38. 0,
  39. IntPtr.Zero);
  40. SetHandle (newHandle);
  41. }
  42. #endregion // Constructors
  43. #region Methods
  44. [DllImport ("oci")]
  45. static extern int OCIEnvCreate (out IntPtr envhpp,
  46. [MarshalAs (UnmanagedType.U4)] OciEnvironmentMode mode,
  47. IntPtr ctxp,
  48. IntPtr malocfp,
  49. IntPtr ralocfp,
  50. IntPtr mfreep,
  51. int xtramem_sz,
  52. IntPtr usrmempp);
  53. public OciErrorInfo HandleError ()
  54. {
  55. int errbufSize = 512;
  56. IntPtr errbuf = Marshal.AllocHGlobal (errbufSize);
  57. OciErrorInfo info;
  58. info.ErrorCode = 0;
  59. info.ErrorMessage = String.Empty;
  60. OciGlue.OCIErrorGet (Handle,
  61. 1,
  62. IntPtr.Zero,
  63. out info.ErrorCode,
  64. errbuf,
  65. (uint) errbufSize,
  66. OciHandleType.Environment);
  67. object err = Marshal.PtrToStringAnsi (errbuf);
  68. if (err != null) {
  69. string errmsg = (string) err;
  70. info.ErrorMessage = String.Copy (errmsg);
  71. Marshal.FreeHGlobal (errbuf);
  72. }
  73. return info;
  74. }
  75. #endregion // Methods
  76. }
  77. }