New test.
[mono.git] / mcs / class / System.Data / System.Data.SqlClient.jvm / SqlException.cs
1 //\r
2 // System.Data.SqlClient.SqlException\r
3 //
4 // Authors:
5 //      Konstantin Triger <kostat@mainsoft.com>
6 //      Boris Kirzner <borisk@mainsoft.com>
7 //      
8 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
9 //
10
11 //
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:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
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.
30 //\r
31 \r
32 namespace System.Data.SqlClient\r
33 {\r
34 \r
35     using java.sql;\r
36 \r
37     using System;\r
38         using System.Data.ProviderBase;\r
39 \r
40     /**\r
41      * The exception that is thrown when SQL Server returns a warning or error.\r
42      * This class cannot be inherited.\r
43      */\r
44 \r
45     /*\r
46     * CURRENT LIMITATIONS\r
47     * 1. Constructor for serialization SqlException(SerializationInfo info, StreamingContext sc) \r
48     *    is not supported.\r
49     * 2. Method "void GetObjectData(...,...)" is not supported (serialization)\r
50     */\r
51 \r
52     public sealed class SqlException : AbstractDbException\r
53     {\r
54                 internal SqlException(Exception cause, SqlConnection connection) : base(cause, connection) {}\r
55 \r
56                 internal SqlException(SQLException cause, SqlConnection connection) : base(cause, connection) {}\r
57 \r
58                 internal SqlException(string message, SQLException cause, SqlConnection connection) : base(message, cause, connection) {}\r
59 \r
60                 protected override AbstractDbErrorCollection DbErrors {\r
61                         get {\r
62                                 return Errors;\r
63                         }\r
64                 }\r
65 \r
66         \r
67 \r
68         /**\r
69          * Gets the severity level of the error returned from the SQL Server .NET \r
70          * Data Provider.\r
71          * @return severity level of the first error in the collection.\r
72          */\r
73         public byte Class\r
74         {\r
75             get\r
76             {\r
77                                 SqlErrorCollection errors = Errors;\r
78                                 return errors.Count > 0 ? errors[0].Class : (byte)0;\r
79             }\r
80         }\r
81 \r
82         /**\r
83          * Gets a collection of one or more SqlError objects that give detailed \r
84          * information about exceptions generated by the SQL Server .NET Data Provider.\r
85          * @return collection of SqlError objects\r
86          */\r
87         public SqlErrorCollection Errors\r
88         {\r
89             get\r
90             {\r
91                 return new SqlErrorCollection(_cause, _connection);\r
92             }\r
93         }\r
94 \r
95         /**\r
96          * Gets the line number within the Transact-SQL command batch or stored \r
97          * procedure that generated the error.\r
98          * @return line number of the first error in the collection.\r
99          */\r
100         public int LineNumber\r
101         {\r
102             get\r
103             {\r
104                                 SqlErrorCollection errors = Errors;\r
105                                 return errors.Count > 0 ? errors[0].LineNumber : 0;\r
106             }\r
107         }\r
108 \r
109         /**\r
110          * Gets a number that identifies the type of error.\r
111          * @return number that identifies the type of first error in the collection\r
112          */\r
113         public int Number\r
114         {\r
115             get\r
116             {\r
117                                 SqlErrorCollection errors = Errors;\r
118                                 return errors.Count > 0 ? errors[0].Number : 0;\r
119             }\r
120         }\r
121 \r
122         /**\r
123          * Gets the name of the stored procedure or remote procedure call (RPC) \r
124          * that generated the error.\r
125          * @return name of the stored procedure \r
126          */\r
127         public String Procedure\r
128         {\r
129             get\r
130             {\r
131                                 SqlErrorCollection errors = Errors;\r
132                                 return errors.Count > 0 ? errors[0].Procedure : null;\r
133             }\r
134         }\r
135 \r
136         /**\r
137          * Gets the name of the computer running an instance of SQL Server \r
138          * that generated the error.\r
139          * @return name of the computer where error generated\r
140          */\r
141         public String Server\r
142         {\r
143             get\r
144             {\r
145                                 SqlErrorCollection errors = Errors;\r
146                                 return errors.Count > 0 ? errors[0].Server : null;\r
147             }\r
148         }\r
149 \r
150 \r
151         /**\r
152          * Gets a numeric error code from SQL Server that represents an error, \r
153          * warning or "no data found" message. \r
154          * @return numeric error code from SQL Server\r
155          */\r
156         public byte State\r
157         {\r
158             get\r
159             {\r
160                                 SqlErrorCollection errors = Errors;\r
161                                 return errors.Count > 0 ? errors[0].State : (byte)0;\r
162             }\r
163         }\r
164     }\r
165 }