@@ -20,7 +20,7 @@ public class SQLFunctionsTest : TestCase
20
20
21
21
protected override IList Mappings
22
22
{
23
- get { return new string [ ] { "Simple.hbm.xml" , "Blobber.hbm.xml" , "Broken.hbm.xml" } ; }
23
+ get { return new string [ ] { "Simple.hbm.xml" , "Blobber.hbm.xml" , "Broken.hbm.xml" } ; }
24
24
}
25
25
26
26
[ Test ]
@@ -33,7 +33,7 @@ public void DialectSQLFunctions()
33
33
. GetEnumerator ( ) ;
34
34
35
35
if ( Dialect is MySQLDialect
36
- // Added two dialects below for NH
36
+ // Added two dialects below for NH
37
37
|| Dialect is MsSql2000Dialect
38
38
|| Dialect is PostgreSQLDialect )
39
39
{
@@ -50,20 +50,20 @@ public void DialectSQLFunctions()
50
50
51
51
// Test to make sure allocating an specified object operates correctly.
52
52
Assert . AreEqual ( 1 ,
53
- s . CreateQuery ( "select new S(s.Count, s.Address) from s in class Simple" ) . List ( )
54
- . Count ) ;
53
+ s . CreateQuery ( "select new S(s.Count, s.Address) from s in class Simple" ) . List ( )
54
+ . Count ) ;
55
55
56
56
// Quick check the base dialect functions operate correctly
57
57
Assert . AreEqual ( 1 ,
58
- s . CreateQuery ( "select max(s.Count) from s in class Simple" ) . List ( ) . Count ) ;
58
+ s . CreateQuery ( "select max(s.Count) from s in class Simple" ) . List ( ) . Count ) ;
59
59
Assert . AreEqual ( 1 ,
60
- s . CreateQuery ( "select count(*) from s in class Simple" ) . List ( ) . Count ) ;
60
+ s . CreateQuery ( "select count(*) from s in class Simple" ) . List ( ) . Count ) ;
61
61
62
62
if ( Dialect is Oracle8iDialect )
63
63
{
64
64
// Check Oracle Dialect mix of dialect functions - no args (no parenthesis and single arg functions
65
65
IList rset = s . CreateQuery ( "select s.Name, sysdate, trunc(s.Pay), round(s.Pay) from s in class Simple" ) . List ( ) ;
66
- object [ ] row = ( object [ ] ) rset [ 0 ] ;
66
+ object [ ] row = ( object [ ] ) rset [ 0 ] ;
67
67
Assert . IsNotNull ( row [ 0 ] , "Name string should have been returned" ) ;
68
68
Assert . IsNotNull ( row [ 1 ] , "Todays Date should have been returned" ) ;
69
69
Assert . AreEqual ( 45f , row [ 2 ] , "trunc(45.8) result was incorrect" ) ;
@@ -76,14 +76,6 @@ public void DialectSQLFunctions()
76
76
rset = s . CreateQuery ( "select abs(round(s.Pay)) from s in class Simple" ) . List ( ) ;
77
77
Assert . AreEqual ( 46f , rset [ 0 ] , "abs(round(-45.8)) result was incorrect" ) ;
78
78
79
- /* As of NH-3893, left and right functions are broken. Seemed confused with join keyword, and not
80
- supported on Hibernate side.
81
- rset = s.CreateQuery("select left('abc', 2), right('abc', 2) from s in class Simple").List();
82
- row = (object[]) rset[0];
83
- Assert.AreEqual("ab", row[0], "Left function is broken.");
84
- Assert.AreEqual("bc", row[1], "Right function is broken.");
85
- */
86
-
87
79
// Test a larger depth 3 function example - Not a useful combo other than for testing
88
80
Assert . AreEqual ( 1 ,
89
81
s . CreateQuery ( "select trunc(round(length('A'))) from s in class Simple" ) . List ( ) . Count ) ;
@@ -112,14 +104,31 @@ supported on Hibernate side.
112
104
s . Close ( ) ;
113
105
}
114
106
107
+ [ Test ]
108
+ [ Ignore ( "NH-3893 is not fixed" ) ]
109
+ public void LeftAndRight ( )
110
+ {
111
+ // As of NH-3893, left and right functions are broken. Seemed confused with join keyword, and not
112
+ // supported on Hibernate side.
113
+ using ( var s = OpenSession ( ) )
114
+ using ( var t = s . BeginTransaction ( ) )
115
+ {
116
+ var rset = s . CreateQuery ( "select left('abc', 2), right('abc', 2) from s in class Simple" ) . List < object [ ] > ( ) ;
117
+ var row = rset [ 0 ] ;
118
+ Assert . AreEqual ( "ab" , row [ 0 ] , "Left function is broken." ) ;
119
+ Assert . AreEqual ( "bc" , row [ 1 ] , "Right function is broken." ) ;
120
+ t . Commit ( ) ;
121
+ }
122
+ }
123
+
115
124
[ Test ]
116
125
public void SetProperties ( )
117
126
{
118
127
ISession s = OpenSession ( ) ;
119
128
ITransaction t = s . BeginTransaction ( ) ;
120
129
Simple simple = new Simple ( ) ;
121
130
simple . Name = "Simple 1" ;
122
- s . Save ( simple , ( long ) 10 ) ;
131
+ s . Save ( simple , ( long ) 10 ) ;
123
132
IQuery q = s . CreateQuery ( "from s in class Simple where s.Name=:Name and s.Count=:Count" ) ;
124
133
q . SetProperties ( simple ) ;
125
134
Assert . AreEqual ( simple , q . List ( ) [ 0 ] ) ;
@@ -155,7 +164,7 @@ public void Broken()
155
164
156
165
s = OpenSession ( ) ;
157
166
t = s . BeginTransaction ( ) ;
158
- b = ( Broken ) s . Load ( typeof ( Broken ) , b ) ;
167
+ b = ( Broken ) s . Load ( typeof ( Broken ) , b ) ;
159
168
t . Commit ( ) ;
160
169
s . Close ( ) ;
161
170
@@ -173,19 +182,19 @@ public void NothingToUpdate()
173
182
ITransaction t = s . BeginTransaction ( ) ;
174
183
Simple simple = new Simple ( ) ;
175
184
simple . Name = "Simple 1" ;
176
- s . Save ( simple , ( long ) 10 ) ;
185
+ s . Save ( simple , ( long ) 10 ) ;
177
186
t . Commit ( ) ;
178
187
s . Close ( ) ;
179
188
180
189
s = OpenSession ( ) ;
181
190
t = s . BeginTransaction ( ) ;
182
- s . Update ( simple , ( long ) 10 ) ;
191
+ s . Update ( simple , ( long ) 10 ) ;
183
192
t . Commit ( ) ;
184
193
s . Close ( ) ;
185
194
186
195
s = OpenSession ( ) ;
187
196
t = s . BeginTransaction ( ) ;
188
- s . Update ( simple , ( long ) 10 ) ;
197
+ s . Update ( simple , ( long ) 10 ) ;
189
198
s . Delete ( simple ) ;
190
199
t . Commit ( ) ;
191
200
s . Close ( ) ;
@@ -218,7 +227,7 @@ public void CachedQuery()
218
227
q . SetString ( "name" , "Simple 1" ) ;
219
228
Assert . AreEqual ( 1 , q . List ( ) . Count ) ;
220
229
221
- simple = ( Simple ) q . List ( ) [ 0 ] ;
230
+ simple = ( Simple ) q . List ( ) [ 0 ] ;
222
231
223
232
q . SetString ( "name" , "Simple 2" ) ;
224
233
Assert . AreEqual ( 0 , q . List ( ) . Count ) ;
@@ -296,7 +305,7 @@ public void SQLFunctionAsAlias()
296
305
t = s . BeginTransaction ( ) ;
297
306
IList result = s . CreateQuery ( query ) . List ( ) ;
298
307
Assert . IsTrue ( result [ 0 ] is Simple ,
299
- "Unexpected result type [" + result [ 0 ] . GetType ( ) . Name + "]" ) ;
308
+ "Unexpected result type [" + result [ 0 ] . GetType ( ) . Name + "]" ) ;
300
309
s . Delete ( result [ 0 ] ) ;
301
310
t . Commit ( ) ;
302
311
s . Close ( ) ;
@@ -384,7 +393,7 @@ public void CachedQueryRegion()
384
393
q . SetCacheable ( true ) ;
385
394
q . SetString ( "name" , "Simple 1" ) ;
386
395
Assert . AreEqual ( 1 , q . List ( ) . Count ) ;
387
- simple = ( Simple ) q . List ( ) [ 0 ] ;
396
+ simple = ( Simple ) q . List ( ) [ 0 ] ;
388
397
389
398
q . SetString ( "name" , "Simple 2" ) ;
390
399
Assert . AreEqual ( 0 , q . List ( ) . Count ) ;
@@ -422,7 +431,7 @@ public void SQLFunctions()
422
431
ITransaction t = s . BeginTransaction ( ) ;
423
432
Simple simple = new Simple ( ) ;
424
433
simple . Name = "Simple 1" ;
425
- s . Save ( simple , ( long ) 10 ) ;
434
+ s . Save ( simple , ( long ) 10 ) ;
426
435
427
436
if ( Dialect is DB2Dialect )
428
437
{
@@ -433,23 +442,23 @@ public void SQLFunctions()
433
442
434
443
Assert . AreEqual ( 1 , s . CreateQuery ( "from s in class Simple where upper(s.Name) = 'SIMPLE 1'" ) . List ( ) . Count ) ;
435
444
Assert . AreEqual ( 1 ,
436
- s . CreateQuery (
437
- "from s in class Simple where not( upper(s.Name)='yada' or 1=2 or 'foo'='bar' or not('foo'='foo') or 'foo' like 'bar')" )
438
- . List ( ) . Count ) ;
445
+ s . CreateQuery (
446
+ "from s in class Simple where not( upper(s.Name)='yada' or 1=2 or 'foo'='bar' or not('foo'='foo') or 'foo' like 'bar')" )
447
+ . List ( ) . Count ) ;
439
448
440
449
if ( ! ( Dialect is MySQLDialect ) && ! ( Dialect is MsSql2000Dialect ) )
441
450
{
442
451
// Dialect.MckoiDialect and Dialect.InterbaseDialect also included
443
452
// My Sql has a funny concatenation operator
444
453
Assert . AreEqual ( 1 ,
445
- s . CreateQuery ( "from s in class Simple where lower(s.Name || ' foo')='simple 1 foo'" ) . List ( ) . Count ) ;
454
+ s . CreateQuery ( "from s in class Simple where lower(s.Name || ' foo')='simple 1 foo'" ) . List ( ) . Count ) ;
446
455
}
447
456
448
457
if ( ( Dialect is MsSql2000Dialect ) )
449
458
{
450
459
Assert . AreEqual ( 1 ,
451
- s . CreateQuery ( "from s in class Simple where lower( s.Name + ' foo' ) = 'simple 1 foo'" ) . List ( ) .
452
- Count ) ;
460
+ s . CreateQuery ( "from s in class Simple where lower( s.Name + ' foo' ) = 'simple 1 foo'" ) . List ( ) .
461
+ Count ) ;
453
462
}
454
463
455
464
/*
@@ -464,46 +473,46 @@ public void SQLFunctions()
464
473
other . Name = "Simple 2" ;
465
474
other . Count = 12 ;
466
475
simple . Other = other ;
467
- s . Save ( other , ( long ) 20 ) ;
476
+ s . Save ( other , ( long ) 20 ) ;
468
477
Assert . AreEqual ( 1 , s . CreateQuery ( "from s in class Simple where upper( s.Other.Name )='SIMPLE 2'" ) . List ( ) . Count ) ;
469
478
Assert . AreEqual ( 0 , s . CreateQuery ( "from s in class Simple where not (upper(s.Other.Name)='SIMPLE 2')" ) . List ( ) . Count ) ;
470
479
Assert . AreEqual ( 1 ,
471
- s . CreateQuery (
472
- "select distinct s from s in class Simple where ( ( s.Other.Count + 3) = (15*2)/2 and s.Count = 69) or ( (s.Other.Count + 2) / 7 ) = 2" )
473
- . List ( ) . Count ) ;
480
+ s . CreateQuery (
481
+ "select distinct s from s in class Simple where ( ( s.Other.Count + 3) = (15*2)/2 and s.Count = 69) or ( (s.Other.Count + 2) / 7 ) = 2" )
482
+ . List ( ) . Count ) ;
474
483
Assert . AreEqual ( 1 ,
475
- s . CreateQuery (
476
- "select s from s in class Simple where ( ( s.Other.Count + 3) = (15*2)/2 and s.Count = 69) or ( (s.Other.Count + 2) / 7 ) = 2 order by s.Other.Count" )
477
- . List ( ) . Count ) ;
484
+ s . CreateQuery (
485
+ "select s from s in class Simple where ( ( s.Other.Count + 3) = (15*2)/2 and s.Count = 69) or ( (s.Other.Count + 2) / 7 ) = 2 order by s.Other.Count" )
486
+ . List ( ) . Count ) ;
478
487
479
488
Simple min = new Simple ( ) ;
480
489
min . Count = - 1 ;
481
490
482
- s . Save ( min , ( long ) 30 ) ;
491
+ s . Save ( min , ( long ) 30 ) ;
483
492
484
493
if ( Dialect . SupportsSubSelects && TestDialect . SupportsOperatorSome )
485
494
{
486
495
Assert . AreEqual ( 2 ,
487
- s . CreateQuery (
488
- "from s in class Simple where s.Count > ( select min(sim.Count) from sim in class NHibernate.DomainModel.Simple )" )
489
- . List ( ) . Count ) ;
496
+ s . CreateQuery (
497
+ "from s in class Simple where s.Count > ( select min(sim.Count) from sim in class NHibernate.DomainModel.Simple )" )
498
+ . List ( ) . Count ) ;
490
499
t . Commit ( ) ;
491
500
t = s . BeginTransaction ( ) ;
492
501
Assert . AreEqual ( 2 ,
493
- s . CreateQuery (
494
- "from s in class Simple where s = some( select sim from sim in class NHibernate.DomainModel.Simple where sim.Count>=0) and s.Count >= 0" )
495
- . List ( ) . Count ) ;
502
+ s . CreateQuery (
503
+ "from s in class Simple where s = some( select sim from sim in class NHibernate.DomainModel.Simple where sim.Count>=0) and s.Count >= 0" )
504
+ . List ( ) . Count ) ;
496
505
Assert . AreEqual ( 1 ,
497
- s . CreateQuery (
498
- "from s in class Simple where s = some( select sim from sim in class NHibernate.DomainModel.Simple where sim.Other.Count=s.Other.Count ) and s.Other.Count > 0" )
499
- . List ( ) . Count ) ;
506
+ s . CreateQuery (
507
+ "from s in class Simple where s = some( select sim from sim in class NHibernate.DomainModel.Simple where sim.Other.Count=s.Other.Count ) and s.Other.Count > 0" )
508
+ . List ( ) . Count ) ;
500
509
}
501
510
502
511
IEnumerator enumer =
503
512
s . CreateQuery ( "select sum(s.Count) from s in class Simple group by s.Count having sum(s.Count) > 10 " ) . Enumerable ( )
504
513
. GetEnumerator ( ) ;
505
514
Assert . IsTrue ( enumer . MoveNext ( ) ) ;
506
- Assert . AreEqual ( 12 , ( Int64 ) enumer . Current ) ; // changed cast from Int32 to Int64 (H3.2)
515
+ Assert . AreEqual ( 12 , ( Int64 ) enumer . Current ) ; // changed cast from Int32 to Int64 (H3.2)
507
516
Assert . IsFalse ( enumer . MoveNext ( ) ) ;
508
517
509
518
if ( Dialect . SupportsSubSelects )
@@ -571,7 +580,7 @@ public void SQLFunctions()
571
580
list . Add ( "Simple 1" ) ;
572
581
list . Add ( "foo" ) ;
573
582
q . SetParameterList ( "name_list" , list ) ;
574
- q . SetParameter ( "count" , ( int ) - 1 ) ;
583
+ q . SetParameter ( "count" , ( int ) - 1 ) ;
575
584
Assert . AreEqual ( 1 , q . List ( ) . Count ) ;
576
585
577
586
s . Delete ( other ) ;
0 commit comments