2 // Mono.Data.PostgreSqlClient.PgSqlException.cs
5 // Rodrigo Moya (rodrigo@ximian.com)
6 // Daniel Morgan (danmorg@sc.rr.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System
.Runtime
.Serialization
;
35 namespace Mono
.Data
.PostgreSqlClient
38 /// Exceptions, as returned by SQL databases.
40 public sealed class PgSqlException
: SystemException
42 private PgSqlErrorCollection errors
;
44 internal PgSqlException()
45 : base("a SQL Exception has occurred") {
46 errors
= new PgSqlErrorCollection();
49 internal PgSqlException(byte theClass
, int lineNumber
,
50 string message
, int number
, string procedure
,
51 string server
, string source
, byte state
)
54 errors
= new PgSqlErrorCollection (theClass
,
57 server
, source
, state
);
66 return 0; // FIXME: throw exception here?
68 return errors
[0].Class
;
72 errors
[0].SetClass(value);
77 public PgSqlErrorCollection Errors
{
88 public int LineNumber
{
91 return 0; // FIXME: throw exception here?
92 return errors
[0].LineNumber
;
96 errors
[0].SetLineNumber(value);
101 public override string Message
{
103 if(errors
.Count
== 0)
104 return ""; // FIXME: throw exception?
109 for(i
= 0; i
< errors
.Count
- 1; i
++) {
110 msg
= msg
+ errors
[i
].Message
+ "\n";
112 msg
= msg
+ errors
[i
].Message
;
122 if(errors
.Count
== 0)
123 return 0; // FIXME: throw exception?
125 return errors
[0].Number
;
129 errors
[0].SetNumber(value);
134 public string Procedure
{
136 if(errors
.Count
== 0)
137 return ""; // FIXME: throw exception?
139 return errors
[0].Procedure
;
143 errors
[0].SetProcedure(value);
148 public string Server
{
150 if(errors
.Count
== 0)
151 return ""; // FIXME: throw exception?
153 return errors
[0].Server
;
157 errors
[0].SetServer(value);
162 public override string Source
{
164 if(errors
.Count
== 0)
165 return ""; // FIXME: throw exception?
167 return errors
[0].Source
;
171 errors
[0].SetSource(value);
178 if(errors
.Count
== 0)
179 return 0; // FIXME: throw exception?
181 return errors
[0].State
;
185 errors
[0].SetState(value);
189 #endregion // Properties
194 public override void GetObjectData(SerializationInfo si
,
195 StreamingContext context
) {
200 // [ClassInterface(ClassInterfaceType.AutoDual)]
201 public override string ToString() {
203 for (int i
= 0; i
< errors
.Count
; i
++) {
204 toStr
= toStr
+ errors
[i
].ToString() + "\n";
209 internal void Add(byte theClass
, int lineNumber
,
210 string message
, int number
, string procedure
,
211 string server
, string source
, byte state
) {
213 errors
.Add (theClass
, lineNumber
, message
,
215 server
, source
, state
);
220 // FIXME: destructor to release resources
223 #endregion // Methods