On Aug 22, 2012, at 4:37 PM, ThiefMaster wrote:

> I think this is a bug; it should either result in an error or work as 
> expected - in python this **is** valid after all:
> 
> >>> str(X.query.filter(2 < X.id < 5))
> 'SELECT x.id AS x_id \nFROM x \nWHERE x.id > :id_1'
> 
> This shouldn't generate the following SQL
> 
> >>> str(X.query.filter(2 < X.id))
> 'SELECT x.id AS x_id \nFROM x \nWHERE x.id > :id_1'
> 
> but rather this SQL:
> 
> >>> str(X.query.filter(2 < X.id, X.id < 5))
> 'SELECT x.id AS x_id \nFROM x \nWHERE x.id > :id_1 AND x.id < :id_2'

Here, I will illustrate the "bug" here is a fact of Python itself.   If I'm 
missing how to make this work, apply it to the following script and I'll gladly 
commit :


class MyComparator(object):
    def __lt__(self, other):
        return Binary(self, other, "<")

class Column(MyComparator):
    def __init__(self, name):
        self.name = name

    def __str__(self):
        return self.name

class Binary(MyComparator):
    def __init__(self, left, right, operator):
        self.left = left
        self.right = right
        self.operator = operator

    def __str__(self):
        return "%s %s %s" % (self.left, self.operator, self.right)

c1, c2, c3 = Column('c1'), Column('c2'), Column('c3')

# prints "c1 < c2"
print c1 < c2

# prints "c1 < c2 < c3"
print (c1 < c2) < c3

# prints "c2 < c3". the "c1 < c2" and "c2 < c3" are
# evaluated by __lt__() separately;
# the result of "c1 < c2" is lost and the expression
# only returns "c2 < c3" individually.
print c1 < c2 < c3

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