[GRASS-SVN] r60535 - in grass/branches/releasebranch_7_0: db/db.databases db/drivers/postgres gui/wxpython/gui_core lib/db/dbmi_base
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed May 28 06:17:02 PDT 2014
Author: martinl
Date: 2014-05-28 06:17:02 -0700 (Wed, 28 May 2014)
New Revision: 60535
Modified:
grass/branches/releasebranch_7_0/db/db.databases/main.c
grass/branches/releasebranch_7_0/db/drivers/postgres/listdb.c
grass/branches/releasebranch_7_0/gui/wxpython/gui_core/gselect.py
grass/branches/releasebranch_7_0/lib/db/dbmi_base/login.c
Log:
wxGUI: reports error from db.databases
pg-db: fix list_databases() to accept user/passwd
(merge r60461-2, r60465-6 from trunk)
Modified: grass/branches/releasebranch_7_0/db/db.databases/main.c
===================================================================
--- grass/branches/releasebranch_7_0/db/db.databases/main.c 2014-05-28 11:12:25 UTC (rev 60534)
+++ grass/branches/releasebranch_7_0/db/db.databases/main.c 2014-05-28 13:17:02 UTC (rev 60535)
@@ -49,7 +49,8 @@
if (db_list_databases(driver, &locations,
nlocs, &handles, &count) != DB_OK)
- G_fatal_error(_("Unable to list databases"));
+ G_fatal_error(_("Unable to list databases. "
+ "Try to define correct connection settings by db.login."));
db_shutdown_driver(driver);
Modified: grass/branches/releasebranch_7_0/db/drivers/postgres/listdb.c
===================================================================
--- grass/branches/releasebranch_7_0/db/drivers/postgres/listdb.c 2014-05-28 11:12:25 UTC (rev 60534)
+++ grass/branches/releasebranch_7_0/db/drivers/postgres/listdb.c 2014-05-28 13:17:02 UTC (rev 60535)
@@ -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"));
@@ -47,10 +45,19 @@
G_debug(3, "host = %s, port = %s, options = %s, tty = %s",
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:"),
Modified: grass/branches/releasebranch_7_0/gui/wxpython/gui_core/gselect.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/gui_core/gselect.py 2014-05-28 11:12:25 UTC (rev 60534)
+++ grass/branches/releasebranch_7_0/gui/wxpython/gui_core/gselect.py 2014-05-28 13:17:02 UTC (rev 60535)
@@ -1860,7 +1860,7 @@
self.dbWidgets['featType'].Enable(enableFeatType)
if showChoice:
# try to get list of PG databases
- dbNames = RunCommand('db.databases', quiet=True, read=True,
+ dbNames = RunCommand('db.databases', parent=self, quiet=True, read=True,
driver='pg').splitlines()
if dbNames is not None:
self.dbWidgets['choice'].SetItems(sorted(dbNames))
Modified: grass/branches/releasebranch_7_0/lib/db/dbmi_base/login.c
===================================================================
--- grass/branches/releasebranch_7_0/lib/db/dbmi_base/login.c 2014-05-28 11:12:25 UTC (rev 60534)
+++ grass/branches/releasebranch_7_0/lib/db/dbmi_base/login.c 2014-05-28 13:17:02 UTC (rev 60535)
@@ -221,7 +221,7 @@
is not found, user/password are set to NULL
\param driver driver name
- \param database database name
+ \param database database name (can be NULL)
\param[out] user name
\param[out] password string
@@ -246,7 +246,7 @@
for (i = 0; i < login.n; i++) {
if (strcmp(login.data[i].driver, driver) == 0 &&
- strcmp(login.data[i].database, database) == 0) {
+ (!database || strcmp(login.data[i].database, database) == 0)) {
if (login.data[i].user && strlen(login.data[i].user) > 0)
*user = G_store(login.data[i].user);
else
More information about the grass-commit
mailing list