2 -- Glyn Astill 09/02/2014
3 -- Plpython untrusted functions to do conversion from DOS cp850 native through Latin1 to UTF8 and vice versa
6 CREATE OR REPLACE FUNCTION cp850_to_utf8(in_text text) RETURNS text AS
8 rv = plpy.execute("SHOW client_encoding", 1)
9 v_encoding = rv[0]["client_encoding"]
10 if v_encoding.upper() != 'UTF8':
11 raise plpy.Error('Sorry client_encoding should be UTF8')
13 return unicode(in_text, 'cp850').encode('iso8859_1')
19 CREATE OR REPLACE FUNCTION utf8_to_cp850(in_text text) RETURNS text AS
21 rv = plpy.execute("SHOW client_encoding", 1)
22 v_encoding = rv[0]["client_encoding"]
23 if v_encoding.upper() != 'UTF8':
24 raise plpy.Error('Sorry client_encoding should be UTF8')
26 return unicode(in_text, 'iso8859_1').encode('cp850')
32 CREATE OR REPLACE FUNCTION cp850_to_latin1(in_text text) RETURNS text AS
34 rv = plpy.execute("SHOW client_encoding", 1)
35 v_encoding = rv[0]["client_encoding"]
36 if v_encoding.upper() != 'LATIN1':
37 raise plpy.Error('Sorry client_encoding should be LATIN1')
39 return unicode(in_text, 'cp850').encode('utf-8')
45 CREATE OR REPLACE FUNCTION latin1_to_cp850(in_text text) RETURNS text AS
47 rv = plpy.execute("SHOW client_encoding", 1)
48 v_encoding = rv[0]["client_encoding"]
49 if v_encoding.upper() != 'LATIN1':
50 raise plpy.Error('Sorry client_encoding should be LATIN1')
52 return unicode(in_text, 'utf-8').encode('cp850')