Skip to content

Commit df5a308

Browse files
authored
Handle comment column name correctly (#198)
1 parent 71f446f commit df5a308

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

mysql_ch_replicator/converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ def _strip_comments(self, create_statement):
10851085
# Look for COMMENT keyword (case insensitive)
10861086
if (i + 7 < len(create_statement) and
10871087
create_statement[i:i+7].upper() == 'COMMENT' and
1088-
(i == 0 or not create_statement[i-1].isalnum()) and
1088+
(i == 0 or (not create_statement[i-1].isalnum() and create_statement[i-1] != '`')) and
10891089
(i + 7 >= len(create_statement) or not create_statement[i+7].isalnum())):
10901090

10911091
# Skip COMMENT keyword

test_mysql_ch_replicator.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3314,6 +3314,21 @@ def test_charset_configuration():
33143314
"CREATE TABLE test (id int comment 'lowercase', name varchar(255) Comment 'Mixed case')",
33153315
"CREATE TABLE test (id int , name varchar(255) )"
33163316
),
3317+
# Field named comment
3318+
(
3319+
"""CREATE TABLE test (
3320+
`departments int(11) NOT NULL,
3321+
`termine int(11) NOT NULL,
3322+
`comment` varchar(120) DEFAULT NULL,
3323+
PRIMARY KEY (departments,termine)
3324+
)""",
3325+
"""CREATE TABLE test (
3326+
`departments int(11) NOT NULL,
3327+
`termine int(11) NOT NULL,
3328+
`comment` varchar(120) DEFAULT NULL,
3329+
PRIMARY KEY (departments,termine)
3330+
)"""
3331+
),
33173332
])
33183333
def test_strip_comments_function(input_sql, expected_output):
33193334
"""

0 commit comments

Comments
 (0)