Python mysql.connector InternalError: Unread result found when close cursor

前端 未结 2 1664
执笔经年
执笔经年 2021-01-13 17:32

I want to read part of result from cursor and then close it without reading all result. cursor.close() raises InternalError: Unread result found. I

相关标签:
2条回答
  • 2021-01-13 18:06

    All you have to do is pass buffered = true in your cursor. Read more official docs

    cursor = conn.cursor(buffered=True)
    
    0 讨论(0)
  • 2021-01-13 18:16

    It would appear that you need:

    cursor = conn.cursor(buffered=True,dictionary=true)
    

    in order to abandon a resultset mid-stream.

    Full disclosure, I am a mysql dev, not a python dev.

    See the Python Manual Page MySQLConnection.cursor() Method and cursor.MySQLCursorBuffered Class.

    All rows are read immediately, true. Fantasic for small to mid-sized resultsets.

    The latter reference above states:

    For queries executed using a buffered cursor, row-fetching methods such as fetchone() return rows from the set of buffered rows. For nonbuffered cursors, rows are not fetched from the server until a row-fetching method is called. In this case, you must be sure to fetch all rows of the result set before executing any other statements on the same connection, or an InternalError (Unread result found) exception will be raised.

    As a side note, you can modify your strategy by using pagination. The MySQL LIMIT clause supports this with the offset,pageSize settings:

    [LIMIT {[offset,] row_count | row_count OFFSET offset}]
    
    0 讨论(0)
提交回复
热议问题