Skip to content

Commit 17b038f

Browse files
NH-4004 - More SqlCe tests fixes.
1 parent 0230648 commit 17b038f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+464
-195
lines changed

src/NHibernate.Test/CompositeId/CompositeIdFixture.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections;
3+
using NHibernate.Dialect;
34
using NUnit.Framework;
45

56
namespace NHibernate.Test.CompositeId
@@ -29,6 +30,12 @@ protected override string CacheConcurrencyStrategy
2930
get { return null; }
3031
}
3132

33+
protected override bool AppliesTo(Dialect.Dialect dialect)
34+
{
35+
// Order uses a scalar sub-select formula.
36+
return Dialect.SupportsScalarSubSelects;
37+
}
38+
3239
[Test]
3340
public void CompositeIds()
3441
{

src/NHibernate.Test/Hql/Ast/HqlFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,4 +341,4 @@ public void UnaryMinusBeforeParenthesesHandledCorrectly()
341341
}
342342
}
343343
}
344-
}
344+
}

src/NHibernate.Test/Hql/Ast/WithClauseFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,4 @@ public void Cleanup()
163163
}
164164
}
165165
}
166-
}
166+
}

src/NHibernate.Test/Hql/HQLFunctions.cs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ static HQLFunctions()
2121
{"locate", new[] {typeof (SQLiteDialect)}},
2222
{"bit_length", new[] {typeof (SQLiteDialect)}},
2323
{"extract", new[] {typeof (SQLiteDialect)}},
24-
{"nullif", new[] {typeof (Oracle8iDialect)}}
24+
{
25+
"nullif",
26+
new[]
27+
{
28+
typeof (Oracle8iDialect),
29+
// Actually not supported by the db engine. (Well, could likely still be done with a case when override.)
30+
typeof (MsSqlCeDialect),
31+
typeof (MsSqlCe40Dialect)
32+
}}
2533
};
2634
}
2735

@@ -74,9 +82,13 @@ public void AggregateCount()
7482
using (ISession s = OpenSession())
7583
{
7684
// Count in select
77-
object result = s.CreateQuery("select count(distinct a.id) from Animal a").UniqueResult();
78-
Assert.AreEqual(typeof(long), result.GetType());
79-
Assert.AreEqual(2, result);
85+
object result;
86+
if (TestDialect.SupportsCountDistinct)
87+
{
88+
result = s.CreateQuery("select count(distinct a.id) from Animal a").UniqueResult();
89+
Assert.AreEqual(typeof(long), result.GetType());
90+
Assert.AreEqual(2, result);
91+
}
8092

8193
result = s.CreateQuery("select count(*) from Animal").UniqueResult();
8294
Assert.AreEqual(typeof(long), result.GetType());
@@ -758,6 +770,17 @@ public void Cast()
758770
if (!ex.InnerException.Message.Contains(msgToCheck))
759771
throw;
760772
}
773+
else if (Dialect is MsSqlCeDialect)
774+
{
775+
var errorCodeProperty = ex.InnerException.GetType().GetProperty("NativeError");
776+
if (errorCodeProperty == null ||
777+
// 25515 is the error code for "In aggregate and grouping expressions, the SELECT clause can contain only aggregates and grouping expressions."
778+
// https://technet.microsoft.com/en-us/library/ms172350(v=sql.110).aspx
779+
errorCodeProperty.GetValue(ex.InnerException) as int? != 25515)
780+
{
781+
throw;
782+
}
783+
}
761784
else
762785
{
763786
string msgToCheck =
@@ -864,6 +887,7 @@ public void Current_TimeStamp_Offset()
864887
public void Extract()
865888
{
866889
IgnoreIfNotSupported("extract");
890+
IgnoreIfNotSupported("current_timestamp");
867891

868892
// test only the parser and render
869893
using (ISession s = OpenSession())
@@ -906,6 +930,9 @@ public void Concat()
906930
public void HourMinuteSecond()
907931
{
908932
IgnoreIfNotSupported("second");
933+
IgnoreIfNotSupported("minute");
934+
IgnoreIfNotSupported("hour");
935+
IgnoreIfNotSupported("current_timestamp");
909936
// test only the parser and render
910937
using (ISession s = OpenSession())
911938
{
@@ -997,6 +1024,7 @@ from MaterialResource mr
9971024
[Test]
9981025
public void NH1725()
9991026
{
1027+
IgnoreIfNotSupported("iif");
10001028
// Only to test the parser
10011029
using (ISession s = OpenSession())
10021030
{

src/NHibernate.Test/Immutable/EntityWithMutableCollection/AbstractEntityWithOneToManyTest.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,23 @@ public virtual void OneToManyCollectionOptimisticLockingWithUpdate()
12231223
s = OpenSession();
12241224
t = s.BeginTransaction();
12251225
c = s.CreateCriteria<Contract>().UniqueResult<Contract>();
1226-
s.CreateQuery("delete from Party").ExecuteUpdate();
1226+
// If the entity uses a join mapping, DML queries require temp tables.
1227+
if (Dialect.SupportsTemporaryTables)
1228+
s.CreateQuery("delete from Party").ExecuteUpdate();
1229+
else
1230+
{
1231+
// The current join mapping seems a bit invalid or unsupported.
1232+
// The party_contract join table is optional, but its FK is not-nullable. The test removes the contract
1233+
// from both parties (explicitly for partyOrig, indirectly by updating cOrig instead of c for newParty),
1234+
// and it the appears those parties are no more loadable, failing with a "not-null property references a
1235+
// null or transient value NHibernate.Test.Immutable.EntityWithMutableCollection.Party.Contract".
1236+
// So we need to "fix" already previously loaded instances before deleting them.
1237+
partyOrig.Contract = cOrig;
1238+
newParty.Contract = cOrig;
1239+
s.Delete(partyOrig);
1240+
s.Delete(newParty);
1241+
}
1242+
12271243
s.Delete(c);
12281244
Assert.That(s.CreateCriteria<Contract>().SetProjection(Projections.RowCountInt64()).UniqueResult<long>(), Is.EqualTo(0L));
12291245
Assert.That(s.CreateCriteria<Party>().SetProjection(Projections.RowCountInt64()).UniqueResult<long>(), Is.EqualTo(0L));

src/NHibernate.Test/Legacy/ABCTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public void HigherLevelIndexDefinitionInPropertyTag()
3939
[Test]
4040
public void Subselect()
4141
{
42+
if (!Dialect.SupportsScalarSubSelects)
43+
Assert.Ignore("Dialect does not support scalar sub-select, used by Map formula in B (C1 and C2) mapping");
4244
using (ISession s = OpenSession())
4345
using (ITransaction t = s.BeginTransaction())
4446
{
@@ -78,6 +80,8 @@ public void Subselect()
7880
[Test]
7981
public void Subclassing()
8082
{
83+
if (!Dialect.SupportsScalarSubSelects)
84+
Assert.Ignore("Dialect does not support scalar sub-select, used by Map formula in B (C1 and C2) mapping");
8185
ISession s = OpenSession();
8286
ITransaction t = s.BeginTransaction();
8387
C1 c1 = new C1();

src/NHibernate.Test/Legacy/FooBarTest.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,14 @@ public void Query()
522522
Assert.AreEqual(2, list.Count, "component query");
523523
}
524524

525-
list =
526-
s.CreateQuery("from foo in class NHibernate.DomainModel.Foo where size(foo.Component.ImportantDates) = 3").List();
527-
Assert.AreEqual(2, list.Count, "component query");
528-
list = s.CreateQuery("from foo in class Foo where 0 = size(foo.Component.ImportantDates)").List();
529-
Assert.AreEqual(0, list.Count, "component query");
525+
if (Dialect.SupportsScalarSubSelects)
526+
{
527+
list =
528+
s.CreateQuery("from foo in class NHibernate.DomainModel.Foo where size(foo.Component.ImportantDates) = 3").List();
529+
Assert.AreEqual(2, list.Count, "component query");
530+
list = s.CreateQuery("from foo in class Foo where 0 = size(foo.Component.ImportantDates)").List();
531+
Assert.AreEqual(0, list.Count, "component query");
532+
}
530533
list = s.CreateQuery("from foo in class Foo where exists elements(foo.Component.ImportantDates)").List();
531534
Assert.AreEqual(2, list.Count, "component query");
532535
s.CreateQuery("from foo in class Foo where not exists (from bar in class Bar where bar.id = foo.id)").List();
@@ -1095,7 +1098,8 @@ public void QueryCollectionOfValues()
10951098

10961099
if (Dialect.SupportsSubSelects)
10971100
{
1098-
s.CreateFilter(baz.FooArray, "where size(this.Bytes) > 0").List();
1101+
if (Dialect.SupportsScalarSubSelects)
1102+
s.CreateFilter(baz.FooArray, "where size(this.Bytes) > 0").List();
10991103
s.CreateFilter(baz.FooArray, "where 0 in elements(this.Bytes)").List();
11001104
}
11011105
s.Flush();
@@ -2385,7 +2389,7 @@ public void CompositeKeyPathExpressions()
23852389
hql = "from fum1 in class Fum where fum1.Fo.FumString is not null order by fum1.Fo.FumString";
23862390
s.CreateQuery(hql).List();
23872391

2388-
if (Dialect.SupportsSubSelects)
2392+
if (Dialect.SupportsScalarSubSelects)
23892393
{
23902394
hql = "from fum1 in class Fum where size(fum1.Friends) = 0";
23912395
s.CreateQuery(hql).List();
@@ -2461,7 +2465,7 @@ public void CollectionsInSelect()
24612465
s.CreateQuery("select count(*) from Bar as bar where 1 in indices(bar.Baz.FooArray)").List();
24622466
s.CreateQuery(
24632467
"select count(*) from Bar as bar where '1' in (from bar.Component.Glarch.ProxyArray g where g.Name='foo')").List();
2464-
2468+
24652469
// The nex query is wrong and is not present in H3.2:
24662470
// The SQL result, from Classic parser, is the same of the previous query.
24672471
// The AST parser has some problem to parse 'from g in bar.Component.Glarch.ProxyArray'
@@ -2472,7 +2476,9 @@ public void CollectionsInSelect()
24722476

24732477
// TODO: figure out why this is throwing an ORA-1722 error
24742478
// probably the conversion ProxyArray.id (to_number ensuring a not null value)
2475-
if (!(Dialect is Oracle8iDialect))
2479+
// Indeed, ProxyArray.id is Glarch.tha_key which is a string filled with a Guid. It does
2480+
// not fail with most engine likely because there are no results thanks to other conditions.
2481+
if (!(Dialect is Oracle8iDialect) && !(Dialect is MsSqlCeDialect))
24762482
{
24772483
s.CreateQuery(
24782484
"select count(*) from Bar as bar join bar.Component.Glarch.ProxyArray as g where cast(g.id as Int32) in indices(bar.Baz.FooArray)").

src/NHibernate.Test/Legacy/FumTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,8 @@ public void CompositeKeyPathExpressions()
598598
if (Dialect.SupportsSubSelects)
599599
{
600600
s.CreateQuery("from fum1 in class Fum where exists elements(fum1.Friends)").List();
601-
s.CreateQuery("from fum1 in class Fum where size(fum1.Friends) = 0").List();
601+
if (Dialect.SupportsScalarSubSelects)
602+
s.CreateQuery("from fum1 in class Fum where size(fum1.Friends) = 0").List();
602603
}
603604
s.CreateQuery("select elements(fum1.Friends) from fum1 in class Fum").List();
604605
s.CreateQuery("from fum1 in class Fum, fr in elements( fum1.Friends )").List();

src/NHibernate.Test/Legacy/MasterDetailTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ public void MasterDetail()
401401
master.AddDetail(d1);
402402
master.AddDetail(d2);
403403

404-
if (Dialect.SupportsSubSelects)
404+
if (Dialect.SupportsScalarSubSelects)
405405
{
406406
string hql = "from d in class NHibernate.DomainModel.Detail, m in class NHibernate.DomainModel.Master " +
407407
"where m = d.Master and m.Outgoing.size = 0 and m.Incoming.size = 0";

src/NHibernate.Test/Legacy/ParentChildTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ public void CollectionQuery()
387387
Assert.AreEqual(1,
388388
s.CreateQuery("select c from c in class ContainerX where 's' = c.ManyToMany[(3+1)/4-1].Name").List().
389389
Count);
390-
if (Dialect.SupportsSubSelects)
390+
if (Dialect.SupportsScalarSubSelects)
391391
{
392392
Assert.AreEqual(1,
393393
s.CreateQuery(

src/NHibernate.Test/Legacy/SQLFunctionsTest.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,11 +492,14 @@ public void SQLFunctions()
492492

493493
if (Dialect.SupportsSubSelects && TestDialect.SupportsOperatorSome)
494494
{
495-
Assert.AreEqual(2,
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);
499-
t.Commit();
495+
if (Dialect.SupportsScalarSubSelects)
496+
{
497+
Assert.AreEqual(2,
498+
s.CreateQuery(
499+
"from s in class Simple where s.Count > ( select min(sim.Count) from sim in class NHibernate.DomainModel.Simple )")
500+
.List().Count);
501+
t.Commit();
502+
}
500503
t = s.BeginTransaction();
501504
Assert.AreEqual(2,
502505
s.CreateQuery(

src/NHibernate.Test/Legacy/SQLLoaderTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ public void EscapedODBC()
333333
[Test]
334334
public void DoubleAliasing()
335335
{
336-
if (Dialect is MySQLDialect) return;
337-
if (Dialect is FirebirdDialect) return; // See comment below
336+
if (!Dialect.SupportsScalarSubSelects)
337+
Assert.Ignore("Dialect does not support scalar sub-select, used by Map formula in B (C1 and C2) mapping");
338338

339339
ISession session = OpenSession();
340340

@@ -364,7 +364,6 @@ public void DoubleAliasing()
364364
Assert.IsNotNull(list);
365365

366366
Assert.AreEqual(2, list.Count);
367-
// On Firebird the list has 4 elements, I don't understand why.
368367

369368
session.Delete("from A");
370369
session.Flush();
@@ -582,7 +581,8 @@ public void FindBySQLDiscriminatorSameSession()
582581
[Test]
583582
public void FindBySQLDiscriminatedDiffSessions()
584583
{
585-
if (Dialect is MySQLDialect) return;
584+
if (!Dialect.SupportsScalarSubSelects)
585+
Assert.Ignore("Dialect does not support scalar sub-select, used by Map formula in B (C1 and C2) mapping");
586586

587587
ISession session = OpenSession();
588588
A savedA = new A();

src/NHibernate.Test/Linq/ByMethod/AnyTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public void ManyToManyAny()
4141
[Test(Description = "NH-2654")]
4242
public void AnyWithCount()
4343
{
44+
if (!Dialect.SupportsScalarSubSelects)
45+
Assert.Ignore("Dialect does not support scalar sub-selects");
46+
4447
var result = db.Orders
4548
.Any(p => p.OrderLines.Count == 0);
4649

src/NHibernate.Test/Linq/ByMethod/CountTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ protected override void Configure(Configuration configuration)
1616
[Test]
1717
public void CountDistinctProperty_ReturnsNumberOfDistinctEntriesForThatProperty()
1818
{
19+
if (!TestDialect.SupportsCountDistinct)
20+
Assert.Ignore("Dialect does not support count distinct");
1921
//NH-2722
2022
var result = db.Orders
2123
.Select(x => x.ShippingDate)
@@ -49,6 +51,8 @@ public void Count_ReturnsNumberOfRecords()
4951
[Test]
5052
public void LongCountDistinctProperty_ReturnsNumberOfDistinctEntriesForThatProperty()
5153
{
54+
if (!TestDialect.SupportsCountDistinct)
55+
Assert.Ignore("Dialect does not support count distinct");
5256
//NH-2722
5357
var result = db.Orders
5458
.Select(x => x.ShippingDate)

src/NHibernate.Test/Linq/ByMethod/GroupByTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public void SingleKeyGroupAndOrderByKey()
8888
[Test]
8989
public void SingleKeyGroupAndOrderByKeyAggregateProjection()
9090
{
91+
if (!TestDialect.SupportsOrderByAggregate)
92+
Assert.Ignore("Dialect does not support ordering by an aggregation");
93+
9194
//NH-2452
9295
var result = db.Products
9396
.GroupBy(i => i.UnitPrice)
@@ -106,6 +109,9 @@ public void SingleKeyGroupAndOrderByKeyAggregateProjection()
106109
[Test]
107110
public void SingleKeyPropertyGroupAndOrderByProjectedCount()
108111
{
112+
if (!TestDialect.SupportsOrderByAggregate)
113+
Assert.Ignore("Dialect does not support ordering by an aggregation");
114+
109115
// NH-2560
110116

111117
var orderCounts = db.Orders
@@ -126,6 +132,9 @@ public void SingleKeyPropertyGroupAndOrderByProjectedCount()
126132
[Test]
127133
public void SingleKeyPropertyGroupAndOrderByCountBeforeProjection()
128134
{
135+
if (!TestDialect.SupportsOrderByAggregate)
136+
Assert.Ignore("Dialect does not support ordering by an aggregation");
137+
129138
// NH-3026, variation of NH-2560.
130139
// This is a variation of SingleKeyPropertyGroupAndOrderByProjectedCount()
131140
// that puts the ordering expression inside the OrderBy, without first
@@ -216,6 +225,8 @@ public void SingleKeyPropertyGroupByEntityAndSelectEntity()
216225
[Test]
217226
public void SingleKeyGroupAndOrderByNonKeyAggregateProjection()
218227
{
228+
if (!TestDialect.SupportsOrderByAggregate)
229+
Assert.Ignore("Dialect does not support ordering by an aggregation");
219230
//NH-2452
220231
var result = db.Products
221232
.GroupBy(p => p.UnitPrice)
@@ -448,6 +459,9 @@ public void FilteredByCountWithPredicate()
448459
[Test]
449460
public void FilteredByCountFromSubQuery()
450461
{
462+
if (!Dialect.SupportsScalarSubSelects)
463+
Assert.Ignore("Dialect does not support scalar sub-selects");
464+
451465
//Not really an aggregate filter, but included to ensure that this kind of query still works
452466
var result = db.Products
453467
.GroupBy(x => x.Supplier.CompanyName)
@@ -498,6 +512,9 @@ public void FilteredByKeyAndProjectedWithAggregatePredicates()
498512
[Test]
499513
public void ProjectingWithSubQueriesFilteredByTheAggregateKey()
500514
{
515+
if (!Dialect.SupportsScalarSubSelects)
516+
Assert.Ignore("Dialect does not support scalar sub-selects");
517+
501518
var result=db.Products.GroupBy(x => x.Supplier.Address.Country)
502519
.OrderBy(x=>x.Key)
503520
.Select(x => new { x.Key, MaxFreight = db.Orders.Where(y => y.ShippingAddress.Country == x.Key).Max(y => y.Freight), FirstOrder = db.Orders.Where(o => o.Employee.FirstName.StartsWith("A")).OrderBy(o => o.OrderId).Select(y => y.OrderId).First() })

0 commit comments

Comments
 (0)