Re: Cannot store special chars using c lib - Mailing list pgsql-general

From Alexander Reichstadt
Subject Re: Cannot store special chars using c lib
Date
Msg-id 99963FD2-372E-496F-9104-031659358965@mac.com
Whole thread Raw
In response to Cannot store special chars using c lib  (Alexander Reichstadt <lxr@mac.com>)
Responses Re: Cannot store special chars using c lib
List pgsql-general
Sorry, there is a copy-paste error, actually the code really is:
const char *cString = [sql cStringUsingEncoding:defaultEncoding];
if (cString == NULL) {
blablabla
//This just catches cases where cString failed to encode.
}
res = PQexec(pgconn, cString);

Am 22.03.2012 um 09:02 schrieb Alexander Reichstadt:

Hi,

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?

Thanks

pgsql-general by date:

Previous
From: Alexander Reichstadt
Date:
Subject: Cannot store special chars using c lib
Next
From: "Albe Laurenz"
Date:
Subject: Re: Slow information_schema.views