Skip to content

Commit 3a26ff9

Browse files
Fix some HQL functions registration
* ceiling was not registered for Oracle, while it needs to be transcripted to ceil * ceil was registered as ceil for SQL-Server, which only supports ceiling * chr was wrongly registered as chr for SQL-Server, it needs to be registered as char
1 parent 93d7246 commit 3a26ff9

File tree

5 files changed

+94
-2
lines changed

5 files changed

+94
-2
lines changed

src/NHibernate.Test/Async/Hql/HQLFunctions.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ protected override void OnTearDown()
7575
{
7676
s.Delete("from Human");
7777
s.Delete("from Animal");
78+
s.Delete("from MaterialResource");
7879
s.Flush();
7980
}
8081
}
@@ -531,6 +532,28 @@ public async Task AbsAsync()
531532
}
532533
}
533534

535+
[Test]
536+
public async Task CeilingAsync()
537+
{
538+
using (var s = OpenSession())
539+
{
540+
var a1 = new Animal("a1", 1.3f);
541+
await (s.SaveAsync(a1));
542+
await (s.FlushAsync());
543+
}
544+
using (var s = OpenSession())
545+
{
546+
var ceiling = await (s.CreateQuery("select ceiling(a.BodyWeight) from Animal a").UniqueResultAsync<float>());
547+
Assert.That(ceiling, Is.EqualTo(2));
548+
var count =
549+
await (s
550+
.CreateQuery("select count(*) from Animal a where ceiling(a.BodyWeight) = :c")
551+
.SetInt32("c", 2)
552+
.UniqueResultAsync<long>());
553+
Assert.That(count, Is.EqualTo(1));
554+
}
555+
}
556+
534557
[Test]
535558
public async Task ModAsync()
536559
{
@@ -637,6 +660,28 @@ public async Task LowerAsync()
637660
}
638661
}
639662

663+
[Test]
664+
public async Task ChrAsync()
665+
{
666+
using (var s = OpenSession())
667+
{
668+
var m = new MaterialResource("Blah", "000", (MaterialResource.MaterialState)32);
669+
await (s.SaveAsync(m));
670+
await (s.FlushAsync());
671+
}
672+
using (var s = OpenSession())
673+
{
674+
var space = await (s.CreateQuery("select chr(m.State) from MaterialResource m").UniqueResultAsync<char>());
675+
Assert.That(space, Is.EqualTo(' '));
676+
var count =
677+
await (s
678+
.CreateQuery("select count(*) from MaterialResource m where chr(m.State) = :c")
679+
.SetCharacter("c", ' ')
680+
.UniqueResultAsync<long>());
681+
Assert.That(count, Is.EqualTo(1));
682+
}
683+
}
684+
640685
[Test]
641686
public async Task CastAsync()
642687
{

src/NHibernate.Test/Hql/HQLFunctions.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ protected override void OnTearDown()
6464
{
6565
s.Delete("from Human");
6666
s.Delete("from Animal");
67+
s.Delete("from MaterialResource");
6768
s.Flush();
6869
}
6970
}
@@ -520,6 +521,28 @@ public void Abs()
520521
}
521522
}
522523

524+
[Test]
525+
public void Ceiling()
526+
{
527+
using (var s = OpenSession())
528+
{
529+
var a1 = new Animal("a1", 1.3f);
530+
s.Save(a1);
531+
s.Flush();
532+
}
533+
using (var s = OpenSession())
534+
{
535+
var ceiling = s.CreateQuery("select ceiling(a.BodyWeight) from Animal a").UniqueResult<float>();
536+
Assert.That(ceiling, Is.EqualTo(2));
537+
var count =
538+
s
539+
.CreateQuery("select count(*) from Animal a where ceiling(a.BodyWeight) = :c")
540+
.SetInt32("c", 2)
541+
.UniqueResult<long>();
542+
Assert.That(count, Is.EqualTo(1));
543+
}
544+
}
545+
523546
[Test]
524547
public void Mod()
525548
{
@@ -626,6 +649,28 @@ public void Lower()
626649
}
627650
}
628651

652+
[Test]
653+
public void Chr()
654+
{
655+
using (var s = OpenSession())
656+
{
657+
var m = new MaterialResource("Blah", "000", (MaterialResource.MaterialState)32);
658+
s.Save(m);
659+
s.Flush();
660+
}
661+
using (var s = OpenSession())
662+
{
663+
var space = s.CreateQuery("select chr(m.State) from MaterialResource m").UniqueResult<char>();
664+
Assert.That(space, Is.EqualTo(' '));
665+
var count =
666+
s
667+
.CreateQuery("select count(*) from MaterialResource m where chr(m.State) = :c")
668+
.SetCharacter("c", ' ')
669+
.UniqueResult<long>();
670+
Assert.That(count, Is.EqualTo(1));
671+
}
672+
}
673+
629674
[Test]
630675
public void Cast()
631676
{

src/NHibernate/Dialect/MsSql2000Dialect.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ protected virtual void RegisterFunctions()
284284
RegisterFunction("sign", new StandardSQLFunction("sign", NHibernateUtil.Int32));
285285

286286
RegisterFunction("ceiling", new StandardSQLFunction("ceiling"));
287-
RegisterFunction("ceil", new StandardSQLFunction("ceil"));
287+
RegisterFunction("ceil", new StandardSQLFunction("ceiling"));
288288
RegisterFunction("floor", new StandardSQLFunction("floor"));
289289
RegisterFunction("round", new StandardSQLFunction("round"));
290290

@@ -326,7 +326,7 @@ protected virtual void RegisterFunctions()
326326
RegisterFunction("date", new SQLFunctionTemplate(NHibernateUtil.Date, "dateadd(dd, 0, datediff(dd, 0, ?1))"));
327327
RegisterFunction("concat", new VarArgsSQLFunction(NHibernateUtil.String, "(", "+", ")"));
328328
RegisterFunction("digits", new StandardSQLFunction("digits", NHibernateUtil.String));
329-
RegisterFunction("chr", new StandardSQLFunction("chr", NHibernateUtil.Character));
329+
RegisterFunction("chr", new StandardSQLFunction("char", NHibernateUtil.Character));
330330
RegisterFunction("upper", new StandardSQLFunction("upper"));
331331
RegisterFunction("ucase", new StandardSQLFunction("ucase"));
332332
RegisterFunction("lcase", new StandardSQLFunction("lcase"));

src/NHibernate/Dialect/Oracle8iDialect.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ protected virtual void RegisterFunctions()
230230
RegisterFunction("round", new StandardSQLFunction("round"));
231231
RegisterFunction("trunc", new StandardSQLFunction("trunc"));
232232
RegisterFunction("ceil", new StandardSQLFunction("ceil"));
233+
RegisterFunction("ceiling", new StandardSQLFunction("ceil"));
233234
RegisterFunction("floor", new StandardSQLFunction("floor"));
234235

235236
RegisterFunction("chr", new StandardSQLFunction("chr", NHibernateUtil.Character));

src/NHibernate/Dialect/OracleLiteDialect.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public OracleLiteDialect()
6969
RegisterFunction("round", new StandardSQLFunction("round"));
7070
RegisterFunction("trunc", new StandardSQLFunction("trunc"));
7171
RegisterFunction("ceil", new StandardSQLFunction("ceil"));
72+
RegisterFunction("ceiling", new StandardSQLFunction("ceil"));
7273
RegisterFunction("floor", new StandardSQLFunction("floor"));
7374

7475
RegisterFunction("chr", new StandardSQLFunction("chr", NHibernateUtil.Character));

0 commit comments

Comments
 (0)