Commit 1a0bc4c2 authored by Tom Lane's avatar Tom Lane

Fix documentation for libpq's PQfn().

The SGML docs claimed that 1-byte integers could be sent or received with
the "isint" options, but no such behavior has ever been implemented in
pqGetInt() or pqPutInt().  The in-code documentation header for PQfn() was
even less in tune with reality, and the code itself used parameter names
matching neither the SGML docs nor its libpq-fe.h declaration.  Do a bit
of additional wordsmithing on the SGML docs while at it.

Since the business about 1-byte integers is a clear documentation bug,
back-patch to all supported branches.
parent 90c35a9e
...@@ -4810,22 +4810,29 @@ typedef struct ...@@ -4810,22 +4810,29 @@ typedef struct
parameters to be passed to the function; they must match the declared parameters to be passed to the function; they must match the declared
function argument list. When the <parameter>isint</> field of a function argument list. When the <parameter>isint</> field of a
parameter structure is true, the <parameter>u.integer</> value is sent parameter structure is true, the <parameter>u.integer</> value is sent
to the server as an integer of the indicated length (this must be 1, to the server as an integer of the indicated length (this must be
2, or 4 bytes); proper byte-swapping occurs. When <parameter>isint</> 2 or 4 bytes); proper byte-swapping occurs. When <parameter>isint</>
is false, the indicated number of bytes at <parameter>*u.ptr</> are is false, the indicated number of bytes at <parameter>*u.ptr</> are
sent with no processing; the data must be in the format expected by sent with no processing; the data must be in the format expected by
the server for binary transmission of the function's argument data the server for binary transmission of the function's argument data
type. <parameter>result_buf</parameter> is the buffer in which to type. (The declaration of <parameter>u.ptr</> as being of
place the return value. The caller must have allocated sufficient type <type>int *</> is historical; it would be better to consider
it <type>void *</>.)
<parameter>result_buf</parameter> points to the buffer in which to place
the function's return value. The caller must have allocated sufficient
space to store the return value. (There is no check!) The actual result space to store the return value. (There is no check!) The actual result
length will be returned in the integer pointed to by length in bytes will be returned in the integer pointed to by
<parameter>result_len</parameter>. If a 1, 2, or 4-byte integer result <parameter>result_len</parameter>. If a 2- or 4-byte integer result
is expected, set <parameter>result_is_int</parameter> to 1, otherwise is expected, set <parameter>result_is_int</parameter> to 1, otherwise
set it to 0. Setting <parameter>result_is_int</parameter> to 1 causes set it to 0. Setting <parameter>result_is_int</parameter> to 1 causes
<application>libpq</> to byte-swap the value if necessary, so that it <application>libpq</> to byte-swap the value if necessary, so that it
is delivered as a proper <type>int</type> value for the client machine. is delivered as a proper <type>int</type> value for the client machine;
note that a 4-byte integer is delivered into <parameter>*result_buf</>
for either allowed result size.
When <parameter>result_is_int</> is 0, the binary-format byte string When <parameter>result_is_int</> is 0, the binary-format byte string
sent by the server is returned unmodified. sent by the server is returned unmodified. (In this case it's better
to consider <parameter>result_buf</parameter> as being of
type <type>void *</>.)
</para> </para>
<para> <para>
......
...@@ -2514,20 +2514,18 @@ PQendcopy(PGconn *conn) ...@@ -2514,20 +2514,18 @@ PQendcopy(PGconn *conn)
* PQfn - Send a function call to the POSTGRES backend. * PQfn - Send a function call to the POSTGRES backend.
* *
* conn : backend connection * conn : backend connection
* fnid : function id * fnid : OID of function to be called
* result_buf : pointer to result buffer (&int if integer) * result_buf : pointer to result buffer
* result_len : length of return value. * result_len : actual length of result is returned here
* actual_result_len: actual length returned. (differs from result_len * result_is_int : If the result is an integer, this must be 1,
* for varlena structures.)
* result_type : If the result is an integer, this must be 1,
* otherwise this should be 0 * otherwise this should be 0
* args : pointer to an array of function arguments. * args : pointer to an array of function arguments
* (each has length, if integer, and value/pointer) * (each has length, if integer, and value/pointer)
* nargs : # of arguments in args array. * nargs : # of arguments in args array.
* *
* RETURNS * RETURNS
* PGresult with status = PGRES_COMMAND_OK if successful. * PGresult with status = PGRES_COMMAND_OK if successful.
* *actual_result_len is > 0 if there is a return value, 0 if not. * *result_len is > 0 if there is a return value, 0 if not.
* PGresult with status = PGRES_FATAL_ERROR if backend returns an error. * PGresult with status = PGRES_FATAL_ERROR if backend returns an error.
* NULL on communications failure. conn->errorMessage will be set. * NULL on communications failure. conn->errorMessage will be set.
* ---------------- * ----------------
...@@ -2537,12 +2535,12 @@ PGresult * ...@@ -2537,12 +2535,12 @@ PGresult *
PQfn(PGconn *conn, PQfn(PGconn *conn,
int fnid, int fnid,
int *result_buf, int *result_buf,
int *actual_result_len, int *result_len,
int result_is_int, int result_is_int,
const PQArgBlock *args, const PQArgBlock *args,
int nargs) int nargs)
{ {
*actual_result_len = 0; *result_len = 0;
if (!conn) if (!conn)
return NULL; return NULL;
...@@ -2560,12 +2558,12 @@ PQfn(PGconn *conn, ...@@ -2560,12 +2558,12 @@ PQfn(PGconn *conn,
if (PG_PROTOCOL_MAJOR(conn->pversion) >= 3) if (PG_PROTOCOL_MAJOR(conn->pversion) >= 3)
return pqFunctionCall3(conn, fnid, return pqFunctionCall3(conn, fnid,
result_buf, actual_result_len, result_buf, result_len,
result_is_int, result_is_int,
args, nargs); args, nargs);
else else
return pqFunctionCall2(conn, fnid, return pqFunctionCall2(conn, fnid,
result_buf, actual_result_len, result_buf, result_len,
result_is_int, result_is_int,
args, nargs); args, nargs);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment