Skip to content

Commit 92bb008

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 1352ee9 commit 92bb008

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
@@ -4299,22 +4299,29 @@ typedef struct
42994299
parameters to be passed to the function; they must match the declared
43004300
function argument list. When the <parameter>isint</> field of a
43014301
parameter structure is true, the <parameter>u.integer</> value is sent
4302-
to the server as an integer of the indicated length (this must be 1,
4303-
2, or 4 bytes); proper byte-swapping occurs. When <parameter>isint</>
4302+
to the server as an integer of the indicated length (this must be
4303+
2 or 4 bytes); proper byte-swapping occurs. When <parameter>isint</>
43044304
is false, the indicated number of bytes at <parameter>*u.ptr</> are
43054305
sent with no processing; the data must be in the format expected by
43064306
the server for binary transmission of the function's argument data
4307-
type. <parameter>result_buf</parameter> is the buffer in which to
4308-
place the return value. The caller must have allocated sufficient
4307+
type. (The declaration of <parameter>u.ptr</> as being of
4308+
type <type>int *</> is historical; it would be better to consider
4309+
it <type>void *</>.)
4310+
<parameter>result_buf</parameter> points to the buffer in which to place
4311+
the function's return value. The caller must have allocated sufficient
43094312
space to store the return value. (There is no check!) The actual result
4310-
length will be returned in the integer pointed to by
4311-
<parameter>result_len</parameter>. If a 1, 2, or 4-byte integer result
4313+
length in bytes will be returned in the integer pointed to by
4314+
<parameter>result_len</parameter>. If a 2- or 4-byte integer result
43124315
is expected, set <parameter>result_is_int</parameter> to 1, otherwise
43134316
set it to 0. Setting <parameter>result_is_int</parameter> to 1 causes
43144317
<application>libpq</> to byte-swap the value if necessary, so that it
4315-
is delivered as a proper <type>int</type> value for the client machine.
4318+
is delivered as a proper <type>int</type> value for the client machine;
4319+
note that a 4-byte integer is delivered into <parameter>*result_buf</>
4320+
for either allowed result size.
43164321
When <parameter>result_is_int</> is 0, the binary-format byte string
4317-
sent by the server is returned unmodified.
4322+
sent by the server is returned unmodified. (In this case it's better
4323+
to consider <parameter>result_buf</parameter> as being of
4324+
type <type>void *</>.)
43184325
</para>
43194326

43204327
<para>

src/interfaces/libpq/fe-exec.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,20 +2338,18 @@ PQendcopy(PGconn *conn)
23382338
* PQfn - Send a function call to the POSTGRES backend.
23392339
*
23402340
* conn : backend connection
2341-
* fnid : function id
2342-
* result_buf : pointer to result buffer (&int if integer)
2343-
* result_len : length of return value.
2344-
* actual_result_len: actual length returned. (differs from result_len
2345-
* for varlena structures.)
2346-
* result_type : If the result is an integer, this must be 1,
2341+
* fnid : OID of function to be called
2342+
* result_buf : pointer to result buffer
2343+
* result_len : actual length of result is returned here
2344+
* result_is_int : If the result is an integer, this must be 1,
23472345
* otherwise this should be 0
2348-
* args : pointer to an array of function arguments.
2346+
* args : pointer to an array of function arguments
23492347
* (each has length, if integer, and value/pointer)
23502348
* nargs : # of arguments in args array.
23512349
*
23522350
* RETURNS
23532351
* PGresult with status = PGRES_COMMAND_OK if successful.
2354-
* *actual_result_len is > 0 if there is a return value, 0 if not.
2352+
* *result_len is > 0 if there is a return value, 0 if not.
23552353
* PGresult with status = PGRES_FATAL_ERROR if backend returns an error.
23562354
* NULL on communications failure. conn->errorMessage will be set.
23572355
* ----------------
@@ -2361,12 +2359,12 @@ PGresult *
23612359
PQfn(PGconn *conn,
23622360
int fnid,
23632361
int *result_buf,
2364-
int *actual_result_len,
2362+
int *result_len,
23652363
int result_is_int,
23662364
const PQArgBlock *args,
23672365
int nargs)
23682366
{
2369-
*actual_result_len = 0;
2367+
*result_len = 0;
23702368

23712369
if (!conn)
23722370
return NULL;
@@ -2384,12 +2382,12 @@ PQfn(PGconn *conn,
23842382

23852383
if (PG_PROTOCOL_MAJOR(conn->pversion) >= 3)
23862384
return pqFunctionCall3(conn, fnid,
2387-
result_buf, actual_result_len,
2385+
result_buf, result_len,
23882386
result_is_int,
23892387
args, nargs);
23902388
else
23912389
return pqFunctionCall2(conn, fnid,
2392-
result_buf, actual_result_len,
2390+
result_buf, result_len,
23932391
result_is_int,
23942392
args, nargs);
23952393
}

0 commit comments

Comments
 (0)