I'm working with an existing MySQL schema that has lots of columns of
type ENUM('N', 'Y').  I'd like to deal with them as real booleans on
the python side.

I have a simple TypeDecorator which almost works (I think):

    class YNBoolean(sqlalchemy.types.TypeDecorator):

        impl = mysql.ENUM('N', 'Y', charset='ascii')

        def process_bind_param(self, value, dialect):
            if value is None:
                return value
            return 'Y' if value else 'N'

        def process_result_value(self, value, dialect):
            if value is None:
                return None
            return value == 'Y'

The one problem I've discovered with this is that

    session.query(MyTable).filter(MyTable.ynbool)

produces a query like

    SELECT ... FROM MyTable WHERE MyTable.ynbool;

What I really want is

    SELECT ... FROM MyTable WHERE MyTable.ynbool = 'Y';


(If I do .filter(MyTable.ynbool == True) that does work as desired/expected.)


Is there a way to customize how my column gets compiled when used
in an expression in a boolean context?  (If not, I can live with it
as is.  I'll just get surprised once in awhile when I forget that
treating the column as a boolean in expressions won't work.)

Thank you for any help.
Jeff



-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to