diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-05-03 22:31:52 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2007-05-03 22:31:52 +0000 |
| commit | 752ef2802c57d32fe832b76b9503f42f0300da05 (patch) | |
| tree | 4399442fe946dbaec6386c5f9b5a997a7e63bd8b | |
| parent | 76a1d1276c48cb7f3eb4186d8872b1d7915d360a (diff) | |
| download | sqlalchemy-752ef2802c57d32fe832b76b9503f42f0300da05.tar.gz | |
- _Label class overrides compare_self to return its ultimate object.
meaning, if you say someexpr.label('foo') == 5, it produces
the correct "someexpr == 5".
| -rw-r--r-- | CHANGES | 4 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql.py | 3 | ||||
| -rw-r--r-- | test/sql/select.py | 6 |
3 files changed, 12 insertions, 1 deletions
@@ -1,3 +1,7 @@ +- sql + - _Label class overrides compare_self to return its ultimate object. + meaning, if you say someexpr.label('foo') == 5, it produces + the correct "someexpr == 5". - mysql - support for column-level CHARACTER SET and COLLATE declarations, as well as ASCII, UNICODE, NATIONAL and BINARY shorthand. diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py index fe987cc11..0dcba3698 100644 --- a/lib/sqlalchemy/sql.py +++ b/lib/sqlalchemy/sql.py @@ -2380,6 +2380,9 @@ class _Label(ColumnElement): key = property(lambda s: s.name) _label = property(lambda s: s.name) orig_set = property(lambda s:s.obj.orig_set) + + def _compare_self(self): + return self.obj def get_children(self, **kwargs): return self.obj, diff --git a/test/sql/select.py b/test/sql/select.py index c10f12c2c..ccd5c33a8 100644 --- a/test/sql/select.py +++ b/test/sql/select.py @@ -218,7 +218,11 @@ sq.myothertable_othername AS sq_myothertable_othername FROM (" + sqstring + ") A order_by = ['dist', places.c.nm] ) self.runtest(q, "SELECT places.id, places.nm, main_zip.zipcode, latlondist((SELECT zips.latitude FROM zips WHERE zips.zipcode = main_zip.zipcode), (SELECT zips.longitude FROM zips WHERE zips.zipcode = main_zip.zipcode)) AS dist FROM places, zips AS main_zip ORDER BY dist, places.nm") - + + def testlabelcomparison(self): + x = func.lala(table1.c.myid).label('foo') + self.runtest(select([x], x==5), "SELECT lala(mytable.myid) AS foo FROM mytable WHERE lala(mytable.myid) = :literal") + def testand(self): self.runtest( select(['*'], and_(table1.c.myid == 12, table1.c.name=='asdf', table2.c.othername == 'foo', "sysdate() = today()")), |
