mirror of
https://github.com/postgres/postgres.git
synced 2025-04-27 22:56:53 +03:00
Reimplement 9f80f4835a55a1cbffcda5d23a617917f3286c14 with PQconninfo().
Apart from ignoring "hostaddr" set to the empty string, this behaves identically to its predecessor. Back-patch to 9.4, where the original commit first appeared. Reviewed by Fujii Masao.
This commit is contained in:
parent
27b6f9ce7b
commit
36e5247985
@ -302,14 +302,33 @@ exec_command(const char *cmd,
|
|||||||
else if (strcmp(cmd, "conninfo") == 0)
|
else if (strcmp(cmd, "conninfo") == 0)
|
||||||
{
|
{
|
||||||
char *db = PQdb(pset.db);
|
char *db = PQdb(pset.db);
|
||||||
char *host = PQhost(pset.db);
|
|
||||||
|
|
||||||
if (db == NULL)
|
if (db == NULL)
|
||||||
printf(_("You are currently not connected to a database.\n"));
|
printf(_("You are currently not connected to a database.\n"));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
char *host;
|
||||||
|
PQconninfoOption *connOptions;
|
||||||
|
PQconninfoOption *option;
|
||||||
|
|
||||||
|
host = PQhost(pset.db);
|
||||||
if (host == NULL)
|
if (host == NULL)
|
||||||
host = DEFAULT_PGSOCKET_DIR;
|
host = DEFAULT_PGSOCKET_DIR;
|
||||||
|
/* A usable "hostaddr" overrides the basic sense of host. */
|
||||||
|
connOptions = PQconninfo(pset.db);
|
||||||
|
if (connOptions == NULL)
|
||||||
|
{
|
||||||
|
psql_error("out of memory\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
for (option = connOptions; option && option->keyword; option++)
|
||||||
|
if (strcmp(option->keyword, "hostaddr") == 0)
|
||||||
|
{
|
||||||
|
if (option->val != NULL && option->val[0] != '\0')
|
||||||
|
host = option->val;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* If the host is an absolute path, the connection is via socket */
|
/* If the host is an absolute path, the connection is via socket */
|
||||||
if (is_absolute_path(host))
|
if (is_absolute_path(host))
|
||||||
printf(_("You are connected to database \"%s\" as user \"%s\" via socket in \"%s\" at port \"%s\".\n"),
|
printf(_("You are connected to database \"%s\" as user \"%s\" via socket in \"%s\" at port \"%s\".\n"),
|
||||||
@ -318,6 +337,8 @@ exec_command(const char *cmd,
|
|||||||
printf(_("You are connected to database \"%s\" as user \"%s\" on host \"%s\" at port \"%s\".\n"),
|
printf(_("You are connected to database \"%s\" as user \"%s\" on host \"%s\" at port \"%s\".\n"),
|
||||||
db, PQuser(pset.db), host, PQport(pset.db));
|
db, PQuser(pset.db), host, PQport(pset.db));
|
||||||
printSSLInfo();
|
printSSLInfo();
|
||||||
|
|
||||||
|
PQconninfoFree(connOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user