From 4b44801af5f31419a0b5953a092e25f628e76107 Mon Sep 17 00:00:00 2001 From: James A Sutherland Date: Tue, 16 Jul 2024 10:33:27 -0500 Subject: [PATCH] Minor tidying --- FAnsiSql/Discovery/DiscoveredServerHelper.cs | 8 ++++---- FAnsiSql/Discovery/DiscoveredTable.cs | 2 ++ .../PostgreSql/PostgreSqlServerHelper.cs | 15 +++------------ 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/FAnsiSql/Discovery/DiscoveredServerHelper.cs b/FAnsiSql/Discovery/DiscoveredServerHelper.cs index 07eb066..f5af2e6 100644 --- a/FAnsiSql/Discovery/DiscoveredServerHelper.cs +++ b/FAnsiSql/Discovery/DiscoveredServerHelper.cs @@ -47,7 +47,7 @@ public static void AddConnectionStringKeyword(DatabaseType databaseType, string public abstract DbConnection GetConnection(DbConnectionStringBuilder builder); - public DbConnectionStringBuilder GetConnectionStringBuilder(string connectionString) + public DbConnectionStringBuilder GetConnectionStringBuilder(string? connectionString) { var builder = GetConnectionStringBuilderImpl(connectionString); EnforceKeywords(builder); @@ -77,7 +77,7 @@ protected virtual void EnforceKeywords(DbConnectionStringBuilder builder) } protected abstract DbConnectionStringBuilder GetConnectionStringBuilderImpl(string connectionString, string? database, string username, string password); - protected abstract DbConnectionStringBuilder GetConnectionStringBuilderImpl(string connectionString); + protected abstract DbConnectionStringBuilder GetConnectionStringBuilderImpl(string? connectionString); protected abstract string ServerKeyName { get; } @@ -165,7 +165,7 @@ public bool RespondsWithinTime(DbConnectionStringBuilder builder, int timeoutInS public abstract string? GetExplicitPasswordIfAny(DbConnectionStringBuilder builder); public abstract Version? GetVersion(DiscoveredServer server); - private static readonly Regex _rVagueVersion = RVagueVersionRe(); + private static readonly Regex RVagueVersion = RVagueVersionRe(); /// /// Number of seconds to allow to run for before timing out. @@ -185,7 +185,7 @@ public bool RespondsWithinTime(DbConnectionStringBuilder builder, int timeoutInS if (Version.TryParse(versionString, out var result)) return result; - var m = _rVagueVersion.Match(versionString); + var m = RVagueVersion.Match(versionString); return m.Success ? Version.Parse(m.Value) : //whatever the string was it didn't even remotely resemble a Version null; diff --git a/FAnsiSql/Discovery/DiscoveredTable.cs b/FAnsiSql/Discovery/DiscoveredTable.cs index a02d963..064ce62 100644 --- a/FAnsiSql/Discovery/DiscoveredTable.cs +++ b/FAnsiSql/Discovery/DiscoveredTable.cs @@ -388,6 +388,7 @@ public void CreateIndex(string indexName, DiscoveredColumn[] discoverColumns, bo /// /// Creates an index on the table /// + /// /// /// /// @@ -408,6 +409,7 @@ public void DropIndex(string indexName) /// /// Drops the specified index from the discovered table /// + /// /// public void DropIndex(DatabaseOperationArgs args, string indexName) { diff --git a/FAnsiSql/Implementations/PostgreSql/PostgreSqlServerHelper.cs b/FAnsiSql/Implementations/PostgreSql/PostgreSqlServerHelper.cs index a90d349..61ddd02 100644 --- a/FAnsiSql/Implementations/PostgreSql/PostgreSqlServerHelper.cs +++ b/FAnsiSql/Implementations/PostgreSql/PostgreSqlServerHelper.cs @@ -33,9 +33,7 @@ public override DbConnectionStringBuilder EnableAsync(DbConnectionStringBuilder public override void CreateDatabase(DbConnectionStringBuilder builder, IHasRuntimeName newDatabaseName) { - var b = (NpgsqlConnectionStringBuilder)GetConnectionStringBuilder(builder.ConnectionString); - - using var con = new NpgsqlConnection(b.ConnectionString); + using var con = new NpgsqlConnection(builder.ConnectionString); con.Open(); using var cmd = GetCommand($"CREATE DATABASE \"{newDatabaseName.GetRuntimeName()}\"", con); cmd.CommandTimeout = CreateDatabaseTimeoutInSeconds; @@ -58,14 +56,7 @@ public override Version GetVersion(DiscoveredServer server) public override IEnumerable ListDatabases(DbConnectionStringBuilder builder) { - //create a copy so as not to corrupt the original - - var b = new NpgsqlConnectionStringBuilder(builder.ConnectionString) - { - Timeout = builder.TryGetValue("Timeout", out var timeout) ? (int)timeout : 5 - }; - - using var con = new NpgsqlConnection(b.ConnectionString); + using var con = new NpgsqlConnection(builder.ConnectionString); con.Open(); foreach (var listDatabase in ListDatabases(con)) yield return listDatabase; } @@ -89,7 +80,7 @@ public override IEnumerable ListDatabases(DbConnection con) public override DbConnection GetConnection(DbConnectionStringBuilder builder) => new NpgsqlConnection(builder.ConnectionString); - protected override DbConnectionStringBuilder GetConnectionStringBuilderImpl(string server, string database, + protected override DbConnectionStringBuilder GetConnectionStringBuilderImpl(string server, string? database, string username, string password) { var toReturn = new NpgsqlConnectionStringBuilder