]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- the label() method on ColumnElement will properly propigate the
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 29 Apr 2007 21:33:05 +0000 (21:33 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 29 Apr 2007 21:33:05 +0000 (21:33 +0000)
TypeEngine of the base element out to the label, including a label()
created from a scalar=True select() statement.

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

diff --git a/CHANGES b/CHANGES
index ea7e68d6c660a1669526e27bdb76c2917e517349..2932a76a4c29627b2a34c16052c4d9dd09bc5384 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -60,6 +60,9 @@
       are to work around glitchy SQLite behavior that doesnt understand
       "foo.id" as equivalent to "id", are now only generated in the case 
       that those named columns are selected from (part of [ticket:513])
+    - the label() method on ColumnElement will properly propigate the
+      TypeEngine of the base element out to the label, including a label()
+      created from a scalar=True select() statement.
     - MS-SQL better detects when a query is a subquery and knows not to
       generate ORDER BY phrases for those [ticket:513]
     - fix for fetchmany() "size" argument being positional in most
index 988366617fb05af7a9c8c4a100963c188a5c5653..a7ca55e31510368898527ad92b8518bb14785f10 100644 (file)
@@ -2360,7 +2360,7 @@ class _Label(ColumnElement):
             obj = obj.obj
         self.obj = obj
         self.case_sensitive = getattr(obj, "case_sensitive", True)
-        self.type = sqltypes.to_instance(type)
+        self.type = sqltypes.to_instance(type or getattr(obj, 'type', None))
         obj.parens=True
 
     key = property(lambda s: s.name)
index 53022a6a02a900b1256f378932e2f85e8315b3f9..d69a67ef4f200e1caec5cdfdd89d040515478ed5 100644 (file)
@@ -5,6 +5,15 @@ from sqlalchemy import *
 # TODO: either create a mock dialect with named paramstyle and a short identifier length,
 # or find a way to just use sqlite dialect and make those changes
 
+class LabelTypeTest(testbase.PersistTest):
+    def test_type(self):
+        m = MetaData()
+        t = Table('sometable', m, 
+            Column('col1', Integer),
+            Column('col2', Float))
+        assert isinstance(t.c.col1.label('hi').type, Integer)
+        assert isinstance(select([t.c.col2], scalar=True).label('lala').type, Float)
+
 class LongLabelsTest(testbase.PersistTest):
     def setUpAll(self):
         global metadata, table1