[GRASS-SVN] r60536 - in grass/branches/releasebranch_7_0: db/db.login include/defs lib/db/dbmi_base
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed May 28 06:24:33 PDT 2014
Author: martinl
Date: 2014-05-28 06:24:33 -0700 (Wed, 28 May 2014)
New Revision: 60536
Modified:
grass/branches/releasebranch_7_0/db/db.login/main.c
grass/branches/releasebranch_7_0/include/defs/dbmi.h
grass/branches/releasebranch_7_0/lib/db/dbmi_base/login.c
Log:
libdbmi: db_get_login_dump() added
db.login: implement print flag
(merge r60471-2 from trunk)
Modified: grass/branches/releasebranch_7_0/db/db.login/main.c
===================================================================
--- grass/branches/releasebranch_7_0/db/db.login/main.c 2014-05-28 13:17:02 UTC (rev 60535)
+++ grass/branches/releasebranch_7_0/db/db.login/main.c 2014-05-28 13:24:33 UTC (rev 60536)
@@ -30,6 +30,7 @@
int main(int argc, char *argv[])
{
struct Option *driver, *database, *user, *password;
+ struct Flag *print;
struct GModule *module;
/* Initialize the GIS calls */
@@ -65,9 +66,20 @@
password->description = _("Password to set for DB connection");
password->guisection = _("Settings");
+ print = G_define_flag();
+ print->key = 'p';
+ print->description = _("Print connection settings and exit");
+ print->guisection = _("Print");
+
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
+ if (print->answer) {
+ /* print all settings to standard output and exit */
+ db_get_login_dump(stdout);
+ exit(EXIT_SUCCESS);
+ }
+
if (db_set_login(driver->answer, database->answer, user->answer,
password->answer) == DB_FAILED) {
G_fatal_error(_("Unable to set user/password"));
Modified: grass/branches/releasebranch_7_0/include/defs/dbmi.h
===================================================================
--- grass/branches/releasebranch_7_0/include/defs/dbmi.h 2014-05-28 13:17:02 UTC (rev 60535)
+++ grass/branches/releasebranch_7_0/include/defs/dbmi.h 2014-05-28 13:24:33 UTC (rev 60536)
@@ -411,5 +411,6 @@
unsigned int db_sizeof_string(const dbString *);
int db_set_login(const char *, const char *, const char *, const char *);
int db_get_login(const char *, const char *, const char **, const char **);
+int db_get_login_dump(FILE *);
#endif
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 13:17:02 UTC (rev 60535)
+++ grass/branches/releasebranch_7_0/lib/db/dbmi_base/login.c 2014-05-28 13:24:33 UTC (rev 60536)
@@ -171,8 +171,8 @@
\param user user name
\param password password string
- \return DB_OK
- \return DB_FAILED
+ \return DB_OK on success
+ \return DB_FAILED on failure
*/
int db_set_login(const char *driver, const char *database, const char *user,
const char *password)
@@ -225,8 +225,8 @@
\param[out] user name
\param[out] password string
- \return DB_OK
- \return DB_FAILED
+ \return DB_OK on success
+ \return DB_FAILED on failure
*/
int db_get_login(const char *driver, const char *database, const char **user,
const char **password)
@@ -263,3 +263,33 @@
return DB_OK;
}
+
+/*!
+ \brief Print all connection settings to file
+
+ \param fd file where to print settings
+
+ \return DB_OK on success
+ \return DB_FAILED on failure
+*/
+int db_get_login_dump(FILE *fd)
+{
+ int i;
+ LOGIN login;
+
+ G_debug(3, "db_get_login_dump()");
+
+ init_login(&login);
+ if (read_file(&login) == -1)
+ return DB_FAILED;
+
+ for (i = 0; i < login.n; i++) {
+ fprintf(fd, "%s|%s|%s|%s\n",
+ login.data[i].driver,
+ login.data[i].database,
+ login.data[i].user,
+ login.data[i].password);
+ }
+
+ return DB_OK;
+}
More information about the grass-commit
mailing list