]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Parse (but don't record) COMMENT portion of MySQL table key
authorLele Long <schemacs@gmail.com>
Sat, 3 Dec 2016 18:10:07 +0000 (13:10 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 17 Jan 2017 15:23:07 +0000 (10:23 -0500)
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
lib/sqlalchemy/dialects/mysql/reflection.py
test/dialect/mysql/test_reflection.py

index ead292570654037152fac41145923fe01dfab9a0..4c3cc949eb89939c2d63dadc9ed5c2f2f750e129 100644 (file)
         :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
 
index d020fb2969685d49d9ffdff6f6ba07fcd7797ac1..f5f09b80b38265d4a9cf95154b31063eb5b30ba7 100644 (file)
@@ -359,6 +359,7 @@ class MySQLTableDefinitionParser(object):
             r'(?: +USING +(?P<using_post>\S+))?'
             r'(?: +KEY_BLOCK_SIZE *[ =]? *(?P<keyblock>\S+))?'
             r'(?: +WITH PARSER +(?P<parser>\S+))?'
+            r'(?: +COMMENT +(?P<comment>(\x27\x27|\x27([^\x27])*?\x27)+))?'
             r',?$'
             % quotes
         )
index ddf15816785a894915f40bc2e5f6a124b0632da3..2ccb299bc5d08cfb3942e05eeab4ee68aca9519e 100644 (file)
@@ -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