[postgis-tickets] [SCM] PostGIS branch stable-3.0 updated. 3.0.4-2-g83b233682

git at osgeo.org git at osgeo.org
Mon Nov 29 08:42:54 PST 2021


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, stable-3.0 has been updated
       via  83b23368293d3b7391c5216e9aa1f05d057b596a (commit)
      from  3253373e873027409bc50373ad155d50e530a70b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 83b23368293d3b7391c5216e9aa1f05d057b596a
Author: Sandro Santilli <strk at kbt.io>
Date:   Thu Nov 25 23:52:15 2021 +0100

    Allow droppping TopoGeometry columns in presence of UPDATE triggers
    
    References #5026 in 3.0 branch (3.0.5dev)
    Includes regression test

diff --git a/NEWS b/NEWS
index 3a4a6ef37..f827b16ad 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
 PostGIS 3.0.5
 2021/XX/XX
 * Bug Fixes and Enhancements *
+  - #5026, fix DropTopology in presence of UPDATE triggers on
+           topology layers (Sandro Santilli)
 
 PostGIS 3.0.4
 2021/09/04
diff --git a/topology/test/regress/droptopology.sql b/topology/test/regress/droptopology.sql
index 84f2ca4b4..0b63a6d71 100644
--- a/topology/test/regress/droptopology.sql
+++ b/topology/test/regress/droptopology.sql
@@ -1,19 +1,36 @@
 set client_min_messages to WARNING;
 
-SELECT topology.CreateTopology('t1') > 0;
-SELECT topology.CreateTopology('t2') > 0;
+SELECT NULL FROM topology.CreateTopology('t1');
+SELECT NULL FROM topology.CreateTopology('t2');
 
 CREATE TABLE t1f (id int);
-SELECT topology.AddTopoGeometryColumn('t1', 'public', 't1f', 'geom_t1', 'LINE') > 0;
+SELECT NULL FROM topology.AddTopoGeometryColumn('t1', 'public', 't1f', 'geom_t1', 'LINE');
 
 CREATE TABLE t2f (id int);
-SELECT topology.AddTopoGeometryColumn('t2', 'public', 't2f', 'geom_t2', 'LINE') > 0;
+SELECT NULL FROM topology.AddTopoGeometryColumn('t2', 'public', 't2f', 'geom_t2', 'LINE');
 
 SELECT topology.DropTopology('t1');
 SELECT topology.DropTopology('t2');
 DROP TABLE t2f;
 DROP TABLE t1f;
 
+SELECT NULL FROM topology.CreateTopology('t3');
+CREATE FUNCTION t3.bail_out() RETURNS trigger AS $BODY$
+BEGIN
+  RAISE EXCEPTION '%: trigger prevents % on %', TG_ARGV[0], TG_OP, TG_RELNAME;
+END;
+$BODY$ LANGUAGE 'plpgsql';
+
+-- Test DropTopology in presence of triggers
+-- See https://trac.osgeo.org/postgis/ticket/5026
+CREATE TABLE t3.f(id serial);
+SELECT NULL FROM topology.AddTopoGeometryColumn('t3', 't3', 'f', 'g', 'POINT');
+CREATE TRIGGER prevent_delete AFTER DELETE OR UPDATE ON t3.f
+FOR EACH STATEMENT EXECUTE PROCEDURE t3.bail_out('t3');
+INSERT INTO t3.f(g) VALUES (toTopoGeom('POINT(0 0)', 't3', 1));
+--SELECT topology.DropTopoGeometryColumn('t3', 'f', 'g');
+SELECT topology.DropTopology('t3');
+
 -- Exceptions
 SELECT topology.DropTopology('topology');
 SELECT topology.DropTopology('doesnotexist');
diff --git a/topology/test/regress/droptopology_expected b/topology/test/regress/droptopology_expected
index e8ef689d4..37905a4d3 100644
--- a/topology/test/regress/droptopology_expected
+++ b/topology/test/regress/droptopology_expected
@@ -1,8 +1,5 @@
-t
-t
-t
-t
 Topology 't1' dropped
 Topology 't2' dropped
+Topology 't3' dropped
 ERROR:  Topology 'topology' does not exist
 ERROR:  Topology 'doesnotexist' does not exist
diff --git a/topology/topology.sql.in b/topology/topology.sql.in
index b822ee7ba..38e92ce8b 100644
--- a/topology/topology.sql.in
+++ b/topology/topology.sql.in
@@ -723,7 +723,7 @@ DECLARE
   result text;
 BEGIN
 
-        -- Get layer and topology info
+  -- Get layer and topology info
   ok = false;
   FOR rec IN EXECUTE 'SELECT t.name as toponame, l.* FROM '
        'topology.topology t, topology.layer l '
@@ -773,12 +773,11 @@ BEGIN
   END LOOP;
 
   IF ok THEN
-    -- Set feature column to NULL to bypass referential integrity
-    -- checks
-    EXECUTE 'UPDATE ' || quote_ident(schema) || '.'
+    -- Drop the layer column
+    EXECUTE 'ALTER TABLE ' || quote_ident(schema) || '.'
       || quote_ident(tbl)
-      || ' SET ' || quote_ident(col)
-      || ' = NULL';
+      || ' DROP ' || quote_ident(col)
+      || ' cascade';
   END IF;
 
   -- Delete the layer record
@@ -786,13 +785,6 @@ BEGIN
        ' WHERE topology_id = ' || lyrinfo.topology_id
     || ' AND layer_id = ' || lyrinfo.layer_id;
 
-  IF ok THEN
-    -- Drop the layer column
-    EXECUTE 'ALTER TABLE ' || quote_ident(schema) || '.'
-      || quote_ident(tbl)
-      || ' DROP ' || quote_ident(col)
-      || ' cascade';
-  END IF;
 
   result = 'Layer ' || lyrinfo.layer_id || ' ('
     || schema || '.' || tbl || '.' || col

-----------------------------------------------------------------------

Summary of changes:
 NEWS                                        |  2 ++
 topology/test/regress/droptopology.sql      | 25 +++++++++++++++++++++----
 topology/test/regress/droptopology_expected |  5 +----
 topology/topology.sql.in                    | 18 +++++-------------
 4 files changed, 29 insertions(+), 21 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list