Thread: There doesn't seem to be any case where PQputCopyEnd() returns 0

There doesn't seem to be any case where PQputCopyEnd() returns 0

From
Kasahara Tatsuhito
Date:
Hi,

The following is written in the comments of PQputCopyEnd().

 (snip)
 * Returns 1 if successful, 0 if data could not be sent (only possible
 * in nonblock mode), or -1 if an error occurs.
 (snip)

The PQputCopyEnd() section of the manual (libpq.sgml) describes the following.

       The result is 1 if the termination message was sent; or in
       nonblocking mode, this may only indicate that the termination
       message was successfully queued.  (In nonblocking mode, to be
       certain that the data has been sent, you should next wait for
       write-ready and call <xref linkend="libpq-PQflush"/>, repeating until it
       returns zero.)  Zero indicates that the function could not queue
       the termination message because of full buffers; this will only
       happen in nonblocking mode.  (In this case, wait for
       write-ready and try the <xref linkend="libpq-PQputCopyEnd"/> call
       again.)  If a hard error occurs, -1 is returned; you can use
       <xref linkend="libpq-PQerrorMessage"/> to retrieve details.


These says that 0 may be returned if a non-blocking mode is used, but
there doesn't seem to be any case where 0 is returned in the code of
PQputCopyEnd().

I may have missed something, but is it a mistake in the comments or
documentation?

Or should it return 0 when sending a COPY exit message fails
in non-blocking mode, like this?

@@ -2370,7 +2370,7 @@ PQputCopyEnd(PGconn *conn, const char *errormsg)
                        /* Send COPY DONE */
                        if (pqPutMsgStart('c', false, conn) < 0 ||
                                pqPutMsgEnd(conn) < 0)
-                               return -1;
+                               return pqIsnonblocking(conn) ? 0 : -1;
                }

                /*
@@ -2399,7 +2399,7 @@ PQputCopyEnd(PGconn *conn, const char *errormsg)
                        if (pqPutMsgStart(0, false, conn) < 0 ||
                                pqPutnchar("\\.\n", 3, conn) < 0 ||
                                pqPutMsgEnd(conn) < 0)
-                               return -1;
+                               return pqIsnonblocking(conn) ? 0 : -1;
                }
        }


Best regards,

-- 
Tatsuhito Kasahara
kasahara.tatsuhito _at_ gmail.com



Re: There doesn't seem to be any case where PQputCopyEnd() returns 0

From
Fujii Masao
Date:

On 2021/02/05 16:52, Kasahara Tatsuhito wrote:
> Hi,
> 
> The following is written in the comments of PQputCopyEnd().
> 
>   (snip)
>   * Returns 1 if successful, 0 if data could not be sent (only possible
>   * in nonblock mode), or -1 if an error occurs.
>   (snip)
> 
> The PQputCopyEnd() section of the manual (libpq.sgml) describes the following.
> 
>         The result is 1 if the termination message was sent; or in
>         nonblocking mode, this may only indicate that the termination
>         message was successfully queued.  (In nonblocking mode, to be
>         certain that the data has been sent, you should next wait for
>         write-ready and call <xref linkend="libpq-PQflush"/>, repeating until it
>         returns zero.)  Zero indicates that the function could not queue
>         the termination message because of full buffers; this will only
>         happen in nonblocking mode.  (In this case, wait for
>         write-ready and try the <xref linkend="libpq-PQputCopyEnd"/> call
>         again.)  If a hard error occurs, -1 is returned; you can use
>         <xref linkend="libpq-PQerrorMessage"/> to retrieve details.
> 
> 
> These says that 0 may be returned if a non-blocking mode is used, but
> there doesn't seem to be any case where 0 is returned in the code of
> PQputCopyEnd().

I found the past discussion [1] about this issue.

[1]
https://www.postgresql.org/message-id/CA+Tgmobjj+0modbnmjy7ezeBFOBo9d2mAVcSPkzLx4LtZmc==g@mail.gmail.com

Regards,

-- 
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION



Re: There doesn't seem to be any case where PQputCopyEnd() returns 0

From
Kasahara Tatsuhito
Date:
On Fri, Feb 5, 2021 at 11:01 PM Fujii Masao <masao.fujii@oss.nttdata.com> wrote:
>
>
>
> On 2021/02/05 16:52, Kasahara Tatsuhito wrote:
> > Hi,
> >
> > The following is written in the comments of PQputCopyEnd().
> >
> >   (snip)
> >   * Returns 1 if successful, 0 if data could not be sent (only possible
> >   * in nonblock mode), or -1 if an error occurs.
> >   (snip)
> >
> > The PQputCopyEnd() section of the manual (libpq.sgml) describes the following.
> >
> >         The result is 1 if the termination message was sent; or in
> >         nonblocking mode, this may only indicate that the termination
> >         message was successfully queued.  (In nonblocking mode, to be
> >         certain that the data has been sent, you should next wait for
> >         write-ready and call <xref linkend="libpq-PQflush"/>, repeating until it
> >         returns zero.)  Zero indicates that the function could not queue
> >         the termination message because of full buffers; this will only
> >         happen in nonblocking mode.  (In this case, wait for
> >         write-ready and try the <xref linkend="libpq-PQputCopyEnd"/> call
> >         again.)  If a hard error occurs, -1 is returned; you can use
> >         <xref linkend="libpq-PQerrorMessage"/> to retrieve details.
> >
> >
> > These says that 0 may be returned if a non-blocking mode is used, but
> > there doesn't seem to be any case where 0 is returned in the code of
> > PQputCopyEnd().
>
> I found the past discussion [1] about this issue.
>
> [1]
> https://www.postgresql.org/message-id/CA+Tgmobjj+0modbnmjy7ezeBFOBo9d2mAVcSPkzLx4LtZmc==g@mail.gmail.com
Oh, thank you.
I understood what was unclear.

Best regards,

>
> Regards,
>
> --
> Fujii Masao
> Advanced Computing Technology Center
> Research and Development Headquarters
> NTT DATA CORPORATION



-- 
Tatsuhito Kasahara
kasahara.tatsuhito _at_ gmail.com