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