File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed
Filter options
src/NHibernate.Test/ExceptionsTest Expand file tree Collapse file tree 1 file changed +8
-8
lines changed
Original file line number Diff line number Diff line change 1
1
using System ;
2
- using System . Data . Common ;
3
2
using NHibernate . Exceptions ;
3
+ using Npgsql ;
4
4
5
5
namespace NHibernate . Test . ExceptionsTest
6
6
{
@@ -10,23 +10,23 @@ public class PostgresExceptionConverterExample : ISQLExceptionConverter
10
10
11
11
public Exception Convert ( AdoExceptionContextInfo exInfo )
12
12
{
13
- var sqle = ADOExceptionHelper . ExtractDbException ( exInfo . SqlException ) as DbException ;
14
- if ( sqle != null )
13
+ if ( ADOExceptionHelper . ExtractDbException ( exInfo . SqlException ) is PostgresException pge )
15
14
{
16
- string code = ( string ) sqle . GetType ( ) . GetProperty ( "Code" ) . GetValue ( sqle , null ) ;
17
-
15
+ string code = pge . SqlState ;
18
16
if ( code == "23503" )
19
17
{
20
- return new ConstraintViolationException ( exInfo . Message , sqle . InnerException , exInfo . Sql , null ) ;
18
+ return new ConstraintViolationException ( exInfo . Message , pge . InnerException , exInfo . Sql , null ) ;
21
19
}
20
+
22
21
if ( code == "42P01" )
23
22
{
24
- return new SQLGrammarException ( exInfo . Message , sqle . InnerException , exInfo . Sql ) ;
23
+ return new SQLGrammarException ( exInfo . Message , pge . InnerException , exInfo . Sql ) ;
25
24
}
26
25
}
26
+
27
27
return SQLStateConverter . HandledNonSpecificException ( exInfo . SqlException , exInfo . Message , exInfo . Sql ) ;
28
28
}
29
29
30
30
#endregion
31
31
}
32
- }
32
+ }
You can’t perform that action at this time.
0 commit comments