[GRASS-dev] [GRASS GIS] #3167: db.connect: connection to remote database does not work

GRASS GIS trac at osgeo.org
Wed Sep 28 06:46:36 PDT 2016


#3167: db.connect: connection to remote database does not work
--------------------------+-----------------------------------
  Reporter:  mlennert     |      Owner:  grass-dev@…
      Type:  defect       |     Status:  new
  Priority:  blocker      |  Milestone:  7.0.5
 Component:  Database     |    Version:  unspecified
Resolution:               |   Keywords:  postgresql db.connect
       CPU:  Unspecified  |   Platform:  Unspecified
--------------------------+-----------------------------------

Comment (by mlennert):

 Replying to [comment:12 mlennert]:
 > Another issue linked to the wxGUI (reported by Stefan Lüdtke - I can
 confirm):
 >
 > "If everything is in db.login, I can connect to the db (as reported
 > earlier) and list tables. However I can neither link nor import them
 > because they are not listed in the gui box."
 >
 > I can see the database in the list, but once I select it, no tables are
 listed.
 >
 > Using
 >
 >
 > {{{
 > v.in.ogr input="PG:dbname=testgrass host=myRemoteServer"
 layer=boundary_county out=bc
 > }}}
 >
 > I can import a layer, but not using
 >
 >
 > {{{
 > v.in.ogr input="PG:dbname=testgrass" layer=boundary_county out=bc
 > }}}
 >
 > I imagine v.in.ogr does not take into account the .grass7/dblogin file.



 In grass70_release/vector/v.in.ogr/main.c, I see (line 359-60):

 {{{
     if (driver_name && strcmp(driver_name, "pg") == 0 &&
         G_strcasecmp(param.dsn->answer, "PG:") == 0) {
 }}}

 Two questions:

 * Why does the default driver have to be "pg", here ? We should import
 from postgres, whatever the default driver.
 * Unless I misunderstand how G_strcasecmp works,
 G_strcasecmp(param.dsn->answer, "PG:") will never be 0 (it would be only
 in the case that param.dsn->answer = 'PG:', but that should never be the
 case). So, IIUC, the condition is never met and whatever we would like to
 add to the dsn in terms of username, passwd, host, etc will never be
 added.

 If I skip the condition check (but obviously the 'PG:' check is needed),
 and I add something like this to main.c:


 {{{
 ===================================================================
 --- main.c      (révision 69596)
 +++ main.c      (copie de travail)
 @@ -382,6 +382,10 @@
                  strcat(dsn, " passwd=");
                  strcat(dsn, conn.password);
              }
 +            if (conn.hostName) {
 +                strcat(dsn, " host=");
 +                strcat(dsn, conn.hostName);
 +            }
              /* TODO: host/port... */
          }
          else {
 }}}


 v.in.ogr imports a layer from the database on a remote server if the login
 info is correct.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3167#comment:21>
GRASS GIS <https://grass.osgeo.org>



More information about the grass-dev mailing list