From bd6ba3ac8274381e578c8e6c8018a7878fe94208 Mon Sep 17 00:00:00 2001 From: Lele Long Date: Sat, 3 Dec 2016 13:10:07 -0500 Subject: [PATCH] Parse (but don't record) COMMENT portion of MySQL table key The MySQL dialect now will not warn when a reflected column has a "COMMENT" keyword on it, but note however the comment is not yet reflected; this is on the roadmap for a future release. Pull request courtesy Lele Long. Fixes: #3867 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/324 Change-Id: I869e29aba6766d0eda1e59af09a3e8e3748a3942 --- doc/build/changelog/changelog_11.rst | 9 +++++++++ lib/sqlalchemy/dialects/mysql/reflection.py | 1 + test/dialect/mysql/test_reflection.py | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst index ead2925706..4c3cc949eb 100644 --- a/doc/build/changelog/changelog_11.rst +++ b/doc/build/changelog/changelog_11.rst @@ -139,6 +139,15 @@ :class:`.Engine`, concealing the URL password. Pull request courtesy Valery Yundin. + .. change:: 3867 + :tags: bug, mysql + :tickets: 3867 + + The MySQL dialect now will not warn when a reflected column has a + "COMMENT" keyword on it, but note however the comment is not yet + reflected; this is on the roadmap for a future release. Pull request + courtesy Lele Long. + .. change:: pg_timestamp_zero_prec :tags: bug, postgresql diff --git a/lib/sqlalchemy/dialects/mysql/reflection.py b/lib/sqlalchemy/dialects/mysql/reflection.py index d020fb2969..f5f09b80b3 100644 --- a/lib/sqlalchemy/dialects/mysql/reflection.py +++ b/lib/sqlalchemy/dialects/mysql/reflection.py @@ -359,6 +359,7 @@ class MySQLTableDefinitionParser(object): r'(?: +USING +(?P\S+))?' r'(?: +KEY_BLOCK_SIZE *[ =]? *(?P\S+))?' r'(?: +WITH PARSER +(?P\S+))?' + r'(?: +COMMENT +(?P(\x27\x27|\x27([^\x27])*?\x27)+))?' r',?$' % quotes ) diff --git a/test/dialect/mysql/test_reflection.py b/test/dialect/mysql/test_reflection.py index ddf1581678..2ccb299bc5 100644 --- a/test/dialect/mysql/test_reflection.py +++ b/test/dialect/mysql/test_reflection.py @@ -552,6 +552,18 @@ class RawReflectionTest(fixtures.TestBase): ' PRIMARY KEY (`id`) USING BTREE KEY_BLOCK_SIZE = 16') assert not regex.match( ' PRIMARY KEY (`id`) USING BTREE KEY_BLOCK_SIZE = = 16') + assert regex.match( + " KEY (`id`) USING BTREE COMMENT 'comment'") + # `SHOW CREATE TABLE` returns COMMENT '''comment' + # after creating table with COMMENT '\'comment' + assert regex.match( + " KEY (`id`) USING BTREE COMMENT '''comment'") + assert regex.match( + " KEY (`id`) USING BTREE COMMENT 'comment'''") + assert regex.match( + " KEY (`id`) USING BTREE COMMENT 'prefix''suffix'") + assert regex.match( + " KEY (`id`) USING BTREE COMMENT 'prefix''text''suffix'") def test_fk_reflection(self): regex = self.parser._re_constraint -- 2.47.3