On Nov 29, 2011, at 10:39 PM, Dirk Makowski wrote:

> Thanks for the quick reply. Passing use_native_unicode=False  to 
> create_engine() indeed prevents this error. Is this parameter missing in the 
> docs for create_engine() 
> (http://www.sqlalchemy.org/docs/core/engines.html#engine-creation-api)?

you need to look at the docs specific to the DBAPI in use (we support like 20): 
 
http://www.sqlalchemy.org/docs/dialects/postgresql.html#module-sqlalchemy.dialects.postgresql.psycopg2

> 
> I had assumed the "encoding" parameter to set the wanted client-encoding, but 
> changing it had no effect on the decode error. What is the purpose of this 
> parameter, then?

"encoding" as passed to create_engine() only affects those encode/decode 
operations which SQLAlchemy performs itself; when a DBAPI does not accept 
Python unicode objects, or does not return them, SQLAlchemy uses this as the 
charset to coerce to/from Python unicode.   Even DBAPIs that do "support" 
unicode still often expose areas where SQLA has to do things by hand;  bound 
parameter names, bound parameter values, result set values, the string 
statement itself, the string names within cursor.description (many DBAPIs 
especially miss that last one).

As we all move to Python 3 and those DBAPIs will at last all be forced to fully 
support unicode natively (which has already been happening for several years), 
this parameter will likely no longer be needed.


> 
> The psycopg2 script detects the database encoding as "SQLASCII" and prints 
> out "'St\xc3\xbcck'::character varying".
> After adding
> dbapi.extensions.register_type(dbapi.extensions.UNICODE, c)
> indeed the decode error happens.
> However, if I explicitly do  set_client_encoding('utf8'), then it prints 
> without an error u"'St\xfcck'::character varying"
> 
> I had expected the "encoding" parameter of create_engine() to have the same 
> purpose as set_client_encoding() of psycopg2. Did I misunderstand sth.?

Yeah funny story here is that I forgot all about that setting.   We added 
support for that in 0.7.3 and that is the "client_encoding" parameter on 
create_engine(), documented here:  
http://www.sqlalchemy.org/docs/dialects/postgresql.html#client-encoding    - 
however quite disastrously that paragraph supercedes/contradicts the "unicode" 
paragraph further up, so I'm going to merge those two together right now.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to