Michael Bayer wrote: > On Oct 4, 2007, at 5:07 AM, Werner F. Bruhin wrote: > > >> I have just started to work with sqlalchemy and there is one thing I >> can't figure out. >> >> I am using Firebird SQL 2.0 and kinterbasdb 3.2, and I have some blob >> columns defined as: >> >> NOTES MEMO /* MEMO = BLOB SUB_TYPE 1 SEGMENT SIZE 80 */, >> >> CREATE DOMAIN MEMO AS >> BLOB SUB_TYPE 1 SEGMENT SIZE 80 CHARACTER SET ISO8859_1; >> >> The call to create_engine includes " encoding='utf-8'," but any blob >> column is returned as a string instead of Unicode. >> >> varchar columns are returned as Unicode. >> >> I am working on an existing database, so I adapted the script from on >> this page http://www.sqlalchemy.org/trac/wiki/UsageRecipes/AutoCode >> and >> it generated the model for the notes column as "sa.Column( u'notes', >> sa.TEXT(length=None,convert_unicode=False))". >> >> So, first I thought it had to do with the convert_unicode param but >> the >> same is used on the varchar fields which work fine for me. >> >> Can anyone point out what I am doing wrong. >> > > you should have the convert_unicode=True param set on the TEXT > column. that will apply the engine's encoding of "utf-8" to the > encoded strings returned from the database. if you have VARCHAR > fields which dont have this flag set, but they are still coming back > as unicode, then its probably a product of kinterbasdb doing it (i > dont use firebird over here). > I have done some more research on this. kinterbasdb the way it is configured by default in firebird.py (type_conv=200) will do the conversion from any encoding used within the database to the encoding defined on the connection. I guess this is why it works for the varchar and char fields. There is some stuff implemented in kinterbasdb to do the same for blob fields but due to some FB limitation it is currently not activated by default in the Dynamic Type Translation.
See the thread: http://sourceforge.net/forum/forum.php?thread_id=1299756&forum_id=30917 I wonder if this stuff could be used? I am willing to give it a try but don't know how to access the kinterbasdb.connection when using sqlalchemy. def blobInputDTT(x): ____if isinstance(x, unicode): ________return x.encode('UTF-8') ____else: ________return x kinterbasdb.connection.set_type_trans_in({'BLOB': blobInputDTT}) kinterbasdb.connection.set_type_trans_out({'BLOB': {'mode': 'materialize', 'treat_subtype_text_as_text': True}}) Could this be done on the engine instance? Werner > > > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
