Skip to content

Commit 32c058a

Browse files
committed
Fix MySQL57 tests #87
1 parent 15415fc commit 32c058a

File tree

5 files changed

+852
-18
lines changed

5 files changed

+852
-18
lines changed

NHibernate.Spatial.MySQL/Dialect/MySQL57SpatialDialect.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,21 @@ public SqlString GetSpatialTransformString(object geometry, int srid)
228228
/// <returns></returns>
229229
public virtual SqlString GetSpatialValidationString(object geometry, SpatialValidation validation, bool criterion)
230230
{
231+
// In MySQL 5.7, the ST_Valid function requires geometries to have an SRID of 0
232+
// See: https://dev.mysql.com/doc/refman/5.7/en/spatial-convenience-functions.html#function_st-isvalid
233+
if (validation == SpatialValidation.IsValid)
234+
{
235+
return new SqlStringBuilder()
236+
.Add(DialectPrefix)
237+
.Add(validation.ToString())
238+
.Add("(")
239+
.Add("ST_GeomFromWKB(ST_AsWKB(")
240+
.AddObject(geometry)
241+
.Add("), 0)")
242+
.Add(")")
243+
.ToSqlString();
244+
}
245+
231246
return new SqlStringBuilder()
232247
.Add(DialectPrefix)
233248
.Add(validation.ToString())

NHibernate.Spatial.MySQL/Type/MySQL57GeometryType.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,6 @@ protected override void SetDefaultSRID(Geometry geometry)
5656
return null;
5757
}
5858

59-
// MySQL parses empty geometry as NULL
60-
if (geometry.IsEmpty)
61-
{
62-
return null; // TODO: Somehow specify an empty geometry and not just null.
63-
64-
// MySqlGeometry does not support empty geometry collections
65-
// so we simply return null for now. At some point we should to
66-
// use GeometryCollection.Empty here, when MySQL supports it.
67-
}
68-
6959
SetDefaultSRID(geometry);
7060
byte[] bytes = new MySQLWriter().Write(geometry);
7161
return new MySqlGeometry(MySqlDbType.Geometry, bytes);

Tests.NHibernate.Spatial.MySQL57/MySQL57NtsTestCasesFixture.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
using NHibernate.Cfg;
2-
using NHibernate.Spatial.Criterion;
32
using NUnit.Framework;
3+
using System.IO;
44
using Tests.NHibernate.Spatial.NtsTestCases;
55

66
namespace Tests.NHibernate.Spatial
77
{
88
[TestFixture]
99
public class MySQL57NtsTestCasesFixture : NtsTestCasesFixture
1010
{
11-
[Test]
12-
public override void IsValid()
13-
{
14-
TestBooleanUnaryOperation("IsValid", SpatialProjections.IsValid, SpatialRestrictions.IsValid);
15-
}
11+
private const string LocalDataPath = "../../../../Tests.NHibernate.Spatial.MySQL57/NtsTestCases/Data/vivid";
12+
13+
protected override string TestFunctionAAPrecDataPath => Path.Combine(LocalDataPath, "TestFunctionAAPrec.xml");
1614

1715
protected override void Configure(Configuration configuration)
1816
{

Tests.NHibernate.Spatial.MySQL57/MySQL57SpatialQueriesFixture.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using NHibernate;
22
using NHibernate.Cfg;
3+
using NHibernate.Spatial.Dialect;
34
using NUnit.Framework;
45
using Tests.NHibernate.Spatial.RandomGeometries;
56

@@ -46,7 +47,7 @@ protected override string SqlOvelapsLineString(string filterString)
4647
SELECT count(*)
4748
FROM linestringtest
4849
WHERE the_geom IS NOT NULL
49-
AND Overlaps(PolygonFromText('{filterString}', 4326), the_geom)
50+
AND {SpatialDialect.IsoPrefix}Overlaps(PolygonFromText('{filterString}', 4326), the_geom)
5051
";
5152
}
5253

@@ -56,7 +57,7 @@ protected override string SqlIntersectsLineString(string filterString)
5657
SELECT count(*)
5758
FROM linestringtest
5859
WHERE the_geom IS NOT NULL
59-
AND Intersects(PolygonFromText('{filterString}', 4326), the_geom)
60+
AND {SpatialDialect.IsoPrefix}Intersects(PolygonFromText('{filterString}', 4326), the_geom)
6061
";
6162
}
6263

0 commit comments

Comments
 (0)