From: Mike Bayer Date: Tue, 9 Sep 2008 15:54:10 +0000 (+0000) Subject: - Bind params now subclass ColumnElement which allows them to be X-Git-Tag: rel_0_5rc1~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b724ae1ccefd0b8db516877b58a3411803e44ad;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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 --- diff --git a/CHANGES b/CHANGES index 98c81348a3..89b7355237 100644 --- 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, diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 9b24f7930b..f7fc5f9617 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 4958e4812a..a7243f2794 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 6ca2a2542d..0849d1a7b7 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 18f4b91dda..cff8a9d331 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):