Skip to content

Commit

Permalink
Minor tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
jas88 committed Jul 16, 2024
1 parent 66e8390 commit 4b44801
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
8 changes: 4 additions & 4 deletions FAnsiSql/Discovery/DiscoveredServerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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();

/// <summary>
/// Number of seconds to allow <see cref="CreateDatabase(DbConnectionStringBuilder, IHasRuntimeName)"/> to run for before timing out.
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions FAnsiSql/Discovery/DiscoveredTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ public void CreateIndex(string indexName, DiscoveredColumn[] discoverColumns, bo
/// <summary>
/// Creates an index on the table
/// </summary>
/// <param name="args"></param>
/// <param name="indexName"></param>
/// <param name="discoverColumns"></param>
/// <param name="isUnique"></param>
Expand All @@ -408,6 +409,7 @@ public void DropIndex(string indexName)
/// <summary>
/// Drops the specified index from the discovered table
/// </summary>
/// <param name="args"></param>
/// <param name="indexName"></param>
public void DropIndex(DatabaseOperationArgs args, string indexName)
{
Expand Down
15 changes: 3 additions & 12 deletions FAnsiSql/Implementations/PostgreSql/PostgreSqlServerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -58,14 +56,7 @@ public override Version GetVersion(DiscoveredServer server)

public override IEnumerable<string> 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;
}
Expand All @@ -89,7 +80,7 @@ public override IEnumerable<string> 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
Expand Down

0 comments on commit 4b44801

Please sign in to comment.