2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.Data / System.Data.OleDb / OleDbException.cs
1 //
2 // System.Data.OleDb.OleDbException
3 //
4 // Author:
5 //   Rodrigo Moya (rodrigo@ximian.com)
6 //   Tim Coleman (tim@timcoleman.com)
7 //
8 // Copyright (C) Rodrigo Moya, 2002
9 // Copyright (C) Tim Coleman, 2002
10 //
11
12 //
13 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 //
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 // 
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 // 
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 //
34
35 using System.ComponentModel;
36 using System.Data;
37 using System.Data.Common;
38 using System.Runtime.InteropServices;
39 using System.Runtime.Serialization;
40
41 namespace System.Data.OleDb
42 {
43         [Serializable]
44         public sealed class OleDbException : ExternalException
45         {
46                 private OleDbConnection connection;
47                 
48                 #region Constructors
49
50                 internal OleDbException (OleDbConnection cnc)
51                 {
52                         connection = cnc;
53                 }
54                 
55                 #endregion // Constructors
56                 
57                 #region Properties
58                 // FIXME : On .NET the string is System.Data.OleDb.OleDbException+ErrorConverter 
59                 [TypeConverterAttribute (typeof (OleDbException))]
60                 public override int ErrorCode { 
61                         get {
62                                 GdaList glist;
63                                 IntPtr errors;
64
65                                 errors = libgda.gda_connection_get_errors (connection.GdaConnection);
66                                 if (errors != IntPtr.Zero) {
67                                         glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
68                                         return (int) libgda.gda_error_get_number (glist.data);
69                                 }
70
71                                 return -1;
72                         }
73                 }
74                 
75                 [ DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
76                 public OleDbErrorCollection Errors {
77                         get {
78                                 GdaList glist;
79                                 IntPtr errors;
80                                 OleDbErrorCollection col = new OleDbErrorCollection ();
81                                 
82                                 errors = libgda.gda_connection_get_errors (connection.GdaConnection);
83                                 if (errors != IntPtr.Zero) {
84                                         glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
85                                         while (glist != null) {
86                                                 col.Add (new OleDbError (
87                                                                  libgda.gda_error_get_description (glist.data),
88                                                                  (int) libgda.gda_error_get_number (glist.data),
89                                                                  libgda.gda_error_get_source (glist.data),
90                                                                  libgda.gda_error_get_sqlstate (glist.data)));
91                                                 glist = (GdaList) Marshal.PtrToStructure (glist.next,
92                                                                                           typeof (GdaList));
93                                         }
94                                 }
95
96                                 return col;
97                         }
98                 }
99
100                 public override string Message {        
101                         get {
102                                 GdaList glist;
103                                 IntPtr errors;
104                                 string msg = "";
105
106                                 errors = libgda.gda_connection_get_errors (connection.GdaConnection);
107                                 if (errors != IntPtr.Zero) {
108                                         glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
109                                         while (glist != null) {
110                                                 msg = msg + ";" +  libgda.gda_error_get_description (glist.data);
111                                                 glist = (GdaList) Marshal.PtrToStructure (glist.next,
112                                                                                           typeof (GdaList));
113                                         }
114
115                                         return msg;
116                                 }
117
118                                 return null;
119                         }
120                 }
121
122                 public override string Source { 
123                         get {
124                                 GdaList glist;
125                                 IntPtr errors;
126
127                                 errors = libgda.gda_connection_get_errors (connection.GdaConnection);
128                                 if (errors != IntPtr.Zero) {
129                                         glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
130                                         return libgda.gda_error_get_source (glist.data);
131                                 }
132
133                                 return null;
134                         }
135                 }
136
137                 #endregion // Properties
138
139                 #region Methods
140
141                 public override void GetObjectData (SerializationInfo si, StreamingContext context)
142                 {
143                         if (si == null)
144                                 throw new ArgumentNullException ("si");
145
146                         si.AddValue ("connection", connection);
147                         base.GetObjectData (si, context);
148                         throw new NotImplementedException ();
149                 }
150
151                 #endregion // Methods
152         }
153 }