Skip to content

Commit

Permalink
Merge pull request #291 from HicServices/feature/pgversion
Browse files Browse the repository at this point in the history
Get Version directly from postgres driver
  • Loading branch information
JFriel authored Jul 16, 2024
2 parents 94e3ade + f473d8c commit 9e56c80
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions FAnsiSql/Implementations/PostgreSql/PostgreSqlServerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace FAnsi.Implementations.PostgreSql;
public sealed class PostgreSqlServerHelper : DiscoveredServerHelper
{
public static readonly PostgreSqlServerHelper Instance = new();

private PostgreSqlServerHelper() : base(DatabaseType.PostgreSql)
{
}
Expand Down Expand Up @@ -47,16 +48,11 @@ public override void CreateDatabase(DbConnectionStringBuilder builder, IHasRunti

public override string? GetExplicitPasswordIfAny(DbConnectionStringBuilder builder) => ((NpgsqlConnectionStringBuilder)builder).Password;

public override Version? GetVersion(DiscoveredServer server)
public override Version GetVersion(DiscoveredServer server)
{
using var con = server.GetConnection();
using var con = new NpgsqlConnection(server.Builder.ConnectionString);
con.Open();
using var cmd = server.GetCommand("SHOW server_version", con);
using var r = cmd.ExecuteReader();
if (r.Read())
return r[0] == DBNull.Value ? null : CreateVersionFromString((string)r[0]);

return null;
return con.PostgreSqlVersion;
}


Expand Down

0 comments on commit 9e56c80

Please sign in to comment.