Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
933761e7
Commit
933761e7
authored
Nov 20, 2001
by
Tatsuo Ishii
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify pg_convert() in that it calls pg_convert2 using new fmgr interface.
parent
1436b212
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
46 deletions
+11
-46
src/backend/utils/mb/mbutils.c
src/backend/utils/mb/mbutils.c
+11
-46
No files found.
src/backend/utils/mb/mbutils.c
View file @
933761e7
...
...
@@ -3,7 +3,7 @@
* client encoding and server internal encoding.
* (currently mule internal code (mic) is used)
* Tatsuo Ishii
* $Id: mbutils.c,v 1.2
6 2001/11/19 06:48:3
9 ishii Exp $
* $Id: mbutils.c,v 1.2
7 2001/11/20 01:32:2
9 ishii Exp $
*/
#include "postgres.h"
...
...
@@ -212,54 +212,19 @@ pg_do_encoding_conversion(unsigned char *src, int len,
Datum
pg_convert
(
PG_FUNCTION_ARGS
)
{
text
*
string
=
PG_GETARG_TEXT_P
(
0
);
Name
s
=
PG_GETARG_NAME
(
1
);
int
encoding
=
pg_char_to_encoding
(
NameStr
(
*
s
));
int
db_encoding
=
DatabaseEncoding
->
encoding
;
to_mic_converter
src
;
from_mic_converter
dest
;
unsigned
char
*
result
;
text
*
retval
;
unsigned
char
*
str
;
int
len
;
if
(
encoding
<
0
)
elog
(
ERROR
,
"Invalid encoding name %s"
,
NameStr
(
*
s
));
if
(
pg_find_encoding_converters
(
db_encoding
,
encoding
,
&
src
,
&
dest
)
<
0
)
{
char
*
encoding_name
=
(
char
*
)
pg_encoding_to_char
(
db_encoding
);
Datum
string
=
PG_GETARG_DATUM
(
0
);
Datum
dest_encoding_name
=
PG_GETARG_DATUM
(
1
);
Datum
src_encoding_name
=
DirectFunctionCall1
(
namein
,
CStringGetDatum
(
DatabaseEncoding
->
name
));
Datum
result
;
elog
(
ERROR
,
"Conversion from %s to %s is not possible"
,
NameStr
(
*
s
),
encoding_name
);
}
result
=
DirectFunctionCall3
(
pg_convert2
,
string
,
src_encoding_name
,
dest_encoding_name
);
/* make sure that source string is null terminated */
len
=
VARSIZE
(
string
)
-
VARHDRSZ
;
str
=
palloc
(
len
+
1
);
memcpy
(
str
,
VARDATA
(
string
),
len
);
*
(
str
+
len
)
=
'\0'
;
/* free memory allocated by namein */
pfree
((
void
*
)
dest_encoding_name
);
result
=
pg_do_encoding_conversion
(
str
,
len
,
src
,
dest
);
if
(
result
==
NULL
)
elog
(
ERROR
,
"Encoding conversion failed"
);
/* build text data type structre. we cannot use textin() here,
since textin assumes that input string encoding is same as
database encoding. */
len
=
strlen
(
result
)
+
VARHDRSZ
;
retval
=
palloc
(
len
);
VARATT_SIZEP
(
retval
)
=
len
;
memcpy
(
VARDATA
(
retval
),
result
,
len
-
VARHDRSZ
);
/* free memory allocated by pg_do_encoding_conversion */
if
(
result
!=
str
)
pfree
(
result
);
pfree
(
str
);
/* free memory if allocated by the toaster */
PG_FREE_IF_COPY
(
string
,
0
);
PG_RETURN_TEXT_P
(
retval
);
PG_RETURN_TEXT_P
(
result
);
}
/*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment