(cursor, binlog_event, row=None, e_start_pos=None, flashback=False, no_pk=False)
| 165 | |
| 166 | |
| 167 | def 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 | |
| 190 | def generate_sql_pattern(binlog_event, row=None, flashback=False, no_pk=False): |
no test coverage detected