OciEnvironmentHandle.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 = OciCalls.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. public OciErrorInfo HandleError ()
  45. {
  46. int errbufSize = 512;
  47. IntPtr errbuf = Marshal.AllocHGlobal (errbufSize);
  48. OciErrorInfo info;
  49. info.ErrorCode = 0;
  50. info.ErrorMessage = String.Empty;
  51. OciCalls.OCIErrorGet (Handle,
  52. 1,
  53. IntPtr.Zero,
  54. out info.ErrorCode,
  55. errbuf,
  56. (uint) errbufSize,
  57. OciHandleType.Environment);
  58. object err = Marshal.PtrToStringAnsi (errbuf);
  59. if (err != null) {
  60. string errmsg = (string) err;
  61. info.ErrorMessage = String.Copy (errmsg);
  62. Marshal.FreeHGlobal (errbuf);
  63. }
  64. return info;
  65. }
  66. #endregion // Methods
  67. }
  68. }