Skip to content

Commit 996b21c

Browse files
committed
Fix bugs in PQhost().
In the platform that doesn't support Unix-domain socket, when neither host nor hostaddr are specified, the default host 'localhost' is used to connect to the server and PQhost() must return that, but it didn't. This patch fixes PQhost() so that it returns the default host in that case. Also this patch fixes PQhost() so that it doesn't return Unix-domain socket directory path in the platform that doesn't support Unix-domain socket. Back-patch to all supported versions.
1 parent f2eede9 commit 996b21c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4291,7 +4291,16 @@ PQhost(const PGconn *conn)
42914291
{
42924292
if (!conn)
42934293
return NULL;
4294-
return conn->pghost ? conn->pghost : conn->pgunixsocket;
4294+
if (conn->pghost != NULL && conn->pghost[0] != '\0')
4295+
return conn->pghost;
4296+
else
4297+
{
4298+
#ifdef HAVE_UNIX_SOCKETS
4299+
return conn->pgunixsocket;
4300+
#else
4301+
return DefaultHost;
4302+
#endif
4303+
}
42954304
}
42964305

42974306
char *

0 commit comments

Comments
 (0)