Skip to content

Commit

Permalink
Changes for v4.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarris committed Oct 6, 2022
1 parent 0df4313 commit 326db16
Show file tree
Hide file tree
Showing 16 changed files with 169 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Build/linq2db.Default.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Version>4.2.0</Version>
<Version>4.3.0</Version>

<Description>LINQ to DB is a data access technology that provides a run-time infrastructure for managing relational data as objects. This package is a provider for DB2 on the IBM iSeries.</Description>
<Authors>Roy Chase, Nikos Sarris</Authors>
Expand Down
10 changes: 5 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
-->
<ItemGroup>
<!--as stated in issue 1 - packages in this item group shouldn't be duplicated in other groups-->
<PackageVersion Include="linq2db" Version="4.2.0" />
<PackageVersion Include="linq2db.Tools" Version="4.2.0" />
<PackageVersion Include="linq2db.AspNet" Version="4.2.0" />
<PackageVersion Include="linq2db.Remote.Grpc" Version="4.2.0" />
<PackageVersion Include="linq2db.Remote.Wcf" Version="4.2.0" />
<PackageVersion Include="linq2db" Version="4.3.0" />
<PackageVersion Include="linq2db.Tools" Version="4.3.0" />
<PackageVersion Include="linq2db.AspNet" Version="4.3.0" />
<PackageVersion Include="linq2db.Remote.Grpc" Version="4.3.0" />
<PackageVersion Include="linq2db.Remote.Wcf" Version="4.3.0" />
<PackageVersion Include="JetBrains.Annotations" Version="2022.1.0" />
<!--generic packages for source projects-->
<!--generic packages for source projects-->
Expand Down
36 changes: 25 additions & 11 deletions Source/ISeriesProvider/DB2iSeriesMetadataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace LinqToDB.DataProvider.DB2iSeries
{
using LinqToDB.DataProvider.DB2;
using LinqToDB.SqlProvider;
using SqlQuery;
using System.CodeDom;
using System.Collections.Concurrent;
Expand Down Expand Up @@ -94,8 +96,8 @@ private T[] GetExpressionAttributes<T>(Type type, MemberInfo memberInfo, bool in
case "StringAggregate" when memberInfo is MethodInfo stringAggregateMethod:
var firstParameter = stringAggregateMethod.GetParameters().Any(x => x.Name == "selector") ? "selector" : "source";
return GetExtension<T>(() => new Sql.ExtensionAttribute(providerName, "LISTAGG({" + firstParameter + "}, {separator}){_}{aggregation_ordering?}") { IsAggregate = true, ChainPrecedence = 10 });
//case "Decimal":
// break;
//case "Decimal":
// break;
}

return EmptyArray<T>.Value;
Expand Down Expand Up @@ -240,7 +242,7 @@ public class TrimBuilderDB2i : Sql.IExtensionCallBuilder
{
public void Build(Sql.ISqExtensionBuilder builder)
{
var text = builder.GetExpression(0);
var stringExpression = builder.GetExpression(0);
var charExpression = builder.GetExpression(1);

char[] chars;
Expand Down Expand Up @@ -270,17 +272,29 @@ public void Build(Sql.ISqExtensionBuilder builder)

var direction = builder.Member.Name switch
{
nameof(Linq.Expressions.TrimLeft) => 'L',
nameof(Linq.Expressions.TrimRight) => 'T',
_ => 'B',
nameof(Linq.Expressions.TrimLeft) => "LTRIM",
nameof(Linq.Expressions.TrimRight) => "RTRIM",
_ => "TRIM",
};

var sqlExpression =
chars.Length == 0 ?
$"Strip({{0}}, {direction})" :
chars.Skip(1).Aggregate($"Strip({{0}}, {direction}, '{chars[0]}')", (acc, cur) => $"Strip({acc}, {direction} , '{cur}')");
if (chars == null || chars.Length == 0)
{
builder.ResultExpression = new SqlFunction(
typeof(string),
direction,
stringExpression);
return;
}

if (!builder.DataContext.SqlProviderFlags.CustomFlags.Contains(Constants.ProviderFlags.SupportsTrimCharacters))
throw new LinqToDBException("TrimLeft/TrimRight with multiple characters not supported on i series version 7.1");

builder.ResultExpression = new SqlExpression(sqlExpression, text);
builder.ResultExpression = new SqlExpression(
typeof(string),
direction + "({0}, {1})",
Precedence.Primary,
stringExpression,
new SqlExpression(typeof(string), "{0}", new SqlValue(new string(chars))));
}
}
}
2 changes: 2 additions & 0 deletions Source/ISeriesProvider/DB2iSeriesProviderOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public DB2iSeriesProviderOptions(string providerName, DB2iSeriesProviderType pro
SupportsNCharTypes = version >= DB2iSeriesVersion.V7_1;
SupportsDropIfExists = version >= DB2iSeriesVersion.V7_4;
SupportsArbitraryTimeStampPrecision = version >= DB2iSeriesVersion.V7_2;
SupportsTrimCharacters = version >= DB2iSeriesVersion.V7_2;
}

public DB2iSeriesProviderOptions()
Expand All @@ -46,6 +47,7 @@ public DB2iSeriesProviderOptions()
public bool SupportsNCharTypes { get; set; }
public bool SupportsDropIfExists { get; set; }
public bool SupportsArbitraryTimeStampPrecision { get; set; }
public bool SupportsTrimCharacters { get; set; }
public bool MapGuidAsString { get; set; }
}
}
16 changes: 11 additions & 5 deletions Source/ISeriesProvider/DB2iSeriesSqlProviderFlags.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace LinqToDB.DataProvider.DB2iSeries
{
using LinqToDB.Tools;
using SqlProvider;

public class DB2iSeriesSqlProviderFlags
Expand All @@ -12,7 +11,8 @@ public DB2iSeriesSqlProviderFlags(
bool supportsMergeStatement,
bool supportsNCharTypes,
bool supportsDropTableIfExists,
bool supportsArbitraryTimeStampPrecision)
bool supportsArbitraryTimeStampPrecision,
bool suppotsTrimCharacters)
{
SupportsOffsetClause = supportsOffsetClause;
SupportsTruncateTable = supportsTruncateTable;
Expand All @@ -21,6 +21,7 @@ public DB2iSeriesSqlProviderFlags(
SupportsNCharTypes = supportsNCharTypes;
SupportsDropTableIfExists = supportsDropTableIfExists;
SupportsArbitraryTimeStampPrecision = supportsArbitraryTimeStampPrecision;
SupportsTrimCharacters = suppotsTrimCharacters;
}

public DB2iSeriesSqlProviderFlags(SqlProviderFlags sqlProviderFlags)
Expand All @@ -31,7 +32,8 @@ public DB2iSeriesSqlProviderFlags(SqlProviderFlags sqlProviderFlags)
supportsMergeStatement: sqlProviderFlags.CustomFlags.Contains(Constants.ProviderFlags.SupportsMergeStatement),
supportsNCharTypes: sqlProviderFlags.CustomFlags.Contains(Constants.ProviderFlags.SupportsNCharTypes),
supportsDropTableIfExists: sqlProviderFlags.CustomFlags.Contains(Constants.ProviderFlags.SupportsDropTableIfExists),
supportsArbitraryTimeStampPrecision: sqlProviderFlags.CustomFlags.Contains(Constants.ProviderFlags.SupportsArbitraryTimeStampPrecision))
supportsArbitraryTimeStampPrecision: sqlProviderFlags.CustomFlags.Contains(Constants.ProviderFlags.SupportsArbitraryTimeStampPrecision),
suppotsTrimCharacters: sqlProviderFlags.CustomFlags.Contains(Constants.ProviderFlags.SupportsTrimCharacters))
{

}
Expand All @@ -44,7 +46,8 @@ public DB2iSeriesSqlProviderFlags(DB2iSeriesProviderOptions options)
supportsMergeStatement: options.SupportsMergeStatement,
supportsNCharTypes: options.SupportsNCharTypes,
supportsDropTableIfExists: options.SupportsDropIfExists,
supportsArbitraryTimeStampPrecision: options.SupportsArbitraryTimeStampPrecision)
supportsArbitraryTimeStampPrecision: options.SupportsArbitraryTimeStampPrecision,
suppotsTrimCharacters: options.SupportsTrimCharacters)
{

}
Expand All @@ -59,7 +62,8 @@ public DB2iSeriesSqlProviderFlags(
supportsMergeStatement: version >= DB2iSeriesVersion.V7_1,
supportsNCharTypes: version >= DB2iSeriesVersion.V7_1,
supportsDropTableIfExists: version >= DB2iSeriesVersion.V7_4,
supportsArbitraryTimeStampPrecision: version >= DB2iSeriesVersion.V7_2
supportsArbitraryTimeStampPrecision: version >= DB2iSeriesVersion.V7_2,
suppotsTrimCharacters: version >= DB2iSeriesVersion.V7_2
)
{

Expand All @@ -72,6 +76,7 @@ public DB2iSeriesSqlProviderFlags(
public bool SupportsNCharTypes { get; }
public bool SupportsDropTableIfExists { get; }
public bool SupportsArbitraryTimeStampPrecision { get; }
public bool SupportsTrimCharacters { get; }

public void SetCustomFlags(SqlProviderFlags sqlProviderFlags)
{
Expand All @@ -82,6 +87,7 @@ public void SetCustomFlags(SqlProviderFlags sqlProviderFlags)
sqlProviderFlags.SetFlag(Constants.ProviderFlags.SupportsNCharTypes, SupportsNCharTypes);
sqlProviderFlags.SetFlag(Constants.ProviderFlags.SupportsDropTableIfExists, SupportsDropTableIfExists);
sqlProviderFlags.SetFlag(Constants.ProviderFlags.SupportsArbitraryTimeStampPrecision, SupportsArbitraryTimeStampPrecision);
sqlProviderFlags.SetFlag(Constants.ProviderFlags.SupportsTrimCharacters, SupportsTrimCharacters);
}
}
}
1 change: 1 addition & 0 deletions Source/ISeriesProvider/Internal/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static class ProviderFlags
public const string SupportsNCharTypes = "SupportsNCharTypes";
public const string SupportsDropTableIfExists = "SupportsDropTableIfExists";
public const string SupportsArbitraryTimeStampPrecision = "SupportsArbitraryTimeStampPrecision";
public const string SupportsTrimCharacters = "SupportsTrimCharacters";
}

public static class DbTypes
Expand Down
4 changes: 2 additions & 2 deletions Tests How-to.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

- How to maintain the tests from upstream

The test have been set up in a way that tests from upstream can be simply copied over. You have to copy only the source code files and not the project files as follows:
The tests have been set up in a way that tests from upstream can be simply copied over. You have to copy only the source code files and not the project files as follows:

- Copy all code (e.g. exlude \bin, \obj and .csproj file) from :
Tests\Base (except CustomizationSupport folder)
Tests\Linq (apply customization changes to the TestsInitialization.cs make class partial and InitCustom() invocation in Initialize())
Tests\Linq
Tests\FSharp
Tests\VisualBasic
Tests\Model
Expand Down
5 changes: 5 additions & 0 deletions Tests/Base/CustomizationSupport/CustomizationSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ public static class CustomizationSupport
{
//Replace this instance with a custom implementation to override default behaviour
public static readonly CustomizationSupportInterceptor Interceptor = new Db2iInterceptor();

public static void Init()
{
LinqToDB.DataProvider.DB2iSeries.DB2iSeriesTools.RegisterProviderDetector();
}
}
}
8 changes: 0 additions & 8 deletions Tests/Linq/Custom/TestsInitialization.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Tests/Linq/DataProvider/SybaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public static IEnumerable<StringTestCase> StringTestCases
{
get
{
yield return new StringTestCase("'\u2000\u2001\u2002\u2003\uabab\u03bctесt", "u&'''\\2000\\2001\\2002\\2003\\abab\\03bctесt'", "Test case 1");
yield return new StringTestCase("'\u2000\u2001\u2002\u2003\uabab\u03bctest тест", "u&'''\\2000\\2001\\2002\\2003\\abab\\03bctest тест'", "Test case 1");
// this case fails for parameters, because driver terminates parameter value at \0 character
//yield return Tuple.Create("\0test", "char(0) + 'test'");
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Linq/Linq/ConcatUnionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,9 +1087,9 @@ public void Issue3359_MultipleSetsCombined([DataSources(false)] string context)
db.LastQuery!.Should().Contain("SELECT", Exactly.Times(6));
}

// only pgsql supports all 6 operators right now
// only pgsql and CH support all 6 operators right now
[Test(Description = "Test that we generate sub-queries for incompatible set operators and order queries properly")]
public void Issue3359_MultipleSetsCombined_DifferentOperators([IncludeDataSources(TestProvName.AllPostgreSQL)] string context)
public void Issue3359_MultipleSetsCombined_DifferentOperators([IncludeDataSources(TestProvName.AllPostgreSQL/*, TestProvName.AllClickHouse*/)] string context)
{
using var db = (TestDataConnection)GetDataContext(context);

Expand Down
4 changes: 2 additions & 2 deletions Tests/Linq/Linq/FullTextTests.SqlServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1905,15 +1905,15 @@ public void ContainsByColumns([IncludeDataSources(TestProvName.AllNorthwind)] st
{
var q =
from c in db.Category
where Sql.Ext.SqlServer().Contains("aнанас", c.Description, c.Description)
where Sql.Ext.SqlServer().Contains("ананас", c.Description, c.Description)
orderby c.CategoryID descending
select c;

var results = q.ToList();

Assert.AreEqual(0, results.Count);

Assert.That(db.LastQuery!.Contains("CONTAINS(([c_1].[Description], [c_1].[Description]), N'aнанас')"));
Assert.That(db.LastQuery!.Contains("CONTAINS(([c_1].[Description], [c_1].[Description]), N'ананас')"));
}
}

Expand Down
6 changes: 4 additions & 2 deletions Tests/Linq/TestsInitialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// 2. This class implements test assembly setup/teardown methods.
/// </summary>
[SetUpFixture]
public partial class TestsInitialization
public class TestsInitialization
{
[OneTimeSetUp]
public void TestAssemblySetup()
Expand Down Expand Up @@ -55,7 +55,9 @@ public void TestAssemblySetup()

// uncomment to run FEC for all tests and comment reset line in TestBase.OnAfterTest
//LinqToDB.Common.Compilation.SetExpressionCompiler(_ => FastExpressionCompiler.ExpressionCompiler.CompileFast(_, true));
InitCustom();

//custom initialization logic
CustomizationSupport.Init();
}

// workaround for
Expand Down
20 changes: 14 additions & 6 deletions Tests/Linq/UserTests/Issue3161Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using FluentAssertions;
using LinqToDB;
using LinqToDB.Data;
using LinqToDB.Mapping;
using NUnit.Framework;

Expand Down Expand Up @@ -63,11 +64,12 @@ public void CrossApplyOnce([IncludeDataSources(TestProvName.AllSqlServer2008Plus
.FirstOrDefault()
})
.ToList();
Assert.That(ret.Count, Is.EqualTo(2));

ret.Should().HaveCount(2);
}

[Test]
public void CrossApplyTwice([IncludeDataSources(TestProvName.AllSqlServer2008Plus, TestProvName.AllClickHouse)] string context)
public void CrossApplyTwice([IncludeDataSources(TestProvName.AllSqlServer2008Plus)] string context)
{
using var db = GetDataContext(context);
using var tbl1 = db.CreateLocalTable(new[]
Expand Down Expand Up @@ -112,10 +114,16 @@ public void CrossApplyTwice([IncludeDataSources(TestProvName.AllSqlServer2008Plu
.ToList();
Assert.That(ret.Count, Is.EqualTo(2));

// uncomment after 3161 fixed
//var baselines = GetCurrentBaselines();
//baselines.Should().Contain("SELECT", Exactly.Twice());
//baselines.Should().Contain("SELECT TOP", Exactly.Once());
// validate that the prior statement executed as a single query, not two distinct queries
var baselines = GetCurrentBaselines();
baselines.Should().Contain("SELECT", Exactly.Times(3));
baselines.Should().Contain("SELECT TOP", Exactly.Twice());

// LastQuery will only return a single query, so if it was split into two queries, not all name fields would be present
var lastQuery = ((DataConnection)db).LastQuery;
lastQuery.Should().Contain("NAME1", Exactly.Once());
lastQuery.Should().Contain("NAME2", Exactly.Once());
lastQuery.Should().Contain("NAME3", Exactly.Once());
}
}
}
Loading

0 comments on commit 326db16

Please sign in to comment.