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

Commit933761e

Browse files
committed
Simplify pg_convert() in that it calls pg_convert2 using new fmgr interface.
1 parent1436b21 commit933761e

File tree

1 file changed

+11
-46
lines changed

1 file changed

+11
-46
lines changed

‎src/backend/utils/mb/mbutils.c

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* client encoding and server internal encoding.
44
* (currently mule internal code (mic) is used)
55
* Tatsuo Ishii
6-
* $Id: mbutils.c,v 1.26 2001/11/19 06:48:39 ishii Exp $
6+
* $Id: mbutils.c,v 1.27 2001/11/20 01:32:29 ishii Exp $
77
*/
88
#include"postgres.h"
99

@@ -212,54 +212,19 @@ pg_do_encoding_conversion(unsigned char *src, int len,
212212
Datum
213213
pg_convert(PG_FUNCTION_ARGS)
214214
{
215-
text*string=PG_GETARG_TEXT_P(0);
216-
Names=PG_GETARG_NAME(1);
217-
intencoding=pg_char_to_encoding(NameStr(*s));
218-
intdb_encoding=DatabaseEncoding->encoding;
219-
to_mic_convertersrc;
220-
from_mic_converterdest;
221-
unsignedchar*result;
222-
text*retval;
223-
unsignedchar*str;
224-
intlen;
225-
226-
if (encoding<0)
227-
elog(ERROR,"Invalid encoding name %s",NameStr(*s));
228-
229-
if (pg_find_encoding_converters(db_encoding,encoding,&src,&dest)<0)
230-
{
231-
char*encoding_name= (char*)pg_encoding_to_char(db_encoding);
215+
Datumstring=PG_GETARG_DATUM(0);
216+
Datumdest_encoding_name=PG_GETARG_DATUM(1);
217+
Datumsrc_encoding_name=DirectFunctionCall1(
218+
namein,CStringGetDatum(DatabaseEncoding->name));
219+
Datumresult;
232220

233-
elog(ERROR,"Conversion from %s to %s is not possible",NameStr(*s),encoding_name);
234-
}
221+
result=DirectFunctionCall3(
222+
pg_convert2,string,src_encoding_name,dest_encoding_name);
235223

236-
/* make sure that source string is null terminated */
237-
len=VARSIZE(string)-VARHDRSZ;
238-
str=palloc(len+1);
239-
memcpy(str,VARDATA(string),len);
240-
*(str+len)='\0';
224+
/* free memory allocated by namein */
225+
pfree((void*)dest_encoding_name);
241226

242-
result=pg_do_encoding_conversion(str,len,src,dest);
243-
if (result==NULL)
244-
elog(ERROR,"Encoding conversion failed");
245-
246-
/* build text data type structre. we cannot use textin() here,
247-
since textin assumes that input string encoding is same as
248-
database encoding. */
249-
len=strlen(result)+VARHDRSZ;
250-
retval=palloc(len);
251-
VARATT_SIZEP(retval)=len;
252-
memcpy(VARDATA(retval),result,len-VARHDRSZ);
253-
254-
/* free memory allocated by pg_do_encoding_conversion */
255-
if (result!=str)
256-
pfree(result);
257-
pfree(str);
258-
259-
/* free memory if allocated by the toaster */
260-
PG_FREE_IF_COPY(string,0);
261-
262-
PG_RETURN_TEXT_P(retval);
227+
PG_RETURN_TEXT_P(result);
263228
}
264229

265230
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp