88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.290 2007/12/03 00:03:05 tgl Exp $
11+ * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.291 2007/12/27 16:45:22 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -3094,13 +3094,7 @@ CopyAttributeOutText(CopyState cstate, char *string)
30943094start = ptr ;
30953095while ((c = * ptr )!= '\0' )
30963096{
3097- if (c == '\\' || c == delimc )
3098- {
3099- DUMPSOFAR ();
3100- CopySendChar (cstate ,'\\' );
3101- start = ptr ++ ;/* we include char in next run */
3102- }
3103- else if ((unsignedchar )c < (unsignedchar )0x20 )
3097+ if ((unsignedchar )c < (unsignedchar )0x20 )
31043098{
31053099/*
31063100 * \r and \n must be escaped, the others are traditional.
@@ -3130,6 +3124,9 @@ CopyAttributeOutText(CopyState cstate, char *string)
31303124c = 'v' ;
31313125break ;
31323126default :
3127+ /* If it's the delimiter, must backslash it */
3128+ if (c == delimc )
3129+ break ;
31333130/* All ASCII control chars are length 1 */
31343131ptr ++ ;
31353132continue ;/* fall to end of loop */
@@ -3140,6 +3137,12 @@ CopyAttributeOutText(CopyState cstate, char *string)
31403137CopySendChar (cstate ,c );
31413138start = ++ ptr ;/* do not include char in next run */
31423139}
3140+ else if (c == '\\' || c == delimc )
3141+ {
3142+ DUMPSOFAR ();
3143+ CopySendChar (cstate ,'\\' );
3144+ start = ptr ++ ;/* we include char in next run */
3145+ }
31433146else if (IS_HIGHBIT_SET (c ))
31443147ptr += pg_encoding_mblen (cstate -> client_encoding ,ptr );
31453148else
@@ -3151,13 +3154,7 @@ CopyAttributeOutText(CopyState cstate, char *string)
31513154start = ptr ;
31523155while ((c = * ptr )!= '\0' )
31533156{
3154- if (c == '\\' || c == delimc )
3155- {
3156- DUMPSOFAR ();
3157- CopySendChar (cstate ,'\\' );
3158- start = ptr ++ ;/* we include char in next run */
3159- }
3160- else if ((unsignedchar )c < (unsignedchar )0x20 )
3157+ if ((unsignedchar )c < (unsignedchar )0x20 )
31613158{
31623159/*
31633160 * \r and \n must be escaped, the others are traditional.
@@ -3187,6 +3184,9 @@ CopyAttributeOutText(CopyState cstate, char *string)
31873184c = 'v' ;
31883185break ;
31893186default :
3187+ /* If it's the delimiter, must backslash it */
3188+ if (c == delimc )
3189+ break ;
31903190/* All ASCII control chars are length 1 */
31913191ptr ++ ;
31923192continue ;/* fall to end of loop */
@@ -3197,6 +3197,12 @@ CopyAttributeOutText(CopyState cstate, char *string)
31973197CopySendChar (cstate ,c );
31983198start = ++ ptr ;/* do not include char in next run */
31993199}
3200+ else if (c == '\\' || c == delimc )
3201+ {
3202+ DUMPSOFAR ();
3203+ CopySendChar (cstate ,'\\' );
3204+ start = ptr ++ ;/* we include char in next run */
3205+ }
32003206else
32013207ptr ++ ;
32023208}