[GRASS-SVN] r60645 - grass/branches/releasebranch_7_0/lib/vector/Vlib
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat May 31 08:35:38 PDT 2014
Author: martinl
Date: 2014-05-31 08:35:38 -0700 (Sat, 31 May 2014)
New Revision: 60645
Modified:
grass/branches/releasebranch_7_0/lib/vector/Vlib/open_pg.c
Log:
vlib: do not ignore connection settings defined for PG driver when opening external maps
(merge r60543 from trunk)
Modified: grass/branches/releasebranch_7_0/lib/vector/Vlib/open_pg.c
===================================================================
--- grass/branches/releasebranch_7_0/lib/vector/Vlib/open_pg.c 2014-05-31 15:24:01 UTC (rev 60644)
+++ grass/branches/releasebranch_7_0/lib/vector/Vlib/open_pg.c 2014-05-31 15:35:38 UTC (rev 60645)
@@ -503,11 +503,51 @@
{
char stmt[DB_SQL_MAX];
+ /* check if connection string already contains user/passwd */
+ if (!strstr(pg_info->conninfo, "user")) {
+ char dbname[GNAME_MAX];
+ char *p;
+ const char *user, *passwd;
+
+ dbname[0] = '\0';
+ p = strstr(pg_info->conninfo, "dbname");
+ if (p) {
+ int i;
+ p += strlen("dbname") + 1; /* dbname= */
+
+ for (i = 0; *p && *p != ' '; i++, p++)
+ dbname[i] = *p;
+ }
+
+ /* try connection settings for given database first, then try
+ * any settings defined for pg driver */
+ db_get_login("pg", dbname, &user, &passwd);
+ if (strlen(dbname) > 0 && !user && !passwd)
+ db_get_login("pg", NULL, &user, &passwd);
+
+ if (user || passwd) {
+ char conninfo[DB_SQL_MAX];
+
+ sprintf(conninfo, "%s", pg_info->conninfo);
+ if (user) {
+ strcat(conninfo, " user=");
+ strcat(conninfo, user);
+ }
+ if (passwd) {
+ strcat(conninfo, " password=");
+ strcat(conninfo, passwd);
+ }
+ G_free(pg_info->conninfo);
+ pg_info->conninfo = G_store(conninfo);
+ }
+ }
+
pg_info->conn = PQconnectdb(pg_info->conninfo);
- G_debug(2, " PQconnectdb(): %s", pg_info->conninfo);
+ G_debug(1, " PQconnectdb(): %s", pg_info->conninfo);
if (PQstatus(pg_info->conn) == CONNECTION_BAD)
G_fatal_error("%s\n%s",
- _("Connection to PostgreSQL database failed."),
+ _("Connection to PostgreSQL database failed. "
+ "Try to set up username/password by db.login."),
PQerrorMessage(pg_info->conn));
/* get DB name */
More information about the grass-commit
mailing list