8000 BUG#30089671: Fix decoding VARBINARY columns when using a prepared cu… · mysql/mysql-connector-python@f798837 · GitHub
[go: up one dir, main page]

Skip to content

Commit f798837

Browse files
committed
BUG#30089671: Fix decoding VARBINARY columns when using a prepared cursor
When fetching results from a prepared cursor using the pure Python implementation, it may fail if the VARBINARY column contains bytes that cannot be decoded. With this patch, bytes are returned if cannot be decoded. Thank you for the contribution. Change-Id: I1655daab3a320dbbde9942acca4fb06e64288bcf
1 parent ce8a1a2 commit f798837

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ v8.0.32
1414
- WL#15348: Support MIT Kerberos library on Windows
1515
- WL#15036: Support for type hints
1616
- BUG#34556157: Kerberos authorization fails when using SSPI as security interface
17+
- BUG#30089671: Fix decoding VARBINARY columns when using a prepared cursor
1718

1819
v8.0.31
1920
=======

lib/mysql/connector/protocol.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,10 @@ def _parse_binary_values(
641641
values.append(value)
642642
else:
643643
(packet, value) = utils.read_lc_string(packet)
644-
values.append(value.decode(charset))
644+
try:
645+
values.append(value.decode(charset))
646+
except UnicodeDecodeError:
647+
values.append(value)
645648

646649
return tuple(values)
647650

tests/test_protocol.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,13 +464,17 @@ def test__parse_binary_values(self):
464464
("aDateTime", 12, None, None, None, None, 1, 128),
465465
("aTime", 11, None, None, None, None, 1, 128),
466466
("aNull", 6, None, None, None, None, 1, 128),
467+
("aBlob", 252, None, None, None, None, 1, 144),
468+
("aVarBinary", 253, None, None, None, None, 1, 128),
467469
]
468470

469471
packet = bytearray(
470472
b"\x00\x01\x03\x61\x62\x63\x04\x33\x2e\x31\x34\x08"
471473
b"\x2d\x33\x2e\x31\x34\x31\x35\x39\x04\xd3\x07"
472474
b"\x01\x1f\x07\xb9\x07\x06\x0e\x15\x21\x0e\x0c"
473475
b"\x00\x0a\x00\x00\x00\x10\x0f\x1e\x70\x82\x03\x00"
476+
b"\x05\xaa\xbb\xcc\xdd\xff"
477+
b"\x05\xaa\xbb\xcc\xdd\xff"
474478
)
475479

476480
# float/double are returned as DECIMAL by MySQL
@@ -482,6 +486,8 @@ def test__parse_binary_values(self):
482486
datetime.datetime(1977, 6, 14, 21, 33, 14),
483487
datetime.timedelta(10, 58530, 230000),
484488
None,
489+
bytearray(b"\xaa\xbb\xcc\xdd\xff"),
490+
bytearray(b"\xaa\xbb\xcc\xdd\xff"),
485491
)
486492
res = self._protocol._parse_binary_values(fields, packet)
487493
self.assertEqual(exp, res)

0 commit comments

Comments
 (0)
0