summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql.py
diff options
context:
space:
mode:
authorAnts Aasma <ants.aasma@gmail.com>2007-06-25 18:14:40 +0000
committerAnts Aasma <ants.aasma@gmail.com>2007-06-25 18:14:40 +0000
commit987581e6d2c893f4fe1c6877bd4b096f00ff63c3 (patch)
tree19a71c67c0fd50baa7019314dc6caa1c51eb550e /lib/sqlalchemy/sql.py
parentbc58df9c1f1f443b67a3312463df2c9425531503 (diff)
downloadsqlalchemy-987581e6d2c893f4fe1c6877bd4b096f00ff63c3.tar.gz
fix precedence of between (ticket #621)
Diffstat (limited to 'lib/sqlalchemy/sql.py')
-rw-r--r--lib/sqlalchemy/sql.py16
1 files changed, 5 insertions, 11 deletions
diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py
index 9bea33946..be1ed8a69 100644
--- a/lib/sqlalchemy/sql.py
+++ b/lib/sqlalchemy/sql.py
@@ -33,7 +33,7 @@ __all__ = ['AbstractDialect', 'Alias', 'ClauseElement', 'ClauseParameters',
'ClauseVisitor', 'ColumnCollection', 'ColumnElement',
'Compiled', 'CompoundSelect', 'Executor', 'FromClause', 'Join',
'Select', 'Selectable', 'TableClause', 'alias', 'and_', 'asc',
- 'between_', 'bindparam', 'case', 'cast', 'column', 'delete',
+ 'between_', 'between', 'bindparam', 'case', 'cast', 'column', 'delete',
'desc', 'distinct', 'except_', 'except_all', 'exists', 'extract', 'func', 'modifier',
'insert', 'intersect', 'intersect_all', 'join', 'literal',
'literal_column', 'not_', 'null', 'or_', 'outerjoin', 'select',
@@ -62,13 +62,13 @@ PRECEDENCE = {
'<':5,
'>=':5,
'<=':5,
+ 'BETWEEN':5,
'NOT':4,
'AND':3,
'OR':2,
',':-1,
'AS':-1,
'EXISTS':0,
- 'BETWEEN':0,
'_smallest': -1000,
'_largest': 1000
}
@@ -404,7 +404,7 @@ def between(ctest, cleft, cright):
provides similar functionality.
"""
- return _BinaryExpression(ctest, and_(_literals_as_binds(cleft, type=ctest.type), _literals_as_binds(cright, type=ctest.type)), 'BETWEEN')
+ return _BinaryExpression(ctest, ClauseList(_literals_as_binds(cleft, type=ctest.type), _literals_as_binds(cright, type=ctest.type), operator='AND', group=False), 'BETWEEN')
def between_(*args, **kwargs):
"""synonym for [sqlalchemy.sql#between()] (deprecated)."""
@@ -1352,7 +1352,7 @@ class _CompareMixin(object):
def between(self, cleft, cright):
"""produce a BETWEEN clause, i.e. ``<column> BETWEEN <cleft> AND <cright>``"""
- return _BinaryExpression(self, and_(self._check_literal(cleft), self._check_literal(cright)), 'BETWEEN')
+ return _BinaryExpression(self, ClauseList(self._check_literal(cleft), self._check_literal(cright), operator='AND', group=False), 'BETWEEN')
def op(self, operator):
"""produce a generic operator function.
@@ -1953,12 +1953,6 @@ class ClauseList(ClauseElement):
clauses = [clause.copy_container() for clause in self.clauses]
return ClauseList(operator=self.operator, *clauses)
- def self_group(self, against=None):
- if self.group:
- return _Grouping(self)
- else:
- return self
-
def append(self, clause):
# TODO: not sure if i like the 'group_contents' flag. need to define the difference between
# a ClauseList of ClauseLists, and a "flattened" ClauseList of ClauseLists. flatten() method ?
@@ -1980,7 +1974,7 @@ class ClauseList(ClauseElement):
return f
def self_group(self, against=None):
- if self.operator != against and PRECEDENCE.get(self.operator, PRECEDENCE['_smallest']) <= PRECEDENCE.get(against, PRECEDENCE['_largest']):
+ if self.group and self.operator != against and PRECEDENCE.get(self.operator, PRECEDENCE['_smallest']) <= PRECEDENCE.get(against, PRECEDENCE['_largest']):
return _Grouping(self)
else:
return self