From 69fcd2336ffc58fbcf60dc44d5a566bc3d755919 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Thu, 23 Feb 2012 12:54:48 +0000 Subject: [PATCH] Have ST_GetFaceGeometry check face existance, regress-test git-svn-id: http://svn.osgeo.org/postgis/trunk@9276 b70326c6-7e19-0410-871a-916f4a2858ee --- topology/sql/sqlmm.sql.in.c | 37 ++++++++++++------- topology/test/regress/st_getfacegeometry.sql | 3 ++ .../test/regress/st_getfacegeometry_expected | 1 + 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/topology/sql/sqlmm.sql.in.c b/topology/sql/sqlmm.sql.in.c index 38a2a16f3..704c5b9bc 100644 --- a/topology/sql/sqlmm.sql.in.c +++ b/topology/sql/sqlmm.sql.in.c @@ -1408,6 +1408,7 @@ CREATE OR REPLACE FUNCTION topology.ST_GetFaceGeometry(toponame varchar, aface i $$ DECLARE rec RECORD; + sql TEXT; BEGIN -- @@ -1426,30 +1427,38 @@ BEGIN '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 ' + + -- No such face + sql := 'SELECT NOT EXISTS (SELECT * from ' || quote_ident(toponame) + || '.face WHERE face_id = ' || aface + || ') as none'; + EXECUTE sql INTO rec; + IF rec.none THEN + RAISE EXCEPTION 'SQL/MM Spatial exception - non-existent face.'; + END IF; + + -- + -- Construct face + -- + sql := + 'SELECT ST_BuildArea(ST_Collect(geom)) as geom FROM ' || quote_ident(toponame) - || '.edge_data WHERE left_face = ' || aface || - ' OR right_face = ' || aface + || '.edge_data WHERE left_face = ' || aface + || ' OR right_face = ' || aface; + FOR rec IN EXECUTE sql LOOP - RETURN rec.st_buildarea; + RETURN rec.geom; 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; + RAISE EXCEPTION 'corrupted topology "%"', toponame; END; - - -- - -- No face found - -- - RAISE EXCEPTION 'SQL/MM Spatial exception - non-existent face.'; + RETURN NULL; END $$ LANGUAGE 'plpgsql' STABLE; diff --git a/topology/test/regress/st_getfacegeometry.sql b/topology/test/regress/st_getfacegeometry.sql index edac60942..2bb2c1397 100644 --- a/topology/test/regress/st_getfacegeometry.sql +++ b/topology/test/regress/st_getfacegeometry.sql @@ -41,4 +41,7 @@ SELECT topology.st_getfacegeometry('tt', null); SELECT topology.st_getfacegeometry('NonExistent', 1); SELECT topology.st_getfacegeometry('', 1); +-- Non-existent face +SELECT topology.st_getfacegeometry('tt', 666); + SELECT topology.DropTopology('tt'); diff --git a/topology/test/regress/st_getfacegeometry_expected b/topology/test/regress/st_getfacegeometry_expected index 7bd616c77..751676399 100644 --- a/topology/test/regress/st_getfacegeometry_expected +++ b/topology/test/regress/st_getfacegeometry_expected @@ -6,4 +6,5 @@ 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 +ERROR: SQL/MM Spatial exception - non-existent face. Topology 'tt' dropped -- 2.40.0