On Sep 23, 2009, at 9:03 PM, Joe wrote:
>
> I've tried various combinations of convert_unicode, assert_encoding
> and
> encoding parameters to the create_engine() call and I have not been
> able
> to get Unicode strings from SA, which I find somewhat surprising.
> Is it
> possible, or do I have to filter every string retrieved from the
> database through encoding(value, encoding='utf-8)?
>
> For reference, this is on Debian, using Python 2.5.4 and SA 0.5.5.
convert_unicode only takes effect for typed SQLAlchemy statements.
That is:
table = Table('sometable', metadata, Column('foo', String(50))
engine.execute(table.select())
or without convert_unicode, the Unicode type:
table = Table('sometable', metadata, Column('foo', Unicode(50))
engine.execute(table.select())
For straight textual statements, explicit typing is provided by Text().
With convert_unicode:
engine.execute(
text("select foo from table", typemap={'foo':String})
)
or with any engine:
engine.execute(
text("select foo from table", typemap={'foo':Unicode})
)
If you'd like to instead rely upon pyscopg2's implicit unicode
conversion, just do as you said:
from psycopg2.extensions import register_type, UNICODE
register_type(UNICODE)
then use create_engine() and further normally with any statement.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---