From: Mike Bayer Date: Mon, 13 Nov 2017 14:21:48 +0000 (-0500) Subject: Propagate kwargs for mysql concat, match X-Git-Tag: rel_1_2_0~26 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4f054550b768985f1c3393e46e0fc26bfefeeaf6;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Propagate kwargs for mysql concat, match Fixed bug where the MySQL "concat" and "match" operators failed to propagate kwargs to the left and right expressions, causing compiler options such as "literal_binds" to fail. Also adds non-interpreted **kw for visit_create_index, visit_typeclause Change-Id: Iaf54ac18949cc6a54f50678125f010b4f12c5673 Fixes: #4136 --- diff --git a/doc/build/changelog/unreleased_11/ticket_4136.rst b/doc/build/changelog/unreleased_11/ticket_4136.rst new file mode 100644 index 0000000000..fa0e084763 --- /dev/null +++ b/doc/build/changelog/unreleased_11/ticket_4136.rst @@ -0,0 +1,8 @@ +.. change:: + :tags: bug, mysql + :tickets: 4136 + :versions: 1.2.0b4 + + Fixed bug where the MySQL "concat" and "match" operators failed to + propagate kwargs to the left and right expressions, causing compiler + options such as "literal_binds" to fail. \ No newline at end of file diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 2aaeacb194..bee62b76f9 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -941,21 +941,21 @@ class MySQLCompiler(compiler.SQLCompiler): return 'ON DUPLICATE KEY UPDATE ' + ', '.join(clauses) def visit_concat_op_binary(self, binary, operator, **kw): - return "concat(%s, %s)" % (self.process(binary.left), - self.process(binary.right)) + return "concat(%s, %s)" % (self.process(binary.left, **kw), + self.process(binary.right, **kw)) def visit_match_op_binary(self, binary, operator, **kw): return "MATCH (%s) AGAINST (%s IN BOOLEAN MODE)" % \ - (self.process(binary.left), self.process(binary.right)) + (self.process(binary.left, **kw), self.process(binary.right, **kw)) def get_from_hint_text(self, table, text): return text - def visit_typeclause(self, typeclause, type_=None): + def visit_typeclause(self, typeclause, type_=None, **kw): if type_ is None: type_ = typeclause.type.dialect_impl(self.dialect) if isinstance(type_, sqltypes.TypeDecorator): - return self.visit_typeclause(typeclause, type_.impl) + return self.visit_typeclause(typeclause, type_.impl, **kw) elif isinstance(type_, sqltypes.Integer): if getattr(type_, 'unsigned', False): return 'UNSIGNED INTEGER' @@ -1208,7 +1208,7 @@ class MySQLDDLCompiler(compiler.DDLCompiler): return ' '.join(table_opts) - def visit_create_index(self, create): + def visit_create_index(self, create, **kw): index = create.element self._verify_index_table(index) preparer = self.preparer @@ -1225,7 +1225,7 @@ class MySQLDDLCompiler(compiler.DDLCompiler): index_prefix = index.kwargs.get('mysql_prefix', None) if index_prefix: - text += index_prefix + ' ' + text += index_prefix + ' ' text += "INDEX %s ON %s " % (name, table) diff --git a/test/dialect/mysql/test_compiler.py b/test/dialect/mysql/test_compiler.py index e8731e5329..cebbfc8968 100644 --- a/test/dialect/mysql/test_compiler.py +++ b/test/dialect/mysql/test_compiler.py @@ -8,7 +8,7 @@ from sqlalchemy import Table, MetaData, Column, select, String, \ NUMERIC, DECIMAL, Numeric, Float, FLOAT, TIMESTAMP, DATE, \ DATETIME, TIME, \ DateTime, Time, Date, Interval, NCHAR, CHAR, CLOB, TEXT, Boolean, \ - BOOLEAN, LargeBinary, BLOB, SmallInteger, INT, func, cast + BOOLEAN, LargeBinary, BLOB, SmallInteger, INT, func, cast, literal from sqlalchemy.dialects.mysql import insert from sqlalchemy.dialects.mysql import base as mysql @@ -202,6 +202,22 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): matchtable.c.title.match('somstr'), "MATCH (matchtable.title) AGAINST (%s IN BOOLEAN MODE)") + def test_match_compile_kw(self): + expr = literal('x').match(literal('y')) + self.assert_compile( + expr, + "MATCH ('x') AGAINST ('y' IN BOOLEAN MODE)", + literal_binds=True + ) + + def test_concat_compile_kw(self): + expr = literal('x', type_=String) + literal('y', type_=String) + self.assert_compile( + expr, + "concat('x', 'y')", + literal_binds=True + ) + def test_for_update(self): table1 = table('mytable', column('myid'), column('name'), column('description'))