Skip to content

Commit

Permalink
lib/db: Remove deprecated implementation of db_get_login() and replac…
Browse files Browse the repository at this point in the history
…e it with that of db_get_login2() (#4302)

`db_get_login()` is deprecated in 7.8.0 release with da399c5. Change its function signature and implementation to match that of the currently preferred `db_get_login2()`. Technically, this is removing the old function and introducing a new one with the same name, but a different signature.

Modify `db_get_login2()` to internally call `db_get_login()` function call. In the next major version, `db_get_login2()` should be removed to have only one method to get login details for simplicity.

See also #4308.

---------

Signed-off-by: Mohan Yelugoti <[email protected]>
  • Loading branch information
ymdatta authored Oct 23, 2024
1 parent 2575783 commit a05ed29
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion db/drivers/mysql/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int db__driver_open_database(dbHandle *handle)
connpar.host, connpar.port, connpar.dbname, connpar.user,
connpar.password);

db_get_login2("mysql", name, &user, &password, &host, &port);
db_get_login("mysql", name, &user, &password, &host, &port);

connection = mysql_init(NULL);
res =
Expand Down
4 changes: 2 additions & 2 deletions db/drivers/postgres/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int db__driver_open_database(dbHandle *handle)
return DB_FAILED;
}

db_get_login2("pg", name, &user, &password, &host, &port);
db_get_login("pg", name, &user, &password, &host, &port);

pg_conn = PQsetdbLogin(host, port, pgconn.options, pgconn.tty,
pgconn.dbname, user, password);
Expand Down Expand Up @@ -241,7 +241,7 @@ int create_delete_db(dbHandle *handle, int create)
pgconn.host, pgconn.port, pgconn.options, pgconn.tty, pgconn.dbname,
pgconn.user, pgconn.password, pgconn.host, pgconn.port,
pgconn.schema);
db_get_login2("pg", template_db, &user, &password, &host, &port);
db_get_login("pg", template_db, &user, &password, &host, &port);

pg_conn = PQsetdbLogin(host, port, pgconn.options, pgconn.tty,
pgconn.dbname, user, password);
Expand Down
2 changes: 1 addition & 1 deletion db/drivers/postgres/listdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int db__driver_list_databases(dbString *dbpath, int npaths, dbHandle **dblist,
pgconn.dbname, pgconn.user, pgconn.password, pgconn.host,
pgconn.port, pgconn.options, pgconn.tty);

db_get_login2("pg", NULL, &user, &passwd, &host, &port);
db_get_login("pg", NULL, &user, &passwd, &host, &port);
G_debug(1, "user = %s, passwd = %s", user, passwd ? "xxx" : "");

if (user || passwd) {
Expand Down
3 changes: 2 additions & 1 deletion include/grass/defs/dbmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ unsigned int db_sizeof_string(const dbString *);
int db_set_login(const char *, const char *, const char *, const char *);
int db_set_login2(const char *, const char *, const char *, const char *,
const char *, const char *, int);
int db_get_login(const char *, const char *, const char **, const char **);
int db_get_login(const char *, const char *, const char **, const char **,
const char **, const char **);
int db_get_login2(const char *, const char *, const char **, const char **,
const char **, const char **);
int db_get_login_dump(FILE *);
Expand Down
10 changes: 5 additions & 5 deletions lib/db/dbmi_base/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ int db_get_connection(dbConnection *connection)
connection->group = (char *)G_getenv_nofatal2("DB_GROUP", G_VAR_MAPSET);

/* try to get user/password */
db_get_login2(connection->driverName, connection->databaseName,
(const char **)&(connection->user),
(const char **)&(connection->password),
(const char **)&(connection->hostName),
(const char **)&(connection->port));
db_get_login(connection->driverName, connection->databaseName,
(const char **)&(connection->user),
(const char **)&(connection->password),
(const char **)&(connection->hostName),
(const char **)&(connection->port));

return DB_OK;
}
16 changes: 7 additions & 9 deletions lib/db/dbmi_base/login.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,22 +346,20 @@ static int get_login(const char *driver, const char *database,
If driver/database is not found, output arguments are set to NULL.
\deprecated Use db_set_login2() instead.
\todo: GRASS 8: to be replaced by db_set_login2().
\param driver driver name
\param database database name (can be NULL)
\param[out] user name
\param[out] password string
\param[out] host name
\param[out] port
\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)
int db_get_login2(const char *driver, const char *database, const char **user,
const char **password, const char **host, const char **port)
{
return get_login(driver, database, user, password, NULL, NULL);
return db_get_login(driver, database, user, password, host, port);
}

/*!
Expand All @@ -379,8 +377,8 @@ int db_get_login(const char *driver, const char *database, const char **user,
\return DB_OK on success
\return DB_FAILED on failure
*/
int db_get_login2(const char *driver, const char *database, const char **user,
const char **password, const char **host, const char **port)
int db_get_login(const char *driver, const char *database, const char **user,
const char **password, const char **host, const char **port)
{
return get_login(driver, database, user, password, host, port);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/vector/Vlib/open_pg.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,11 @@ void connect_db(struct Format_info_pg *pg_info)

/* try connection settings for given database first, then try
* any settings defined for pg driver */
db_get_login2("pg", dbname, &user, &passwd, &host, &port);
db_get_login("pg", dbname, &user, &passwd, &host, &port);
/* any settings defined for pg driver disabled - can cause
problems when running multiple local/remote db clusters
if (strlen(dbname) > 0 && !user && !passwd)
db_get_login2("pg", NULL, &user, &passwd, &host, &port);
db_get_login("pg", NULL, &user, &passwd, &host, &port);
*/
if (user || passwd || host || port) {
char conninfo[DB_SQL_MAX];
Expand Down
2 changes: 1 addition & 1 deletion vector/v.external/dsn.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ char *get_datasource_name(const char *opt_dsn, int use_ogr)

/* add db.login settings (user, password, host, port) */
if (DB_OK ==
db_get_login2("pg", database, &user, &passwd, &host, &port)) {
db_get_login("pg", database, &user, &passwd, &host, &port)) {
if (user) {
if (!G_strcasestr(opt_dsn, "user=")) {
strcat(connect_str, " user=");
Expand Down
2 changes: 1 addition & 1 deletion vector/v.in.ogr/dsn.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ char *get_datasource_name(const char *opt_dsn, int use_ogr)

/* add db.login settings (user, password, host, port) */
if (DB_OK ==
db_get_login2("pg", database, &user, &passwd, &host, &port)) {
db_get_login("pg", database, &user, &passwd, &host, &port)) {
if (user) {
if (!G_strcasestr(opt_dsn, "user=")) {
strcat(connect_str, " user=");
Expand Down
2 changes: 1 addition & 1 deletion vector/v.out.ogr/dsn.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ char *get_datasource_name(const char *opt_dsn, int use_ogr)

/* add db.login settings (user, password, host, port) */
if (DB_OK ==
db_get_login2("pg", database, &user, &passwd, &host, &port)) {
db_get_login("pg", database, &user, &passwd, &host, &port)) {
if (user) {
if (!G_strcasestr(opt_dsn, "user=")) {
strcat(connect_str, " user=");
Expand Down

0 comments on commit a05ed29

Please sign in to comment.