Commit e74e3580 authored by Jérome Perrin's avatar Jérome Perrin

ZMySQLDA: fix string_literal usage

MySQLdb's string_literal is a method from the C API and the name is not
natural for python programmers, because it manipulates bytes. It
supports str, unless they have non ASCII characters, so it's better to
always pass bytes.

On python2, this change repairs a regression visible when searching
catalog with translated related keys. This regression was introduced in
the merge of zope4 support, more specifically with 610972af (py3:
Update Shared.DC.ZRDB.{sqltest,sqlvar} monkey patches., 2022-04-16),
because with the new version of the patches this method gets passed
unicode strings, which is fine, unless they contain non ASCII characters.
parent cd24fb39
......@@ -89,6 +89,7 @@ $Id: DA.py,v 1.4 2001/08/09 20:16:36 adustman Exp $''' % database_type
__version__='$Revision: 1.4 $'[11:-2]
import os
import six
from collections import defaultdict
from weakref import WeakKeyDictionary
import transaction
......@@ -172,6 +173,8 @@ class Connection(DABase.Connection):
# any reason, that would generate an infinite loop.
self.connect(self.connection_string)
connection = self._v_database_connection
if not isinstance(v, six.binary_type):
v = v.encode('utf-8')
return connection.string_literal(v)
......
......@@ -466,6 +466,8 @@ class DB(TM):
return items, result
def string_literal(self, s):
# This methods accepts bytes or str with only ASCII characters
# and return bytes.
return self.db.string_literal(s)
def _begin(self, *ignored):
......
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