MCPcopy Index your code
hub / github.com/danfengcao/binlog2sql / concat_sql_from_binlog_event

Function concat_sql_from_binlog_event

binlog2sql/binlog2sql_util.py:167–187  ·  view source on GitHub ↗
(cursor, binlog_event, row=None, e_start_pos=None, flashback=False, no_pk=False)

Source from the content-addressed store, hash-verified

165
166
167def concat_sql_from_binlog_event(cursor, binlog_event, row=None, e_start_pos=None, flashback=False, no_pk=False):
168 if flashback and no_pk:
169 raise ValueError('only one of flashback or no_pk can be True')
170 if not (isinstance(binlog_event, WriteRowsEvent) or isinstance(binlog_event, UpdateRowsEvent)
171 or isinstance(binlog_event, DeleteRowsEvent) or isinstance(binlog_event, QueryEvent)):
172 raise ValueError('binlog_event must be WriteRowsEvent, UpdateRowsEvent, DeleteRowsEvent or QueryEvent')
173
174 sql = ''
175 if isinstance(binlog_event, WriteRowsEvent) or isinstance(binlog_event, UpdateRowsEvent) \
176 or isinstance(binlog_event, DeleteRowsEvent):
177 pattern = generate_sql_pattern(binlog_event, row=row, flashback=flashback, no_pk=no_pk)
178 sql = cursor.mogrify(pattern['template'], pattern['values'])
179 time = datetime.datetime.fromtimestamp(binlog_event.timestamp)
180 sql += ' #start %s end %s time %s' % (e_start_pos, binlog_event.packet.log_pos, time)
181 elif flashback is False and isinstance(binlog_event, QueryEvent) and binlog_event.query != 'BEGIN' \
182 and binlog_event.query != 'COMMIT':
183 if binlog_event.schema:
184 sql = 'USE {0};\n'.format(binlog_event.schema)
185 sql += '{0};'.format(fix_object(binlog_event.query))
186
187 return sql
188
189
190def generate_sql_pattern(binlog_event, row=None, flashback=False, no_pk=False):

Callers 1

process_binlogMethod · 0.90

Calls 2

generate_sql_patternFunction · 0.85
fix_objectFunction · 0.85

Tested by

no test coverage detected