Fix COPY FROM when database encoding is SQL_ASCII.
In the codepath when no encoding conversion is required, the check for incomplete character at the end of input incorrectly used server encoding's max character length, instead of the client's. Usually the server and client encodings are the same when we're not performing encoding conversion, but SQL_ASCII is an exception. In the passing, also fix some outdated comments that still talked about the old COPY protocol. It was removed in v14. Per bug #17501 from Vitaly Voronov. Backpatch to v14 where this was introduced. Discussion: https://www.postgresql.org/message-id/17501-128b1dd039362ae6@postgresql.org
This commit is contained in:
parent
9f2d1946d4
commit
f82595ac90
@ -443,7 +443,7 @@ CopyConvertBuf(CopyFromState cstate)
|
|||||||
* least one character, and a failure to do so means that we've
|
* least one character, and a failure to do so means that we've
|
||||||
* hit an invalid byte sequence.
|
* hit an invalid byte sequence.
|
||||||
*/
|
*/
|
||||||
if (cstate->raw_reached_eof || unverifiedlen >= pg_database_encoding_max_length())
|
if (cstate->raw_reached_eof || unverifiedlen >= pg_encoding_max_length(cstate->file_encoding))
|
||||||
cstate->input_reached_error = true;
|
cstate->input_reached_error = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1124,14 +1124,12 @@ CopyReadLineText(CopyFromState cstate)
|
|||||||
char c;
|
char c;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Load more data if needed. Ideally we would just force four bytes
|
* Load more data if needed.
|
||||||
* of read-ahead and avoid the many calls to
|
*
|
||||||
* IF_NEED_REFILL_AND_NOT_EOF_CONTINUE(), but the COPY_OLD_FE protocol
|
* TODO: We could just force four bytes of read-ahead and avoid the
|
||||||
* does not allow us to read too far ahead or we might read into the
|
* many calls to IF_NEED_REFILL_AND_NOT_EOF_CONTINUE(). That was
|
||||||
* next data, so we read-ahead only as far we know we can. One
|
* unsafe with the old v2 COPY protocol, but we don't support that
|
||||||
* optimization would be to read-ahead four byte here if
|
* anymore.
|
||||||
* cstate->copy_src != COPY_OLD_FE, but it hardly seems worth it,
|
|
||||||
* considering the size of the buffer.
|
|
||||||
*/
|
*/
|
||||||
if (input_buf_ptr >= copy_buf_len || need_data)
|
if (input_buf_ptr >= copy_buf_len || need_data)
|
||||||
{
|
{
|
||||||
@ -1166,9 +1164,6 @@ CopyReadLineText(CopyFromState cstate)
|
|||||||
* Force fetch of the next character if we don't already have it.
|
* Force fetch of the next character if we don't already have it.
|
||||||
* We need to do this before changing CSV state, in case one of
|
* We need to do this before changing CSV state, in case one of
|
||||||
* these characters is also the quote or escape character.
|
* these characters is also the quote or escape character.
|
||||||
*
|
|
||||||
* Note: old-protocol does not like forced prefetch, but it's OK
|
|
||||||
* here since we cannot validly be at EOF.
|
|
||||||
*/
|
*/
|
||||||
if (c == '\\' || c == '\r')
|
if (c == '\\' || c == '\r')
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user