From: Mike Bayer Date: Sat, 19 Jun 2010 17:21:19 +0000 (-0400) Subject: - MySQL dialect doesn't emit CAST() for MySQL version X-Git-Tag: rel_0_6_2~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=17073a015546f9fe0ce09e668e9e318269c09a2a;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - MySQL dialect doesn't emit CAST() for MySQL version detected < 4.0.2. This allows the unicode check on connect to proceed. [ticket:1826] --- diff --git a/CHANGES b/CHANGES index a1013546ee..8d1b3207db 100644 --- a/CHANGES +++ b/CHANGES @@ -77,6 +77,11 @@ CHANGES - Column.copy() takes along the "unique" attribute among others, fixes [ticket:1829] regarding declarative mixins + +- mysql + - MySQL dialect doesn't emit CAST() for MySQL version + detected < 4.0.2. This allows the unicode + check on connect to proceed. [ticket:1826] - firebird - Fixed incorrect signature in do_execute(), error diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 179e0c76d8..c4af013fc2 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -1187,6 +1187,9 @@ class MySQLCompiler(compiler.SQLCompiler): def visit_cast(self, cast, **kwargs): # No cast until 4, no decimals until 5. + if not self.dialect._supports_cast: + return self.process(cast.clause) + type_ = self.process(cast.typeclause) if type_ is None: return self.process(cast.clause) @@ -1761,8 +1764,14 @@ class MySQLDialect(default.DefaultDialect): if self._server_ansiquotes: # if ansiquotes == True, build a new IdentifierPreparer # with the new setting - self.identifier_preparer = self.preparer(self, server_ansiquotes=self._server_ansiquotes) + self.identifier_preparer = self.preparer(self, + server_ansiquotes=self._server_ansiquotes) + @property + def _supports_cast(self): + return self.server_version_info is None or \ + self.server_version_info >= (4, 0, 2) + @reflection.cache def get_schema_names(self, connection, **kw): rp = connection.execute("SHOW schemas") diff --git a/test/dialect/test_mysql.py b/test/dialect/test_mysql.py index f61af42381..f41f062095 100644 --- a/test/dialect/test_mysql.py +++ b/test/dialect/test_mysql.py @@ -1162,7 +1162,20 @@ class SQLTest(TestBase, AssertsCompiledSQL): for type_, expected in specs: self.assert_compile(cast(t.c.col, type_), expected) - + + def test_no_cast_pre_4(self): + self.assert_compile( + cast(Column('foo', Integer), String), + "CAST(foo AS CHAR)", + ) + dialect = mysql.dialect() + dialect.server_version_info = (3, 2, 3) + self.assert_compile( + cast(Column('foo', Integer), String), + "foo", + dialect=dialect + ) + def test_extract(self): t = sql.table('t', sql.column('col1'))