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

Bugfix/mysqltext #212

Merged
merged 4 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

...
- Bugfix: MySQL text was erroneously capped at 64k (TEXT) instead of LONGTEXT (4GiB)

## [3.1.0] - 2023-05-15

- Now targeting .Net 6
Expand Down
2 changes: 1 addition & 1 deletion FAnsiSql/Connections/IManagedTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace FAnsi.Connections;

/// <summary>
/// Wrapper for DbTransaction that associates it with a specific DbConnection. Helps simplify calls to information
/// Wrapper for DbTransaction that associates it with a specific DbConnection. Helps simplify calls to information
/// methods such as DiscoveredTable.GetRowCount etc during the middle of an ongoing database transaction
/// </summary>
public interface IManagedTransaction
Expand Down
2 changes: 1 addition & 1 deletion FAnsiSql/Connections/ManagedConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ManagedConnection : IManagedConnection

/// <inheritdoc/>
public bool CloseOnDispose { get; set; }

internal ManagedConnection(DiscoveredServer discoveredServer, IManagedTransaction managedTransaction)
{
//get a new connection or use the existing one within the transaction
Expand Down
6 changes: 3 additions & 3 deletions FAnsiSql/DatabaseOperationArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class DatabaseOperationArgs
/// Time to allow <see cref="DbCommand"/> to run before cancelling (this is db timeout and doesn't affect <see cref="CancellationToken"/>)
/// </summary>
public int TimeoutInSeconds { get; set; }

/// <summary>
/// Optional, if provided all commands interacting with these args should cancel if the command was cancelled
/// </summary>
Expand Down Expand Up @@ -87,15 +87,15 @@ private T Execute<T>(DbCommand cmd, Func<Task<T>> method)
throw;
}

if (!t.IsCompleted)
if (!t.IsCompleted)
cmd.Cancel();

if (t.Exception == null) return t.Result;
if (t.Exception.InnerExceptions.Count == 1)
throw t.Exception.InnerExceptions[0];
throw t.Exception;
}

public void Fill(DbDataAdapter da, DbCommand cmd, DataTable dt)
{
Hydrate(cmd);
Expand Down
2 changes: 1 addition & 1 deletion FAnsiSql/DatabaseType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public enum DatabaseType
MicrosoftSQLServer,

/// <summary>
/// My Sql database engine.
/// My Sql database engine.
/// </summary>
MySql,

Expand Down
14 changes: 7 additions & 7 deletions FAnsiSql/Discovery/BulkCopy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public abstract class BulkCopy:IBulkCopy
/// call <see cref="InvalidateTableSchema"/> to refresh this.
/// </summary>
protected DiscoveredColumn[] TargetTableColumns;

/// <summary>
/// When calling GetMapping if there are DataColumns in the input table that you are trying to bulk insert that are not matched
/// in the destination table then the default behaviour is to throw a KeyNotFoundException. Set this to false to ignore that
Expand All @@ -41,7 +41,7 @@ public abstract class BulkCopy:IBulkCopy

/// <inheritdoc/>
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
/// <see cref="DiscoveredTable.BeginBulkInsert(IManagedTransaction)"/>.
Expand Down Expand Up @@ -126,7 +126,7 @@ protected void ConvertStringTypesToHardTypes(DataTable dt)
decider = DateTimeDecider;
DateTimeDecider.GuessDateFormat(dt.Rows.Cast<DataRow>().Take(500).Select(r=>r[kvp.Key] as string));
}


foreach(DataRow dr in dt.Rows)
{
Expand Down Expand Up @@ -160,8 +160,8 @@ protected void ConvertStringTypesToHardTypes(DataTable dt)
}

/// <summary>
/// Returns a case insensitive mapping between columns in your DataTable that you are trying to upload and the columns that actually exist in the destination
/// table.
/// Returns a case insensitive mapping between columns in your DataTable that you are trying to upload and the columns that actually exist in the destination
/// table.
/// <para>This overload gives you a list of all unmatched destination columns, these should be given null/default automatically by your database API</para>
/// <para>Throws <exception cref="KeyNotFoundException"> if there are unmatched input columns unless <see cref="AllowUnmatchedInputColumns"/> is true.</exception></para>
/// </summary>
Expand Down Expand Up @@ -194,8 +194,8 @@ protected Dictionary<DataColumn, DiscoveredColumn> GetMapping(IEnumerable<DataCo
}

/// <summary>
/// Returns a case insensitive mapping between columns in your DataTable that you are trying to upload and the columns that actually exist in the destination
/// table.
/// Returns a case insensitive mapping between columns in your DataTable that you are trying to upload and the columns that actually exist in the destination
/// table.
/// <para>Throws <exception cref="KeyNotFoundException"> if there are unmatched input columns unless <see cref="AllowUnmatchedInputColumns"/> is true.</exception></para>
/// </summary>
/// <param name="inputColumns"></param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace FAnsi.Discovery.ConnectionStringDefaults;

/// <summary>
/// <para>Gathers keywords for use in building connection strings for a given <see cref="DatabaseType"/>. Once created you can add keywords and then apply the template
/// <para>Gathers keywords for use in building connection strings for a given <see cref="DatabaseType"/>. Once created you can add keywords and then apply the template
/// to new novel connection strings (see <see cref="EnforceOptions"/>).</para>
///
/// <para>Also handles connection string keyword aliases (where two words mean the same thing)</para>
Expand All @@ -33,7 +33,7 @@ public ConnectionStringKeywordAccumulator(DatabaseType databaseType)
}

/// <summary>
/// Adds a new connection string option (which must be compatible with <see cref="DatabaseType"/>)
/// Adds a new connection string option (which must be compatible with <see cref="DatabaseType"/>)
/// </summary>
/// <param name="keyword"></param>
/// <param name="value"></param>
Expand All @@ -44,12 +44,12 @@ public void AddOrUpdateKeyword(string keyword, string value, ConnectionStringKey

if (collision != null)
{
//if there is already a semantically equivalent keyword....
//if there is already a semantically equivalent keyword....

//if it is of lower or equal priority
if (_keywords[collision].Item2 <= priority)
_keywords[collision] = Tuple.Create(value, priority); //update it
_keywords[collision] = Tuple.Create(value, priority); //update it

//either way don't record it as a new keyword
return;
}
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 @@ -26,7 +26,7 @@ public class DiscoveredRelationship
public DiscoveredTable ForeignKeyTable { get; private set; }

/// <summary>
/// Mapping of primary key column(s) in <see cref="PrimaryKeyTable"/> to foreign key column(s) in <see cref="ForeignKeyTable"/>. If there are more than one entry
/// Mapping of primary key column(s) in <see cref="PrimaryKeyTable"/> to foreign key column(s) in <see cref="ForeignKeyTable"/>. If there are more than one entry
/// then the foreign key is a composite key.
/// </summary>
public Dictionary<DiscoveredColumn, DiscoveredColumn> Keys { get; private set; }
Expand Down
4 changes: 2 additions & 2 deletions FAnsiSql/Discovery/Constraints/RelationshipTopologicalSort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace FAnsi.Discovery.Constraints;

/// <summary>
/// Helps resolve a dependency order between a collection of tables with interlinking foreign key constraints. Implements Khan's algorithm.
/// Helps resolve a dependency order between a collection of tables with interlinking foreign key constraints. Implements Khan's algorithm.
/// </summary>
public class RelationshipTopologicalSort
{
Expand Down Expand Up @@ -42,7 +42,7 @@ public RelationshipTopologicalSort(IEnumerable<DiscoveredTable> tables)
}

/// <summary>
/// Topological Sorting (Kahn's algorithm)
/// Topological Sorting (Kahn's algorithm)
/// </summary>
/// <remarks>https://en.wikipedia.org/wiki/Topological_sorting</remarks>
/// <typeparam name="T"></typeparam>
Expand Down
4 changes: 2 additions & 2 deletions FAnsiSql/Discovery/DatabaseColumnRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class DatabaseColumnRequest:ISupplementalColumnInformation,IHasRuntimeNam
public bool AllowNulls { get; set; }

/// <summary>
/// True to include the column as part of the tables primary key
/// True to include the column as part of the tables primary key
/// </summary>
public bool IsPrimaryKey { get; set; }

Expand All @@ -53,7 +53,7 @@ public class DatabaseColumnRequest:ISupplementalColumnInformation,IHasRuntimeNam
public MandatoryScalarFunctions Default { get; set; }

/// <summary>
/// Applies only if the <see cref="TypeRequested"/> is string based. Setting this will override the default collation and specify
/// Applies only if the <see cref="TypeRequested"/> is string based. Setting this will override the default collation and specify
/// a specific collation. The value specified must be an installed collation supported by the DBMS
/// </summary>
public string Collation { get; set; }
Expand Down
12 changes: 6 additions & 6 deletions FAnsiSql/Discovery/DiscoveredDataType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace FAnsi.Discovery;
/// </summary>
public class DiscoveredDataType
{
private readonly DiscoveredColumn Column;
private readonly DiscoveredColumn Column;

/// <summary>
/// The proprietary DBMS name for the datatype e.g. varchar2(100) for Oracle, datetime2 for Sql Server etc.
Expand Down Expand Up @@ -91,7 +91,7 @@ public override string ToString()
public void Resize(int newSize, IManagedTransaction managedTransaction = null)
{
var toReplace = GetLengthIfString();

if(newSize == toReplace)
return;

Expand All @@ -104,7 +104,7 @@ public void Resize(int newSize, IManagedTransaction managedTransaction = null)
}

/// <summary>
/// <para>Creates and runs an ALTER TABLE statement which will increase the size of a decimal column to support larger Precision/Scale values than it currently does.
/// <para>Creates and runs an ALTER TABLE statement which will increase the size of a decimal column to support larger Precision/Scale values than it currently does.
/// If you want decimal(4,2) then pass <paramref name="numberOfDigitsBeforeDecimalPoint"/>=2 and <paramref name="numberOfDigitsAfterDecimalPoint"/>=2</para>
///
/// <para>Throws <see cref="InvalidResizeException"/> if the column is not a decimal type or the new size is smaller than the current column size</para>
Expand All @@ -126,11 +126,11 @@ public void Resize(int numberOfDigitsBeforeDecimalPoint, int numberOfDigitsAfter

if (toReplace.NumbersAfterDecimalPlace> numberOfDigitsAfterDecimalPoint)
throw new InvalidResizeException(string.Format(FAnsiStrings.DiscoveredDataType_Resize_Cannot_shrink_column__number_of_digits_after_the_decimal_point_is_currently__0__and_you_asked_to_set_it_to__1___Current_SQLType_is__2__, toReplace.NumbersAfterDecimalPlace, numberOfDigitsAfterDecimalPoint, SQLType));

var newDataType = Column.Table.GetQuerySyntaxHelper()
.TypeTranslater.GetSQLDBTypeForCSharpType(new DatabaseTypeRequest(typeof (decimal), null,
new DecimalSize(numberOfDigitsBeforeDecimalPoint, numberOfDigitsAfterDecimalPoint)));

AlterTypeTo(newDataType, managedTransaction);
}

Expand Down Expand Up @@ -164,7 +164,7 @@ public void AlterTypeTo(string newType, IManagedTransaction managedTransaction =
}
}

SQLType = newType;
SQLType = newType;
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions FAnsiSql/Discovery/DiscoveredDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public IEnumerable<DiscoveredTableValuedFunction> DiscoverTableValuedFunctions(I
Helper.ListTableValuedFunctions(this, _querySyntaxHelper, managedConnection.Connection,
GetRuntimeName(), managedConnection.Transaction).ToArray();
}

/// <summary>
/// Returns the name of the database without any qualifiers
/// </summary>
Expand All @@ -82,7 +82,7 @@ public string GetRuntimeName()
{
return _querySyntaxHelper.GetRuntimeName(_database);
}

/// <summary>
/// Returns the wrapped e.g. "[MyDatabase]" name of the database including escaping e.g. if you wanted to name a database "][nquisitor" (which would return "[]][nquisitor]").
/// </summary>
Expand Down Expand Up @@ -250,7 +250,7 @@ public DiscoveredTable CreateTable(CreateTableArgs args)
}

/// <summary>
/// Creates a table in the database big enough to store the supplied DataTable with appropriate types.
/// Creates a table in the database big enough to store the supplied DataTable with appropriate types.
/// </summary>
/// <param name="typeDictionary">The computers used to determine column types</param>
/// <param name="tableName"></param>
Expand All @@ -275,7 +275,7 @@ public DiscoveredTable CreateTable(out Dictionary<string, Guesser> typeDictionar

return table;
}


/// <summary>
/// Creates a new schema within the database if the DBMS supports it (Sql Server does, MySql doesn't) and it does not already exist. Schema
Expand Down
18 changes: 9 additions & 9 deletions FAnsiSql/Discovery/DiscoveredDatabaseHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace FAnsi.Discovery;

/// <summary>
/// DBMS specific implementation of all functionality that relates to interacting with existing databases (dropping databases, creating tables, finding stored proceedures etc). For
/// DBMS specific implementation of all functionality that relates to interacting with existing databases (dropping databases, creating tables, finding stored proceedures etc). For
/// database creation see <see cref="DiscoveredServerHelper"/>
/// </summary>
public abstract class DiscoveredDatabaseHelper:IDiscoveredDatabaseHelper
Expand Down Expand Up @@ -60,17 +60,17 @@ public DiscoveredTable CreateTable(CreateTableArgs args)

//Type requested is a proper FAnsi type (e.g. string, at least 5 long)
var request = overriding.TypeRequested;

if(request == null)
if(!string.IsNullOrWhiteSpace(overriding.ExplicitDbType))
{
//Type is for an explicit SQL Type e.g. varchar(5)

//Translate the sql type to a FAnsi type definition
//Translate the sql type to a FAnsi type definition
var tt = args.Database.Server.GetQuerySyntaxHelper().TypeTranslater;

request = tt.GetDataTypeRequestForSQLDBType(overriding.ExplicitDbType);

}
else
throw new Exception(string.Format(FAnsiStrings.DiscoveredDatabaseHelper_CreateTable_DatabaseColumnRequestMustHaveEitherTypeRequestedOrExplicitDbType, column));
Expand All @@ -84,15 +84,15 @@ public DiscoveredTable CreateTable(CreateTableArgs args)
//no, work out the column definition using a guesser
var guesser = GetGuesser(column);
guesser.Culture = args.Culture;

CopySettings(guesser,args);

guesser.AdjustToCompensateForValues(column);

//if DoNotRetype is set on the column adjust the requested CSharpType to be the original type
if (column.GetDoNotReType())
guesser.Guess.CSharpType = column.DataType;

typeDictionary.Add(column.ColumnName,guesser);

columns.Add(new DatabaseColumnRequest(column.ColumnName, guesser.Guess, column.AllowDBNull) { IsPrimaryKey = args.DataTable.PrimaryKey.Contains(column)});
Expand Down Expand Up @@ -202,7 +202,7 @@ public virtual string GetCreateTableSql(DiscoveredDatabase database, string tabl
foreach (var col in columns)
{
var datatype = col.GetSQLDbType(syntaxHelper.TypeTranslater);

//add the column name and accompanying datatype
bodySql.AppendLine($"{GetCreateTableSqlLineForColumn(col, datatype, syntaxHelper)},");
}
Expand Down Expand Up @@ -278,7 +278,7 @@ private string MakeSensibleConstraintName(string prefix, string tableName)

return $"{prefix}{constraintName}";
}

public void ExecuteBatchNonQuery(string sql, DbConnection conn, DbTransaction transaction = null, int timeout = 30)
{
ExecuteBatchNonQuery(sql, conn, transaction, out _, timeout);
Expand Down
10 changes: 5 additions & 5 deletions FAnsiSql/Discovery/DiscoveredServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private DbParameter GetParameter(string parameterName)
}

/// <summary>
/// Returns a new <see cref="DbParameter"/> of the correct <see cref="DatabaseType"/> of the server. Also adds it
/// Returns a new <see cref="DbParameter"/> of the correct <see cref="DatabaseType"/> of the server. Also adds it
/// to the <see cref="DbCommand.Parameters"/> of <paramref name="command"/> and sets it's <paramref name="valueForParameter"/>
/// </summary>
/// <param name="parameterName"></param>
Expand Down Expand Up @@ -297,10 +297,10 @@ public DiscoveredDatabase GetCurrentDatabase()
//no (e.g. Oracle or no default database specified in connection string)
return _currentDatabase; //yes use that one
}

/// <summary>
/// Edits the connection string (See <see cref="Builder"/>) to allow async operations. Depending on DBMS this may have
/// no effect (e.g. Sql Server needs AsynchronousProcessing and MultipleActiveResultSets but Oracle / MySql do not need
/// Edits the connection string (See <see cref="Builder"/>) to allow async operations. Depending on DBMS this may have
/// no effect (e.g. Sql Server needs AsynchronousProcessing and MultipleActiveResultSets but Oracle / MySql do not need
/// any special keywords)
/// </summary>
public void EnableAsync()
Expand Down Expand Up @@ -383,7 +383,7 @@ public IQuerySyntaxHelper GetQuerySyntaxHelper()
{
return Helper.GetQuerySyntaxHelper();
}

/// <summary>
/// Return key value pairs which describe attributes of the server e.g. version, available drive space etc
/// </summary>
Expand Down
Loading