8000 BUG#35503506: Query on information_schema.columns returns bytes · mysql/mysql-connector-python@387572d · GitHub
[go: up one dir, main page]

Skip to content

Commit 387572d

Browse files
committed
BUG#35503506: Query on information_schema.columns returns bytes
When querying information_schema.columns using the C extension, MySQL Connector/Python returns bytes instead of str in the result values. This patch fixes this issue by testing if the charset is binary. Change-Id: If736b245a64af75c793391a4b03e37b47e02035c
1 parent a751670 commit 387572d

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ v8.2.0
1616
- WL#15218: Support WebAuthn authentication
1717
- BUG#35547876: C/Python 8.1.0 type check build fails in the pb2 branch
1818
- BUG#35544123: Kerberos unit tests configuration is outdated
19+
- BUG#35503506: Query on information_schema.columns returns bytes
1920

2021
v8.1.0
2122
======

src/mysql_capi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2781,7 +2781,8 @@ MySQL_fetch_row(MySQL *self)
27812781
PyTuple_SET_ITEM(result_row, i, mytopy_bit(row[i], field_lengths[i]));
27822782
}
27832783
else if (field_type == MYSQL_TYPE_BLOB) {
2784-
if ((field_flags & BLOB_FLAG) && (field_flags & BINARY_FLAG)) {
2784+
if ((field_flags & BLOB_FLAG) &&
2785+
(field_flags & BINARY_FLAG) && field_charsetnr == 63) {
27852786
value = PyBytes_FromStringAndSize(row[i], field_lengths[i]);
27862787
}
27872788
else {

tests/test_bugs.py

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@
4242
"""
4343

4444
import gc
45-
import io
4645
import os
4746
import pickle
4847
import platform
49-
import struct
5048
import sys
5149
import tempfile
5250
import time
@@ -7667,3 +7665,55 @@ def test_long_field_names(self):
76677665
cur.execute(query) # No error is success
76687666
res = cur.fetchall()
76697667
self.assertEqual(res, [])
7668+
7669+
7670+
class BugOra35503506(tests.MySQLConnectorTests):
7671+
"""BUG#35503506: Query on information_schema.columns returns bytes
7672+
7673+
When querying information_schema.columns using the C extension, MySQL
7674+
Connector/Python returns bytes instead of str in the result values.
7675+
7676+
This patch fixes this issue by testing if the charset is binary.
7677+
"""
7678+
7679+
table_name = "BugOra35503506"
7680+
7681+
def setUp(self):
7682+
config = tests.get_mysql_config()
7683+
with mysql.connector.connect(**config) as cnx:
7684+
cnx.cmd_query(f"DROP TABLE IF EXISTS {self.table_name}")
7685+
cnx.cmd_query(
7686+
f"""
7687+
CREATE TABLE {self.table_name} (
7688+
id INT AUTO_INCREMENT PRIMARY KEY,
7689+
data LONGBLOB,
7690+
text VARCHAR(50)
7691+
)
7692+
"""
7693+
)
7694+
7695+
def tearDown(self):
7696+
config = tests.get_mysql_config()
7697+
with mysql.connector.connect(**config) as cnx:
7698+
cnx.cmd_query(f"DROP TABLE IF EXISTS {self.table_name}")
7699+
7700+
@foreach_cnx()
7701+
def test_information_schema_columns_result(self):
7702+
config = tests.get_mysql_config()
7703+
database = config["database"]
7704+
exp = [("id", "int", None, "int", 10, 0)]
7705+
with mysql.connector.connect(**config) as cnx:
7706+
with cnx.cursor() as cur:
7707+
cur.execute(
7708+
f"""
7709+
SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH,
7710+
COLUMN_TYPE, NUMERIC_PRECISION, NUMERIC_SCALE
7711+
FROM information_schema.columns
7712+
WHERE TABLE_NAME = '{self.table_name}'
7713+
AND TABLE_SCHEMA = '{database}'
7714+
AND COLUMN_NAME = 'id'
7715+
ORDER BY ORDINAL_POSITION
7716+
"""
7717+
)
7718+
res = cur.fetchall()
7719+
self.assertEqual(exp, res)

0 commit comments

Comments
 (0)
0