Skip to content

Commit 841468b

Browse files
committed
Merge branch '7.1'
# Conflicts: # Orm/Xtensive.Orm/Tuples/Packed/TupleLayout.cs # Version.props
2 parents d46d04b + 7539eb9 commit 841468b

File tree

45 files changed

+4841
-802
lines changed

Some content is hidden

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

45 files changed

+4841
-802
lines changed

ChangeLog/6.0.14_Z_Final.txt

Lines changed: 9 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 3 deletions
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>
@@ -39,8 +39,7 @@
3939
</EmbeddedResource>
4040
</ItemGroup>
4141
<ItemGroup>
42-
<PackageReference Include="Google.Protobuf" Version="3.19.4" />
43-
<PackageReference Include="MySql.Data" Version="8.0.30" />
42+
<PackageReference Include="MySql.Data" Version="8.0.31" />
4443
<PackageReference Include="System.Xml.XPath.XmlDocument" Version="4.3.0" />
4544
</ItemGroup>
4645
<ItemGroup>

Orm/Xtensive.Orm.Oracle/Xtensive.Orm.Oracle.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
</Content>
2626
</ItemGroup>
2727
<ItemGroup>
28-
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="2.18.3" />
28+
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="2.18.151" />
2929
</ItemGroup>
3030
<ItemGroup>
3131
<ProjectReference Include="..\Xtensive.Orm\Xtensive.Orm.csproj" />

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

Lines changed: 75 additions & 2 deletions
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, List<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, CompilerConfiguration configuration)
66139
: base(handlers, configuration)
67140
{

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,15 @@ private static SqlDriver CreateDriverInstance(
111111

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

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

129125
/// <inheritdoc/>

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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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)