7
7
*
8
8
*
9
9
* 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 $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -370,8 +370,9 @@ PQexec(PGconn* conn, const char* query)
370
370
char pname [MAX_MESSAGE_LEN ]; /* portal name */
371
371
PGnotify * newNotify ;
372
372
FILE * pfin , * pfout , * pfdebug ;
373
- int emptiesSent = 0 ;
374
-
373
+ static int emptiesPending = 0 ;
374
+ bool emptySent = false;
375
+
375
376
pname [0 ]= '\0' ;
376
377
377
378
if (!conn ) return NULL ;
@@ -457,12 +458,13 @@ PQexec(PGconn* conn, const char* query)
457
458
// send an empty query down, and keep reading out of the pipe
458
459
// until an 'I' is received.
459
460
*/
460
- pqPuts ("Q " ,pfout ,pfdebug ); /* send an empty query */
461
+ pqPuts ("Q" ,pfout ,pfdebug ); /* send an empty query */
461
462
/*
462
463
* Increment a flag and process messages in the usual way because
463
464
* there may be async notifications pending. DZ - 31-8-1996
464
465
*/
465
- emptiesSent ++ ;
466
+ emptiesPending ++ ;
467
+ emptySent = true;
466
468
}
467
469
break ;
468
470
case 'E' : /* error return */
@@ -480,8 +482,8 @@ PQexec(PGconn* conn, const char* query)
480
482
if ((c = pqGetc (pfin ,pfdebug )) != '\0' ) {
481
483
fprintf (stderr ,"error!, unexpected character %c following 'I'\n" , c );
482
484
}
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? */
485
487
/*
486
488
* If this is the result of a portal query command set the
487
489
* command status and message accordingly. DZ - 31-8-1996
@@ -621,42 +623,36 @@ PQputline(PGconn *conn, const char *s)
621
623
* to a "copy".
622
624
*
623
625
* RETURNS:
624
- * 0 on failure
625
- * 1 on success
626
+ * 0 on success
627
+ * 1 on failure
626
628
*/
627
629
int
628
630
PQendcopy (PGconn * conn )
629
631
{
630
- char id ;
631
632
FILE * pfin , * pfdebug ;
633
+ bool valid = true;
632
634
633
635
if (!conn ) return (int )NULL ;
634
636
635
637
pfin = conn -> Pfin ;
636
638
pfdebug = conn -> Pfdebug ;
637
639
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 ,
647
651
"Error return detected from backend, "
648
652
"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 );
657
653
fprintf (stderr ,"resetting connection\n" );
658
654
PQreset (conn );
659
- return (0 );
655
+ return (1 );
660
656
}
661
657
}
662
658
0 commit comments