Fix bugs in PQhost().
authorFujii Masao <fujii@postgresql.org>
Thu, 23 Jan 2014 14:02:03 +0000 (23:02 +0900)
committerFujii Masao <fujii@postgresql.org>
Thu, 23 Jan 2014 14:02:03 +0000 (23:02 +0900)
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.

src/interfaces/libpq/fe-connect.c

index cc465404a18f494e7a7eb071d87ca8312770ad80..d897a4084783772dc10a971fe564a6f53dce2808 100644 (file)
@@ -4291,7 +4291,16 @@ PQhost(const PGconn *conn)
 {
    if (!conn)
        return NULL;
-   return conn->pghost ? conn->pghost : conn->pgunixsocket;
+   if (conn->pghost != NULL && conn->pghost[0] != '\0')
+       return conn->pghost;
+   else
+   {
+#ifdef HAVE_UNIX_SOCKETS
+       return conn->pgunixsocket;
+#else
+       return DefaultHost;
+#endif
+   }
 }
 
 char *