[postgis-tickets] [SCM] PostGIS branch master updated. 3.2.0-481-g3878e2497

git at osgeo.org git at osgeo.org
Fri Feb 4 06:14:27 PST 2022


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, master has been updated
       via  3878e2497790025ef5c08a6c9c71fefc8f17d687 (commit)
      from  0ffe2870eade1a26a1573eb11e7540eacc207783 (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 3878e2497790025ef5c08a6c9c71fefc8f17d687
Author: Sandro Santilli <strk at kbt.io>
Date:   Fri Feb 4 15:14:03 2022 +0100

    Replace || with format() in DropTopolgy and DropTopoGeometryColumn

diff --git a/topology/topology.sql.in b/topology/topology.sql.in
index 14b7e2ead..6382b5b50 100644
--- a/topology/topology.sql.in
+++ b/topology/topology.sql.in
@@ -716,25 +716,31 @@ LANGUAGE 'sql' VOLATILE;
 CREATE OR REPLACE FUNCTION topology.DropTopoGeometryColumn(schema varchar, tbl varchar, col varchar)
   RETURNS text
 AS
-$$
+$BODY$
 DECLARE
   rec RECORD;
   lyrinfo RECORD;
   ok BOOL;
   result text;
+  sql TEXT;
 BEGIN
 
   -- Get layer and topology info
-  ok = false;
-  FOR rec IN EXECUTE 'SELECT t.name as toponame, l.* FROM '
-       'topology.topology t, topology.layer l '
-       ' WHERE l.topology_id = t.id'
-       ' AND l.schema_name = ' || quote_literal(schema)
-    || ' AND l.table_name = ' || quote_literal(tbl)
-    || ' AND l.feature_column = ' || quote_literal(col)
+
+  sql := $$
+    SELECT t.name as toponame, l.*
+    FROM topology.topology t, topology.layer l
+    WHERE l.topology_id = t.id
+    AND l.schema_name = $1
+    AND l.table_name = $2
+    AND l.feature_column = $3
+  $$;
+
+  ok := false;
+  FOR rec IN EXECUTE sql USING schema, tbl, col
   LOOP
-    ok = true;
-    lyrinfo = rec;
+    ok := true;
+    lyrinfo := rec;
   END LOOP;
 
   -- Layer not found
@@ -746,14 +752,19 @@ BEGIN
   -- Clean up the topology schema
   BEGIN
     -- Cleanup the relation table
-    EXECUTE 'DELETE FROM ' || quote_ident(lyrinfo.toponame)
-      || '.relation '
-         ' WHERE '
-         'layer_id = ' || lyrinfo.layer_id;
+    sql := format(
+      'DELETE FROM %I.relation WHERE layer_id = $1',
+      lyrinfo.toponame
+    );
+    EXECUTE sql USING lyrinfo.layer_id;
 
     -- Drop the sequence for topogeoms in this layer
-    EXECUTE 'DROP SEQUENCE ' || quote_ident(lyrinfo.toponame)
-      || '.topogeo_s_' || lyrinfo.layer_id;
+    sql := format(
+      'DROP SEQUENCE %I.topogeo_s_%s',
+      lyrinfo.toponame,
+      lyrinfo.layer_id
+    );
+    EXECUTE sql;
   EXCEPTION
     WHEN UNDEFINED_TABLE THEN
       RAISE NOTICE '%', SQLERRM;
@@ -775,25 +786,30 @@ BEGIN
 
   IF ok THEN
     -- Drop the layer column
-    EXECUTE 'ALTER TABLE ' || quote_ident(schema) || '.'
-      || quote_ident(tbl)
-      || ' DROP ' || quote_ident(col)
-      || ' cascade';
+    sql := format(
+      'ALTER TABLE %I.%I DROP %I CASCADE',
+      schema, tbl, col
+    );
+    EXECUTE sql;
   END IF;
 
   -- Delete the layer record
-  EXECUTE 'DELETE FROM topology.layer '
-       ' WHERE topology_id = ' || lyrinfo.topology_id
-    || ' AND layer_id = ' || lyrinfo.layer_id;
+  sql := $$
+    DELETE FROM topology.layer
+    WHERE topology_id = $1
+    AND layer_id = $2
+  $$;
+  EXECUTE sql USING lyrinfo.topology_id, lyrinfo.layer_id;
 
 
-  result = 'Layer ' || lyrinfo.layer_id || ' ('
-    || schema || '.' || tbl || '.' || col
-    || ') dropped';
+  result := format(
+    'Layer %s (%I.%I.%I) dropped',
+    lyrinfo.layer_id, schema, tbl, col
+  );
 
   RETURN result;
 END;
-$$
+$BODY$
 LANGUAGE 'plpgsql' VOLATILE;
 --
 --} DropTopoGeometryColumn
@@ -1723,6 +1739,7 @@ $$
 DECLARE
   topoid integer;
   rec RECORD;
+  sql TEXT;
 BEGIN
   -- Get topology id
   SELECT id INTO topoid
@@ -1736,30 +1753,43 @@ BEGIN
     quote_literal(atopology), topoid;
 
   -- Drop all layers in the topology
-  FOR rec IN EXECUTE 'SELECT * FROM topology.layer WHERE '
-    || ' topology_id = ' || topoid
+  sql := 'SELECT * FROM topology.layer WHERE topology_id = $1';
+  FOR rec IN EXECUTE sql USING topoid
   LOOP
 
-    EXECUTE 'SELECT topology.DropTopoGeometryColumn('
-      || quote_literal(rec.schema_name)
-      || ','
-      || quote_literal(rec.table_name)
-      || ','
-      || quote_literal(rec.feature_column)
-      || ')';
+    sql := format(
+      'SELECT topology.DropTopoGeometryColumn(%L, %L, %L)',
+      rec.schema_name, rec.table_name, rec.feature_column
+    );
+#ifdef POSTGIS_TOPOLOGY_DEBUG
+    RAISE DEBUG 'Executing: %', sql;
+#endif
+    EXECUTE sql;
   END LOOP;
 
+#ifdef POSTGIS_TOPOLOGY_DEBUG
+  RAISE DEBUG 'Deleting record from topology.topology';
+#endif
+
   -- Delete record from topology.topology
-  EXECUTE 'DELETE FROM topology.topology WHERE id = '
-    || topoid;
+  sql := 'DELETE FROM topology.topology WHERE id = $1';
+  EXECUTE sql USING topoid;
+
+#ifdef POSTGIS_TOPOLOGY_DEBUG
+  RAISE DEBUG 'Query pg_namespace';
+#endif
 
   -- Drop the schema (if it exists)
   FOR rec IN SELECT * FROM pg_namespace WHERE text(nspname) = atopology
   LOOP
-    EXECUTE 'DROP SCHEMA '||quote_ident(atopology)||' CASCADE';
+    sql := format('DROP SCHEMA %I CASCADE', atopology);
+#ifdef POSTGIS_TOPOLOGY_DEBUG
+    RAISE DEBUG 'Executing: %', sql;
+#endif
+    EXECUTE sql;
   END LOOP;
 
-  RETURN 'Topology ' || quote_literal(atopology) || ' dropped';
+  RETURN format('Topology %L dropped', atopology);
 END
 $$
 LANGUAGE 'plpgsql' VOLATILE STRICT;

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

Summary of changes:
 topology/topology.sql.in | 110 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 70 insertions(+), 40 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list