[GRASS-SVN] r70388 - grass/branches/releasebranch_7_2/vector/v.external

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jan 17 12:05:40 PST 2017


Author: martinl
Date: 2017-01-17 12:05:39 -0800 (Tue, 17 Jan 2017)
New Revision: 70388

Modified:
   grass/branches/releasebranch_7_2/vector/v.external/dsn.c
   grass/branches/releasebranch_7_2/vector/v.external/main.c
Log:
v.external: fix dsn handling (full / db-login-based connection strings)
            (merge r70342 from trunk)


Modified: grass/branches/releasebranch_7_2/vector/v.external/dsn.c
===================================================================
--- grass/branches/releasebranch_7_2/vector/v.external/dsn.c	2017-01-17 19:28:47 UTC (rev 70387)
+++ grass/branches/releasebranch_7_2/vector/v.external/dsn.c	2017-01-17 20:05:39 UTC (rev 70388)
@@ -27,7 +27,7 @@
         database[i] = '\0';
         
         /* build connection string */
-        sprintf(connect_str, "dbname=%s", database);
+        sprintf(connect_str, "%s", opt_dsn);
         
         /* add db.login settings (user, password, host, port) */
         if (DB_OK == db_get_login2("pg", database, &user, &passwd, &host, &port)) {
@@ -61,11 +61,15 @@
             }
         }
         
-        if (!use_ogr)
-            /* be friendly, ignored 'PG:' prefix for PostGIS links */
+        if (use_ogr) {
             dsn = G_store(connect_str);
-        else
-            G_asprintf(&dsn, "PG:%s", connect_str);
+        }
+        else {
+            /* strip PG: prefix */
+            p = (char *)connect_str;
+            p += strlen("PG:");
+            dsn = G_store(p);
+        }
     }
     else {
         /* other datasources */

Modified: grass/branches/releasebranch_7_2/vector/v.external/main.c
===================================================================
--- grass/branches/releasebranch_7_2/vector/v.external/main.c	2017-01-17 19:28:47 UTC (rev 70387)
+++ grass/branches/releasebranch_7_2/vector/v.external/main.c	2017-01-17 20:05:39 UTC (rev 70388)
@@ -138,7 +138,17 @@
     if (!flags.override->answer) {
         /* here must be used original dsn since check_projection() is
          * using GDAL library */
-        check_projection(options.dsn->answer, ilayer);
+        char dsn_ogr[DB_SQL_MAX];
+
+        if (!use_ogr && G_strncasecmp(options.dsn->answer, "PG:", 3) == 0) {
+            /* make dsn OGR-compatible */
+            strcpy(dsn_ogr, "PG:");
+            strcat(dsn_ogr, dsn);
+        }
+        else {
+            sprintf(dsn_ogr, "%s", dsn);
+        }
+        check_projection(dsn_ogr, ilayer);
     }
     
     /* create new vector map */



More information about the grass-commit mailing list