SqlException.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //
  2. // System.Data.SqlClient.SqlException.cs
  3. //
  4. // Author:
  5. // Rodrigo Moya ([email protected])
  6. // Daniel Morgan ([email protected])
  7. //
  8. // (C) Ximian, Inc
  9. //
  10. using System;
  11. using System.Data;
  12. using System.Runtime.Serialization;
  13. namespace System.Data.SqlClient
  14. {
  15. /// <summary>
  16. /// Exceptions, as returned by SQL databases.
  17. /// </summary>
  18. public sealed class SqlException : SystemException
  19. {
  20. private SqlErrorCollection errors = new SqlErrorCollection();
  21. internal SqlException() {
  22. }
  23. internal SqlException(byte theClass, int lineNumber,
  24. string message, int number, string procedure,
  25. string server, string source, byte state) {
  26. errors = new SqlErrorCollection (theClass,
  27. lineNumber, message,
  28. number, procedure,
  29. server, source, state);
  30. }
  31. #region Properties
  32. [MonoTODO]
  33. public byte Class {
  34. get {
  35. if(errors.Count == 0)
  36. return 0; // FIXME: throw exception here?
  37. else
  38. return errors[0].Class;
  39. }
  40. set {
  41. errors[0].SetClass(value);
  42. }
  43. }
  44. [MonoTODO]
  45. public SqlErrorCollection Errors {
  46. get {
  47. return errors;
  48. }
  49. set {
  50. errors = value;
  51. }
  52. }
  53. [MonoTODO]
  54. public int LineNumber {
  55. get {
  56. if(errors.Count == 0)
  57. return 0; // FIXME: throw exception here?
  58. return errors[0].LineNumber;
  59. }
  60. set {
  61. errors[0].SetLineNumber(value);
  62. }
  63. }
  64. [MonoTODO]
  65. public override string Message {
  66. get {
  67. if(errors.Count == 0)
  68. return ""; // FIXME: throw exception?
  69. else {
  70. String msg = "";
  71. int i = 0;
  72. for(i = 0; i < errors.Count - 1; i++) {
  73. msg = msg + errors[i].Message + "\n";
  74. }
  75. msg = msg + errors[i];
  76. return msg;
  77. }
  78. }
  79. }
  80. [MonoTODO]
  81. public int Number {
  82. get {
  83. if(errors.Count == 0)
  84. return 0; // FIXME: throw exception?
  85. else
  86. return errors[0].Number;
  87. }
  88. set {
  89. errors[0].SetNumber(value);
  90. }
  91. }
  92. [MonoTODO]
  93. public string Procedure {
  94. get {
  95. if(errors.Count == 0)
  96. return ""; // FIXME: throw exception?
  97. else
  98. return errors[0].Procedure;
  99. }
  100. set {
  101. errors[0].SetProcedure(value);
  102. }
  103. }
  104. [MonoTODO]
  105. public string Server {
  106. get {
  107. if(errors.Count == 0)
  108. return ""; // FIXME: throw exception?
  109. else
  110. return errors[0].Server;
  111. }
  112. set {
  113. errors[0].SetServer(value);
  114. }
  115. }
  116. [MonoTODO]
  117. public override string Source {
  118. get {
  119. if(errors.Count == 0)
  120. return ""; // FIXME: throw exception?
  121. else
  122. return errors[0].Source;
  123. }
  124. set {
  125. errors[0].SetSource(value);
  126. }
  127. }
  128. [MonoTODO]
  129. public byte State {
  130. get {
  131. if(errors.Count == 0)
  132. return 0; // FIXME: throw exception?
  133. else
  134. return errors[0].State;
  135. }
  136. set {
  137. errors[0].SetState(value);
  138. }
  139. }
  140. #endregion // Properties
  141. #region Methods
  142. [MonoTODO]
  143. public override void GetObjectData(SerializationInfo si,
  144. StreamingContext context) {
  145. // FIXME: to do
  146. }
  147. // [Serializable]
  148. // [ClassInterface(ClassInterfaceType.AutoDual)]
  149. public override string ToString() {
  150. String toStr = "";
  151. for (int i = 0; i < errors.Count; i++) {
  152. toStr = toStr + errors[i].ToString() + "\n";
  153. }
  154. return toStr;
  155. }
  156. internal void Add(byte theClass, int lineNumber,
  157. string message, int number, string procedure,
  158. string server, string source, byte state) {
  159. errors.Add (theClass, lineNumber, message,
  160. number, procedure,
  161. server, source, state);
  162. }
  163. [MonoTODO]
  164. ~SqlException() {
  165. // FIXME: destructor to release resources
  166. }
  167. #endregion // Methods
  168. }
  169. }