]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- changed "BooleanExpression" to subclass from "BinaryExpression", so that boolean
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 19 Jan 2007 20:32:13 +0000 (20:32 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 19 Jan 2007 20:32:13 +0000 (20:32 +0000)
expressions can also follow column-clause behaviors (i.e. label(), etc).
- query.select() had to become more picky about what it considers to be a full "selectable"
and what it considers to be a fragment that represents a WHERE criterion - looks for the presence
of a FromClause now (which is still pretty liberal, since i originally intended the check to be
for select() only).  the previous exception-catch method also added a little stack tracing
overhead anyway.

CHANGES
lib/sqlalchemy/orm/query.py
lib/sqlalchemy/sql.py

diff --git a/CHANGES b/CHANGES
index fe16a2acc54af8f4af799654b6c1db3cc74af9fa..1f8c26d7bf95e62d2d3a763d5cb6140bd0199d08 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,8 @@
   non-ambiguous.
 - sql:
   - added "fetchmany()" support to ResultProxy
+  - changed "BooleanExpression" to subclass from "BinaryExpression", so that boolean
+  expressions can also follow column-clause behaviors (i.e. label(), etc).
   - fix to correlation of subqueries when the column list of the select statement
   is constructed with individual calls to append_column(); this fixes an ORM
   bug whereby nested select statements were not getting correlated with the 
index 5d82b594f0d042c452725a572fc9aa9af2a66af1..ce2f78bb73ecdef2f83bc58ad1e62482d76e186b 100644 (file)
@@ -241,12 +241,10 @@ class Query(object):
         ret = self.extension.select(self, arg=arg, **kwargs)
         if ret is not mapper.EXT_PASS:
             return ret
-        try:
-            s = arg._selectable()
-        except AttributeError:
-            return self.select_whereclause(whereclause=arg, **kwargs)
+        if isinstance(arg, sql.FromClause):
+            return self.select_statement(arg, **kwargs)
         else:
-            return self.select_statement(s, **kwargs)
+            return self.select_whereclause(whereclause=arg, **kwargs)
 
     def select_whereclause(self, whereclause=None, params=None, **kwargs):
         """given a WHERE criterion, create a SELECT statement, execute and return the resulting instances."""
index dbd119fd1ef32946a966ae634e3b3cb6e6ef1fc4..e0bae905a0f7ac822d10b127b61d15ae7079fa17 100644 (file)
@@ -1076,8 +1076,14 @@ class _BinaryClause(ClauseElement):
             self.left.compare(other.left) and self.right.compare(other.right)
         )
 
-class _BooleanExpression(_BinaryClause):
-    """represents a boolean expression, which is only useable in WHERE criterion."""
+class _BinaryExpression(_BinaryClause, ColumnElement):
+    """represents a binary expression, which can be in a WHERE criterion or in the column list 
+    of a SELECT.  By adding "ColumnElement" to its inherited list, it becomes a Selectable
+    unit which can be placed in the column list of a SELECT."""
+    pass
+
+class _BooleanExpression(_BinaryExpression):
+    """represents a boolean expression."""
     def __init__(self, *args, **kwargs):
         self.negate = kwargs.pop('negate', None)
         super(_BooleanExpression, self).__init__(*args, **kwargs)
@@ -1087,13 +1093,6 @@ class _BooleanExpression(_BinaryClause):
         else:
             return super(_BooleanExpression, self)._negate()
         
-class _BinaryExpression(_BinaryClause, ColumnElement):
-    """represents a binary expression, which can be in a WHERE criterion or in the column list 
-    of a SELECT.  By adding "ColumnElement" to its inherited list, it becomes a Selectable
-    unit which can be placed in the column list of a SELECT."""
-    pass
-    
-        
 class Join(FromClause):
     def __init__(self, left, right, onclause=None, isouter = False):
         self.left = left._selectable()