OleDbException.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // System.Data.OleDb.OleDbException
  3. //
  4. // Author:
  5. // Rodrigo Moya ([email protected])
  6. // Tim Coleman ([email protected])
  7. //
  8. // Copyright (C) Rodrigo Moya, 2002
  9. // Copyright (C) Tim Coleman, 2002
  10. //
  11. using System.Data;
  12. using System.Data.Common;
  13. using System.Runtime.InteropServices;
  14. using System.Runtime.Serialization;
  15. namespace System.Data.OleDb
  16. {
  17. [Serializable]
  18. public sealed class OleDbException : ExternalException
  19. {
  20. private OleDbConnection connection;
  21. #region Constructors
  22. internal OleDbException (OleDbConnection cnc)
  23. {
  24. connection = cnc;
  25. }
  26. #endregion // Constructors
  27. #region Properties
  28. public override int ErrorCode {
  29. get {
  30. GdaList glist;
  31. IntPtr errors;
  32. errors = libgda.gda_connection_get_errors (connection.GdaConnection);
  33. if (errors != IntPtr.Zero) {
  34. glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
  35. return (int) libgda.gda_error_get_number (glist.data);
  36. }
  37. return -1;
  38. }
  39. }
  40. public OleDbErrorCollection Errors {
  41. get {
  42. GdaList glist;
  43. IntPtr errors;
  44. OleDbErrorCollection col = new OleDbErrorCollection ();
  45. errors = libgda.gda_connection_get_errors (connection.GdaConnection);
  46. if (errors != IntPtr.Zero) {
  47. glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
  48. while (glist != null) {
  49. col.Add (new OleDbError (
  50. libgda.gda_error_get_description (glist.data),
  51. (int) libgda.gda_error_get_number (glist.data),
  52. libgda.gda_error_get_source (glist.data),
  53. libgda.gda_error_get_sqlstate (glist.data)));
  54. glist = (GdaList) Marshal.PtrToStructure (glist.next,
  55. typeof (GdaList));
  56. }
  57. }
  58. return col;
  59. }
  60. }
  61. public override string Message {
  62. get {
  63. GdaList glist;
  64. IntPtr errors;
  65. string msg = "";
  66. errors = libgda.gda_connection_get_errors (connection.GdaConnection);
  67. if (errors != IntPtr.Zero) {
  68. glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
  69. while (glist != null) {
  70. msg = msg + ";" + libgda.gda_error_get_description (glist.data);
  71. glist = (GdaList) Marshal.PtrToStructure (glist.next,
  72. typeof (GdaList));
  73. }
  74. return msg;
  75. }
  76. return null;
  77. }
  78. }
  79. public override string Source {
  80. get {
  81. GdaList glist;
  82. IntPtr errors;
  83. errors = libgda.gda_connection_get_errors (connection.GdaConnection);
  84. if (errors != IntPtr.Zero) {
  85. glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
  86. return libgda.gda_error_get_source (glist.data);
  87. }
  88. return null;
  89. }
  90. }
  91. #endregion // Properties
  92. #region Methods
  93. [MonoTODO]
  94. public override void GetObjectData (SerializationInfo si, StreamingContext context)
  95. {
  96. throw new NotImplementedException ();
  97. }
  98. #endregion // Methods
  99. }
  100. }