Skip to content

Commit 083a928

Browse files
Fix some HQL functions registration (#1535)
* 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 * More registrations of ascii, chr, floor, ceiling, ceil * Fix type registrations for ceiling, floor, chr, ascii in Firebird * Fix registrations of chr in MySql * Fixes #837 * Consolidate function support test logic in Test project
1 parent 7a01d97 commit 083a928

File tree

12 files changed

+283
-170
lines changed

12 files changed

+283
-170
lines changed

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

Lines changed: 105 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,6 @@ namespace NHibernate.Test.Hql
2323
[TestFixture]
2424
public class HQLFunctionsAsync : TestCase
2525
{
26-
static readonly Hashtable notSupportedStandardFunction;
27-
static HQLFunctionsAsync()
28-
{
29-
notSupportedStandardFunction =
30-
new Hashtable
31-
{
32-
{"locate", new[] {typeof (SQLiteDialect)}},
33-
{"bit_length", new[] {typeof (SQLiteDialect)}},
34-
{"extract", new[] {typeof (SQLiteDialect)}},
35-
{
36-
"nullif",
37-
new[]
38-
{
39-
typeof (Oracle8iDialect),
40-
// Actually not supported by the db engine. (Well, could likely still be done with a case when override.)
41-
typeof (MsSqlCeDialect),
42-
typeof (MsSqlCe40Dialect)
43-
}}
44-
};
45-
}
46-
47-
private bool IsOracleDialect()
48-
{
49-
return Dialect is Oracle8iDialect;
50-
}
51-
52-
private void IgnoreIfNotSupported(string functionName)
53-
{
54-
if (notSupportedStandardFunction.ContainsKey(functionName))
55-
{
56-
IList dialects = (IList)notSupportedStandardFunction[functionName];
57-
if(dialects.Contains(Dialect.GetType()))
58-
Assert.Ignore(Dialect + " doesn't support "+functionName+" function.");
59-
}
60-
}
61-
6226
protected override string MappingsAssembly
6327
{
6428
get { return "NHibernate.Test"; }
@@ -75,6 +39,7 @@ protected override void OnTearDown()
7539
{
7640
s.Delete("from Human");
7741
s.Delete("from Animal");
42+
s.Delete("from MaterialResource");
7843
s.Flush();
7944
}
8045
}
@@ -255,7 +220,7 @@ public async Task SubStringTwoParametersAsync()
255220
// the two-parameter overload - emulating it by generating the
256221
// third parameter (length) if the database requires three parameters.
257222

258-
IgnoreIfNotSupported("substring");
223+
AssumeFunctionSupported("substring");
259224

260225
using (ISession s = OpenSession())
261226
{
@@ -293,7 +258,7 @@ public async Task SubStringTwoParametersAsync()
293258
[Test]
294259
public async Task SubStringAsync()
295260
{
296-
IgnoreIfNotSupported("substring");
261+
AssumeFunctionSupported("substring");
297262
using (ISession s = OpenSession())
298263
{
299264
Animal a1 = new Animal("abcdef", 20);
@@ -345,7 +310,7 @@ public async Task SubStringAsync()
345310
[Test]
346311
public async Task LocateAsync()
347312
{
348-
IgnoreIfNotSupported("locate");
313+
AssumeFunctionSupported("locate");
349314
using (ISession s = OpenSession())
350315
{
351316
Animal a1 = new Animal("abcdef", 20);
@@ -367,7 +332,7 @@ public async Task LocateAsync()
367332
[Test]
368333
public async Task TrimAsync()
369334
{
370-
IgnoreIfNotSupported("trim");
335+
AssumeFunctionSupported("trim");
371336
using (ISession s = OpenSession())
372337
{
373338
Animal a1 = new Animal("abc ", 1);
@@ -425,7 +390,7 @@ public async Task TrimAsync()
425390
[Test]
426391
public async Task LengthAsync()
427392
{
428-
IgnoreIfNotSupported("length");
393+
AssumeFunctionSupported("length");
429394

430395
using (ISession s = OpenSession())
431396
{
@@ -450,7 +415,7 @@ public async Task LengthAsync()
450415
[Test]
451416
public async Task Bit_lengthAsync()
452417
{
453-
IgnoreIfNotSupported("bit_length");
418+
AssumeFunctionSupported("bit_length");
454419

455420
// test only the parser
456421
using (ISession s = OpenSession())
@@ -466,7 +431,7 @@ public async Task Bit_lengthAsync()
466431
[Test]
467432
public async Task CoalesceAsync()
468433
{
469-
IgnoreIfNotSupported("coalesce");
434+
AssumeFunctionSupported("coalesce");
470435
// test only the parser and render
471436
using (ISession s = OpenSession())
472437
{
@@ -481,9 +446,9 @@ public async Task CoalesceAsync()
481446
[Test]
482447
public async Task NullifAsync()
483448
{
484-
IgnoreIfNotSupported("nullif");
449+
AssumeFunctionSupported("nullif");
485450
string hql1, hql2;
486-
if(!IsOracleDialect())
451+
if(!(Dialect is Oracle8iDialect))
487452
{
488453
hql1 = "select nullif(h.NickName, '1e1') from Human h";
489454
hql2 = "from Human h where not(nullif(h.NickName, '1e1') is null)";
@@ -505,7 +470,7 @@ public async Task NullifAsync()
505470
[Test]
506471
public async Task AbsAsync()
507472
{
508-
IgnoreIfNotSupported("abs");
473+
AssumeFunctionSupported("abs");
509474
using (ISession s = OpenSession())
510475
{
511476
Animal a1 = new Animal("Dog", 9);
@@ -531,10 +496,34 @@ public async Task AbsAsync()
531496
}
532497
}
533498

499+
[Test]
500+
public async Task CeilingAsync()
501+
{
502+
AssumeFunctionSupported("ceiling");
503+
504+
using (var s = OpenSession())
505+
{
506+
var a1 = new Animal("a1", 1.3f);
507+
await (s.SaveAsync(a1));
508+
await (s.FlushAsync());
509+
}
510+
using (var s = OpenSession())
511+
{
512+
var ceiling = await (s.CreateQuery("select ceiling(a.BodyWeight) from Animal a").UniqueResultAsync<float>());
513+
Assert.That(ceiling, Is.EqualTo(2));
514+
var count =
515+
await (s
516+
.CreateQuery("select count(*) from Animal a where ceiling(a.BodyWeight) = :c")
517+
.SetInt32("c", 2)
518+
.UniqueResultAsync<long>());
519+
Assert.That(count, Is.EqualTo(1));
520+
}
521+
}
522+
534523
[Test]
535524
public async Task ModAsync()
536525
{
537-
IgnoreIfNotSupported("mod");
526+
AssumeFunctionSupported("mod");
538527
using (ISession s = OpenSession())
539528
{
540529
Animal a1 = new Animal("abcdef", 20);
@@ -560,7 +549,7 @@ public async Task ModAsync()
560549
[Test]
561550
public async Task SqrtAsync()
562551
{
563-
IgnoreIfNotSupported("sqrt");
552+
AssumeFunctionSupported("sqrt");
564553
using (ISession s = OpenSession())
565554
{
566555
Animal a1 = new Animal("abcdef", 65536f);
@@ -582,7 +571,7 @@ public async Task SqrtAsync()
582571
[Test]
583572
public async Task UpperAsync()
584573
{
585-
IgnoreIfNotSupported("upper");
574+
AssumeFunctionSupported("upper");
586575
using (ISession s = OpenSession())
587576
{
588577
Animal a1 = new Animal("abcdef", 1f);
@@ -611,7 +600,7 @@ public async Task UpperAsync()
611600
[Test]
612601
public async Task LowerAsync()
613602
{
614-
IgnoreIfNotSupported("lower");
603+
AssumeFunctionSupported("lower");
615604
using (ISession s = OpenSession())
616605
{
617606
Animal a1 = new Animal("ABCDEF", 1f);
@@ -637,12 +626,60 @@ public async Task LowerAsync()
637626
}
638627
}
639628

629+
[Test]
630+
public async Task AsciiAsync()
631+
{
632+
AssumeFunctionSupported("ascii");
633+
634+
using (var s = OpenSession())
635+
{
636+
var m = new MaterialResource(" ", "000", MaterialResource.MaterialState.Available);
637+
await (s.SaveAsync(m));
638+
await (s.FlushAsync());
639+
}
640+
using (var s = OpenSession())
641+
{
642+
var space = await (s.CreateQuery("select ascii(m.Description) from MaterialResource m").UniqueResultAsync<int>());
643+
Assert.That(space, Is.EqualTo(32));
644+
var count =
645+
await (s
646+
.CreateQuery("select count(*) from MaterialResource m where ascii(m.Description) = :c")
647+
.SetInt32("c", 32)
648+
.UniqueResultAsync<long>());
649+
Assert.That(count, Is.EqualTo(1));
650+
}
651+
}
652+
653+
[Test]
654+
public async Task ChrAsync()
655+
{
656+
AssumeFunctionSupported("chr");
657+
658+
using (var s = OpenSession())
659+
{
660+
var m = new MaterialResource("Blah", "000", (MaterialResource.MaterialState)32);
661+
await (s.SaveAsync(m));
662+
await (s.FlushAsync());
663+
}
664+
using (var s = OpenSession())
665+
{
666+
var space = await (s.CreateQuery("select chr(m.State) from MaterialResource m").UniqueResultAsync<char>());
667+
Assert.That(space, Is.EqualTo(' '));
668+
var count =
669+
await (s
670+
.CreateQuery("select count(*) from MaterialResource m where chr(m.State) = :c")
671+
.SetCharacter("c", ' ')
672+
.UniqueResultAsync<long>());
673+
Assert.That(count, Is.EqualTo(1));
674+
}
675+
}
676+
640677
[Test]
641678
public async Task CastAsync()
642679
{
643680
const double magicResult = 7 + 123 - 5*1.3d;
644681

645-
IgnoreIfNotSupported("cast");
682+
AssumeFunctionSupported("cast");
646683
// The cast is used to test various cases of a function render
647684
// Cast was selected because represent a special case for:
648685
// 1) Has more then 1 argument
@@ -820,7 +857,7 @@ public async Task CastAsync()
820857
[Test]
821858
public async Task CastNH1446Async()
822859
{
823-
IgnoreIfNotSupported("cast");
860+
AssumeFunctionSupported("cast");
824861
using (ISession s = OpenSession())
825862
{
826863
Animal a1 = new Animal("abcdef", 1.3f);
@@ -840,7 +877,7 @@ public async Task CastNH1446Async()
840877
[Test]
841878
public async Task CastNH1979Async()
842879
{
843-
IgnoreIfNotSupported("cast");
880+
AssumeFunctionSupported("cast");
844881
using (ISession s = OpenSession())
845882
{
846883
Animal a1 = new Animal("abcdef", 1.3f);
@@ -858,7 +895,7 @@ public async Task CastNH1979Async()
858895
[Test]
859896
public async Task Current_TimeStampAsync()
860897
{
861-
IgnoreIfNotSupported("current_timestamp");
898+
AssumeFunctionSupported("current_timestamp");
862899
using (ISession s = OpenSession())
863900
{
864901
Animal a1 = new Animal("abcdef", 1.3f);
@@ -878,9 +915,7 @@ public async Task Current_TimeStampAsync()
878915
[Test]
879916
public async Task Current_TimeStamp_OffsetAsync()
880917
{
881-
if (!Dialect.Functions.ContainsKey("current_timestamp_offset"))
882-
Assert.Ignore(Dialect + " doesn't support current_timestamp_offset function");
883-
IgnoreIfNotSupported("current_timestamp_offset");
918+
AssumeFunctionSupported("current_timestamp_offset");
884919
using (ISession s = OpenSession())
885920
{
886921
Animal a1 = new Animal("abcdef", 1.3f);
@@ -897,8 +932,8 @@ public async Task Current_TimeStamp_OffsetAsync()
897932
[Test]
898933
public async Task ExtractAsync()
899934
{
900-
IgnoreIfNotSupported("extract");
901-
IgnoreIfNotSupported("current_timestamp");
935+
AssumeFunctionSupported("extract");
936+
AssumeFunctionSupported("current_timestamp");
902937

903938
// test only the parser and render
904939
using (ISession s = OpenSession())
@@ -914,7 +949,7 @@ public async Task ExtractAsync()
914949
[Test]
915950
public async Task ConcatAsync()
916951
{
917-
IgnoreIfNotSupported("concat");
952+
AssumeFunctionSupported("concat");
918953
using (ISession s = OpenSession())
919954
{
920955
Animal a1 = new Animal("abcdef", 1f);
@@ -940,10 +975,10 @@ public async Task ConcatAsync()
940975
[Test]
941976
public async Task HourMinuteSecondAsync()
942977
{
943-
IgnoreIfNotSupported("second");
944-
IgnoreIfNotSupported("minute");
945-
IgnoreIfNotSupported("hour");
946-
IgnoreIfNotSupported("current_timestamp");
978+
AssumeFunctionSupported("second");
979+
AssumeFunctionSupported("minute");
980+
AssumeFunctionSupported("hour");
981+
AssumeFunctionSupported("current_timestamp");
947982
// test only the parser and render
948983
using (ISession s = OpenSession())
949984
{
@@ -955,9 +990,9 @@ public async Task HourMinuteSecondAsync()
955990
[Test]
956991
public async Task DayMonthYearAsync()
957992
{
958-
IgnoreIfNotSupported("day");
959-
IgnoreIfNotSupported("month");
960-
IgnoreIfNotSupported("year");
993+
AssumeFunctionSupported("day");
994+
AssumeFunctionSupported("month");
995+
AssumeFunctionSupported("year");
961996
// test only the parser and render
962997
using (ISession s = OpenSession())
963998
{
@@ -969,7 +1004,7 @@ public async Task DayMonthYearAsync()
9691004
[Test]
9701005
public async Task StrAsync()
9711006
{
972-
IgnoreIfNotSupported("str");
1007+
AssumeFunctionSupported("str");
9731008
using (ISession s = OpenSession())
9741009
{
9751010
Animal a1 = new Animal("abcdef", 20);
@@ -991,8 +1026,7 @@ public async Task StrAsync()
9911026
[Test]
9921027
public async Task IifAsync()
9931028
{
994-
if (!Dialect.Functions.ContainsKey("iif"))
995-
Assert.Ignore(Dialect + "doesn't support iif function.");
1029+
AssumeFunctionSupported("Iif");
9961030
using (ISession s = OpenSession())
9971031
{
9981032
await (s.SaveAsync(new MaterialResource("Flash card 512MB", "A001/07", MaterialResource.MaterialState.Available)));
@@ -1035,7 +1069,7 @@ from MaterialResource mr
10351069
[Test]
10361070
public async Task NH1725Async()
10371071
{
1038-
IgnoreIfNotSupported("iif");
1072+
AssumeFunctionSupported("iif");
10391073
// Only to test the parser
10401074
using (ISession s = OpenSession())
10411075
{

0 commit comments

Comments
 (0)