]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Bind params now subclass ColumnElement which allows them to be
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 9 Sep 2008 15:54:10 +0000 (15:54 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 9 Sep 2008 15:54:10 +0000 (15:54 +0000)
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

CHANGES
lib/sqlalchemy/sql/expression.py
lib/sqlalchemy/types.py
test/sql/query.py
test/sql/select.py

diff --git a/CHANGES b/CHANGES
index 98c81348a325ed217c7c1e71f92460a042205fb4..89b7355237420bc55454df7d4e8457ab8b8b6677 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -157,6 +157,13 @@ CHANGES
       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, 
index 9b24f7930b2b8399bf0066dddd989cfd55d30b4f..f7fc5f9617cb314846ad550ac352adaed2a96902 100644 (file)
@@ -1814,7 +1814,7 @@ class FromClause(Selectable):
     def _populate_column_collection(self):
         pass
 
-class _BindParamClause(ClauseElement, _CompareMixin):
+class _BindParamClause(ColumnElement):
     """Represent a bind parameter.
 
     Public constructor is the ``bindparam()`` function.
@@ -1874,7 +1874,7 @@ class _BindParamClause(ClauseElement, _CompareMixin):
             self.type = type_()
         else:
             self.type = type_
-
+    
     def _clone(self):
         c = ClauseElement._clone(self)
         if self.unique:
@@ -2291,6 +2291,13 @@ class _Exists(_UnaryExpression):
     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."""
index 4958e4812a21f4bc0502be9e43c09ce3432f94ef..a7243f279460af36c228c13a28d9880491bf6e2b 100644 (file)
@@ -625,6 +625,7 @@ type_map = {
     unicode : NCHAR,
     int : Integer,
     float : Numeric,
+    bool: Boolean,
     _python_Decimal : Numeric,
     dt.date : Date,
     dt.datetime : DateTime,
index 6ca2a2542dc4f23dbda181e8bf05bb8b495483e3..0849d1a7b7b7a79d94fe404acc550875a934500a 100644 (file)
@@ -201,10 +201,7 @@ class QueryTest(TestBase):
         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)
index 18f4b91dda6f0bb07075b919cf047fed56b374fe..cff8a9d3313fd604c64aa9ae48a993c233271802 100644 (file)
@@ -1097,6 +1097,7 @@ UNION SELECT mytable.myid FROM mytable"
 
         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):