Browse Source

Vlib/pg: fix reading PostGIS features when fid column contains uppercase letter

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@70343 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 8 năm trước cách đây
mục cha
commit
ec34715f07
1 tập tin đã thay đổi với 13 bổ sung5 xóa
  1. 13 5
      lib/vector/Vlib/read_pg.c

+ 13 - 5
lib/vector/Vlib/read_pg.c

@@ -1245,17 +1245,25 @@ int Vect__open_cursor_next_line_pg(struct Format_info_pg *pg_info, int fetch_all
     if (!pg_info->toposchema_name) {
     if (!pg_info->toposchema_name) {
         /* simple feature access (geom, fid) */
         /* simple feature access (geom, fid) */
         /* TODO: start_fid */
         /* TODO: start_fid */
-        if (pg_info->where)
+        if (pg_info->where) {
             /* set attribute filter if where sql statement defined */
             /* set attribute filter if where sql statement defined */
+            char **tokens = G_tokenize(pg_info->where, "=");
+            if (G_number_of_tokens(tokens) != 2) {
+                G_warning(_("Unable to parse '%s'"), pg_info->where);
+                return -1;
+            }
             sprintf(stmt,
             sprintf(stmt,
-                    "DECLARE %s CURSOR FOR SELECT %s,%s FROM \"%s\".\"%s\" WHERE %s ORDER BY %s",
+                    "DECLARE %s CURSOR FOR SELECT \"%s\",\"%s\" FROM \"%s\".\"%s\" WHERE \"%s\"=%s ORDER BY \"%s\"",
                     pg_info->cursor_name, pg_info->geom_column, pg_info->fid_column, pg_info->schema_name,
                     pg_info->cursor_name, pg_info->geom_column, pg_info->fid_column, pg_info->schema_name,
-                    pg_info->table_name, pg_info->where, pg_info->fid_column);
-        else
+                    pg_info->table_name, tokens[0], tokens[1], pg_info->fid_column);
+            G_free_tokens(tokens);
+        }
+        else {
             sprintf(stmt,
             sprintf(stmt,
-                    "DECLARE %s CURSOR FOR SELECT %s,%s FROM \"%s\".\"%s\" ORDER BY %s",
+                    "DECLARE %s CURSOR FOR SELECT \"%s\",\"%s\" FROM \"%s\".\"%s\" ORDER BY \"%s\"",
                     pg_info->cursor_name, pg_info->geom_column, pg_info->fid_column, pg_info->schema_name,
                     pg_info->cursor_name, pg_info->geom_column, pg_info->fid_column, pg_info->schema_name,
                     pg_info->table_name, pg_info->fid_column);
                     pg_info->table_name, pg_info->fid_column);
+        }
     }
     }
     else {
     else {
         /* topology access (geom,id,fid,type) */
         /* topology access (geom,id,fid,type) */