77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.74 1999/02/13 23:22:41 momjian Exp $
10+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.75 1999/03/14 16:42:15 momjian Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -467,6 +467,7 @@ static void
467467parseInput (PGconn * conn )
468468{
469469char id ;
470+ static int pendingT = 0 ;
470471
471472/*
472473 * Loop to parse successive complete messages available in the buffer.
@@ -535,7 +536,15 @@ parseInput(PGconn *conn)
535536PGRES_COMMAND_OK );
536537if (pqGets (conn -> result -> cmdStatus ,CMDSTATUS_LEN ,conn ))
537538return ;
538- conn -> asyncStatus = PGASYNC_READY ;
539+ if (pendingT ) {
540+ /* Check the returned message */
541+ /* if it's a SELECT in a pendingT case, */
542+ /* then it probably means no rows returned. */
543+ /* We clear pendingT in that case. */
544+ if (strncmp (conn -> result -> cmdStatus ,"SELECT" ,6 )== 0 )
545+ pendingT = 0 ;
546+ }
547+ if (!pendingT )conn -> asyncStatus = PGASYNC_READY ;
539548break ;
540549case 'E' :/* error return */
541550if (pqGets (conn -> errorMessage ,ERROR_MSG_LENGTH ,conn ))
@@ -545,10 +554,11 @@ parseInput(PGconn *conn)
545554/* and build an error result holding the error message */
546555conn -> result = PQmakeEmptyPGresult (conn ,
547556PGRES_FATAL_ERROR );
548- conn -> asyncStatus = PGASYNC_READY ;
557+ if (! pendingT ) conn -> asyncStatus = PGASYNC_READY ;
549558break ;
550559case 'Z' :/* backend is ready for new query */
551560conn -> asyncStatus = PGASYNC_IDLE ;
561+ pendingT = 0 ;
552562break ;
553563case 'I' :/* empty query */
554564/* read and throw away the closing '\0' */
@@ -563,7 +573,7 @@ parseInput(PGconn *conn)
563573if (conn -> result == NULL )
564574conn -> result = PQmakeEmptyPGresult (conn ,
565575PGRES_EMPTY_QUERY );
566- conn -> asyncStatus = PGASYNC_READY ;
576+ if (! pendingT ) conn -> asyncStatus = PGASYNC_READY ;
567577break ;
568578case 'K' :/* secret key data from the backend */
569579
@@ -584,11 +594,15 @@ parseInput(PGconn *conn)
584594break ;
585595case 'T' :/* row descriptions (start of query
586596 * results) */
597+ if (pendingT ) {
598+ DONOTICE (conn ,"Got second 'T' message!\n" );
599+ }
587600if (conn -> result == NULL )
588601{
589602/* First 'T' in a query sequence */
590603if (getRowDescriptions (conn ))
591604return ;
605+ pendingT = 1 ;
592606}
593607else
594608{
@@ -600,11 +614,13 @@ parseInput(PGconn *conn)
600614 * We stop parsing until the application accepts
601615 * the current result.
602616 */
617+ pendingT = 0 ;
603618conn -> asyncStatus = PGASYNC_READY ;
604619return ;
605620}
606621break ;
607622case 'D' :/* ASCII data tuple */
623+ pendingT = 0 ;
608624if (conn -> result != NULL )
609625{
610626/* Read another tuple of a normal query response */
@@ -622,6 +638,7 @@ parseInput(PGconn *conn)
622638}
623639break ;
624640case 'B' :/* Binary data tuple */
641+ pendingT = 0 ;
625642if (conn -> result != NULL )
626643{
627644/* Read another tuple of a normal query response */
@@ -639,12 +656,15 @@ parseInput(PGconn *conn)
639656}
640657break ;
641658case 'G' :/* Start Copy In */
659+ pendingT = 0 ;
642660conn -> asyncStatus = PGASYNC_COPY_IN ;
643661break ;
644662case 'H' :/* Start Copy Out */
663+ pendingT = 0 ;
645664conn -> asyncStatus = PGASYNC_COPY_OUT ;
646665break ;
647666default :
667+ pendingT = 0 ;
648668sprintf (conn -> errorMessage ,
649669"unknown protocol character '%c' read from backend. "
650670"(The protocol character is the first character the "