[GRASS-SVN] r58329 - in grass/trunk/lib/vector: Vlib diglib

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Nov 29 04:35:30 PST 2013


Author: martinl
Date: 2013-11-29 04:35:30 -0800 (Fri, 29 Nov 2013)
New Revision: 58329

Modified:
   grass/trunk/lib/vector/Vlib/open_pg.c
   grass/trunk/lib/vector/diglib/frmt.c
Log:
vlib/pg: fix fid_column usage in several SQL statements


Modified: grass/trunk/lib/vector/Vlib/open_pg.c
===================================================================
--- grass/trunk/lib/vector/Vlib/open_pg.c	2013-11-29 12:16:58 UTC (rev 58328)
+++ grass/trunk/lib/vector/Vlib/open_pg.c	2013-11-29 12:35:30 UTC (rev 58329)
@@ -1501,7 +1501,7 @@
                 "(SELECT node FROM (SELECT start_node AS node FROM \"%s\".edge "
                 "GROUP BY start_node UNION ALL SELECT end_node AS node FROM "
                 "\"%s\".edge GROUP BY end_node) AS foo) ORDER BY node_id",
-                "fid", pg_info->toposchema_name, pg_info->schema_name, pg_info->table_name,
+                pg_info->fid_column, pg_info->toposchema_name, pg_info->schema_name, pg_info->table_name,
                 pg_info->topogeom_column, pg_info->topogeom_column, pg_info->toposchema_name,
                 pg_info->toposchema_name);
     else
@@ -1510,7 +1510,7 @@
                 "FROM \"%s\".node AS tt LEFT JOIN \"%s\".\"%s\" AS ft ON "
                 "(%s).type = 1 AND (%s).id = node_id WHERE node_id NOT IN "
                 "(SELECT node_id FROM \"%s\".%s) AND containing_face IS NULL ORDER BY node_id",
-                "fid", pg_info->toposchema_name, pg_info->schema_name, pg_info->table_name,
+                pg_info->fid_column, pg_info->toposchema_name, pg_info->schema_name, pg_info->table_name,
                 pg_info->topogeom_column, pg_info->topogeom_column,
                 pg_info->toposchema_name, TOPO_TABLE_NODE);
     G_debug(2, "SQL: %s", stmt);
@@ -1542,19 +1542,19 @@
        -> boundaries
     */
     if (pg_info->topo_geo_only)
-        sprintf(stmt, /* TODO: fix fid column! */
+        sprintf(stmt, 
                 "SELECT edge_id,start_node,end_node,left_face,right_face AS right_area,tt.geom,ft.%s "
                 "FROM \"%s\".edge AS tt LEFT JOIN \"%s\".\"%s\" AS ft ON (%s).type = 2 AND "
                 "(%s).id = edge_id ORDER BY edge_id",
-                "fid", pg_info->toposchema_name, pg_info->schema_name, pg_info->table_name,
+                pg_info->fid_column, pg_info->toposchema_name, pg_info->schema_name, pg_info->table_name,
                 pg_info->topogeom_column, pg_info->topogeom_column);
     else
-        sprintf(stmt, /* TODO: fix fid column! */
+        sprintf(stmt, 
                 "SELECT edge_id,start_node,end_node,left_area,right_area,tt.geom,ft.%s "
                 "FROM \"%s\".edge AS tt LEFT JOIN \"%s\".\"%s\" ON "
                 "edge_id = line_id LEFT JOIN \"%s\".\"%s\" AS ft ON (%s).type = 2 AND "
                 "(%s).id = edge_id ORDER BY edge_id",
-                "fid", pg_info->toposchema_name, pg_info->toposchema_name, TOPO_TABLE_LINE,
+                pg_info->fid_column, pg_info->toposchema_name, pg_info->toposchema_name, TOPO_TABLE_LINE,
                 pg_info->schema_name, pg_info->table_name, pg_info->topogeom_column,
                 pg_info->topogeom_column);
         
@@ -1598,7 +1598,7 @@
                 "(SELECT node FROM (SELECT start_node AS node FROM \"%s\".edge "
                 "GROUP BY start_node UNION ALL SELECT end_node AS node FROM "
                 "\"%s\".edge GROUP BY end_node) AS foo) ORDER BY node_id",
-                "fid", pg_info->toposchema_name, pg_info->schema_name, pg_info->table_name,
+                pg_info->fid_column, pg_info->toposchema_name, pg_info->schema_name, pg_info->table_name,
                 pg_info->topogeom_column, pg_info->topogeom_column,
                 pg_info->toposchema_name,
                 pg_info->toposchema_name);
@@ -1609,7 +1609,7 @@
                 "(%s).type = 3 AND (%s).id = containing_face WHERE "
                 "node_id NOT IN (SELECT node_id FROM \"%s\".%s) AND containing_face "
                 "IS NOT NULL ORDER BY node_id",
-                "fid", pg_info->toposchema_name, pg_info->schema_name, pg_info->table_name,
+                pg_info->fid_column, pg_info->toposchema_name, pg_info->schema_name, pg_info->table_name,
                 pg_info->topogeom_column, pg_info->topogeom_column,
                 pg_info->toposchema_name, TOPO_TABLE_NODE);
     G_debug(2, "SQL: %s", stmt);

Modified: grass/trunk/lib/vector/diglib/frmt.c
===================================================================
--- grass/trunk/lib/vector/diglib/frmt.c	2013-11-29 12:16:58 UTC (rev 58328)
+++ grass/trunk/lib/vector/diglib/frmt.c	2013-11-29 12:35:30 UTC (rev 58329)
@@ -121,6 +121,8 @@
                 finfo->pg.schema_name = G_store(ptr);
             if (G_strcasecmp(buf1, "TABLE") == 0)
                 finfo->pg.table_name = G_store(ptr);
+            if (G_strcasecmp(buf1, "FID") == 0)
+                finfo->pg.fid_column = G_store(ptr);
         }
 #endif
     }
@@ -131,6 +133,12 @@
         !finfo->pg.schema_name) {
         finfo->pg.schema_name = G_store("public");
     }
+
+    /* if fid column not defined, use default value */
+    if (frmt == GV_FORMAT_POSTGIS &&
+        !finfo->pg.fid_column) {
+        finfo->pg.fid_column = G_store(GV_PG_FID_COLUMN);
+    }
 #endif
 
     return frmt;



More information about the grass-commit mailing list