forked from bwtakacy/eudc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eudc.sql.pg13.in
64 lines (56 loc) · 2.94 KB
/
eudc.sql.pg13.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
-- SJIS_EUDC --> UTF8
CREATE FUNCTION pg_catalog.sjis_eudc_to_utf8
(integer, integer, cstring, internal, integer)
RETURNS void AS '$libdir/eudc', 'sjis_eudc_to_utf8' LANGUAGE C STRICT;
CREATE CONVERSION pg_catalog.sjis_eudc_to_utf8
FOR 'SJIS' TO 'UTF8' FROM sjis_eudc_to_utf8;
-- UTF8 --> SJIS_EUDC
CREATE FUNCTION pg_catalog.utf8_to_sjis_eudc
(integer, integer, cstring, internal, integer)
RETURNS void AS '$libdir/eudc', 'utf8_to_sjis_eudc' LANGUAGE C STRICT;
CREATE CONVERSION pg_catalog.utf8_to_sjis_eudc
FOR 'UTF8' TO 'SJIS' FROM utf8_to_sjis_eudc;
-- EUC_JP_EUDC --> UTF8
CREATE FUNCTION pg_catalog.euc_jp_eudc_to_utf8
(integer, integer, cstring, internal, integer)
RETURNS void AS '$libdir/eudc', 'euc_jp_eudc_to_utf8' LANGUAGE C STRICT;
CREATE CONVERSION pg_catalog.euc_jp_eudc_to_utf8
FOR 'EUC_JP' TO 'UTF8' FROM euc_jp_eudc_to_utf8;
-- UTF8 --> EUC_JP_EUDC
CREATE FUNCTION pg_catalog.utf8_to_euc_jp_eudc
(integer, integer, cstring, internal, integer)
RETURNS void AS '$libdir/eudc', 'utf8_to_euc_jp_eudc' LANGUAGE C STRICT;
CREATE CONVERSION pg_catalog.utf8_to_euc_jp_eudc
FOR 'UTF8' TO 'EUC_JP' FROM utf8_to_euc_jp_eudc;
-- To show eudc function information
CREATE OR REPLACE FUNCTION show_eudc(OUT "Conversion Function" varchar,
OUT "Source" varchar, OUT "Destination" varchar,
OUT "Is Default?" varchar)
RETURNS SETOF record
AS '$libdir/eudc', 'show_eudc' LANGUAGE C IMMUTABLE STRICT;
-- enable/disable function
CREATE OR REPLACE FUNCTION pg_catalog.enable_eudc()
RETURNS void SET search_path TO 'pg_catalog' AS
$$
UPDATE pg_conversion SET condefault = 'f' WHERE conname = 'sjis_to_utf8';
UPDATE pg_conversion SET condefault = 'f' WHERE conname = 'utf8_to_sjis';
UPDATE pg_conversion SET condefault = 'f' WHERE conname = 'euc_jp_to_utf8';
UPDATE pg_conversion SET condefault = 'f' WHERE conname = 'utf8_to_euc_jp';
UPDATE pg_conversion SET condefault = 't' WHERE conname = 'sjis_eudc_to_utf8';
UPDATE pg_conversion SET condefault = 't' WHERE conname = 'utf8_to_sjis_eudc';
UPDATE pg_conversion SET condefault = 't' WHERE conname = 'euc_jp_eudc_to_utf8';
UPDATE pg_conversion SET condefault = 't' WHERE conname = 'utf8_to_euc_jp_eudc';
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION pg_catalog.disable_eudc()
RETURNS void SET search_path TO 'pg_catalog' AS
$$
UPDATE pg_conversion SET condefault = 'f' WHERE conname = 'sjis_eudc_to_utf8';
UPDATE pg_conversion SET condefault = 'f' WHERE conname = 'utf8_to_sjis_eudc';
UPDATE pg_conversion SET condefault = 'f' WHERE conname = 'euc_jp_eudc_to_utf8';
UPDATE pg_conversion SET condefault = 'f' WHERE conname = 'utf8_to_euc_jp_eudc';
UPDATE pg_conversion SET condefault = 't' WHERE conname = 'sjis_to_utf8';
UPDATE pg_conversion SET condefault = 't' WHERE conname = 'utf8_to_sjis';
UPDATE pg_conversion SET condefault = 't' WHERE conname = 'euc_jp_to_utf8';
UPDATE pg_conversion SET condefault = 't' WHERE conname = 'utf8_to_euc_jp';
$$ LANGUAGE sql;
SELECT pg_catalog.enable_eudc();