|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * 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 $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -1083,13 +1083,48 @@ PQexecStart(PGconn *conn)
|
1083 | 1083 | */
|
1084 | 1084 | while ((result = PQgetResult(conn)) != NULL)
|
1085 | 1085 | {
|
1086 |
| - if (result->resultStatus == PGRES_COPY_IN || |
1087 |
| - result->resultStatus == PGRES_COPY_OUT) |
| 1086 | + if (result->resultStatus == PGRES_COPY_IN) |
1088 | 1087 | {
|
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 | + } |
1093 | 1128 | }
|
1094 | 1129 | PQclear(result);
|
1095 | 1130 | }
|
|
0 commit comments