From bc6bbb47b7fec532a534ee4e0d94c96abb96fa82 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Tue, 24 May 2011 13:49:18 +0000 Subject: [PATCH] ST_GetFaceGeometry: throw SQL/MM exception when asked for the Universal Face geometry. Fixes bug #973 [RT-SIGTA] git-svn-id: http://svn.osgeo.org/postgis/trunk@7234 b70326c6-7e19-0410-871a-916f4a2858ee --- topology/sql/sqlmm.sql | 55 +++++++++++-------- topology/test/regress/st_getfacegeometry.sql | 14 +++-- .../test/regress/st_getfacegeometry_expected | 6 +- 3 files changed, 46 insertions(+), 29 deletions(-) diff --git a/topology/sql/sqlmm.sql b/topology/sql/sqlmm.sql index 1c444ce10..23f4908a6 100644 --- a/topology/sql/sqlmm.sql +++ b/topology/sql/sqlmm.sql @@ -643,35 +643,42 @@ BEGIN -- toponame and aface are required -- IF toponame IS NULL OR aface IS NULL THEN - RAISE EXCEPTION - 'SQL/MM Spatial exception - null argument'; - END IF; - - -- - -- Construct face - -- - BEGIN - FOR rec IN EXECUTE 'SELECT ST_BuildArea(ST_Collect(geom)) FROM ' - || quote_ident(toponame) - || '.edge WHERE left_face = ' || aface || - ' OR right_face = ' || aface - LOOP - RETURN rec.st_buildarea; - END LOOP; - EXCEPTION - WHEN INVALID_SCHEMA_NAME THEN - RAISE EXCEPTION 'SQL/MM Spatial exception - invalid topology name'; - WHEN UNDEFINED_TABLE THEN - RAISE EXCEPTION 'corrupted topology "%" (missing edge_data table)', - toponame; - END; + RAISE EXCEPTION 'SQL/MM Spatial exception - null argument'; + END IF; + + IF toponame = '' THEN + RAISE EXCEPTION 'SQL/MM Spatial exception - invalid topology name'; + END IF; + + IF aface = 0 THEN + RAISE EXCEPTION + 'SQL/MM Spatial exception - universal face has no geometry'; + END IF; + + -- + -- Construct face + -- + BEGIN + FOR rec IN EXECUTE 'SELECT ST_BuildArea(ST_Collect(geom)) FROM ' + || quote_ident(toponame) + || '.edge_data WHERE left_face = ' || aface || + ' OR right_face = ' || aface + LOOP + RETURN rec.st_buildarea; + END LOOP; + EXCEPTION + WHEN INVALID_SCHEMA_NAME THEN + RAISE EXCEPTION 'SQL/MM Spatial exception - invalid topology name'; + WHEN UNDEFINED_TABLE THEN + RAISE EXCEPTION 'corrupted topology "%" (missing edge_data table)', + toponame; + END; -- -- No face found -- - RAISE EXCEPTION - 'SQL/MM Spatial exception - non-existent face.'; + RAISE EXCEPTION 'SQL/MM Spatial exception - non-existent face.'; END $$ LANGUAGE 'plpgsql' VOLATILE; diff --git a/topology/test/regress/st_getfacegeometry.sql b/topology/test/regress/st_getfacegeometry.sql index 15f9d16c8..edac60942 100644 --- a/topology/test/regress/st_getfacegeometry.sql +++ b/topology/test/regress/st_getfacegeometry.sql @@ -24,15 +24,21 @@ COPY tt.edge_data( 3 3 3 3 3 3 -3 0 3 LINESTRING(12 2, 12 8, 18 8, 18 2, 12 2) \. -SELECT * FROM topology.ValidateTopology('tt'); - -- F1 should have an hole ! -- See http://trac.osgeo.org/postgis/ticket/726 SELECT 'f1 (with hole)', ST_asText(topology.st_getfacegeometry('tt', 1)); SELECT 'f2 (fill hole)', ST_asText(topology.st_getfacegeometry('tt', 2)); --- Universal face is the union of all faces +-- Universal face has no geometry -- See http://trac.osgeo.org/postgis/ticket/973 -SELECT 'f0', ST_AsText(topology.st_getfacegeometry('tt', 0)); +SELECT topology.st_getfacegeometry('tt', 0); + +-- Null arguments +SELECT topology.st_getfacegeometry(null, 1); +SELECT topology.st_getfacegeometry('tt', null); + +-- Invalid topology names +SELECT topology.st_getfacegeometry('NonExistent', 1); +SELECT topology.st_getfacegeometry('', 1); SELECT topology.DropTopology('tt'); diff --git a/topology/test/regress/st_getfacegeometry_expected b/topology/test/regress/st_getfacegeometry_expected index 770bef25d..7bd616c77 100644 --- a/topology/test/regress/st_getfacegeometry_expected +++ b/topology/test/regress/st_getfacegeometry_expected @@ -1,5 +1,9 @@ t f1 (with hole)|POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,8 2,8 8,2 8,2 2)) f2 (fill hole)|POLYGON((2 2,2 8,8 8,8 2,2 2)) -f0|MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((12 2,12 8,18 8,18 2,12 2))) +ERROR: SQL/MM Spatial exception - universal face has no geometry +ERROR: SQL/MM Spatial exception - null argument +ERROR: SQL/MM Spatial exception - null argument +ERROR: SQL/MM Spatial exception - invalid topology name +ERROR: SQL/MM Spatial exception - invalid topology name Topology 'tt' dropped -- 2.50.1