summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-04-29 21:33:05 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-04-29 21:33:05 +0000
commit8d5a0729abff9fe4ac86f49d810564037a68b0e3 (patch)
tree5107f342b6bd5221e5e8c487fc672d009db0c998
parent05f1e509518f62d2cdf8cc697e5bf6d4108df432 (diff)
downloadsqlalchemy-8d5a0729abff9fe4ac86f49d810564037a68b0e3.tar.gz
- 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.
-rw-r--r--CHANGES3
-rw-r--r--lib/sqlalchemy/sql.py2
-rw-r--r--test/sql/labels.py9
3 files changed, 13 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index ea7e68d6c..2932a76a4 100644
--- 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
diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py
index 988366617..a7ca55e31 100644
--- a/lib/sqlalchemy/sql.py
+++ b/lib/sqlalchemy/sql.py
@@ -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)
diff --git a/test/sql/labels.py b/test/sql/labels.py
index 53022a6a0..d69a67ef4 100644
--- a/test/sql/labels.py
+++ b/test/sql/labels.py
@@ -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