as :class:`.TypeDecorator` objects.
series as well. For changes that are specific to 1.0 with an emphasis
on compatibility concerns, see :doc:`/changelog/migration_10`.
+ .. change::
+ :tags: bug, mysql
+
+ The MySQL dialect now supports CAST on types that are constructed
+ as :class:`.TypeDecorator` objects.
+
.. change::
:tags: bug, mysql
:tickets: 3237
def get_from_hint_text(self, table, text):
return text
- def visit_typeclause(self, typeclause):
- type_ = typeclause.type.dialect_impl(self.dialect)
- if isinstance(type_, sqltypes.Integer):
+ def visit_typeclause(self, typeclause, type_=None):
+ if type_ is None:
+ type_ = typeclause.type.dialect_impl(self.dialect)
+ if isinstance(type_, sqltypes.TypeDecorator):
+ return self.visit_typeclause(typeclause, type_.impl)
+ elif isinstance(type_, sqltypes.Integer):
if getattr(type_, 'unsigned', False):
return 'UNSIGNED INTEGER'
else:
(m.MSVarBinary, "CAST(t.col AS BINARY)"),
(m.MSVarBinary(32), "CAST(t.col AS BINARY)"),
+ (Interval, "CAST(t.col AS DATETIME)"),
+
]
for type_, expected in specs:
self.assert_compile(cast(t.c.col, type_), expected)
+ def test_cast_type_decorator(self):
+ class MyInteger(sqltypes.TypeDecorator):
+ impl = Integer
+
+ type_ = MyInteger()
+ t = sql.table('t', sql.column('col'))
+ self.assert_compile(
+ cast(t.c.col, type_), "CAST(t.col AS SIGNED INTEGER)")
+
def test_unsupported_casts(self):
t = sql.table('t', sql.column('col'))
(m.MSYear, "t.col"),
(m.MSYear(2), "t.col"),
- (Interval, "t.col"),
(Boolean, "t.col"),
(BOOLEAN, "t.col"),