@@ -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,11 +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
- rset = s . CreateQuery ( "select left('abc', 2), right('abc', 2) from s in class Simple" ) . List ( ) ;
80
- row = ( object [ ] ) rset [ 0 ] ;
81
- Assert . AreEqual ( "ab" , row [ 0 ] , "Left function is broken." ) ;
82
- Assert . AreEqual ( "bc" , row [ 1 ] , "Right function is broken." ) ;
83
-
84
79
// Test a larger depth 3 function example - Not a useful combo other than for testing
85
80
Assert . AreEqual ( 1 ,
86
81
s . CreateQuery ( "select trunc(round(length('A'))) from s in class Simple" ) . List ( ) . Count ) ;
@@ -109,14 +104,31 @@ public void DialectSQLFunctions()
109
104
s . Close ( ) ;
110
105
}
111
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
+
112
124
[ Test ]
113
125
public void SetProperties ( )
114
126
{
115
127
ISession s = OpenSession ( ) ;
116
128
ITransaction t = s . BeginTransaction ( ) ;
117
129
Simple simple = new Simple ( ) ;
118
130
simple . Name = "Simple 1" ;
119
- s . Save ( simple , ( long ) 10 ) ;
131
+ s . Save ( simple , ( long ) 10 ) ;
120
132
IQuery q = s . CreateQuery ( "from s in class Simple where s.Name=:Name and s.Count=:Count" ) ;
121
133
q . SetProperties ( simple ) ;
122
134
Assert . AreEqual ( simple , q . List ( ) [ 0 ] ) ;
@@ -152,7 +164,7 @@ public void Broken()
152
164
153
165
s = OpenSession ( ) ;
154
166
t = s . BeginTransaction ( ) ;
155
- b = ( Broken ) s . Load ( typeof ( Broken ) , b ) ;
167
+ b = ( Broken ) s . Load ( typeof ( Broken ) , b ) ;
156
168
t . Commit ( ) ;
157
169
s . Close ( ) ;
158
170
@@ -170,19 +182,19 @@ public void NothingToUpdate()
170
182
ITransaction t = s . BeginTransaction ( ) ;
171
183
Simple simple = new Simple ( ) ;
172
184
simple . Name = "Simple 1" ;
173
- s . Save ( simple , ( long ) 10 ) ;
185
+ s . Save ( simple , ( long ) 10 ) ;
174
186
t . Commit ( ) ;
175
187
s . Close ( ) ;
176
188
177
189
s = OpenSession ( ) ;
178
190
t = s . BeginTransaction ( ) ;
179
- s . Update ( simple , ( long ) 10 ) ;
191
+ s . Update ( simple , ( long ) 10 ) ;
180
192
t . Commit ( ) ;
181
193
s . Close ( ) ;
182
194
183
195
s = OpenSession ( ) ;
184
196
t = s . BeginTransaction ( ) ;
185
- s . Update ( simple , ( long ) 10 ) ;
197
+ s . Update ( simple , ( long ) 10 ) ;
186
198
s . Delete ( simple ) ;
187
199
t . Commit ( ) ;
188
200
s . Close ( ) ;
@@ -215,7 +227,7 @@ public void CachedQuery()
215
227
q . SetString ( "name" , "Simple 1" ) ;
216
228
Assert . AreEqual ( 1 , q . List ( ) . Count ) ;
217
229
218
- simple = ( Simple ) q . List ( ) [ 0 ] ;
230
+ simple = ( Simple ) q . List ( ) [ 0 ] ;
219
231
220
232
q . SetString ( "name" , "Simple 2" ) ;
221
233
Assert . AreEqual ( 0 , q . List ( ) . Count ) ;
@@ -293,7 +305,7 @@ public void SQLFunctionAsAlias()
293
305
t = s . BeginTransaction ( ) ;
294
306
IList result = s . CreateQuery ( query ) . List ( ) ;
295
307
Assert . IsTrue ( result [ 0 ] is Simple ,
296
- "Unexpected result type [" + result [ 0 ] . GetType ( ) . Name + "]" ) ;
308
+ "Unexpected result type [" + result [ 0 ] . GetType ( ) . Name + "]" ) ;
297
309
s . Delete ( result [ 0 ] ) ;
298
310
t . Commit ( ) ;
299
311
s . Close ( ) ;
@@ -381,7 +393,7 @@ public void CachedQueryRegion()
381
393
q . SetCacheable ( true ) ;
382
394
q . SetString ( "name" , "Simple 1" ) ;
383
395
Assert . AreEqual ( 1 , q . List ( ) . Count ) ;
384
- simple = ( Simple ) q . List ( ) [ 0 ] ;
396
+ simple = ( Simple ) q . List ( ) [ 0 ] ;
385
397
386
398
q . SetString ( "name" , "Simple 2" ) ;
387
399
Assert . AreEqual ( 0 , q . List ( ) . Count ) ;
@@ -419,7 +431,7 @@ public void SQLFunctions()
419
431
ITransaction t = s . BeginTransaction ( ) ;
420
432
Simple simple = new Simple ( ) ;
421
433
simple . Name = "Simple 1" ;
422
- s . Save ( simple , ( long ) 10 ) ;
434
+ s . Save ( simple , ( long ) 10 ) ;
423
435
424
436
if ( Dialect is DB2Dialect )
425
437
{
@@ -430,23 +442,23 @@ public void SQLFunctions()
430
442
431
443
Assert . AreEqual ( 1 , s . CreateQuery ( "from s in class Simple where upper(s.Name) = 'SIMPLE 1'" ) . List ( ) . Count ) ;
432
444
Assert . AreEqual ( 1 ,
433
- s . CreateQuery (
434
- "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')" )
435
- . 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 ) ;
436
448
437
449
if ( ! ( Dialect is MySQLDialect ) && ! ( Dialect is MsSql2000Dialect ) )
438
450
{
439
451
// Dialect.MckoiDialect and Dialect.InterbaseDialect also included
440
452
// My Sql has a funny concatenation operator
441
453
Assert . AreEqual ( 1 ,
442
- 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 ) ;
443
455
}
444
456
445
457
if ( ( Dialect is MsSql2000Dialect ) )
446
458
{
447
459
Assert . AreEqual ( 1 ,
448
- s . CreateQuery ( "from s in class Simple where lower( s.Name + ' foo' ) = 'simple 1 foo'" ) . List ( ) .
449
- Count ) ;
460
+ s . CreateQuery ( "from s in class Simple where lower( s.Name + ' foo' ) = 'simple 1 foo'" ) . List ( ) .
461
+ Count ) ;
450
462
}
451
463
452
464
/*
@@ -461,46 +473,46 @@ public void SQLFunctions()
461
473
other . Name = "Simple 2" ;
462
474
other . Count = 12 ;
463
475
simple . Other = other ;
464
- s . Save ( other , ( long ) 20 ) ;
476
+ s . Save ( other , ( long ) 20 ) ;
465
477
Assert . AreEqual ( 1 , s . CreateQuery ( "from s in class Simple where upper( s.Other.Name )='SIMPLE 2'" ) . List ( ) . Count ) ;
466
478
Assert . AreEqual ( 0 , s . CreateQuery ( "from s in class Simple where not (upper(s.Other.Name)='SIMPLE 2')" ) . List ( ) . Count ) ;
467
479
Assert . AreEqual ( 1 ,
468
- s . CreateQuery (
469
- "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" )
470
- . 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 ) ;
471
483
Assert . AreEqual ( 1 ,
472
- s . CreateQuery (
473
- "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" )
474
- . 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 ) ;
475
487
476
488
Simple min = new Simple ( ) ;
477
489
min . Count = - 1 ;
478
490
479
- s . Save ( min , ( long ) 30 ) ;
491
+ s . Save ( min , ( long ) 30 ) ;
480
492
481
493
if ( Dialect . SupportsSubSelects && TestDialect . SupportsOperatorSome )
482
494
{
483
495
Assert . AreEqual ( 2 ,
484
- s . CreateQuery (
485
- "from s in class Simple where s.Count > ( select min(sim.Count) from sim in class NHibernate.DomainModel.Simple )" )
486
- . 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 ) ;
487
499
t . Commit ( ) ;
488
500
t = s . BeginTransaction ( ) ;
489
501
Assert . AreEqual ( 2 ,
490
- s . CreateQuery (
491
- "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" )
492
- . 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 ) ;
493
505
Assert . AreEqual ( 1 ,
494
- s . CreateQuery (
495
- "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" )
496
- . 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 ) ;
497
509
}
498
510
499
511
IEnumerator enumer =
500
512
s . CreateQuery ( "select sum(s.Count) from s in class Simple group by s.Count having sum(s.Count) > 10 " ) . Enumerable ( )
501
513
. GetEnumerator ( ) ;
502
514
Assert . IsTrue ( enumer . MoveNext ( ) ) ;
503
- 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)
504
516
Assert . IsFalse ( enumer . MoveNext ( ) ) ;
505
517
506
518
if ( Dialect . SupportsSubSelects )
@@ -568,7 +580,7 @@ public void SQLFunctions()
568
580
list . Add ( "Simple 1" ) ;
569
581
list . Add ( "foo" ) ;
570
582
q . SetParameterList ( "name_list" , list ) ;
571
- q . SetParameter ( "count" , ( int ) - 1 ) ;
583
+ q . SetParameter ( "count" , ( int ) - 1 ) ;
572
584
Assert . AreEqual ( 1 , q . List ( ) . Count ) ;
573
585
574
586
s . Delete ( other ) ;
0 commit comments