0

I have a UTF8 encoding database. I am using ECPG - PROGRAM C.

When I get data recordset with EXEC SQL

 EXEC SQL DECLARE cur_myTable CURSOR FOR
     SELECT code,
            label
     INTO  :hv_cod,
           :hv_label
     FROM  myTable

but I print data in the pgc file,

printf("\n libellé => %s", :hv_label ), I get:

I get :

libellé => télé.

Is it possible to UTF8 decode a host variable to ISO-8859-1 in a program C ? Is it possible to say in the .pgc file : Postgres I want UTF8-decode values ?

Thanks

toch
  • 67
  • 6

1 Answers1

4

Is it possible to UTF8 decode a host variable to ISO-8859-1 in a program C ?

Sure, lots of libraries do it. Look at libiconv for example.

Is it possible to say in the .pgc file : Postgres I want UTF8-decode values ?

Trivially. Set client_encoding to iso-8859-1 or whatever your local encoding is. You can do this with libpq functions; ecpg may have its own equivalents, not sure.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • Hi Craig ! thank you, I found what I need at [UTF8 decoding](http://stackoverflow.com/a/11173493/3318639) in C language, but ecpg does not have equivalents. – toch Apr 18 '14 at 12:39
  • 2
    Oh man, Postgres is so cool ! NO NEED for UTF8 decoding or encoding, I found an easier solution : in the pgc file, just say : EXEC SQL SET CLIENT_ENCODING TO "ISO-8859-1"; It doesn't matter what database encoding is and it works ! so cool ! – toch Apr 18 '14 at 13:04