Commit d4dbfdb4 authored by Bruce Momjian's avatar Bruce Momjian

Patch for copy from stdin.

parent 15526ff0
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.24 1996/12/26 22:08:21 momjian Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.25 1996/12/28 01:57:13 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -370,7 +370,8 @@ PQexec(PGconn* conn, const char* query) ...@@ -370,7 +370,8 @@ PQexec(PGconn* conn, const char* query)
char pname[MAX_MESSAGE_LEN]; /* portal name */ char pname[MAX_MESSAGE_LEN]; /* portal name */
PGnotify *newNotify; PGnotify *newNotify;
FILE *pfin, *pfout, *pfdebug; FILE *pfin, *pfout, *pfdebug;
int emptiesSent = 0; static int emptiesPending = 0;
bool emptySent = false;
pname[0]='\0'; pname[0]='\0';
...@@ -457,12 +458,13 @@ PQexec(PGconn* conn, const char* query) ...@@ -457,12 +458,13 @@ PQexec(PGconn* conn, const char* query)
// send an empty query down, and keep reading out of the pipe // send an empty query down, and keep reading out of the pipe
// until an 'I' is received. // until an 'I' is received.
*/ */
pqPuts("Q ",pfout,pfdebug); /* send an empty query */ pqPuts("Q",pfout,pfdebug); /* send an empty query */
/* /*
* Increment a flag and process messages in the usual way because * Increment a flag and process messages in the usual way because
* there may be async notifications pending. DZ - 31-8-1996 * there may be async notifications pending. DZ - 31-8-1996
*/ */
emptiesSent++; emptiesPending++;
emptySent = true;
} }
break; break;
case 'E': /* error return */ case 'E': /* error return */
...@@ -480,8 +482,8 @@ PQexec(PGconn* conn, const char* query) ...@@ -480,8 +482,8 @@ PQexec(PGconn* conn, const char* query)
if ((c = pqGetc(pfin,pfdebug)) != '\0') { if ((c = pqGetc(pfin,pfdebug)) != '\0') {
fprintf(stderr,"error!, unexpected character %c following 'I'\n", c); fprintf(stderr,"error!, unexpected character %c following 'I'\n", c);
} }
if (emptiesSent) { if (emptiesPending) {
if (--emptiesSent == 0) { /* is this the last one? */ if (--emptiesPending == 0 && emptySent) { /* is this the last one? */
/* /*
* If this is the result of a portal query command set the * If this is the result of a portal query command set the
* command status and message accordingly. DZ - 31-8-1996 * command status and message accordingly. DZ - 31-8-1996
...@@ -621,42 +623,36 @@ PQputline(PGconn *conn, const char *s) ...@@ -621,42 +623,36 @@ PQputline(PGconn *conn, const char *s)
* to a "copy". * to a "copy".
* *
* RETURNS: * RETURNS:
* 0 on failure * 0 on success
* 1 on success * 1 on failure
*/ */
int int
PQendcopy(PGconn *conn) PQendcopy(PGconn *conn)
{ {
char id;
FILE *pfin, *pfdebug; FILE *pfin, *pfdebug;
bool valid = true;
if (!conn) return (int)NULL; if (!conn) return (int)NULL;
pfin = conn->Pfin; pfin = conn->Pfin;
pfdebug = conn->Pfdebug; pfdebug = conn->Pfdebug;
if ( (id = pqGetc(pfin,pfdebug)) > 0) if ( pqGetc(pfin,pfdebug) == 'C')
return(0); {
switch (id) { char command[MAX_MESSAGE_LEN];
case 'Z': /* backend finished the copy */ pqGets(command,MAX_MESSAGE_LEN, pfin, pfdebug); /* read command tag */
return(1); }
case 'E': else valid = false;
case 'N':
if (pqGets(conn->errorMessage, ERROR_MSG_LENGTH, pfin, pfdebug) == 1) { if ( valid )
return (0);
else {
sprintf(conn->errorMessage, sprintf(conn->errorMessage,
"Error return detected from backend, " "Error return detected from backend, "
"but attempt to read the message failed."); "but attempt to read the message failed.");
}
return(0);
break;
default:
(void) sprintf(conn->errorMessage,
"FATAL: PQendcopy: protocol error: id=%x\n",
id);
fputs(conn->errorMessage, stderr);
fprintf(stderr,"resetting connection\n"); fprintf(stderr,"resetting connection\n");
PQreset(conn); PQreset(conn);
return(0); return(1);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment