summaryrefslogtreecommitdiff
path: root/test/dialect/mysql/test_compiler.py
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2020-12-30 20:36:27 +0100
committerFederico Caselli <cfederico87@gmail.com>2020-12-30 22:26:23 +0100
commit95d8f401839bdbe1399fb7d656c11024072f32b0 (patch)
tree94b8b2c3a8ed0d4fa419fe94558e87782af0d29f /test/dialect/mysql/test_compiler.py
parente8507b21ec5e4420fbb6f0df8a14ee33501e26cd (diff)
downloadsqlalchemy-95d8f401839bdbe1399fb7d656c11024072f32b0.tar.gz
Support casting to ``FLOAT`` in MySQL and MariaDb.
Fixes: #5808 Change-Id: I8106ddcf681eec3cb3a67d853586702f6e844b9d
Diffstat (limited to 'test/dialect/mysql/test_compiler.py')
-rw-r--r--test/dialect/mysql/test_compiler.py32
1 files changed, 29 insertions, 3 deletions
diff --git a/test/dialect/mysql/test_compiler.py b/test/dialect/mysql/test_compiler.py
index 2993f96b8..62292b9da 100644
--- a/test/dialect/mysql/test_compiler.py
+++ b/test/dialect/mysql/test_compiler.py
@@ -710,7 +710,9 @@ class SQLTest(fixtures.TestBase, AssertsCompiledSQL):
def test_unsupported_cast_literal_bind(self):
expr = cast(column("foo", Integer) + 5, Float)
- with expect_warnings("Datatype FLOAT does not support CAST on MySQL;"):
+ with expect_warnings(
+ "Datatype FLOAT does not support CAST on MySQL/MariaDb;"
+ ):
self.assert_compile(expr, "(foo + 5)", literal_binds=True)
m = mysql
@@ -734,11 +736,35 @@ class SQLTest(fixtures.TestBase, AssertsCompiledSQL):
def test_unsupported_casts(self, type_, expected):
t = sql.table("t", sql.column("col"))
- with expect_warnings("Datatype .* does not support CAST on MySQL;"):
+ with expect_warnings(
+ "Datatype .* does not support CAST on MySQL/MariaDb;"
+ ):
self.assert_compile(cast(t.c.col, type_), expected)
+ @testing.combinations(
+ (m.FLOAT, "CAST(t.col AS FLOAT)"),
+ (Float, "CAST(t.col AS FLOAT)"),
+ (FLOAT, "CAST(t.col AS FLOAT)"),
+ (m.DOUBLE, "CAST(t.col AS DOUBLE)"),
+ (m.FLOAT, "CAST(t.col AS FLOAT)"),
+ argnames="type_,expected",
+ )
+ @testing.combinations(True, False, argnames="maria_db")
+ def test_float_cast(self, type_, expected, maria_db):
+
+ dialect = mysql.dialect()
+ if maria_db:
+ dialect.is_mariadb = maria_db
+ dialect.server_version_info = (10, 4, 5)
+ else:
+ dialect.server_version_info = (8, 0, 17)
+ t = sql.table("t", sql.column("col"))
+ self.assert_compile(cast(t.c.col, type_), expected, dialect=dialect)
+
def test_cast_grouped_expression_non_castable(self):
- with expect_warnings("Datatype FLOAT does not support CAST on MySQL;"):
+ with expect_warnings(
+ "Datatype FLOAT does not support CAST on MySQL/MariaDb;"
+ ):
self.assert_compile(
cast(sql.column("x") + sql.column("y"), Float), "(x + y)"
)