From 1c060fef4ce23ca69a5d2841333c335d6d3065f9 Mon Sep 17 00:00:00 2001 From: jas88 Date: Thu, 31 Aug 2023 13:41:12 -0500 Subject: [PATCH] Clean up whitespace --- FAnsiSql/DatabaseType.cs | 2 +- FAnsiSql/Discovery/BulkCopy.cs | 14 ++++---- FAnsiSql/Discovery/DiscoveredDataType.cs | 4 +-- FAnsiSql/Discovery/DiscoveredDatabase.cs | 8 ++--- .../Discovery/DiscoveredDatabaseHelper.cs | 16 +++++----- FAnsiSql/Discovery/DiscoveredServer.cs | 10 +++--- FAnsiSql/Discovery/DiscoveredServerHelper.cs | 10 +++--- FAnsiSql/Discovery/DiscoveredTable.cs | 16 +++++----- FAnsiSql/Discovery/DiscoveredTableHelper.cs | 2 +- .../DiscoveredTableValuedFunction.cs | 4 +-- .../Discovery/IDiscoveredDatabaseHelper.cs | 4 +-- FAnsiSql/Discovery/IDiscoveredServerHelper.cs | 6 ++-- FAnsiSql/Discovery/IDiscoveredTableHelper.cs | 8 ++--- .../QuerySyntax/IQuerySyntaxHelper.cs | 24 +++++++------- FAnsiSql/Discovery/QuerySyntaxHelper.cs | 32 +++++++++---------- .../TypeTranslation/TypeTranslater.cs | 18 +++++------ FAnsiSql/Extensions/DataColumnExtensions.cs | 2 +- .../Implementation/ImplementationManager.cs | 2 +- FAnsiSql/Naming/IHasRuntimeName.cs | 4 +-- .../Aggregation/AggregationTests.cs | 4 +-- .../Aggregation/CalendarAggregationTests.cs | 24 +++++++------- Tests/FAnsiTests/All.cs | 2 +- Tests/FAnsiTests/CrossPlatformTests.cs | 32 +++++++++---------- Tests/FAnsiTests/DatabaseTests.cs | 10 +++--- Tests/FAnsiTests/ManagedConnectionTests.cs | 12 +++---- .../Query/QuerySyntaxHelperDatabaseTests.cs | 2 +- .../Query/QuerySyntaxHelperTests.cs | 12 +++---- Tests/FAnsiTests/Server/ServerTests.cs | 4 +-- Tests/FAnsiTests/Table/BadNamesTests.cs | 18 +++++------ Tests/FAnsiTests/Table/BasicInsertTests.cs | 4 +-- Tests/FAnsiTests/Table/BulkInsertTest.cs | 12 +++---- Tests/FAnsiTests/Table/CreateTableTests.cs | 10 +++--- Tests/FAnsiTests/Table/ForeignKeyTests.cs | 4 +-- Tests/FAnsiTests/Table/TopXTests.cs | 4 +-- Tests/FAnsiTests/Table/UpdateTests.cs | 4 +-- .../TypeTranslation/DatatypeComputerTests.cs | 6 ++-- .../TypeTranslation/TypeTranslaterTests.cs | 2 +- 37 files changed, 176 insertions(+), 176 deletions(-) diff --git a/FAnsiSql/DatabaseType.cs b/FAnsiSql/DatabaseType.cs index 5f86b17d..e4de8b88 100644 --- a/FAnsiSql/DatabaseType.cs +++ b/FAnsiSql/DatabaseType.cs @@ -11,7 +11,7 @@ public enum DatabaseType MicrosoftSQLServer, /// - /// My Sql database engine. + /// My Sql database engine. /// MySql, diff --git a/FAnsiSql/Discovery/BulkCopy.cs b/FAnsiSql/Discovery/BulkCopy.cs index ca4a2ad0..e77d3e04 100644 --- a/FAnsiSql/Discovery/BulkCopy.cs +++ b/FAnsiSql/Discovery/BulkCopy.cs @@ -29,7 +29,7 @@ public abstract class BulkCopy:IBulkCopy /// call to refresh this. /// protected DiscoveredColumn[] TargetTableColumns; - + /// /// 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 @@ -41,7 +41,7 @@ public abstract class BulkCopy:IBulkCopy /// public DateTimeTypeDecider DateTimeDecider {get; protected set; } - + /// /// Begins a new bulk copy operation in which one or more data tables are uploaded to the . The API entrypoint for this is /// . @@ -126,7 +126,7 @@ protected void ConvertStringTypesToHardTypes(DataTable dt) decider = DateTimeDecider; DateTimeDecider.GuessDateFormat(dt.Rows.Cast().Take(500).Select(r=>r[kvp.Key] as string)); } - + foreach(DataRow dr in dt.Rows) { @@ -160,8 +160,8 @@ protected void ConvertStringTypesToHardTypes(DataTable dt) } /// - /// 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. /// This overload gives you a list of all unmatched destination columns, these should be given null/default automatically by your database API /// Throws if there are unmatched input columns unless is true. /// @@ -194,8 +194,8 @@ protected Dictionary GetMapping(IEnumerable - /// 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. /// Throws if there are unmatched input columns unless is true. /// /// diff --git a/FAnsiSql/Discovery/DiscoveredDataType.cs b/FAnsiSql/Discovery/DiscoveredDataType.cs index 89c920a4..30a1123d 100644 --- a/FAnsiSql/Discovery/DiscoveredDataType.cs +++ b/FAnsiSql/Discovery/DiscoveredDataType.cs @@ -13,7 +13,7 @@ namespace FAnsi.Discovery; /// public class DiscoveredDataType { - private readonly DiscoveredColumn Column; + private readonly DiscoveredColumn Column; /// /// The proprietary DBMS name for the datatype e.g. varchar2(100) for Oracle, datetime2 for Sql Server etc. @@ -104,7 +104,7 @@ public void Resize(int newSize, IManagedTransaction managedTransaction = null) } /// - /// 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. + /// 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 =2 and =2 /// /// Throws if the column is not a decimal type or the new size is smaller than the current column size diff --git a/FAnsiSql/Discovery/DiscoveredDatabase.cs b/FAnsiSql/Discovery/DiscoveredDatabase.cs index 4df35b6a..39d3efda 100644 --- a/FAnsiSql/Discovery/DiscoveredDatabase.cs +++ b/FAnsiSql/Discovery/DiscoveredDatabase.cs @@ -73,7 +73,7 @@ public IEnumerable DiscoverTableValuedFunctions(I Helper.ListTableValuedFunctions(this, _querySyntaxHelper, managedConnection.Connection, GetRuntimeName(), managedConnection.Transaction).ToArray(); } - + /// /// Returns the name of the database without any qualifiers /// @@ -82,7 +82,7 @@ public string GetRuntimeName() { return _querySyntaxHelper.GetRuntimeName(_database); } - + /// /// 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]"). /// @@ -250,7 +250,7 @@ public DiscoveredTable CreateTable(CreateTableArgs args) } /// - /// 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. /// /// The computers used to determine column types /// @@ -275,7 +275,7 @@ public DiscoveredTable CreateTable(out Dictionary typeDictionar return table; } - + /// /// 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 diff --git a/FAnsiSql/Discovery/DiscoveredDatabaseHelper.cs b/FAnsiSql/Discovery/DiscoveredDatabaseHelper.cs index 41fc9d69..5533589c 100644 --- a/FAnsiSql/Discovery/DiscoveredDatabaseHelper.cs +++ b/FAnsiSql/Discovery/DiscoveredDatabaseHelper.cs @@ -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)); @@ -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)}); @@ -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)},"); } @@ -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); diff --git a/FAnsiSql/Discovery/DiscoveredServer.cs b/FAnsiSql/Discovery/DiscoveredServer.cs index eb1884a7..3b76e435 100644 --- a/FAnsiSql/Discovery/DiscoveredServer.cs +++ b/FAnsiSql/Discovery/DiscoveredServer.cs @@ -149,7 +149,7 @@ private DbParameter GetParameter(string parameterName) } /// - /// Returns a new of the correct of the server. Also adds it + /// Returns a new of the correct of the server. Also adds it /// to the of and sets it's /// /// @@ -305,10 +305,10 @@ public DiscoveredDatabase GetCurrentDatabase() //no (e.g. Oracle or no default database specified in connection string) return _currentDatabase; //yes use that one } - + /// - /// Edits the connection string (See ) 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 ) 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) /// public void EnableAsync() @@ -391,7 +391,7 @@ public IQuerySyntaxHelper GetQuerySyntaxHelper() { return Helper.GetQuerySyntaxHelper(); } - + /// /// Return key value pairs which describe attributes of the server e.g. version, available drive space etc /// diff --git a/FAnsiSql/Discovery/DiscoveredServerHelper.cs b/FAnsiSql/Discovery/DiscoveredServerHelper.cs index 5c6753f2..f3faa283 100644 --- a/FAnsiSql/Discovery/DiscoveredServerHelper.cs +++ b/FAnsiSql/Discovery/DiscoveredServerHelper.cs @@ -31,7 +31,7 @@ public static void AddConnectionStringKeyword(DatabaseType databaseType, string ConnectionStringKeywordAccumulators[databaseType].AddOrUpdateKeyword(keyword,value,priority); } - + /// public abstract DbCommand GetCommand(string s, DbConnection con, DbTransaction transaction = null); @@ -43,7 +43,7 @@ public static void AddConnectionStringKeyword(DatabaseType databaseType, string /// public abstract DbParameter GetParameter(string parameterName); - + public abstract DbConnection GetConnection(DbConnectionStringBuilder builder); public DbConnectionStringBuilder GetConnectionStringBuilder(string connectionString) @@ -53,7 +53,7 @@ public DbConnectionStringBuilder GetConnectionStringBuilder(string connectionStr return builder; } - + /// public DbConnectionStringBuilder GetConnectionStringBuilder(string server, string database, string username, string password) { @@ -76,8 +76,8 @@ 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 string ServerKeyName { get; } protected abstract string DatabaseKeyName { get; } diff --git a/FAnsiSql/Discovery/DiscoveredTable.cs b/FAnsiSql/Discovery/DiscoveredTable.cs index a2d0237b..416cf47a 100644 --- a/FAnsiSql/Discovery/DiscoveredTable.cs +++ b/FAnsiSql/Discovery/DiscoveredTable.cs @@ -68,7 +68,7 @@ public DiscoveredTable(DiscoveredDatabase database, string table, IQuerySyntaxHe QuerySyntaxHelper.ValidateTableName(_table); } - + /// /// Checks that the exists then lists the tables in the database to confirm this table exists on the server /// @@ -101,7 +101,7 @@ public virtual string GetFullyQualifiedName() { return QuerySyntaxHelper.EnsureFullyQualified(Database.GetRuntimeName(),Schema, GetRuntimeName()); } - + /// /// Returns the wrapped e.g. "[MyTbl]" name of the table including escaping e.g. if you wanted to name a table "][nquisitor" (which would return "[]][nquisitor]"). Use to return the full name including table/database/schema. /// @@ -142,7 +142,7 @@ public IQuerySyntaxHelper GetQuerySyntaxHelper() /// /// Returns from the on the server. This is not not case sensitive. Requires - /// connecting to the database. + /// connecting to the database. /// /// The column you want to find /// Optional - if set the connection to list tables will be sent on the connection on which the current @@ -198,9 +198,9 @@ public DataTable GetDataTable(DatabaseOperationArgs args,int topX = int.MaxValue return dt; } - + /// - /// Drops (deletes) the table from the database. This is irreversible unless you have a database backup. + /// Drops (deletes) the table from the database. This is irreversible unless you have a database backup. /// public virtual void Drop() { @@ -223,7 +223,7 @@ public int GetRowCount(DatabaseOperationArgs args) { return Helper.GetRowCount(args, this); } - + /// /// Returns true if there are no rows in the table /// @@ -294,7 +294,7 @@ public void DropColumn(DiscoveredColumn column) using var connection = Database.Server.GetManagedConnection(); Helper.DropColumn(connection.Connection, column); } - + /// /// Creates a new object for bulk inserting records into the table. You should use a using block since is . /// Depending on implementation, records may not be committed to the server until the is disposed. @@ -411,7 +411,7 @@ public void CreatePrimaryKey(IManagedTransaction transaction ,CancellationToken }, this, discoverColumns); } - + public void CreatePrimaryKey(DatabaseOperationArgs args, params DiscoveredColumn[] discoverColumns) { Helper.CreatePrimaryKey(args,this, discoverColumns); diff --git a/FAnsiSql/Discovery/DiscoveredTableHelper.cs b/FAnsiSql/Discovery/DiscoveredTableHelper.cs index 874c67c4..d6b92fdb 100644 --- a/FAnsiSql/Discovery/DiscoveredTableHelper.cs +++ b/FAnsiSql/Discovery/DiscoveredTableHelper.cs @@ -20,7 +20,7 @@ public abstract class DiscoveredTableHelper :IDiscoveredTableHelper public abstract string GetTopXSqlForTable(IHasFullyQualifiedNameToo table, int topX); public abstract DiscoveredColumn[] DiscoverColumns(DiscoveredTable discoveredTable, IManagedConnection connection, string database); - + public abstract IDiscoveredColumnHelper GetColumnHelper(); public virtual void DropTable(DbConnection connection, DiscoveredTable tableToDrop) { diff --git a/FAnsiSql/Discovery/DiscoveredTableValuedFunction.cs b/FAnsiSql/Discovery/DiscoveredTableValuedFunction.cs index 47315c84..9c32fd97 100644 --- a/FAnsiSql/Discovery/DiscoveredTableValuedFunction.cs +++ b/FAnsiSql/Discovery/DiscoveredTableValuedFunction.cs @@ -12,7 +12,7 @@ namespace FAnsi.Discovery; public class DiscoveredTableValuedFunction : DiscoveredTable { private readonly string _functionName; - + //constructor public DiscoveredTableValuedFunction(DiscoveredDatabase database, string functionName, IQuerySyntaxHelper querySyntaxHelper, string schema = null) : base(database, functionName, querySyntaxHelper, @@ -36,7 +36,7 @@ public override string GetFullyQualifiedName() //Note that we do not give the parameters values, the client must decide appropriate values and put them in correspondingly named variables return $"{Database.GetRuntimeName()}..{GetRuntimeName()}({parameters})"; } - + public override string ToString() => _functionName; public override void Drop() diff --git a/FAnsiSql/Discovery/IDiscoveredDatabaseHelper.cs b/FAnsiSql/Discovery/IDiscoveredDatabaseHelper.cs index 757d8e58..24939e4c 100644 --- a/FAnsiSql/Discovery/IDiscoveredDatabaseHelper.cs +++ b/FAnsiSql/Discovery/IDiscoveredDatabaseHelper.cs @@ -26,7 +26,7 @@ public interface IDiscoveredDatabaseHelper Dictionary DescribeDatabase(DbConnectionStringBuilder builder, string database); DiscoveredTable CreateTable(CreateTableArgs args); - + string GetCreateTableSql(DiscoveredDatabase database, string tableName, DatabaseColumnRequest[] columns, Dictionary foreignKeyPairs, bool cascadeDelete,string schema = null); /// @@ -47,7 +47,7 @@ string GetForeignKeyConstraintSql(string foreignTable, IQuerySyntaxHelper syntax DirectoryInfo Detach(DiscoveredDatabase database); void CreateBackup(DiscoveredDatabase discoveredDatabase, string backupName); - + /// /// Gets a sensible name for a foreign key constraint between the two tables /// diff --git a/FAnsiSql/Discovery/IDiscoveredServerHelper.cs b/FAnsiSql/Discovery/IDiscoveredServerHelper.cs index 2a9745b6..ece65f91 100644 --- a/FAnsiSql/Discovery/IDiscoveredServerHelper.cs +++ b/FAnsiSql/Discovery/IDiscoveredServerHelper.cs @@ -21,9 +21,9 @@ public interface IDiscoveredServerHelper DbConnection GetConnection(DbConnectionStringBuilder builder); DbConnectionStringBuilder GetConnectionStringBuilder(string connectionString); - + /// - /// Returns a new connection string builder with the supplied parameters. Note that if a concept is not supported in the + /// Returns a new connection string builder with the supplied parameters. Note that if a concept is not supported in the /// implementation then the value will not appear in the connection string (e.g. Oracle /// does not support specifying a to connect to). /// @@ -54,7 +54,7 @@ public interface IDiscoveredServerHelper DatabaseType DatabaseType { get; } Dictionary DescribeServer(DbConnectionStringBuilder builder); bool RespondsWithinTime(DbConnectionStringBuilder builder, int timeoutInSeconds, out Exception exception); - + string GetExplicitUsernameIfAny(DbConnectionStringBuilder builder); string GetExplicitPasswordIfAny(DbConnectionStringBuilder builder); Version GetVersion(DiscoveredServer server); diff --git a/FAnsiSql/Discovery/IDiscoveredTableHelper.cs b/FAnsiSql/Discovery/IDiscoveredTableHelper.cs index bc995d52..f4c96679 100644 --- a/FAnsiSql/Discovery/IDiscoveredTableHelper.cs +++ b/FAnsiSql/Discovery/IDiscoveredTableHelper.cs @@ -20,7 +20,7 @@ public interface IDiscoveredTableHelper DiscoveredColumn[] DiscoverColumns(DiscoveredTable discoveredTable, IManagedConnection connection, string database); IDiscoveredColumnHelper GetColumnHelper(); - + void DropTable(DbConnection connection, DiscoveredTable tableToDrop); void DropFunction(DbConnection connection, DiscoveredTableValuedFunction functionToDrop); void DropColumn(DbConnection connection, DiscoveredColumn columnToDrop); @@ -32,7 +32,7 @@ public interface IDiscoveredTableHelper IEnumerable DiscoverTableValuedFunctionParameters(DbConnection connection, DiscoveredTableValuedFunction discoveredTableValuedFunction, DbTransaction transaction); IBulkCopy BeginBulkInsert(DiscoveredTable discoveredTable, IManagedConnection connection,CultureInfo culture); - + void TruncateTable(DiscoveredTable discoveredTable); void MakeDistinct(DatabaseOperationArgs args,DiscoveredTable discoveredTable); @@ -44,8 +44,8 @@ public interface IDiscoveredTableHelper int ExecuteInsertReturningIdentity(DiscoveredTable discoveredTable, DbCommand cmd, IManagedTransaction transaction=null); DiscoveredRelationship[] DiscoverRelationships(DiscoveredTable discoveredTable,DbConnection connection, IManagedTransaction transaction = null); void FillDataTableWithTopX(DatabaseOperationArgs args,DiscoveredTable table, int topX, DataTable dt); - - + + /// /// Creates a new primary key relationship in a foreign key table that points to a primary key table (which must have a primary key) /// diff --git a/FAnsiSql/Discovery/QuerySyntax/IQuerySyntaxHelper.cs b/FAnsiSql/Discovery/QuerySyntax/IQuerySyntaxHelper.cs index 69186f8e..f181f425 100644 --- a/FAnsiSql/Discovery/QuerySyntax/IQuerySyntaxHelper.cs +++ b/FAnsiSql/Discovery/QuerySyntax/IQuerySyntaxHelper.cs @@ -11,10 +11,10 @@ namespace FAnsi.Discovery.QuerySyntax; /// /// Cross database type functionality for helping build SQL commands that will work regardless of DatabaseType (Microsoft Sql Server / MySql etc). Describes -/// how to translate broad requirements like 'database type capable of storing strings up to 10 characters long' into a specific implementation e.g. +/// how to translate broad requirements like 'database type capable of storing strings up to 10 characters long' into a specific implementation e.g. /// 'varchar(10)' in Microsoft SQL Server and 'varchar2(10)' in Oracle (See ITypeTranslater). /// -/// Also includes features such as qualifying database entities [MyDatabase]..[MyTable].[MyColumn] in Sql Server vs `MyDatabase`.`MyTable`.`MyColumn` in +/// Also includes features such as qualifying database entities [MyDatabase]..[MyTable].[MyColumn] in Sql Server vs `MyDatabase`.`MyTable`.`MyColumn` in /// MySql. /// /// Also includes methods for dealing with no n Ansi standard functionality e.g. TOP X , MD5 etc @@ -36,7 +36,7 @@ public interface IQuerySyntaxHelper IAggregateHelper AggregateHelper { get; } IUpdateHelper UpdateHelper { get; set; } - + /// /// The character that is used to qualify database entity names e.g. "[" for "[My Table]" /// @@ -80,7 +80,7 @@ public interface IQuerySyntaxHelper string EnsureFullyQualified(string databaseName,string schemaName, string tableName); string EnsureFullyQualified(string databaseName, string schemaName,string tableName, string columnName, bool isTableValuedFunction = false); - + /// /// Returns the given escaped e.g. doubling up single quotes. Does not add any wrapping. /// @@ -91,11 +91,11 @@ public interface IQuerySyntaxHelper TopXResponse HowDoWeAchieveTopX(int x); string GetParameterDeclaration(string proposedNewParameterName, DatabaseTypeRequest request); string GetParameterDeclaration(string proposedNewParameterName, string sqlType); - + bool IsValidParameterName(string parameterSQL); string AliasPrefix { get; } - + /// /// The maximum number of characters allowed in database names according to the DBMS /// @@ -142,7 +142,7 @@ public interface IQuerySyntaxHelper bool IsBasicallyNull(object value); bool IsTimeout(Exception exception); - + HashSet GetReservedWords(); /// @@ -155,7 +155,7 @@ public interface IQuerySyntaxHelper /// /// Gets a DbParameter hard typed with the correct DbType for the discoveredColumn and the Value set to the correct Value representation (e.g. DBNull for nulls or whitespace). - /// Also handles converting DateTime representations since many DBMS are a bit rubbish at that + /// Also handles converting DateTime representations since many DBMS are a bit rubbish at that /// /// /// The column the parameter is for loading - this is used to determine the DbType for the paramter @@ -165,7 +165,7 @@ public interface IQuerySyntaxHelper /// /// Gets a DbParameter hard typed with the correct DbType for the discoveredColumn and the Value set to the correct Value representation (e.g. DBNull for nulls or whitespace). - /// Also handles converting DateTime representations since many DBMS are a bit rubbish at that + /// Also handles converting DateTime representations since many DBMS are a bit rubbish at that /// /// /// The column the parameter is for loading - this is used to determine the DbType for the paramter @@ -189,7 +189,7 @@ public interface IQuerySyntaxHelper /// Throws if the supplied name is invalid (because it is too long or contains unsupported characters) /// void ValidateColumnName(string columnName); - + /// /// Returns false if the supplied name is invalid (because it is too long or contains unsupported characters) /// @@ -222,12 +222,12 @@ public enum MandatoryScalarFunctions /// A scalar function which must return todays datetime. Must be valid as a column default too /// GetTodaysDate, - + /// /// A scalar function which must return a new random GUID. /// GetGuid, - + /// /// A scalar function which must take a single argument (column name) and return the length of values in it /// diff --git a/FAnsiSql/Discovery/QuerySyntaxHelper.cs b/FAnsiSql/Discovery/QuerySyntaxHelper.cs index 0133874a..7f717f44 100644 --- a/FAnsiSql/Discovery/QuerySyntaxHelper.cs +++ b/FAnsiSql/Discovery/QuerySyntaxHelper.cs @@ -18,7 +18,7 @@ namespace FAnsi.Discovery; public abstract class QuerySyntaxHelper : IQuerySyntaxHelper { public virtual string DatabaseTableSeparator => "."; - + /// public abstract int MaximumDatabaseLength { get; } @@ -27,7 +27,7 @@ public abstract class QuerySyntaxHelper : IQuerySyntaxHelper /// public abstract int MaximumColumnLength { get; } - + /// public virtual char[] IllegalNameChars { get; } = {'.','(',')'}; @@ -44,12 +44,12 @@ public abstract class QuerySyntaxHelper : IQuerySyntaxHelper /// public abstract string OpenQualifier {get;} - + /// public abstract string CloseQualifier {get;} public ITypeTranslater TypeTranslater { get; private set; } - + private readonly Dictionary factories = new(); public IAggregateHelper AggregateHelper { get; private set; } @@ -81,14 +81,14 @@ protected string GetAliasConst() { return " AS "; } - + public string AliasPrefix => GetAliasConst(); //Only look at the start of the string or following an equals or white space and stop at word boundaries private static readonly Regex ParameterNameRegex = new ($@"(?:^|[\s+\-*/\\=(,])+{ParameterNamesRegex}\b"); /// - /// Lists the names of all parameters required by the supplied whereSql e.g. @bob = 'bob' would return "@bob" + /// Lists the names of all parameters required by the supplied whereSql e.g. @bob = 'bob' would return "@bob" /// /// the SQL you want to determine the parameter names in /// parameter names that are required by the SQL @@ -122,7 +122,7 @@ protected QuerySyntaxHelper(ITypeTranslater translater, IAggregateHelper aggrega DatabaseType = databaseType; } - + public virtual string GetRuntimeName(string s) { if (string.IsNullOrWhiteSpace(s)) @@ -219,7 +219,7 @@ public virtual HashSet GetReservedWords() public abstract string GetParameterDeclaration(string proposedNewParameterName, string sqlType); /// - /// Splits the given into + /// Splits the given into /// /// /// @@ -303,7 +303,7 @@ public static string MakeHeaderNameSensible(string header) for (var i = 0; i < sb.Length; i++) { //if we are looking at a space - if (sb[i] == ' ' && i + 1 < sb.Length && sb[i + 1] >= 'a' && sb[i + 1] <= 'z') //and there is another character + if (sb[i] == ' ' && i + 1 < sb.Length && sb[i + 1] >= 'a' && sb[i + 1] <= 'z') //and there is another character //and that character is a lower case letter sb[i + 1] = char.ToUpper(sb[i + 1]); } @@ -357,15 +357,15 @@ public virtual bool IsTimeout(Exception exception) } public abstract string HowDoWeAchieveMd5(string selectSql); - - + + public DbParameter GetParameter(DbParameter p, DiscoveredColumn discoveredColumn, object value,CultureInfo culture) { try { culture ??= CultureInfo.InvariantCulture; - + if(!factories.ContainsKey(culture)) factories.Add(culture,new TypeDeciderFactory(culture)); @@ -376,7 +376,7 @@ public DbParameter GetParameter(DbParameter p, DiscoveredColumn discoveredColumn if (IsBasicallyNull(value)) p.Value = DBNull.Value; else - if (value is string strVal && factories[culture].IsSupported(cSharpType)) //if the input is a string and it's for a hard type e.g. TimeSpan + if (value is string strVal && factories[culture].IsSupported(cSharpType)) //if the input is a string and it's for a hard type e.g. TimeSpan { var decider = factories[culture].Create(cSharpType); var o = decider.Parse(strVal); @@ -391,7 +391,7 @@ public DbParameter GetParameter(DbParameter p, DiscoveredColumn discoveredColumn { o = FormatTimespanForDbParameter(t); } - + p.Value = o; @@ -428,7 +428,7 @@ public bool IsValidDatabaseName(string databaseName,out string reason) reason = ValidateName(databaseName, "Database", MaximumDatabaseLength); return string.IsNullOrWhiteSpace(reason); } - + public bool IsValidTableName(string tableName,out string reason) { reason = ValidateName(tableName, "Table", MaximumTableLength); @@ -539,7 +539,7 @@ public Dictionary GetParameterNamesFor(T[] columns, Func { var c = columns[i]; var columnName = toStringFunc(c); - + if(!sensibleParameterNamesInclude.IsMatch(columnName)) //if column name is "_:_" or something toReturn.Add(c, $"{ParameterSymbol}p{i}"); else diff --git a/FAnsiSql/Discovery/TypeTranslation/TypeTranslater.cs b/FAnsiSql/Discovery/TypeTranslation/TypeTranslater.cs index 73c193fe..365b995c 100644 --- a/FAnsiSql/Discovery/TypeTranslation/TypeTranslater.cs +++ b/FAnsiSql/Discovery/TypeTranslation/TypeTranslater.cs @@ -37,7 +37,7 @@ public abstract class TypeTranslater:ITypeTranslater /// use to determine the required length/type at runtime. /// private readonly int StringWidthWhenNotSupplied; - + /// /// /// @@ -89,7 +89,7 @@ public string GetSQLDBTypeForCSharpType(DatabaseTypeRequest request) throw new TypeNotMappedException(string.Format(FAnsiStrings.TypeTranslater_GetSQLDBTypeForCSharpType_Unsure_what_SQL_type_to_use_for_CSharp_Type___0_____TypeTranslater_was___1__, t.Name, GetType().Name)); } - + protected string GetByteArrayDataType() { return "varbinary(max)"; @@ -130,8 +130,8 @@ protected virtual string GetStringDataTypeImpl(int maxExpectedStringWidth) } public abstract string GetStringDataTypeWithUnlimitedWidth(); - - + + private string GetUnicodeStringDataType(int? maxExpectedStringWidth) { if (maxExpectedStringWidth == null) @@ -228,7 +228,7 @@ public Type TryGetCSharpTypeForSQLDBType(string sqlType) return null; } - + /// public bool IsSupportedSQLDBType(string sqlType) { @@ -328,7 +328,7 @@ protected Guesser GetGuesserFor(DiscoveredColumn discoveredColumn, int extraLeng ExtraLengthPerNonAsciiCharacter = extraLengthPerNonAsciiCharacter }; } - + public virtual int GetLengthIfString(string sqlType) { if (string.IsNullOrWhiteSpace(sqlType)) @@ -374,11 +374,11 @@ public string TranslateSQLDBType(string sqlType, ITypeTranslater destinationType //this then returns datetime (e.g. mysql) return destinationTypeTranslater.GetSQLDBTypeForCSharpType(requested); } - + /// /// Return the number of characters required to not truncate/lose any data when altering a column from time (e.g. TIME etc) to varchar(x). Return - /// x such that the column does not loose integrity. This is needed when dynamically discovering what size to make a column by streaming data into a table. + /// x such that the column does not loose integrity. This is needed when dynamically discovering what size to make a column by streaming data into a table. /// if we see many times and nulls we will decide to use a time column then we see strings and have to convert the column to a varchar column without loosing the /// currently loaded data. /// @@ -409,7 +409,7 @@ select LEN(dt) from omgTimes /// /// Return the number of characters required to not truncate/loose any data when altering a column from datetime (e.g. datetime2, DATE etc) to varchar(x). Return - /// x such that the column does not lose integrity. This is needed when dynamically discovering what size to make a column by streaming data into a table. + /// x such that the column does not lose integrity. This is needed when dynamically discovering what size to make a column by streaming data into a table. /// if we see many dates and nulls we will decide to use a date column then we see strings and have to convert the column to a varchar column without loosing the /// currently loaded data. /// diff --git a/FAnsiSql/Extensions/DataColumnExtensions.cs b/FAnsiSql/Extensions/DataColumnExtensions.cs index 94c98792..002ef8ad 100644 --- a/FAnsiSql/Extensions/DataColumnExtensions.cs +++ b/FAnsiSql/Extensions/DataColumnExtensions.cs @@ -35,7 +35,7 @@ public static void SetDoNotReType(this DataColumn dc, bool value) /// public static bool GetDoNotReType(this DataColumn dc) { - return + return dc.DataType == typeof(string) && dc.ExtendedProperties[DoNotReTypeExtendedProperty] is true; } diff --git a/FAnsiSql/Implementation/ImplementationManager.cs b/FAnsiSql/Implementation/ImplementationManager.cs index cdc03fda..1ec88d11 100644 --- a/FAnsiSql/Implementation/ImplementationManager.cs +++ b/FAnsiSql/Implementation/ImplementationManager.cs @@ -69,7 +69,7 @@ public static IImplementation GetImplementation(DbConnectionStringBuilder connec public static IImplementation GetImplementation(DbConnection connection) { - return GetImplementation(i => i.IsFor(connection), + return GetImplementation(i => i.IsFor(connection), string.Format( FAnsiStrings .ImplementationManager_GetImplementation_No_implementation_found_for_ADO_Net_object_of_Type__0_, diff --git a/FAnsiSql/Naming/IHasRuntimeName.cs b/FAnsiSql/Naming/IHasRuntimeName.cs index 5988a83c..98b2d8fc 100644 --- a/FAnsiSql/Naming/IHasRuntimeName.cs +++ b/FAnsiSql/Naming/IHasRuntimeName.cs @@ -2,9 +2,9 @@ namespace FAnsi.Naming; /// /// Interface for an object which references a database location (e.g. a column or a table or a database etc). The 'RuntimeName' is defined as an unqualified string -/// as it could be used at runtime e.g. in an DbDataReader. So for example a TableInfo called '[MyDb]..[MyTbl]' would have a 'RuntimeName' of 'MyTbl'. +/// as it could be used at runtime e.g. in an DbDataReader. So for example a TableInfo called '[MyDb]..[MyTbl]' would have a 'RuntimeName' of 'MyTbl'. /// -/// This also must take into account aliases so an ExtractionInformation class defined as 'UPPER([MyDb]..[MyTbl].[Name]) as CapsName' would have a 'RuntimeName' +/// This also must take into account aliases so an ExtractionInformation class defined as 'UPPER([MyDb]..[MyTbl].[Name]) as CapsName' would have a 'RuntimeName' /// of 'CapsName'. /// public interface IHasRuntimeName diff --git a/Tests/FAnsiTests/Aggregation/AggregationTests.cs b/Tests/FAnsiTests/Aggregation/AggregationTests.cs index c3f490e1..3cf97d9d 100644 --- a/Tests/FAnsiTests/Aggregation/AggregationTests.cs +++ b/Tests/FAnsiTests/Aggregation/AggregationTests.cs @@ -118,7 +118,7 @@ private static bool IsMatch(DataRow r, object[] cells) //they are not a match because they are not the same type and cannot be converted return false; } - + if (!a.Equals(b)) return false; } @@ -177,5 +177,5 @@ protected DiscoveredTable GetTestTable(DatabaseType type, bool easy = false) return dic[type]; } - + } \ No newline at end of file diff --git a/Tests/FAnsiTests/Aggregation/CalendarAggregationTests.cs b/Tests/FAnsiTests/Aggregation/CalendarAggregationTests.cs index c5bbe68d..9f43b673 100644 --- a/Tests/FAnsiTests/Aggregation/CalendarAggregationTests.cs +++ b/Tests/FAnsiTests/Aggregation/CalendarAggregationTests.cs @@ -24,11 +24,11 @@ public void Test_Calendar_Year(DatabaseType type) new("SELECT", QueryComponent.SELECT), new("count(*) as MyCount,", QueryComponent.QueryTimeColumn) { Role = CustomLineRole.CountFunction }, - new(eventDate.GetFullyQualifiedName(), QueryComponent.QueryTimeColumn) { Role = CustomLineRole.Axis }, //tell it which the axis are + new(eventDate.GetFullyQualifiedName(), QueryComponent.QueryTimeColumn) { Role = CustomLineRole.Axis }, //tell it which the axis are new("FROM ", QueryComponent.FROM), new(tbl.GetFullyQualifiedName(), QueryComponent.FROM), new("GROUP BY", QueryComponent.GroupBy), - new(eventDate.GetFullyQualifiedName(), QueryComponent.GroupBy) { Role = CustomLineRole.Axis } //tell it which the axis are + new(eventDate.GetFullyQualifiedName(), QueryComponent.GroupBy) { Role = CustomLineRole.Axis } //tell it which the axis are }; var axis = new QueryAxis @@ -83,11 +83,11 @@ public void Test_Calendar_Quarter(DatabaseType type) { new("SELECT", QueryComponent.SELECT), new("count(*) as MyCount,", QueryComponent.QueryTimeColumn) { Role = CustomLineRole.CountFunction }, - new(col.GetFullyQualifiedName(), QueryComponent.QueryTimeColumn) { Role = CustomLineRole.Axis }, //tell it which the axis are + new(col.GetFullyQualifiedName(), QueryComponent.QueryTimeColumn) { Role = CustomLineRole.Axis }, //tell it which the axis are new("FROM ", QueryComponent.FROM), new(tbl.GetFullyQualifiedName(), QueryComponent.FROM), new("GROUP BY", QueryComponent.GroupBy), - new(col.GetFullyQualifiedName(), QueryComponent.GroupBy) { Role = CustomLineRole.Axis } //tell it which the axis are + new(col.GetFullyQualifiedName(), QueryComponent.GroupBy) { Role = CustomLineRole.Axis } //tell it which the axis are }; var axis = new QueryAxis @@ -128,11 +128,11 @@ public void Test_Calendar_Month(DatabaseType type) new("SELECT", QueryComponent.SELECT), new("count(*) as MyCount,", QueryComponent.QueryTimeColumn) { Role = CustomLineRole.CountFunction }, - new(syntax.EnsureWrapped("EventDate"), QueryComponent.QueryTimeColumn) { Role = CustomLineRole.Axis }, //tell it which the axis are + new(syntax.EnsureWrapped("EventDate"), QueryComponent.QueryTimeColumn) { Role = CustomLineRole.Axis }, //tell it which the axis are new("FROM ", QueryComponent.FROM), new(tbl.GetFullyQualifiedName(), QueryComponent.FROM), new("GROUP BY", QueryComponent.GroupBy), - new(syntax.EnsureWrapped("EventDate"), QueryComponent.GroupBy) { Role = CustomLineRole.Axis } //tell it which the axis are + new(syntax.EnsureWrapped("EventDate"), QueryComponent.GroupBy) { Role = CustomLineRole.Axis } //tell it which the axis are }; var axis = new QueryAxis @@ -172,11 +172,11 @@ public void Test_Calendar_Day(DatabaseType type) new("SELECT", QueryComponent.SELECT), new("count(*) as MyCount,", QueryComponent.QueryTimeColumn) { Role = CustomLineRole.CountFunction }, - new(col.GetFullyQualifiedName(), QueryComponent.QueryTimeColumn) { Role = CustomLineRole.Axis }, //tell it which the axis are + new(col.GetFullyQualifiedName(), QueryComponent.QueryTimeColumn) { Role = CustomLineRole.Axis }, //tell it which the axis are new("FROM ", QueryComponent.FROM), new(tbl.GetFullyQualifiedName(), QueryComponent.FROM), new("GROUP BY", QueryComponent.GroupBy), - new(col.GetFullyQualifiedName(), QueryComponent.GroupBy) { Role = CustomLineRole.Axis } //tell it which the axis are + new(col.GetFullyQualifiedName(), QueryComponent.GroupBy) { Role = CustomLineRole.Axis } //tell it which the axis are }; var axis = new QueryAxis @@ -216,11 +216,11 @@ public void Test_Calendar_ToToday(DatabaseType type) new("SELECT", QueryComponent.SELECT), new("count(*) as MyCount,", QueryComponent.QueryTimeColumn) { Role = CustomLineRole.CountFunction }, - new(eventDate.GetFullyQualifiedName(), QueryComponent.QueryTimeColumn) { Role = CustomLineRole.Axis }, //tell it which the axis are + new(eventDate.GetFullyQualifiedName(), QueryComponent.QueryTimeColumn) { Role = CustomLineRole.Axis }, //tell it which the axis are new("FROM ", QueryComponent.FROM), new(tbl.GetFullyQualifiedName(), QueryComponent.FROM), new("GROUP BY", QueryComponent.GroupBy), - new(eventDate.GetFullyQualifiedName(), QueryComponent.GroupBy) { Role = CustomLineRole.Axis } //tell it which the axis are + new(eventDate.GetFullyQualifiedName(), QueryComponent.GroupBy) { Role = CustomLineRole.Axis } //tell it which the axis are }; var axis = new QueryAxis @@ -284,12 +284,12 @@ public void Test_Calendar_SELECTColumnOrder_CountAfterAxisColumn(DatabaseType ty { new("SELECT", QueryComponent.SELECT), new($"{eventDate.GetFullyQualifiedName()},", QueryComponent.QueryTimeColumn) - { Role = CustomLineRole.Axis }, //tell it which the axis are + { Role = CustomLineRole.Axis }, //tell it which the axis are new("count(*) as MyCount", QueryComponent.QueryTimeColumn) { Role = CustomLineRole.CountFunction }, new("FROM ", QueryComponent.FROM), new(tbl.GetFullyQualifiedName(), QueryComponent.FROM), new("GROUP BY", QueryComponent.GroupBy), - new(eventDate.GetFullyQualifiedName(), QueryComponent.GroupBy) { Role = CustomLineRole.Axis } //tell it which the axis are + new(eventDate.GetFullyQualifiedName(), QueryComponent.GroupBy) { Role = CustomLineRole.Axis } //tell it which the axis are }; var axis = new QueryAxis diff --git a/Tests/FAnsiTests/All.cs b/Tests/FAnsiTests/All.cs index 7290ba05..0d9946a1 100644 --- a/Tests/FAnsiTests/All.cs +++ b/Tests/FAnsiTests/All.cs @@ -30,7 +30,7 @@ public class All new object[] {DatabaseType.PostgreSql,false} }; - + /// /// for tests that should run on all DBMS /// with all permutations of true/false for 2 args. Matches exhaustively method signature (DatabaseType,bool,bool) diff --git a/Tests/FAnsiTests/CrossPlatformTests.cs b/Tests/FAnsiTests/CrossPlatformTests.cs index f284faaa..8de922ec 100644 --- a/Tests/FAnsiTests/CrossPlatformTests.cs +++ b/Tests/FAnsiTests/CrossPlatformTests.cs @@ -17,7 +17,7 @@ namespace FAnsiTests; public class CrossPlatformTests:DatabaseTests { - + [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] public void TestTableCreation_NullTableName(DatabaseType type) { @@ -55,7 +55,7 @@ public void DateColumnTests_NoTime(DatabaseType type, object input) Assert.AreEqual(expectedDate, result.Rows[0][0]); Assert.AreEqual(expectedDate, result.Rows[1][0]); } - + [TestCase(DatabaseType.MicrosoftSQLServer, "2/28/1993 5:36:27 AM","en-US")] [TestCase(DatabaseType.MySql, "2/28/1993 5:36:27 AM","en-US")] [TestCase(DatabaseType.Oracle, "2/28/1993 5:36:27 AM","en-US")] @@ -89,7 +89,7 @@ public void DateColumnTests_UkUsFormat_Explicit(DatabaseType type, object input, Assert.AreEqual(expectedDate, result.Rows[0][0]); Assert.AreEqual(expectedDate, result.Rows[1][0]); } - + /// /// Since DateTimes are converted in DataTable in memory before being up loaded to the database we need to check @@ -344,7 +344,7 @@ public void ForeignKeyCreationTest(DatabaseType type) var cmd = tblParent.Database.Server.GetCommand( $"INSERT INTO {tblChild.GetFullyQualifiedName()} VALUES (100,'chucky')", con); - + //violation of fk Assert.That(() => cmd.ExecuteNonQuery(), Throws.Exception); @@ -353,7 +353,7 @@ public void ForeignKeyCreationTest(DatabaseType type) tblParent.Database.Server.GetCommand( $"INSERT INTO {tblChild.GetFullyQualifiedName()} VALUES (1,'chucky2')", con).ExecuteNonQuery(); } - + Assert.AreEqual(2,tblParent.GetRowCount()); Assert.AreEqual(2, tblChild.GetRowCount()); @@ -364,7 +364,7 @@ public void ForeignKeyCreationTest(DatabaseType type) var cmd = tblParent.Database.Server.GetCommand($"DELETE FROM {tblParent.GetFullyQualifiedName()}", con); cmd.ExecuteNonQuery(); } - + Assert.AreEqual(0,tblParent.GetRowCount()); Assert.AreEqual(0, tblChild.GetRowCount()); } @@ -412,7 +412,7 @@ public void ForeignKeyCreationTest_TwoColumns(DatabaseType type, bool cascadeDel dt.Columns.Add("Name"); dt.Rows.Add(1,2, "Bob"); - + intoParent.Upload(dt); } @@ -868,7 +868,7 @@ public void HorribleColumnNames(DatabaseType type, string horribleDatabaseName, dt.PrimaryKey = new[] {dt.Columns[0]}; var tbl = database.CreateTable(horribleTableName, dt); - + Assert.AreEqual(1, tbl.GetRowCount()); Assert.IsTrue(tbl.DiscoverColumns().Single().IsPrimaryKey); @@ -876,7 +876,7 @@ public void HorribleColumnNames(DatabaseType type, string horribleDatabaseName, Assert.AreEqual(1,tbl.GetDataTable().Rows.Count); tbl.Insert(new Dictionary { {columnName,"fff" } }); - + Assert.AreEqual(2,tbl.GetDataTable().Rows.Count); } finally @@ -929,7 +929,7 @@ public void CreateTable_DefaultTest_Date(DatabaseType type) var tbl = database.CreateTable("MyTable", new[] { - new DatabaseColumnRequest("Name", new DatabaseTypeRequest(typeof(string),100)), + new DatabaseColumnRequest("Name", new DatabaseTypeRequest(typeof(string),100)), new DatabaseColumnRequest("myDt", new DatabaseTypeRequest(typeof (DateTime))) { AllowNulls = false, @@ -982,7 +982,7 @@ public void CreateTable_DefaultTest_Guid(DatabaseType type) var tbl = database.CreateTable("MyTable", new[] { - new DatabaseColumnRequest("Name", new DatabaseTypeRequest(typeof(string),100)), + new DatabaseColumnRequest("Name", new DatabaseTypeRequest(typeof(string),100)), new DatabaseColumnRequest("MyGuid", new DatabaseTypeRequest(typeof (string))) { AllowNulls = false, @@ -1014,9 +1014,9 @@ public void Test_BulkInserting_LotsOfDates(DatabaseType type) var db = GetTestDatabase(type); var tbl = db.CreateTable("LotsOfDatesTest",new DatabaseColumnRequest[] - { + { new("ID",new DatabaseTypeRequest(typeof(int))), - new("MyDate",new DatabaseTypeRequest(typeof(DateTime))), + new("MyDate",new DatabaseTypeRequest(typeof(DateTime))), new("MyString",new DatabaseTypeRequest(typeof(string),int.MaxValue)) }); @@ -1024,9 +1024,9 @@ public void Test_BulkInserting_LotsOfDates(DatabaseType type) foreach(var s in someDates) { tbl.Insert(new Dictionary - { - {"ID",1}, - {"MyDate",s}, + { + {"ID",1}, + {"MyDate",s}, {"MyString",Guid.NewGuid().ToString()} },culture ); diff --git a/Tests/FAnsiTests/DatabaseTests.cs b/Tests/FAnsiTests/DatabaseTests.cs index 37a3b28f..6c3b6754 100644 --- a/Tests/FAnsiTests/DatabaseTests.cs +++ b/Tests/FAnsiTests/DatabaseTests.cs @@ -38,7 +38,7 @@ public void CheckFiles() ImplementationManager.Load(); var file = Path.Combine(TestContext.CurrentContext.TestDirectory, TestFilename); - + Assert.IsTrue(File.Exists(file),"Could not find " + TestFilename); var doc = XDocument.Load(file); @@ -57,7 +57,7 @@ public void CheckFiles() throw new Exception($"Missing element 'TestScratchDatabase' in {TestFilename}"); _testScratchDatabase = e.Value; - + foreach (var element in root.Elements("TestDatabase")) { var type = element.Element("DatabaseType")?.Value; @@ -65,9 +65,9 @@ public void CheckFiles() if(!Enum.TryParse(type, out DatabaseType databaseType)) throw new Exception($"Could not parse DatabaseType {type}"); - + var constr = element.Element("ConnectionString")?.Value; - + TestConnectionStrings.Add(databaseType,constr); } } @@ -76,7 +76,7 @@ public void CheckFiles() TestContext.WriteLine(exception); throw; } - + } protected IEnumerable TestServer() diff --git a/Tests/FAnsiTests/ManagedConnectionTests.cs b/Tests/FAnsiTests/ManagedConnectionTests.cs index d46ed61b..9d68ccf6 100644 --- a/Tests/FAnsiTests/ManagedConnectionTests.cs +++ b/Tests/FAnsiTests/ManagedConnectionTests.cs @@ -13,7 +13,7 @@ public void Test_GetConnection_NotOpenAtStart(DatabaseType dbType) var db = GetTestDatabase(dbType); var con = db.Server.GetConnection(); - + //GetConnection should return an unopened connection Assert.AreEqual(ConnectionState.Closed,con.State); } @@ -74,13 +74,13 @@ public void Test_BeginNewTransactedConnection_AutoOpenClose(DatabaseType dbType) public void Test_GetManagedConnection_OngoingTransaction(DatabaseType dbType) { var db = GetTestDatabase(dbType); - + IManagedConnection ongoingCon; //pretend that there is an ongoing transaction already using (ongoingCon = db.Server.BeginNewTransactedConnection()) { var ongoingTrans = ongoingCon.ManagedTransaction; - + //BeginNewTransactedConnection should open itself Assert.AreEqual(ConnectionState.Open,ongoingCon.Connection.State); Assert.IsNotNull(ongoingTrans); @@ -97,7 +97,7 @@ public void Test_GetManagedConnection_OngoingTransaction(DatabaseType dbType) //it should still be open after this finally block Assert.AreEqual(ConnectionState.Open,con.Connection.State); } - + //this is the using on the transaction this one should now close itself Assert.AreEqual(ConnectionState.Closed,ongoingCon.Connection.State); } @@ -105,7 +105,7 @@ public void Test_GetManagedConnection_OngoingTransaction(DatabaseType dbType) /// /// Same as Test_GetManagedConnection_OngoingTransaction except we call or - /// instead of relying on the outermost using finally + /// instead of relying on the outermost using finally /// /// /// Whether to commit @@ -119,7 +119,7 @@ public void Test_GetManagedConnection_OngoingTransaction_WithCommitRollback(Data using (ongoingCon = db.Server.BeginNewTransactedConnection()) { var ongoingTrans = ongoingCon.ManagedTransaction; - + //BeginNewTransactedConnection should open itself Assert.AreEqual(ConnectionState.Open,ongoingCon.Connection.State); Assert.IsNotNull(ongoingTrans); diff --git a/Tests/FAnsiTests/Query/QuerySyntaxHelperDatabaseTests.cs b/Tests/FAnsiTests/Query/QuerySyntaxHelperDatabaseTests.cs index af1b5267..7e1cb73a 100644 --- a/Tests/FAnsiTests/Query/QuerySyntaxHelperDatabaseTests.cs +++ b/Tests/FAnsiTests/Query/QuerySyntaxHelperDatabaseTests.cs @@ -7,7 +7,7 @@ namespace FAnsiTests.Query; internal class QuerySyntaxHelperDatabaseTests : DatabaseTests { - + [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] public void Test_HowDoWeAchieveMd5(DatabaseType dbType) { diff --git a/Tests/FAnsiTests/Query/QuerySyntaxHelperTests.cs b/Tests/FAnsiTests/Query/QuerySyntaxHelperTests.cs index e265b69b..d026cddf 100644 --- a/Tests/FAnsiTests/Query/QuerySyntaxHelperTests.cs +++ b/Tests/FAnsiTests/Query/QuerySyntaxHelperTests.cs @@ -10,18 +10,18 @@ namespace FAnsiTests.Query; internal class QuerySyntaxHelperTests { - + //Oracle always uppers everything because... Oracle [TestCase(DatabaseType.Oracle,"CHI","\"TEST_ScratchArea\".public.\"Biochemistry\".\"chi\"")] [TestCase(DatabaseType.PostgreSql,"chi","\"TEST_ScratchArea\".public.\"Biochemistry\".\"chi\"")] - + [TestCase(DatabaseType.Oracle,"FRANK","count(*) as Frank")] [TestCase(DatabaseType.PostgreSql,"Frank","count(*) as Frank")] [TestCase(DatabaseType.Oracle,"FRANK","count(cast(1 as int)) as Frank")] [TestCase(DatabaseType.PostgreSql,"Frank","count(cast(1 as int)) as Frank")] - + [TestCase(DatabaseType.Oracle,"FRANK","count(cast(1 as int)) as \"Frank\"")] [TestCase(DatabaseType.PostgreSql,"Frank","count(cast(1 as int)) as \"Frank\"")] [TestCase(DatabaseType.MySql,"Frank","count(cast(1 as int)) as `Frank`")] @@ -36,11 +36,11 @@ internal class QuerySyntaxHelperTests [TestCase(DatabaseType.MicrosoftSQLServer,"zombie","dbo.GetMyCoolThing(\"Magic Fun Times\") as zombie")] [TestCase(DatabaseType.MySql,"zombie","dbo.GetMyCoolThing(\"Magic Fun Times\") as zombie")] [TestCase(DatabaseType.PostgreSql,"zombie","dbo.GetMyCoolThing(\"Magic Fun Times\") as zombie")] - + [TestCase(DatabaseType.Oracle,"MYCOL","\"mydb\".\"mytbl\".\"mycol\"")] [TestCase(DatabaseType.MicrosoftSQLServer,"mycol","[mydb].[mytbl].[mycol]")] [TestCase(DatabaseType.MySql,"mycol","`mydb`.`mytbl`.`mycol`")] - [TestCase(DatabaseType.PostgreSql,"mycol","\"mydb\".\"mytbl\".\"mycol\"")] + [TestCase(DatabaseType.PostgreSql,"mycol","\"mydb\".\"mytbl\".\"mycol\"")] public void SyntaxHelperTest_GetRuntimeName(DatabaseType dbType, string expected, string forInput) { var syntaxHelper = ImplementationManager.GetImplementation(dbType).GetQuerySyntaxHelper(); @@ -86,7 +86,7 @@ public void SyntaxHelperTest_GetRuntimeName_MultipleCalls(DatabaseType dbType, } } } - + [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] public void EnsureWrapped_MultipleCalls(DatabaseType dbType) { diff --git a/Tests/FAnsiTests/Server/ServerTests.cs b/Tests/FAnsiTests/Server/ServerTests.cs index af4c0572..016e35ba 100644 --- a/Tests/FAnsiTests/Server/ServerTests.cs +++ b/Tests/FAnsiTests/Server/ServerTests.cs @@ -69,7 +69,7 @@ public void ServerHelper_GetConnectionStringBuilder(DatabaseType type) Assert.AreEqual("wacky",server.ExplicitPasswordIfAny); } - + [TestCaseSource(typeof(All),nameof(All.DatabaseTypesWithBoolFlags))] public void ServerHelper_GetConnectionStringBuilder_NoDatabase(DatabaseType type,bool useWhitespace) { @@ -224,5 +224,5 @@ public void TestServer_GetVersion(DatabaseType dbType) Assert.Greater(ver.Major,0); } - + } \ No newline at end of file diff --git a/Tests/FAnsiTests/Table/BadNamesTests.cs b/Tests/FAnsiTests/Table/BadNamesTests.cs index bcd5e447..f3f65e68 100644 --- a/Tests/FAnsiTests/Table/BadNamesTests.cs +++ b/Tests/FAnsiTests/Table/BadNamesTests.cs @@ -38,8 +38,8 @@ private DiscoveredTable SetupBadNamesTable(DatabaseType dbType) var (badTableName,badColumnName,badColumnName2) = GetBadNames(dbType); return db.CreateTable(badTableName,new[] { - new DatabaseColumnRequest(badColumnName,new DatabaseTypeRequest(typeof(string),100)), - new DatabaseColumnRequest(badColumnName2,new DatabaseTypeRequest(typeof(int))) + new DatabaseColumnRequest(badColumnName,new DatabaseTypeRequest(typeof(string),100)), + new DatabaseColumnRequest(badColumnName2,new DatabaseTypeRequest(typeof(int))) }); } @@ -125,14 +125,14 @@ public void BadNames_TopXColumn(DatabaseType dbType,bool noNulls) Assert.IsTrue(r.Read()); Assert.AreEqual(!noNulls,r.Read()); - + Assert.IsFalse(r.Read()); } tbl.Drop(); } - + [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] public void BadNames_DropColumn(DatabaseType dbType) { @@ -181,7 +181,7 @@ public void BadNames_TopXTable(DatabaseType dbType) tbl.Drop(); } - + [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] public void BadNames_DiscoverRelationships(DatabaseType dbType) { @@ -191,8 +191,8 @@ public void BadNames_DiscoverRelationships(DatabaseType dbType) var tbl1 = db.CreateTable(badTableName,new[] { - new DatabaseColumnRequest(badColumnName,new DatabaseTypeRequest(typeof(string),100)){IsPrimaryKey = true }, - new DatabaseColumnRequest("Frrrrr ##' ank",new DatabaseTypeRequest(typeof(int))) + new DatabaseColumnRequest(badColumnName,new DatabaseTypeRequest(typeof(string),100)){IsPrimaryKey = true }, + new DatabaseColumnRequest("Frrrrr ##' ank",new DatabaseTypeRequest(typeof(int))) }); var pk = tbl1.DiscoverColumns().Single(c=>c.IsPrimaryKey); @@ -200,7 +200,7 @@ public void BadNames_DiscoverRelationships(DatabaseType dbType) var tbl2 = db.CreateTable(new CreateTableArgs(db, $"{badTableName}2",null) { - ExplicitColumnDefinitions = new []{fk = new DatabaseColumnRequest($"{badColumnName}2",new DatabaseTypeRequest(typeof(string),100)) }, + ExplicitColumnDefinitions = new []{fk = new DatabaseColumnRequest($"{badColumnName}2",new DatabaseTypeRequest(typeof(string),100)) }, ForeignKeyPairs = new Dictionary {{fk, pk} } }); @@ -237,7 +237,7 @@ public void BadNames_BulkInsert(DatabaseType dbType) tbl.Drop(); } - + [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] public void BadNames_Rename(DatabaseType dbType) { diff --git a/Tests/FAnsiTests/Table/BasicInsertTests.cs b/Tests/FAnsiTests/Table/BasicInsertTests.cs index c3851cd6..fb735a85 100644 --- a/Tests/FAnsiTests/Table/BasicInsertTests.cs +++ b/Tests/FAnsiTests/Table/BasicInsertTests.cs @@ -12,7 +12,7 @@ internal class BasicInsertTests:DatabaseTests [TestCase(DatabaseType.MySql,"Dave")] [TestCase(DatabaseType.Oracle, "Dave")] [TestCase(DatabaseType.PostgreSql, "Dave")] - + [TestCase(DatabaseType.MicrosoftSQLServer, @"].;\""ffff [")] @@ -82,7 +82,7 @@ public void CreateTableAndInsertAValue_ReturnsIdentity(DatabaseType type) var tbl = db.CreateTable("InsertTable", new[] { - new DatabaseColumnRequest("myidentity",new DatabaseTypeRequest(typeof(int))){IsPrimaryKey = true,IsAutoIncrement = true}, + new DatabaseColumnRequest("myidentity",new DatabaseTypeRequest(typeof(int))){IsPrimaryKey = true,IsAutoIncrement = true}, new DatabaseColumnRequest("Name",new DatabaseTypeRequest(typeof(string),100)) }); diff --git a/Tests/FAnsiTests/Table/BulkInsertTest.cs b/Tests/FAnsiTests/Table/BulkInsertTest.cs index 0c383cb8..1873c0ee 100644 --- a/Tests/FAnsiTests/Table/BulkInsertTest.cs +++ b/Tests/FAnsiTests/Table/BulkInsertTest.cs @@ -476,7 +476,7 @@ public void UnmatchedColumnsBulkInsertTest_UsesDefaultValues_TwoLargeBatches_Pas cts.Cancel(); //creation should have been cancelled at the database level var ex = Assert.Throws(()=>tbl.CreatePrimaryKey(con.ManagedTransaction,cts.Token,50000,bobCol)); - + //MySql seems to be throwing null reference inside ExecuteNonQueryAsync. No idea why but it is still cancelled if(type != DatabaseType.MySql) StringAssert.Contains("cancel",ex?.InnerException?.Message); @@ -653,7 +653,7 @@ public void TestBulkInsert_Unicode(DatabaseType dbType) Assert.Contains("你好",dtResult.Rows.Cast().Select(r=>r[0]).ToArray()); Assert.Contains("مرحبا",dtResult.Rows.Cast().Select(r=>r[0]).ToArray()); table.Drop(); - } + } [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] public void TestBulkInsert_SchemaTooNarrow_StringError(DatabaseType type) @@ -762,7 +762,7 @@ public void TestBulkInsert_SchemaTooNarrow_DecimalError(DatabaseType type) dt.Rows.Add(60,"Jamie",1.2); dt.Rows.Add(30,"Frank",1.3); - dt.Rows.Add(11,"Toad",111111111.11); //bad data + dt.Rows.Add(11,"Toad",111111111.11); //bad data dt.Rows.Add(100,"King"); dt.Rows.Add(10,"Frog"); @@ -770,7 +770,7 @@ public void TestBulkInsert_SchemaTooNarrow_DecimalError(DatabaseType type) bulk.Timeout = 30; Exception ex = null; - try + try { bulk.Upload(dt); } @@ -827,7 +827,7 @@ public void TestBulkInsert_BadDecimalFormat_DecimalError(DatabaseType type) dt.Rows.Add(60,"Jamie",1.2); dt.Rows.Add(30,"Frank",1.3); - dt.Rows.Add(11,"Toad","."); //bad data + dt.Rows.Add(11,"Toad","."); //bad data dt.Rows.Add(100,"King"); dt.Rows.Add(10,"Frog"); @@ -835,7 +835,7 @@ public void TestBulkInsert_BadDecimalFormat_DecimalError(DatabaseType type) bulk.Timeout = 30; Exception ex = null; - try + try { bulk.Upload(dt); } diff --git a/Tests/FAnsiTests/Table/CreateTableTests.cs b/Tests/FAnsiTests/Table/CreateTableTests.cs index 2585943f..b1280fd0 100644 --- a/Tests/FAnsiTests/Table/CreateTableTests.cs +++ b/Tests/FAnsiTests/Table/CreateTableTests.cs @@ -49,7 +49,7 @@ public void TestTableCreation(DatabaseType type) new DatabaseColumnRequest("address", new DatabaseTypeRequest(typeof (string), 500)), new DatabaseColumnRequest("dob", new DatabaseTypeRequest(typeof (DateTime)),false), new DatabaseColumnRequest("score", - new DatabaseTypeRequest(typeof (decimal), null, new DecimalSize(5, 3))) //<- e.g. 12345.123 + new DatabaseTypeRequest(typeof (decimal), null, new DecimalSize(5, 3))) //<- e.g. 12345.123 }); @@ -160,7 +160,7 @@ public void CreateTable_PrimaryKey_FromDataTable(DatabaseType databaseType) Assert.IsTrue(table.DiscoverColumn("Name").IsPrimaryKey); } - + [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] public void CreateTable_PrimaryKey_FromColumnRequest(DatabaseType databaseType) { @@ -285,7 +285,7 @@ public void Test_OracleBit_IsNotStringAnyMore() } - + [TestCase(DatabaseType.MicrosoftSQLServer, "didn’t")] //<- it's a ’ not a ' [TestCase(DatabaseType.MicrosoftSQLServer, "Æther")] [TestCase(DatabaseType.MicrosoftSQLServer, "乗")] @@ -406,7 +406,7 @@ public void Test_CreateTable_DoNotRetype(DatabaseType dbType) tbl.Drop(); } - + /// /// Just to check that clone on properly clones /// @@ -460,7 +460,7 @@ public void CreateTable_ObjectColumns_StringContent(DatabaseType dbType) StringAssert.Contains("System.Object",ex?.Message); } - + /// /// Tests how we can customize how "T" and "F" etc are interpreted (either as boolean true/false or as string). This test /// uses the static defaults in . diff --git a/Tests/FAnsiTests/Table/ForeignKeyTests.cs b/Tests/FAnsiTests/Table/ForeignKeyTests.cs index ed02619d..c25158ad 100644 --- a/Tests/FAnsiTests/Table/ForeignKeyTests.cs +++ b/Tests/FAnsiTests/Table/ForeignKeyTests.cs @@ -36,7 +36,7 @@ public void TestForeignKey_OneColumnKey(DatabaseType dbType, bool cascade) }, new Dictionary { {requested_fkCol,discovered_pkCol} - + }, cascade); var discovered_fkCol = childTable.DiscoverColumn("Parent_Id"); @@ -189,7 +189,7 @@ public void Test_ThreeTables_OnePrimary(DatabaseType dbType, bool useTransaction Assert.Contains(t2, sort2.Order.ToList()); Assert.Contains(t3, sort2.Order.ToList()); } - + [TestCaseSource(typeof(All),nameof(All.DatabaseTypes))] public void Test_ThreeTables_TwoPrimary(DatabaseType dbType) { diff --git a/Tests/FAnsiTests/Table/TopXTests.cs b/Tests/FAnsiTests/Table/TopXTests.cs index c0dd7bb8..0566ff30 100644 --- a/Tests/FAnsiTests/Table/TopXTests.cs +++ b/Tests/FAnsiTests/Table/TopXTests.cs @@ -27,7 +27,7 @@ public void Test_TopX_OrderBy(DatabaseType type,bool asc) tbl = db.CreateTable("MyTopXTable",dt); } - + var topx = tbl.GetQuerySyntaxHelper().HowDoWeAchieveTopX(1); var f = tbl.GetQuerySyntaxHelper().EnsureWrapped("F"); @@ -58,7 +58,7 @@ public void Test_TopX_OrderBy(DatabaseType type,bool asc) var sqlcol = tbl.DiscoverColumn("X").GetTopXSql(1,false); Assert.AreEqual(DBNull.Value,db.Server.GetCommand(sqlcol,con).ExecuteScalar()); - + sqlcol = tbl.DiscoverColumn("X").GetTopXSql(1,true); Assert.AreEqual("fish",db.Server.GetCommand(sqlcol,con).ExecuteScalar()); diff --git a/Tests/FAnsiTests/Table/UpdateTests.cs b/Tests/FAnsiTests/Table/UpdateTests.cs index eeb0c82d..658d44a7 100644 --- a/Tests/FAnsiTests/Table/UpdateTests.cs +++ b/Tests/FAnsiTests/Table/UpdateTests.cs @@ -36,14 +36,14 @@ public void Test_UpdateTableFromJoin(DatabaseType dbType) dt2.Columns.Add("Score"); dt2.Rows.Add("Dave", 50); dt2.Rows.Add("Frank", 900); - + tbl2 = db.CreateTable("NewScoresTable", dt2); } var syntaxHelper = db.Server.GetQuerySyntaxHelper(); var updateHelper = syntaxHelper.UpdateHelper; - + var queryLines = new List(); var highScore = syntaxHelper.EnsureWrapped("HighScore"); diff --git a/Tests/FAnsiTests/TypeTranslation/DatatypeComputerTests.cs b/Tests/FAnsiTests/TypeTranslation/DatatypeComputerTests.cs index 48c4eb71..c0f2c767 100644 --- a/Tests/FAnsiTests/TypeTranslation/DatatypeComputerTests.cs +++ b/Tests/FAnsiTests/TypeTranslation/DatatypeComputerTests.cs @@ -12,7 +12,7 @@ namespace FAnsiTests.TypeTranslation; /// /// Critically it covers fallback from one data type estimate to another based on new data e.g. if you see a "100" then a "1" then a "1.1" /// the final estimate should be decimal(4,1) to allow for both 100.0f and 1.1f. -/// +/// /// public class GuesserTests { @@ -413,7 +413,7 @@ public void TestGuesser_NumberOfDecimalPlaces() Assert.AreEqual(9, t.Guess.Size.NumbersBeforeDecimalPlace); Assert.AreEqual(14, t.Guess.Size.NumbersAfterDecimalPlace); } - + [Test] public void TestGuesser_TrailingZeroesFallbackToString() @@ -616,7 +616,7 @@ public void TestGuesser_RandomCrud(string randomCrud) t.AdjustToCompensateForValue(randomCrud); Assert.AreEqual(typeof(string), t.Guess.CSharpType); } - + [Test] public void TestGuesser_ScientificNotation() { diff --git a/Tests/FAnsiTests/TypeTranslation/TypeTranslaterTests.cs b/Tests/FAnsiTests/TypeTranslation/TypeTranslaterTests.cs index 2cb5ae3c..5dbde895 100644 --- a/Tests/FAnsiTests/TypeTranslation/TypeTranslaterTests.cs +++ b/Tests/FAnsiTests/TypeTranslation/TypeTranslaterTests.cs @@ -23,7 +23,7 @@ namespace FAnsiTests.TypeTranslation; public class TypeTranslaterTests : DatabaseTests { private readonly Dictionary _translaters = new(); - + [OneTimeSetUp] public void SetupDatabases() {