OleDbException.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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.ComponentModel;
  12. using System.Data;
  13. using System.Data.Common;
  14. using System.Runtime.InteropServices;
  15. using System.Runtime.Serialization;
  16. namespace System.Data.OleDb
  17. {
  18. [Serializable]
  19. public sealed class OleDbException : ExternalException
  20. {
  21. private OleDbConnection connection;
  22. #region Constructors
  23. internal OleDbException (OleDbConnection cnc)
  24. {
  25. connection = cnc;
  26. }
  27. #endregion // Constructors
  28. #region Properties
  29. // FIXME : On .NET the string is System.Data.OleDb.OleDbException+ErrorConverter
  30. [TypeConverterAttribute (typeof (OleDbException))]
  31. public override int ErrorCode {
  32. get {
  33. GdaList glist;
  34. IntPtr errors;
  35. errors = libgda.gda_connection_get_errors (connection.GdaConnection);
  36. if (errors != IntPtr.Zero) {
  37. glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
  38. return (int) libgda.gda_error_get_number (glist.data);
  39. }
  40. return -1;
  41. }
  42. }
  43. [ DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
  44. public OleDbErrorCollection Errors {
  45. get {
  46. GdaList glist;
  47. IntPtr errors;
  48. OleDbErrorCollection col = new OleDbErrorCollection ();
  49. errors = libgda.gda_connection_get_errors (connection.GdaConnection);
  50. if (errors != IntPtr.Zero) {
  51. glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
  52. while (glist != null) {
  53. col.Add (new OleDbError (
  54. libgda.gda_error_get_description (glist.data),
  55. (int) libgda.gda_error_get_number (glist.data),
  56. libgda.gda_error_get_source (glist.data),
  57. libgda.gda_error_get_sqlstate (glist.data)));
  58. glist = (GdaList) Marshal.PtrToStructure (glist.next,
  59. typeof (GdaList));
  60. }
  61. }
  62. return col;
  63. }
  64. }
  65. public override string Message {
  66. get {
  67. GdaList glist;
  68. IntPtr errors;
  69. string msg = "";
  70. errors = libgda.gda_connection_get_errors (connection.GdaConnection);
  71. if (errors != IntPtr.Zero) {
  72. glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
  73. while (glist != null) {
  74. msg = msg + ";" + libgda.gda_error_get_description (glist.data);
  75. glist = (GdaList) Marshal.PtrToStructure (glist.next,
  76. typeof (GdaList));
  77. }
  78. return msg;
  79. }
  80. return null;
  81. }
  82. }
  83. public override string Source {
  84. get {
  85. GdaList glist;
  86. IntPtr errors;
  87. errors = libgda.gda_connection_get_errors (connection.GdaConnection);
  88. if (errors != IntPtr.Zero) {
  89. glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
  90. return libgda.gda_error_get_source (glist.data);
  91. }
  92. return null;
  93. }
  94. }
  95. #endregion // Properties
  96. #region Methods
  97. public override void GetObjectData (SerializationInfo si, StreamingContext context)
  98. {
  99. if (si == null)
  100. throw new ArgumentNullException ("si");
  101. si.AddValue ("connection", connection);
  102. base.GetObjectData (si, context);
  103. throw new NotImplementedException ();
  104. }
  105. #endregion // Methods
  106. }
  107. }