From 300abc2ba24fd8d882b448b77b5dd81130ebf375 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Sun, 1 Jan 2012 22:31:09 +0000 Subject: [PATCH] minor update regarding unicode unescaping --- plugins/dbms/mysql/syntax.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/dbms/mysql/syntax.py b/plugins/dbms/mysql/syntax.py index c5f385ecc..1d2c9fb6e 100644 --- a/plugins/dbms/mysql/syntax.py +++ b/plugins/dbms/mysql/syntax.py @@ -22,7 +22,10 @@ class Syntax(GenericSyntax): if quote: unescaped = expression for item in re.findall(r"'[^']+'", expression, re.S): - unescaped = unescaped.replace(item, "0x%s" % binascii.hexlify(item.strip("'"))) + try: + unescaped = unescaped.replace(item, "0x%s" % binascii.hexlify(item.strip("'"))) + except UnicodeEncodeError: + unescaped = unescaped.replace(item, "CHAR(0x%s USING utf8)" % "".join(("%.2x" % ord(_)) if ord(_) < 256 else ("%.4x" % ord(_)) for _ in item.strip("'"))) else: unescaped = "0x%s" % binascii.hexlify(expression)