Skip to content

Commit f85d3e6

Browse files
committed
BUG27991948: unread_result is not unset after invoke get_rows on c-ext
The invocation of cmd_query after retrieve the results of a previews query with get_rows raise an InternalError: "Unread result found" this is because the unread_result property is not automatically set to false after the results are read. This patch improves the usability of the c-extension by unseting the unread_result property to mimic the behavior of the pure python implementation that set to false this variable when the results had been read, with this change the user will not require to invoke the free_result method in order of reuse the same connection to run a new query.
1 parent 2f98f58 commit f85d3e6

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/test_bugs.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4693,6 +4693,49 @@ def test_executemany_utf8mb4(self):
46934693
)
46944694

46954695

4696+
@unittest.skipIf(not CMySQLConnection, ERR_NO_CEXT)
4697+
class BugOra27991948(tests.MySQLConnectorTests):
4698+
"""BUG#27991948: UNREAD_RESULT IS NOT UNSET AFTER INVOKE GET_ROWS ON C-EXT
4699+
"""
4700+
test_sql_single_result = "show variables like '%port%'"
4701+
cnx_cext = None
4702+
cnx_cext_raw = None
4703+
4704+
def setUp(self):
4705+
config_cext = tests.get_mysql_config()
4706+
config_cext["use_pure"] = False
4707+
self.cnx_cext = mysql.connector.connect(**config_cext)
4708+
4709+
def tearDown(self):
4710+
self.cnx_cext.close()
4711+
4712+
def test_automatically_set_of_unread_rows(self):
4713+
"""Test unread_rows is automatically set after fetchall()"""
4714+
# Test get all the rows and execute a query without invoke free_result
4715+
self.cnx_cext.cmd_query(self.test_sql_single_result)
4716+
unread_result = self.cnx_cext.unread_result
4717+
self.assertTrue(unread_result, "unread_rows is expected to be True")
4718+
_ = self.cnx_cext.get_rows()
4719+
unread_result = self.cnx_cext.unread_result
4720+
self.assertFalse(unread_result, "unread_rows was not set to False")
4721+
# Query execution must not raise InternalError: Unread result found
4722+
self.cnx_cext.cmd_query(self.test_sql_single_result)
4723+
_ = self.cnx_cext.get_rows()
4724+
4725+
# Test cursor fetchall
4726+
cur_cext = self.cnx_cext.cursor()
4727+
cur_cext.execute(self.test_sql_single_result)
4728+
unread_result = self.cnx_cext.unread_result
4729+
self.assertTrue(unread_result, "unread_rows is expected to be True")
4730+
_ = cur_cext.fetchall()
4731+
unread_result = self.cnx_cext.unread_result
4732+
self.assertFalse(unread_result, "unread_rows was not set to False")
4733+
# Query execution must not raise InternalError: Unread result found
4734+
cur_cext.execute(self.test_sql_single_result)
4735+
_ = cur_cext.fetchall()
4736+
4737+
cur_cext.close()
4738+
46964739
@unittest.skipIf(tests.MYSQL_VERSION < (8, 0, 1),
46974740
"Collation utf8mb4_0900_ai_ci not available on 5.7.x")
46984741
class BugOra27277964(tests.MySQLConnectorTests):

0 commit comments

Comments
 (0)