Skip to content

Commit bc530dd

Browse files
authored
Allow queries to be executed at connection
it's usefull to set connection collate , SET and others variables
1 parent 511b42c commit bc530dd

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pymysqlreplication/binlogstream.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ def __init__(self, connection_settings, server_id,
138138
report_slave=None, slave_uuid=None,
139139
pymysql_wrapper=None,
140140
fail_on_table_metadata_unavailable=False,
141-
slave_heartbeat=None):
141+
slave_heartbeat=None,
142+
connect_queries=None):
142143
"""
143144
Attributes:
144145
ctl_connection_settings: Connection settings for cluster holding
@@ -213,6 +214,7 @@ def __init__(self, connection_settings, server_id,
213214
self.report_slave = ReportSlave(report_slave)
214215
self.slave_uuid = slave_uuid
215216
self.slave_heartbeat = slave_heartbeat
217+
self.connect_queries = None if connect_queries is None else ([connect_queries] if not isinstance(connect_queries, list) else connect_queries)
216218

217219
if pymysql_wrapper:
218220
self.pymysql_wrapper = pymysql_wrapper
@@ -413,6 +415,10 @@ def __connect_to_stream(self):
413415
else:
414416
self._stream_connection._write_bytes(prelude)
415417
self._stream_connection._next_seq_id = 1
418+
if self.connect_queries is not None:
419+
cur = self._stream_connection.cursor()
420+
for i in self.connect_queries:
421+
cur.execute(i)
416422
self.__connected_stream = True
417423

418424
def fetchone(self):

0 commit comments

Comments
 (0)