OciEnvironmentHandle.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. IntPtr newHandle = IntPtr.Zero;
  31. OciCalls.OCIEnvCreate (out newHandle,
  32. mode,
  33. IntPtr.Zero,
  34. IntPtr.Zero,
  35. IntPtr.Zero,
  36. IntPtr.Zero,
  37. 0,
  38. IntPtr.Zero);
  39. SetHandle (newHandle);
  40. }
  41. #endregion // Constructors
  42. #region Methods
  43. public OciErrorInfo HandleError ()
  44. {
  45. int errbufSize = 512;
  46. IntPtr errbuf = Marshal.AllocHGlobal (errbufSize);
  47. OciErrorInfo info;
  48. info.ErrorCode = 0;
  49. info.ErrorMessage = String.Empty;
  50. OciCalls.OCIErrorGet (Handle,
  51. 1,
  52. IntPtr.Zero,
  53. out info.ErrorCode,
  54. errbuf,
  55. (uint) errbufSize,
  56. OciHandleType.Environment);
  57. object err = Marshal.PtrToStringAnsi (errbuf);
  58. if (err != null) {
  59. string errmsg = (string) err;
  60. info.ErrorMessage = String.Copy (errmsg);
  61. Marshal.FreeHGlobal (errbuf);
  62. }
  63. return info;
  64. }
  65. #endregion // Methods
  66. }
  67. }