Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9937f6e

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 d645273 commit 9937f6e

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
@@ -4694,22 +4694,29 @@ typedef struct
46944694
parameters to be passed to the function; they must match the declared
46954695
function argument list. When the <parameter>isint</> field of a
46964696
parameter structure is true, the <parameter>u.integer</> value is sent
4697-
to the server as an integer of the indicated length (this must be 1,
4698-
2, or 4 bytes); proper byte-swapping occurs. When <parameter>isint</>
4697+
to the server as an integer of the indicated length (this must be
4698+
2 or 4 bytes); proper byte-swapping occurs. When <parameter>isint</>
46994699
is false, the indicated number of bytes at <parameter>*u.ptr</> are
47004700
sent with no processing; the data must be in the format expected by
47014701
the server for binary transmission of the function's argument data
4702-
type. <parameter>result_buf</parameter> is the buffer in which to
4703-
place the return value. The caller must have allocated sufficient
4702+
type. (The declaration of <parameter>u.ptr</> as being of
4703+
type <type>int *</> is historical; it would be better to consider
4704+
it <type>void *</>.)
4705+
<parameter>result_buf</parameter> points to the buffer in which to place
4706+
the function's return value. The caller must have allocated sufficient
47044707
space to store the return value. (There is no check!) The actual result
4705-
length will be returned in the integer pointed to by
4706-
<parameter>result_len</parameter>. If a 1, 2, or 4-byte integer result
4708+
length in bytes will be returned in the integer pointed to by
4709+
<parameter>result_len</parameter>. If a 2- or 4-byte integer result
47074710
is expected, set <parameter>result_is_int</parameter> to 1, otherwise
47084711
set it to 0. Setting <parameter>result_is_int</parameter> to 1 causes
47094712
<application>libpq</> to byte-swap the value if necessary, so that it
4710-
is delivered as a proper <type>int</type> value for the client machine.
4713+
is delivered as a proper <type>int</type> value for the client machine;
4714+
note that a 4-byte integer is delivered into <parameter>*result_buf</>
4715+
for either allowed result size.
47114716
When <parameter>result_is_int</> is 0, the binary-format byte string
4712-
sent by the server is returned unmodified.
4717+
sent by the server is returned unmodified. (In this case it's better
4718+
to consider <parameter>result_buf</parameter> as being of
4719+
type <type>void *</>.)
47134720
</para>
47144721

47154722
<para>

src/interfaces/libpq/fe-exec.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,20 +2513,18 @@ PQendcopy(PGconn *conn)
25132513
* PQfn - Send a function call to the POSTGRES backend.
25142514
*
25152515
* conn : backend connection
2516-
* fnid : function id
2517-
* result_buf : pointer to result buffer (&int if integer)
2518-
* result_len : length of return value.
2519-
* actual_result_len: actual length returned. (differs from result_len
2520-
* for varlena structures.)
2521-
* result_type : If the result is an integer, this must be 1,
2516+
* fnid : OID of function to be called
2517+
* result_buf : pointer to result buffer
2518+
* result_len : actual length of result is returned here
2519+
* result_is_int : If the result is an integer, this must be 1,
25222520
* otherwise this should be 0
2523-
* args : pointer to an array of function arguments.
2521+
* args : pointer to an array of function arguments
25242522
* (each has length, if integer, and value/pointer)
25252523
* nargs : # of arguments in args array.
25262524
*
25272525
* RETURNS
25282526
* PGresult with status = PGRES_COMMAND_OK if successful.
2529-
* *actual_result_len is > 0 if there is a return value, 0 if not.
2527+
* *result_len is > 0 if there is a return value, 0 if not.
25302528
* PGresult with status = PGRES_FATAL_ERROR if backend returns an error.
25312529
* NULL on communications failure. conn->errorMessage will be set.
25322530
* ----------------
@@ -2536,12 +2534,12 @@ PGresult *
25362534
PQfn(PGconn *conn,
25372535
int fnid,
25382536
int *result_buf,
2539-
int *actual_result_len,
2537+
int *result_len,
25402538
int result_is_int,
25412539
const PQArgBlock *args,
25422540
int nargs)
25432541
{
2544-
*actual_result_len = 0;
2542+
*result_len = 0;
25452543

25462544
if (!conn)
25472545
return NULL;
@@ -2559,12 +2557,12 @@ PQfn(PGconn *conn,
25592557

25602558
if (PG_PROTOCOL_MAJOR(conn->pversion) >= 3)
25612559
return pqFunctionCall3(conn, fnid,
2562-
result_buf, actual_result_len,
2560+
result_buf, result_len,
25632561
result_is_int,
25642562
args, nargs);
25652563
else
25662564
return pqFunctionCall2(conn, fnid,
2567-
result_buf, actual_result_len,
2565+
result_buf, result_len,
25682566
result_is_int,
25692567
args, nargs);
25702568
}

0 commit comments

Comments
 (0)