Re: Cannot store special chars using c lib

From: "Albe Laurenz" <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "Alexander Reichstadt *EXTERN*" <lxr(at)mac(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Cannot store special chars using c lib
Date: 2012-03-22 11:50:37
Message-ID: D960CB61B694CF459DCFB4B0128514C207A2B74E@exadv11.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alexander Reichstadt wrote:
> I need to be able to store special chars, German Umlaute, in my tables. This works when using
> pgPHPAdmin to store the same value to the same field. But when using the c-library it doesn't, fields
> stored are garbled.
>
> I checked using \l to see what encoding the database is which is UTF8, UTF8 is what's required.
>
> List of databases
> Name | Owner | Encoding | Collation | Ctype | Access privileges
> -----------+----------+----------+-----------+-------+-----------------------
> MyDB | postgres | UTF8 | C | C |
> alltypes | postgres | UTF8 | de_DE | C |
> postgres | postgres | UTF8 | C | C |
> template0 | postgres | UTF8 | C | C | =c/postgres +
> | | | | | postgres=CTc/postgres
> template1 | postgres | UTF8 | C | C | =c/postgres +
> | | | | | postgres=CTc/postgres
>
>
> As a way to store things I use PGSQLKit, which in turn uses
>
> const char *cString = [sql cStringUsingEncoding:defaultEncoding];
> if (cString == NULL)
>
> res = PQexec(pgconn, cString);
>
> to store things. The defaultEncoding I also changed explicitly from defaultEncoding to UTF8 to try,
> but got the same result. As far as I can see this is not an error on part of the PGSQLKit.
>
>
> From what I read there is no table specific encoding.
>
> The collation is set to C, but that's something only relevant to sorting as far s I understand.
>
> So, I am at a loss as to where things go wrong.
>
> Any ideas?

I know nothing about PGSQLKit, but you should check what client_encoding is set to.
If it is set to something else than UTF8, say for example LATIN1, then PostgreSQL
will happily interpret the bytes in your UTF8 string as LATIN1 and convert them
to UTF8, resulting in things like 'schöne ScheiÃ\u009Fe'.

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alexander Reichstadt 2012-03-22 12:24:50 Re: Cannot store special chars using c lib
Previous Message Alexander Reichstadt 2012-03-22 10:42:23 Re: Cannot store special chars using c lib