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)
370370char pname [MAX_MESSAGE_LEN ];/* portal name */
371371PGnotify * newNotify ;
372372FILE * pfin ,* pfout ,* pfdebug ;
373- int emptiesSent = 0 ;
374-
373+ static int emptiesPending = 0 ;
374+ bool emptySent = false;
375+
375376pname [0 ]= '\0' ;
376377
377378if (!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 }
467469break ;
468470case 'E' :/* error return */
@@ -480,8 +482,8 @@ PQexec(PGconn* conn, const char* query)
480482if ((c = pqGetc (pfin ,pfdebug ))!= '\0' ) {
481483fprintf (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 onfailure
625- * 1 onsuccess
626+ * 0 onsuccess
627+ * 1 onfailure
626628 */
627629int
628630PQendcopy (PGconn * conn )
629631{
630- char id ;
631632FILE * pfin ,* pfdebug ;
633+ bool valid = true;
632634
633635if (!conn )return (int )NULL ;
634636
635637pfin = conn -> Pfin ;
636638pfdebug = 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 );
657653fprintf (stderr ,"resetting connection\n" );
658654PQreset (conn );
659- return (0 );
655+ return (1 );
660656 }
661657}
662658