Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf05cfd2

Browse files
committed
Fix failure to think clearly about encoding conversion errors in COPY.
We can't regurgitate the unconverted string as I first thought, becausethe elog.c mechanisms will assume the error message data is in the serverencoding and attempt a reverse conversion. Eventually it might be worthproviding a short-circuit path to support this, but for now the simplestsolution is to abandon trying to report back the line contents after aconversion failure. Per bug report from Sil Lee, 27-Oct-2004.
1 parent0851085 commitf05cfd2

File tree

1 file changed

+22
-31
lines changed

1 file changed

+22
-31
lines changed

‎src/backend/commands/copy.c

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.232 2004/09/13 20:06:27 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.233 2004/10/29 19:18:22 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1401,29 +1401,26 @@ copy_in_error_callback(void *arg)
14011401
else
14021402
{
14031403
/* error is relevant to a particular line */
1404-
if (!line_buf_converted)
1404+
if (line_buf_converted||
1405+
client_encoding==server_encoding)
14051406
{
1406-
/* didn't convert the encoding yet... */
1407-
line_buf_converted= true;
1408-
if (client_encoding!=server_encoding)
1409-
{
1410-
char*cvt;
1411-
1412-
cvt= (char*)pg_client_to_server((unsignedchar*)line_buf.data,
1413-
line_buf.len);
1414-
if (cvt!=line_buf.data)
1415-
{
1416-
/* transfer converted data back to line_buf */
1417-
line_buf.len=0;
1418-
line_buf.data[0]='\0';
1419-
appendBinaryStringInfo(&line_buf,cvt,strlen(cvt));
1420-
}
1421-
}
1407+
limit_printout_length(&line_buf);
1408+
errcontext("COPY %s, line %d: \"%s\"",
1409+
copy_relname,copy_lineno,
1410+
line_buf.data);
1411+
}
1412+
else
1413+
{
1414+
/*
1415+
* Here, the line buffer is still in a foreign encoding,
1416+
* and indeed it's quite likely that the error is precisely
1417+
* a failure to do encoding conversion (ie, bad data). We
1418+
* dare not try to convert it, and at present there's no way
1419+
* to regurgitate it without conversion. So we have to punt
1420+
* and just report the line number.
1421+
*/
1422+
errcontext("COPY %s, line %d",copy_relname,copy_lineno);
14221423
}
1423-
limit_printout_length(&line_buf);
1424-
errcontext("COPY %s, line %d: \"%s\"",
1425-
copy_relname,copy_lineno,
1426-
line_buf.data);
14271424
}
14281425
}
14291426
}
@@ -2175,16 +2172,7 @@ CopyReadLine(void)
21752172

21762173
/*
21772174
* Done reading the line. Convert it to server encoding.
2178-
*
2179-
* Note: set line_buf_converted to true *before* attempting conversion;
2180-
* this prevents infinite recursion during error reporting should
2181-
* pg_client_to_server() issue an error, due to copy_in_error_callback
2182-
* again attempting the same conversion. We'll end up issuing the
2183-
* message without conversion, which is bad but better than nothing
2184-
* ...
21852175
*/
2186-
line_buf_converted= true;
2187-
21882176
if (change_encoding)
21892177
{
21902178
cvt= (char*)pg_client_to_server((unsignedchar*)line_buf.data,
@@ -2198,6 +2186,9 @@ CopyReadLine(void)
21982186
}
21992187
}
22002188

2189+
/* Now it's safe to use the buffer in error messages */
2190+
line_buf_converted= true;
2191+
22012192
returnresult;
22022193
}
22032194

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp