Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump HIC.TypeGuesser from 1.1.0 to 1.2.1 #245

Merged
merged 8 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions FAnsiSql/Connections/ManagedConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 3 additions & 13 deletions FAnsiSql/DatabaseOperationArgs.cs
Original file line number Diff line number Diff line change
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);
}
7 changes: 1 addition & 6 deletions FAnsiSql/Discovery/BulkCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ protected void ConvertStringTypesToHardTypes(DataTable dt)


foreach(DataRow dr in dt.Rows)
{
try
{
//parse the value
Expand All @@ -141,7 +140,6 @@ protected void ConvertStringTypesToHardTypes(DataTable dt)
{
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 +199,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 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
10 changes: 2 additions & 8 deletions FAnsiSql/Discovery/DatabaseColumnRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
36 changes: 8 additions & 28 deletions FAnsiSql/Discovery/DiscoveredColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,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,39 +78,28 @@ 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>
Expand Down Expand Up @@ -147,8 +130,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());
}
30 changes: 6 additions & 24 deletions FAnsiSql/Discovery/DiscoveredDataType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,40 +46,28 @@ public DiscoveredDataType(DbDataReader r, string sqlType, DiscoveredColumn colum
/// <para>Returns <see cref="int.MaxValue"/> if the string type has no real limit e.g. "text"</para>
/// </summary>
/// <returns></returns>
public int GetLengthIfString()
{
return Column.Table.Database.Server.Helper.GetQuerySyntaxHelper().TypeTranslater.GetLengthIfString(SQLType);
}
public int GetLengthIfString() => Column.Table.Database.Server.Helper.GetQuerySyntaxHelper().TypeTranslater.GetLengthIfString(SQLType);

/// <summary>
/// <para>Returns the Scale/Precision of the data type. Only applies to decimal(x,y) types not basic types e.g. int.</para>
///
/// <para>Returns null if the datatype is not floating point</para>
/// </summary>
/// <returns></returns>
public DecimalSize GetDecimalSize()
{
return Column.Table.Database.Server.Helper.GetQuerySyntaxHelper().TypeTranslater.GetDigitsBeforeAndAfterDecimalPointIfDecimal(SQLType);
}
public DecimalSize GetDecimalSize() => Column.Table.Database.Server.Helper.GetQuerySyntaxHelper().TypeTranslater.GetDigitsBeforeAndAfterDecimalPointIfDecimal(SQLType);

/// <summary>
/// Returns the System.Type that should be used to store values read out of columns of this data type (See <see cref="ITypeTranslater.GetCSharpTypeForSQLDBType"/>
/// </summary>
/// <returns></returns>
[return:DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties|DynamicallyAccessedMemberTypes.PublicFields)]
public Type GetCSharpDataType()
{
return Column.Table.Database.Server.GetQuerySyntaxHelper().TypeTranslater.GetCSharpTypeForSQLDBType(SQLType);
}
public Type GetCSharpDataType() => Column.Table.Database.Server.GetQuerySyntaxHelper().TypeTranslater.GetCSharpTypeForSQLDBType(SQLType);

/// <summary>
/// Returns the <see cref="SQLType"/>
/// </summary>
/// <returns></returns>
public override string ToString()
{
return SQLType;
}
public override string ToString() => SQLType;

/// <summary>
/// <para>Creates and runs an ALTER TABLE statement which will increase the size of a char column to support longer string values than it currently does.</para>
Expand Down Expand Up @@ -174,19 +162,13 @@ public void AlterTypeTo(string newType, IManagedTransaction managedTransaction =
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
private bool Equals(DiscoveredDataType other)
{
return string.Equals(SQLType, other.SQLType);
}
private bool Equals(DiscoveredDataType other) => string.Equals(SQLType, other.SQLType);

/// <summary>
/// Equality based on <see cref="SQLType"/>
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return SQLType != null ? SQLType.GetHashCode() : 0;
}
public override int GetHashCode() => SQLType != null ? SQLType.GetHashCode() : 0;

/// <summary>
/// Equality based on <see cref="SQLType"/>
Expand Down
Loading
Loading