On Apr 1, 2014, at 11:28 AM, Alex <[email protected]> wrote:

> Yeah, its a very frustrating aspect of SQL Server. Anyway, a query that works 
> is the following:
> 
> SELECT testmodel.id AS testmodel_id, testmodel.flags AS testmodel_flags 
> FROM testmodel 
> WHERE (testmodel.flags & 1) > 0
> 
> I can get sqlalchemy to emit this like so:
> 
> session.query(TestModel).filter(TestModel.flag_one)
> 
> And the negation of it:
> 
> session.query(TestModel).filter(not_(TestModel.flag_one))
> 
> I can't figure out how to emit the required SQL on comparison with a boolean 
> value though.

well we've tried to improve boolean rendering to work around this "= 1"  "is 
true" thing, but I've identified more bugs in that regard, and even with the 
bug fixes that doesn't really help this specific situation. 

Here, you can have:

filter(TestModel.flag_one)
filter(~TestModel.flag_one)

or:

filter(TestModel.flag_one == True)
filter(TestModel.flag_one == False)


to have both at the same time, is more work.  You need to build an __eq__() 
method that swallows the "True" and negates on "False", and playing with this 
there some various ways to do this, trying a few here I'm having semi-success.  
 The most foolproof would be to build another special type that does this.

-- 
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/d/optout.

Reply via email to