AbstractDbException.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 : System.SystemException {
  41. protected SQLException _cause;
  42. protected AbstractDBConnection _connection;
  43. protected AbstractDbException(Exception cause, AbstractDBConnection connection) : base(cause.Message, cause) {
  44. _connection = connection;
  45. }
  46. protected AbstractDbException(SQLException cause, AbstractDBConnection connection) : this(String.Empty, cause, connection) {}
  47. protected AbstractDbException(string message, SQLException cause, AbstractDBConnection connection) : base(message, cause) {
  48. _connection = connection;
  49. _cause = cause;
  50. }
  51. abstract protected AbstractDbErrorCollection DbErrors { get; }
  52. /**
  53. * Gets the error code of the error.
  54. * @return The error code of the error.
  55. */
  56. protected int DbErrorCode {
  57. get {
  58. return _cause != null ? _cause.getErrorCode() : 0;
  59. }
  60. }
  61. /**
  62. * Gets the name of the OLE DB provider that generated the error.
  63. * @return the name of the OLE DB provider that generated the error.
  64. */
  65. public override String Source {
  66. get {
  67. return _connection != null ? _connection.JdbcProvider : null;
  68. }
  69. }
  70. public override string Message {
  71. get {
  72. StringBuilder sb = new StringBuilder();
  73. string message = base.Message;
  74. bool addNewLine = false;
  75. if (message != null && message.Length > 0) {
  76. sb.Append(message);
  77. addNewLine = true;
  78. }
  79. foreach (AbstractDbError err in DbErrors) {
  80. if (addNewLine)
  81. sb.Append(Environment.NewLine);
  82. addNewLine = true;
  83. sb.Append(err.DbMessage);
  84. }
  85. return sb.ToString();
  86. }
  87. }
  88. }
  89. }