Description:
Re-evaluating mysql-connector-python to be supported in SQLAlchemy, using a server side cursor fetchmany(1) never returns an empty list. Run demonstration program below
might have appeared with bz#97830
How to repeat:
from mysql import connector
connection = connector.connect(user="scott", password="tiger", host="mysql80", database="test")
cursor = connection.cursor(buffered=False)
cursor.execute("Drop table if exists test")
cursor.execute("create table test (id integer)")
cursor.execute("insert into test (id) values (1), (2), (3), (4), (5)")
cursor.execute("select * from test")
while True:
many = cursor.fetchmany(2)
print(f"Fetchmany(2): {many}")
if not many:
break
cursor.execute("select * from test")
while True:
many = cursor.fetchmany(1)
print(f"Fetchmany(1): {many}")
if not many:
break
for the fetchmany(2) case, output is correct:
Fetchmany(2): [(1,), (2,)]
Fetchmany(2): [(3,), (4,)]
Fetchmany(2): [(5,)]
Fetchmany(2): []
for the fetchmany(1) case, it gets stuck on [(2,)] and never exits:
Fetchmany(1): [(1,)]
Fetchmany(1): [(2,)]
Fetchmany(1): [(2,)]
Fetchmany(1): [(2,)]
Fetchmany(1): [(2,)]
...
turning on buffered mode also resolves, then we get the correct output
Fetchmany(2): [(1,), (2,)]
Fetchmany(2): [(3,), (4,)]
Fetchmany(2): [(5,)]
Fetchmany(2): []
Fetchmany(1): [(1,)]
Fetchmany(1): [(2,)]
Fetchmany(1): [(3,)]
Fetchmany(1): [(4,)]
Fetchmany(1): [(5,)]
Fetchmany(1): []
The above program continuously returns [(2, )]