Skip to content

Commit 126ef4d

Browse files
authored
Merge pull request #321 from servicetitan/mergeUpstream
Merge upstream
2 parents e2da26e + 7b11fce commit 126ef4d

File tree

47 files changed

+4839
-851
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4839
-851
lines changed

ChangeLog/6.0.14_Z_Final.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[main] Addressed issue of not visiting grouping expression correctly which appeared in previous version
2+
[main] Addressed certain issues of incorrect query optimization when it contains multiple In() calls
3+
[main] In addition to previous version, more cases of incorrect join type usage addressed
4+
[firebird] Updated client library package to version 6.7.0
5+
[mysql] Updated client library package to version 6.10.9
6+
[oracle] Updated client library package to version 2.18.151
7+
[postgresql] Updated Npgsql package to version 4.0.17 which patches some vulnerablity issues
8+
[sqlserver] Updated client library package to version 4.8.6
9+
[sqlite] Updated client library package to version 1.0.119

ChangeLog/7.0.6_Z_Final.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[main] Addressed issue of not visiting grouping expression correctly which appeared in previous version
2+
[mysql] Updated client library package to version 8.0.31
3+
[postgresql] Updated client library package to version 4.1.14

ChangeLog/7.1.3_Z_Final.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[main] Addressed race condition issue with TranslatorState.NonVisitableExpressions
2+
[main] Improved working with nullable enum constants in queries
3+
[main] Improved compatibility of .ToListAsync/.ToArrayAsync/.ToHashSetAsync/.AsAsyncEnumerable extension methods with EntitySet
4+
[postgresql] Improved database structucture extraction
5+
[postgresql] Addressed certain cases of decimal results of aggregate operations being unable to fit to .NET decimal

Directory.Build.props

+2-17
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
<DoIsIdeBuild>false</DoIsIdeBuild>
3838
<DoIsIdeBuild Condition="$(BuildingInsideVisualStudio) == 'true'">true</DoIsIdeBuild>
3939

40+
<TargetFramework>net8.0</TargetFramework>
41+
4042
<!-- Disable "BinaryFormatter is obsolete" warnings for test projects -->
4143
<NoWarn>$(NoWarn);CS0618;CS0672;CS1570;CS1572;CS1573;CS1574;CS1587;CS1734;NU1901;NU1902;NU1903;NU1904;SYSLIB0050;SYSLIB0051;</NoWarn>
4244
<NoWarn Condition="$(MSBuildProjectName.Contains('Tests')) == 'true'">$(NoWarn);SYSLIB0011</NoWarn>
@@ -46,23 +48,6 @@
4648
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4749
</PropertyGroup>
4850

49-
<!-- Debug-NET8, Release-NET8 are mostly for development convenience -->
50-
<PropertyGroup Condition = "$(Configuration.Contains('NET8')) == 'true'">
51-
<!-- hard binding to net8, no property and env variable allowed-->
52-
<TargetFrameworks>net8.0</TargetFrameworks>
53-
</PropertyGroup>
54-
55-
<!-- Debug-NET7, Release-NET7 are mostly for development convenience -->
56-
<PropertyGroup Condition = "$(Configuration.Contains('NET7')) == 'true'">
57-
<!-- hard binding to net7, no property and env variable allowed-->
58-
<TargetFrameworks>net7.0</TargetFrameworks>
59-
</PropertyGroup>
60-
61-
<!-- Debug-NET6, Release-NET6 are mostly for development convenience -->
62-
<PropertyGroup Condition = "$(Configuration.Contains('NET6')) == 'true'">
63-
<!-- hard binding to net6, no property and env variable allowed -->
64-
<TargetFrameworks>net6.0</TargetFrameworks>
65-
</PropertyGroup>
6651

6752
<!--Release and Debug are for final builds, builds on build server, etc. Target frameworks are configurable here -->
6853
<PropertyGroup Label="Defaults"

Directory.Packages.props

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
<ItemGroup Label="Nupkg Versions">
77
<PackageVersion Include="System.CodeDom" Version="$(MSExtVersion)" />
88
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="$(MSExtVersion)" />
9-
9+
<PackageVersion Include="System.Xml.XPath.XmlDocument" Version="4.7.0" />
1010
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="$(MSExtVersion)" />
1111
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="$(MSExtVersion)" />
1212
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="$(MSExtVersion)" />
1313
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="$(MSExtVersion)" />
1414
<PackageVersion Include="Microsoft.Extensions.Configuration.Xml" Version="$(MSExtVersion)" />
15-
<PackageVersion Include="System.Data.SQLite.Core" Version="1.0.109.2" />
15+
<PackageVersion Include="System.Data.SQLite.Core" Version="1.0.119" />
1616
<PackageVersion Include="System.Dynamic.Runtime" Version="4.3.0" />
1717
<PackageVersion Include="System.Spatial" Version="5.8.5" />
1818
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
@@ -29,11 +29,11 @@
2929
<PackageVersion Include="Google.Protobuf" Version="3.28.3" />
3030
<PackageVersion Include="log4net" Version="2.0.10" />
3131
<PackageVersion Include="Mono.Cecil" Version="0.11.6" />
32-
<PackageVersion Include="MySql.Data" Version="8.0.30" />
32+
<PackageVersion Include="MySql.Data" Version="8.0.31" />
3333
<PackageVersion Include="NLog" Version="4.5.0" />
3434
<PackageVersion Include="Npgsql" Version="8.0.3" />
3535
<PackageVersion Include="NUnit" Version="3.14.0" />
3636
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
37-
<PackageVersion Include="Oracle.ManagedDataAccess.Core" Version="2.18.3" />
37+
<PackageVersion Include="Oracle.ManagedDataAccess.Core" Version="2.18.151" />
3838
</ItemGroup>
3939
</Project>

Orm/Xtensive.Orm.Manual/DomainAndSession/DomainAndSessionSample.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class DomainAndSessionSample : HasConfigurationAccessTest
4646
public const string OracleUrl1 = @"oracle://user:password@localhost/MyDatabase";
4747
public const string OracleUrl2 = @"oracle://user:password@dbServer:5511/MyDatabase";
4848
public const string PostrgeSqlUrl1 = @"postgresql://user:[email protected]:8032/MyDatabase?Encoding=Unicode";
49-
public const string PostrgeSqlUrl2 = @"postgresql://user:password@dbServer/MyDatabase?Pooling=on&MinPoolSize=1&MaxPoolSize=5";
49+
public const string PostrgeSqlUrl2 = @"postgresql://user:password@dbServer/MyDatabase?Pooling=True&MinPoolSize=1&MaxPoolSize=5";
5050
public const string InMemoryUrl = @"memory://localhost/MyDatabase";
5151

5252
#endregion

Orm/Xtensive.Orm.MySql/Xtensive.Orm.MySql.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<IsPackable>true</IsPackable>
44
<DocumentationFile>$(OutputPath)$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
@@ -41,6 +41,7 @@
4141
<ItemGroup>
4242
<PackageReference Include="Google.Protobuf" />
4343
<PackageReference Include="MySql.Data" />
44+
<PackageReference Include="System.Xml.XPath.XmlDocument" />
4445
</ItemGroup>
4546
<ItemGroup>
4647
<Compile Update="Sql.Drivers.MySql\Resources\Strings.Designer.cs">

Orm/Xtensive.Orm.PostgreSql/Orm.Providers.PostgreSql/SqlCompiler.cs

+75-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// Created by: Denis Krjuchkov
55
// Created: 2009.04.27
66

7+
using System;
78
using System.Collections.Generic;
89
using System.Linq;
910
using Xtensive.Core;
@@ -18,6 +19,8 @@ namespace Xtensive.Orm.Providers.PostgreSql
1819
{
1920
internal class SqlCompiler : Providers.SqlCompiler
2021
{
22+
private const int MaxDotnetDecimalPrecision = 28;
23+
2124
protected override SqlProvider VisitFreeText(FreeTextProvider provider)
2225
{
2326
var rankColumnName = provider.Header.Columns[provider.Header.Columns.Count - 1].Name;
@@ -55,13 +58,83 @@ protected override SqlProvider VisitFreeText(FreeTextProvider provider)
5558
protected override SqlExpression ProcessAggregate(SqlProvider source, IReadOnlyList<SqlExpression> sourceColumns, AggregateColumn aggregateColumn)
5659
{
5760
var result = base.ProcessAggregate(source, sourceColumns, aggregateColumn);
58-
if (aggregateColumn.AggregateType == AggregateType.Sum || aggregateColumn.AggregateType == AggregateType.Avg) {
61+
var aggregateType = aggregateColumn.AggregateType;
62+
var originCalculateColumn = source.Origin.Header.Columns[aggregateColumn.SourceIndex];
63+
if (AggregateRequiresDecimalAdjustments(aggregateColumn)) {
64+
if (!IsCalculatedColumn(originCalculateColumn)) {
65+
// this is aggregate by one column, result will be defined by the precision and scale of the column
66+
return result;
67+
}
68+
69+
// For expressions we had to try to guess result type parameters to avoid overflow exception
70+
// on reading something like 12.000000000000000000000000000000 (30 zeros) which in practice can be reduced
71+
// to 12.0 on reading but Npgsql does not allow us neither to turn on such conversion inside Npgsql (as it was in v3.x.x) nor
72+
// to get raw data and make conversion by ourselves (because nothing similar to SqlDecimal has provided by the library).
73+
74+
// Official answer of the Npgsql team is to either cast to DECIMAL with proper parameters or read all parameters as
75+
// strings and then convert :-)
76+
// Reading strings is not an option so we try to tell fortunes in a teacup :-(
77+
var resultType = (!TryAdjustPrecisionScale(aggregateColumn.Descriptor.DecimalParametersHint, aggregateType, out var newPrecision, out var newScale))
78+
? Driver.MapValueType(aggregateColumn.Type)
79+
: Driver.MapValueType(aggregateColumn.Type, null, newPrecision, newScale);
80+
return SqlDml.Cast(result, resultType);
81+
}
82+
else if (aggregateType != AggregateType.Count) {
5983
result = SqlDml.Cast(result, Driver.MapValueType(aggregateColumn.Type));
6084
}
61-
6285
return result;
6386
}
6487

88+
private bool AggregateRequiresDecimalAdjustments(AggregateColumn aggregateColumn)
89+
{
90+
var aggregateType = aggregateColumn.AggregateType;
91+
return (aggregateType is AggregateType.Sum or AggregateType.Avg
92+
or AggregateType.Min or AggregateType.Min) && aggregateColumn.Type == WellKnownTypes.DecimalType;
93+
}
94+
95+
private bool TryAdjustPrecisionScale(
96+
in (int precision, int scale)? typeHint,
97+
in AggregateType aggregateType,
98+
out int precision, out int scale)
99+
{
100+
if (!typeHint.HasValue) {
101+
precision = -1;
102+
scale = -1;
103+
return false;
104+
}
105+
var typeHintValue = typeHint.Value;
106+
107+
if (typeHintValue.precision == MaxDotnetDecimalPrecision) {
108+
// No room for adjust, otherwise we'll lose floor part data
109+
precision = typeHintValue.precision;
110+
scale = typeHintValue.scale;
111+
return true;
112+
}
113+
114+
// choose max available precision for .net or let it be the one user declared
115+
precision = (typeHintValue.precision < 28) ? 28 : typeHintValue.precision;
116+
117+
// It is benefitial to increase scale but for how much? It is open question,
118+
// sometimes we need bigger floor part, and sometimes bigger fractional part.
119+
// This algorithm is a trade-off.
120+
scale = aggregateType switch {
121+
AggregateType.Avg =>
122+
(typeHintValue.precision < MaxDotnetDecimalPrecision)
123+
? typeHintValue.scale + Math.Max((precision - typeHintValue.precision) / 2, 1)
124+
: typeHintValue.scale + 1,
125+
AggregateType.Sum or
126+
AggregateType.Min or
127+
AggregateType.Max =>
128+
(typeHintValue.precision < MaxDotnetDecimalPrecision - 1)
129+
? typeHintValue.scale + 2
130+
: typeHintValue.scale + 1,
131+
_ => typeHintValue.scale,
132+
};
133+
return true;
134+
}
135+
136+
private bool IsCalculatedColumn(Column column) => column is CalculatedColumn;
137+
65138
public SqlCompiler(HandlerAccessor handlers, in CompilerConfiguration configuration)
66139
: base(handlers, configuration)
67140
{

Orm/Xtensive.Orm.PostgreSql/Sql.Drivers.PostgreSql/DriverFactory.cs

+9-13
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,15 @@ private static SqlDriver CreateDriverInstance(
110110

111111
// We support 8.3, 8.4 and any 9.0+
112112

113-
if (version.Major == 8) {
114-
return version.Minor == 3 ? new v8_3.Driver(coreServerInfo) : new v8_4.Driver(coreServerInfo);
115-
}
116-
117-
if (version.Major == 9) {
118-
return version.Minor == 0 ? new v9_0.Driver(coreServerInfo) : new v9_1.Driver(coreServerInfo);
119-
}
120-
121-
if (version.Major < 12) {
122-
return new v10_0.Driver(coreServerInfo);
123-
}
124-
125-
return new v12_0.Driver(coreServerInfo);
113+
return version.Major switch {
114+
8 when version.Minor == 3 => new v8_3.Driver(coreServerInfo),
115+
8 when version.Minor > 3 => new v8_4.Driver(coreServerInfo),
116+
9 when version.Minor == 0 => new v9_0.Driver(coreServerInfo),
117+
9 when version.Minor > 0 => new v9_1.Driver(coreServerInfo),
118+
10 => new v10_0.Driver(coreServerInfo),
119+
11 => new v10_0.Driver(coreServerInfo),
120+
_ => new v12_0.Driver(coreServerInfo)
121+
};
126122
}
127123

128124
/// <inheritdoc/>

Orm/Xtensive.Orm.PostgreSql/Sql.Drivers.PostgreSql/Resources/Strings.Designer.cs

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Orm/Xtensive.Orm.PostgreSql/Sql.Drivers.PostgreSql/Resources/Strings.resx

+3
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,7 @@
135135
<data name="ExSchemaXDoesNotExistOrBelongsToAnotherUser" xml:space="preserve">
136136
<value>Schema '{0}' either does not exist or belongs to another user.</value>
137137
</data>
138+
<data name="ExCantFindSchemaXOwnerWithIdYInTheListOfRoles" xml:space="preserve">
139+
<value>Can't find schema '{0}' owner with oid '{1}' in the list of roles.</value>
140+
</data>
138141
</root>

0 commit comments

Comments
 (0)