@@ -182,9 +182,6 @@ PGconn *PQconnectdb(const char *conninfo)
182
182
The return value is a pointer to an abstract struct
183
183
representing the connection to the backend.
184
184
</para>
185
- <para>
186
- This function is not thread-safe.
187
- </para>
188
185
</listitem>
189
186
190
187
<listitem>
@@ -204,9 +201,6 @@ PGconn *PQsetdbLogin(const char *pghost,
204
201
This is the predecessor of <function>PQconnectdb</function> with a fixed number
205
202
of parameters but the same functionality.
206
203
</para>
207
- <para>
208
- This function is not thread-safe.
209
- </para>
210
204
</listitem>
211
205
212
206
<listitem>
@@ -380,9 +374,6 @@ PostgresPollingStatusType *PQconnectPoll(PQconn *conn)
380
374
These functions leave the socket in a non-blocking state as if
381
375
<function>PQsetnonblocking</function> had been called.
382
376
</para>
383
- <para>
384
- These functions are not thread-safe.
385
- </para>
386
377
</listitem>
387
378
388
379
<listitem>
@@ -396,18 +387,17 @@ struct PQconninfoOption
396
387
char *keyword; /* The keyword of the option */
397
388
char *envvar; /* Fallback environment variable name */
398
389
char *compiled; /* Fallback compiled in default value */
399
- char *val; /* Option's value */
390
+ char *val; /* Option'scurrent value, or NULL */
400
391
char *label; /* Label for field in connect dialog */
401
392
char *dispchar; /* Character to display for this field
402
393
in a connect dialog. Values are:
403
394
"" Display entered value as is
404
395
"*" Password field - hide value
405
- "D" Debug options - don't
406
- create a field by default */
396
+ "D" Debug option - don't show by default */
407
397
int dispsize; /* Field size in characters for dialog */
408
398
}
409
399
</synopsis>
410
- Returnsthe address of the connection optionsstructure . This may
400
+ Returnsa connection optionsarray . This may
411
401
be used to determine all possible PQconnectdb options and their
412
402
current default values. The return value points to an array of
413
403
PQconninfoOption structs, which ends with an entry having a NULL
@@ -416,7 +406,14 @@ struct PQconninfoOption
416
406
Callers must treat the connection options data as read-only.
417
407
</para>
418
408
<para>
419
- This function is not thread-safe.
409
+ After processing the options array, free it by passing it to
410
+ PQconninfoFree(). If this is not done, a small amount of memory
411
+ is leaked for each call to PQconndefaults().
412
+ </para>
413
+ <para>
414
+ In PostgreSQL versions before 7.0, PQconndefaults() returned a pointer
415
+ to a static array, rather than a dynamically allocated array. That
416
+ wasn't thread-safe, so the behavior has been changed.
420
417
</para>
421
418
</listitem>
422
419
@@ -675,9 +672,6 @@ void PQsetenvAbort(PGsetenvHandle handle)
675
672
<para>
676
673
The procedure may be aborted at any time by calling PQsetenvAbort(handle).
677
674
</para>
678
- <para>
679
- These functions are not thread-safe.
680
- </para>
681
675
</listitem>
682
676
683
677
<listitem>
@@ -1019,7 +1013,7 @@ char * PQcmdTuples(const PGresult *res);
1019
1013
<synopsis>
1020
1014
Oid PQoidValue(const PGresult *res);
1021
1015
</synopsis>
1022
- The type <type>Oid</type> and the constant <literal>Invalid </literal>
1016
+ The type <type>Oid</type> and the constant <literal>InvalidOid </literal>
1023
1017
will be defined if you include the <application>libpq</application>
1024
1018
header file. They will both be some integer type.
1025
1019
</para>
@@ -1034,7 +1028,7 @@ Oid PQoidValue(const PGresult *res);
1034
1028
<synopsis>
1035
1029
char * PQoidStatus(const PGresult *res);
1036
1030
</synopsis>
1037
- The function is deprecated in favor of <function>PQoidValue</function>
1031
+ This function is deprecated in favor of <function>PQoidValue</function>
1038
1032
and is not thread-safe.
1039
1033
</para>
1040
1034
</listitem>
@@ -1773,13 +1767,14 @@ PQsetNoticeProcessor(PGconn *conn,
1773
1767
</para>
1774
1768
1775
1769
<para>
1776
- By default, <application>libpq</application> prints <quote>notice</quote> messages
1777
- from the backendas well as a few error messages that it generates by itself
1778
- on <filename>stderr</filename> .
1770
+ By default, <application>libpq</application> prints <quote>notice</quote>
1771
+ messages from the backendon <filename>stderr</filename>,
1772
+ as well as a few error messages that it generates by itself .
1779
1773
This behavior can be overridden by supplying a callback function that
1780
1774
does something else with the messages. The callback function is passed
1781
1775
the text of the error message (which includes a trailing newline), plus
1782
- a void pointer that is the same one passed to <function>PQsetNoticeProcessor</function>.
1776
+ a void pointer that is the same one passed to
1777
+ <function>PQsetNoticeProcessor</function>.
1783
1778
(This pointer can be used to access application-specific state if needed.)
1784
1779
The default notice processor is simply
1785
1780
<programlisting>
@@ -1789,13 +1784,23 @@ defaultNoticeProcessor(void * arg, const char * message)
1789
1784
fprintf(stderr, "%s", message);
1790
1785
}
1791
1786
</programlisting>
1792
- To use a special notice processor, call <function>PQsetNoticeProcessor</function> just after
1787
+ To use a special notice processor, call
1788
+ <function>PQsetNoticeProcessor</function> just after
1793
1789
creation of a new PGconn object.
1794
1790
</para>
1795
1791
1796
1792
<para>
1797
- The return value is the pointer to the previous notice processor. If you supply a callback
1798
- function pointer of NULL, no action is taken, but the current pointer is returned.
1793
+ The return value is the pointer to the previous notice processor.
1794
+ If you supply a callback function pointer of NULL, no action is taken,
1795
+ but the current pointer is returned.
1796
+ </para>
1797
+
1798
+ <para>
1799
+ Once you have set a notice processor, you should expect that that function
1800
+ could be called as long as either the PGconn object or PGresult objects
1801
+ made from it exist. At creation of a PGresult, the PGconn's current
1802
+ notice processor pointer is copied into the PGresult for possible use by
1803
+ routines like <function>PQgetvalue</function>.
1799
1804
</para>
1800
1805
1801
1806
</sect1>
@@ -1886,6 +1891,13 @@ sets the default style of date/time representation.
1886
1891
sets the default time zone.
1887
1892
</para>
1888
1893
</listitem>
1894
+ <listitem>
1895
+ <para>
1896
+ <envar>PGCLIENTENCODING</envar>
1897
+ sets the default client encoding (if MULTIBYTE support was selected
1898
+ when configuring Postgres).
1899
+ </para>
1900
+ </listitem>
1889
1901
</itemizedlist>
1890
1902
</para>
1891
1903
@@ -1910,6 +1922,33 @@ for information on correct values for these environment variables.
1910
1922
1911
1923
</sect1>
1912
1924
1925
+ <sect1 id="libpq-threading">
1926
+ <title>Threading Behavior</title>
1927
+
1928
+ <para>
1929
+ <filename>libpq</filename> is thread-safe as of
1930
+ <productname>PostgreSQL</productname> 7.0, so long as no two threads
1931
+ attempt to manipulate the same PGconn object at the same time. In particular,
1932
+ you can't issue concurrent queries from different threads through the same
1933
+ connection object. (If you need to run concurrent queries, start up multiple
1934
+ connections.)
1935
+ </para>
1936
+
1937
+ <para>
1938
+ PGresult objects are read-only after creation, and so can be passed around
1939
+ freely between threads.
1940
+ </para>
1941
+
1942
+ <para>
1943
+ The deprecated functions <function>PQoidStatus</function> and
1944
+ <function>fe_setauthsvc</function> are not thread-safe and should not be
1945
+ used in multi-thread programs. <function>PQoidStatus</function> can be
1946
+ replaced by <function>PQoidValue</function>. There is no good reason to
1947
+ call <function>fe_setauthsvc</function> at all.
1948
+ </para>
1949
+
1950
+ </sect1>
1951
+
1913
1952
<sect1>
1914
1953
<title>Sample Programs</title>
1915
1954