Skip to content

Commit

Permalink
Update PostgreSqlServerHelper.cs
Browse files Browse the repository at this point in the history
Get version directly from PG driver instead of parsing it ourselves
  • Loading branch information
jas88 committed Jul 16, 2024
1 parent ceaa29f commit 22f3ccc
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 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 @@ -48,16 +49,10 @@ 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();
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;
using var con = new NpgsqlConnection(server.Builder.ConnectionString);
return con.PostgreSqlVersion;
}


Expand Down

0 comments on commit 22f3ccc

Please sign in to comment.