Skip to content

Commit ae67e81

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 ce37bf2 commit ae67e81

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
@@ -4579,22 +4579,29 @@ typedef struct
45794579
parameters to be passed to the function; they must match the declared
45804580
function argument list. When the <parameter>isint</> field of a
45814581
parameter structure is true, the <parameter>u.integer</> value is sent
4582-
to the server as an integer of the indicated length (this must be 1,
4583-
2, or 4 bytes); proper byte-swapping occurs. When <parameter>isint</>
4582+
to the server as an integer of the indicated length (this must be
4583+
2 or 4 bytes); proper byte-swapping occurs. When <parameter>isint</>
45844584
is false, the indicated number of bytes at <parameter>*u.ptr</> are
45854585
sent with no processing; the data must be in the format expected by
45864586
the server for binary transmission of the function's argument data
4587-
type. <parameter>result_buf</parameter> is the buffer in which to
4588-
place the return value. The caller must have allocated sufficient
4587+
type. (The declaration of <parameter>u.ptr</> as being of
4588+
type <type>int *</> is historical; it would be better to consider
4589+
it <type>void *</>.)
4590+
<parameter>result_buf</parameter> points to the buffer in which to place
4591+
the function's return value. The caller must have allocated sufficient
45894592
space to store the return value. (There is no check!) The actual result
4590-
length will be returned in the integer pointed to by
4591-
<parameter>result_len</parameter>. If a 1, 2, or 4-byte integer result
4593+
length in bytes will be returned in the integer pointed to by
4594+
<parameter>result_len</parameter>. If a 2- or 4-byte integer result
45924595
is expected, set <parameter>result_is_int</parameter> to 1, otherwise
45934596
set it to 0. Setting <parameter>result_is_int</parameter> to 1 causes
45944597
<application>libpq</> to byte-swap the value if necessary, so that it
4595-
is delivered as a proper <type>int</type> value for the client machine.
4598+
is delivered as a proper <type>int</type> value for the client machine;
4599+
note that a 4-byte integer is delivered into <parameter>*result_buf</>
4600+
for either allowed result size.
45964601
When <parameter>result_is_int</> is 0, the binary-format byte string
4597-
sent by the server is returned unmodified.
4602+
sent by the server is returned unmodified. (In this case it's better
4603+
to consider <parameter>result_buf</parameter> as being of
4604+
type <type>void *</>.)
45984605
</para>
45994606

46004607
<para>

src/interfaces/libpq/fe-exec.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,20 +2488,18 @@ PQendcopy(PGconn *conn)
24882488
* PQfn - Send a function call to the POSTGRES backend.
24892489
*
24902490
* conn : backend connection
2491-
* fnid : function id
2492-
* result_buf : pointer to result buffer (&int if integer)
2493-
* result_len : length of return value.
2494-
* actual_result_len: actual length returned. (differs from result_len
2495-
* for varlena structures.)
2496-
* result_type : If the result is an integer, this must be 1,
2491+
* fnid : OID of function to be called
2492+
* result_buf : pointer to result buffer
2493+
* result_len : actual length of result is returned here
2494+
* result_is_int : If the result is an integer, this must be 1,
24972495
* otherwise this should be 0
2498-
* args : pointer to an array of function arguments.
2496+
* args : pointer to an array of function arguments
24992497
* (each has length, if integer, and value/pointer)
25002498
* nargs : # of arguments in args array.
25012499
*
25022500
* RETURNS
25032501
* PGresult with status = PGRES_COMMAND_OK if successful.
2504-
* *actual_result_len is > 0 if there is a return value, 0 if not.
2502+
* *result_len is > 0 if there is a return value, 0 if not.
25052503
* PGresult with status = PGRES_FATAL_ERROR if backend returns an error.
25062504
* NULL on communications failure. conn->errorMessage will be set.
25072505
* ----------------
@@ -2511,12 +2509,12 @@ PGresult *
25112509
PQfn(PGconn *conn,
25122510
int fnid,
25132511
int *result_buf,
2514-
int *actual_result_len,
2512+
int *result_len,
25152513
int result_is_int,
25162514
const PQArgBlock *args,
25172515
int nargs)
25182516
{
2519-
*actual_result_len = 0;
2517+
*result_len = 0;
25202518

25212519
if (!conn)
25222520
return NULL;
@@ -2534,12 +2532,12 @@ PQfn(PGconn *conn,
25342532

25352533
if (PG_PROTOCOL_MAJOR(conn->pversion) >= 3)
25362534
return pqFunctionCall3(conn, fnid,
2537-
result_buf, actual_result_len,
2535+
result_buf, result_len,
25382536
result_is_int,
25392537
args, nargs);
25402538
else
25412539
return pqFunctionCall2(conn, fnid,
2542-
result_buf, actual_result_len,
2540+
result_buf, result_len,
25432541
result_is_int,
25442542
args, nargs);
25452543
}

0 commit comments

Comments
 (0)