|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.329 2010/08/13 20:10:50 rhaas Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.330 2010/09/18 20:10:15 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -2058,9 +2058,34 @@ CopyFrom(CopyState cstate)
|
2058 | 2058 | int16 fld_count;
|
2059 | 2059 | ListCell *cur;
|
2060 | 2060 |
|
2061 |
| - if (!CopyGetInt16(cstate, &fld_count) || |
2062 |
| - fld_count == -1) |
| 2061 | + if (!CopyGetInt16(cstate, &fld_count)) |
2063 | 2062 | {
|
| 2063 | + /* EOF detected (end of file, or protocol-level EOF) */ |
| 2064 | + done = true; |
| 2065 | + break; |
| 2066 | + } |
| 2067 | + |
| 2068 | + if (fld_count == -1) |
| 2069 | + { |
| 2070 | + /* |
| 2071 | + * Received EOF marker. In a V3-protocol copy, wait for |
| 2072 | + * the protocol-level EOF, and complain if it doesn't come |
| 2073 | + * immediately. This ensures that we correctly handle |
| 2074 | + * CopyFail, if client chooses to send that now. |
| 2075 | + * |
| 2076 | + * Note that we MUST NOT try to read more data in an |
| 2077 | + * old-protocol copy, since there is no protocol-level EOF |
| 2078 | + * marker then. We could go either way for copy from file, |
| 2079 | + * but choose to throw error if there's data after the EOF |
| 2080 | + * marker, for consistency with the new-protocol case. |
| 2081 | + */ |
| 2082 | + char dummy; |
| 2083 | + |
| 2084 | + if (cstate->copy_dest != COPY_OLD_FE && |
| 2085 | + CopyGetData(cstate, &dummy, 1, 1) > 0) |
| 2086 | + ereport(ERROR, |
| 2087 | + (errcode(ERRCODE_BAD_COPY_FILE_FORMAT), |
| 2088 | + errmsg("received copy data after EOF marker"))); |
2064 | 2089 | done = true;
|
2065 | 2090 | break;
|
2066 | 2091 | }
|
|
0 commit comments