[GRASS-SVN] r69599 - grass/branches/releasebranch_7_0/lib/db/dbmi_base
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Sep 28 06:48:13 PDT 2016
Author: martinl
Date: 2016-09-28 06:48:13 -0700 (Wed, 28 Sep 2016)
New Revision: 69599
Modified:
grass/branches/releasebranch_7_0/lib/db/dbmi_base/login.c
Log:
db.connect: connection to remote database does not work (see #3167)
(relbr72: merge r69597 from trunk)
Modified: grass/branches/releasebranch_7_0/lib/db/dbmi_base/login.c
===================================================================
--- grass/branches/releasebranch_7_0/lib/db/dbmi_base/login.c 2016-09-28 13:45:49 UTC (rev 69598)
+++ grass/branches/releasebranch_7_0/lib/db/dbmi_base/login.c 2016-09-28 13:48:13 UTC (rev 69599)
@@ -63,6 +63,10 @@
{
int login_idx;
+ G_debug(3, "add_login(): drv='%s' db='%s' usr='%s' pwd='%s' host='%s', port='%s'",
+ dr, db, usr ? usr : "null", pwd ? pwd : "null", host ? host : "null",
+ port ? port : "null");
+
if (login->n == login->a) {
login->a += 10;
login->data =
@@ -93,7 +97,8 @@
int ret;
const char *file;
FILE *fd;
- char buf[2001], dr[500], db[500], usr[500], pwd[500], host[500], port[500];
+ char buf[DB_SQL_MAX];
+ char **tokens;
login->n = 0;
file = login_filename();
@@ -114,19 +119,24 @@
while (G_getl2(buf, 2000, fd)) {
G_chop(buf);
- usr[0] = pwd[0] = host[0] = port[0] = '\0';
- ret = sscanf(buf, "%[^|]|%[^|]|%[^|]|%[^|]|%[^|]|%[^\n]",
- dr, db, usr, pwd, host, port);
+ tokens = G_tokenize(buf, "|");
+ ret = G_number_of_tokens(tokens);
- G_debug(3, "ret = %d : drv=[%s] db=[%s] usr=[%s] pwd=[%s] host=[%s], port=[%s]",
- ret, dr, db, usr, pwd, host, port);
-
if (ret < 2) {
G_warning(_("Login file (%s) corrupted (line: %s)"), file, buf);
+ G_free_tokens(tokens);
continue;
}
- add_login(login, dr, db, usr, pwd, host, port, -1);
+ add_login(login,
+ tokens[0], /* driver */
+ tokens[1], /* database */
+ ret > 2 ? tokens[2] : NULL, /* user*/
+ ret > 3 ? tokens[3] : NULL, /* password */
+ ret > 4 ? tokens[4] : NULL, /* host */
+ ret > 5 ? tokens[5] : NULL, /* port */
+ -1);
+ G_free_tokens(tokens);
}
fclose(fd);
More information about the grass-commit
mailing list