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

Commit7c5a444

Browse files
committed
Treat empty connection parameters as is, in particular to enable overriding
environment variables with "nothing". Empty host parameter indicatesUnix socket.
1 parent3189e48 commit7c5a444

File tree

2 files changed

+45
-53
lines changed

2 files changed

+45
-53
lines changed

‎doc/src/sgml/libpq.sgml

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.41 2000/09/29 20:21:34 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.42 2000/10/03 19:16:16 petere Exp $
33
-->
44

55
<chapter id="libpq-chapter">
@@ -38,21 +38,22 @@ $Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.41 2000/09/29 20:21:34 peter
3838
<filename>libpq</filename> library.
3939
</para>
4040

41-
<sect1 id="libpq-connect">
42-
<title>Database Connection Functions</title>
41+
<sect1 id="libpq-connect">
42+
<title>Database Connection Functions</title>
4343

44-
<para>
45-
The following routines deal with making a connection to
46-
a <productname>Postgres</productname> backend server. The application
47-
program can have several backend connections open at one time.
48-
(One reason to do that is to access more than one database.)
49-
Each connection is represented by a PGconn object which is obtained
50-
from PQconnectdb() or PQsetdbLogin(). Note that these functions
51-
will always return a non-null object pointer, unless perhaps
52-
there is too little memory even to allocate the PGconn object.
53-
The PQstatus function should be called
54-
to check whether a connection was successfully made
55-
before queries are sent via the connection object.
44+
<para>
45+
The following routines deal with making a connection to a
46+
<productname>Postgres</productname> backend server. The
47+
application program can have several backend connections open at
48+
one time. (One reason to do that is to access more than one
49+
database.) Each connection is represented by a
50+
<structname>PGconn</> object which is obtained from
51+
<function>PQconnectdb</> or <function>PQsetdbLogin</>. Note that
52+
these functions will always return a non-null object pointer,
53+
unless perhaps there is too little memory even to allocate the
54+
<structname>PGconn</> object. The <function>PQstatus</> function
55+
should be called to check whether a connection was successfully
56+
made before queries are sent via the connection object.
5657

5758
<itemizedlist>
5859
<listitem>
@@ -87,9 +88,8 @@ PGconn *PQconnectdb(const char *conninfo)
8788
<listitem>
8889
<para>
8990
Name of host to connect to. If a non-zero-length string is
90-
specified, TCP/IP
91-
communication is used. Using this parameter causes a hostname look-up.
92-
See hostaddr.
91+
specified, TCP/IP communication is used, else Unix sockets.
92+
Using this parameter causes a hostname look-up. See hostaddr.
9393
</para>
9494
</listitem>
9595
</varlistentry>
@@ -1930,22 +1930,22 @@ call <function>fe_setauthsvc</function> at all.
19301930

19311931
</sect1>
19321932

1933-
<sect1 id="libpq-sample">
1934-
<title>Sample Programs</title>
19351933

1936-
<sect2>
1937-
<title>Sample Program 1</title>
1934+
<sect1 id="libpq-example">
1935+
<title>Example Programs</title>
1936+
1937+
<example id="libpq-example-1">
1938+
<title>libpq Example Program 1</title>
19381939

1939-
<para>
19401940
<programlisting>
19411941
/*
1942-
* testlibpq.c Test the C version of Libpq, the Postgres frontend
1943-
* library.
1944-
*
1942+
* testlibpq.c
19451943
*
1944+
* Test the C version of libpq, the PostgreSQL frontend
1945+
* library.
19461946
*/
19471947
#include &lt;stdio.h&gt;
1948-
#include"libpq-fe.h"
1948+
#include&lt;libpq-fe.h&gt;
19491949

19501950
void
19511951
exit_nicely(PGconn *conn)
@@ -2065,13 +2065,11 @@ main()
20652065

20662066
}
20672067
</programlisting>
2068-
</para>
2069-
</sect2>
2068+
</example>
20702069

2071-
<sect2>
2072-
<title>Sample Program 2</title>
2070+
<example id="libpq-example-2">
2071+
<title>libpq Example Program 2</title>
20732072

2074-
<para>
20752073
<programlisting>
20762074
/*
20772075
* testlibpq2.c
@@ -2187,13 +2185,11 @@ main()
21872185
return 0;
21882186
}
21892187
</programlisting>
2190-
</para>
2191-
</sect2>
2188+
</example>
21922189

2193-
<sect2>
2194-
<title>SampleProgram 3</title>
2190+
<example id="libpq-example-3">
2191+
<title>libpq ExampleProgram 3</>
21952192

2196-
<para>
21972193
<programlisting>
21982194
/*
21992195
* testlibpq3.c Test the C version of Libpq, the Postgres frontend
@@ -2370,10 +2366,9 @@ main()
23702366
return 0;
23712367
}
23722368
</programlisting>
2373-
</para>
2369+
</example>
23742370

2375-
</sect2>
2376-
</sect1>
2371+
</sect1>
23772372
</chapter>
23782373

23792374
<!-- Keep this comment at the end of the file

‎src/interfaces/libpq/fe-connect.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.136 2000/10/0303:39:46 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.137 2000/10/0319:16:17 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -416,15 +416,12 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
416416
if (conn==NULL)
417417
return (PGconn*)NULL;
418418

419-
if ((pghost==NULL)||pghost[0]=='\0')
420-
{
421-
if ((tmp=getenv("PGHOST"))!=NULL)
422-
conn->pghost=strdup(tmp);
423-
}
424-
else
419+
if (pghost)
425420
conn->pghost=strdup(pghost);
421+
elseif ((tmp=getenv("PGHOST"))!=NULL)
422+
conn->pghost=strdup(tmp);
426423

427-
if ((pgport==NULL)||pgport[0]=='\0')
424+
if (pgport==NULL)
428425
{
429426
if ((tmp=getenv("PGPORT"))==NULL)
430427
tmp=DEF_PGPORT_STR;
@@ -433,7 +430,7 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
433430
else
434431
conn->pgport=strdup(pgport);
435432

436-
if ((pgtty==NULL)||pgtty[0]=='\0')
433+
if (pgtty==NULL)
437434
{
438435
if ((tmp=getenv("PGTTY"))==NULL)
439436
tmp=DefaultTty;
@@ -442,7 +439,7 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
442439
else
443440
conn->pgtty=strdup(pgtty);
444441

445-
if ((pgoptions==NULL)||pgoptions[0]=='\0')
442+
if (pgoptions==NULL)
446443
{
447444
if ((tmp=getenv("PGOPTIONS"))==NULL)
448445
tmp=DefaultOption;
@@ -476,7 +473,7 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
476473
else
477474
conn->pgpass=strdup(DefaultPassword);
478475

479-
if ((dbName==NULL)||dbName[0]=='\0')
476+
if (dbName==NULL)
480477
{
481478
if ((tmp=getenv("PGDATABASE"))!=NULL)
482479
conn->dbName=strdup(tmp);
@@ -705,7 +702,7 @@ connectDBStart(PGconn *conn)
705702

706703
MemSet((char*)&conn->raddr,0,sizeof(conn->raddr));
707704

708-
if (conn->pghostaddr!=NULL)
705+
if (conn->pghostaddr!=NULL&&conn->pghostaddr[0]!='\0')
709706
{
710707
/* Using pghostaddr avoids a hostname lookup */
711708
/* Note that this supports IPv4 only */
@@ -724,7 +721,7 @@ connectDBStart(PGconn *conn)
724721
memmove((char*)&(conn->raddr.in.sin_addr),
725722
(char*)&addr,sizeof(addr));
726723
}
727-
elseif (conn->pghost!=NULL)
724+
elseif (conn->pghost!=NULL&&conn->pghost[0]!='\0')
728725
{
729726
/* Using pghost, so we have to look-up the hostname */
730727
structhostent*hp;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp