From 85b136441019b2ac581342cc4e4a5d35b0e036c1 Mon Sep 17 00:00:00 2001 From: CodePanter Date: Wed, 23 Aug 2017 13:55:10 +0200 Subject: [PATCH] Fields with binary data will now have their converters set to 'None'. This will happen regardless of whether unicode is being used or not. --- pymysql/connections.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/pymysql/connections.py b/pymysql/connections.py index b7910060..a19037a6 100644 --- a/pymysql/connections.py +++ b/pymysql/connections.py @@ -141,7 +141,7 @@ def _scramble(password, message): stage1 = sha_new(password).digest() stage2 = sha_new(stage1).digest() s = sha_new() - s.update(message[:SCRAMBLE_LENGTH]) + s.update(message[:SCRAMBLE_LENGTH]) s.update(stage2) result = s.digest() return _my_crypt(result, stage1) @@ -807,7 +807,7 @@ def select_db(self, db): def escape(self, obj, mapping=None): """Escape whatever value you pass to it. - + Non-standard, for internal use; do not use this in your applications. """ if isinstance(obj, str_type): @@ -816,7 +816,7 @@ def escape(self, obj, mapping=None): def literal(self, obj): """Alias for escape() - + Non-standard, for internal use; do not use this in your applications. """ return self.escape(obj, self.encoders) @@ -1487,6 +1487,7 @@ def _get_descriptions(self): description = [] for i in range_type(self.field_count): + isbinary = False field = self.connection._read_packet(FieldDescriptorPacket) self.fields.append(field) description.append(field.description()) @@ -1498,19 +1499,24 @@ def _get_descriptions(self): # This behavior is different from TEXT / BLOB. # We should decode result by connection encoding regardless charsetnr. # See https://github.com/PyMySQL/PyMySQL/issues/488 - encoding = conn_encoding # SELECT CAST(... AS JSON) - elif field_type in TEXT_TYPES: - if field.charsetnr == 63: # binary - # TEXTs with charset=binary means BINARY types. - encoding = None - else: - encoding = conn_encoding + encoding = conn_encoding # SELECT CAST(... AS JSON) + elif field_type in TEXT_TYPES and field.charsetnr != 63: # binary + encoding = conn_encoding else: # Integers, Dates and Times, and other basic data is encoded in ascii encoding = 'ascii' else: encoding = None - converter = self.connection.decoders.get(field_type) + + if field_type in TEXT_TYPES and field.charsetnr == 63: # binary + # TEXTs with charset=binary means BINARY types. + encoding = None + isbinary = True + + if not isbinary: + converter = self.connection.decoders.get(field_type) + else: + converter = None if converter is through: converter = None if DEBUG: print("DEBUG: field={}, converter={}".format(field, converter))