On Wed, 1 Mar 2006 16:24:02 -0500, Michael Bayer <[EMAIL PROTECTED]> wrote:
wow, i wish you had told me this yesterday, when i was asking if psycopg can handle unicode (on irc ? not sure where that was).

anyway, theres a ticket that I "fixed" by allowing the "convert_unicode" flag to Engine which will do the native utf-8 <-> binary encoding in and out of any engine. you might want to try that.

It could work if it handled None well :).

but, postgres should be modified to detect this flag and use psycopg's built-in ability to do this, no ? does psycopg return a u'' string in all cases when this is set ?

Yes it does after you set the UNICODE typecaster (which I warmly recommend).

This can be done in this way:

psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)

There's a useful script in psycopg2 examples that runs a bunch of queries about 
encodings 
(http://initd.org/tracker/psycopg/browser/psycopg2/trunk/examples/encoding.py):

The result on my ibook (with UTF-8 terminal):

Available encodings:
 LATIN-1 <-> latin_1
 LATIN1 <-> latin_1
 SQL_ASCII <-> ascii
 UNICODE <-> utf_8
 UTF8 <-> utf_8
Using STRING typecaster
Setting backend encoding to LATIN1 and executing queries:
 -> àèìòù <type 'str'>
 -> àèìòù <type 'str'>
Setting backend encoding to UTF8 and executing queries:
 -> àèìòù <type 'str'>
 -> àèìòù <type 'str'>
Using UNICODE typecaster
Setting backend encoding to LATIN1 and executing queries:
 -> àèìòù : <type 'unicode'>
 -> àèìòù : <type 'unicode'>
Setting backend encoding to UTF8 and executing queries:
 -> àèìòù : <type 'unicode'>
 -> àèìòù : <type 'unicode'>
Executing full UNICODE queries
Setting backend encoding to LATIN1 and executing queries:
 -> àèìòù : <type 'unicode'>
 -> àèìòù : <type 'unicode'>
Setting backend encoding to UTF8 and executing queries:
 -> àèìòù : <type 'unicode'>
 -> àèìòù : <type 'unicode'>


for reference see ticket http://www.sqlalchemy.org/trac/ticket/86

Thanks for the tip :)

--
Valentino Volonghi aka Dialtone
Now Running MacOSX 10.4
Blog: http://vvolonghi.blogspot.com
New Pet: http://www.stiq.it


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to