From: Peter Eisentraut Date: Tue, 3 Oct 2000 19:16:17 +0000 (+0000) Subject: Treat empty connection parameters as is, in particular to enable overriding X-Git-Tag: REL7_1_BETA~581 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7c5a444f53378e9678306de3bdfb772a6c7bac81;p=thirdparty%2Fpostgresql.git Treat empty connection parameters as is, in particular to enable overriding environment variables with "nothing". Empty host parameter indicates Unix socket. --- diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index a9550c8d997..d8d8b3ca929 100644 --- a/doc/src/sgml/libpq.sgml +++ b/doc/src/sgml/libpq.sgml @@ -1,5 +1,5 @@ @@ -38,21 +38,22 @@ $Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.41 2000/09/29 20:21:34 peter libpq library. - - Database Connection Functions + + Database Connection Functions - - The following routines deal with making a connection to - a Postgres backend server. The application - program can have several backend connections open at one time. - (One reason to do that is to access more than one database.) - Each connection is represented by a PGconn object which is obtained - from PQconnectdb() or PQsetdbLogin(). Note that these functions - will always return a non-null object pointer, unless perhaps - there is too little memory even to allocate the PGconn object. - The PQstatus function should be called - to check whether a connection was successfully made - before queries are sent via the connection object. + + The following routines deal with making a connection to a + Postgres backend server. The + application program can have several backend connections open at + one time. (One reason to do that is to access more than one + database.) Each connection is represented by a + PGconn object which is obtained from + PQconnectdb or PQsetdbLogin. Note that + these functions will always return a non-null object pointer, + unless perhaps there is too little memory even to allocate the + PGconn object. The PQstatus function + should be called to check whether a connection was successfully + made before queries are sent via the connection object. @@ -87,9 +88,8 @@ PGconn *PQconnectdb(const char *conninfo) Name of host to connect to. If a non-zero-length string is - specified, TCP/IP - communication is used. Using this parameter causes a hostname look-up. - See hostaddr. + specified, TCP/IP communication is used, else Unix sockets. + Using this parameter causes a hostname look-up. See hostaddr. @@ -1930,22 +1930,22 @@ call fe_setauthsvc at all. - -Sample Programs - -Sample Program 1 + + Example Programs + + + libpq Example Program 1 - /* - * testlibpq.c Test the C version of Libpq, the Postgres frontend - * library. - * + * testlibpq.c * + * Test the C version of libpq, the PostgreSQL frontend + * library. */ #include <stdio.h> -#include "libpq-fe.h" +#include <libpq-fe.h> void exit_nicely(PGconn *conn) @@ -2065,13 +2065,11 @@ main() } - - + - -Sample Program 2 + + libpq Example Program 2 - /* * testlibpq2.c @@ -2187,13 +2185,11 @@ main() return 0; } - - + - -Sample Program 3 + + libpq Example Program 3</> -<para> <programlisting> /* * testlibpq3.c Test the C version of Libpq, the Postgres frontend @@ -2370,10 +2366,9 @@ main() return 0; } </programlisting> -</para> + </example> -</sect2> -</sect1> + </sect1> </chapter> <!-- Keep this comment at the end of the file diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index a02d0ee3ed4..fe0d6e3f6c6 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.136 2000/10/03 03:39:46 momjian Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.137 2000/10/03 19:16:17 petere Exp $ * *------------------------------------------------------------------------- */ @@ -416,15 +416,12 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, if (conn == NULL) return (PGconn *) NULL; - if ((pghost == NULL) || pghost[0] == '\0') - { - if ((tmp = getenv("PGHOST")) != NULL) - conn->pghost = strdup(tmp); - } - else + if (pghost) conn->pghost = strdup(pghost); + else if ((tmp = getenv("PGHOST")) != NULL) + conn->pghost = strdup(tmp); - if ((pgport == NULL) || pgport[0] == '\0') + if (pgport == NULL) { if ((tmp = getenv("PGPORT")) == NULL) tmp = DEF_PGPORT_STR; @@ -433,7 +430,7 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, else conn->pgport = strdup(pgport); - if ((pgtty == NULL) || pgtty[0] == '\0') + if (pgtty == NULL) { if ((tmp = getenv("PGTTY")) == NULL) tmp = DefaultTty; @@ -442,7 +439,7 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, else conn->pgtty = strdup(pgtty); - if ((pgoptions == NULL) || pgoptions[0] == '\0') + if (pgoptions == NULL) { if ((tmp = getenv("PGOPTIONS")) == NULL) tmp = DefaultOption; @@ -476,7 +473,7 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, else conn->pgpass = strdup(DefaultPassword); - if ((dbName == NULL) || dbName[0] == '\0') + if (dbName == NULL) { if ((tmp = getenv("PGDATABASE")) != NULL) conn->dbName = strdup(tmp); @@ -705,7 +702,7 @@ connectDBStart(PGconn *conn) MemSet((char *) &conn->raddr, 0, sizeof(conn->raddr)); - if (conn->pghostaddr != NULL) + if (conn->pghostaddr != NULL && conn->pghostaddr[0] != '\0') { /* Using pghostaddr avoids a hostname lookup */ /* Note that this supports IPv4 only */ @@ -724,7 +721,7 @@ connectDBStart(PGconn *conn) memmove((char *) &(conn->raddr.in.sin_addr), (char *) &addr, sizeof(addr)); } - else if (conn->pghost != NULL) + else if (conn->pghost != NULL && conn->pghost[0] != '\0') { /* Using pghost, so we have to look-up the hostname */ struct hostent *hp;