8
8
from enum import Enum
9
9
10
10
from .event import BinLogEvent
11
- from .exceptions import TableMetadataUnavailableError
12
11
from .constants import FIELD_TYPE
13
12
from .constants import BINLOG
14
13
from .constants import CHARSET
@@ -92,14 +91,6 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs)
92
91
# Body
93
92
self .number_of_columns = self .packet .read_length_coded_binary ()
94
93
self .columns = self .table_map [self .table_id ].columns
95
- column_schemas = self .table_map [self .table_id ].column_schemas
96
-
97
- if (
98
- len (column_schemas ) == 0
99
- ): # could not read the table metadata, probably already dropped
100
- self .complete = False
101
- if self ._fail_on_table_metadata_unavailable :
102
- raise TableMetadataUnavailableError (self .table )
103
94
104
95
@staticmethod
105
96
def _is_null (null_bitmap , position ):
@@ -124,19 +115,13 @@ def _read_column_data(self, cols_bitmap):
124
115
column = self .columns [i ]
125
116
name = self .table_map [self .table_id ].columns [i ].name
126
117
unsigned = self .table_map [self .table_id ].columns [i ].unsigned
127
- zerofill = self .table_map [self .table_id ].columns [i ].zerofill
128
- fixed_binary_length = (
129
- self .table_map [self .table_id ].columns [i ].fixed_binary_length
130
- )
131
118
132
119
values [name ] = self .__read_values_name (
133
120
column ,
134
121
null_bitmap ,
135
122
null_bitmap_index ,
136
123
cols_bitmap ,
137
124
unsigned ,
138
- zerofill ,
139
- fixed_binary_length ,
140
125
i ,
141
126
)
142
127
@@ -146,15 +131,7 @@ def _read_column_data(self, cols_bitmap):
146
131
return values
147
132
148
133
def __read_values_name (
149
- self ,
150
- column ,
151
- null_bitmap ,
152
- null_bitmap_index ,
153
- cols_bitmap ,
154
- unsigned ,
155
- zerofill ,
156
- fixed_binary_length ,
157
- i ,
134
+ self , column , null_bitmap , null_bitmap_index , cols_bitmap , unsigned , i
158
135
):
159
136
if BitGet (cols_bitmap , i ) == 0 :
160
137
return None
@@ -165,32 +142,24 @@ def __read_values_name(
165
142
if column .type == FIELD_TYPE .TINY :
166
143
if unsigned :
167
144
ret = struct .unpack ("<B" , self .packet .read (1 ))[0 ]
168
- if zerofill :
169
- ret = format (ret , "03d" )
170
145
return ret
171
146
else :
172
147
return struct .unpack ("<b" , self .packet .read (1 ))[0 ]
173
148
elif column .type == FIELD_TYPE .SHORT :
174
149
if unsigned :
175
150
ret = struct .unpack ("<H" , self .packet .read (2 ))[0 ]
176
- if zerofill :
177
- ret = format (ret , "05d" )
178
151
return ret
179
152
else :
180
153
return struct .unpack ("<h" , self .packet .read (2 ))[0 ]
181
154
elif column .type == FIELD_TYPE .LONG :
182
155
if unsigned :
183
156
ret = struct .unpack ("<I" , self .packet .read (4 ))[0 ]
184
- if zerofill :
185
- ret = format (ret , "010d" )
186
157
return ret
187
158
else :
188
159
return struct .unpack ("<i" , self .packet .read (4 ))[0 ]
189
160
elif column .type == FIELD_TYPE .INT24 :
190
161
if unsigned :
191
162
ret = self .packet .read_uint24 ()
192
- if zerofill :
193
- ret = format (ret , "08d" )
194
163
return ret
195
164
else :
196
165
return self .packet .read_int24 ()
@@ -205,12 +174,6 @@ def __read_values_name(
205
174
else self .__read_string (1 , column )
206
175
)
207
176
208
- if fixed_binary_length and len (ret ) < fixed_binary_length :
209
- # Fixed-length binary fields are stored in the binlog
210
- # without trailing zeros and must be padded with zeros up
211
- # to the specified length at read time.
212
- nr_pad = fixed_binary_length - len (ret )
213
- ret += b"\x00 " * nr_pad
214
177
return ret
215
178
elif column .type == FIELD_TYPE .NEWDECIMAL :
216
179
return self .__read_new_decimal (column )
@@ -238,8 +201,6 @@ def __read_values_name(
238
201
elif column .type == FIELD_TYPE .LONGLONG :
239
202
if unsigned :
240
203
ret = self .packet .read_uint64 ()
241
- if zerofill :
242
- ret = format (ret , "020d" )
243
204
return ret
244
205
else :
245
206
return self .packet .read_int64 ()
@@ -498,6 +459,10 @@ def _dump(self):
498
459
print ("Table: %s.%s" % (self .schema , self .table ))
499
460
print ("Affected columns: %d" % self .number_of_columns )
500
461
print ("Changed rows: %d" % (len (self .rows )))
462
+ print (
463
+ "Column Name Information Flag: %s"
464
+ % self .table_map [self .table_id ].column_name_flag
465
+ )
501
466
502
467
def _fetch_rows (self ):
503
468
self .__rows = []
@@ -537,6 +502,7 @@ def _fetch_one_row(self):
537
502
def _dump (self ):
538
503
super ()._dump ()
539
504
print ("Values:" )
505
+ print (self .table .data )
540
506
for row in self .rows :
541
507
print ("--" )
542
508
for key in row ["values" ]:
@@ -702,61 +668,20 @@ def __init__(self, from_packet, event_size, table_map, ctl_connection, **kwargs)
702
668
self .column_count = self .packet .read_length_coded_binary ()
703
669
704
670
self .columns = []
705
-
706
- if self .table_id in table_map :
707
- self .column_schemas = table_map [self .table_id ].column_schemas
708
- elif self .__optional_meta_data :
709
- self .column_schemas = []
710
- else :
711
- self .column_schemas = self ._ctl_connection ._get_table_information (
712
- self .schema , self .table
713
- )
714
-
715
671
self .dbms = self ._ctl_connection ._get_dbms ()
716
-
717
- ordinal_pos_loc = 0
718
- if self .column_count != 0 :
719
- # Read columns meta data
720
- column_types = bytearray (self .packet .read (self .column_count ))
721
- self .packet .read_length_coded_binary ()
722
- for i in range (0 , len (column_types )):
723
- column_type = column_types [i ]
724
- try :
725
- column_schema = self .column_schemas [ordinal_pos_loc ]
726
-
727
- # only acknowledge the column definition if the iteration matches with ordinal position of
728
- # the column. this helps in maintaining support for restricted columnar access
729
- if i != (column_schema ["ORDINAL_POSITION" ] - 1 ):
730
- # raise IndexError to follow the workflow of dropping columns which are not matching the
731
- # underlying table schema
732
- raise IndexError
733
-
734
- ordinal_pos_loc += 1
735
- except IndexError :
736
- # this is a dirty hack to prevent row events containing columns which have been dropped prior
737
- # to pymysqlreplication start, but replayed from binlog from blowing up the service.
738
- # TODO: this does not address the issue if the column other than the last one is dropped
739
- column_schema = {
740
- "COLUMN_NAME" : "__dropped_col_{i}__" .format (i = i ),
741
- "COLLATION_NAME" : None ,
742
- "CHARACTER_SET_NAME" : None ,
743
- "CHARACTER_OCTET_LENGTH" : None ,
744
- "DATA_TYPE" : "BLOB" ,
745
- "COLUMN_COMMENT" : None ,
746
- "COLUMN_TYPE" : "BLOB" , # we don't know what it is, so let's not do anything with it.
747
- "COLUMN_KEY" : "" ,
748
- }
749
- col = Column (column_type , column_schema , from_packet )
750
- self .columns .append (col )
751
-
752
- self .table_obj = Table (
753
- self .column_schemas , self .table_id , self .schema , self .table , self .columns
754
- )
672
+ # Read columns meta data
673
+ column_types = bytearray (self .packet .read (self .column_count ))
674
+ self .packet .read_length_coded_binary ()
675
+ for i in range (0 , len (column_types )):
676
+ column_type = column_types [i ]
677
+ col = Column (column_type , from_packet )
678
+ self .columns .append (col )
755
679
756
680
# ith column is nullable if (i - 1)th bit is set to True, not nullable otherwise
757
681
## Refer to definition of and call to row.event._is_null() to interpret bitmap corresponding to columns
758
682
self .null_bitmask = self .packet .read ((self .column_count + 7 ) / 8 )
759
- # optional meta Data
683
+ self .table_obj = Table (self .table_id , self .schema , self .table , self .columns )
684
+ table_map [self .table_id ] = self .table_obj
760
685
self .optional_metadata = self ._get_optional_meta_data ()
761
686
762
687
# We exclude 'CHAR' and 'INTERVAL' as they map to 'TINY' and 'ENUM' respectively
0 commit comments