]> granicus.if.org Git - postgis/commitdiff
Allow unregistering layers of corrupted topologies (#3016)
authorSandro Santilli <strk@keybit.net>
Wed, 21 Jan 2015 14:48:07 +0000 (14:48 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 21 Jan 2015 14:48:07 +0000 (14:48 +0000)
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

topology/test/Makefile.in
topology/test/regress/droptopogeometrycolumn.sql [new file with mode: 0644]
topology/test/regress/droptopogeometrycolumn_expected [new file with mode: 0644]
topology/topology.sql.in

index 87110955b6529d06cb78aec740075bc40628d414..7274ec9e7a7278ec6621363d1c2dfd12866465a4 100644 (file)
@@ -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 (file)
index 0000000..77046b4
--- /dev/null
@@ -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 (file)
index 0000000..65dc643
--- /dev/null
@@ -0,0 +1,4 @@
+t
+t
+Layer 1 (public.t1f.geom_t1) dropped
+Topology 't1' dropped
index dd15bfeda5052a5690ff29607c7d2cb6c1611dae..58f5ed191070d69b0f1accc2550469433f93ee2e 100644 (file)
@@ -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