Skip to content

Commit cc0286d

Browse files
committed
Merge branch '6.0' into 6.0-test-fixes
2 parents 4941021 + 0973687 commit cc0286d

7 files changed

Lines changed: 510 additions & 258 deletions

File tree

Orm/Xtensive.Orm.PostgreSql/Sql.Drivers.PostgreSql/v10_0/ServerInfoProvider.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1-
// Copyright (C) 2019-2020 Xtensive LLC.
1+
// Copyright (C) 2019-2021 Xtensive LLC.
22
// This code is distributed under MIT license terms.
33
// See the License.txt file in the project root for more information.
44
// Created by: Alexey Kulakov
55
// Created: 2019.09.25
66

7+
using Xtensive.Sql.Info;
8+
79
namespace Xtensive.Sql.Drivers.PostgreSql.v10_0
810
{
911
internal class ServerInfoProvider : v9_0.ServerInfoProvider
1012
{
13+
public override QueryInfo GetQueryInfo()
14+
{
15+
var info = base.GetQueryInfo();
16+
info.Features |= QueryFeatures.CrossApply;
17+
return info;
18+
}
19+
1120
// Constructors
1221

1322
public ServerInfoProvider(SqlDriver driver)

Orm/Xtensive.Orm.PostgreSql/Sql.Drivers.PostgreSql/v10_0/Translator.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,46 @@
1-
// Copyright (C) 2019-2020 Xtensive LLC.
1+
// Copyright (C) 2019-2021 Xtensive LLC.
22
// This code is distributed under MIT license terms.
33
// See the License.txt file in the project root for more information.
44
// Created by: Alexey Kulakov
55
// Created: 2019.09.25
66

7+
using System;
8+
using Xtensive.Sql.Compiler;
9+
using Xtensive.Sql.Dml;
10+
711
namespace Xtensive.Sql.Drivers.PostgreSql.v10_0
812
{
913
internal class Translator : v9_1.Translator
1014
{
15+
public override string Translate(SqlCompilerContext context, SqlJoinExpression node, JoinSection section)
16+
{
17+
switch (section) {
18+
case JoinSection.Specification: {
19+
if (node.Expression == null) {
20+
switch (node.JoinType) {
21+
case SqlJoinType.InnerJoin:
22+
case SqlJoinType.LeftOuterJoin:
23+
case SqlJoinType.RightOuterJoin:
24+
case SqlJoinType.FullOuterJoin:
25+
throw new NotSupportedException();
26+
case SqlJoinType.CrossApply:
27+
return "CROSS JOIN LATERAL";
28+
case SqlJoinType.LeftOuterApply:
29+
return "LEFT JOIN LATERAL";
30+
}
31+
}
32+
return Translate(node.JoinType) + " JOIN";
33+
}
34+
case JoinSection.Exit: {
35+
if (node.JoinType == SqlJoinType.LeftOuterApply) {
36+
return "ON TRUE";
37+
}
38+
return string.Empty;
39+
}
40+
}
41+
return base.Translate(context, node, section);
42+
}
43+
1144
// Constructors
1245

1346
public Translator(SqlDriver driver)
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
// Copyright (C) 2020-2021 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Text;
8+
using NUnit.Framework;
9+
using Xtensive.Orm.Configuration;
10+
using Xtensive.Orm.Model;
11+
using Xtensive.Orm.Services;
12+
using Xtensive.Orm.Tests.Issues.IssueGitHub0132_IncorrectInsertForSingleTableHierarchyModel;
13+
14+
namespace Xtensive.Orm.Tests.Issues.IssueGitHub0132_IncorrectInsertForSingleTableHierarchyModel
15+
{
16+
[HierarchyRoot(InheritanceSchema.SingleTable)]
17+
public class A : Entity
18+
{
19+
[Field, Key]
20+
public int Id { get; private set; }
21+
22+
[Field]
23+
public string Name { get; set; }
24+
25+
public A(Session session)
26+
: base(session)
27+
{
28+
}
29+
}
30+
31+
public class B1 : A
32+
{
33+
[Field]
34+
public EntitySet<C> ConflictingField { get; set; }
35+
36+
public B1(Session session)
37+
: base(session)
38+
{
39+
}
40+
}
41+
42+
public class B2 : A
43+
{
44+
[Field]
45+
public double ConflictingField { get; set; }
46+
47+
public B2(Session session)
48+
: base(session)
49+
{
50+
}
51+
}
52+
53+
[HierarchyRoot]
54+
public class C : Entity
55+
{
56+
[Field, Key]
57+
public int Id { get; private set; }
58+
59+
[Field]
60+
[Association(PairTo = nameof(B1.ConflictingField))]
61+
public B1 Ref { get; set; }
62+
63+
public C(Session session)
64+
: base(session)
65+
{
66+
}
67+
}
68+
}
69+
70+
namespace Xtensive.Orm.Tests.Issues
71+
{
72+
public class IssueGitHub0132_IncorrectInsertForSingleTableHierarchy : AutoBuildTest
73+
{
74+
protected override DomainConfiguration BuildConfiguration()
75+
{
76+
var config = base.BuildConfiguration();
77+
config.Types.Register(typeof(A).Assembly, typeof(A).Namespace);
78+
return config;
79+
}
80+
81+
[Test]
82+
public void WriteToWrongColumnTest()
83+
{
84+
using (var session = Domain.OpenSession())
85+
using (var tx = session.OpenTransaction()) {
86+
var aId = new A(session) { Name = "AName" }.Id;
87+
var b = new B1(session) { Name = "B1Name" };
88+
_ = b.ConflictingField.Add(new C(session));
89+
var b1Id = b.Id;
90+
var b2Id = new B2(session) { Name = "B2Name", ConflictingField = 5.0 }.Id;
91+
Assert.DoesNotThrow(session.SaveChanges);
92+
var accessor = session.Services.Get<DirectSqlAccessor>();
93+
using (var command = accessor.CreateCommand()) {
94+
command.CommandText = GetCommandText(session);
95+
using (var reader = command.ExecuteReader()) {
96+
while (reader.Read()) {
97+
var id = reader.GetInt32(0);
98+
var conflictingField = reader.GetDouble(1);
99+
if (id != b2Id) {
100+
Assert.That(conflictingField, Is.EqualTo(0.0));
101+
}
102+
else {
103+
Assert.That(conflictingField, Is.EqualTo(5.0));
104+
}
105+
}
106+
}
107+
}
108+
}
109+
}
110+
111+
private string GetCommandText(Session session)
112+
{
113+
var typeInfo = Domain.Model.Types[typeof(A)];
114+
var table = session.StorageNode.Mapping[typeInfo];
115+
116+
var tableRef = Sql.SqlDml.TableRef(table);
117+
var select = Sql.SqlDml.Select(tableRef);
118+
select.Columns.Add(tableRef[nameof(A.Id)]);
119+
select.Columns.Add(tableRef[nameof(B2.ConflictingField)]);
120+
121+
var queryBuilder = session.Services.Get<QueryBuilder>();
122+
123+
var compileResult = queryBuilder.CompileQuery(select);
124+
return compileResult.GetCommandText();
125+
}
126+
}
127+
}

0 commit comments

Comments
 (0)