From: Sandro Santilli Date: Wed, 21 Jan 2015 14:48:07 +0000 (+0000) Subject: Allow unregistering layers of corrupted topologies (#3016) X-Git-Tag: 2.2.0rc1~701 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d681e9469498153fc0ab113bff80df8658d7c2e6;p=postgis Allow unregistering layers of corrupted topologies (#3016) Makes topology.layer trigger and DropTopoGeometryColumn tolerant of topology schemas with no "relation" table. Allows using DropTopology to de-register and drop these kind of corrupted topologies. git-svn-id: http://svn.osgeo.org/postgis/trunk@13189 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/topology/test/Makefile.in b/topology/test/Makefile.in index 87110955b..7274ec9e7 100644 --- a/topology/test/Makefile.in +++ b/topology/test/Makefile.in @@ -57,6 +57,7 @@ TESTS = regress/legacy_validate.sql regress/legacy_predicate.sql \ regress/topo2.5d.sql \ regress/totopogeom.sql \ regress/droptopology.sql \ + regress/droptopogeometrycolumn.sql \ regress/copytopology.sql \ regress/createtopogeom.sql \ regress/createtopology.sql \ diff --git a/topology/test/regress/droptopogeometrycolumn.sql b/topology/test/regress/droptopogeometrycolumn.sql new file mode 100644 index 000000000..77046b4f9 --- /dev/null +++ b/topology/test/regress/droptopogeometrycolumn.sql @@ -0,0 +1,10 @@ +set client_min_messages to ERROR; +-- Drop corrupted topology (with missing layer tables) +-- See http://trac.osgeo.org/postgis/ticket/3016 +SELECT topology.CreateTopology('t1') > 0; +CREATE TABLE t1f (id int); +SELECT topology.AddTopoGeometryColumn('t1', 'public', 't1f', 'geom_t1', 'LINE') > 0; +DROP TABLE t1.relation; +SELECT topology.DropTopoGeometryColumn('public','t1f','geom_t1'); +DROP TABLE t1f; +SELECT topology.DropTopology('t1'); diff --git a/topology/test/regress/droptopogeometrycolumn_expected b/topology/test/regress/droptopogeometrycolumn_expected new file mode 100644 index 000000000..65dc643d9 --- /dev/null +++ b/topology/test/regress/droptopogeometrycolumn_expected @@ -0,0 +1,4 @@ +t +t +Layer 1 (public.t1f.geom_t1) dropped +Topology 't1' dropped diff --git a/topology/topology.sql.in b/topology/topology.sql.in index dd15bfeda..58f5ed191 100644 --- a/topology/topology.sql.in +++ b/topology/topology.sql.in @@ -277,8 +277,9 @@ BEGIN END IF; -- Check if any record in the relation table references this layer - FOR rec IN SELECT * FROM pg_namespace - WHERE text(nspname) = toponame + FOR rec IN SELECT c.oid FROM pg_namespace n, pg_class c + WHERE text(n.nspname) = toponame AND c.relnamespace = n.oid + AND c.relname = 'relation' LOOP query = 'SELECT * ' || ' FROM ' || quote_ident(toponame) @@ -749,9 +750,7 @@ BEGIN END IF; -- Clean up the topology schema - FOR rec IN SELECT * FROM pg_namespace - WHERE text(nspname) = lyrinfo.toponame - LOOP + BEGIN -- Cleanup the relation table EXECUTE 'DELETE FROM ' || quote_ident(lyrinfo.toponame) || '.relation ' @@ -761,8 +760,12 @@ BEGIN -- Drop the sequence for topogeoms in this layer EXECUTE 'DROP SEQUENCE ' || quote_ident(lyrinfo.toponame) || '.topogeo_s_' || lyrinfo.layer_id; - - END LOOP; + EXCEPTION + WHEN UNDEFINED_TABLE THEN + RAISE NOTICE '%', SQLERRM; + WHEN OTHERS THEN + RAISE EXCEPTION 'Got % (%)', SQLERRM, SQLSTATE; + END; ok = false; FOR rec IN SELECT * FROM pg_namespace n, pg_class c, pg_attribute a