OleDbException.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. #if NET_2_0
  43. public sealed class OleDbException : DbException
  44. #else
  45. public sealed class OleDbException : ExternalException
  46. #endif
  47. {
  48. private OleDbConnection connection;
  49. #region Constructors
  50. internal OleDbException (OleDbConnection cnc)
  51. {
  52. connection = cnc;
  53. }
  54. #endregion // Constructors
  55. #region Properties
  56. [TypeConverterAttribute (typeof (OleDbException.ErrorCodeConverter))]
  57. public override int ErrorCode {
  58. get {
  59. GdaList glist;
  60. IntPtr errors;
  61. errors = libgda.gda_connection_get_errors (connection.GdaConnection);
  62. if (errors != IntPtr.Zero) {
  63. glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
  64. return (int) libgda.gda_error_get_number (glist.data);
  65. }
  66. return -1;
  67. }
  68. }
  69. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
  70. public OleDbErrorCollection Errors {
  71. get {
  72. GdaList glist;
  73. IntPtr errors;
  74. OleDbErrorCollection col = new OleDbErrorCollection ();
  75. errors = libgda.gda_connection_get_errors (connection.GdaConnection);
  76. if (errors != IntPtr.Zero) {
  77. glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
  78. while (glist != null) {
  79. col.Add (new OleDbError (
  80. libgda.gda_error_get_description (glist.data),
  81. (int) libgda.gda_error_get_number (glist.data),
  82. libgda.gda_error_get_source (glist.data),
  83. libgda.gda_error_get_sqlstate (glist.data)));
  84. glist = (GdaList) Marshal.PtrToStructure (glist.next,
  85. typeof (GdaList));
  86. }
  87. }
  88. return col;
  89. }
  90. }
  91. #if NET_1_0 || ONLY_1_1
  92. public
  93. override
  94. #else
  95. new
  96. #endif
  97. string Message {
  98. get {
  99. GdaList glist;
  100. IntPtr errors;
  101. string msg = "";
  102. errors = libgda.gda_connection_get_errors (connection.GdaConnection);
  103. if (errors != IntPtr.Zero) {
  104. glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
  105. while (glist != null) {
  106. msg = msg + ";" + libgda.gda_error_get_description (glist.data);
  107. glist = (GdaList) Marshal.PtrToStructure (glist.next,
  108. typeof (GdaList));
  109. }
  110. return msg;
  111. }
  112. return null;
  113. }
  114. }
  115. #if NET_1_0 || ONLY_1_1
  116. public
  117. override
  118. #else
  119. new
  120. #endif
  121. string Source {
  122. get {
  123. GdaList glist;
  124. IntPtr errors;
  125. errors = libgda.gda_connection_get_errors (connection.GdaConnection);
  126. if (errors != IntPtr.Zero) {
  127. glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
  128. return libgda.gda_error_get_source (glist.data);
  129. }
  130. return null;
  131. }
  132. }
  133. #endregion // Properties
  134. #region Methods
  135. public override void GetObjectData (SerializationInfo si, StreamingContext context)
  136. {
  137. if (si == null)
  138. throw new ArgumentNullException ("si");
  139. si.AddValue ("connection", connection);
  140. base.GetObjectData (si, context);
  141. throw new NotImplementedException ();
  142. }
  143. #endregion // Methods
  144. internal sealed class ErrorCodeConverter : Int32Converter
  145. {
  146. [MonoTODO]
  147. public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
  148. return base.ConvertTo (context, culture, value, destinationType);
  149. }
  150. }
  151. }
  152. }