* OleDbDataReader.cs: Removed bogus MonoTODO.
[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.Globalization;
39 using System.Runtime.InteropServices;
40 using System.Runtime.Serialization;
41
42 namespace System.Data.OleDb
43 {
44         [Serializable]
45 #if NET_2_0
46         public sealed class OleDbException : DbException
47 #else
48         public sealed class OleDbException : ExternalException
49 #endif
50         {
51                 private OleDbConnection connection;
52
53                 #region Constructors
54
55                 internal OleDbException (OleDbConnection cnc)
56                 {
57                         connection = cnc;
58                 }
59                 
60                 #endregion // Constructors
61                 
62                 #region Properties
63
64                 [TypeConverterAttribute (typeof (OleDbException.ErrorCodeConverter))]
65                 public override int ErrorCode {
66                         get {
67                                 GdaList glist;
68                                 IntPtr errors;
69
70                                 errors = libgda.gda_connection_get_errors (connection.GdaConnection);
71                                 if (errors != IntPtr.Zero) {
72                                         glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
73                                         return (int) libgda.gda_error_get_number (glist.data);
74                                 }
75
76                                 return -1;
77                         }
78                 }
79                 
80                 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
81                 public OleDbErrorCollection Errors {
82                         get {
83                                 GdaList glist;
84                                 IntPtr errors;
85                                 OleDbErrorCollection col = new OleDbErrorCollection ();
86                                 
87                                 errors = libgda.gda_connection_get_errors (connection.GdaConnection);
88                                 if (errors != IntPtr.Zero) {
89                                         glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
90                                         while (glist != null) {
91                                                 col.Add (new OleDbError (
92                                                                  libgda.gda_error_get_description (glist.data),
93                                                                  (int) libgda.gda_error_get_number (glist.data),
94                                                                  libgda.gda_error_get_source (glist.data),
95                                                                  libgda.gda_error_get_sqlstate (glist.data)));
96                                                 glist = (GdaList) Marshal.PtrToStructure (glist.next,
97                                                                                           typeof (GdaList));
98                                         }
99                                 }
100
101                                 return col;
102                         }
103                 }
104
105 #if NET_1_0 || ONLY_1_1
106                 public
107                 override
108 #else
109                 new
110 #endif
111                 string Message {
112                         get {
113                                 GdaList glist;
114                                 IntPtr errors;
115                                 string msg = "";
116
117                                 errors = libgda.gda_connection_get_errors (connection.GdaConnection);
118                                 if (errors != IntPtr.Zero) {
119                                         glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
120                                         while (glist != null) {
121                                                 msg = msg + ";" +  libgda.gda_error_get_description (glist.data);
122                                                 glist = (GdaList) Marshal.PtrToStructure (glist.next,
123                                                                                           typeof (GdaList));
124                                         }
125
126                                         return msg;
127                                 }
128
129                                 return null;
130                         }
131                 }
132
133 #if NET_1_0 || ONLY_1_1
134                 public
135                 override
136 #else
137                 new
138 #endif
139                 string Source {
140                         get {
141                                 GdaList glist;
142                                 IntPtr errors;
143
144                                 errors = libgda.gda_connection_get_errors (connection.GdaConnection);
145                                 if (errors != IntPtr.Zero) {
146                                         glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
147                                         return libgda.gda_error_get_source (glist.data);
148                                 }
149
150                                 return null;
151                         }
152                 }
153
154                 #endregion // Properties
155
156                 #region Methods
157
158                 public override void GetObjectData (SerializationInfo si, StreamingContext context)
159                 {
160                         if (si == null)
161                                 throw new ArgumentNullException ("si");
162
163                         si.AddValue ("connection", connection);
164                         base.GetObjectData (si, context);
165                         throw new NotImplementedException ();
166                 }
167
168                 #endregion // Methods
169
170                 internal sealed class ErrorCodeConverter : Int32Converter
171                 {
172                         [MonoTODO]
173                         public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) {
174                                 return base.ConvertTo (context, culture, value, destinationType);
175                         }
176                 }
177         }
178 }