@@ -21,36 +21,16 @@ def __parse_column_definition(self, column_type, column_schema, packet):
2121 self .collation_name = column_schema ["COLLATION_NAME" ]
2222 self .character_set_name = column_schema ["CHARACTER_SET_NAME" ]
2323 self .comment = column_schema ["COLUMN_COMMENT" ]
24- self .unsigned = False
24+ self .unsigned = column_schema [ "COLUMN_TYPE" ]. find ( "unsigned" ) != - 1
2525 self .type_is_bool = False
26- if column_schema ["COLUMN_KEY" ] == "PRI" :
27- self .is_primary = True
28- else :
29- self .is_primary = False
26+ self .is_primary = column_schema ["COLUMN_KEY" ] == "PRI"
3027
31- if column_schema ["COLUMN_TYPE" ].find ("unsigned" ) != - 1 :
32- self .unsigned = True
33- if self .type == FIELD_TYPE .VAR_STRING or \
34- self .type == FIELD_TYPE .STRING :
35- self .__read_string_metadata (packet , column_schema )
36- elif self .type == FIELD_TYPE .VARCHAR :
28+ if self .type == FIELD_TYPE .VARCHAR :
3729 self .max_length = struct .unpack ('<H' , packet .read (2 ))[0 ]
38- elif self .type == FIELD_TYPE .BLOB :
39- self .length_size = packet .read_uint8 ()
40- elif self .type == FIELD_TYPE .GEOMETRY :
41- self .length_size = packet .read_uint8 ()
42- elif self .type == FIELD_TYPE .NEWDECIMAL :
43- self .precision = packet .read_uint8 ()
44- self .decimals = packet .read_uint8 ()
4530 elif self .type == FIELD_TYPE .DOUBLE :
4631 self .size = packet .read_uint8 ()
4732 elif self .type == FIELD_TYPE .FLOAT :
4833 self .size = packet .read_uint8 ()
49- elif self .type == FIELD_TYPE .BIT :
50- bits = packet .read_uint8 ()
51- bytes = packet .read_uint8 ()
52- self .bits = (bytes * 8 ) + bits
53- self .bytes = int ((self .bits + 7 ) / 8 )
5434 elif self .type == FIELD_TYPE .TIMESTAMP2 :
5535 self .fsp = packet .read_uint8 ()
5636 elif self .type == FIELD_TYPE .DATETIME2 :
@@ -60,6 +40,21 @@ def __parse_column_definition(self, column_type, column_schema, packet):
6040 elif self .type == FIELD_TYPE .TINY and \
6141 column_schema ["COLUMN_TYPE" ] == "tinyint(1)" :
6242 self .type_is_bool = True
43+ elif self .type == FIELD_TYPE .VAR_STRING or \
44+ self .type == FIELD_TYPE .STRING :
45+ self .__read_string_metadata (packet , column_schema )
46+ elif self .type == FIELD_TYPE .BLOB :
47+ self .length_size = packet .read_uint8 ()
48+ elif self .type == FIELD_TYPE .GEOMETRY :
49+ self .length_size = packet .read_uint8 ()
50+ elif self .type == FIELD_TYPE .NEWDECIMAL :
51+ self .precision = packet .read_uint8 ()
52+ self .decimals = packet .read_uint8 ()
53+ elif self .type == FIELD_TYPE .BIT :
54+ bits = packet .read_uint8 ()
55+ bytes = packet .read_uint8 ()
56+ self .bits = (bytes * 8 ) + bits
57+ self .bytes = int ((self .bits + 7 ) / 8 )
6358
6459 def __read_string_metadata (self , packet , column_schema ):
6560 metadata = (packet .read_uint8 () << 8 ) + packet .read_uint8 ()
0 commit comments