Skip to content

Commit

Permalink
Merge branch '5.4.x' into upgrade-vulnerable-dep
Browse files Browse the repository at this point in the history
  • Loading branch information
fredericDelaporte authored May 12, 2024
2 parents d8ceaa3 + b967119 commit bb1f321
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Data.Common;
using NHibernate.Exceptions;
using Npgsql;

namespace NHibernate.Test.ExceptionsTest
{
Expand All @@ -10,23 +10,23 @@ public class PostgresExceptionConverterExample : ISQLExceptionConverter

public Exception Convert(AdoExceptionContextInfo exInfo)
{
var sqle = ADOExceptionHelper.ExtractDbException(exInfo.SqlException) as DbException;
if (sqle != null)
if (ADOExceptionHelper.ExtractDbException(exInfo.SqlException) is PostgresException pge)
{
string code = (string)sqle.GetType().GetProperty("Code").GetValue(sqle, null);

string code = pge.SqlState;
if (code == "23503")
{
return new ConstraintViolationException(exInfo.Message, sqle.InnerException, exInfo.Sql, null);
return new ConstraintViolationException(exInfo.Message, pge.InnerException, exInfo.Sql, null);
}

if (code == "42P01")
{
return new SQLGrammarException(exInfo.Message, sqle.InnerException, exInfo.Sql);
return new SQLGrammarException(exInfo.Message, pge.InnerException, exInfo.Sql);
}
}

return SQLStateConverter.HandledNonSpecificException(exInfo.SqlException, exInfo.Message, exInfo.Sql);
}

#endregion
}
}
}
2 changes: 1 addition & 1 deletion src/NHibernate.Test/NHibernate.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="8.5.2" />
<PackageReference Include="Npgsql" Version="6.0.6" />
<PackageReference Include="Npgsql" Version="8.0.3" />
<PackageReference Include="MySql.Data" Version="8.0.30" />
</ItemGroup>
<ItemGroup Condition="$(NhNetFx)">
Expand Down

0 comments on commit bb1f321

Please sign in to comment.