7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.127 2001/01/03 20:04:10 tgl Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.128 2001/01/06 03:33:17 ishii Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -74,8 +74,8 @@ static bool fe_eof;
74
74
static StringInfoData attribute_buf ;
75
75
76
76
#ifdef MULTIBYTE
77
- static int encoding ;
78
-
77
+ static int client_encoding ;
78
+ static int server_encoding ;
79
79
#endif
80
80
81
81
@@ -297,7 +297,8 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
297
297
*/
298
298
initStringInfo (& attribute_buf );
299
299
#ifdef MULTIBYTE
300
- encoding = pg_get_client_encoding ();
300
+ client_encoding = pg_get_client_encoding ();
301
+ server_encoding = GetDatabaseEncoding ();
301
302
#endif
302
303
303
304
if (from )
@@ -1114,29 +1115,35 @@ CopyReadAttribute(FILE *fp, bool *isnull, char *delim, int *newline, char *null_
1114
1115
}
1115
1116
appendStringInfoCharMacro (& attribute_buf ,c );
1116
1117
#ifdef MULTIBYTE
1117
- /* get additional bytes of the char, if any */
1118
- s [0 ]= c ;
1119
- mblen = pg_encoding_mblen (encoding ,s );
1120
- for (j = 1 ;j < mblen ;j ++ )
1118
+ if (client_encoding != server_encoding )
1121
1119
{
1122
- c = CopyGetChar (fp );
1123
- if (c == EOF )
1124
- gotoendOfFile ;
1125
- appendStringInfoCharMacro (& attribute_buf ,c );
1120
+ /* get additional bytes of the char, if any */
1121
+ s [0 ]= c ;
1122
+ mblen = pg_encoding_mblen (client_encoding ,s );
1123
+ for (j = 1 ;j < mblen ;j ++ )
1124
+ {
1125
+ c = CopyGetChar (fp );
1126
+ if (c == EOF )
1127
+ gotoendOfFile ;
1128
+ appendStringInfoCharMacro (& attribute_buf ,c );
1129
+ }
1126
1130
}
1127
1131
#endif
1128
1132
}
1129
1133
1130
1134
#ifdef MULTIBYTE
1131
- cvt = (char * )pg_client_to_server ((unsignedchar * )attribute_buf .data ,
1132
- attribute_buf .len );
1133
- if (cvt != attribute_buf .data )
1135
+ if (client_encoding != server_encoding )
1134
1136
{
1135
- /* transfer converted data back to attribute_buf */
1136
- attribute_buf .len = 0 ;
1137
- attribute_buf .data [0 ]= '\0' ;
1138
- appendBinaryStringInfo (& attribute_buf ,cvt ,strlen (cvt ));
1139
- pfree (cvt );
1137
+ cvt = (char * )pg_client_to_server ((unsignedchar * )attribute_buf .data ,
1138
+ attribute_buf .len );
1139
+ if (cvt != attribute_buf .data )
1140
+ {
1141
+ /* transfer converted data back to attribute_buf */
1142
+ attribute_buf .len = 0 ;
1143
+ attribute_buf .data [0 ]= '\0' ;
1144
+ appendBinaryStringInfo (& attribute_buf ,cvt ,strlen (cvt ));
1145
+ pfree (cvt );
1146
+ }
1140
1147
}
1141
1148
#endif
1142
1149
@@ -1163,15 +1170,22 @@ CopyAttributeOut(FILE *fp, char *server_string, char *delim)
1163
1170
#endif
1164
1171
1165
1172
#ifdef MULTIBYTE
1166
- string = (char * )pg_server_to_client ((unsignedchar * )server_string ,
1167
- strlen (server_string ));
1168
- string_start = string ;
1173
+ if (client_encoding != server_encoding )
1174
+ {
1175
+ string = (char * )pg_server_to_client ((unsignedchar * )server_string ,
1176
+ strlen (server_string ));
1177
+ string_start = string ;
1178
+ }
1179
+ else
1180
+ {
1181
+ string = server_string ;
1182
+ }
1169
1183
#else
1170
1184
string = server_string ;
1171
1185
#endif
1172
1186
1173
1187
#ifdef MULTIBYTE
1174
- for (; (mblen = pg_encoding_mblen (encoding ,string ))&&
1188
+ for (; (mblen = ( server_encoding == client_encoding ? 1 : pg_encoding_mblen (client_encoding ,string ) ))&&
1175
1189
((c = * string )!= '\0' );string += mblen )
1176
1190
#else
1177
1191
for (; (c = * string )!= '\0' ;string ++ )
@@ -1188,7 +1202,7 @@ CopyAttributeOut(FILE *fp, char *server_string, char *delim)
1188
1202
}
1189
1203
1190
1204
#ifdef MULTIBYTE
1191
- if (string_start != server_string )
1205
+ if (client_encoding != server_encoding )
1192
1206
pfree (string_start );/* pfree pg_server_to_client result */
1193
1207
#endif
1194
1208
}