|
42 | 42 | """
|
43 | 43 |
|
44 | 44 | import gc
|
45 |
| -import io |
46 | 45 | import os
|
47 | 46 | import pickle
|
48 | 47 | import platform
|
49 |
| -import struct |
50 | 48 | import sys
|
51 | 49 | import tempfile
|
52 | 50 | import time
|
@@ -7667,3 +7665,55 @@ def test_long_field_names(self):
|
7667 | 7665 | cur.execute(query) # No error is success
|
7668 | 7666 | res = cur.fetchall()
|
7669 | 7667 | 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