This fixes a protocol violation and disconnect when 7.4.x libpq is talking
to a v2 protocol (<=7.3.x) server. The client does COPY FROM STDIN, uses
the new call PQputCopyData(), then ends the copy using PQputCopyEnd(),
and gets back the odd message:
                               FATAL:  Socket command type
followed by "server closed the connection unexpectedly..."

(This won't be seen with psql because it uses the older PQputline() and
PQendcopy() functions. But it breaks COPY into a 7.3 server with my new
Tcl interface pgtcl-ng.)

The problem is that PQputCopyEnd() in libpq sends the copy terminator "\\.\n"
with a trailing null byte. The 7.3.x server does not want the trailing
null there, so it takes it for a command byte. The actual error is
"Socket command type %c unknown" but the %c is '\0' so you lose the rest.

Here's a 1-line patch against 7.4.1 which has PQputCopyEnd() send the
terminator "\\.\n" without a trailing null. (Sorry I missed 7.4.2, but I
just found this.) It will also apply OK (with offset) to what I think will
be 7.4.2 (in CVS as fe-exec.c,v Note this only affects the
down-level "v2" protocol code in libpq.

*** src/interfaces/libpq/fe-exec.c~     Sun Nov 30 15:53:43 2003
--- src/interfaces/libpq/fe-exec.c      Mon Mar  8 19:16:37 2004
*** 1447,1453 ****
                        /* Send old-style end-of-data marker */
                        if (pqPutMsgStart(0, false, conn) < 0 ||
!                               pqPuts("\\.\n", conn) < 0 ||
                                pqPutMsgEnd(conn) < 0)
                                return -1;
--- 1447,1453 ----
                        /* Send old-style end-of-data marker */
                        if (pqPutMsgStart(0, false, conn) < 0 ||
!                               pqPutnchar("\\.\n", 3, conn) < 0 ||
                                pqPutMsgEnd(conn) < 0)
                                return -1;

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Reply via email to