Commits

Mike Bayer committed cb77bf7

- Bind params now subclass ColumnElement which allows them to be
selectable by orm.query (they already had most ColumnElement
semantics).

- Added select_from() method to exists() construct, which becomes
more and more compatible with a regular select().

- Bind parameters/literals given a True/False value will detect
their type as Boolean

  • Participants
  • Parent commits a095e4e

Comments (0)

Files changed (5)

       boolean expressions as result columns, i.e.
       select([and_(1, 0)]).  [ticket:798]
     
+    - Bind params now subclass ColumnElement which allows them to be
+      selectable by orm.query (they already had most ColumnElement
+      semantics).
+      
+    - Added select_from() method to exists() construct, which becomes
+      more and more compatible with a regular select().
+      
     - Added func.min(), func.max(), func.sum() as "generic functions",
       which basically allows for their return type to be determined
       automatically.  Helps with dates on SQLite, decimal types, 

File lib/sqlalchemy/sql/expression.py

     def _populate_column_collection(self):
         pass
 
-class _BindParamClause(ClauseElement, _CompareMixin):
+class _BindParamClause(ColumnElement):
     """Represent a bind parameter.
 
     Public constructor is the ``bindparam()`` function.
             self.type = type_()
         else:
             self.type = type_
-
+    
     def _clone(self):
         c = ClauseElement._clone(self)
         if self.unique:
     def _get_from_objects(self, **modifiers):
         return []
 
+    def select_from(self, clause):
+        """return a new exists() construct with the given expression set as its FROM clause."""
+    
+        e = self._clone()
+        e.element = self.element.select_from(clause).self_group()
+        return e
+        
     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."""

File lib/sqlalchemy/types.py

     unicode : NCHAR,
     int : Integer,
     float : Numeric,
+    bool: Boolean,
     _python_Decimal : Numeric,
     dt.date : Date,
     dt.datetime : DateTime,

File test/sql/query.py

         self.assert_(not (equal != equal))
 
     def test_or_and_as_columns(self):
-        if testing.against('sqlite'):
-            true, false = 1, 0
-        else:
-            true, false = literal_column('true'), literal_column('false')
+        true, false = literal(True), literal(False)
         
         self.assertEquals(testing.db.execute(select([and_(true, false)])).scalar(), False)
         self.assertEquals(testing.db.execute(select([and_(true, true)])).scalar(), True)

File test/sql/select.py

 
         s = select([t, literal('lala').label('hoho')])
         self.assert_compile(s, "SELECT foo.id, :param_1 AS hoho FROM foo")
+        
         assert [str(c) for c in s.c] == ["id", "hoho"]
 
     def test_in(self):