Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit64f86fb

Browse files
committed
Reimplement9f80f48 with PQconninfo().
Apart from ignoring "hostaddr" set to the empty string, this behavesidentically to its predecessor. Back-patch to 9.4, where the originalcommit first appeared.Reviewed by Fujii Masao.
1 parent2cda889 commit64f86fb

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

‎src/bin/psql/command.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,33 @@ exec_command(const char *cmd,
302302
elseif (strcmp(cmd,"conninfo")==0)
303303
{
304304
char*db=PQdb(pset.db);
305-
char*host=PQhost(pset.db);
306305

307306
if (db==NULL)
308307
printf(_("You are currently not connected to a database.\n"));
309308
else
310309
{
310+
char*host;
311+
PQconninfoOption*connOptions;
312+
PQconninfoOption*option;
313+
314+
host=PQhost(pset.db);
311315
if (host==NULL)
312316
host=DEFAULT_PGSOCKET_DIR;
317+
/* A usable "hostaddr" overrides the basic sense of host. */
318+
connOptions=PQconninfo(pset.db);
319+
if (connOptions==NULL)
320+
{
321+
psql_error("out of memory\n");
322+
exit(EXIT_FAILURE);
323+
}
324+
for (option=connOptions;option&&option->keyword;option++)
325+
if (strcmp(option->keyword,"hostaddr")==0)
326+
{
327+
if (option->val!=NULL&&option->val[0]!='\0')
328+
host=option->val;
329+
break;
330+
}
331+
313332
/* If the host is an absolute path, the connection is via socket */
314333
if (is_absolute_path(host))
315334
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,
318337
printf(_("You are connected to database \"%s\" as user \"%s\" on host \"%s\" at port \"%s\".\n"),
319338
db,PQuser(pset.db),host,PQport(pset.db));
320339
printSSLInfo();
340+
341+
PQconninfoFree(connOptions);
321342
}
322343
}
323344

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp