Skip to content

Commit

Permalink
MDEV-32619 Fix setting SRID with ST_*FromWKB().
Browse files Browse the repository at this point in the history
  second argument is handled in Item_func_geometry_from_wkb::val_str.
  contributed by Maximilian Krög <maxi_kroeg@web.de>
  • Loading branch information
Alexey Botchkov committed Jan 28, 2025
1 parent 7eded23 commit 47908d3
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 @@ -5474,4 +5474,31 @@ INSERT INTO t VALUES (1,POINT(0,0)),(2,POINT(0,0));
SELECT NTH_VALUE(a,b) OVER () FROM t;
ERROR HY000: Illegal parameter data types point and bigint for operation '-'
DROP TABLE t;
#
# 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 @@ -3482,4 +3482,30 @@ INSERT INTO t VALUES (1,POINT(0,0)),(2,POINT(0,0));
SELECT NTH_VALUE(a,b) OVER () FROM t;
DROP TABLE t;

--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 # End of 10.5 tests
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 47908d3

Please sign in to comment.