[GRASS-SVN] r60465 - grass/trunk/db/drivers/postgres
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat May 24 14:08:38 PDT 2014
Author: martinl
Date: 2014-05-24 14:08:38 -0700 (Sat, 24 May 2014)
New Revision: 60465
Modified:
grass/trunk/db/drivers/postgres/listdb.c
Log:
pg-db: fix list_databases() to accept user/passwd
Modified: grass/trunk/db/drivers/postgres/listdb.c
===================================================================
--- grass/trunk/db/drivers/postgres/listdb.c 2014-05-24 20:51:18 UTC (rev 60464)
+++ grass/trunk/db/drivers/postgres/listdb.c 2014-05-24 21:08:38 UTC (rev 60465)
@@ -19,6 +19,7 @@
dbHandle ** dblist, int *dbcount)
{
int i;
+ const char *user, *passwd;
PGCONN pgconn;
PGresult *res;
int rec_num = 0;
@@ -27,11 +28,8 @@
*dblist = NULL;
*dbcount = 0;
- /* TODO: the solution below is not good as user usually does not have permissions for "template1" */
- /* db_d_append_error(_("db_driver_list_databases() is not implemented"));
- db_d_report_error();
- return DB_FAILED;
- */
+ /* TODO: the solution below is not good as user usually does not
+ * have permissions for "template1" */
if (npaths < 1) {
db_d_append_error(_("No path given"));
@@ -48,10 +46,19 @@
pgconn.dbname, pgconn.user, pgconn.password, pgconn.host,
pgconn.port, pgconn.options, pgconn.tty);
- pg_conn =
- PQsetdb(pgconn.host, pgconn.port, pgconn.options, pgconn.tty,
- "template1");
+ db_get_login("pg", NULL, &user, &passwd);
+ G_debug(1, "user = %s, passwd = %s", user, passwd ? "xxx" : "");
+ if (user || passwd) {
+ pg_conn = PQsetdbLogin(pgconn.host, pgconn.port, pgconn.options, pgconn.tty,
+ "template1", user, passwd);
+ }
+ else {
+ pg_conn =
+ PQsetdb(pgconn.host, pgconn.port, pgconn.options, pgconn.tty,
+ "template1");
+ }
+
if (PQstatus(pg_conn) == CONNECTION_BAD) {
db_d_append_error("%s\n%s",
_("Unable to connect to Postgres:"),
More information about the grass-commit
mailing list