SqlException.cs 3.6 KB

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