mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 02:54:29 +08:00
Revert "Use _binary prefix for bytes/bytearray parameters"
This commit is contained in:
@ -27,7 +27,6 @@ apilevel = "2.0"
|
|||||||
paramstyle = "format"
|
paramstyle = "format"
|
||||||
|
|
||||||
from _mysql import *
|
from _mysql import *
|
||||||
from MySQLdb.compat import PY2
|
|
||||||
from MySQLdb.constants import FIELD_TYPE
|
from MySQLdb.constants import FIELD_TYPE
|
||||||
from MySQLdb.times import Date, Time, Timestamp, \
|
from MySQLdb.times import Date, Time, Timestamp, \
|
||||||
DateFromTicks, TimeFromTicks, TimestampFromTicks
|
DateFromTicks, TimeFromTicks, TimestampFromTicks
|
||||||
@ -73,11 +72,7 @@ def test_DBAPISet_set_equality_membership():
|
|||||||
def test_DBAPISet_set_inequality_membership():
|
def test_DBAPISet_set_inequality_membership():
|
||||||
assert FIELD_TYPE.DATE != STRING
|
assert FIELD_TYPE.DATE != STRING
|
||||||
|
|
||||||
if PY2:
|
def Binary(x):
|
||||||
def Binary(x):
|
|
||||||
return bytearray(x)
|
|
||||||
else:
|
|
||||||
def Binary(x):
|
|
||||||
return bytes(x)
|
return bytes(x)
|
||||||
|
|
||||||
def Connect(*args, **kwargs):
|
def Connect(*args, **kwargs):
|
||||||
|
@ -197,7 +197,7 @@ class Connection(_mysql.connection):
|
|||||||
|
|
||||||
db = proxy(self)
|
db = proxy(self)
|
||||||
def _get_string_literal():
|
def _get_string_literal():
|
||||||
# Note: string_literal() is called for bytes object on Python 3 (via bytes_literal)
|
# Note: string_literal() is called for bytes object on Python 3.
|
||||||
def string_literal(obj, dummy=None):
|
def string_literal(obj, dummy=None):
|
||||||
return db.string_literal(obj)
|
return db.string_literal(obj)
|
||||||
return string_literal
|
return string_literal
|
||||||
@ -213,11 +213,6 @@ class Connection(_mysql.connection):
|
|||||||
return db.literal(str(u).encode(unicode_literal.charset))
|
return db.literal(str(u).encode(unicode_literal.charset))
|
||||||
return unicode_literal
|
return unicode_literal
|
||||||
|
|
||||||
def _get_bytes_literal():
|
|
||||||
def bytes_literal(obj, dummy=None):
|
|
||||||
return b'_binary' + db.string_literal(obj)
|
|
||||||
return bytes_literal
|
|
||||||
|
|
||||||
def _get_string_decoder():
|
def _get_string_decoder():
|
||||||
def string_decoder(s):
|
def string_decoder(s):
|
||||||
return s.decode(string_decoder.charset)
|
return s.decode(string_decoder.charset)
|
||||||
@ -225,7 +220,6 @@ class Connection(_mysql.connection):
|
|||||||
|
|
||||||
string_literal = _get_string_literal()
|
string_literal = _get_string_literal()
|
||||||
self.unicode_literal = unicode_literal = _get_unicode_literal()
|
self.unicode_literal = unicode_literal = _get_unicode_literal()
|
||||||
bytes_literal = _get_bytes_literal()
|
|
||||||
self.string_decoder = string_decoder = _get_string_decoder()
|
self.string_decoder = string_decoder = _get_string_decoder()
|
||||||
if not charset:
|
if not charset:
|
||||||
charset = self.character_set_name()
|
charset = self.character_set_name()
|
||||||
@ -240,8 +234,7 @@ class Connection(_mysql.connection):
|
|||||||
self.converter[FIELD_TYPE.VARCHAR].append((None, string_decoder))
|
self.converter[FIELD_TYPE.VARCHAR].append((None, string_decoder))
|
||||||
self.converter[FIELD_TYPE.BLOB].append((None, string_decoder))
|
self.converter[FIELD_TYPE.BLOB].append((None, string_decoder))
|
||||||
|
|
||||||
self.encoders[bytes] = string_literal if PY2 else bytes_literal
|
self.encoders[bytes] = string_literal
|
||||||
self.encoders[bytearray] = bytes_literal
|
|
||||||
self.encoders[unicode] = unicode_literal
|
self.encoders[unicode] = unicode_literal
|
||||||
self._transactional = self.server_capabilities & CLIENT.TRANSACTIONS
|
self._transactional = self.server_capabilities & CLIENT.TRANSACTIONS
|
||||||
if self._transactional:
|
if self._transactional:
|
||||||
|
Reference in New Issue
Block a user