diff options
| author | Bruce Momjian | 1998-05-06 23:53:48 +0000 |
|---|---|---|
| committer | Bruce Momjian | 1998-05-06 23:53:48 +0000 |
| commit | 1c2d9cb63774f46f70f20ca8daa70f451886da1f (patch) | |
| tree | cd2d311458fb6399644a1b1aa64b09cd3c908549 /src/interfaces/libpq | |
| parent | edbd51395c425795b3ccacbc9d26044beb1a1277 (diff) | |
It seems the regression tests don't cover copy in/out at all, so
code that I had assumed was working had not been tested. Naturally,
it was broken ...
Tom Lane
Diffstat (limited to 'src/interfaces/libpq')
| -rw-r--r-- | src/interfaces/libpq/fe-exec.c | 12 | ||||
| -rw-r--r-- | src/interfaces/libpq/fe-misc.c | 20 |
2 files changed, 27 insertions, 5 deletions
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index aac0ea0e97b..ae770e197aa 100644 --- a/src/interfaces/libpq/fe-exec.c +++ b/src/interfaces/libpq/fe-exec.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.50 1998/05/06 23:51:13 momjian Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.51 1998/05/06 23:53:38 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -748,7 +748,8 @@ PQexec(PGconn *conn, const char *query) return NULL; /* For backwards compatibility, return the last result if there are - * more than one. + * more than one. We have to stop if we see copy in/out, however. + * We will resume parsing when application calls PQendcopy. */ lastResult = NULL; while ((result = PQgetResult(conn)) != NULL) @@ -756,6 +757,9 @@ PQexec(PGconn *conn, const char *query) if (lastResult) PQclear(lastResult); lastResult = result; + if (result->resultStatus == PGRES_COPY_IN || + result->resultStatus == PGRES_COPY_OUT) + break; } return lastResult; } @@ -950,7 +954,7 @@ PQputline(PGconn *conn, const char *s) { if (conn && conn->sock >= 0) { - (void) pqPuts(s, conn); + (void) pqPutnchar(s, strlen(s), conn); } } @@ -988,7 +992,7 @@ PQendcopy(PGconn *conn) result = PQgetResult(conn); /* Expecting a successful result */ - if (result->resultStatus == PGRES_COMMAND_OK) + if (result && result->resultStatus == PGRES_COMMAND_OK) { PQclear(result); return 0; diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c index d7fc71dd134..3d3cf2a7197 100644 --- a/src/interfaces/libpq/fe-misc.c +++ b/src/interfaces/libpq/fe-misc.c @@ -24,7 +24,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.11 1998/05/06 23:51:14 momjian Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.12 1998/05/06 23:53:48 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -342,6 +342,15 @@ tryAgain: { if (errno == EINTR) goto tryAgain; + /* Some systems return EAGAIN/EWOULDBLOCK for no data */ +#ifdef EAGAIN + if (errno == EAGAIN) + return 0; +#endif +#if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN)) + if (errno == EWOULDBLOCK) + return 0; +#endif sprintf(conn->errorMessage, "pqReadData() -- read() failed: errno=%d\n%s\n", errno, strerror(errno)); @@ -374,6 +383,15 @@ tryAgain2: { if (errno == EINTR) goto tryAgain2; + /* Some systems return EAGAIN/EWOULDBLOCK for no data */ +#ifdef EAGAIN + if (errno == EAGAIN) + return 0; +#endif +#if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN)) + if (errno == EWOULDBLOCK) + return 0; +#endif sprintf(conn->errorMessage, "pqReadData() -- read() failed: errno=%d\n%s\n", errno, strerror(errno)); |
