From 830e4786c151d2b41c2c6b59eda89015fb0bbade Mon Sep 17 00:00:00 2001 From: Pete Hunt Date: Fri, 30 Jul 2010 14:24:41 +0000 Subject: [PATCH] fixed a bug with encoding decimals and fixed a bug with respect to binary data and unicode --- pymysql/converters.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pymysql/converters.py b/pymysql/converters.py index bf90a3b..49fc8f1 100644 --- a/pymysql/converters.py +++ b/pymysql/converters.py @@ -51,8 +51,11 @@ def escape_float(value, charset): def escape_string(value, charset): r = ("'%s'" % ESCAPE_REGEX.sub( lambda match: ESCAPE_MAP.get(match.group(0)), value)) - if not charset is None: - r = r.encode(charset) + # TODO: make sure that encodings are handled correctly here. + # Since we may be dealing with binary data, the encoding + # routine below is commented out. + #if not charset is None: + # r = r.encode(charset) return r def escape_unicode(value, charset): @@ -296,8 +299,8 @@ try: decoders[FIELD_TYPE.DECIMAL] = Decimal decoders[FIELD_TYPE.NEWDECIMAL] = Decimal - def escape_decimal(obj): - return str(obj) + def escape_decimal(obj, charset): + return unicode(obj).encode(charset) encoders[Decimal] = escape_decimal except ImportError: