]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- _Label class overrides compare_self to return its ultimate object.
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 3 May 2007 22:31:52 +0000 (22:31 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 3 May 2007 22:31:52 +0000 (22:31 +0000)
meaning, if you say someexpr.label('foo') == 5, it produces
the correct "someexpr == 5".

CHANGES
lib/sqlalchemy/sql.py
test/sql/select.py

diff --git a/CHANGES b/CHANGES
index c507c202ecdb2c3a88593e60918b33b311739035..d1c0df454208fa9d702e2f2fa0db61117d8c9457 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -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.
index fe987cc11ec33eb9ea78cf8ee4f778c236b9b7e2..0dcba3698d9f4fd8d7a056bde8b446e5cf0490e9 100644 (file)
@@ -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,
index c10f12c2c61cecd8cd9526176f1fd1e3d24ff9f2..ccd5c33a8ab667847605716bb691fa70f58cd535 100644 (file)
@@ -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()")),