diff options
-rw-r--r-- | CHANGES | 7 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/expression.py | 11 | ||||
-rw-r--r-- | lib/sqlalchemy/types.py | 1 | ||||
-rw-r--r-- | test/sql/query.py | 5 | ||||
-rw-r--r-- | test/sql/select.py | 1 |
5 files changed, 19 insertions, 6 deletions
@@ -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, diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 9b24f7930..f7fc5f961 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -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.""" diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index 4958e4812..a7243f279 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -625,6 +625,7 @@ type_map = { unicode : NCHAR, int : Integer, float : Numeric, + bool: Boolean, _python_Decimal : Numeric, dt.date : Date, dt.datetime : DateTime, diff --git a/test/sql/query.py b/test/sql/query.py index 6ca2a2542..0849d1a7b 100644 --- a/test/sql/query.py +++ b/test/sql/query.py @@ -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) diff --git a/test/sql/select.py b/test/sql/select.py index 18f4b91dd..cff8a9d33 100644 --- a/test/sql/select.py +++ b/test/sql/select.py @@ -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): |