diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2009-03-02 21:18:50 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2009-03-02 21:18:50 +0000 |
commit | eb828d9398b0cf383502cca2f1706496033b2ab6 (patch) | |
tree | dbb0d408e4af341b38a2582f0f3a5fd41a4d2123 /src/backend/libpq/pqformat.c | |
parent | 327c5e37d7c87aded85d348a3236d71a6e2d34e7 (diff) |
When we are in error recursion trouble, arrange to suppress translation and
encoding conversion of any elog/ereport message being sent to the frontend.
This generalizes a patch that I put in last October, which suppressed
translation of only specific messages known to be associated with recursive
can't-translate-the-message behavior. As shown in bug #4680, we need a more
general answer in order to have some hope of coping with broken encoding
conversion setups. This approach seems a good deal less klugy anyway.
Patch in all supported branches.
Diffstat (limited to 'src/backend/libpq/pqformat.c')
-rw-r--r-- | src/backend/libpq/pqformat.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/backend/libpq/pqformat.c b/src/backend/libpq/pqformat.c index 15cb4b4df2a..4d0ae27f389 100644 --- a/src/backend/libpq/pqformat.c +++ b/src/backend/libpq/pqformat.c @@ -24,7 +24,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/libpq/pqformat.c,v 1.47 2008/01/01 19:45:49 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/libpq/pqformat.c,v 1.47.2.1 2009/03/02 21:18:50 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -41,6 +41,7 @@ * pq_sendcountedtext - append a counted text string (with character set conversion) * pq_sendtext - append a text string (with conversion) * pq_sendstring - append a null-terminated text string (with conversion) + * pq_send_ascii_string - append a null-terminated text string (without conversion) * pq_endmessage - send the completed message to the frontend * Note: it is also possible to append data to the StringInfo buffer using * the regular StringInfo routines, but this is discouraged since required @@ -184,7 +185,6 @@ void pq_sendstring(StringInfo buf, const char *str) { int slen = strlen(str); - char *p; p = pg_server_to_client(str, slen); @@ -199,6 +199,35 @@ pq_sendstring(StringInfo buf, const char *str) } /* -------------------------------- + * pq_send_ascii_string - append a null-terminated text string (without conversion) + * + * This function intentionally bypasses encoding conversion, instead just + * silently replacing any non-7-bit-ASCII characters with question marks. + * It is used only when we are having trouble sending an error message to + * the client with normal localization and encoding conversion. The caller + * should already have taken measures to ensure the string is just ASCII; + * the extra work here is just to make certain we don't send a badly encoded + * string to the client (which might or might not be robust about that). + * + * NB: passed text string must be null-terminated, and so is the data + * sent to the frontend. + * -------------------------------- + */ +void +pq_send_ascii_string(StringInfo buf, const char *str) +{ + while (*str) + { + char ch = *str++; + + if (IS_HIGHBIT_SET(ch)) + ch = '?'; + appendStringInfoCharMacro(buf, ch); + } + appendStringInfoChar(buf, '\0'); +} + +/* -------------------------------- * pq_sendint - append a binary integer to a StringInfo buffer * -------------------------------- */ |