From 224d6d4cdfe72843c81c589fb653f2fe3e040d72 Mon Sep 17 00:00:00 2001 From: "roman.artiukhin" Date: Mon, 2 Jan 2023 09:33:42 +0200 Subject: [PATCH 1/5] test case --- .../NHSpecificTest/GH3215/Entity.cs | 17 ++++++++ .../NHSpecificTest/GH3215/FixtureByCode.cs | 41 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/NHibernate.Test/NHSpecificTest/GH3215/Entity.cs create mode 100644 src/NHibernate.Test/NHSpecificTest/GH3215/FixtureByCode.cs diff --git a/src/NHibernate.Test/NHSpecificTest/GH3215/Entity.cs b/src/NHibernate.Test/NHSpecificTest/GH3215/Entity.cs new file mode 100644 index 00000000000..bd40de89544 --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/GH3215/Entity.cs @@ -0,0 +1,17 @@ +using System; + +namespace NHibernate.Test.NHSpecificTest.GH3215 +{ + class Member + { + public virtual int Code { get; set; } + public virtual string Name { get; set; } + public virtual DateTime Date { get; set; } + } + + class Request + { + public virtual Guid Id { get; set; } + public virtual Member Member { get; set; } + } +} diff --git a/src/NHibernate.Test/NHSpecificTest/GH3215/FixtureByCode.cs b/src/NHibernate.Test/NHSpecificTest/GH3215/FixtureByCode.cs new file mode 100644 index 00000000000..cd58e9d1a68 --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/GH3215/FixtureByCode.cs @@ -0,0 +1,41 @@ +using NHibernate.Cfg.MappingSchema; +using NHibernate.Mapping.ByCode; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.GH3215 +{ + [TestFixture] + public class ByCodeFixture : TestCaseMappingByCode + { + protected override HbmMapping GetMappings() + { + var mapper = new ModelMapper(); + + mapper.Class(rc => + { + rc.Id(x => x.Code); + rc.Property(x => x.Name); + rc.Property(x => x.Date); + }); + + mapper.Class(rc => + { + rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb)); + rc.ManyToOne(x => x.Member); + }); + return mapper.CompileMappingForAllExplicitlyAddedEntities(); + } + + [Test] + public void CountDistinctWithReservedWords() + { + using (var session = OpenSession()) + { + var hql = "select Count(DISTINCT r.Member.id), Count(DISTINCT Date(r.Member.Date)) from Request r"; + var result = session.CreateQuery(hql).List(); + + Assert.That(result, Has.Count.EqualTo(1)); + } + } + } +} From 65f5a61e0f456802eaef0da8bd8e9f815efe0e09 Mon Sep 17 00:00:00 2001 From: "roman.artiukhin" Date: Mon, 2 Jan 2023 09:38:25 +0200 Subject: [PATCH 2/5] Fix count distinct on path with hql reserved words --- src/NHibernate/Hql/Ast/ANTLR/Hql.g | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NHibernate/Hql/Ast/ANTLR/Hql.g b/src/NHibernate/Hql/Ast/ANTLR/Hql.g index 8dcd5dbc533..281e997138f 100644 --- a/src/NHibernate/Hql/Ast/ANTLR/Hql.g +++ b/src/NHibernate/Hql/Ast/ANTLR/Hql.g @@ -600,7 +600,7 @@ vectorExpr // NOTE: handleDotIdent() is called immediately after the first IDENT is recognized because // the method looks a head to find keywords after DOT and turns them into identifiers. identPrimary - : identifier { HandleDotIdent(); } + : identifier {{ HandleDotIdent(); }} ( options {greedy=true;} : DOT^ ( identifier | o=OBJECT { $o.Type = IDENT; } ) )* ( ( op=OPEN^ { $op.Type = METHOD_CALL;} exprList CLOSE! ) )? From 4b7e29b6b5aeb158257ddff07b348cd1b321ab3c Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Mon, 2 Jan 2023 10:30:28 +0200 Subject: [PATCH 3/5] Fix test case for some dialects --- .../NHSpecificTest/GH3215/FixtureByCode.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/NHibernate.Test/NHSpecificTest/GH3215/FixtureByCode.cs b/src/NHibernate.Test/NHSpecificTest/GH3215/FixtureByCode.cs index cd58e9d1a68..8e7d7e435cf 100644 --- a/src/NHibernate.Test/NHSpecificTest/GH3215/FixtureByCode.cs +++ b/src/NHibernate.Test/NHSpecificTest/GH3215/FixtureByCode.cs @@ -1,4 +1,5 @@ -using NHibernate.Cfg.MappingSchema; +using NHibernate.Cfg; +using NHibernate.Cfg.MappingSchema; using NHibernate.Mapping.ByCode; using NUnit.Framework; @@ -25,6 +26,12 @@ protected override HbmMapping GetMappings() }); return mapper.CompileMappingForAllExplicitlyAddedEntities(); } + + protected override void Configure(Configuration configuration) + { + base.Configure(configuration); + configuration.SetProperty(Environment.Hbm2ddlKeyWords, "auto-quote"); + } [Test] public void CountDistinctWithReservedWords() From 32b75e4a0750fe77154c8c5f7ec88fb8123837a3 Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Mon, 2 Jan 2023 13:57:49 +0200 Subject: [PATCH 4/5] Fix for SqlServerCe --- src/NHibernate.Test/NHSpecificTest/GH3215/FixtureByCode.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/NHibernate.Test/NHSpecificTest/GH3215/FixtureByCode.cs b/src/NHibernate.Test/NHSpecificTest/GH3215/FixtureByCode.cs index 8e7d7e435cf..9935fd79940 100644 --- a/src/NHibernate.Test/NHSpecificTest/GH3215/FixtureByCode.cs +++ b/src/NHibernate.Test/NHSpecificTest/GH3215/FixtureByCode.cs @@ -26,7 +26,12 @@ protected override HbmMapping GetMappings() }); return mapper.CompileMappingForAllExplicitlyAddedEntities(); } - + + protected override bool AppliesTo(Dialect.Dialect dialect) + { + return TestDialect.SupportsCountDistinct; + } + protected override void Configure(Configuration configuration) { base.Configure(configuration); From 574d9aabab1a59f09c574fa56fecd58ab4836bef Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 2 Jan 2023 12:00:37 +0000 Subject: [PATCH 5/5] Generate async files --- .../NHSpecificTest/GH3215/FixtureByCode.cs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/NHibernate.Test/Async/NHSpecificTest/GH3215/FixtureByCode.cs diff --git a/src/NHibernate.Test/Async/NHSpecificTest/GH3215/FixtureByCode.cs b/src/NHibernate.Test/Async/NHSpecificTest/GH3215/FixtureByCode.cs new file mode 100644 index 00000000000..8d5772bf3d5 --- /dev/null +++ b/src/NHibernate.Test/Async/NHSpecificTest/GH3215/FixtureByCode.cs @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by AsyncGenerator. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + +using NHibernate.Cfg; +using NHibernate.Cfg.MappingSchema; +using NHibernate.Mapping.ByCode; +using NUnit.Framework; + +namespace NHibernate.Test.NHSpecificTest.GH3215 +{ + using System.Threading.Tasks; + [TestFixture] + public class ByCodeFixtureAsync : TestCaseMappingByCode + { + protected override HbmMapping GetMappings() + { + var mapper = new ModelMapper(); + + mapper.Class(rc => + { + rc.Id(x => x.Code); + rc.Property(x => x.Name); + rc.Property(x => x.Date); + }); + + mapper.Class(rc => + { + rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb)); + rc.ManyToOne(x => x.Member); + }); + return mapper.CompileMappingForAllExplicitlyAddedEntities(); + } + + protected override bool AppliesTo(Dialect.Dialect dialect) + { + return TestDialect.SupportsCountDistinct; + } + + protected override void Configure(Configuration configuration) + { + base.Configure(configuration); + configuration.SetProperty(Environment.Hbm2ddlKeyWords, "auto-quote"); + } + + [Test] + public async Task CountDistinctWithReservedWordsAsync() + { + using (var session = OpenSession()) + { + var hql = "select Count(DISTINCT r.Member.id), Count(DISTINCT Date(r.Member.Date)) from Request r"; + var result = await (session.CreateQuery(hql).ListAsync()); + + Assert.That(result, Has.Count.EqualTo(1)); + } + } + } +}