11<!--
2- $Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.119 2003/04/19 00:02:29 tgl Exp $
2+ $Header: /cvsroot/pgsql/doc/src/sgml/libpq.sgml,v 1.120 2003/04/22 00:08:06 tgl Exp $
33-->
44
55 <chapter id="libpq">
@@ -175,7 +175,8 @@ PGconn *PQconnectdb(const char *conninfo);
175175 <term><literal>connect_timeout</literal></term>
176176 <listitem>
177177 <para>
178- Time space in seconds given to connection function. Zero or not set means infinite.
178+ Maximum wait for connection, in seconds (write as a decimal integer
179+ string). Zero or not specified means infinite.
179180 </para>
180181 </listitem>
181182 </varlistentry>
@@ -184,7 +185,7 @@ PGconn *PQconnectdb(const char *conninfo);
184185 <term><literal>options</literal></term>
185186 <listitem>
186187 <para>
187- Configuration options to be sent to the server.
188+ Command-line options to be sent to the server.
188189 </para>
189190 </listitem>
190191 </varlistentry>
@@ -252,8 +253,9 @@ PGconn *PQsetdbLogin(const char *pghost,
252253</para>
253254
254255<para>
255- This is the predecessor of <function>PQconnectdb</function> with a fixed number
256- of parameters but the same functionality.
256+ This is the predecessor of <function>PQconnectdb</function> with a fixed
257+ number of parameters. It has the same functionality except that the
258+ missing parameters cannot be specified in the call.
257259 </para>
258260 </listitem>
259261 </varlistentry>
@@ -274,8 +276,8 @@ PGconn *PQsetdb(char *pghost,
274276
275277<para>
276278 This is a macro that calls <function>PQsetdbLogin</function> with null pointers
277- for the <parameter>login</> and <parameter>pwd</> parameters. It is provided primarily
278- for backward compatibility with old programs.
279+ for the <parameter>login</> and <parameter>pwd</> parameters. It is provided
280+ for backward compatibility withvery old programs.
279281 </para>
280282 </listitem>
281283 </varlistentry>
@@ -454,7 +456,7 @@ switch(PQstatus(conn))
454456 </para>
455457
456458 <para>
457- Finally, these functions leave thesocket in a nonblocking state as if
459+ Finally, these functions leave theconnection in a nonblocking state as if
458460 <function>PQsetnonblocking</function> had been called.
459461 </para>
460462 </listitem>
@@ -486,8 +488,6 @@ typedef struct
486488</para>
487489
488490<para>
489- converts an escaped string representation of binary data into binary
490- data --- the reverse of <function>PQescapeBytea</function>.
491491 Returns a connection options array. This may
492492 be used to determine all possible <function>PQconnectdb</function> options and their
493493 current default values. The return value points to an array of
@@ -683,7 +683,7 @@ char *PQtty(const PGconn *conn);
683683<term><function>PQoptions</function></term>
684684<listitem>
685685<para>
686- Returns theconfiguration options passed in the connection request.
686+ Returns thecommand-line options passed in the connection request.
687687<synopsis>
688688char *PQoptions(const PGconn *conn);
689689</synopsis>
@@ -2047,13 +2047,13 @@ contains example functions that correctly handle the <command>COPY</command> pro
20472047<term><function>PQgetlineAsync</function></term>
20482048<listitem>
20492049<para>
2050- Reads a newline-terminated line of characters
2050+ Readsa row ofCOPY data
20512051 (transmitted by the server) into a buffer
20522052 without blocking.
20532053<synopsis>
20542054int PQgetlineAsync(PGconn *conn,
20552055 char *buffer,
2056- intlength );
2056+ intbufsize );
20572057</synopsis>
20582058</para>
20592059
@@ -2070,24 +2070,27 @@ end-of-data signal is detected.
20702070<para>
20712071Unlike <function>PQgetline</function>, this function takes
20722072responsibility for detecting end-of-data.
2073- On each call, <function>PQgetlineAsync</function> will return data if a complete newline-
2074- terminated data line is available in <application>libpq</>'s input buffer, or if the
2075- incoming data line is too long to fit in the buffer offered by the caller.
2076- Otherwise, no data is returned until the rest of the line arrives.
2073+ </para>
2074+ <para>
2075+ On each call, <function>PQgetlineAsync</function> will return data if a
2076+ complete data row is available in <application>libpq</>'s input buffer.
2077+ Otherwise, no data is returned until the rest of the row arrives.
20772078The function returns -1 if the end-of-copy-data marker has been recognized,
20782079or 0 if no data is available, or a positive number giving the number of
20792080bytes of data returned. If -1 is returned, the caller must next call
20802081<function>PQendcopy</function>, and then return to normal processing.
20812082</para>
20822083<para>
2083- The data returned will not extend beyond a newline character. If possible
2084- a whole line will be returned at one time. But if the buffer offered by
2085- the caller is too small to hold a line sent by the server, then a partial
2086- data line will be returned. This can be detected by testing whether the
2087- last returned byte is <literal>\n</literal> or not.
2084+ The data returned will not extend beyond a data-row boundary. If possible
2085+ a whole row will be returned at one time. But if the buffer offered by
2086+ the caller is too small to hold a row sent by the server, then a partial
2087+ data row will be returned. With textual data this can be detected by testing
2088+ whether the last returned byte is <literal>\n</literal> or not. (In a binary
2089+ COPY, actual parsing of the COPY data format will be needed to make the
2090+ equivalent determination.)
20882091The returned string is not null-terminated. (If you want to add a
2089- terminating null, be sure to pass a <parameter>length </parameter> one smaller than the room
2090- actually available.)
2092+ terminating null, be sure to pass a <parameter>bufsize </parameter> one smaller
2093+ than the room actually available.)
20912094</para>
20922095</listitem>
20932096</varlistentry>
@@ -2105,10 +2108,24 @@ int PQputline(PGconn *conn,
21052108</para>
21062109
21072110<para>
2108- Note the application must explicitly send the two
2109- characters <literal>\.</literal> on a final line to indicate to
2110- the server that it has finished sending its data.
2111+ The COPY datastream sent by a series of calls to
2112+ <function>PQputline</function> has the same format as that returned by
2113+ <function>PQgetlineAsync</function>, except that applications are not
2114+ obliged to send exactly one data row per <function>PQputline</function>
2115+ call; it is okay to send a partial line or multiple lines per call.
21112116</para>
2117+
2118+ <note>
2119+ <para>
2120+ Before <productname>PostgreSQL</productname> 7.4, it was necessary for the
2121+ application to explicitly send the two characters <literal>\.</literal> as a
2122+ final line to indicate to the server that it had finished sending COPY data.
2123+ While this still works, it is deprecated and the special meaning of
2124+ <literal>\.</literal> can be expected to be removed in a future release.
2125+ It is sufficient to call <function>PQendcopy</function> after having sent the
2126+ actual data.
2127+ </para>
2128+ </note>
21122129</listitem>
21132130</varlistentry>
21142131
@@ -2126,9 +2143,9 @@ int PQputnbytes(PGconn *conn,
21262143</para>
21272144
21282145<para>
2129- This is exactly like <function>PQputline</function>, except that the data buffer need
2130- not be null-terminated since the number of bytes to send is
2131- specified directly.
2146+ This is exactly like <function>PQputline</function>, except that the data
2147+ buffer need not be null-terminated since the number of bytes to send is
2148+ specified directly. Use this procedure when sending binary data.
21322149</para>
21332150</listitem>
21342151</varlistentry>
@@ -2147,11 +2164,12 @@ int PQendcopy(PGconn *conn);
21472164 sent to the server using <function>PQputline</function> or when the
21482165 last string has been received from the server
21492166 using <function>PGgetline</function>. It must be issued or the server
2150- may get <quote>out of sync</quote> with the client. Upon
2167+ will get <quote>out of sync</quote> with the client. Upon
21512168 return from this function, the server is ready to
21522169 receive the next SQL command.
21532170 The return value is 0 on successful completion,
2154- nonzero otherwise.
2171+ nonzero otherwise. (Use <function>PQerrorMessage</function> to retrieve
2172+ details if the return value is nonzero.)
21552173</para>
21562174
21572175<para>
@@ -2187,7 +2205,6 @@ PQexec(conn, "COPY foo FROM STDIN;");
21872205PQputline(conn, "3\thello world\t4.5\n");
21882206PQputline(conn, "4\tgoodbye world\t7.11\n");
21892207...
2190- PQputline(conn, "\\.\n");
21912208PQendcopy(conn);
21922209</programlisting>
21932210</para>