On Apr 19, 2010, at 12:51 PM, Chris Withers wrote:

> Michael Bayer wrote:
>> the MySQL string types support MySQL's "collation" flags so you can get
>> close to it for at least that platform.  But then you aren't platform
>> independent.
>> Not sure why you're so averse to creating types.   The interface could not
>> be simpler.   When i used Hibernate, there was no option - you had to make
>> types for pretty much anything non-trivial (like oracle BLOBs and such).
> 
> This is what I've ended up with:
> 
> from sqlalchemy import types
> from sqlalchemy.databases.mysql import MSString
> 
> class CaseSensitiveUnicode(types.TypeDecorator):
>    """This is a unicode case sensitive field"""
> 
>    impl = types.Unicode
> 
>    def get_col_spec(self):
>        if isinstance(self.impl,MSString):
>            self.impl.collation='utf8_bin'
>        return self.impl.get_col_spec()
> 
> Please let me know if there's a better way!

you should use TypeDecorator.load_dialect_impl(dialect), check the "name" of 
the dialect, then return either MSString(arguments) or 
super.load_dialect_impl().

if you want to totally go the "colspec" route in 0.6, make your type extend 
Unicode and implement @compiles for each dialect.    Something like 
http://www.sqlalchemy.org/docs/reference/ext/compiler.html#changing-compilation-of-types
 .




-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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