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

Commit5133dd7

Browse files
committed
Interpret a dbName param to PQsetdbLogin as a conninfo string if it contains an = sign. Tom Lane and Andrew Dunstan.
1 parent93b4f0f commit5133dd7

File tree

3 files changed

+61
-26
lines changed

3 files changed

+61
-26
lines changed

‎doc/src/sgml/libpq.sgml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.220 2006/11/10 22:15:26 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.221 2006/12/19 01:53:36 adunstan Exp $ -->
22

33
<chapter id="libpq">
44
<title><application>libpq</application> - C Library</title>
@@ -324,13 +324,19 @@ PGconn *PQsetdbLogin(const char *pghost,
324324
const char *login,
325325
const char *pwd);
326326
</synopsis>
327-
</para>
327+
</para>
328328

329-
<para>
330-
This is the predecessor of <function>PQconnectdb</function> with a fixed
331-
set of parameters. It has the same functionality except that the
332-
missing parameters will always take on default values. Write <symbol>NULL</symbol> or an
333-
empty string for any one of the fixed parameters that is to be defaulted.
329+
<para>
330+
This is the predecessor of <function>PQconnectdb</function> with a fixed
331+
set of parameters. It has the same functionality except that the
332+
missing parameters will always take on default values. Write <symbol>NULL</symbol> or an
333+
empty string for any one of the fixed parameters that is to be defaulted.
334+
</para>
335+
<para>
336+
If the <parameter>dbName</parameter> contains an <symbol>=</symbol> sign, it
337+
is taken as a <parameter>conninfo</parameter> string in exactly the same way as
338+
if it had been passed to <function>PQconnectdb</function>, and the remaining
339+
parameters are then applied as above.
334340
</para>
335341
</listitem>
336342
</varlistentry>

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.178 2006/12/06 15:47:22 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.179 2006/12/19 01:53:36 adunstan Exp $
33
PostgreSQL documentation
44
-->
55

@@ -113,6 +113,10 @@ PostgreSQL documentation
113113
class="parameter">dbname</replaceable> as the first non-option
114114
argument on the command line.
115115
</para>
116+
<para>
117+
If this parameter contains an <symbol>=</symbol> sign, it it treated as a
118+
<parameter>conninfo</parameter> string. See <xref linkend="libpq-connect"> for more information.
119+
</para>
116120
</listitem>
117121
</varlistentry>
118122

@@ -555,6 +559,18 @@ PostgreSQL documentation
555559
passwords. See <xref linkend="libpq-pgpass"> for more information.
556560
</para>
557561

562+
<para>
563+
An alternative way to specify connection parameters is in a
564+
<parameter>conninfo</parameter>string, which is used instead of a
565+
database name. This mechanism give you very wide control over the
566+
connection. For example,
567+
<programlisting>
568+
$ <userinput>psql "service=myservice sslmode=require"</userinput>
569+
</programlisting>
570+
See <xref linkend="libpq-connect"> for more information on all the
571+
available connection options.
572+
</para>
573+
558574
<para>
559575
If the connection could not be made for any reason (e.g., insufficient
560576
privileges, server is not running on the targeted host, etc.),

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

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.339 2006/11/21 16:28:00 tgl Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.340 2006/12/19 01:53:36 adunstan Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -574,16 +574,36 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
574574
conn=makeEmptyPGconn();
575575
if (conn==NULL)
576576
returnNULL;
577-
578-
/*
579-
* Parse an empty conninfo string in order to set up the same defaults
580-
* that PQconnectdb() would use.
581-
*/
582-
if (!connectOptions1(conn,""))
583-
returnconn;
584-
585-
/*
586-
* Absorb specified options into conn structure, overriding defaults
577+
/*
578+
* If the dbName parameter contains '=', assume it's a conninfo
579+
* string.
580+
*/
581+
if (dbName&&strchr(dbName,'='))
582+
{
583+
if (!connectOptions1(conn,dbName))
584+
returnconn;
585+
}
586+
else
587+
{
588+
/*
589+
* Old-style path: first, parse an empty conninfo string in
590+
* order to set up the same defaults that PQconnectdb() would use.
591+
*/
592+
if (!connectOptions1(conn,""))
593+
returnconn;
594+
595+
/* Insert dbName parameter value into struct */
596+
if (dbName&&dbName[0]!='\0')
597+
{
598+
if (conn->dbName)
599+
free(conn->dbName);
600+
conn->dbName=strdup(dbName);
601+
}
602+
}
603+
604+
/*
605+
* Insert remaining parameters into struct, overriding defaults
606+
* (as well as any conflicting data from dbName taken as a conninfo).
587607
*/
588608
if (pghost&&pghost[0]!='\0')
589609
{
@@ -613,13 +633,6 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions,
613633
conn->pgtty=strdup(pgtty);
614634
}
615635

616-
if (dbName&&dbName[0]!='\0')
617-
{
618-
if (conn->dbName)
619-
free(conn->dbName);
620-
conn->dbName=strdup(dbName);
621-
}
622-
623636
if (login&&login[0]!='\0')
624637
{
625638
if (conn->pguser)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp