Skip to content

Commit

Permalink
MDEV-32619 Fix setting SRID with ST_*FromWKB()
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilian Krög <[email protected]>
  • Loading branch information
MoonE committed May 15, 2024
1 parent 32ee667 commit ab54516
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
27 changes: 27 additions & 0 deletions mysql-test/main/gis.result
Original file line number Diff line number Diff line change
Expand Up @@ -5435,5 +5435,32 @@ AsText(g)
POINT(1 1)
DROP TABLE t1;
#
# MDEV-32619 Settng SRID on geometry with ST_*FromWKKB(g, srid)
#
SELECT
ST_SRID(g1),
ST_SRID(ST_GeomFromWKB(g1, 4326)),
ST_SRID(ST_GeomFromWKB(g1)),
ST_AsText(g1),
ST_SRID(ST_PointFromWKB(g2, 4326)),
ST_SRID(g2),
ST_SRID(ST_LineStringFromWKB(g3, 3)),
ST_SRID(ST_PolygonFromWKB(g4, 4)),
ST_SRID(ST_MultiPointFromWKB(g5, 5)),
ST_SRID(ST_MultiLineStringFromWKB(g6, 6)),
ST_SRID(ST_MultiPolygonFromWKB(g7, 7))
FROM (
SELECT
POINT(1, 2) AS g1,
POINT(4, 3) AS g2,
LINESTRING(POINT(4, 3), POINT(4, 4)) AS g3,
POLYGON(LINESTRING(POINT(4, 3), POINT(4, 4), POINT(3, 4), POINT(4, 3))) AS g4,
MULTIPOINT(POINT(4, 3)) AS g5,
MULTILINESTRING(LINESTRING(POINT(4, 3), POINT(4, 4))) AS g6,
MULTIPOLYGON(POLYGON(LINESTRING(POINT(4, 3), POINT(4, 4), POINT(3, 4), POINT(4, 3)))) AS g7
) AS t;
ST_SRID(g1) ST_SRID(ST_GeomFromWKB(g1, 4326)) ST_SRID(ST_GeomFromWKB(g1)) ST_AsText(g1) ST_SRID(ST_PointFromWKB(g2, 4326)) ST_SRID(g2) ST_SRID(ST_LineStringFromWKB(g3, 3)) ST_SRID(ST_PolygonFromWKB(g4, 4)) ST_SRID(ST_MultiPointFromWKB(g5, 5)) ST_SRID(ST_MultiLineStringFromWKB(g6, 6)) ST_SRID(ST_MultiPolygonFromWKB(g7, 7))
0 4326 0 POINT(1 2) 4326 0 3 4 5 6 7
#
# End of 10.5 tests
#
26 changes: 26 additions & 0 deletions mysql-test/main/gis.test
Original file line number Diff line number Diff line change
Expand Up @@ -3438,6 +3438,32 @@ SHOW CREATE TABLE t1;
SELECT AsText(g) FROM t1;
DROP TABLE t1;

--echo #
--echo # MDEV-32619 Settng SRID on geometry with ST_*FromWKKB(g, srid)
--echo #
SELECT
ST_SRID(g1),
ST_SRID(ST_GeomFromWKB(g1, 4326)),
ST_SRID(ST_GeomFromWKB(g1)),
ST_AsText(g1),
ST_SRID(ST_PointFromWKB(g2, 4326)),
ST_SRID(g2),
ST_SRID(ST_LineStringFromWKB(g3, 3)),
ST_SRID(ST_PolygonFromWKB(g4, 4)),
ST_SRID(ST_MultiPointFromWKB(g5, 5)),
ST_SRID(ST_MultiLineStringFromWKB(g6, 6)),
ST_SRID(ST_MultiPolygonFromWKB(g7, 7))
FROM (
SELECT
POINT(1, 2) AS g1,
POINT(4, 3) AS g2,
LINESTRING(POINT(4, 3), POINT(4, 4)) AS g3,
POLYGON(LINESTRING(POINT(4, 3), POINT(4, 4), POINT(3, 4), POINT(4, 3))) AS g4,
MULTIPOINT(POINT(4, 3)) AS g5,
MULTILINESTRING(LINESTRING(POINT(4, 3), POINT(4, 4))) AS g6,
MULTIPOLYGON(POLYGON(LINESTRING(POINT(4, 3), POINT(4, 4), POINT(3, 4), POINT(4, 3)))) AS g7
) AS t;

--echo #
--echo # End of 10.5 tests
--echo #
9 changes: 9 additions & 0 deletions sql/item_geofunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ String *Item_func_geometry_from_wkb::val_str(String *str)
{
String *str_ret= args[0]->val_str(str);
null_value= args[0]->null_value;
if (!null_value && arg_count == 2 && !args[1]->null_value) {
srid= (uint32)args[1]->val_int();

if (str->copy(*str_ret))
return 0;

int4store(str->ptr(), srid);
return str;
}
return str_ret;
}

Expand Down

0 comments on commit ab54516

Please sign in to comment.