Skip to content

Commit a63b63f

Browse files
committed
Revert COPY OUT to follow the pre-8.3 handling of ASCII control characters,
namely that \r, \n, \t, \b, \f, \v are dumped as those two-character representations rather than a backslash and the literal control character. I had made it do the other to save some code, but this was ill-advised, because dump files in which these characters appear literally are prone to newline mangling. Fortunately, doing it the old way should only cost a few more lines of code, and not slow down the copy loop materially. Per bug #3795 from Lou Duchez.
1 parent 3b3251c commit a63b63f

File tree

1 file changed

+49
-17
lines changed

1 file changed

+49
-17
lines changed

src/backend/commands/copy.c

Lines changed: 49 additions & 17 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.289 2007/11/30 21:22:53 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.290 2007/12/03 00:03:05 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -3102,27 +3102,43 @@ CopyAttributeOutText(CopyState cstate, char *string)
31023102
}
31033103
else if ((unsigned char) c < (unsigned char) 0x20)
31043104
{
3105+
/*
3106+
* \r and \n must be escaped, the others are traditional.
3107+
* We prefer to dump these using the C-like notation, rather
3108+
* than a backslash and the literal character, because it
3109+
* makes the dump file a bit more proof against Microsoftish
3110+
* data mangling.
3111+
*/
31053112
switch (c)
31063113
{
3107-
/*
3108-
* \r and \n must be escaped, the others are
3109-
* traditional
3110-
*/
31113114
case '\b':
3115+
c = 'b';
3116+
break;
31123117
case '\f':
3118+
c = 'f';
3119+
break;
31133120
case '\n':
3121+
c = 'n';
3122+
break;
31143123
case '\r':
3124+
c = 'r';
3125+
break;
31153126
case '\t':
3127+
c = 't';
3128+
break;
31163129
case '\v':
3117-
DUMPSOFAR();
3118-
CopySendChar(cstate, '\\');
3119-
start = ptr++; /* we include char in next run */
3130+
c = 'v';
31203131
break;
31213132
default:
31223133
/* All ASCII control chars are length 1 */
31233134
ptr++;
3124-
break;
3135+
continue; /* fall to end of loop */
31253136
}
3137+
/* if we get here, we need to convert the control char */
3138+
DUMPSOFAR();
3139+
CopySendChar(cstate, '\\');
3140+
CopySendChar(cstate, c);
3141+
start = ++ptr; /* do not include char in next run */
31263142
}
31273143
else if (IS_HIGHBIT_SET(c))
31283144
ptr += pg_encoding_mblen(cstate->client_encoding, ptr);
@@ -3143,27 +3159,43 @@ CopyAttributeOutText(CopyState cstate, char *string)
31433159
}
31443160
else if ((unsigned char) c < (unsigned char) 0x20)
31453161
{
3162+
/*
3163+
* \r and \n must be escaped, the others are traditional.
3164+
* We prefer to dump these using the C-like notation, rather
3165+
* than a backslash and the literal character, because it
3166+
* makes the dump file a bit more proof against Microsoftish
3167+
* data mangling.
3168+
*/
31463169
switch (c)
31473170
{
3148-
/*
3149-
* \r and \n must be escaped, the others are
3150-
* traditional
3151-
*/
31523171
case '\b':
3172+
c = 'b';
3173+
break;
31533174
case '\f':
3175+
c = 'f';
3176+
break;
31543177
case '\n':
3178+
c = 'n';
3179+
break;
31553180
case '\r':
3181+
c = 'r';
3182+
break;
31563183
case '\t':
3184+
c = 't';
3185+
break;
31573186
case '\v':
3158-
DUMPSOFAR();
3159-
CopySendChar(cstate, '\\');
3160-
start = ptr++; /* we include char in next run */
3187+
c = 'v';
31613188
break;
31623189
default:
31633190
/* All ASCII control chars are length 1 */
31643191
ptr++;
3165-
break;
3192+
continue; /* fall to end of loop */
31663193
}
3194+
/* if we get here, we need to convert the control char */
3195+
DUMPSOFAR();
3196+
CopySendChar(cstate, '\\');
3197+
CopySendChar(cstate, c);
3198+
start = ++ptr; /* do not include char in next run */
31673199
}
31683200
else
31693201
ptr++;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy