determined.
- sql
+ - Fixed missing _label attribute on Function object, others
+ when used in a select() with use_labels (such as when used
+ in an ORM column_property()). [ticket:1302]
+
- the __selectable__() interface has been replaced entirely
by __clause_element__().
if not isinstance(column, sql.ColumnElement):
raise sa_exc.InvalidRequestError("Invalid column expression '%r'" % column)
- if not hasattr(column, '_label'):
+ # if the Column is unnamed, give it a
+ # label() so that mutable column expressions
+ # can be located in the result even
+ # if the expression's identity has been changed
+ # due to adaption
+ if not column._label:
column = column.label(None)
query._entities.append(self)
primary_key = False
foreign_keys = []
quote = None
-
+ _label = None
+
@property
def _select_iterable(self):
return (self, )
GenericFunction.__init__(self, args=[arg], **kwargs)
self.assert_compile(fake_func('foo'), "fake_func(%s)" % bindtemplate % {'name':'param_1', 'position':1}, dialect=dialect)
-
+
+ def test_use_labels(self):
+ self.assert_compile(select([func.foo()], use_labels=True),
+ "SELECT foo() AS foo_1"
+ )
def test_underscores(self):
self.assert_compile(func.if_(), "if()")
select([ClauseList(column('a'), column('b'))]).select_from('sometable'),
'SELECT a, b FROM sometable'
)
+
+ def test_use_labels(self):
+ self.assert_compile(
+ select([table1.c.myid==5], use_labels=True),
+ "SELECT mytable.myid = :myid_1 AS anon_1 FROM mytable"
+ )
+
+ self.assert_compile(
+ select([func.foo()], use_labels=True),
+ "SELECT foo() AS foo_1"
+ )
+
+ self.assert_compile(
+ select([not_(True)], use_labels=True),
+ "SELECT NOT :param_1" # TODO: should this make an anon label ??
+ )
+
+ self.assert_compile(
+ select([cast("data", sqlite.SLInteger)], use_labels=True), # this will work with plain Integer in 0.6
+ "SELECT CAST(:param_1 AS INTEGER) AS anon_1"
+ )
+
+
+
def test_nested_uselabels(self):
"""test nested anonymous label generation. this
essentially tests the ANONYMOUS_LABEL regex.