forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSqlStateExtracter.cs
51 lines (47 loc) · 1.58 KB
/
SqlStateExtracter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Data.Common;
namespace NHibernate.Exceptions
{
public abstract class SqlStateExtracter
{
/* Many drivers provide both SqlState and NativeError in the Exception
* Some of them, like OdbcException, have fields SQLState, NativeError
* Some of them contain it in Data field, like PsqlException
* Some of them have only text message
*/
public int ExtractErrorCode(DbException sqle)
{
int errorCode;
Exception nested;
errorCode = ExtractSingleErrorCode(sqle);
nested = sqle.InnerException;
while (errorCode == 0 && nested != null)
{
if (nested is DbException)
{
errorCode = ExtractSingleErrorCode(sqle);
}
nested = sqle.InnerException;
}
return errorCode;
}
public string ExtractSqlState(DbException sqle)
{
string sqlState;
Exception nested;
sqlState = ExtractSingleSqlState(sqle);
nested = sqle.InnerException;
while (sqlState.Length == 0 && nested != null)
{
if (nested is DbException)
{
sqlState = ExtractSingleSqlState(sqle);
}
nested = sqle.InnerException;
}
return sqlState;
}
public abstract int ExtractSingleErrorCode(DbException sqle);
public abstract string ExtractSingleSqlState(DbException sqle);
}
}