Skip to content

Commit 10d878c

Browse files
committed
Add GEOMCOLLECTION as data type alias. Fixes #845
1 parent 43bd227 commit 10d878c

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

src/MySqlConnector/Core/TypeMapper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ private TypeMapper()
9090
AddColumnTypeMetadata(new ColumnTypeMetadata("MULTILINESTRING", typeBinary, MySqlDbType.Geometry, binary: true));
9191
AddColumnTypeMetadata(new ColumnTypeMetadata("MULTIPOLYGON", typeBinary, MySqlDbType.Geometry, binary: true));
9292
AddColumnTypeMetadata(new ColumnTypeMetadata("GEOMETRYCOLLECTION", typeBinary, MySqlDbType.Geometry, binary: true));
93+
AddColumnTypeMetadata(new ColumnTypeMetadata("GEOMCOLLECTION", typeBinary, MySqlDbType.Geometry, binary: true));
9394

9495
// date/time
9596
var typeDate = AddDbTypeMapping(new DbTypeMapping(typeof(DateTime), new[] { DbType.Date }));

tests/SideBySide/DataTypes.cs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -965,17 +965,24 @@ public void GetMySqlDateTime(string columnName)
965965
}
966966
}
967967

968-
[Fact]
969-
public void QueryGeometry()
968+
[Theory]
969+
[InlineData("Geometry", "GEOMETRY", new byte[] { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 240, 63 })]
970+
[InlineData("Point", "GEOMETRY", new byte[] { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 240, 63 })]
971+
[InlineData("LineString", "GEOMETRY", new byte[] { 0, 0, 0, 0, 1, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 64 })]
972+
[InlineData("Polygon", "GEOMETRY", new byte[] { 0, 0, 0, 0, 1, 3, 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 })]
973+
[InlineData("MultiPoint", "GEOMETRY", new byte[] { 0, 0, 0, 0, 1, 4, 0, 0, 0, 3, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 240, 63, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 64, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 0, 0, 0, 0, 0, 0, 8, 64 })]
974+
[InlineData("MultiLineString", "GEOMETRY", new byte[] { 0, 0, 0, 0, 1, 5, 0, 0, 0, 2, 0, 0, 0, 1, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 64, 0, 0, 0, 0, 0, 0, 36, 64, 0, 0, 0, 0, 0, 0, 52, 64, 0, 0, 0, 0, 0, 0, 52, 64, 1, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 46, 64, 0, 0, 0, 0, 0, 0, 46, 64, 0, 0, 0, 0, 0, 0, 62, 64, 0, 0, 0, 0, 0, 0, 46, 64 })]
975+
[InlineData("MultiPolygon", "GEOMETRY", new byte[] { 0, 0, 0, 0, 1, 6, 0, 0, 0, 2, 0, 0, 0, 1, 3, 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 64, 0, 0, 0, 0, 0, 0, 36, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 64, 0, 0, 0, 0, 0, 0, 20, 64, 0, 0, 0, 0, 0, 0, 28, 64, 0, 0, 0, 0, 0, 0, 20, 64, 0, 0, 0, 0, 0, 0, 28, 64, 0, 0, 0, 0, 0, 0, 28, 64, 0, 0, 0, 0, 0, 0, 20, 64, 0, 0, 0, 0, 0, 0, 28, 64, 0, 0, 0, 0, 0, 0, 20, 64, 0, 0, 0, 0, 0, 0, 20, 64 })]
976+
[InlineData("GeometryCollection", "GEOMETRY", new byte[] { 0, 0, 0, 0, 1, 7, 0, 0, 0, 3, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 64, 0, 0, 0, 0, 0, 0, 36, 64, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 64, 0, 0, 0, 0, 0, 0, 62, 64, 1, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 46, 64, 0, 0, 0, 0, 0, 0, 46, 64, 0, 0, 0, 0, 0, 0, 52, 64, 0, 0, 0, 0, 0, 0, 52, 64 })]
977+
public void QueryGeometry(string columnName, string dataTypeName, byte[] expected)
970978
{
971979
var geometryData = new byte[][]
972980
{
973981
null,
974-
new byte[] { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 240, 63 },
975-
new byte[] { 0, 0, 0, 0, 1, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 64 }
982+
expected,
976983
};
977984

978-
DoQuery("geometry", "Geometry", "GEOMETRY", geometryData.ToArray(),
985+
DoQuery("geometry", columnName, dataTypeName, geometryData.ToArray(),
979986
#if !BASELINE
980987
GetBytes
981988
#else
@@ -984,7 +991,7 @@ public void QueryGeometry()
984991
#endif
985992
);
986993

987-
DoQuery<GetGeometryWhenNullException>("geometry", "Geometry", "GEOMETRY", geometryData.Select(CreateGeometry).ToArray(),
994+
DoQuery<GetGeometryWhenNullException>("geometry", columnName, dataTypeName, geometryData.Select(CreateGeometry).ToArray(),
988995
reader => reader.GetMySqlGeometry(0),
989996
matchesDefaultType: false,
990997
#if BASELINE
@@ -1071,6 +1078,13 @@ private static object CreateGeometry(byte[] data)
10711078
[InlineData("Year", "datatypes_times", MySqlDbType.Year, 4, typeof(int), "N", 0, 0)]
10721079
#endif
10731080
[InlineData("Geometry", "datatypes_geometry", MySqlDbType.Geometry, int.MaxValue, typeof(byte[]), "LN", 0, 0)]
1081+
[InlineData("Point", "datatypes_geometry", MySqlDbType.Geometry, int.MaxValue, typeof(byte[]), "LN", 0, 0)]
1082+
[InlineData("LineString", "datatypes_geometry", MySqlDbType.Geometry, int.MaxValue, typeof(byte[]), "LN", 0, 0)]
1083+
[InlineData("Polygon", "datatypes_geometry", MySqlDbType.Geometry, int.MaxValue, typeof(byte[]), "LN", 0, 0)]
1084+
[InlineData("MultiPoint", "datatypes_geometry", MySqlDbType.Geometry, int.MaxValue, typeof(byte[]), "LN", 0, 0)]
1085+
[InlineData("MultiLineString", "datatypes_geometry", MySqlDbType.Geometry, int.MaxValue, typeof(byte[]), "LN", 0, 0)]
1086+
[InlineData("MultiPolygon", "datatypes_geometry", MySqlDbType.Geometry, int.MaxValue, typeof(byte[]), "LN", 0, 0)]
1087+
[InlineData("GeometryCollection", "datatypes_geometry", MySqlDbType.Geometry, int.MaxValue, typeof(byte[]), "LN", 0, 0)]
10741088
public void GetSchemaTable(string column, string table, MySqlDbType mySqlDbType, int columnSize, Type dataType, string flags, int precision, int scale) =>
10751089
DoGetSchemaTable(column, table, mySqlDbType, columnSize, dataType, flags, precision, scale);
10761090

@@ -1241,6 +1255,13 @@ public void GetSchemaTableAfterNextResult()
12411255
[InlineData("Time", "datatypes_times", MySqlDbType.Time, "TIME", 17, typeof(TimeSpan), "N", -1, 6)]
12421256
[InlineData("Year", "datatypes_times", MySqlDbType.Year, "YEAR", 4, typeof(int), "N", -1, 0)]
12431257
[InlineData("Geometry", "datatypes_geometry", MySqlDbType.Geometry, "GEOMETRY", int.MaxValue, typeof(byte[]), "LN", -1, 0)]
1258+
[InlineData("Point", "datatypes_geometry", MySqlDbType.Geometry, "GEOMETRY", int.MaxValue, typeof(byte[]), "LN", -1, 0)]
1259+
[InlineData("LineString", "datatypes_geometry", MySqlDbType.Geometry, "GEOMETRY", int.MaxValue, typeof(byte[]), "LN", -1, 0)]
1260+
[InlineData("Polygon", "datatypes_geometry", MySqlDbType.Geometry, "GEOMETRY", int.MaxValue, typeof(byte[]), "LN", -1, 0)]
1261+
[InlineData("MultiPoint", "datatypes_geometry", MySqlDbType.Geometry, "GEOMETRY", int.MaxValue, typeof(byte[]), "LN", -1, 0)]
1262+
[InlineData("MultiLineString", "datatypes_geometry", MySqlDbType.Geometry, "GEOMETRY", int.MaxValue, typeof(byte[]), "LN", -1, 0)]
1263+
[InlineData("MultiPolygon", "datatypes_geometry", MySqlDbType.Geometry, "GEOMETRY", int.MaxValue, typeof(byte[]), "LN", -1, 0)]
1264+
[InlineData("GeometryCollection", "datatypes_geometry", MySqlDbType.Geometry, "GEOMETRY", int.MaxValue, typeof(byte[]), "LN", -1, 0)]
12441265
public void GetColumnSchema(string column, string table, MySqlDbType mySqlDbType, string dataTypeName, int columnSize, Type dataType, string flags, int precision, int scale)
12451266
{
12461267
if (table == "datatypes_json_core" && !AppConfig.SupportsJson)
@@ -1333,6 +1354,13 @@ public void GetColumnSchema(string column, string table, MySqlDbType mySqlDbType
13331354
#if !BASELINE
13341355
[InlineData("value", "datatypes_json_core", MySqlDbType.JSON, "JSON", typeof(string), 4, "[]")]
13351356
[InlineData("Geometry", "datatypes_geometry", MySqlDbType.Geometry, "GEOMETRY", typeof(byte[]), 2, null)]
1357+
[InlineData("Point", "datatypes_geometry", MySqlDbType.Geometry, "POINT", typeof(byte[]), 2, null)]
1358+
[InlineData("LineString", "datatypes_geometry", MySqlDbType.Geometry, "LINESTRING", typeof(byte[]), 2, null)]
1359+
[InlineData("Polygon", "datatypes_geometry", MySqlDbType.Geometry, "POLYGON", typeof(byte[]), 2, null)]
1360+
[InlineData("MultiPoint", "datatypes_geometry", MySqlDbType.Geometry, "MULTIPOINT", typeof(byte[]), 2, null)]
1361+
[InlineData("MultiLineString", "datatypes_geometry", MySqlDbType.Geometry, "MULTILINESTRING", typeof(byte[]), 2, null)]
1362+
[InlineData("MultiPolygon", "datatypes_geometry", MySqlDbType.Geometry, "MULTIPOLYGON", typeof(byte[]), 2, null)]
1363+
[InlineData("GeometryCollection", "datatypes_geometry", MySqlDbType.Geometry, "GEOMETRYCOLLECTION", typeof(byte[]), 2, null)]
13361364
#endif
13371365
public void StoredProcedureOutParameter(string column, string table, MySqlDbType mySqlDbType, string dataTypeName, Type dataType, int rowid, object expectedValue)
13381366
{

tests/SideBySide/DataTypesFixture.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,22 @@ insert into datatypes_guids (char38, char38bin, `text`, `blob`)
202202
drop table if exists datatypes_geometry;
203203
create table datatypes_geometry (
204204
rowid integer not null primary key auto_increment,
205-
`Geometry` geometry null
205+
`Geometry` geometry null,
206+
`Point` point null,
207+
`LineString` linestring null,
208+
`Polygon` polygon null,
209+
`MultiPoint` multipoint null,
210+
`MultiLineString` multilinestring null,
211+
`MultiPolygon` multipolygon null,
212+
`GeometryCollection` geometrycollection null
206213
);
207214
208-
insert into datatypes_geometry (`Geometry`)
215+
insert into datatypes_geometry (`Geometry`, `Point`, `LineString`, `Polygon`, `MultiPoint`, `MultiLineString`, `MultiPolygon`, `GeometryCollection`)
209216
values
210-
(null),
211-
(ST_GeomFromText('POINT(1 1)')),
212-
(ST_GeomFromText('LINESTRING(0 0,1 1,2 2)'));
217+
(null, null, null, null, null, null, null, null),
218+
(ST_GeomFromText('POINT(1 1)'), ST_PointFromText('POINT(1 1)'), ST_LineFromText('LINESTRING(0 0,1 1,2 2)'), ST_PolyFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))'),
219+
ST_GeomFromText('MULTIPOINT(1 1, 2 2, 3 3)'), ST_GeomFromText('MULTILINESTRING((10 10, 20 20), (15 15, 30 15))'), ST_GeomFromText('MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)),((5 5,7 5,7 7,5 7, 5 5)))'),
220+
ST_GeomCollFromText('GEOMETRYCOLLECTION(POINT(10 10), POINT(30 30), LINESTRING(15 15, 20 20))'));
213221
");
214222

215223
if (AppConfig.SupportsJson)

0 commit comments

Comments
 (0)