Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ea20397

Browse files
committed
When using new protocol, PQexec can get out of a COPY IN or COPY OUT
state by itself, so do so.
1 parent bf75f1a commit ea20397

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

src/interfaces/libpq/fe-exec.c

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.140 2003/06/23 19:20:24 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.141 2003/06/28 00:06:01 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1083,13 +1083,48 @@ PQexecStart(PGconn *conn)
10831083
*/
10841084
while ((result = PQgetResult(conn)) != NULL)
10851085
{
1086-
if (result->resultStatus == PGRES_COPY_IN ||
1087-
result->resultStatus == PGRES_COPY_OUT)
1086+
if (result->resultStatus == PGRES_COPY_IN)
10881087
{
1089-
PQclear(result);
1090-
printfPQExpBuffer(&conn->errorMessage,
1091-
libpq_gettext("COPY state must be terminated first\n"));
1092-
return false;
1088+
if (PG_PROTOCOL_MAJOR(conn->pversion) >= 3)
1089+
{
1090+
/* In protocol 3, we can get out of a COPY IN state */
1091+
if (PQputCopyEnd(conn,
1092+
libpq_gettext("COPY terminated by new PQexec")) < 0)
1093+
{
1094+
PQclear(result);
1095+
return false;
1096+
}
1097+
/* keep waiting to swallow the copy's failure message */
1098+
}
1099+
else
1100+
{
1101+
/* In older protocols we have to punt */
1102+
PQclear(result);
1103+
printfPQExpBuffer(&conn->errorMessage,
1104+
libpq_gettext("COPY IN state must be terminated first\n"));
1105+
return false;
1106+
}
1107+
}
1108+
else if (result->resultStatus == PGRES_COPY_OUT)
1109+
{
1110+
if (PG_PROTOCOL_MAJOR(conn->pversion) >= 3)
1111+
{
1112+
/*
1113+
* In protocol 3, we can get out of a COPY OUT state: we
1114+
* just switch back to BUSY and allow the remaining COPY
1115+
* data to be dropped on the floor.
1116+
*/
1117+
conn->asyncStatus = PGASYNC_BUSY;
1118+
/* keep waiting to swallow the copy's completion message */
1119+
}
1120+
else
1121+
{
1122+
/* In older protocols we have to punt */
1123+
PQclear(result);
1124+
printfPQExpBuffer(&conn->errorMessage,
1125+
libpq_gettext("COPY OUT state must be terminated first\n"));
1126+
return false;
1127+
}
10931128
}
10941129
PQclear(result);
10951130
}

0 commit comments

Comments
 (0)