Commit d3b7eb7b authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-7528 GIS: Functions return NULL instead of specified -1 for NULL arguments.

        The behaviour required by the standard seems too weird to expect.
parent 3e4126e9
...@@ -1111,7 +1111,7 @@ DROP TABLE t0, t1, t2; ...@@ -1111,7 +1111,7 @@ DROP TABLE t0, t1, t2;
# #
SELECT ISCLOSED(CONVERT(CONCAT(' ', 0x2), BINARY(20))); SELECT ISCLOSED(CONVERT(CONCAT(' ', 0x2), BINARY(20)));
ISCLOSED(CONVERT(CONCAT(' ', 0x2), BINARY(20))) ISCLOSED(CONVERT(CONCAT(' ', 0x2), BINARY(20)))
NULL -1
# #
# BUG#12537203 - CRASH WHEN SUBSELECTING GLOBAL VARIABLES IN # BUG#12537203 - CRASH WHEN SUBSELECTING GLOBAL VARIABLES IN
# GEOMETRY FUNCTION ARGUMENTS # GEOMETRY FUNCTION ARGUMENTS
...@@ -1810,3 +1810,9 @@ disjoint ...@@ -1810,3 +1810,9 @@ disjoint
select ST_Relate(ST_PointFromText('POINT(0 0)'),ST_PointFromText('POINT(0 0)'),'FF*FF****') as disjoint; select ST_Relate(ST_PointFromText('POINT(0 0)'),ST_PointFromText('POINT(0 0)'),'FF*FF****') as disjoint;
disjoint disjoint
0 0
#
# MDEV-7528 GIS: Functions return NULL instead of specified -1 for NULL arguments.
#
select ST_IsRing(NULL);
ST_IsRing(NULL)
-1
...@@ -1511,3 +1511,10 @@ select ST_Relate(ST_PointFromText('POINT(0 0)'),ST_PointFromText('POINT(0 0)'),' ...@@ -1511,3 +1511,10 @@ select ST_Relate(ST_PointFromText('POINT(0 0)'),ST_PointFromText('POINT(0 0)'),'
select ST_Relate(ST_PointFromText('POINT(0 0)'),ST_PointFromText('POINT(1 1)'),'FF*FF****') as disjoint; select ST_Relate(ST_PointFromText('POINT(0 0)'),ST_PointFromText('POINT(1 1)'),'FF*FF****') as disjoint;
select ST_Relate(ST_PointFromText('POINT(0 0)'),ST_PointFromText('POINT(0 0)'),'FF*FF****') as disjoint; select ST_Relate(ST_PointFromText('POINT(0 0)'),ST_PointFromText('POINT(0 0)'),'FF*FF****') as disjoint;
--echo #
--echo # MDEV-7528 GIS: Functions return NULL instead of specified -1 for NULL arguments.
--echo #
select ST_IsRing(NULL);
...@@ -1860,10 +1860,14 @@ longlong Item_func_issimple::val_int() ...@@ -1860,10 +1860,14 @@ longlong Item_func_issimple::val_int()
DBUG_ENTER("Item_func_issimple::val_int"); DBUG_ENTER("Item_func_issimple::val_int");
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
if ((null_value= (args[0]->null_value || null_value= 0;
if ((args[0]->null_value ||
!(g= Geometry::construct(&buffer, swkb->ptr(), swkb->length())) || !(g= Geometry::construct(&buffer, swkb->ptr(), swkb->length())) ||
g->get_mbr(&mbr, &c_end)))) g->get_mbr(&mbr, &c_end)))
DBUG_RETURN(0); {
/* We got NULL as an argument. Have to return -1 */
DBUG_RETURN(-1);
}
collector.set_extent(mbr.xmin, mbr.xmax, mbr.ymin, mbr.ymax); collector.set_extent(mbr.xmin, mbr.xmax, mbr.ymin, mbr.ymax);
...@@ -1924,11 +1928,15 @@ longlong Item_func_isclosed::val_int() ...@@ -1924,11 +1928,15 @@ longlong Item_func_isclosed::val_int()
Geometry *geom; Geometry *geom;
int isclosed= 0; // In case of error int isclosed= 0; // In case of error
null_value= (!swkb || null_value= 0;
if (!swkb ||
args[0]->null_value || args[0]->null_value ||
!(geom= !(geom= Geometry::construct(&buffer, swkb->ptr(), swkb->length())) ||
Geometry::construct(&buffer, swkb->ptr(), swkb->length())) || geom->is_closed(&isclosed))
geom->is_closed(&isclosed)); {
/* IsClosed(NULL) should return -1 */
return -1;
}
return (longlong) isclosed; return (longlong) isclosed;
} }
...@@ -1944,11 +1952,15 @@ longlong Item_func_isring::val_int() ...@@ -1944,11 +1952,15 @@ longlong Item_func_isring::val_int()
Geometry *geom; Geometry *geom;
int isclosed= 0; // In case of error int isclosed= 0; // In case of error
null_value= (!swkb || null_value= 0;
if (!swkb ||
args[0]->null_value || args[0]->null_value ||
!(geom= !(geom= Geometry::construct(&buffer, swkb->ptr(), swkb->length())) ||
Geometry::construct(&buffer, swkb->ptr(), swkb->length())) || geom->is_closed(&isclosed))
geom->is_closed(&isclosed)); {
/* IsRing(NULL) should return -1 */
return -1;
}
if (!isclosed) if (!isclosed)
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment