OciErrorHandle.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // OciErrorHandle.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 sealed class OciErrorHandle : OciHandle, IDisposable
  21. {
  22. #region Fields
  23. bool disposed = false;
  24. #endregion // Fields
  25. #region Constructors
  26. public OciErrorHandle (OciHandle parent, IntPtr newHandle)
  27. : base (OciHandleType.Error, parent, newHandle)
  28. {
  29. }
  30. #endregion // Constructors
  31. #region Methods
  32. protected override void Dispose (bool disposing)
  33. {
  34. if (!disposed) {
  35. disposed = true;
  36. base.Dispose (disposing);
  37. }
  38. }
  39. public OciErrorInfo HandleError ()
  40. {
  41. OciErrorInfo info;
  42. info.ErrorCode = 0;
  43. info.ErrorMessage = String.Empty;
  44. int errbufSize = 512;
  45. IntPtr errbuf = Marshal.AllocHGlobal (errbufSize);
  46. OciCalls.OCIErrorGet (this,
  47. 1,
  48. IntPtr.Zero,
  49. out info.ErrorCode,
  50. errbuf,
  51. (uint) errbufSize,
  52. OciHandleType.Error);
  53. object err = Marshal.PtrToStringAnsi (errbuf);
  54. if (err != null) {
  55. string errmsg = (string) err;
  56. info.ErrorMessage = String.Copy (errmsg);
  57. Marshal.FreeHGlobal (errbuf);
  58. }
  59. return info;
  60. }
  61. #endregion // Methods
  62. }
  63. }