* OleDbDataAdapter.cs: added stub for missing
[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 using System.ComponentModel;
13 using System.Data;
14 using System.Data.Common;
15 using System.Runtime.InteropServices;
16 using System.Runtime.Serialization;
17
18 namespace System.Data.OleDb
19 {
20         [Serializable]
21         public sealed class OleDbException : ExternalException
22         {
23                 private OleDbConnection connection;
24                 
25                 #region Constructors
26
27                 internal OleDbException (OleDbConnection cnc)
28                 {
29                         connection = cnc;
30                 }
31                 
32                 #endregion // Constructors
33                 
34                 #region Properties
35                 // FIXME : On .NET the string is System.Data.OleDb.OleDbException+ErrorConverter 
36                 [TypeConverterAttribute (typeof (OleDbException))]
37                 public override int ErrorCode { 
38                         get {
39                                 GdaList glist;
40                                 IntPtr errors;
41
42                                 errors = libgda.gda_connection_get_errors (connection.GdaConnection);
43                                 if (errors != IntPtr.Zero) {
44                                         glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
45                                         return (int) libgda.gda_error_get_number (glist.data);
46                                 }
47
48                                 return -1;
49                         }
50                 }
51                 
52                 [ DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
53                 public OleDbErrorCollection Errors {
54                         get {
55                                 GdaList glist;
56                                 IntPtr errors;
57                                 OleDbErrorCollection col = new OleDbErrorCollection ();
58                                 
59                                 errors = libgda.gda_connection_get_errors (connection.GdaConnection);
60                                 if (errors != IntPtr.Zero) {
61                                         glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
62                                         while (glist != null) {
63                                                 col.Add (new OleDbError (
64                                                                  libgda.gda_error_get_description (glist.data),
65                                                                  (int) libgda.gda_error_get_number (glist.data),
66                                                                  libgda.gda_error_get_source (glist.data),
67                                                                  libgda.gda_error_get_sqlstate (glist.data)));
68                                                 glist = (GdaList) Marshal.PtrToStructure (glist.next,
69                                                                                           typeof (GdaList));
70                                         }
71                                 }
72
73                                 return col;
74                         }
75                 }
76
77                 public override string Message {        
78                         get {
79                                 GdaList glist;
80                                 IntPtr errors;
81                                 string msg = "";
82
83                                 errors = libgda.gda_connection_get_errors (connection.GdaConnection);
84                                 if (errors != IntPtr.Zero) {
85                                         glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
86                                         while (glist != null) {
87                                                 msg = msg + ";" +  libgda.gda_error_get_description (glist.data);
88                                                 glist = (GdaList) Marshal.PtrToStructure (glist.next,
89                                                                                           typeof (GdaList));
90                                         }
91
92                                         return msg;
93                                 }
94
95                                 return null;
96                         }
97                 }
98
99                 public override string Source { 
100                         get {
101                                 GdaList glist;
102                                 IntPtr errors;
103
104                                 errors = libgda.gda_connection_get_errors (connection.GdaConnection);
105                                 if (errors != IntPtr.Zero) {
106                                         glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
107                                         return libgda.gda_error_get_source (glist.data);
108                                 }
109
110                                 return null;
111                         }
112                 }
113
114                 #endregion // Properties
115
116                 #region Methods
117
118                 public override void GetObjectData (SerializationInfo si, StreamingContext context)
119                 {
120                         if (si == null)
121                                 throw new ArgumentNullException ("si");
122
123                         si.AddValue ("connection", connection);
124                         base.GetObjectData (si, context);
125                         throw new NotImplementedException ();
126                 }
127
128                 #endregion // Methods
129         }
130 }