Skip to content

Commit d4dbfdb

Browse files
committed
Patch for copy from stdin.
1 parent 15526ff commit d4dbfdb

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

src/interfaces/libpq/fe-exec.c

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.24 1996/12/26 22:08:21 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.25 1996/12/28 01:57:13 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -370,8 +370,9 @@ PQexec(PGconn* conn, const char* query)
370370
char pname[MAX_MESSAGE_LEN]; /* portal name */
371371
PGnotify *newNotify;
372372
FILE *pfin, *pfout, *pfdebug;
373-
int emptiesSent = 0;
374-
373+
static int emptiesPending = 0;
374+
bool emptySent = false;
375+
375376
pname[0]='\0';
376377

377378
if (!conn) return NULL;
@@ -457,12 +458,13 @@ PQexec(PGconn* conn, const char* query)
457458
// send an empty query down, and keep reading out of the pipe
458459
// until an 'I' is received.
459460
*/
460-
pqPuts("Q ",pfout,pfdebug); /* send an empty query */
461+
pqPuts("Q",pfout,pfdebug); /* send an empty query */
461462
/*
462463
* Increment a flag and process messages in the usual way because
463464
* there may be async notifications pending. DZ - 31-8-1996
464465
*/
465-
emptiesSent++;
466+
emptiesPending++;
467+
emptySent = true;
466468
}
467469
break;
468470
case 'E': /* error return */
@@ -480,8 +482,8 @@ PQexec(PGconn* conn, const char* query)
480482
if ((c = pqGetc(pfin,pfdebug)) != '\0') {
481483
fprintf(stderr,"error!, unexpected character %c following 'I'\n", c);
482484
}
483-
if (emptiesSent) {
484-
if (--emptiesSent == 0) { /* is this the last one? */
485+
if (emptiesPending) {
486+
if (--emptiesPending == 0 && emptySent) { /* is this the last one? */
485487
/*
486488
* If this is the result of a portal query command set the
487489
* command status and message accordingly. DZ - 31-8-1996
@@ -621,42 +623,36 @@ PQputline(PGconn *conn, const char *s)
621623
* to a "copy".
622624
*
623625
* RETURNS:
624-
* 0 on failure
625-
* 1 on success
626+
* 0 on success
627+
* 1 on failure
626628
*/
627629
int
628630
PQendcopy(PGconn *conn)
629631
{
630-
char id;
631632
FILE *pfin, *pfdebug;
633+
bool valid = true;
632634

633635
if (!conn) return (int)NULL;
634636

635637
pfin = conn->Pfin;
636638
pfdebug = conn->Pfdebug;
637639

638-
if ( (id = pqGetc(pfin,pfdebug)) > 0)
639-
return(0);
640-
switch (id) {
641-
case 'Z': /* backend finished the copy */
642-
return(1);
643-
case 'E':
644-
case 'N':
645-
if (pqGets(conn->errorMessage, ERROR_MSG_LENGTH, pfin, pfdebug) == 1) {
646-
sprintf(conn->errorMessage,
640+
if ( pqGetc(pfin,pfdebug) == 'C')
641+
{
642+
char command[MAX_MESSAGE_LEN];
643+
pqGets(command,MAX_MESSAGE_LEN, pfin, pfdebug); /* read command tag */
644+
}
645+
else valid = false;
646+
647+
if ( valid )
648+
return (0);
649+
else {
650+
sprintf(conn->errorMessage,
647651
"Error return detected from backend, "
648652
"but attempt to read the message failed.");
649-
}
650-
return(0);
651-
break;
652-
default:
653-
(void) sprintf(conn->errorMessage,
654-
"FATAL: PQendcopy: protocol error: id=%x\n",
655-
id);
656-
fputs(conn->errorMessage, stderr);
657653
fprintf(stderr,"resetting connection\n");
658654
PQreset(conn);
659-
return(0);
655+
return(1);
660656
}
661657
}
662658

0 commit comments

Comments
 (0)