Skip to content

Commit 1a0bc4c

Browse files
committed
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.
1 parent 90c35a9 commit 1a0bc4c

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

doc/src/sgml/libpq.sgml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4810,22 +4810,29 @@ typedef struct
48104810
parameters to be passed to the function; they must match the declared
48114811
function argument list. When the <parameter>isint</> field of a
48124812
parameter structure is true, the <parameter>u.integer</> value is sent
4813-
to the server as an integer of the indicated length (this must be 1,
4814-
2, or 4 bytes); proper byte-swapping occurs. When <parameter>isint</>
4813+
to the server as an integer of the indicated length (this must be
4814+
2 or 4 bytes); proper byte-swapping occurs. When <parameter>isint</>
48154815
is false, the indicated number of bytes at <parameter>*u.ptr</> are
48164816
sent with no processing; the data must be in the format expected by
48174817
the server for binary transmission of the function's argument data
4818-
type. <parameter>result_buf</parameter> is the buffer in which to
4819-
place the return value. The caller must have allocated sufficient
4818+
type. (The declaration of <parameter>u.ptr</> as being of
4819+
type <type>int *</> is historical; it would be better to consider
4820+
it <type>void *</>.)
4821+
<parameter>result_buf</parameter> points to the buffer in which to place
4822+
the function's return value. The caller must have allocated sufficient
48204823
space to store the return value. (There is no check!) The actual result
4821-
length will be returned in the integer pointed to by
4822-
<parameter>result_len</parameter>. If a 1, 2, or 4-byte integer result
4824+
length in bytes will be returned in the integer pointed to by
4825+
<parameter>result_len</parameter>. If a 2- or 4-byte integer result
48234826
is expected, set <parameter>result_is_int</parameter> to 1, otherwise
48244827
set it to 0. Setting <parameter>result_is_int</parameter> to 1 causes
48254828
<application>libpq</> to byte-swap the value if necessary, so that it
4826-
is delivered as a proper <type>int</type> value for the client machine.
4829+
is delivered as a proper <type>int</type> value for the client machine;
4830+
note that a 4-byte integer is delivered into <parameter>*result_buf</>
4831+
for either allowed result size.
48274832
When <parameter>result_is_int</> is 0, the binary-format byte string
4828-
sent by the server is returned unmodified.
4833+
sent by the server is returned unmodified. (In this case it's better
4834+
to consider <parameter>result_buf</parameter> as being of
4835+
type <type>void *</>.)
48294836
</para>
48304837

48314838
<para>

src/interfaces/libpq/fe-exec.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,20 +2514,18 @@ PQendcopy(PGconn *conn)
25142514
* PQfn - Send a function call to the POSTGRES backend.
25152515
*
25162516
* conn : backend connection
2517-
* fnid : function id
2518-
* result_buf : pointer to result buffer (&int if integer)
2519-
* result_len : length of return value.
2520-
* actual_result_len: actual length returned. (differs from result_len
2521-
* for varlena structures.)
2522-
* result_type : If the result is an integer, this must be 1,
2517+
* fnid : OID of function to be called
2518+
* result_buf : pointer to result buffer
2519+
* result_len : actual length of result is returned here
2520+
* result_is_int : If the result is an integer, this must be 1,
25232521
* otherwise this should be 0
2524-
* args : pointer to an array of function arguments.
2522+
* args : pointer to an array of function arguments
25252523
* (each has length, if integer, and value/pointer)
25262524
* nargs : # of arguments in args array.
25272525
*
25282526
* RETURNS
25292527
* PGresult with status = PGRES_COMMAND_OK if successful.
2530-
* *actual_result_len is > 0 if there is a return value, 0 if not.
2528+
* *result_len is > 0 if there is a return value, 0 if not.
25312529
* PGresult with status = PGRES_FATAL_ERROR if backend returns an error.
25322530
* NULL on communications failure. conn->errorMessage will be set.
25332531
* ----------------
@@ -2537,12 +2535,12 @@ PGresult *
25372535
PQfn(PGconn *conn,
25382536
int fnid,
25392537
int *result_buf,
2540-
int *actual_result_len,
2538+
int *result_len,
25412539
int result_is_int,
25422540
const PQArgBlock *args,
25432541
int nargs)
25442542
{
2545-
*actual_result_len = 0;
2543+
*result_len = 0;
25462544

25472545
if (!conn)
25482546
return NULL;
@@ -2560,12 +2558,12 @@ PQfn(PGconn *conn,
25602558

25612559
if (PG_PROTOCOL_MAJOR(conn->pversion) >= 3)
25622560
return pqFunctionCall3(conn, fnid,
2563-
result_buf, actual_result_len,
2561+
result_buf, result_len,
25642562
result_is_int,
25652563
args, nargs);
25662564
else
25672565
return pqFunctionCall2(conn, fnid,
2568-
result_buf, actual_result_len,
2566+
result_buf, result_len,
25692567
result_is_int,
25702568
args, nargs);
25712569
}

0 commit comments

Comments
 (0)