From 05b0ab86eb3dba30705d5d2487656c8c742c6a63 Mon Sep 17 00:00:00 2001 From: Vilnis Termanis Date: Tue, 9 Aug 2016 12:13:55 +0100 Subject: [PATCH] Improve binary value handling in queries (Python 3) --- lib/mysql/connector/conversion.py | 2 ++ src/mysql_capi.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/mysql/connector/conversion.py b/lib/mysql/connector/conversion.py index d94e9e9..7a888fe 100644 --- a/lib/mysql/connector/conversion.py +++ b/lib/mysql/connector/conversion.py @@ -169,6 +169,8 @@ def quote(self, buf): return str(buf).encode('ascii') elif isinstance(buf, type(None)): return bytearray(b"NULL") + elif not PY2 and isinstance(buf, (bytes, bytearray)): + return bytearray(b"_binary'" + buf + b"'") else: return bytearray(b"'" + buf + b"'") diff --git a/src/mysql_capi.c b/src/mysql_capi.c index ea1fe3f..2574bbe 100644 --- a/src/mysql_capi.c +++ b/src/mysql_capi.c @@ -1778,7 +1778,7 @@ MySQL_convert_to_mysql(MySQL *self, PyObject *args) } else if (PyBytes_Check(new_value)) { - quoted= PyBytes_FromFormat("'%s'", PyBytes_AsString(new_value)); + quoted= PyBytes_FromFormat("_binary'%s'", PyBytes_AsString(new_value)); PyTuple_SET_ITEM(prepared, i, quoted); #endif }