Skip to content

Commit 10e90a1

Browse files
committed
check possible optional metadata version And delete get Table information
check possible optional metadata version And delete get Table information check possible optional metadata version And delete get Table information
1 parent 06ddd9f commit 10e90a1

File tree

1 file changed

+54
-33
lines changed

1 file changed

+54
-33
lines changed

pymysqlreplication/binlogstream.py

+54-33
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ def close(self):
290290
if self.__connected_ctl:
291291
# break reference cycle between stream reader and underlying
292292
# mysql connection object
293-
self._ctl_connection._get_table_information = None
294293
self._ctl_connection.close()
295294
self.__connected_ctl = False
296295

@@ -301,9 +300,9 @@ def __connect_to_ctl(self):
301300
self._ctl_connection_settings["cursorclass"] = DictCursor
302301
self._ctl_connection_settings["autocommit"] = True
303302
self._ctl_connection = self.pymysql_wrapper(**self._ctl_connection_settings)
304-
self._ctl_connection._get_table_information = self.__get_table_information
305303
self._ctl_connection._get_dbms = self.__get_dbms
306304
self.__connected_ctl = True
305+
self.__check_optional_meta_data()
307306

308307
def __checksum_enabled(self):
309308
"""Return True if binlog-checksum = CRC32. Only for MySQL > 5.6"""
@@ -548,6 +547,28 @@ def __set_mariadb_settings(self):
548547

549548
return prelude
550549

550+
def __check_optional_meta_data(self):
551+
cur = self._ctl_connection.cursor()
552+
cur.execute("SHOW VARIABLES LIKE 'BINLOG_ROW_METADATA';")
553+
value = cur.fetchone()
554+
if value is None:
555+
logging.log(
556+
logging.WARN,
557+
"""
558+
Before using MARIADB 10.5.0 and MYSQL 8.0.14 versions,
559+
use python-mysql-replication version Before 1.0 version """,
560+
)
561+
else:
562+
value = value.get("Value", "")
563+
if value.upper() != "FULL":
564+
logging.log(
565+
logging.WARN,
566+
"""
567+
Setting The Variable Value BINLOG_ROW_METADATA = FULL
568+
By Applying this, provide properly mapped column information on UPDATE,DELETE,INSERT.
569+
""",
570+
)
571+
551572
def fetchone(self):
552573
while True:
553574
if self.end_log_pos and self.is_past_end_log_pos:
@@ -709,37 +730,37 @@ def _allowed_event_list(
709730
pass
710731
return frozenset(events)
711732

712-
def __get_table_information(self, schema, table):
713-
for i in range(1, 3):
714-
try:
715-
if not self.__connected_ctl:
716-
self.__connect_to_ctl()
717-
718-
cur = self._ctl_connection.cursor()
719-
cur.execute(
720-
"""
721-
SELECT
722-
COLUMN_NAME, COLLATION_NAME, CHARACTER_SET_NAME,
723-
COLUMN_COMMENT, COLUMN_TYPE, COLUMN_KEY, ORDINAL_POSITION,
724-
DATA_TYPE, CHARACTER_OCTET_LENGTH
725-
FROM
726-
information_schema.columns
727-
WHERE
728-
table_schema = %s AND table_name = %s
729-
""",
730-
(schema, table),
731-
)
732-
result = sorted(cur.fetchall(), key=lambda x: x["ORDINAL_POSITION"])
733-
cur.close()
734-
735-
return result
736-
except pymysql.OperationalError as error:
737-
code, message = error.args
738-
if code in MYSQL_EXPECTED_ERROR_CODES:
739-
self.__connected_ctl = False
740-
continue
741-
else:
742-
raise error
733+
# def __get_table_information(self, schema, table):
734+
# for i in range(1, 3):
735+
# try:
736+
# if not self.__connected_ctl:
737+
# self.__connect_to_ctl()
738+
#
739+
# cur = self._ctl_connection.cursor()
740+
# cur.execute(
741+
# """
742+
# SELECT
743+
# COLUMN_NAME, COLLATION_NAME, CHARACTER_SET_NAME,
744+
# COLUMN_COMMENT, COLUMN_TYPE, COLUMN_KEY, ORDINAL_POSITION,
745+
# DATA_TYPE, CHARACTER_OCTET_LENGTH
746+
# FROM
747+
# information_schema.columns
748+
# WHERE
749+
# table_schema = %s AND table_name = %s
750+
# """,
751+
# (schema, table),
752+
# )
753+
# result = sorted(cur.fetchall(), key=lambda x: x["ORDINAL_POSITION"])
754+
# cur.close()
755+
#
756+
# return result
757+
# except pymysql.OperationalError as error:
758+
# code, message = error.args
759+
# if code in MYSQL_EXPECTED_ERROR_CODES:
760+
# self.__connected_ctl = False
761+
# continue
762+
# else:
763+
# raise error
743764

744765
def __get_dbms(self):
745766
if not self.__connected_ctl:

0 commit comments

Comments
 (0)