2
0

AbstractDbException.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // System.Data.ProviderBase.AbstractDbException
  3. //
  4. // Authors:
  5. // Konstantin Triger <[email protected]>
  6. // Boris Kirzner <[email protected]>
  7. //
  8. // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
  9. //
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. namespace System.Data.ProviderBase {
  31. using java.sql;
  32. using System.Text;
  33. using System.Data.Common;
  34. /*
  35. * CURRENT LIMITATIONS
  36. * 1. Constructor for serialization SqlException(SerializationInfo info, StreamingContext sc)
  37. * is not supported.
  38. * 2. Method "void GetObjectData(...,...)" is not supported (serialization)
  39. */
  40. public abstract class AbstractDbException :
  41. #if NET_2_0
  42. DbException
  43. #else
  44. System.SystemException
  45. #endif
  46. {
  47. protected SQLException _cause;
  48. protected AbstractDBConnection _connection;
  49. protected AbstractDbException(Exception cause, AbstractDBConnection connection) : base(cause.Message, cause) {
  50. _connection = connection;
  51. }
  52. protected AbstractDbException(SQLException cause, AbstractDBConnection connection) : this(String.Empty, cause, connection) {}
  53. protected AbstractDbException(string message, SQLException cause, AbstractDBConnection connection) : base(message, cause) {
  54. _connection = connection;
  55. _cause = cause;
  56. }
  57. abstract protected AbstractDbErrorCollection DbErrors { get; }
  58. /**
  59. * Gets the error code of the error.
  60. * @return The error code of the error.
  61. */
  62. protected int DbErrorCode {
  63. get {
  64. return _cause != null ? _cause.getErrorCode() : 0;
  65. }
  66. }
  67. /**
  68. * Gets the name of the OLE DB provider that generated the error.
  69. * @return the name of the OLE DB provider that generated the error.
  70. */
  71. public override String Source {
  72. get {
  73. return _connection != null ? _connection.JdbcProvider : null;
  74. }
  75. }
  76. public override string Message {
  77. get {
  78. StringBuilder sb = new StringBuilder();
  79. string message = base.Message;
  80. bool addNewLine = false;
  81. if (message != null && message.Length > 0) {
  82. sb.Append(message);
  83. addNewLine = true;
  84. }
  85. foreach (AbstractDbError err in DbErrors) {
  86. if (addNewLine)
  87. sb.Append(Environment.NewLine);
  88. addNewLine = true;
  89. sb.Append(err.DbMessage);
  90. }
  91. return sb.ToString();
  92. }
  93. }
  94. }
  95. }