Skip to content

Commit 9cec971

Browse files
Merge pull request julien-duponchelle#66 from lxyu/primay_col_info
expose primay_keys info for row based events
2 parents db88361 + 3fda284 commit 9cec971

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

pymysqlreplication/binlogstream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def __get_table_information(self, schema, table):
189189
cur.execute("""
190190
SELECT
191191
COLUMN_NAME, COLLATION_NAME, CHARACTER_SET_NAME,
192-
COLUMN_COMMENT, COLUMN_TYPE
192+
COLUMN_COMMENT, COLUMN_TYPE, COLUMN_KEY
193193
FROM
194194
columns
195195
WHERE

pymysqlreplication/column.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def __parse_column_definition(self, column_type, column_schema, packet):
2424
self.data["comment"] = column_schema["COLUMN_COMMENT"]
2525
self.data["unsigned"] = False
2626
self.data["type_is_bool"] = False
27+
self.data["is_primary"] = column_schema["COLUMN_KEY"] == "PRI"
2728

2829
if column_schema["COLUMN_TYPE"].find("unsigned") != -1:
2930
self.data["unsigned"] = True

pymysqlreplication/row_event.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection):
2121

2222
#Header
2323
self.table_id = self._read_table_id()
24+
self.primary_key = table_map[self.table_id].data["primary_key"]
2425
self.flags = struct.unpack('<H', self.packet.read(2))[0]
2526

2627
#Event V2

pymysqlreplication/table.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@
33

44
class Table(object):
55
def __init__(self, column_schemas, table_id, schema, table, columns):
6+
primary_key = [c.data["name"] for c in columns if c.data["is_primary"]]
7+
if len(primary_key) == 0:
8+
primary_key = ''
9+
elif len(primary_key) == 1:
10+
primary_key, = primary_key
11+
else:
12+
primary_key = tuple(primary_key)
13+
614
self.data = {
715
"column_schemas": column_schemas,
816
"table_id": table_id,
917
"schema": schema,
1018
"table": table,
11-
"columns": columns
19+
"columns": columns,
20+
"primary_key": primary_key
1221
}
1322

1423
def __getattr__(self, item):

0 commit comments

Comments
 (0)