From: Sandro Santilli Date: Thu, 14 Jun 2012 16:06:54 +0000 (+0000) Subject: Catch invalid topology name passed to topogeo_add* (#1867) X-Git-Tag: 2.1.0beta2~909 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a5532e02b7e559667b414f4b8b499057aa89a950;p=postgis Catch invalid topology name passed to topogeo_add* (#1867) git-svn-id: http://svn.osgeo.org/postgis/trunk@9908 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/topology/sql/populate.sql.in.c b/topology/sql/populate.sql.in.c index 70953b6b8..492e3606e 100644 --- a/topology/sql/populate.sql.in.c +++ b/topology/sql/populate.sql.in.c @@ -42,18 +42,27 @@ $$ LANGUAGE 'sql' IMMUTABLE STRICT; -- { -- Get tolerance for a given topology --- and if zero the min for a given topology +-- and if zero the minimum for the given geometry -- -- }{ CREATE OR REPLACE FUNCTION topology._st_mintolerance(atopology varchar, ageom Geometry) RETURNS float8 AS $$ +DECLARE + ret FLOAT8; +BEGIN SELECT COALESCE( NULLIF(precision, 0), topology._st_mintolerance($2)) FROM topology.topology - WHERE name = $1; -$$ LANGUAGE 'sql' STABLE STRICT; + WHERE name = $1 INTO ret; + IF NOT FOUND THEN + RAISE EXCEPTION + 'No topology with name "%" in topology.topology', atopology; + END IF; + return ret; +END; +$$ LANGUAGE 'plpgsql' STABLE STRICT; -- } --{ diff --git a/topology/test/regress/topogeo_addlinestring.sql b/topology/test/regress/topogeo_addlinestring.sql index 06ae4d194..cd1d410eb 100644 --- a/topology/test/regress/topogeo_addlinestring.sql +++ b/topology/test/regress/topogeo_addlinestring.sql @@ -58,6 +58,7 @@ $$ LANGUAGE 'plpgsql'; -- Invalid calls SELECT 'invalid', TopoGeo_addLineString('city_data', 'MULTILINESTRING((36 26, 38 30))'); SELECT 'invalid', TopoGeo_addLineString('city_data', 'POINT(36 26)'); +SELECT 'invalid', TopoGeo_addLineString('invalid', 'LINESTRING(36 26, 0 0)'); -- Isolated edge in universal face SELECT 'iso_uni', TopoGeo_addLineString('city_data', 'LINESTRING(36 26, 38 30)'); diff --git a/topology/test/regress/topogeo_addlinestring_expected b/topology/test/regress/topogeo_addlinestring_expected index eac9fe62a..4d7996448 100644 --- a/topology/test/regress/topogeo_addlinestring_expected +++ b/topology/test/regress/topogeo_addlinestring_expected @@ -8,6 +8,7 @@ max|node|22 max|edge|26 ERROR: Invalid geometry type (MULTILINESTRING) passed to TopoGeo_AddLinestring, expected LINESTRING ERROR: Invalid geometry type (POINT) passed to TopoGeo_AddLinestring, expected LINESTRING +ERROR: No topology with name "invalid" in topology.topology iso_uni|27 N|23||POINT(36 26) N|24||POINT(38 30) diff --git a/topology/test/regress/topogeo_addpoint.sql b/topology/test/regress/topogeo_addpoint.sql index 5a9377136..7ea45693d 100644 --- a/topology/test/regress/topogeo_addpoint.sql +++ b/topology/test/regress/topogeo_addpoint.sql @@ -6,6 +6,7 @@ set client_min_messages to ERROR; -- Invalid calls SELECT 'invalid', TopoGeo_addPoint('city_data', 'LINESTRING(36 26, 38 30)'); SELECT 'invalid', TopoGeo_addPoint('city_data', 'MULTIPOINT((36 26))'); +SELECT 'invalid', TopoGeo_addPoint('invalid', 'POINT(36 26)'); -- Save max node id select 'node'::text as what, max(node_id) INTO city_data.limits FROM city_data.node; diff --git a/topology/test/regress/topogeo_addpoint_expected b/topology/test/regress/topogeo_addpoint_expected index 026d2dbfa..a48f496dc 100644 --- a/topology/test/regress/topogeo_addpoint_expected +++ b/topology/test/regress/topogeo_addpoint_expected @@ -6,6 +6,7 @@ t COMMIT ERROR: Invalid geometry type (LINESTRING) passed to TopoGeo_AddPoint, expected POINT ERROR: Invalid geometry type (MULTIPOINT) passed to TopoGeo_AddPoint, expected POINT +ERROR: No topology with name "invalid" in topology.topology iso_uni|23 iso_f3|24 iso_ex|23 diff --git a/topology/test/regress/topogeo_addpolygon.sql b/topology/test/regress/topogeo_addpolygon.sql index 4e415e9a7..7722b16c8 100644 --- a/topology/test/regress/topogeo_addpolygon.sql +++ b/topology/test/regress/topogeo_addpolygon.sql @@ -74,6 +74,7 @@ $$ LANGUAGE 'plpgsql'; -- Invalid calls SELECT 'invalid', TopoGeo_addPolygon('city_data', 'MULTILINESTRING((36 26, 38 30))'); SELECT 'invalid', TopoGeo_addPolygon('city_data', 'POINT(36 26)'); +SELECT 'invalid', TopoGeo_addPolygon('invalid', 'POLYGON((36 26, 40 24, 40 30, 36 26))'); -- Isolated face in universal face SELECT 'iso_uni', TopoGeo_addPolygon('city_data', 'POLYGON((36 26, 38 30, 43 26, 36 26))'); diff --git a/topology/test/regress/topogeo_addpolygon_expected b/topology/test/regress/topogeo_addpolygon_expected index 75e316d74..f0059eb49 100644 --- a/topology/test/regress/topogeo_addpolygon_expected +++ b/topology/test/regress/topogeo_addpolygon_expected @@ -9,6 +9,7 @@ max|edge|26 max|face|9 ERROR: Invalid geometry type (MULTILINESTRING) passed to TopoGeo_AddPolygon, expected POLYGON ERROR: Invalid geometry type (POINT) passed to TopoGeo_AddPolygon, expected POLYGON +ERROR: No topology with name "invalid" in topology.topology iso_uni|10 N|23||POINT(36 26) E|27|sn23|en23