diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 75589c7a..d4eda6ac 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -24,7 +24,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Initialize CodeQL uses: github/codeql-action/init@v2 diff --git a/.github/workflows/dotnet-core.yml b/.github/workflows/dotnet-core.yml index 39c29513..46dfe4f8 100644 --- a/.github/workflows/dotnet-core.yml +++ b/.github/workflows/dotnet-core.yml @@ -34,7 +34,7 @@ jobs: steps: - name: Disable write flush for CI runs run: sudo apt-get install -y libeatmydata1 apt-transport-https curl - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup .NET Core uses: actions/setup-dotnet@v3 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index e89aad82..0537b775 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [3.1.1] - 2023-09-01 + - Bugfix: MySQL text was erroneously capped at 64k (TEXT) instead of LONGTEXT (4GiB) +- Adjust timeout handling, use 10 seconds not 3 for server live tests since our Azure VM is slow +- Bump MySqlConnector from 2.2.6 to 2.2.7 +- Bump Oracle.ManagedDataAccess.Core from 3.21.100 to 3.21.110 ## [3.1.0] - 2023-05-15 @@ -349,7 +354,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed Drop table to work correctly with Views - Exists now works correctly for Views (previously it would return true if there was no view but a table with the same name) -[Unreleased]: https://github.com/HicServices/FAnsiSql/compare/3.1.0...develop +[Unreleased]: https://github.com/HicServices/FAnsiSql/compare/3.1.1...develop +[3.1.1]: https://github.com/HicServices/FAnsiSql/compare/3.1.0...3.1.1 [3.1.0]: https://github.com/HicServices/FAnsiSql/compare/3.0.1...3.1.0 [3.0.1]: https://github.com/HicServices/FAnsiSql/compare/3.0.0...3.0.1 [3.0.0]: https://github.com/HicServices/FAnsiSql/compare/2.0.5...3.0.0 diff --git a/FAnsiSql/DatabaseOperationArgs.cs b/FAnsiSql/DatabaseOperationArgs.cs index 720517d8..95c72a22 100644 --- a/FAnsiSql/DatabaseOperationArgs.cs +++ b/FAnsiSql/DatabaseOperationArgs.cs @@ -30,7 +30,7 @@ public class DatabaseOperationArgs public DatabaseOperationArgs() { - + } public DatabaseOperationArgs(IManagedTransaction transactionIfAny, CancellationToken cancellationToken, int timeoutInSeconds) { @@ -66,7 +66,7 @@ private T Execute(DbCommand cmd, Func> method) { Hydrate(cmd); var t = method(); - + try { switch (t.Status) @@ -86,7 +86,7 @@ private T Execute(DbCommand cmd, Func> method) throw e.InnerExceptions[0]; throw; } - + if (!t.IsCompleted) cmd.Cancel(); @@ -103,7 +103,7 @@ public void Fill(DbDataAdapter da, DbCommand cmd, DataTable dt) CancellationToken.ThrowIfCancellationRequested(); if(CancellationToken.CanBeCanceled) - dt.RowChanged += ThrowIfCancelled; + dt.RowChanged += ThrowIfCancelled; da.Fill(dt); CancellationToken.ThrowIfCancellationRequested(); diff --git a/FAnsiSql/Discovery/DiscoveredDataType.cs b/FAnsiSql/Discovery/DiscoveredDataType.cs index c5102a1e..30a1123d 100644 --- a/FAnsiSql/Discovery/DiscoveredDataType.cs +++ b/FAnsiSql/Discovery/DiscoveredDataType.cs @@ -91,7 +91,7 @@ public override string ToString() public void Resize(int newSize, IManagedTransaction managedTransaction = null) { var toReplace = GetLengthIfString(); - + if(newSize == toReplace) return; @@ -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); } @@ -164,7 +164,7 @@ public void AlterTypeTo(string newType, IManagedTransaction managedTransaction = } } - SQLType = newType; + SQLType = newType; } /// diff --git a/FAnsiSql/Discovery/DiscoveredDatabaseHelper.cs b/FAnsiSql/Discovery/DiscoveredDatabaseHelper.cs index 2e521deb..5533589c 100644 --- a/FAnsiSql/Discovery/DiscoveredDatabaseHelper.cs +++ b/FAnsiSql/Discovery/DiscoveredDatabaseHelper.cs @@ -16,7 +16,7 @@ namespace FAnsi.Discovery; /// -/// 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 procedures etc). For /// database creation see /// public abstract class DiscoveredDatabaseHelper:IDiscoveredDatabaseHelper diff --git a/FAnsiSql/Discovery/DiscoveredServer.cs b/FAnsiSql/Discovery/DiscoveredServer.cs index c5bfe30d..3b76e435 100644 --- a/FAnsiSql/Discovery/DiscoveredServer.cs +++ b/FAnsiSql/Discovery/DiscoveredServer.cs @@ -188,7 +188,7 @@ public DiscoveredDatabase ExpectDatabase(string database) /// /// /// - public void TestConnection(int timeoutInMillis = 3000) + public void TestConnection(int timeoutInMillis = 10000) { using var con = Helper.GetConnection(Builder); using(var tokenSource = new CancellationTokenSource(timeoutInMillis)) @@ -196,7 +196,15 @@ public void TestConnection(int timeoutInMillis = 3000) { try { - openTask.Wait(tokenSource.Token); + openTask.Wait(timeoutInMillis, tokenSource.Token); + } + catch (OperationCanceledException e) + { + throw new TimeoutException( + string.Format( + FAnsiStrings + .DiscoveredServer_TestConnection_Could_not_connect_to_server___0___after_timeout_of__1__milliseconds_, + Name, timeoutInMillis), e); } catch (AggregateException e) { diff --git a/FAnsiSql/Discovery/TypeTranslation/TypeTranslater.cs b/FAnsiSql/Discovery/TypeTranslation/TypeTranslater.cs index 9b386e0f..365b995c 100644 --- a/FAnsiSql/Discovery/TypeTranslation/TypeTranslater.cs +++ b/FAnsiSql/Discovery/TypeTranslation/TypeTranslater.cs @@ -58,13 +58,13 @@ public string GetSQLDBTypeForCSharpType(DatabaseTypeRequest request) if (t == typeof(byte)) return GetByteDataType(); - + if (t == typeof(short) || t == typeof(short) || t == typeof(ushort) || t == typeof(short?) || t == typeof(ushort?)) return GetSmallIntDataType(); if (t == typeof(int) || t == typeof(int) || t == typeof(uint) || t == typeof(int?) || t == typeof(uint?)) return GetIntDataType(); - + if (t == typeof (long) || t == typeof(ulong) || t == typeof(long?) || t == typeof(ulong?)) return GetBigIntDataType(); @@ -80,7 +80,7 @@ public string GetSQLDBTypeForCSharpType(DatabaseTypeRequest request) if (t == typeof(TimeSpan) || t == typeof(TimeSpan?)) return GetTimeDataType(); - + if (t == typeof (byte[])) return GetByteArrayDataType(); @@ -120,7 +120,7 @@ protected string GetStringDataType(int? maxExpectedStringWidth) if (maxExpectedStringWidth > MaxStringWidthBeforeMax) return GetStringDataTypeWithUnlimitedWidth(); - + return GetStringDataTypeImpl(maxExpectedStringWidth.Value); } @@ -139,7 +139,7 @@ private string GetUnicodeStringDataType(int? maxExpectedStringWidth) if (maxExpectedStringWidth > MaxStringWidthBeforeMax) return GetUnicodeStringDataTypeWithUnlimitedWidth(); - + return GetUnicodeStringDataTypeImpl(maxExpectedStringWidth.Value); } @@ -259,13 +259,13 @@ public DbType GetDbTypeForSQLDBType(string sqlType) if (IsString(sqlType)) return DbType.String; - + if (IsDate(sqlType)) return DbType.DateTime; if (IsTime(sqlType)) return DbType.Time; - + if (IsByteArray(sqlType)) return DbType.Object; @@ -295,7 +295,7 @@ public virtual DatabaseTypeRequest GetDataTypeRequestForSQLDBType(string sqlType if (cSharpType == typeof(TimeSpan)) lengthIfString = GetStringLengthForTimeSpan(); - + var request = new DatabaseTypeRequest(cSharpType, lengthIfString, digits); if (cSharpType == typeof(string)) @@ -377,7 +377,7 @@ public string TranslateSQLDBType(string sqlType, ITypeTranslater destinationType /// - /// Return the number of characters required to not truncate/loose any data when altering a column from time (e.g. TIME etc) to varchar(x). Return + /// 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. /// 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 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 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/FAnsi.csproj b/FAnsiSql/FAnsi.csproj index d959145b..7fa3dd1d 100644 --- a/FAnsiSql/FAnsi.csproj +++ b/FAnsiSql/FAnsi.csproj @@ -38,9 +38,9 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + - + diff --git a/SharedAssemblyInfo.cs b/SharedAssemblyInfo.cs index 1a8a3f96..7d4f566c 100644 --- a/SharedAssemblyInfo.cs +++ b/SharedAssemblyInfo.cs @@ -6,6 +6,6 @@ [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -[assembly: AssemblyVersion("3.1.0")] -[assembly: AssemblyFileVersion("3.1.0")] -[assembly: AssemblyInformationalVersion("3.1.0")] +[assembly: AssemblyVersion("3.1.1")] +[assembly: AssemblyFileVersion("3.1.1")] +[assembly: AssemblyInformationalVersion("3.1.1")] diff --git a/Tests/FAnsiTests/CrossPlatformTests.cs b/Tests/FAnsiTests/CrossPlatformTests.cs index 88909067..8de922ec 100644 --- a/Tests/FAnsiTests/CrossPlatformTests.cs +++ b/Tests/FAnsiTests/CrossPlatformTests.cs @@ -40,7 +40,7 @@ public void DateColumnTests_NoTime(DatabaseType type, object input) var tbl = db.CreateTable("MyTable",new []{new DatabaseColumnRequest("MyDate",new DatabaseTypeRequest(typeof(DateTime)))}); tbl.Insert(new Dictionary { { "MyDate", input } }); - + using (var blk = tbl.BeginBulkInsert()) { using var dt = new DataTable(); @@ -73,7 +73,7 @@ public void DateColumnTests_UkUsFormat_Explicit(DatabaseType type, object input, //basic insert tbl.Insert(new Dictionary { { "MyDate", input } },cultureInfo); - + //then bulk insert, both need to work using (var blk = tbl.BeginBulkInsert(cultureInfo)) { @@ -313,7 +313,7 @@ public void ForeignKeyCreationTest(DatabaseType type) }); var parentIdPkCol = tblParent.DiscoverColumn("ID"); - + var parentIdFkCol = new DatabaseColumnRequest("Parent_ID", new DatabaseTypeRequest(typeof (int))); var tblChild = database.CreateTable("Child", new[] @@ -481,10 +481,10 @@ public void CreateMaxVarcharColumns(DatabaseType type) public void CreateMaxVarcharColumnFromDataTable(DatabaseType type) { var database = GetTestDatabase(type); - + var dt = new DataTable(); dt.Columns.Add("MassiveColumn"); - + var sb = new StringBuilder("Amaa"); for (var i = 0; i < 10000; i++) sb.Append(i); @@ -552,7 +552,7 @@ public void AddColumnTest(DatabaseType type,bool useTransaction) { tbl.AddColumn(newColumnName, new DatabaseTypeRequest(typeof(DateTime)), true, 1000); } - + //new column should exist var newCol = tbl.DiscoverColumn(newColumnName); @@ -566,7 +566,7 @@ public void AddColumnTest(DatabaseType type,bool useTransaction) //sql server can't handle altering primary key columns or anything with a foreign key on it too! if (type == DatabaseType.MicrosoftSQLServer) - fieldsToAlter.Remove("Field1"); + fieldsToAlter.Remove("Field1"); foreach (var fieldName in fieldsToAlter) { @@ -679,7 +679,7 @@ public void TestIntDataTypes(DatabaseType type) Assert.AreEqual(2, size.NumbersAfterDecimalPlace); Assert.AreEqual(5, size.Precision); Assert.AreEqual(2, size.Scale); - + dt = tbl.GetDataTable(); Assert.AreEqual(1, dt.Rows.OfType().Count(r => Convert.ToDecimal(r[0]) == new decimal(100.0f))); Assert.AreEqual(1, dt.Rows.OfType().Count(r => Convert.ToDecimal(r[0]) == new decimal(105.0f))); @@ -704,7 +704,7 @@ public void TestFloatDataTypes(DatabaseType type) Assert.AreEqual(1,dt.Rows.OfType().Count(r=>Convert.ToDecimal(r[0]) == new decimal(100.0f))); Assert.AreEqual(1, dt.Rows.OfType().Count(r => Convert.ToDecimal(r[0]) == new decimal(105.0f))); Assert.AreEqual(1, dt.Rows.OfType().Count(r => Convert.ToDecimal(r[0]) == new decimal(2.1f))); - + var col = tbl.DiscoverColumn("MyCol"); var size = col.DataType.GetDecimalSize(); @@ -713,7 +713,7 @@ public void TestFloatDataTypes(DatabaseType type) Assert.AreEqual(1,size.NumbersAfterDecimalPlace); Assert.AreEqual(4, size.Precision); Assert.AreEqual(1, size.Scale); - + col.DataType.AlterTypeTo("decimal(5,2)"); size = tbl.DiscoverColumn("MyCol").DataType.GetDecimalSize(); @@ -737,7 +737,7 @@ public void HorribleDatabaseAndTableNames(DatabaseType type,string horribleDatab database = database.Server.ExpectDatabase(horribleDatabaseName); database.Create(true); - + SqlConnection.ClearAllPools(); try @@ -798,7 +798,7 @@ public void HorribleDatabaseAndTableNames(DatabaseType type,string horribleDatab [TestCase(DatabaseType.PostgreSql, "my.database", "my.table", "my.col")] public void UnsupportedEntityNames(DatabaseType type, string horribleDatabaseName, string horribleTableName,string columnName) { - + var database = GetTestDatabase(type); //ExpectDatabase with illegal name @@ -812,7 +812,7 @@ public void UnsupportedEntityNames(DatabaseType type, string horribleDatabaseNam "Table .* contained unsupported .* characters", Assert.Throws(()=>database.ExpectTable(horribleTableName)) ?.Message); - + //CreateTable with illegal name StringAssert.IsMatch( "Table .* contained unsupported .* characters", @@ -832,7 +832,7 @@ public void UnsupportedEntityNames(DatabaseType type, string horribleDatabaseNam ?.Message); AssertCanCreateDatabases(); - + //CreateDatabase with illegal name StringAssert.IsMatch( "Database .* contained unsupported .* characters", @@ -937,7 +937,7 @@ public void CreateTable_DefaultTest_Date(DatabaseType type) } }); DateTime currentValue; - + using (var insert = tbl.BeginBulkInsert()) { using var dt = new DataTable(); @@ -951,7 +951,7 @@ public void CreateTable_DefaultTest_Date(DatabaseType type) var dt2 = tbl.GetDataTable(); var databaseValue = (DateTime)dt2.Rows.Cast().Single()["myDt"]; - + Assert.AreEqual(currentValue.Year,databaseValue.Year); Assert.AreEqual(currentValue.Month, databaseValue.Month); Assert.AreEqual(currentValue.Day, databaseValue.Day); @@ -1002,7 +1002,7 @@ public void CreateTable_DefaultTest_Guid(DatabaseType type) var dt2 = tbl.GetDataTable(); var databaseValue = (string)dt2.Rows.Cast().Single()["MyGuid"]; - + Assert.IsNotNull(databaseValue); TestContext.WriteLine(databaseValue); } diff --git a/Tests/FAnsiTests/DatabaseTests.cs b/Tests/FAnsiTests/DatabaseTests.cs index 9a64b81d..6c3b6754 100644 --- a/Tests/FAnsiTests/DatabaseTests.cs +++ b/Tests/FAnsiTests/DatabaseTests.cs @@ -76,7 +76,7 @@ public void CheckFiles() TestContext.WriteLine(exception); throw; } - + } protected IEnumerable TestServer() diff --git a/Tests/FAnsiTests/FAnsiTests.csproj b/Tests/FAnsiTests/FAnsiTests.csproj index 320bc73e..19befb56 100644 --- a/Tests/FAnsiTests/FAnsiTests.csproj +++ b/Tests/FAnsiTests/FAnsiTests.csproj @@ -10,10 +10,10 @@ - + - - + + diff --git a/Tests/FAnsiTests/ManagedConnectionTests.cs b/Tests/FAnsiTests/ManagedConnectionTests.cs index cfb5bbc8..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,7 +74,7 @@ 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()) @@ -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); } diff --git a/Tests/FAnsiTests/Table/TopXTests.cs b/Tests/FAnsiTests/Table/TopXTests.cs index bf1a6152..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"); diff --git a/Tests/FAnsiTests/Table/UpdateTests.cs b/Tests/FAnsiTests/Table/UpdateTests.cs index 124c54bb..658d44a7 100644 --- a/Tests/FAnsiTests/Table/UpdateTests.cs +++ b/Tests/FAnsiTests/Table/UpdateTests.cs @@ -43,7 +43,7 @@ public void Test_UpdateTableFromJoin(DatabaseType dbType) var syntaxHelper = db.Server.GetQuerySyntaxHelper(); var updateHelper = syntaxHelper.UpdateHelper; - + var queryLines = new List(); var highScore = syntaxHelper.EnsureWrapped("HighScore"); diff --git a/Tests/FAnsiTests/TypeTranslation/TypeTranslaterTests.cs b/Tests/FAnsiTests/TypeTranslation/TypeTranslaterTests.cs index 4225f1e1..5dbde895 100644 --- a/Tests/FAnsiTests/TypeTranslation/TypeTranslaterTests.cs +++ b/Tests/FAnsiTests/TypeTranslation/TypeTranslaterTests.cs @@ -250,7 +250,7 @@ private void RunKnownTypeTest(DatabaseType type, string sqlType, Type expectedTy finally { tbl.Drop(); - } + } } //Data types not supported by FAnsi