Skip to content

Commit 335e336

Browse files
NH-3893 - isolating left()/right() failure in a dedicated test for all dialects.
1 parent c4b0aac commit 335e336

File tree

1 file changed

+58
-49
lines changed

1 file changed

+58
-49
lines changed

src/NHibernate.Test/Legacy/SQLFunctionsTest.cs

Lines changed: 58 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class SQLFunctionsTest : TestCase
2020

2121
protected override IList Mappings
2222
{
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" }; }
2424
}
2525

2626
[Test]
@@ -33,7 +33,7 @@ public void DialectSQLFunctions()
3333
.GetEnumerator();
3434

3535
if (Dialect is MySQLDialect
36-
// Added two dialects below for NH
36+
// Added two dialects below for NH
3737
|| Dialect is MsSql2000Dialect
3838
|| Dialect is PostgreSQLDialect)
3939
{
@@ -50,20 +50,20 @@ public void DialectSQLFunctions()
5050

5151
// Test to make sure allocating an specified object operates correctly.
5252
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);
5555

5656
// Quick check the base dialect functions operate correctly
5757
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);
5959
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);
6161

6262
if (Dialect is Oracle8iDialect)
6363
{
6464
// Check Oracle Dialect mix of dialect functions - no args (no parenthesis and single arg functions
6565
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];
6767
Assert.IsNotNull(row[0], "Name string should have been returned");
6868
Assert.IsNotNull(row[1], "Todays Date should have been returned");
6969
Assert.AreEqual(45f, row[2], "trunc(45.8) result was incorrect");
@@ -76,14 +76,6 @@ public void DialectSQLFunctions()
7676
rset = s.CreateQuery("select abs(round(s.Pay)) from s in class Simple").List();
7777
Assert.AreEqual(46f, rset[0], "abs(round(-45.8)) result was incorrect");
7878

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-
8779
// Test a larger depth 3 function example - Not a useful combo other than for testing
8880
Assert.AreEqual(1,
8981
s.CreateQuery("select trunc(round(length('A'))) from s in class Simple").List().Count);
@@ -112,14 +104,31 @@ supported on Hibernate side.
112104
s.Close();
113105
}
114106

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+
115124
[Test]
116125
public void SetProperties()
117126
{
118127
ISession s = OpenSession();
119128
ITransaction t = s.BeginTransaction();
120129
Simple simple = new Simple();
121130
simple.Name = "Simple 1";
122-
s.Save(simple, (long) 10);
131+
s.Save(simple, (long)10);
123132
IQuery q = s.CreateQuery("from s in class Simple where s.Name=:Name and s.Count=:Count");
124133
q.SetProperties(simple);
125134
Assert.AreEqual(simple, q.List()[0]);
@@ -155,7 +164,7 @@ public void Broken()
155164

156165
s = OpenSession();
157166
t = s.BeginTransaction();
158-
b = (Broken) s.Load(typeof(Broken), b);
167+
b = (Broken)s.Load(typeof(Broken), b);
159168
t.Commit();
160169
s.Close();
161170

@@ -173,19 +182,19 @@ public void NothingToUpdate()
173182
ITransaction t = s.BeginTransaction();
174183
Simple simple = new Simple();
175184
simple.Name = "Simple 1";
176-
s.Save(simple, (long) 10);
185+
s.Save(simple, (long)10);
177186
t.Commit();
178187
s.Close();
179188

180189
s = OpenSession();
181190
t = s.BeginTransaction();
182-
s.Update(simple, (long) 10);
191+
s.Update(simple, (long)10);
183192
t.Commit();
184193
s.Close();
185194

186195
s = OpenSession();
187196
t = s.BeginTransaction();
188-
s.Update(simple, (long) 10);
197+
s.Update(simple, (long)10);
189198
s.Delete(simple);
190199
t.Commit();
191200
s.Close();
@@ -218,7 +227,7 @@ public void CachedQuery()
218227
q.SetString("name", "Simple 1");
219228
Assert.AreEqual(1, q.List().Count);
220229

221-
simple = (Simple) q.List()[0];
230+
simple = (Simple)q.List()[0];
222231

223232
q.SetString("name", "Simple 2");
224233
Assert.AreEqual(0, q.List().Count);
@@ -296,7 +305,7 @@ public void SQLFunctionAsAlias()
296305
t = s.BeginTransaction();
297306
IList result = s.CreateQuery(query).List();
298307
Assert.IsTrue(result[0] is Simple,
299-
"Unexpected result type [" + result[0].GetType().Name + "]");
308+
"Unexpected result type [" + result[0].GetType().Name + "]");
300309
s.Delete(result[0]);
301310
t.Commit();
302311
s.Close();
@@ -384,7 +393,7 @@ public void CachedQueryRegion()
384393
q.SetCacheable(true);
385394
q.SetString("name", "Simple 1");
386395
Assert.AreEqual(1, q.List().Count);
387-
simple = (Simple) q.List()[0];
396+
simple = (Simple)q.List()[0];
388397

389398
q.SetString("name", "Simple 2");
390399
Assert.AreEqual(0, q.List().Count);
@@ -422,7 +431,7 @@ public void SQLFunctions()
422431
ITransaction t = s.BeginTransaction();
423432
Simple simple = new Simple();
424433
simple.Name = "Simple 1";
425-
s.Save(simple, (long) 10);
434+
s.Save(simple, (long)10);
426435

427436
if (Dialect is DB2Dialect)
428437
{
@@ -433,23 +442,23 @@ public void SQLFunctions()
433442

434443
Assert.AreEqual(1, s.CreateQuery("from s in class Simple where upper(s.Name) = 'SIMPLE 1'").List().Count);
435444
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);
439448

440449
if (!(Dialect is MySQLDialect) && !(Dialect is MsSql2000Dialect))
441450
{
442451
// Dialect.MckoiDialect and Dialect.InterbaseDialect also included
443452
// My Sql has a funny concatenation operator
444453
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);
446455
}
447456

448457
if ((Dialect is MsSql2000Dialect))
449458
{
450459
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);
453462
}
454463

455464
/*
@@ -464,46 +473,46 @@ public void SQLFunctions()
464473
other.Name = "Simple 2";
465474
other.Count = 12;
466475
simple.Other = other;
467-
s.Save(other, (long) 20);
476+
s.Save(other, (long)20);
468477
Assert.AreEqual(1, s.CreateQuery("from s in class Simple where upper( s.Other.Name )='SIMPLE 2'").List().Count);
469478
Assert.AreEqual(0, s.CreateQuery("from s in class Simple where not (upper(s.Other.Name)='SIMPLE 2')").List().Count);
470479
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);
474483
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);
478487

479488
Simple min = new Simple();
480489
min.Count = -1;
481490

482-
s.Save(min, (long) 30);
491+
s.Save(min, (long)30);
483492

484493
if (Dialect.SupportsSubSelects && TestDialect.SupportsOperatorSome)
485494
{
486495
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);
490499
t.Commit();
491500
t = s.BeginTransaction();
492501
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);
496505
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);
500509
}
501510

502511
IEnumerator enumer =
503512
s.CreateQuery("select sum(s.Count) from s in class Simple group by s.Count having sum(s.Count) > 10 ").Enumerable()
504513
.GetEnumerator();
505514
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)
507516
Assert.IsFalse(enumer.MoveNext());
508517

509518
if (Dialect.SupportsSubSelects)
@@ -571,7 +580,7 @@ public void SQLFunctions()
571580
list.Add("Simple 1");
572581
list.Add("foo");
573582
q.SetParameterList("name_list", list);
574-
q.SetParameter("count", (int) -1);
583+
q.SetParameter("count", (int)-1);
575584
Assert.AreEqual(1, q.List().Count);
576585

577586
s.Delete(other);

0 commit comments

Comments
 (0)