I want to read part of result from cursor and then close it without reading all result. cursor.close()
raises InternalError: Unread result found.
Is it possible to close cursor without iterating through all result or using buffer option?
Update:
My query get about 3000 records, I aim to getting first several records which fit some conditions. After iterating through part of result, I get what I want. Then I want to just abandon unread result. I don't use buffer option which, as I know, will read all result immediately. This question is Not duplicate of Python MySQL connector - unread result found when using fetchone
def chooseInstrumentsFromOrigin(self, time):
sql = """select symbol, name, total_ratio, outstanding_ratio from market_values
where time = %s order by {captype} asc""".format(captype=self.strategy_data['captype'])
args = [time]
conn = mysql.connector.connect(**mysql_config)
cursor = conn.cursor(dictionary=True)
cursor.execute(sql, args)
# This function will return half way.
symbols = self.chooseInstrumentsFromLeaders(time, cursor)
# I don't want this line!
for i in cursor: pass
cursor.close()
conn.close()
return symbols