diff options
author | Marc G. Fournier <scrappy@hub.org> | 1998-08-17 03:50:43 +0000 |
---|---|---|
committer | Marc G. Fournier <scrappy@hub.org> | 1998-08-17 03:50:43 +0000 |
commit | 93120330713916c28f87deb3466010b1f23a213e (patch) | |
tree | fc56a3e099f78a8f4d3b10a1c4fbfc1aba594099 /src/interfaces/libpgtcl/pgtclId.c | |
parent | 3fa676a74cd7f4e010610e1da1bf17395b1d05c7 (diff) |
Date: Sun, 16 Aug 1998 14:56:48 -0400
From: Tom Lane <tgl@sss.pgh.pa.us>
Attached is a patch for this weekend's work on libpq. I've dealt
with several issues:
<for details: see message, in pgsql-patches archive for above data>
Diffstat (limited to 'src/interfaces/libpgtcl/pgtclId.c')
-rw-r--r-- | src/interfaces/libpgtcl/pgtclId.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/interfaces/libpgtcl/pgtclId.c b/src/interfaces/libpgtcl/pgtclId.c index 4ed8f58d57f..05dfb19b6de 100644 --- a/src/interfaces/libpgtcl/pgtclId.c +++ b/src/interfaces/libpgtcl/pgtclId.c @@ -12,7 +12,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.11 1998/06/16 04:10:17 momjian Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.12 1998/08/17 03:50:26 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -43,7 +43,10 @@ static int PgEndCopy(Pg_ConnectionId *connid, int *errorCodePtr) } /* - * Called when reading data (via gets) for a copy <rel> to stdout + * Called when reading data (via gets) for a copy <rel> to stdout. + * + * NOTE: this routine knows way more than it ought to about libpq's + * internal buffering mechanisms. */ int PgInputProc(DRIVER_INPUT_PROTO) { @@ -62,10 +65,10 @@ int PgInputProc(DRIVER_INPUT_PROTO) } /* Try to load any newly arrived data */ - errno = 0; - - if (pqReadData(conn) < 0) { - *errorCodePtr = errno ? errno : EIO; + conn->errorMessage[0] = '\0'; + PQconsumeInput(conn); + if (conn->errorMessage[0]) { + *errorCodePtr = EIO; return -1; } @@ -80,8 +83,8 @@ int PgInputProc(DRIVER_INPUT_PROTO) conn->inCursor = conn->inStart; avail = bufSize; - while (avail > 0 && - pqGetc(&c, conn) == 0) { + while (avail > 0 && conn->inCursor < conn->inEnd) { + c = conn->inBuffer[conn->inCursor++]; *buf++ = c; --avail; if (c == '\n') { @@ -130,10 +133,12 @@ int PgOutputProc(DRIVER_OUTPUT_PROTO) return -1; } - errno = 0; + conn->errorMessage[0] = '\0'; - if (pqPutnchar(buf, bufSize, conn)) { - *errorCodePtr = errno ? errno : EIO; + PQputnbytes(conn, buf, bufSize); + + if (conn->errorMessage[0]) { + *errorCodePtr = EIO; return -1; } @@ -141,7 +146,6 @@ int PgOutputProc(DRIVER_OUTPUT_PROTO) * in a single operation; maybe not such a good assumption? */ if (bufSize >= 3 && strncmp(&buf[bufSize-3], "\\.\n", 3) == 0) { - (void) pqFlush(conn); if (PgEndCopy(connid, errorCodePtr) == -1) return -1; } @@ -423,7 +427,7 @@ PgGetConnByResultId(Tcl_Interp *interp, char *resid_c) *mark = '\0'; conn_chan = Tcl_GetChannel(interp, resid_c, 0); *mark = '.'; - if(conn_chan && Tcl_GetChannelType(conn_chan) != &Pg_ConnType) { + if(conn_chan && Tcl_GetChannelType(conn_chan) == &Pg_ConnType) { Tcl_SetResult(interp, Tcl_GetChannelName(conn_chan), TCL_VOLATILE); return TCL_OK; } |