Skip to content

Commit

Permalink
Bump HIC.TypeGuesser from 1.1.0 to 1.2.1 (#245)
Browse files Browse the repository at this point in the history
* Bump HIC.TypeGuesser from 1.1.0 to 1.2.1
* Enable nullable and start adding annotations as needed
  • Loading branch information
dependabot[bot] authored Feb 6, 2024
1 parent ead11f7 commit 67e9f3b
Show file tree
Hide file tree
Showing 78 changed files with 598 additions and 1,247 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x
- name: Install Sql Server
run: |
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
Expand Down
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project>
<PropertyGroup>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion FAnsiSql/Connections/IManagedConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface IManagedConnection : IDisposable
/// <summary>
/// Optional - DbTransaction being wrapped if one has been started or null
/// </summary>
DbTransaction Transaction { get; }
DbTransaction? Transaction { get; }

/// <summary>
/// Optional - transaction being run (See <see cref="DiscoveredServer.BeginNewTransactedConnection"/>. If this is not null then <see cref="Transaction"/> should also be not null.
Expand Down
7 changes: 2 additions & 5 deletions FAnsiSql/Connections/ManagedConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public sealed class ManagedConnection : IManagedConnection
public DbConnection Connection { get; }

/// <inheritdoc/>
public DbTransaction Transaction { get; }
public DbTransaction? Transaction { get; }

/// <inheritdoc/>
public IManagedTransaction ManagedTransaction { get; }
Expand All @@ -37,10 +37,7 @@ internal ManagedConnection(DiscoveredServer discoveredServer, IManagedTransactio
Connection.Open();
}

public ManagedConnection Clone()
{
return (ManagedConnection) MemberwiseClone();
}
public ManagedConnection Clone() => (ManagedConnection) MemberwiseClone();

/// <summary>
/// Closes and disposes the DbConnection unless this class is part of an <see cref="IManagedTransaction"/>
Expand Down
18 changes: 4 additions & 14 deletions FAnsiSql/DatabaseOperationArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed class DatabaseOperationArgs
/// <summary>
/// If using an ongoing connection/transaction. Otherwise null.
/// </summary>
public IManagedTransaction TransactionIfAny{ get; set; }
public IManagedTransaction? TransactionIfAny { get; set; }

/// <summary>
/// Time to allow <see cref="DbCommand"/> to run before cancelling (this is db timeout and doesn't affect <see cref="CancellationToken"/>)
Expand Down Expand Up @@ -130,31 +130,21 @@ private void Hydrate(DbCommand cmd)
/// </summary>
/// <param name="table"></param>
/// <returns></returns>
public IManagedConnection GetManagedConnection(DiscoveredTable table)
{
return GetManagedConnection(table.Database.Server);
}
public IManagedConnection GetManagedConnection(DiscoveredTable table) => GetManagedConnection(table.Database.Server);

/// <summary>
/// Opens a new connection or passes back an existing opened connection (that matches
/// <see cref="TransactionIfAny"/>). This command should be wrapped in a using statement
/// </summary>
/// <param name="database"></param>
/// <returns></returns>
public IManagedConnection GetManagedConnection(DiscoveredDatabase database)
{
return GetManagedConnection(database.Server);
}
public IManagedConnection GetManagedConnection(DiscoveredDatabase database) => GetManagedConnection(database.Server);

/// <summary>
/// Opens a new connection or passes back an existing opened connection (that matches
/// <see cref="TransactionIfAny"/>). This command should be wrapped in a using statement
/// </summary>
/// <param name="server"></param>
/// <returns></returns>
public IManagedConnection GetManagedConnection(DiscoveredServer server)
{
return server.GetManagedConnection(TransactionIfAny);
}

public IManagedConnection GetManagedConnection(DiscoveredServer server) => server.GetManagedConnection(TransactionIfAny);
}
18 changes: 6 additions & 12 deletions FAnsiSql/Discovery/BulkCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public abstract class BulkCopy:IBulkCopy
public bool AllowUnmatchedInputColumns { get; private set; }

/// <inheritdoc/>
public DateTimeTypeDecider DateTimeDecider {get; protected set; }
public DateTimeTypeDecider DateTimeDecider { get; protected set; }

/// <summary>
/// Begins a new bulk copy operation in which one or more data tables are uploaded to the <paramref name="targetTable"/>. The API entrypoint for this is
Expand All @@ -50,7 +50,7 @@ public abstract class BulkCopy:IBulkCopy
/// <param name="targetTable"></param>
/// <param name="connection"></param>
/// <param name="culture">For parsing string date expressions etc</param>
protected BulkCopy(DiscoveredTable targetTable, IManagedConnection connection,CultureInfo culture)
protected BulkCopy(DiscoveredTable targetTable, IManagedConnection connection, CultureInfo culture)
{
Culture = culture;
TargetTable = targetTable;
Expand Down Expand Up @@ -121,27 +121,24 @@ protected void ConvertStringTypesToHardTypes(DataTable dt)
var newColumn = dt.Columns.Add($"{dataColumn.ColumnName}_{Guid.NewGuid()}",dataType);

//if it's a DateTime decider then guess DateTime culture based on values in the table
if(decider is DateTimeTypeDecider)
if (decider is DateTimeTypeDecider)
{
//also use this one in case the user has set up explicit stuff on it e.g. Culture/Settings
decider = DateTimeDecider;
DateTimeDecider.GuessDateFormat(dt.Rows.Cast<DataRow>().Take(500).Select(r=>r[dataColumn] as string));
DateTimeDecider.GuessDateFormat(dt.Rows.Cast<DataRow>().Take(500).Select(r => r[dataColumn] as string).OfType<string>());
}


foreach(DataRow dr in dt.Rows)
{
try
{
//parse the value
dr[newColumn] = decider.Parse(dr[dataColumn] as string)??DBNull.Value;

}
catch(Exception ex)
catch (Exception ex)
{
throw new Exception($"Failed to parse value '{dr[dataColumn]}' in column '{dataColumn}'",ex);
}
}

//if the DataColumn is part of the Primary Key of the DataTable (in memory)
//then we need to update the primary key to include the new column not the old one
Expand Down Expand Up @@ -201,8 +198,5 @@ protected Dictionary<DataColumn, DiscoveredColumn> GetMapping(IEnumerable<DataCo
/// </summary>
/// <param name="inputColumns"></param>
/// <returns></returns>
protected Dictionary<DataColumn,DiscoveredColumn> GetMapping(IEnumerable<DataColumn> inputColumns)
{
return GetMapping(inputColumns, out _);
}
protected Dictionary<DataColumn,DiscoveredColumn> GetMapping(IEnumerable<DataColumn> inputColumns) => GetMapping(inputColumns, out _);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ public void AddOrUpdateKeyword(string keyword, string value, ConnectionStringKey

//if we have not got that keyword yet
if(!_keywords.TryAdd(keyword, Tuple.Create(value, priority)) && _keywords[keyword].Item2 <= priority)
{
//or the keyword that was previously specified had a lower priority
_keywords[keyword] = Tuple.Create(value, priority); //update it with the new value
}
}

/// <summary>
Expand All @@ -63,7 +61,7 @@ public void AddOrUpdateKeyword(string keyword, string value, ConnectionStringKey
/// <param name="keyword"></param>
/// <param name="value"></param>
/// <returns></returns>
private string GetCollisionWithKeyword(string keyword, string value)
private string? GetCollisionWithKeyword(string keyword, string value)
{
ArgumentNullException.ThrowIfNull(keyword);
ArgumentNullException.ThrowIfNull(value);
Expand Down
2 changes: 1 addition & 1 deletion FAnsiSql/Discovery/Constraints/DiscoveredRelationship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public sealed class DiscoveredRelationship(string fkName, DiscoveredTable pkTabl
/// <param name="primaryKeyCol"></param>
/// <param name="foreignKeyCol"></param>
/// <param name="transaction"></param>
public void AddKeys(string primaryKeyCol, string foreignKeyCol,IManagedTransaction transaction = null)
public void AddKeys(string primaryKeyCol, string foreignKeyCol,IManagedTransaction? transaction = null)
{
if (_pkColumns == null)
{
Expand Down
2 changes: 0 additions & 2 deletions FAnsiSql/Discovery/Constraints/RelationshipTopologicalSort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ private static List<T> TopologicalSort<T>(IEnumerable<T> nodes, HashSet<Tuple<T,

// if m has no other incoming edges then
if (edges.All(me => !me.Item2.Equals(m)))
{
// insert m into S
s.Add(m);
}
}
}

Expand Down
18 changes: 6 additions & 12 deletions FAnsiSql/Discovery/DatabaseColumnRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ namespace FAnsi.Discovery;
///
/// <para>Type specification is defined in the DatabaseTypeRequest but can also be specified explicitly (e.g. 'varchar(10)').</para>
/// </summary>
public sealed class DatabaseColumnRequest(string columnName, DatabaseTypeRequest typeRequested, bool allowNulls = true)
public sealed class DatabaseColumnRequest(string columnName, DatabaseTypeRequest? typeRequested, bool allowNulls = true)
: ISupplementalColumnInformation, IHasRuntimeName
{
/// <summary>
/// The fixed string proprietary data type to use. This overrides <see cref="TypeRequested"/> if specified.
///
/// <para>See also <see cref="GetSQLDbType"/></para>
/// </summary>
public string ExplicitDbType { get; set; }
public string? ExplicitDbType { get; set; }


public string ColumnName { get; set; } = columnName;
Expand All @@ -31,7 +31,7 @@ public sealed class DatabaseColumnRequest(string columnName, DatabaseTypeRequest
///
/// <para>See also <see cref="GetSQLDbType"/></para>
/// </summary>
public DatabaseTypeRequest TypeRequested { get; set; } = typeRequested;
public DatabaseTypeRequest? TypeRequested { get; set; } = typeRequested;

/// <summary>
/// True to create a column which is nullable
Expand Down Expand Up @@ -59,7 +59,7 @@ public sealed class DatabaseColumnRequest(string columnName, DatabaseTypeRequest
/// </summary>
public string Collation { get; set; }

Check warning on line 60 in FAnsiSql/Discovery/DatabaseColumnRequest.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'value' of 'void DatabaseColumnRequest.Collation.set' doesn't match implicitly implemented member 'void ISupplementalColumnInformation.Collation.set' (possibly because of nullability attributes).

Check warning on line 60 in FAnsiSql/Discovery/DatabaseColumnRequest.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'value' of 'void DatabaseColumnRequest.Collation.set' doesn't match implicitly implemented member 'void ISupplementalColumnInformation.Collation.set' (possibly because of nullability attributes).

public DatabaseColumnRequest(string columnName, string explicitDbType, bool allowNulls = true) : this(columnName, (DatabaseTypeRequest)null, allowNulls)
public DatabaseColumnRequest(string columnName, string explicitDbType, bool allowNulls = true) : this(columnName, (DatabaseTypeRequest?)null, allowNulls)
{
ExplicitDbType = explicitDbType;
}
Expand All @@ -69,13 +69,7 @@ public DatabaseColumnRequest(string columnName, string explicitDbType, bool allo
/// </summary>
/// <param name="typeTranslater"></param>
/// <returns></returns>
public string GetSQLDbType(ITypeTranslater typeTranslater)
{
return ExplicitDbType??typeTranslater.GetSQLDBTypeForCSharpType(TypeRequested);
}
public string GetSQLDbType(ITypeTranslater typeTranslater) => ExplicitDbType??typeTranslater.GetSQLDBTypeForCSharpType(TypeRequested);

public string GetRuntimeName()
{
return ColumnName;
}
public string GetRuntimeName() => ColumnName;
}
43 changes: 12 additions & 31 deletions FAnsiSql/Discovery/DiscoveredColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ namespace FAnsi.Discovery;
/// <param name="table"></param>
/// <param name="name"></param>
/// <param name="allowsNulls"></param>
public sealed class DiscoveredColumn(DiscoveredTable table, string name, bool allowsNulls) : IHasFullyQualifiedNameToo,ISupplementalColumnInformation
public sealed class DiscoveredColumn(DiscoveredTable table, string name, bool allowsNulls) : IHasFullyQualifiedNameToo,
ISupplementalColumnInformation
{
/// <summary>
/// The <see cref="DiscoveredTable"/> on which the <see cref="DiscoveredColumn"/> was found
Expand Down Expand Up @@ -44,7 +45,7 @@ public sealed class DiscoveredColumn(DiscoveredTable table, string name, bool al
/// <summary>
/// The DBMS proprietary column specific collation e.g. "Latin1_General_CS_AS_KS_WS"
/// </summary>
public string Collation { get; set; }
public string? Collation { get; set; }

/// <summary>
/// The data type of the column found (includes String Length and Scale/Precision).
Expand All @@ -63,19 +64,13 @@ public sealed class DiscoveredColumn(DiscoveredTable table, string name, bool al
/// The unqualified name of the column e.g. "MyCol"
/// </summary>
/// <returns></returns>
public string GetRuntimeName()
{
return _querySyntaxHelper.GetRuntimeName(_name);
}
public string? GetRuntimeName() => _querySyntaxHelper.GetRuntimeName(_name);

/// <summary>
/// The fully qualified name of the column e.g. [MyDb].dbo.[MyTable].[MyCol] or `MyDb`.`MyCol`
/// </summary>
/// <returns></returns>
public string GetFullyQualifiedName()
{
return _querySyntaxHelper.EnsureFullyQualified(Table.Database.GetRuntimeName(),Table.Schema, Table.GetRuntimeName(), GetRuntimeName(), Table is DiscoveredTableValuedFunction);
}
public string GetFullyQualifiedName() => _querySyntaxHelper.EnsureFullyQualified(Table.Database.GetRuntimeName(),Table.Schema, Table.GetRuntimeName(), GetRuntimeName(), Table is DiscoveredTableValuedFunction);


/// <summary>
Expand All @@ -84,45 +79,34 @@ public string GetFullyQualifiedName()
/// <param name="topX">The number of records to return</param>
/// <param name="discardNulls">If true adds a WHERE statement to throw away null values</param>
/// <returns></returns>
public string GetTopXSql(int topX, bool discardNulls)
{
return Helper.GetTopXSqlForColumn(Table.Database, Table, this, topX, discardNulls);
}
public string GetTopXSql(int topX, bool discardNulls) => Helper.GetTopXSqlForColumn(Table.Database, Table, this, topX, discardNulls);

/// <summary>
/// Returns the name of the column
/// </summary>
/// <returns></returns>
public override string ToString()
{
return _name;
}
public override string ToString() => _name;

/// <summary>
/// Generates a <see cref="Guesser"/> primed with the <see cref="DataType"/> of this column. This can be used to inspect new
/// untyped (string) data to determine whether it will fit into the column.
/// </summary>
/// <returns></returns>
public Guesser GetGuesser()
{
return Table.GetQuerySyntaxHelper().TypeTranslater.GetGuesserFor(this);
}
public Guesser GetGuesser() => Table.GetQuerySyntaxHelper().TypeTranslater.GetGuesserFor(this);

/// <summary>
/// Based on column name and Table
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
private bool Equals(DiscoveredColumn other)
{
return string.Equals(_name, other._name) && Equals(Table, other.Table);
}
private bool Equals(DiscoveredColumn other) => string.Equals(_name, other._name) && Equals(Table, other.Table);

/// <summary>
/// Based on column name and Table
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (obj is null) return false;
if (ReferenceEquals(this, obj)) return true;
Expand All @@ -147,8 +131,5 @@ public override int GetHashCode()
/// Returns the wrapped e.g. "[MyCol]" name of the column including escaping e.g. if you wanted to name a column "][nquisitor" (which would return "[]][nquisitor]"). Use <see cref="GetFullyQualifiedName()"/> to return the full name including table/database/schema.
/// </summary>
/// <returns></returns>
public string GetWrappedName()
{
return Table.GetQuerySyntaxHelper().EnsureWrapped(GetRuntimeName());
}
public string GetWrappedName() => Table.GetQuerySyntaxHelper().EnsureWrapped(GetRuntimeName());
}
Loading

0 comments on commit 67e9f3b

Please sign in to comment.