diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-09-08 22:50:37 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-09-08 22:50:37 +0000 |
commit | e158234478f3bb17ec90e5dc5a125d0207d2d5fe (patch) | |
tree | 5eb6c9af9dea8e5b404a10513f1283b4bb7a14e0 /lib/sqlalchemy/sql/expression.py | |
parent | bf71da5ee6961e4ce67d079651b38f414e641ac7 (diff) | |
download | sqlalchemy-e158234478f3bb17ec90e5dc5a125d0207d2d5fe.tar.gz |
- The exists() construct won't "export" its contained list
of elements as FROM clauses, allowing them to be used more
effectively in the columns clause of a SELECT.
- and_() and or_() now generate a ColumnElement, allowing
boolean expressions as result columns, i.e.
select([and_(1, 0)]). [ticket:798]
Diffstat (limited to 'lib/sqlalchemy/sql/expression.py')
-rw-r--r-- | lib/sqlalchemy/sql/expression.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 899c6285a..9b24f7930 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -372,7 +372,7 @@ def and_(*clauses): """ if len(clauses) == 1: return clauses[0] - return ClauseList(operator=operators.and_, *clauses) + return BooleanClauseList(operator=operators.and_, *clauses) def or_(*clauses): """Join a list of clauses together using the ``OR`` operator. @@ -384,7 +384,7 @@ def or_(*clauses): if len(clauses) == 1: return clauses[0] - return ClauseList(operator=operators.or_, *clauses) + return BooleanClauseList(operator=operators.or_, *clauses) def not_(clause): """Return a negation of the given clause, i.e. ``NOT(clause)``. @@ -1993,6 +1993,7 @@ class ClauseList(ClauseElement): """Describe a list of clauses, separated by an operator. By default, is comma-separated, such as a column listing. + """ __visit_name__ = 'clauselist' @@ -2052,6 +2053,16 @@ class ClauseList(ClauseElement): else: return False +class BooleanClauseList(ClauseList, ColumnElement): + __visit_name__ = 'clauselist' + + def __init__(self, *clauses, **kwargs): + super(BooleanClauseList, self).__init__(*clauses, **kwargs) + self.type = sqltypes.to_instance(kwargs.get('type_', sqltypes.Boolean)) + + def self_group(self, against=None): + return _Grouping(self) + class _CalculatedClause(ColumnElement): """Describe a calculated SQL expression that has a type, like ``CASE``. @@ -2277,6 +2288,9 @@ class _Exists(_UnaryExpression): e.element = self.element.correlate(fromclause).self_group() return e + def _get_from_objects(self, **modifiers): + return [] + def where(self, clause): """return a new exists() construct with the given expression added to its WHERE clause, joined to the existing clause via AND, if any.""" |