Commit 7c1c7a86 authored by Jérome Perrin's avatar Jérome Perrin

ZMySQLDA: MySQLdb's query expect bytes

it supports text, but unless they have non-ASCI characters, so it's
better to always pass bytes.
parent b0b18426
...@@ -111,7 +111,6 @@ from Shared.DC.ZRDB.TM import TM ...@@ -111,7 +111,6 @@ from Shared.DC.ZRDB.TM import TM
from DateTime import DateTime from DateTime import DateTime
from zLOG import LOG, ERROR, WARNING from zLOG import LOG, ERROR, WARNING
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from Products.ERP5Type.Utils import str2bytes
hosed_connection = ( hosed_connection = (
CR.SERVER_GONE_ERROR, CR.SERVER_GONE_ERROR,
...@@ -425,8 +424,8 @@ class DB(TM): ...@@ -425,8 +424,8 @@ class DB(TM):
"""Execute 'query_string' and return at most 'max_rows'.""" """Execute 'query_string' and return at most 'max_rows'."""
self._use_TM and self._register() self._use_TM and self._register()
desc = None desc = None
if not isinstance(query_string, bytes): if isinstance(query_string, six.text_type):
query_string = str2bytes(query_string) query_string = query_string.encode('utf-8')
# XXX deal with a typical mistake that the user appends # XXX deal with a typical mistake that the user appends
# an unnecessary and rather harmful semicolon at the end. # an unnecessary and rather harmful semicolon at the end.
# Unfortunately, MySQLdb does not want to be graceful. # Unfortunately, MySQLdb does not want to be graceful.
...@@ -651,6 +650,8 @@ class DeferredDB(DB): ...@@ -651,6 +650,8 @@ class DeferredDB(DB):
def query(self, query_string, max_rows=1000): def query(self, query_string, max_rows=1000):
self._register() self._register()
if isinstance(query_string, six.text_type):
query_string = query_string.encode('utf-8')
for qs in query_string.split(b'\0'): for qs in query_string.split(b'\0'):
qs = qs.strip() qs = qs.strip()
if qs: if qs:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment