Skip to content

Commit fce95fe

Browse files
More fixes. Fixes #837
* More registrations of ascii, chr, floor, ceiling, ceil
1 parent 3a26ff9 commit fce95fe

File tree

7 files changed

+70
-2
lines changed

7 files changed

+70
-2
lines changed

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,8 @@ public async Task AbsAsync()
535535
[Test]
536536
public async Task CeilingAsync()
537537
{
538+
Assume.That(Dialect.Functions.ContainsKey("ceiling"), Is.True, Dialect + " doesn't support ceiling function.");
539+
538540
using (var s = OpenSession())
539541
{
540542
var a1 = new Animal("a1", 1.3f);
@@ -660,9 +662,35 @@ public async Task LowerAsync()
660662
}
661663
}
662664

665+
[Test]
666+
public async Task AsciiAsync()
667+
{
668+
Assume.That(Dialect.Functions.ContainsKey("ascii"), Is.True, Dialect + " doesn't support ascii function.");
669+
670+
using (var s = OpenSession())
671+
{
672+
var m = new MaterialResource(" ", "000", MaterialResource.MaterialState.Available);
673+
await (s.SaveAsync(m));
674+
await (s.FlushAsync());
675+
}
676+
using (var s = OpenSession())
677+
{
678+
var space = await (s.CreateQuery("select ascii(m.Description) from MaterialResource m").UniqueResultAsync<int>());
679+
Assert.That(space, Is.EqualTo(32));
680+
var count =
681+
await (s
682+
.CreateQuery("select count(*) from MaterialResource m where ascii(m.Description) = :c")
683+
.SetInt32("c", 32)
684+
.UniqueResultAsync<long>());
685+
Assert.That(count, Is.EqualTo(1));
686+
}
687+
}
688+
663689
[Test]
664690
public async Task ChrAsync()
665691
{
692+
Assume.That(Dialect.Functions.ContainsKey("chr"), Is.True, Dialect + " doesn't support chr function.");
693+
666694
using (var s = OpenSession())
667695
{
668696
var m = new MaterialResource("Blah", "000", (MaterialResource.MaterialState)32);
@@ -1037,7 +1065,7 @@ public async Task StrAsync()
10371065
public async Task IifAsync()
10381066
{
10391067
if (!Dialect.Functions.ContainsKey("iif"))
1040-
Assert.Ignore(Dialect + "doesn't support iif function.");
1068+
Assert.Ignore(Dialect + " doesn't support iif function.");
10411069
using (ISession s = OpenSession())
10421070
{
10431071
await (s.SaveAsync(new MaterialResource("Flash card 512MB", "A001/07", MaterialResource.MaterialState.Available)));

src/NHibernate.Test/Hql/HQLFunctions.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ public void Abs()
524524
[Test]
525525
public void Ceiling()
526526
{
527+
Assume.That(Dialect.Functions.ContainsKey("ceiling"), Is.True, Dialect + " doesn't support ceiling function.");
528+
527529
using (var s = OpenSession())
528530
{
529531
var a1 = new Animal("a1", 1.3f);
@@ -649,9 +651,35 @@ public void Lower()
649651
}
650652
}
651653

654+
[Test]
655+
public void Ascii()
656+
{
657+
Assume.That(Dialect.Functions.ContainsKey("ascii"), Is.True, Dialect + " doesn't support ascii function.");
658+
659+
using (var s = OpenSession())
660+
{
661+
var m = new MaterialResource(" ", "000", MaterialResource.MaterialState.Available);
662+
s.Save(m);
663+
s.Flush();
664+
}
665+
using (var s = OpenSession())
666+
{
667+
var space = s.CreateQuery("select ascii(m.Description) from MaterialResource m").UniqueResult<int>();
668+
Assert.That(space, Is.EqualTo(32));
669+
var count =
670+
s
671+
.CreateQuery("select count(*) from MaterialResource m where ascii(m.Description) = :c")
672+
.SetInt32("c", 32)
673+
.UniqueResult<long>();
674+
Assert.That(count, Is.EqualTo(1));
675+
}
676+
}
677+
652678
[Test]
653679
public void Chr()
654680
{
681+
Assume.That(Dialect.Functions.ContainsKey("chr"), Is.True, Dialect + " doesn't support chr function.");
682+
655683
using (var s = OpenSession())
656684
{
657685
var m = new MaterialResource("Blah", "000", (MaterialResource.MaterialState)32);
@@ -1026,7 +1054,7 @@ public void Str()
10261054
public void Iif()
10271055
{
10281056
if (!Dialect.Functions.ContainsKey("iif"))
1029-
Assert.Ignore(Dialect + "doesn't support iif function.");
1057+
Assert.Ignore(Dialect + " doesn't support iif function.");
10301058
using (ISession s = OpenSession())
10311059
{
10321060
s.Save(new MaterialResource("Flash card 512MB", "A001/07", MaterialResource.MaterialState.Available));

src/NHibernate/Dialect/DB2Dialect.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public DB2Dialect()
115115
RegisterFunction("smallint", new StandardSQLFunction("smallint", NHibernateUtil.Int16));
116116

117117
RegisterFunction("digits", new StandardSQLFunction("digits", NHibernateUtil.String));
118+
RegisterFunction("ascii", new StandardSQLFunction("ascii", NHibernateUtil.Int32));
118119
RegisterFunction("chr", new StandardSQLFunction("chr", NHibernateUtil.Character));
119120
RegisterFunction("upper", new StandardSQLFunction("upper"));
120121
RegisterFunction("ucase", new StandardSQLFunction("ucase"));

src/NHibernate/Dialect/FirebirdDialect.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ private void RegisterMathematicalFunctions()
454454
{
455455
RegisterFunction("abs", new StandardSQLFunction("abs", NHibernateUtil.Double));
456456
RegisterFunction("ceiling", new StandardSQLFunction("ceiling", NHibernateUtil.Double));
457+
RegisterFunction("ceil", new StandardSQLFunction("ceil", NHibernateUtil.Double));
457458
RegisterFunction("div", new StandardSQLFunction("div", NHibernateUtil.Double));
458459
RegisterFunction("dpower", new StandardSQLFunction("dpower", NHibernateUtil.Double));
459460
RegisterFunction("ln", new StandardSQLFunction("ln", NHibernateUtil.Double));
@@ -486,7 +487,9 @@ private void RegisterDateTimeFunctions()
486487
private void RegisterStringAndCharFunctions()
487488
{
488489
RegisterFunction("ascii_char", new StandardSQLFunction("ascii_char"));
490+
RegisterFunction("chr", new StandardSQLFunction("ascii_char"));
489491
RegisterFunction("ascii_val", new StandardSQLFunction("ascii_val", NHibernateUtil.Int16));
492+
RegisterFunction("ascii", new StandardSQLFunction("ascii_val", NHibernateUtil.Int16));
490493
RegisterFunction("lpad", new StandardSQLFunction("lpad"));
491494
RegisterFunction("ltrim", new StandardSQLFunction("ltrim"));
492495
RegisterFunction("sright", new StandardSQLFunction("sright"));

src/NHibernate/Dialect/MsSql2000Dialect.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +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("ascii", new StandardSQLFunction("ascii", NHibernateUtil.Int32));
329330
RegisterFunction("chr", new StandardSQLFunction("char", NHibernateUtil.Character));
330331
RegisterFunction("upper", new StandardSQLFunction("upper"));
331332
RegisterFunction("ucase", new StandardSQLFunction("ucase"));

src/NHibernate/Dialect/PostgreSQLDialect.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ public PostgreSQLDialect()
7979

8080
RegisterFunction("power", new StandardSQLFunction("power", NHibernateUtil.Double));
8181

82+
RegisterFunction("floor", new StandardSQLFunction("floor"));
83+
RegisterFunction("ceiling", new StandardSQLFunction("ceiling"));
84+
RegisterFunction("ceil", new StandardSQLFunction("ceil"));
85+
RegisterFunction("chr", new StandardSQLFunction("chr", NHibernateUtil.Character));
86+
RegisterFunction("ascii", new StandardSQLFunction("ascii", NHibernateUtil.Int32));
87+
8288
// Register the date function, since when used in LINQ select clauses, NH must know the data type.
8389
RegisterFunction("date", new SQLFunctionTemplate(NHibernateUtil.Date, "cast(?1 as date)"));
8490

src/NHibernate/Dialect/SQLiteDialect.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ protected virtual void RegisterFunctions()
7878
RegisterFunction("left", new SQLFunctionTemplate(NHibernateUtil.String, "substr(?1,1,?2)"));
7979
RegisterFunction("trim", new AnsiTrimEmulationFunction());
8080
RegisterFunction("replace", new StandardSafeSQLFunction("replace", NHibernateUtil.String, 3));
81+
RegisterFunction("chr", new StandardSQLFunction("char", NHibernateUtil.Character));
8182

8283
RegisterFunction("mod", new SQLFunctionTemplate(NHibernateUtil.Int32, "((?1) % (?2))"));
8384

0 commit comments

Comments
 (0)