SqlException.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // System.Data.SqlClient.SqlException.cs
  3. //
  4. // Author:
  5. // Rodrigo Moya ([email protected])
  6. // Daniel Morgan ([email protected])
  7. // Tim Coleman ([email protected])
  8. //
  9. // (C) Ximian, Inc
  10. // Copyright (C) Tim Coleman, 2002
  11. //
  12. using Mono.Data.TdsClient.Internal;
  13. using System;
  14. using System.ComponentModel;
  15. using System.Data;
  16. using System.Runtime.Serialization;
  17. namespace System.Data.SqlClient {
  18. [Serializable]
  19. public sealed class SqlException : SystemException
  20. {
  21. #region Fields
  22. SqlErrorCollection errors;
  23. #endregion // Fields
  24. #region Constructors
  25. internal SqlException ()
  26. : base ("a SQL Exception has occurred.")
  27. {
  28. errors = new SqlErrorCollection();
  29. }
  30. internal SqlException (byte theClass, int lineNumber, string message, int number, string procedure, string server, string source, byte state)
  31. : base (message)
  32. {
  33. errors = new SqlErrorCollection (theClass, lineNumber, message, number, procedure, server, source, state);
  34. }
  35. #endregion // Constructors
  36. #region Properties
  37. [MonoTODO]
  38. public byte Class {
  39. get {
  40. if(errors.Count == 0)
  41. return 0; // FIXME: throw exception here?
  42. else
  43. return errors[0].Class;
  44. }
  45. }
  46. [MonoTODO]
  47. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  48. public SqlErrorCollection Errors {
  49. get { return errors; }
  50. }
  51. [MonoTODO]
  52. public int LineNumber {
  53. get { if(errors.Count == 0)
  54. return 0; // FIXME: throw exception here?
  55. return errors[0].LineNumber;
  56. }
  57. }
  58. [MonoTODO]
  59. public override string Message {
  60. get {
  61. if(errors.Count == 0)
  62. return ""; // FIXME: throw exception?
  63. else {
  64. String msg = "";
  65. int i = 0;
  66. for(i = 0; i < errors.Count - 1; i++) {
  67. msg = msg + errors[i].Message + "\n";
  68. }
  69. msg = msg + errors[i].Message;
  70. return msg;
  71. }
  72. }
  73. }
  74. [MonoTODO]
  75. public int Number {
  76. get {
  77. if(errors.Count == 0)
  78. return 0; // FIXME: throw exception?
  79. else
  80. return errors[0].Number;
  81. }
  82. }
  83. [MonoTODO]
  84. public string Procedure {
  85. get {
  86. if(errors.Count == 0)
  87. return ""; // FIXME: throw exception?
  88. else
  89. return errors[0].Procedure;
  90. }
  91. }
  92. [MonoTODO]
  93. public string Server {
  94. get {
  95. if(errors.Count == 0)
  96. return ""; // FIXME: throw exception?
  97. else
  98. return errors[0].Server;
  99. }
  100. }
  101. [MonoTODO]
  102. public override string Source {
  103. get {
  104. if(errors.Count == 0)
  105. return ""; // FIXME: throw exception?
  106. else
  107. return errors[0].Source;
  108. }
  109. }
  110. [MonoTODO]
  111. public byte State {
  112. get {
  113. if(errors.Count == 0)
  114. return 0; // FIXME: throw exception?
  115. else
  116. return errors[0].State;
  117. }
  118. }
  119. #endregion // Properties
  120. #region Methods
  121. [MonoTODO]
  122. public override void GetObjectData (SerializationInfo si, StreamingContext context)
  123. {
  124. throw new NotImplementedException ();
  125. }
  126. #endregion // Methods
  127. }
  128. }