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 $ -->
2
2
3
3
<chapter id="libpq">
4
4
<title><application>libpq</application> - C Library</title>
56
56
one time. (One reason to do that is to access more than one
57
57
database.) Each connection is represented by a
58
58
<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
60
61
<function>PQsetdbLogin</>. Note that these functions will always
61
62
return a non-null object pointer, unless perhaps there is too
62
63
little memory even to allocate the <structname>PGconn</> object.
91
92
92
93
<variablelist>
93
94
<varlistentry>
94
- <term><function>PQconnectdb </function><indexterm><primary>PQconnectdb </></></term>
95
+ <term><function>PQconnectdbParams </function><indexterm><primary>PQconnectdbParams </></></term>
95
96
<listitem>
96
97
<para>
97
98
Makes a new connection to the database server.
98
99
99
100
<synopsis>
100
- PGconn *PQconnectdb (const char *conninfo );
101
+ PGconn *PQconnectdbParams (const char **keywords, const char **values );
101
102
</synopsis>
102
103
</para>
103
104
104
105
<para>
105
106
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.
110
115
</para>
111
116
112
117
<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.
123
122
</para>
124
123
125
124
<para>
477
476
</listitem>
478
477
</varlistentry>
479
478
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
+
480
512
<varlistentry>
481
513
<term><function>PQsetdbLogin</function><indexterm><primary>PQsetdbLogin</></></term>
482
514
<listitem>
@@ -532,13 +564,18 @@ PGconn *PQsetdb(char *pghost,
532
564
</varlistentry>
533
565
534
566
<varlistentry>
567
+ <term><function>PQconnectStartParams</function><indexterm><primary>PQconnectStartParams</></></term>
535
568
<term><function>PQconnectStart</function><indexterm><primary>PQconnectStart</></></term>
536
569
<term><function>PQconnectPoll</function><indexterm><primary>PQconnectPoll</></></term>
537
570
<listitem>
538
571
<para>
539
572
<indexterm><primary>nonblocking connection</primary></indexterm>
540
573
Make a connection to the database server in a nonblocking manner.
541
574
575
+ <synopsis>
576
+ PGconn *PQconnectStartParams(const char **keywords, const char **values);
577
+ </synopsis>
578
+
542
579
<synopsis>
543
580
PGconn *PQconnectStart(const char *conninfo);
544
581
</synopsis>
@@ -549,29 +586,37 @@ PGconn *PQsetdb(char *pghost,
549
586
</para>
550
587
551
588
<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
553
590
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.
559
595
</para>
560
596
561
597
<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>.
565
602
</para>
603
+
566
604
<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
568
613
restrictions are met:
569
614
<itemizedlist>
570
615
<listitem>
571
616
<para>
572
617
The <literal>hostaddr</> and <literal>host</> parameters are used appropriately to ensure that
573
618
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.
575
620
</para>
576
621
</listitem>
577
622
@@ -591,6 +636,11 @@ PGconn *PQsetdb(char *pghost,
591
636
</itemizedlist>
592
637
</para>
593
638
639
+ <para>
640
+ Note: use of <function>PQconnectStartParams</> is analogous to
641
+ <function>PQconnectStart</> shown below.
642
+ </para>
643
+
594
644
<para>
595
645
To begin a nonblocking connection request, call <literal>conn = PQconnectStart("<replaceable>connection_info_string</>")</literal>.
596
646
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);
883
933
parameters previously used. This can be useful for error recovery if a
884
934
working connection is lost. They differ from <function>PQreset</function> (above) in that they
885
935
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</>.
887
938
</para>
888
939
889
940
<para>
@@ -1096,9 +1147,9 @@ PQconninfoOption *PQconninfoParse(const char *conninfo, char **errmsg);
1096
1147
</para>
1097
1148
1098
1149
<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.
1102
1153
</para>
1103
1154
</listitem>
1104
1155
</varlistentry>
0 commit comments