@@ -23,42 +23,6 @@ namespace NHibernate.Test.Hql
23
23
[ TestFixture ]
24
24
public class HQLFunctionsAsync : TestCase
25
25
{
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
-
62
26
protected override string MappingsAssembly
63
27
{
64
28
get { return "NHibernate.Test" ; }
@@ -75,6 +39,7 @@ protected override void OnTearDown()
75
39
{
76
40
s . Delete ( "from Human" ) ;
77
41
s . Delete ( "from Animal" ) ;
42
+ s . Delete ( "from MaterialResource" ) ;
78
43
s . Flush ( ) ;
79
44
}
80
45
}
@@ -255,7 +220,7 @@ public async Task SubStringTwoParametersAsync()
255
220
// the two-parameter overload - emulating it by generating the
256
221
// third parameter (length) if the database requires three parameters.
257
222
258
- IgnoreIfNotSupported ( "substring" ) ;
223
+ AssumeFunctionSupported ( "substring" ) ;
259
224
260
225
using ( ISession s = OpenSession ( ) )
261
226
{
@@ -293,7 +258,7 @@ public async Task SubStringTwoParametersAsync()
293
258
[ Test ]
294
259
public async Task SubStringAsync ( )
295
260
{
296
- IgnoreIfNotSupported ( "substring" ) ;
261
+ AssumeFunctionSupported ( "substring" ) ;
297
262
using ( ISession s = OpenSession ( ) )
298
263
{
299
264
Animal a1 = new Animal ( "abcdef" , 20 ) ;
@@ -345,7 +310,7 @@ public async Task SubStringAsync()
345
310
[ Test ]
346
311
public async Task LocateAsync ( )
347
312
{
348
- IgnoreIfNotSupported ( "locate" ) ;
313
+ AssumeFunctionSupported ( "locate" ) ;
349
314
using ( ISession s = OpenSession ( ) )
350
315
{
351
316
Animal a1 = new Animal ( "abcdef" , 20 ) ;
@@ -367,7 +332,7 @@ public async Task LocateAsync()
367
332
[ Test ]
368
333
public async Task TrimAsync ( )
369
334
{
370
- IgnoreIfNotSupported ( "trim" ) ;
335
+ AssumeFunctionSupported ( "trim" ) ;
371
336
using ( ISession s = OpenSession ( ) )
372
337
{
373
338
Animal a1 = new Animal ( "abc " , 1 ) ;
@@ -425,7 +390,7 @@ public async Task TrimAsync()
425
390
[ Test ]
426
391
public async Task LengthAsync ( )
427
392
{
428
- IgnoreIfNotSupported ( "length" ) ;
393
+ AssumeFunctionSupported ( "length" ) ;
429
394
430
395
using ( ISession s = OpenSession ( ) )
431
396
{
@@ -450,7 +415,7 @@ public async Task LengthAsync()
450
415
[ Test ]
451
416
public async Task Bit_lengthAsync ( )
452
417
{
453
- IgnoreIfNotSupported ( "bit_length" ) ;
418
+ AssumeFunctionSupported ( "bit_length" ) ;
454
419
455
420
// test only the parser
456
421
using ( ISession s = OpenSession ( ) )
@@ -466,7 +431,7 @@ public async Task Bit_lengthAsync()
466
431
[ Test ]
467
432
public async Task CoalesceAsync ( )
468
433
{
469
- IgnoreIfNotSupported ( "coalesce" ) ;
434
+ AssumeFunctionSupported ( "coalesce" ) ;
470
435
// test only the parser and render
471
436
using ( ISession s = OpenSession ( ) )
472
437
{
@@ -481,9 +446,9 @@ public async Task CoalesceAsync()
481
446
[ Test ]
482
447
public async Task NullifAsync ( )
483
448
{
484
- IgnoreIfNotSupported ( "nullif" ) ;
449
+ AssumeFunctionSupported ( "nullif" ) ;
485
450
string hql1 , hql2 ;
486
- if ( ! IsOracleDialect ( ) )
451
+ if ( ! ( Dialect is Oracle8iDialect ) )
487
452
{
488
453
hql1 = "select nullif(h.NickName, '1e1') from Human h" ;
489
454
hql2 = "from Human h where not(nullif(h.NickName, '1e1') is null)" ;
@@ -505,7 +470,7 @@ public async Task NullifAsync()
505
470
[ Test ]
506
471
public async Task AbsAsync ( )
507
472
{
508
- IgnoreIfNotSupported ( "abs" ) ;
473
+ AssumeFunctionSupported ( "abs" ) ;
509
474
using ( ISession s = OpenSession ( ) )
510
475
{
511
476
Animal a1 = new Animal ( "Dog" , 9 ) ;
@@ -531,10 +496,34 @@ public async Task AbsAsync()
531
496
}
532
497
}
533
498
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
+
534
523
[ Test ]
535
524
public async Task ModAsync ( )
536
525
{
537
- IgnoreIfNotSupported ( "mod" ) ;
526
+ AssumeFunctionSupported ( "mod" ) ;
538
527
using ( ISession s = OpenSession ( ) )
539
528
{
540
529
Animal a1 = new Animal ( "abcdef" , 20 ) ;
@@ -560,7 +549,7 @@ public async Task ModAsync()
560
549
[ Test ]
561
550
public async Task SqrtAsync ( )
562
551
{
563
- IgnoreIfNotSupported ( "sqrt" ) ;
552
+ AssumeFunctionSupported ( "sqrt" ) ;
564
553
using ( ISession s = OpenSession ( ) )
565
554
{
566
555
Animal a1 = new Animal ( "abcdef" , 65536f ) ;
@@ -582,7 +571,7 @@ public async Task SqrtAsync()
582
571
[ Test ]
583
572
public async Task UpperAsync ( )
584
573
{
585
- IgnoreIfNotSupported ( "upper" ) ;
574
+ AssumeFunctionSupported ( "upper" ) ;
586
575
using ( ISession s = OpenSession ( ) )
587
576
{
588
577
Animal a1 = new Animal ( "abcdef" , 1f ) ;
@@ -611,7 +600,7 @@ public async Task UpperAsync()
611
600
[ Test ]
612
601
public async Task LowerAsync ( )
613
602
{
614
- IgnoreIfNotSupported ( "lower" ) ;
603
+ AssumeFunctionSupported ( "lower" ) ;
615
604
using ( ISession s = OpenSession ( ) )
616
605
{
617
606
Animal a1 = new Animal ( "ABCDEF" , 1f ) ;
@@ -637,12 +626,60 @@ public async Task LowerAsync()
637
626
}
638
627
}
639
628
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
+
640
677
[ Test ]
641
678
public async Task CastAsync ( )
642
679
{
643
680
const double magicResult = 7 + 123 - 5 * 1.3d ;
644
681
645
- IgnoreIfNotSupported ( "cast" ) ;
682
+ AssumeFunctionSupported ( "cast" ) ;
646
683
// The cast is used to test various cases of a function render
647
684
// Cast was selected because represent a special case for:
648
685
// 1) Has more then 1 argument
@@ -820,7 +857,7 @@ public async Task CastAsync()
820
857
[ Test ]
821
858
public async Task CastNH1446Async ( )
822
859
{
823
- IgnoreIfNotSupported ( "cast" ) ;
860
+ AssumeFunctionSupported ( "cast" ) ;
824
861
using ( ISession s = OpenSession ( ) )
825
862
{
826
863
Animal a1 = new Animal ( "abcdef" , 1.3f ) ;
@@ -840,7 +877,7 @@ public async Task CastNH1446Async()
840
877
[ Test ]
841
878
public async Task CastNH1979Async ( )
842
879
{
843
- IgnoreIfNotSupported ( "cast" ) ;
880
+ AssumeFunctionSupported ( "cast" ) ;
844
881
using ( ISession s = OpenSession ( ) )
845
882
{
846
883
Animal a1 = new Animal ( "abcdef" , 1.3f ) ;
@@ -858,7 +895,7 @@ public async Task CastNH1979Async()
858
895
[ Test ]
859
896
public async Task Current_TimeStampAsync ( )
860
897
{
861
- IgnoreIfNotSupported ( "current_timestamp" ) ;
898
+ AssumeFunctionSupported ( "current_timestamp" ) ;
862
899
using ( ISession s = OpenSession ( ) )
863
900
{
864
901
Animal a1 = new Animal ( "abcdef" , 1.3f ) ;
@@ -878,9 +915,7 @@ public async Task Current_TimeStampAsync()
878
915
[ Test ]
879
916
public async Task Current_TimeStamp_OffsetAsync ( )
880
917
{
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" ) ;
884
919
using ( ISession s = OpenSession ( ) )
885
920
{
886
921
Animal a1 = new Animal ( "abcdef" , 1.3f ) ;
@@ -897,8 +932,8 @@ public async Task Current_TimeStamp_OffsetAsync()
897
932
[ Test ]
898
933
public async Task ExtractAsync ( )
899
934
{
900
- IgnoreIfNotSupported ( "extract" ) ;
901
- IgnoreIfNotSupported ( "current_timestamp" ) ;
935
+ AssumeFunctionSupported ( "extract" ) ;
936
+ AssumeFunctionSupported ( "current_timestamp" ) ;
902
937
903
938
// test only the parser and render
904
939
using ( ISession s = OpenSession ( ) )
@@ -914,7 +949,7 @@ public async Task ExtractAsync()
914
949
[ Test ]
915
950
public async Task ConcatAsync ( )
916
951
{
917
- IgnoreIfNotSupported ( "concat" ) ;
952
+ AssumeFunctionSupported ( "concat" ) ;
918
953
using ( ISession s = OpenSession ( ) )
919
954
{
920
955
Animal a1 = new Animal ( "abcdef" , 1f ) ;
@@ -940,10 +975,10 @@ public async Task ConcatAsync()
940
975
[ Test ]
941
976
public async Task HourMinuteSecondAsync ( )
942
977
{
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" ) ;
947
982
// test only the parser and render
948
983
using ( ISession s = OpenSession ( ) )
949
984
{
@@ -955,9 +990,9 @@ public async Task HourMinuteSecondAsync()
955
990
[ Test ]
956
991
public async Task DayMonthYearAsync ( )
957
992
{
958
- IgnoreIfNotSupported ( "day" ) ;
959
- IgnoreIfNotSupported ( "month" ) ;
960
- IgnoreIfNotSupported ( "year" ) ;
993
+ AssumeFunctionSupported ( "day" ) ;
994
+ AssumeFunctionSupported ( "month" ) ;
995
+ AssumeFunctionSupported ( "year" ) ;
961
996
// test only the parser and render
962
997
using ( ISession s = OpenSession ( ) )
963
998
{
@@ -969,7 +1004,7 @@ public async Task DayMonthYearAsync()
969
1004
[ Test ]
970
1005
public async Task StrAsync ( )
971
1006
{
972
- IgnoreIfNotSupported ( "str" ) ;
1007
+ AssumeFunctionSupported ( "str" ) ;
973
1008
using ( ISession s = OpenSession ( ) )
974
1009
{
975
1010
Animal a1 = new Animal ( "abcdef" , 20 ) ;
@@ -991,8 +1026,7 @@ public async Task StrAsync()
991
1026
[ Test ]
992
1027
public async Task IifAsync ( )
993
1028
{
994
- if ( ! Dialect . Functions . ContainsKey ( "iif" ) )
995
- Assert . Ignore ( Dialect + "doesn't support iif function." ) ;
1029
+ AssumeFunctionSupported ( "Iif" ) ;
996
1030
using ( ISession s = OpenSession ( ) )
997
1031
{
998
1032
await ( s . SaveAsync ( new MaterialResource ( "Flash card 512MB" , "A001/07" , MaterialResource . MaterialState . Available ) ) ) ;
@@ -1035,7 +1069,7 @@ from MaterialResource mr
1035
1069
[ Test ]
1036
1070
public async Task NH1725Async ( )
1037
1071
{
1038
- IgnoreIfNotSupported ( "iif" ) ;
1072
+ AssumeFunctionSupported ( "iif" ) ;
1039
1073
// Only to test the parser
1040
1074
using ( ISession s = OpenSession ( ) )
1041
1075
{
0 commit comments