1- <!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.295 2010/01/21 14:58:52 rhaas Exp $ -->
1+ <!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.296 2010/01/28 06:28:26 joe Exp $ -->
22
33<chapter id="libpq">
44 <title><application>libpq</application> - C Library</title>
5656 one time. (One reason to do that is to access more than one
5757 database.) Each connection is represented by a
5858 <structname>PGconn</><indexterm><primary>PGconn</></> object, which
59- is obtained from the function <function>PQconnectdb</> or
59+ is obtained from the function <function>PQconnectdb</>,
60+ <function>PQconnectdbParams</>, or
6061 <function>PQsetdbLogin</>. Note that these functions will always
6162 return a non-null object pointer, unless perhaps there is too
6263 little memory even to allocate the <structname>PGconn</> object.
9192
9293 <variablelist>
9394 <varlistentry>
94- <term><function>PQconnectdb </function><indexterm><primary>PQconnectdb </></></term>
95+ <term><function>PQconnectdbParams </function><indexterm><primary>PQconnectdbParams </></></term>
9596 <listitem>
9697 <para>
9798 Makes a new connection to the database server.
9899
99100 <synopsis>
100- PGconn *PQconnectdb (const char *conninfo );
101+ PGconn *PQconnectdbParams (const char **keywords, const char **values );
101102 </synopsis>
102103 </para>
103104
104105 <para>
105106 This function opens a new database connection using the parameters taken
106- from the string <literal>conninfo</literal>. Unlike <function>PQsetdbLogin</> below,
107- the parameter set can be extended without changing the function signature,
108- so use of this function (or its nonblocking analogues <function>PQconnectStart</>
109- and <function>PQconnectPoll</function>) is preferred for new application programming.
107+ from two <symbol>NULL</symbol>-terminated arrays. The first,
108+ <literal>keywords</literal>, is defined as an array of strings, each one
109+ being a key word. The second, <literal>values</literal>, gives the value
110+ for each key word. Unlike <function>PQsetdbLogin</> below, the parameter
111+ set can be extended without changing the function signature, so use of
112+ this function (or its nonblocking analogs <function>PQconnectStartParams</>
113+ and <function>PQconnectPoll</function>) is preferred for new application
114+ programming.
110115 </para>
111116
112117 <para>
113- The passed string
114- can be empty to use all default parameters, or it can contain one or more
115- parameter settings separated by whitespace.
116- Each parameter setting is in the form <literal>keyword = value</literal>.
117- Spaces around the equal sign are optional.
118- To write an empty value or a value containing
119- spaces, surround it with single quotes, e.g.,
120- <literal>keyword = 'a value'</literal>.
121- Single quotes and backslashes within the value must be escaped with a
122- backslash, i.e., <literal>\'</literal> and <literal>\\</literal>.
118+ The passed arrays can be empty to use all default parameters, or can
119+ contain one or more parameter settings. They should be matched in length.
120+ Processing will stop with the last non-<symbol>NULL</symbol> element
121+ of the <literal>keywords</literal> array.
123122 </para>
124123
125124 <para>
477476 </listitem>
478477 </varlistentry>
479478
479+ <varlistentry>
480+ <term><function>PQconnectdb</function><indexterm><primary>PQconnectdb</></></term>
481+ <listitem>
482+ <para>
483+ Makes a new connection to the database server.
484+
485+ <synopsis>
486+ PGconn *PQconnectdb(const char *conninfo);
487+ </synopsis>
488+ </para>
489+
490+ <para>
491+ This function opens a new database connection using the parameters taken
492+ from the string <literal>conninfo</literal>.
493+ </para>
494+
495+ <para>
496+ The passed string can be empty to use all default parameters, or it can
497+ contain one or more parameter settings separated by whitespace.
498+ Each parameter setting is in the form <literal>keyword = value</literal>.
499+ Spaces around the equal sign are optional. To write an empty value,
500+ or a value containing spaces, surround it with single quotes, e.g.,
501+ <literal>keyword = 'a value'</literal>. Single quotes and backslashes
502+ within the value must be escaped with a backslash, i.e.,
503+ <literal>\'</literal> and <literal>\\</literal>.
504+ </para>
505+
506+ <para>
507+ The currently recognized parameter key words are the same as above.
508+ </para>
509+ </listitem>
510+ </varlistentry>
511+
480512 <varlistentry>
481513 <term><function>PQsetdbLogin</function><indexterm><primary>PQsetdbLogin</></></term>
482514 <listitem>
@@ -532,13 +564,18 @@ PGconn *PQsetdb(char *pghost,
532564 </varlistentry>
533565
534566 <varlistentry>
567+ <term><function>PQconnectStartParams</function><indexterm><primary>PQconnectStartParams</></></term>
535568 <term><function>PQconnectStart</function><indexterm><primary>PQconnectStart</></></term>
536569 <term><function>PQconnectPoll</function><indexterm><primary>PQconnectPoll</></></term>
537570 <listitem>
538571 <para>
539572 <indexterm><primary>nonblocking connection</primary></indexterm>
540573 Make a connection to the database server in a nonblocking manner.
541574
575+ <synopsis>
576+ PGconn *PQconnectStartParams(const char **keywords, const char **values);
577+ </synopsis>
578+
542579 <synopsis>
543580 PGconn *PQconnectStart(const char *conninfo);
544581 </synopsis>
@@ -549,29 +586,37 @@ PGconn *PQsetdb(char *pghost,
549586 </para>
550587
551588 <para>
552- These two functions are used to open a connection to a database server such
589+ These three functions are used to open a connection to a database server such
553590 that your application's thread of execution is not blocked on remote I/O
554- whilst doing so.
555- The point of this approach is that the waits for I/O to complete can occur
556- in the application's main loop, rather than down inside
557- <function>PQconnectdb</>, and so the application can manage this
558- operation in parallel with other activities.
591+ whilst doing so. The point of this approach is that the waits for I/O to
592+ complete can occur in the application's main loop, rather than down inside
593+ <function>PQconnectdbParams</> or <function>PQconnectdb</>, and so the
594+ application can manage this operation in parallel with other activities.
559595 </para>
560596
561597 <para>
562- The database connection is made using the parameters taken from the string
563- <literal>conninfo</literal>, passed to <function>PQconnectStart</function>. This string is in
564- the same format as described above for <function>PQconnectdb</function>.
598+ With <function>PQconnectStartParams</function>, the database connection is made
599+ using the parameters taken from the <literal>keywords</literal> and
600+ <literal>values</literal> arrays, as described above for
601+ <function>PQconnectdbParams</function>.
565602 </para>
603+
566604 <para>
567- Neither <function>PQconnectStart</function> nor <function>PQconnectPoll</function> will block, so long as a number of
605+ With <function>PQconnectStart</function>, the database connection is made
606+ using the parameters taken from the string <literal>conninfo</literal> as
607+ described above for <function>PQconnectdb</function>.
608+ </para>
609+
610+ <para>
611+ Neither <function>PQconnectStartParams</function> nor <function>PQconnectStart</function>
612+ nor <function>PQconnectPoll</function> will block, so long as a number of
568613 restrictions are met:
569614 <itemizedlist>
570615 <listitem>
571616 <para>
572617 The <literal>hostaddr</> and <literal>host</> parameters are used appropriately to ensure that
573618 name and reverse name queries are not made. See the documentation of
574- these parameters under <function>PQconnectdb </function> above for details.
619+ these parameters under <function>PQconnectdbParams </function> above for details.
575620 </para>
576621 </listitem>
577622
@@ -591,6 +636,11 @@ PGconn *PQsetdb(char *pghost,
591636 </itemizedlist>
592637 </para>
593638
639+ <para>
640+ Note: use of <function>PQconnectStartParams</> is analogous to
641+ <function>PQconnectStart</> shown below.
642+ </para>
643+
594644 <para>
595645 To begin a nonblocking connection request, call <literal>conn = PQconnectStart("<replaceable>connection_info_string</>")</literal>.
596646 If <varname>conn</varname> is null, then <application>libpq</> has been unable to allocate a new <structname>PGconn</>
@@ -883,7 +933,8 @@ PQconninfoOption *PQconninfoParse(const char *conninfo, char **errmsg);
883933 parameters previously used. This can be useful for error recovery if a
884934 working connection is lost. They differ from <function>PQreset</function> (above) in that they
885935 act in a nonblocking manner. These functions suffer from the same
886- restrictions as <function>PQconnectStart</> and <function>PQconnectPoll</>.
936+ restrictions as <function>PQconnectStartParams</>, <function>PQconnectStart</>
937+ and <function>PQconnectPoll</>.
887938 </para>
888939
889940 <para>
@@ -1096,9 +1147,9 @@ PQconninfoOption *PQconninfoParse(const char *conninfo, char **errmsg);
10961147 </para>
10971148
10981149 <para>
1099- See the entry for <function>PQconnectStart </> and <function>PQconnectPoll </> with regards
1100- to other status codes
1101- that might be seen.
1150+ See the entry for <function>PQconnectStartParams </>, <function>PQconnectStart </>
1151+ and <function>PQconnectPoll</> with regards to other status codes that
1152+ might be seen.
11021153 </para>
11031154 </listitem>
11041155 </varlistentry>
0 commit comments