OleDbException.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. //
  12. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  13. //
  14. // Permission is hereby granted, free of charge, to any person obtaining
  15. // a copy of this software and associated documentation files (the
  16. // "Software"), to deal in the Software without restriction, including
  17. // without limitation the rights to use, copy, modify, merge, publish,
  18. // distribute, sublicense, and/or sell copies of the Software, and to
  19. // permit persons to whom the Software is furnished to do so, subject to
  20. // the following conditions:
  21. //
  22. // The above copyright notice and this permission notice shall be
  23. // included in all copies or substantial portions of the Software.
  24. //
  25. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  29. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  30. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  31. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  32. //
  33. using System.ComponentModel;
  34. using System.Data;
  35. using System.Data.Common;
  36. using System.Globalization;
  37. using System.Runtime.InteropServices;
  38. using System.Runtime.Serialization;
  39. namespace System.Data.OleDb
  40. {
  41. [Serializable]
  42. public sealed class OleDbException : ExternalException
  43. {
  44. private OleDbConnection connection;
  45. #region Constructors
  46. internal OleDbException (OleDbConnection cnc)
  47. {
  48. connection = cnc;
  49. }
  50. #endregion // Constructors
  51. #region Properties
  52. [TypeConverterAttribute (typeof (OleDbException.ErrorCodeConverter))]
  53. public override int ErrorCode {
  54. get {
  55. GdaList glist;
  56. IntPtr errors;
  57. errors = libgda.gda_connection_get_errors (connection.GdaConnection);
  58. if (errors != IntPtr.Zero) {
  59. glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
  60. return (int) libgda.gda_error_get_number (glist.data);
  61. }
  62. return -1;
  63. }
  64. }
  65. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
  66. public OleDbErrorCollection Errors {
  67. get {
  68. GdaList glist;
  69. IntPtr errors;
  70. OleDbErrorCollection col = new OleDbErrorCollection ();
  71. errors = libgda.gda_connection_get_errors (connection.GdaConnection);
  72. if (errors != IntPtr.Zero) {
  73. glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
  74. while (glist != null) {
  75. col.Add (new OleDbError (
  76. libgda.gda_error_get_description (glist.data),
  77. (int) libgda.gda_error_get_number (glist.data),
  78. libgda.gda_error_get_source (glist.data),
  79. libgda.gda_error_get_sqlstate (glist.data)));
  80. glist = (GdaList) Marshal.PtrToStructure (glist.next,
  81. typeof (GdaList));
  82. }
  83. }
  84. return col;
  85. }
  86. }
  87. public override string Message {
  88. get {
  89. GdaList glist;
  90. IntPtr errors;
  91. string msg = "";
  92. errors = libgda.gda_connection_get_errors (connection.GdaConnection);
  93. if (errors != IntPtr.Zero) {
  94. glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
  95. while (glist != null) {
  96. msg = msg + ";" + libgda.gda_error_get_description (glist.data);
  97. glist = (GdaList) Marshal.PtrToStructure (glist.next,
  98. typeof (GdaList));
  99. }
  100. return msg;
  101. }
  102. return null;
  103. }
  104. }
  105. public override string Source {
  106. get {
  107. GdaList glist;
  108. IntPtr errors;
  109. errors = libgda.gda_connection_get_errors (connection.GdaConnection);
  110. if (errors != IntPtr.Zero) {
  111. glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
  112. return libgda.gda_error_get_source (glist.data);
  113. }
  114. return null;
  115. }
  116. }
  117. #endregion // Properties
  118. #region Methods
  119. public override void GetObjectData (SerializationInfo si, StreamingContext context)
  120. {
  121. if (si == null)
  122. throw new ArgumentNullException ("si");
  123. si.AddValue ("connection", connection);
  124. base.GetObjectData (si, context);
  125. throw new NotImplementedException ();
  126. }
  127. #endregion // Methods
  128. internal sealed class ErrorCodeConverter : Int32Converter
  129. {
  130. [MonoTODO]
  131. public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
  132. return base.ConvertTo (context, culture, value, destinationType);
  133. }
  134. }
  135. }
  136. }