diff --git a/mysql_ch_replicator/converter.py b/mysql_ch_replicator/converter.py index 34440c7..f659f18 100644 --- a/mysql_ch_replicator/converter.py +++ b/mysql_ch_replicator/converter.py @@ -710,14 +710,23 @@ def parse_mysql_table_structure(self, create_statement, required_table_name=None continue - #print(" === processing line", line) + line = line.strip() + # print(" === processing line", line) + + if line.startswith('`'): + end_pos = line.find('`', 1) + field_name = line[1:end_pos] + line = line[end_pos+1:].strip() + definition = line.split(' ') + else: + definition = line.split(' ') + field_name = strip_sql_name(definition[0]) + definition = definition[1:] - definition = line.split(' ') - field_name = strip_sql_name(definition[0]) - field_type = definition[1] + field_type = definition[0] field_parameters = '' - if len(definition) > 2: - field_parameters = ' '.join(definition[2:]) + if len(definition) > 1: + field_parameters = ' '.join(definition[1:]) additional_data = None if 'set(' in field_type.lower(): diff --git a/test_mysql_ch_replicator.py b/test_mysql_ch_replicator.py index e1d78ce..307fd2a 100644 --- a/test_mysql_ch_replicator.py +++ b/test_mysql_ch_replicator.py @@ -100,7 +100,7 @@ def test_e2e_regular(config_file): CREATE TABLE `{TEST_TABLE_NAME}` ( id int NOT NULL AUTO_INCREMENT, name varchar(255) COMMENT 'Dân tộc, ví dụ: Kinh', - age int COMMENT 'CMND Cũ', + `age x` int COMMENT 'CMND Cũ', field1 text, field2 blob, PRIMARY KEY (id) @@ -108,10 +108,10 @@ def test_e2e_regular(config_file): ''') mysql.execute( - f"INSERT INTO `{TEST_TABLE_NAME}` (name, age, field1, field2) VALUES ('Ivan', 42, 'test1', 'test2');", + f"INSERT INTO `{TEST_TABLE_NAME}` (name, `age x`, field1, field2) VALUES ('Ivan', 42, 'test1', 'test2');", commit=True, ) - mysql.execute(f"INSERT INTO `{TEST_TABLE_NAME}` (name, age) VALUES ('Peter', 33);", commit=True) + mysql.execute(f"INSERT INTO `{TEST_TABLE_NAME}` (name, `age x`) VALUES ('Peter', 33);", commit=True) binlog_replicator_runner = BinlogReplicatorRunner(cfg_file=config_file) binlog_replicator_runner.run() @@ -125,13 +125,13 @@ def test_e2e_regular(config_file): assert_wait(lambda: TEST_TABLE_NAME in ch.get_tables()) assert_wait(lambda: len(ch.select(TEST_TABLE_NAME)) == 2) - mysql.execute(f"INSERT INTO `{TEST_TABLE_NAME}` (name, age) VALUES ('Filipp', 50);", commit=True) + mysql.execute(f"INSERT INTO `{TEST_TABLE_NAME}` (name, `age x`) VALUES ('Filipp', 50);", commit=True) assert_wait(lambda: len(ch.select(TEST_TABLE_NAME)) == 3) - assert_wait(lambda: ch.select(TEST_TABLE_NAME, where="name='Filipp'")[0]['age'] == 50) + assert_wait(lambda: ch.select(TEST_TABLE_NAME, where="name='Filipp'")[0]['age x'] == 50) mysql.execute(f"ALTER TABLE `{TEST_TABLE_NAME}` ADD `last_name` varchar(255); ") - mysql.execute(f"INSERT INTO `{TEST_TABLE_NAME}` (name, age, last_name) VALUES ('Mary', 24, 'Smith');", commit=True) + mysql.execute(f"INSERT INTO `{TEST_TABLE_NAME}` (name, `age x`, last_name) VALUES ('Mary', 24, 'Smith');", commit=True) assert_wait(lambda: len(ch.select(TEST_TABLE_NAME)) == 4) assert_wait(lambda: ch.select(TEST_TABLE_NAME, where="name='Mary'")[0]['last_name'] == 'Smith') @@ -146,7 +146,7 @@ def test_e2e_regular(config_file): ) mysql.execute( - f"INSERT INTO `{TEST_TABLE_NAME}` (name, age, last_name, country) " + f"INSERT INTO `{TEST_TABLE_NAME}` (name, `age x`, last_name, country) " f"VALUES ('John', 12, 'Doe', 'USA');", commit=True, )