Re: [sqlalchemy] case sensitive Unicode and String columns
Michael Bayer wrote: Please let me know if there's a better way! you should use TypeDecorator.load_dialect_impl(dialect), check the name of the dialect, Why the name rather than doing: if isinstance(dialect,MySQLDialect): ? then return either MSString(arguments) or super.load_dialect_impl(). Okay, but where do I get the arguments from? super(CaseSensitiveUnicode,self).load_dialect_impl(dialect) leads to: 263 if isinstance(self.impl, TypeDecorator): 264 return self.impl.dialect_impl(dialect) 265 else: 266 return dialect.type_descriptor(self.impl) ...which then ends up in some adapt_type stuff that looked pretty hairy. All I want to do is insert a collation argument when the dialect is MySQL... cheers, Chris -- 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.
Re: [sqlalchemy] case sensitive Unicode and String columns
Chris Withers wrote: Michael Bayer wrote: Please let me know if there's a better way! you should use TypeDecorator.load_dialect_impl(dialect), check the name of the dialect, Why the name rather than doing: if isinstance(dialect,MySQLDialect): you could do that too, though the name is more solid then return either MSString(arguments) or super.load_dialect_impl(). Okay, but where do I get the arguments from? you have to stick them on your custom type.i.e. your typedecorator object. super(CaseSensitiveUnicode,self).load_dialect_impl(dialect) leads to: 263 if isinstance(self.impl, TypeDecorator): 264 return self.impl.dialect_impl(dialect) 265 else: 266 return dialect.type_descriptor(self.impl) ...which then ends up in some adapt_type stuff that looked pretty hairy. All I want to do is insert a collation argument when the dialect is MySQL... this is the code: def load_dialect_impl(self, dialect): if dialect.name == 'mysql': return MSString(self.length, collation=self.collation_whatever) else: return super(MyType, self).load_dialect_impl(dialect) -- 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.
Re: [sqlalchemy] case sensitive Unicode and String columns
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! Chris -- 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.
Re: [sqlalchemy] case sensitive Unicode and String columns
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.
Re: [sqlalchemy] case sensitive Unicode and String columns
Michael Bayer wrote: How do I do this? I think all databases that SQLAlchemy supports (in fact, likely all databases in use today) support case-sensitive strings by default, so I don't know if this something you'll need to worry about in your code. Maybe I am misunderstanding what you are trying to do? hes likely referring to case-sensitive collation support. Build a TypeDecorator and intercept the dialect in the process_bind_param() method. This sounds pretty heavyweight unless I'm misunderstanding... I was hoping for something like: class MyModel(Base): __tablename__ = 'foo' ... myfield = Column(String(50,case_sensitive=True)) I know this doesn't exist, but I was hoping either it was easy to implement or a field type could be created that did the right thing no matter what the back end was... Chris -- Simplistix - Content Management, Batch Processing Python Consulting - http://www.simplistix.co.uk -- 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.
Re: [sqlalchemy] case sensitive Unicode and String columns
Chris Withers wrote: Michael Bayer wrote: How do I do this? I think all databases that SQLAlchemy supports (in fact, likely all databases in use today) support case-sensitive strings by default, so I don't know if this something you'll need to worry about in your code. Maybe I am misunderstanding what you are trying to do? hes likely referring to case-sensitive collation support. Build a TypeDecorator and intercept the dialect in the process_bind_param() method. This sounds pretty heavyweight unless I'm misunderstanding... I was hoping for something like: class MyModel(Base): __tablename__ = 'foo' ... myfield = Column(String(50,case_sensitive=True)) I know this doesn't exist, but I was hoping either it was easy to implement or a field type could be created that did the right thing no matter what the back end was... 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). Chris -- Simplistix - Content Management, Batch Processing Python Consulting - http://www.simplistix.co.uk -- 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. -- 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.
[sqlalchemy] case sensitive Unicode and String columns
Hi All, I'm looking to create a model with a unicode or string column type that is case sensitive. I'm looking to do this in the model in such a way that the code in the model doesn't know or care about what backend database is used, but that barfs if it's ever used with a backend that doesn't actually support case-sensitive strings or unicodes. The current set of back ends we're targeting is (MySQL,sqlite)... How do I do this? Chris -- Simplistix - Content Management, Batch Processing Python Consulting - http://www.simplistix.co.uk -- 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.
Re: [sqlalchemy] case sensitive Unicode and String columns
On Thu, Mar 4, 2010 at 11:34 AM, Chris Withers ch...@simplistix.co.uk wrote: Hi All, I'm looking to create a model with a unicode or string column type that is case sensitive. I'm looking to do this in the model in such a way that the code in the model doesn't know or care about what backend database is used, but that barfs if it's ever used with a backend that doesn't actually support case-sensitive strings or unicodes. The current set of back ends we're targeting is (MySQL,sqlite)... How do I do this? I think all databases that SQLAlchemy supports (in fact, likely all databases in use today) support case-sensitive strings by default, so I don't know if this something you'll need to worry about in your code. Maybe I am misunderstanding what you are trying to do? -Daniel -- 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.
Re: [sqlalchemy] case sensitive Unicode and String columns
Daniel Robbins wrote: On Thu, Mar 4, 2010 at 11:34 AM, Chris Withers ch...@simplistix.co.uk wrote: Hi All, I'm looking to create a model with a unicode or string column type that is case sensitive. I'm looking to do this in the model in such a way that the code in the model doesn't know or care about what backend database is used, but that barfs if it's ever used with a backend that doesn't actually support case-sensitive strings or unicodes. The current set of back ends we're targeting is (MySQL,sqlite)... How do I do this? I think all databases that SQLAlchemy supports (in fact, likely all databases in use today) support case-sensitive strings by default, so I don't know if this something you'll need to worry about in your code. Maybe I am misunderstanding what you are trying to do? hes likely referring to case-sensitive collation support. Build a TypeDecorator and intercept the dialect in the process_bind_param() method. -Daniel -- 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. -- 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.